home *** CD-ROM | disk | FTP | other *** search
- /* lstproc.c - program to process lists of filenames. circa:2/15/96*/
- /* Create list by typing the following line at */
- /* DOS prompt: */
-
- /* copy filespec nul: >list.fle */
-
- /* Copyright (C) by D. E. Whitmoyer */
-
- /* GENERAL M.O. */
- /* 0 Read in list.fle - a list of filenames to operate on. */
- /* 1 spawn .exe filename */
- /* 2 do until all filenames have been processed. */
-
- #define NO_FILES 99
- #define LIMIT 39
- #define LSTLN NO_FILES * LIMIT
-
- #include <process.h>
- #include <stdio.h>
- #include <conio.h>
-
- char list[NO_FILES][LIMIT];
- char lst[LSTLN];
-
- main(int argc, char *argv[])
- {
- FILE *fp, *fpdest;
- char c, s[79], *ls=&lst[0], *ls1=ls;
- int limt, i, n, swch = 0, g;
-
- if (argc != 3) {
- printf("\nUsage:\nlstproc filename.exe filename.lst\n");
- printf("\nWhere filename.exe = any executable file\n");
- printf("\t filename.lst = a filename list made by copy to nul device\n");
- printf("\t ie., copy filespec nul: >filename.lst\n\n");
- exit(1);
- }
-
- /* fetch list of filenames */
-
- if ((fp=fopen(argv[2], "r")) == NULL) {
- printf("LISTPROC Can't open %s\n", argv[2]);
- exit(2);
- }
- else {
- while((c = getc(fp)) != EOF)
- *ls++=c;
- }
- fclose(fp);
-
- printf("Fetched list.lst\n");
-
- /* place call to routine to parse the filenames */
- n=prsefn();
- printf("Parsed filenames\n");
- /* spawn exe process for each filename in list */
-
- if(n > (NO_FILES- 1)) {
- printf("\nToo many files in list\n\n");
- exit(3);
- }
-
- for(i=0; i <= n; i++)
- {
- printf("\nNext file in Queue :-> %s", &list[i][0]);
- printf(" Enter <q> to quit\n");
- if(kbhit()) {
- c=getch();
- if ((c == 'q') || (c == 'Q')) exit(0);
- }
- /* spawn process passing args along */
-
- if (!swch)
- status(spawnlp(P_WAIT, argv[1], argv[1], &list[i][0], NULL));
- swch=0;
-
- }
- exit(0);
- }
-
- int status(int value)
- {
- if (value == -1)
- printf("\nFailure to start child process\n");
- else
- if (value > 0)
- {
- printf("\nChild process terminated abnormally\n");
- printf("Error in CRC and/or length\n");
- }
-
- }
-
- /* prsefn - parse filename from a list of filenames */
-
- int prsefn(void) {
-
- int wc=0; /* filename count */
- int i, j=0; /* loop counters */
- char c;
-
- i=0;
- while(i < LSTLN && lst[i] != 32) {
- if(lst[i] == '\n') {
- i++;
- list[wc][j] = '\0';
- wc++;
- j=0;
- }
- else {
- list[wc][j] = lst[i];
- i++;
- j++;
- }
- }
- return(wc-1);
- }
-
- /* GTLN.C - get a line of input */
- /* store in s, return length */
-
- int getline(char *ps,int lim)
- {
- int c ;
- char *i = ps ;
- int cr = 13 ;
-
- while (--lim > 0 && (c=getche()) != cr && c != EOF)
- *ps++=c ;
-
- if (c == cr) {
- *ps++=c ;
- }
- *ps='\0' ;
- return(ps - i) ;
- }
-
- filecpy(FILE *fp, FILE *fpdest) /* copy file fp to file fpdest */
- {
- int c;
-
- while ((c = getc(fp)) != EOF)
- putc(c, fpdest);
- }
-
-
-
-