Back to index

plt-scheme  4.2.1
if_not_there.c
Go to the documentation of this file.
00001 /* Conditionally execute a command based if the file argv[1] doesn't exist */
00002 /* Except for execvp, we stick to ANSI C.                         */
00003 # include "private/gcconfig.h"
00004 # include <stdio.h>
00005 # include <stdlib.h>
00006 # include <unistd.h>
00007 #ifdef __DJGPP__
00008 #include <dirent.h>
00009 #endif /* __DJGPP__ */
00010 
00011 int main(argc, argv, envp)
00012 int argc;
00013 char ** argv;
00014 char ** envp;
00015 {
00016     FILE * f;
00017 #ifdef __DJGPP__
00018     DIR * d;
00019 #endif /* __DJGPP__ */
00020     if (argc < 3) goto Usage;
00021     if ((f = fopen(argv[1], "rb")) != 0
00022         || (f = fopen(argv[1], "r")) != 0) {
00023         fclose(f);
00024         return(0);
00025     }
00026 #ifdef __DJGPP__
00027     if ((d = opendir(argv[1])) != 0) {
00028            closedir(d);
00029            return(0);
00030     }
00031 #endif
00032     printf("^^^^Starting command^^^^\n");
00033     fflush(stdout);
00034     execvp(argv[2], argv+2);
00035     exit(1);
00036     
00037 Usage:
00038     fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
00039     return(1);
00040 }
00041