-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcipscat.c
executable file
·177 lines (151 loc) · 4.73 KB
/
cipscat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*********************************************
*
* file d:\cips\cipscat.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains a program that
* concatenates .c files together, but
* only copies the first occurence of the
* include cips.h statement.
*
* This is very helpful when you need to
* concatenate CIPS code files together
* for compiling.
*
* For example, the cips3.c file contains
* the files addsub.c cutp.c and rotate.c
* To combine these for compiling you run
*
* cipscat addsub.c cutp.c rotate.c -o cips3.c
*
* External Calls:
* none
*
* Modifications:
* 12 May 1993 - created
*
************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENGTH 100
int main(int argc, char *argv[])
{
char input_file_name[LENGTH],
output_file_name[LENGTH],
string[LENGTH],
string2[LENGTH];
FILE *input_file;
FILE *output_file;
int i, j=0;
/*****************************************
*
* Look at the command line to ensure
* it is correct.
*
*****************************************/
if(argc < 4){
printf("\nusage: cipscat in1 in2 ... inx "
"-o out");
printf("\n\n");
exit(1);
}
if(strcmp("-o", argv[argc-2]) != 0){
printf("\nusage: cipscat in1 in2 ... inx "
"-o out");
exit(1);
}
/*****************************************
*
* Ensure none of the input file names
* match the output file name.
*
*****************************************/
for(i=1; i<(argc-2); i++){
if(strcmp(argv[i], argv[argc-1]) == 0){
printf("\nERROR: input file %s has the "
"same name as output file %s\n",
argv[i], argv[argc-1]);
exit(2);
}
}
/*****************************************
*
* Open the output file.
* Put a header comment in it.
*
*****************************************/
strcpy(output_file_name, argv[argc-1]);
if((output_file = fopen(output_file_name, "wt"))
== NULL){
printf("\ncipscat: Error file %s\n",
output_file_name);
exit(1);
}
fputc('\n', output_file);
sprintf(string,
" /*************************** \n");
fputs(string, output_file);
sprintf(string,
" * \n");
fputs(string, output_file);
sprintf(string, " * %s \n",
output_file_name);
fputs(string, output_file);
sprintf(string,
" * COMPOSITE FILE COMPRISING: \n");
fputs(string, output_file);
for(i=1; i<(argc-2); i++){
sprintf(string, " * %s \n",
argv[i]);
fputs(string, output_file);
}
sprintf(string,
" * \n");
fputs(string, output_file);
sprintf(string,
" ***************************\\ \n");
fputs(string, output_file);
fputc('\n', output_file);
fputc('\n', output_file);
/*****************************************
*
* Loop through the input files.
* Copy all of the first one to the
* output. For the rest, look for the
* include cips.h statement and do not copy
* that to the output.
*
*****************************************/
for(i=1; i<(argc-2); i++){
strcpy(input_file_name, argv[i]);
if((input_file = fopen(input_file_name, "rt"))
== NULL){
printf("\ncipscat: Error file %s\n",
input_file_name);
exit(2);
} /* ends if fopen input_file */
printf("\n\tcopying %s to %s",
input_file_name, output_file_name);
if(i==1){ /* First file, so copy it all */
while(fgets(string, LENGTH, input_file))
fputs(string, output_file);
} /* ends if first input file */
else{ /* Other files, look for include */
while(fgets(string, LENGTH, input_file)){
if(strncmp(
string, "#include \"cips.h\"", 15) == 0)
j++;
else
fputs(string, output_file);
}
} /* ends else all the other input files */
fclose(input_file);
} /* ends the main loop over i */
fclose(output_file);
printf("\n");
return(0);
} /* ends main */