SHELL.CPP 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5. #include <dos.h>
  6. #include "getopt.h"
  7. #include "misc.h"
  8. void ShowUsage(void)
  9. {
  10. printf("");
  11. exit(0);
  12. }
  13. void QuitMessage(char * fmt, ...)
  14. {
  15. char msg[80];
  16. va_list argptr;
  17. va_start( argptr, fmt );
  18. vsprintf( msg, fmt, argptr );
  19. va_end(argptr);
  20. printf(msg);
  21. exit(1);
  22. }
  23. void ProcessFile(char *filespec)
  24. {
  25. printf("%s: ", filespec);
  26. printf("done.\n");
  27. }
  28. void ProcessArgument(char *s)
  29. {
  30. char filespec[_MAX_PATH];
  31. char buffer[_MAX_PATH2];
  32. char path[_MAX_PATH];
  33. strcpy(filespec, s);
  34. char *drive, *dir;
  35. // separate the path from the filespec
  36. _splitpath2(s, buffer, &drive, &dir, NULL, NULL);
  37. _makepath(path, drive, dir, NULL, NULL);
  38. struct find_t fileinfo;
  39. unsigned r = _dos_findfirst(s, _A_NORMAL, &fileinfo);
  40. while ( r == 0 )
  41. {
  42. strcpy(filespec, path);
  43. strcat(filespec, fileinfo.name);
  44. ProcessFile(filespec);
  45. r = _dos_findnext( &fileinfo );
  46. }
  47. _dos_findclose(&fileinfo);
  48. }
  49. /***********************************************************************
  50. * Process command line arguments
  51. **********************************************************************/
  52. void ParseOptions( int argc, char *argv[])
  53. {
  54. int c;
  55. while ( (c = GetOptions(argc, argv, "")) != GO_EOF ) {
  56. switch (c) {
  57. case GO_INVALID:
  58. QuitMessage("Invalid argument: %s", OptArgument);
  59. case GO_FULL:
  60. ProcessArgument(OptArgument);
  61. break;
  62. }
  63. }
  64. }
  65. void main(int argc, char *argv[])
  66. {
  67. printf("Conversion shell Copyright (c) 1995 Q Studios Corporation\n");
  68. if (argc < 2) ShowUsage();
  69. ParseOptions(argc, argv);
  70. }