summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorJohn Millaway <john43@users.sourceforge.net>2002-05-10 19:33:34 +0000
committerJohn Millaway <john43@users.sourceforge.net>2002-05-10 19:33:34 +0000
commit3c5f2fde0dedf5b4fd54abac9a7320d347d749b6 (patch)
tree03b3b23da2ff2ea03c82dfdfc5228ddfc730bb64 /misc.c
parent2ade0c4c60d3fa1d0790db4bcb2f4c77d18b1058 (diff)
chomp'd lines when reading external skel file.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/misc.c b/misc.c
index 55fd07d..2e389bc 100644
--- a/misc.c
+++ b/misc.c
@@ -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;
+}