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
Wrap
C/C++ Source or Header
|
1988-03-19
|
2KB
|
91 lines
#include <stdio.h>
#define LINE_LEN 256
char help_txt[] =
"Syntax: submit [<opts>] [<submit file>] [{<parameter>}]\n\n\
Function: Executes commands from the submit file with textual replacement.\r\
The submit file must have the suffix .sub.\n\n\
Options: - ? displays this help message\n\n";
/* bei 'fgets' wird das Zeichen '\n' mitgelesen.
Mit dieser Funktion wird es geloescht.
*/
kill_lf(s)
char s[];
{
s[strlen(s)-1] = '\0';
}
/* Diese Funktion ersetzt im String s die auftretenden '$' Zeichen
mit entsprechenden Argumenten aus der Kommandozeile.
*/
ersetze(s,argc,argv)
char *s;
char *argv[];
int argc;
{
int nummer;
char *position;
char temp[LINE_LEN];
char *index();
if ((position = index(s,'$')) == NULL) return;
strncpy(temp,s,(int)(position - s));
temp[(int)(position - s)] = '\0';
nummer = *(position+1)-'0';
if ((nummer > argc-2) || (nummer < 1))
strcpy(position,position+2);
else
{
strcat(temp,argv[nummer+1]);
strcat(temp,position+2);
strcpy(s,temp);
}
ersetze(s,argc,argv);
}
/* Hauptprogramm */
main(argc,argv)
int argc;
char *argv[];
{
FILE *submit;
FILE *fopen();
char line[LINE_LEN];
if (argc < 2)
{
puts("Error in Parameters");
puts(help_txt);
exit(1);
}
if (!strcmp(argv[1],"-?"))
{
puts(help_txt);
return;
}
strcpy(line,argv[1]);
strcat(line,".sub");
if ((submit = fopen(line,"r")) == NULL)
{
puts("ERROR: Can't open SUBMIT-File");
puts(help_txt);
exit(1);
}
while (fgets(line,LINE_LEN,submit) != NULL)
{
if (strlen(line) < 2) continue;
kill_lf(line);
ersetze(line,argc,argv);
puts(line);
system(line);
}
fclose(submit);
}