home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc / issue.lzh / ISSUE.C next >
Text File  |  1985-12-29  |  7KB  |  97 lines

  1. /*-------------------------------------------------------------------*/
  2. /*   ISSUE -- This is a C Language routine that processes commands   */
  3. /*            across a specified file mask.                          */
  4. /*                                                                   */
  5. /*  Author: J.C. Weilandt II  Date: 12-28-85  Update: 12-29-85       */
  6. /*-------------------------------------------------------------------*/
  7. #define LINT_ARGS 1                /* Enable Strong Type-Checking    */
  8. #include <stdio.h>                 /* File Definitions, etc          */
  9. #include <process.h>               /* Multi-tasking definitions      */
  10. main(number,name)                  /* Initiate main function         */
  11.   int number;                      /* Number of parms                */
  12.   char *name[];                    /* Array of parameters            */
  13.   {                                /* Open main function             */
  14.     FILE *stream;                  /* Define a file pointer          */
  15.     long position = 0;             /* Hold file position             */
  16.     char dest[15];                 /* Destination file_name holder   */
  17.     char odest[15];                /* Old File_Name holder           */
  18.     char cstring[128];             /* Command String Holder          */
  19.     unsigned attr = 0;             /* Attribute for file search      */
  20.     int stat;                      /* DOS Search status code byte    */
  21.     int error;                     /* Declare test integers          */
  22.     char mstring[15];              /* System Mask Holder             */
  23.     char pstring[50];              /* System Parameter Holder        */
  24.     int count = 0;                 /* Count of files processed       */
  25.     int pindex = 0;                /* Parameter string index         */
  26.     int poffset = 0;               /* Parameter offset value         */
  27.     clear();                       /* Clear the screen               */
  28.     printf("              ===> Weilandt Software International <===");
  29.     printf("\n");                  /* Jump down a line               */
  30.     printf("              ===> Issue Command Processor -- 1985 <===");
  31.     printf("\n\n");                /* Jump two lines down            */
  32.     if (number < 2)                /* Q.Parameters passed ??         */
  33.       {                            /*   Nope, open error procedure   */
  34.         printf("Format is:  ISSUE command file_mask parms\n"); /* MS */
  35.         printf("  command:  the command you want to execute\n"); /*  */
  36.         printf("  file_mask: file mask (eg *.*, etc.)\n"); /* MSG    */
  37.         printf("  parms  :  command parameters\n"); /* Message       */
  38.         exit(12);                  /*   Terminate with error         */
  39.       }                            /*   Terminate error procedure    */
  40.     strcpy(odest," ");             /* Initial old destination        */
  41.     strcpy(mstring,"*.*");         /* Load default mask              */
  42.     strcpy(pstring," ");           /* Load default parameter         */
  43.     if (number > 2)      strcpy(mstring,name[2]); /* Load mask       */
  44.     if (number > 3)                /* Q. Do we have parameters ?     */
  45.       {                            /*    Yes, open parameter process */
  46.         pindex = 4;                /*    Load parameter index        */
  47.         while (pindex <= number)   /*    Process all parameters      */
  48.           {                        /*    Open inner loop             */
  49.             poffset = pindex - 1;  /*    Parm block offset value     */
  50.             strcat(pstring,name[poffset]); /* Move in parameter      */
  51.             strcat(pstring," ");   /*    Space between parameters    */
  52.             pindex++;              /*    Increment index value       */
  53.           }                        /*    Terminate while process     */
  54.       }                            /*    Terminate if process        */
  55.     if ((stream = fopen("$$WSI$$$.$$$","a")) == NULL) /* Open file   */
  56.       {                            /* If open failed do this         */
  57.         printf("Temporary File Creation Failed -- Aborting"); /* MSG */
  58.         exit(12);                  /* Terminate Procedure            */
  59.       }                            /* Terminate Failure Logic        */
  60.     stat = dosfirst(mstring,attr,dest); /* Read DOS Directory        */
  61.     while (!stat)                  /* Q. Was the read successful ??  */
  62.       {                            /*    Yes, open inner procedure   */
  63.         fprintf(stream,"%s\n",dest); /*  Write file_name to output   */
  64.         stat = dosnext(mstring,attr,dest); /* Read next Dir Entry    */
  65.       }                            /*    Terminate inner procedure   */
  66.     fclose(stream);                /* Close the output file          */
  67.     if ((stream = fopen("$$WSI$$$.$$$","r")) == NULL) /* Open file   */
  68.       {                            /* If open failed do this         */
  69.         printf("Temporary File Open Has Failed -- Aborting"); /* MSG */
  70.         exit(12);                  /* Terminate Procedure            */
  71.       }                            /* Terminate Failure Logic        */
  72.     while (!feof(stream))          /* Q. Not end-of-file yet ??      */
  73.       {                            /*    Yes, open inner procedure   */
  74.         fseek(stream,position,0);  /*    Position the file pointer   */
  75.                                    /* => FSEEK and FTELL Processing  */
  76.                                    /* => required because SPAWN      */
  77.                                    /* => resets the file pointers    */
  78.         fgets(dest,15,stream);     /*    Read next file entry        */
  79.         position = ftell(stream);  /*    Get new file position       */
  80.         ctrans(dest,'\n',' ');     /*    Translate newline to blank  */
  81.         if (strcmp(dest,odest) == 0) break; /* Get out if done       */
  82.         strcpy(odest,dest);        /*    Copy dest to odest          */
  83.         printf("Executing ==> %s %s %s\n", name[1], dest, pstring);
  84.         count++;                   /* Increment file counter         */
  85.         strcpy(cstring,name[1]);   /* Start DOS Command String Build */
  86.         strcat(cstring," ");       /* Put in a blank                 */
  87.         strcat(cstring,dest);      /* Move in the filename           */
  88.         strcat(cstring," ");       /* Put in a blank                 */
  89.         strcat(cstring,pstring);   /* Move in the Parameters         */
  90.         error = system(cstring);   /* Execute the Dos Command        */
  91.       }                            /*    Terminate inner loop        */
  92.     fclose(stream);                /* Close the input file           */
  93.     system("erase $$WSI$$$.$$$");  /* Delete the input file          */
  94.     printf("\nTotal Files Processed: %d\n", count); /* Final Message */
  95.     exit(0);                       /* Set good RC                    */
  96.   }
  97.