home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum4.lzh / SPRACHEN / C / SUBMIT / submit.c < prev   
C/C++ Source or Header  |  1988-03-19  |  2KB  |  91 lines

  1. #include <stdio.h>
  2.  
  3. #define LINE_LEN   256
  4.  
  5. char     help_txt[] =
  6. "Syntax: submit [<opts>] [<submit file>] [{<parameter>}]\n\n\
  7. Function: Executes commands from the submit file with textual replacement.\r\
  8.           The submit file must have the suffix .sub.\n\n\
  9. Options:   - ?          displays this help message\n\n";
  10.      
  11. /* bei 'fgets' wird das Zeichen '\n' mitgelesen.
  12.    Mit dieser Funktion wird es geloescht.
  13. */
  14.  
  15. kill_lf(s)
  16. char    s[];
  17. {
  18.     s[strlen(s)-1] = '\0';
  19. }
  20.  
  21. /* Diese Funktion ersetzt im String s die auftretenden '$' Zeichen
  22.    mit entsprechenden Argumenten aus der Kommandozeile.
  23. */
  24.  
  25. ersetze(s,argc,argv)
  26. char    *s;
  27. char    *argv[];
  28. int        argc;
  29. {
  30.     int     nummer;
  31.     char    *position;
  32.     char    temp[LINE_LEN];
  33.     char    *index();
  34.  
  35.     if ((position = index(s,'$')) == NULL) return;
  36.     strncpy(temp,s,(int)(position - s)); 
  37.     temp[(int)(position - s)] = '\0';
  38.     nummer = *(position+1)-'0';
  39.     if ((nummer > argc-2) || (nummer < 1))
  40.         strcpy(position,position+2);
  41.     else
  42.         {
  43.             strcat(temp,argv[nummer+1]);
  44.             strcat(temp,position+2);
  45.             strcpy(s,temp);
  46.         }
  47.         ersetze(s,argc,argv);
  48.     }
  49.  
  50.     /* Hauptprogramm */
  51.     
  52.     main(argc,argv)
  53.     int     argc;
  54.     char    *argv[];
  55.     {
  56.         FILE    *submit;
  57.         FILE    *fopen();
  58.         char    line[LINE_LEN];
  59.  
  60.         if (argc < 2)
  61.             {
  62.                 puts("Error in Parameters");
  63.                 puts(help_txt);
  64.                 exit(1);
  65.             }
  66.         if (!strcmp(argv[1],"-?"))
  67.             {
  68.                 puts(help_txt);
  69.                 return;
  70.             }
  71.         strcpy(line,argv[1]);
  72.         strcat(line,".sub");
  73.         if ((submit = fopen(line,"r")) == NULL)
  74.             {
  75.                 puts("ERROR: Can't open SUBMIT-File");
  76.                 puts(help_txt);
  77.                 exit(1);
  78.             }
  79.         while (fgets(line,LINE_LEN,submit) != NULL)
  80.             {
  81.                 if (strlen(line) < 2) continue;
  82.                 kill_lf(line);
  83.                 ersetze(line,argc,argv);
  84.                 puts(line);
  85.                 system(line);
  86.             }
  87.         fclose(submit);
  88.     }
  89.     
  90.             
  91.