Crtl-C gives a new line when reading input
[reactos.git] / reactos / tools / depends.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 int main(int argc, char* argv[])
6 {
7 char buf[512];
8 char buf2[512];
9 char ch;
10 unsigned int i, j;
11 char* dot;
12 char* ext;
13 char* prefix;
14 FILE* out;
15
16 if (argc != 3)
17 {
18 printf("Too few arguments\n");
19 return(1);
20 }
21
22 prefix = strdup(argv[1]);
23
24 out = fopen(argv[2], "wb");
25 if (out == NULL)
26 {
27 printf("Unable to open output file\n");
28 return(1);
29 }
30
31 i = 0;
32 while ((ch = fgetc(stdin)) == '#')
33 {
34 while ((ch = fgetc(stdin)) != '\n' && ch != EOF)
35 {
36 }
37 }
38 if (ch != EOF)
39 {
40 buf[i] = ch;
41 i++;
42 }
43
44 while ((ch = fgetc(stdin)) != ':' && ch != EOF)
45 {
46 buf[i] = ch;
47 i++;
48 }
49 buf[i] = 0;
50
51 if (i == 0)
52 {
53 return(0);
54 }
55 i = 0;
56 while ((ch = fgetc(stdin)) == ' ' && ch != EOF)
57 {
58 buf2[i] = ch;
59 i++;
60 }
61 if (i == 0)
62 {
63 return 0;
64 }
65 if (ch != EOF)
66 {
67 buf2[i] = ch;
68 i++;
69 }
70 j = i;
71 while ((ch = fgetc(stdin)) != ' ' && ch != EOF)
72 {
73 buf2[j] = ch;
74 j++;
75 }
76 buf2[j] = 0;
77 if (i == j)
78 {
79 return 0;
80 }
81
82 ext = strrchr(buf2, '.');
83 if (ext != NULL)
84 {
85 if (0 == strcmp(ext, ".h"))
86 {
87 ext = "h.gch";
88 }
89 else
90 {
91 ext = NULL;
92 }
93 }
94
95 dot = strrchr(buf, '.');
96 if (dot != NULL)
97 {
98 *dot = 0;
99 }
100 fprintf(out, "%s/.%s.TAG %s/.%s.d %s/%s.%s:%s ", prefix, buf, prefix, buf,
101 prefix,buf,ext ? ext : "o" , buf2);
102
103 while ((ch = fgetc(stdin)) != EOF)
104 {
105 fputc(ch, out);
106 }
107
108 return(0);
109 }