]> andersk Git - moira.git/commitdiff
removed trim & strsave, added fix_file & dequote
authormar <mar>
Fri, 5 Aug 1988 19:14:53 +0000 (19:14 +0000)
committermar <mar>
Fri, 5 Aug 1988 19:14:53 +0000 (19:14 +0000)
gen/util.c

index 153987c97fb71e850f81c6f2070c4605238ac1b2..d241de8da1e01a9de87bd9390a96e6f602303f7f 100644 (file)
@@ -6,42 +6,8 @@
 
 #include <stdio.h>
 #include <sys/time.h>
-
-char *malloc();
-
-
-/* Trim trailing spaces from a string by replacing one of them with a null.
- */
-
-trim(s)
-register char *s;
-{
-    register char *p;
-
-    for (p = s; *s; s++)
-      if (*s != ' ')
-       p = s;
-    if (p != s) {
-       if (*p == ' ')
-         *p = 0;
-       else
-         p[1] = 0;
-    }
-}
-
-
-/* return a "saved" copy of the string */
-
-char *strsave(s)
-register char *s;
-{
-    register char *r;
-
-    r = malloc(strlen(s) + 1);
-    strcpy(r, s);
-    return(r);
-}
-
+#include <sms.h>
+#include <sms_app.h>
 
 
 /* ingres_date_and_time: passed a unix time_t, returns a string that ingres
@@ -111,3 +77,43 @@ char *ingres_date(t)
        }
 }
 
+
+fix_file(targetfile)
+char *targetfile;
+{
+    char oldfile[64], filename[64];
+
+    sprintf(oldfile, "%s.old", targetfile);
+    sprintf(filename, "%s~", targetfile);
+    if (rename(targetfile, oldfile) == 0) {
+       if (rename(filename, targetfile) < 0) {
+           rename(oldfile, targetfile);
+           perror("Unable to install new file (rename failed)\n");
+           fprintf(stderr, "Filename = %s\n", targetfile);
+           exit(SMS_CCONFIG);
+       }
+    } else {
+       if (rename(filename, targetfile) < 0) {
+           perror("Unable to rename old file\n");
+           fprintf(stderr, "Filename = %s\n", targetfile);
+           exit(SMS_CCONFIG);
+       }
+    }
+    unlink(oldfile);
+}
+
+
+char *dequote(s)
+register char *s;
+{
+    char *last = s;
+
+    while (*s) {
+       if (*s == '"')
+         *s = '\'';
+       else if (*s != ' ')
+         last = s;
+       s++;
+    }
+    *(++last) = '\0';
+}
This page took 0.075524 seconds and 5 git commands to generate.