]> andersk Git - splint.git/blob - test/nullterminatedtest/buggy_support1.c
noexpand always false.
[splint.git] / test / nullterminatedtest / buggy_support1.c
1 #include <stdio.h>
2
3 #define LF 10
4 #define CR 13
5
6 void getword(char *word, char *line, char stop) {
7     int x = 0,y;
8
9     for(x=0;((line[x]) && (line[x] != stop));x++)
10         word[x] = line[x];
11
12     word[x] = '\0';
13     if(line[x]) ++x;
14     y=0;
15
16     while(line[y++] = line[x++]);
17 }
18
19 char *makeword(char *line, char stop) {
20     int x = 0,y;
21     char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
22
23     for(x=0;((line[x]) && (line[x] != stop));x++)
24         word[x] = line[x];
25
26     word[x] = '\0';
27     if(line[x]) ++x;
28     y=0;
29
30     while(line[y++] = line[x++]);
31     return word;
32 }
33
34 char *fmakeword(FILE *f, char stop, int *cl) {
35     int wsize;
36     char *word;
37     int ll;
38
39     wsize = 102400;
40     ll=0;
41     word = (char *) malloc(sizeof(char) * (wsize + 1));
42
43     while(1) {
44         word[ll] = (char)fgetc(f);
45         if(ll==wsize) {
46             wsize+=102400;
47             word = (char *)realloc(word,sizeof(char)*(wsize+1));
48         }
49         --(*cl);
50         if((word[ll] == stop) || (feof(f)) || (!(*cl))) {
51             if(word[ll] != stop) ll++;
52             word[ll] = '\0';
53             return word;
54         }
55         ++ll;
56     }
57 }
58
59 char x2c(char *what) {
60     register char digit;
61
62     digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
63     digit *= 16;
64     digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
65     return(digit);
66 }
67
68 void unescape_url(char *url) {
69     register int x,y;
70
71     for(x=0,y=0;url[y];++x,++y) {
72         if((url[x] = url[y]) == '%') {
73             url[x] = x2c(&url[y+1]);
74             y+=2;
75         }
76     }
77     url[x] = '\0';
78 }
79
80 void plustospace(char *str) {
81     register int x;
82
83     for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
84 }
85
86 int rind(char *s, char c) {
87     register int x;
88     for(x=strlen(s) - 1;x != -1; x--)
89         if(s[x] == c) return x;
90     return -1;
91 }
92
93 int getline(char *s, int n, FILE *f) {
94     register int i=0;
95
96     while(1) {
97         s[i] = (char)fgetc(f);
98
99         if(s[i] == CR)
100             s[i] = fgetc(f);
101
102         if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
103             s[i] = '\0';
104             return (feof(f) ? 1 : 0);
105         }
106         ++i;
107     }
108 }
109
110 void send_fd(FILE *f, FILE *fd)
111 {
112     int num_chars=0;
113     char c;
114
115     while (1) {
116         c = fgetc(f);
117         if(feof(f))
118             return;
119         fputc(c,fd);
120     }
121 }
122
123 int ind(char *s, char c) {
124     register int x;
125
126     for(x=0;s[x];x++)
127         if(s[x] == c) return x;
128
129     return -1;
130 }
131
132 void escape_shell_cmd(char *cmd) {
133     register int x,y,l;
134
135     l=strlen(cmd);
136     for(x=0;cmd[x];x++) {
137         if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1){
138             for(y=l+1;y>x;y--)
139                 cmd[y] = cmd[y-1];
140             l++; /* length has been increased */
141             cmd[x] = '\\';
142             x++; /* skip the character */
143         }
144     }
145 }
This page took 0.050662 seconds and 5 git commands to generate.