home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 4 / CD_ACTUAL_4.iso / share / dos / utilidad / dewav / lstproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  2.9 KB  |  148 lines

  1. /* lstproc.c - program to process lists of filenames.  circa:2/15/96*/
  2.     /*    Create list by typing the following line at */
  3.     /*    DOS prompt:                       */
  4.  
  5. /*        copy filespec nul: >list.fle     */
  6.  
  7. /* Copyright (C) by D. E. Whitmoyer */
  8.  
  9. /* GENERAL M.O.                   */
  10. /* 0    Read in list.fle - a list of filenames to operate on. */
  11. /* 1    spawn .exe filename */
  12. /* 2    do until all filenames have been processed. */
  13.  
  14. #define NO_FILES 99
  15. #define LIMIT    39
  16. #define LSTLN  NO_FILES * LIMIT
  17.  
  18. #include <process.h>
  19. #include <stdio.h>
  20. #include <conio.h>
  21.  
  22. char    list[NO_FILES][LIMIT];
  23. char    lst[LSTLN];
  24.  
  25. main(int argc, char *argv[])
  26. {
  27. FILE *fp, *fpdest;
  28. char c, s[79], *ls=&lst[0], *ls1=ls;
  29. int limt, i, n, swch = 0, g;
  30.  
  31. if (argc != 3) {
  32.     printf("\nUsage:\nlstproc filename.exe filename.lst\n");
  33.     printf("\nWhere    filename.exe = any executable file\n");
  34.     printf("\t filename.lst = a filename list made by copy to nul device\n");
  35.     printf("\t                ie., copy filespec nul: >filename.lst\n\n");
  36.     exit(1);
  37. }
  38.  
  39. /* fetch list of filenames */
  40.  
  41. if ((fp=fopen(argv[2], "r")) == NULL) {
  42.     printf("LISTPROC Can't open %s\n", argv[2]);
  43.     exit(2);
  44.     }
  45.     else {
  46.         while((c = getc(fp)) != EOF)
  47.             *ls++=c;
  48.             }
  49. fclose(fp);
  50.  
  51. printf("Fetched list.lst\n");
  52.  
  53. /* place call to routine to parse the filenames */
  54. n=prsefn();
  55. printf("Parsed filenames\n");
  56. /* spawn exe process for each filename in list */
  57.  
  58. if(n > (NO_FILES- 1)) {
  59.     printf("\nToo many files in list\n\n");
  60.     exit(3);
  61.     }
  62.  
  63. for(i=0; i <= n; i++)
  64. {
  65.     printf("\nNext file in Queue :-> %s", &list[i][0]);
  66.     printf(" Enter <q> to quit\n");
  67.         if(kbhit()) {
  68.             c=getch();
  69.             if ((c == 'q') || (c == 'Q')) exit(0);
  70.                 }
  71. /* spawn process passing args along */
  72.  
  73. if (!swch)
  74.     status(spawnlp(P_WAIT, argv[1], argv[1], &list[i][0], NULL));
  75. swch=0;
  76.  
  77. }
  78. exit(0);
  79. }
  80.  
  81. int    status(int value)
  82. {
  83.     if (value == -1)
  84.         printf("\nFailure to start child process\n");
  85.     else
  86.         if (value > 0)
  87.                         {
  88.                 printf("\nChild process terminated abnormally\n");
  89.                         printf("Error in CRC and/or length\n");
  90.                 }
  91.  
  92. }
  93.  
  94. /* prsefn - parse filename from a list of filenames */
  95.  
  96. int    prsefn(void) {
  97.  
  98.     int wc=0;  /* filename count */
  99.     int i, j=0;  /* loop counters */
  100.     char    c;
  101.  
  102. i=0;
  103. while(i < LSTLN && lst[i] != 32) {
  104.     if(lst[i] == '\n') {
  105.     i++;
  106.     list[wc][j] = '\0';
  107.     wc++;
  108.     j=0;
  109.     }
  110.     else {
  111.     list[wc][j] = lst[i];
  112.     i++;
  113.     j++;
  114.     }
  115.    }
  116.    return(wc-1);
  117. }
  118.  
  119. /* GTLN.C - get a line of input */
  120.         /* store in s, return length */
  121.  
  122. int     getline(char *ps,int lim)
  123.     {
  124.     int c ;
  125.     char *i = ps ;
  126.     int cr = 13 ;
  127.  
  128.     while (--lim > 0 && (c=getche()) != cr && c != EOF)
  129.         *ps++=c ;
  130.  
  131.     if (c == cr)     {
  132.         *ps++=c ;
  133.         }
  134.     *ps='\0' ;
  135.     return(ps - i) ;
  136.     }
  137.  
  138. filecpy(FILE *fp, FILE *fpdest)  /*     copy file fp to file fpdest  */
  139.     {
  140.     int c;
  141.  
  142.     while ((c = getc(fp)) != EOF)
  143.         putc(c, fpdest);
  144.         }
  145.  
  146.  
  147.  
  148.