]> diplodocus.org Git - nmh/blobdiff - sbr/trimcpy.c
uip: Replace some ints that are only ever 0 or 1 with bool.
[nmh] / sbr / trimcpy.c
index 6bcf3aec693d3002bd934ee2513f56277bb50d86..625c26c0ac0e022fff023db542293c05517fbd03 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * trimcpy.c -- strip leading and trailing whitespace,
+/* trimcpy.c -- strip leading and trailing whitespace,
  *           -- replace internal whitespace with spaces,
  *           -- then return a copy.
  *
@@ -37,7 +35,7 @@ trimcpy (char *cp)
     }
 
     /* now return a copy */
-    return getcpy(cp);
+    return mh_xstrdup(cp);
 }
 
 
@@ -58,7 +56,7 @@ cpytrim (const char *sp) {
     /* skip over leading whitespace */
     while (isspace ((unsigned char) *sp)) ++sp;
 
-    dp = add (sp, NULL);
+    dp = mh_xstrdup(sp);
 
     /* start at the end and zap trailing whitespace */
     for (cp = dp + strlen (dp) - 1;
@@ -72,3 +70,25 @@ cpytrim (const char *sp) {
 
     return dp;
 }
+
+
+/*
+ * rtrim() -- modify the argument to:
+ *         -- strip trailing whitespace
+ *
+ * This code is Copyright (c) 2014, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+char *
+rtrim (char *sp) {
+    char *cp;
+
+    /* start at the end and zap trailing whitespace */
+    for (cp = sp + strlen (sp) - 1;
+         cp >= sp  &&  isspace ((unsigned char) *cp);
+         --cp) { continue; }
+    *++cp = '\0';
+
+    return sp;
+}