Debian Codegraph @

texk/web2c/otps/win32/mkocp.c

raw
1 /*
2 mkocp.c
3 */
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <malloc.h>
9 #include <process.h>
10
11 /* kpathsea functions
12 */
13 #include <kpathsea/kpathsea.h>
14
15 int main(int ac, char **av)
16 {
17 int savo, savi;
18 FILE *fnul;
19 char name[256];
20 char fullname[256];
21 char *p;
22
23 kpse_set_program_name(av[0], "mkocp");
24
25 if(ac != 2) {
26 fprintf(stderr,"%s : Usage %s ocpname\n", av[0], av[0]);
27 return 1;
28 }
29
30 p = strrchr(av[1], '.');
31 if(p)
32 *p = '\0';
33 strcpy(name, av[1]);
34 strcpy(fullname, name);
35 strcat(fullname, ".ocp");
36
37 /* save stdout and stdin */
38 savo = _dup(fileno(stdout));
39 savi = _dup(fileno(stdin));
40
41 /* connect stdout to stderr */
42 _dup2(fileno(stderr), fileno(stdout));
43
44 /* connect stdin to nul device */
45 if(!(fnul = fopen("nul", "r"))) {
46 fprintf(stderr, "Cannot open nul device to read\n");
47 exit(100);
48 }
49 _dup2(fileno(fnul), fileno(stdin));
50
51 /* COMMAND */
52
53 _spawnlp(_P_WAIT, "otp2ocp", "otp2ocp", name, NULL);
54
55 /* END COMMAND */
56
57 /* return to original stdout and stdin */
58 _dup2(savo, fileno(stdout));
59 close(savo);
60 _dup2(savi, fileno(stdin));
61 close(savi);
62
63 /* close nul device */
64 fclose(fnul);
65
66 if(_access(fullname, 0) == 0)
67 printf("%s\n", fullname);
68
69 return 0;
70 }