diff options
author | John Millaway <john43@users.sourceforge.net> | 2002-05-10 19:33:34 +0000 |
---|---|---|
committer | John Millaway <john43@users.sourceforge.net> | 2002-05-10 19:33:34 +0000 |
commit | 3c5f2fde0dedf5b4fd54abac9a7320d347d749b6 (patch) | |
tree | 03b3b23da2ff2ea03c82dfdfc5228ddfc730bb64 /misc.c | |
parent | 2ade0c4c60d3fa1d0790db4bcb2f4c77d18b1058 (diff) |
chomp'd lines when reading external skel file.
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -796,7 +796,12 @@ void skelout() while ( skelfile ? (fgets( buf, MAXLINE, skelfile ) != NULL) : ((buf = (char *) skel[skel_ind++]) != 0) ) - { /* copy from skel array */ + { + + if (skelfile ) + chomp(buf); + + /* copy from skel array */ if ( buf[0] == '%' ) { /* control line */ /* print the control line as a comment. */ @@ -844,15 +849,7 @@ void skelout() } else if ( do_copy ) - { - if ( skelfile ) - /* Skeleton file reads include final - * newline, skel[] array does not. - */ - out( buf ); - else outn( buf ); - } } } @@ -915,3 +912,22 @@ size_t size_in_bytes; while ( rp < rp_end ) *rp++ = 0; } + +/* Remove all '\n' and '\r' characters, if any, from the end of str. + * str can be any null-terminated string, or NULL. + * returns str. */ +char* chomp(char* str){ + char* p=str; + if (!str || !*str) /* s is null or empty string */ + return str; + + /* find end of string minus one*/ + while (*p) + ++p; + --p; + + /* eat newlines */ + while (p >= str && (*p == '\r' || *p == '\n')) + *p-- = 0; + return str; +} |