#include #include #include #define MaxPath 256 //extern char *iconxloc; /* * execute - execute iconx to run the icon program */ static void execute(char *ofile, char *efile, char *args[]) { int n; char **argv, **p; char buf[MaxPath+10]; char *iconxloc = "./iconx"; /* * Build argument vector. */ for (n = 0; args[n] != NULL; n++) /* count arguments */ ; p = argv = malloc((n + 5) * sizeof(char *)); *p++ = ofile; /* pass icode file name */ while ((*p++ = *args++) != 0) /* copy args into argument vector */ ; *p = NULL; /* * Redirect stderr if requested. */ if (efile != NULL) { close(fileno(stderr)); if (strcmp(efile, "-") == 0) dup(fileno(stdout)); else if (freopen(efile, "w", stderr) == NULL) fprintf(stderr,"could not redirect stderr to %s\n", efile); } /* * Export $ICONX to specify the path to iconx. */ sprintf(buf, "ICONX=%s", iconxloc); putenv(buf); /* */ execv(ofile, argv); fprintf(stderr,"could not execute %s\n", ofile); } void main(void) { char *icode = "hello"; char *args[2] = {"hello", NULL}; execute(icode, NULL, args); /* execute the program */ fprintf(stderr,"could not execute %s\n", icode); }