1 #include "test.h"
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <dirent.h>
5
6
main(int argc,char * argv[])7 int main(int argc, char * argv[])
8 {
9 char b[100];
10 char fexe[100];
11 char fpass[100];
12 char ffail[100];
13 char fres[100];
14 char fnob[100];
15 char cmd[100];
16 char *e;
17 struct stat st;
18 DIR *dir;
19 struct dirent *ent;
20
21 if (argc!=2) {
22 printf("usage: runall <dir>\n");
23 return 0; //EXIT_FAILURE;
24 }
25 dir = opendir (argv[1]);
26 if (dir != NULL) {
27 while ((ent = readdir (dir)) != NULL) {
28 strcpy(b, ent->d_name);
29 if (strstr(b,"runall.c")) {
30 /* skip myself */
31 continue;
32 }
33 e = strchr(b,'.');
34 if (e) {
35 *e ++ = '\0';
36 if (strcmp(e,"c")==0) {
37 sprintf(fexe,"%s.exe",b);
38 sprintf(fpass,"%s.pass",b);
39 sprintf(ffail,"%s.fail",b);
40 sprintf(fres,"%s.res",b);
41 sprintf(fnob,"%s.x",b);
42
43 if (stat(fexe,&st)==0) {
44 if ( (stat(fpass,&st)!=0) && (stat(ffail,&st)!=0)) {
45 sprintf(cmd,"%s 2> %s",fexe,fres);
46 if (system(cmd)) {
47 rename(fres,ffail);
48 } else {
49 rename(fres,fpass);
50 }
51 }
52 } else {
53 sprintf(cmd,"touch %s",fnob);
54 system(cmd);
55 }
56 }
57 }
58
59 }
60 closedir (dir);
61 } else {
62 /* could not open directory */
63 perror ("");
64 return 0; //EXIT_FAILURE;
65 }
66 return 0;
67 }
68