home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / ISSUE.C < prev    next >
Text File  |  1991-09-23  |  8KB  |  118 lines

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