diff options
| author | Miles Bader | 2001-10-17 02:53:57 +0000 |
|---|---|---|
| committer | Miles Bader | 2001-10-17 02:53:57 +0000 |
| commit | 0c82822ca0b5cc0445f218d1c719ca6bbe560031 (patch) | |
| tree | b97db3a02469ea082706bb13403f9802b8fb4cdd /lib-src | |
| parent | 9f89e098634f1eeb0bf6e14c2b0b5f9ab575031d (diff) | |
| download | emacs-0c82822ca0b5cc0445f218d1c719ca6bbe560031.tar.gz emacs-0c82822ca0b5cc0445f218d1c719ca6bbe560031.zip | |
(put_char): New function.
(read_c_string_or_comment): Strip trailing spaces and newlines.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/make-docfile.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index cfa7878d6f5..8a74de40301 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c | |||
| @@ -198,6 +198,42 @@ scan_file (filename) | |||
| 198 | 198 | ||
| 199 | char buf[128]; | 199 | char buf[128]; |
| 200 | 200 | ||
| 201 | /* Add CH to either outfile, if PRINTFLAG is positive, or to the buffer | ||
| 202 | whose end is pointed to by BUFP, if PRINTFLAG is negative. | ||
| 203 | If the counters pointed to by PENDING_NEWLINES and PENDING_SPACES are | ||
| 204 | non-zero, that many newlines and spaces are output before CH, and | ||
| 205 | the counters are zeroed. */ | ||
| 206 | |||
| 207 | static INLINE void | ||
| 208 | put_char (ch, printflag, bufp, pending_newlines, pending_spaces) | ||
| 209 | int ch, printflag; | ||
| 210 | char **bufp; | ||
| 211 | unsigned *pending_newlines, *pending_spaces; | ||
| 212 | { | ||
| 213 | int out_ch; | ||
| 214 | do | ||
| 215 | { | ||
| 216 | if (*pending_newlines > 0) | ||
| 217 | { | ||
| 218 | (*pending_newlines)--; | ||
| 219 | out_ch = '\n'; | ||
| 220 | } | ||
| 221 | else if (*pending_spaces > 0) | ||
| 222 | { | ||
| 223 | (*pending_spaces)--; | ||
| 224 | out_ch = ' '; | ||
| 225 | } | ||
| 226 | else | ||
| 227 | out_ch = ch; | ||
| 228 | |||
| 229 | if (printflag > 0) | ||
| 230 | putc (out_ch, outfile); | ||
| 231 | else if (printflag < 0) | ||
| 232 | *(*bufp)++ = out_ch; | ||
| 233 | } | ||
| 234 | while (out_ch != ch); | ||
| 235 | } | ||
| 236 | |||
| 201 | /* Skip a C string or C-style comment from INFILE, and return the | 237 | /* Skip a C string or C-style comment from INFILE, and return the |
| 202 | character that follows. COMMENT non-zero means skip a comment. If | 238 | character that follows. COMMENT non-zero means skip a comment. If |
| 203 | PRINTFLAG is positive, output string contents to outfile. If it is | 239 | PRINTFLAG is positive, output string contents to outfile. If it is |
| @@ -210,6 +246,7 @@ read_c_string_or_comment (infile, printflag, comment) | |||
| 210 | int printflag; | 246 | int printflag; |
| 211 | { | 247 | { |
| 212 | register int c; | 248 | register int c; |
| 249 | unsigned pending_spaces = 0, pending_newlines = 0; | ||
| 213 | char *p = buf; | 250 | char *p = buf; |
| 214 | 251 | ||
| 215 | if (comment) | 252 | if (comment) |
| @@ -239,10 +276,16 @@ read_c_string_or_comment (infile, printflag, comment) | |||
| 239 | c = '\t'; | 276 | c = '\t'; |
| 240 | } | 277 | } |
| 241 | 278 | ||
| 242 | if (printflag > 0) | 279 | if (c == ' ') |
| 243 | putc (c, outfile); | 280 | pending_spaces++; |
| 244 | else if (printflag < 0) | 281 | else if (c == '\n') |
| 245 | *p++ = c; | 282 | { |
| 283 | pending_newlines++; | ||
| 284 | pending_spaces = 0; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | put_char (c, printflag, &p, &pending_newlines, &pending_spaces); | ||
| 288 | |||
| 246 | c = getc (infile); | 289 | c = getc (infile); |
| 247 | } | 290 | } |
| 248 | 291 | ||
| @@ -257,10 +300,7 @@ read_c_string_or_comment (infile, printflag, comment) | |||
| 257 | break; | 300 | break; |
| 258 | } | 301 | } |
| 259 | 302 | ||
| 260 | if (printflag > 0) | 303 | put_char ('*', printflag, &p, &pending_newlines, &pending_spaces); |
| 261 | putc ('*', outfile); | ||
| 262 | else if (printflag < 0) | ||
| 263 | *p++ = '*'; | ||
| 264 | } | 304 | } |
| 265 | else | 305 | else |
| 266 | { | 306 | { |