X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/dfb56d6bef75283bf17170cee566169857f0abe7..99a288b9f3d6334273ef98d166adf71d2e79c2ee:/gen/util.c diff --git a/gen/util.c b/gen/util.c index 153987c9..5e5c7287 100644 --- a/gen/util.c +++ b/gen/util.c @@ -1,47 +1,18 @@ /* $Header$ * * Utility routines used by the SMS extraction programs. + * + * (c) Copyright 1988 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . */ +#include #include #include - -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 +#include /* ingres_date_and_time: passed a unix time_t, returns a string that ingres @@ -111,3 +82,46 @@ 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++; + } + if (*last == ' ') + *last = '\0'; + else + *(++last) = '\0'; +}