forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexc.c
executable file
·104 lines (86 loc) · 2.45 KB
/
texc.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
/*
texc program
usage: texc input_file output_file
Replace the TeX special characters with
the \ and special character.
This is a helpful utility when converting a
text file to a tex file. The text files
use many of the TeX special characters and
the \ needs to be put in front of the
special characters.
27 February 2000
*/
#include <stdio.h>
#include <stdlib.h>
int clear_out_buffer();
int insert_slash();
int main(argc, argv)
int argc;
char *argv[];
{
FILE *input_file;
FILE *output_file;
if(argc != 3){
printf("\nusage: texc input_file output_file\n");
exit(1);
}
if((input_file = fopen (argv[1], "rt")) == NULL){
printf("\ntexc: error opening file %s\n", argv[1]);
exit(1);
}
if((output_file = fopen (argv[2], "wt")) == NULL){
printf("\ntexc: error opening file %s\n", argv[2]);
exit(1);
}
insert_slash(input_file, output_file);
fclose(input_file);
fclose(output_file);
} /* ends main */
int insert_slash(input_file, output_file)
FILE *input_file;
FILE *output_file;
{
char outs[300];
char string[300];
int i, j, k;
while(fgets(string, 300, input_file)){
k = 0;
for(i=0; string[i] != '\n' && string[i] != '\0'; i++){
if(string[i] == '_' ||
string[i] == '$' ||
string[i] == '#' ||
string[i] == '&' ||
string[i] == '{' ||
string[i] == '}' ||
string[i] == '^' ||
string[i] == '~' ||
string[i] == '%' ||
string[i] == '\\'){
outs[k] = '\\';
k++;
outs[k] = string[i];
k++;
} /* ends if string[i] == a special character */
else{
outs[k] = string[i];
k++;
} /* ends else */
} /* ends loop over i and string[i] */
outs[k] = '\n';
outs[k+1] = '\0';
fputs(outs, output_file);
clear_out_buffer(string, 300);
clear_out_buffer(outs, 300);
} /* ends while fgets */
return(1);
} /* ends insert_slash */
int clear_out_buffer(string, n)
char string[];
int n;
{
int i;
for(i=0; i<n; i++)
string[i] = ' ';
string[0] = '\0';
return(1);
}