]> andersk Git - moira.git/blame - gen/util.c
fix misspelling
[moira.git] / gen / util.c
CommitLineData
dfb56d6b 1/* $Header$
2 *
3 * Utility routines used by the SMS extraction programs.
0a5ff702 4 *
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
dfb56d6b 8 */
9
10
0a5ff702 11#include <mit-copyright.h>
dfb56d6b 12#include <stdio.h>
13#include <sys/time.h>
70c18c18 14#include <sms.h>
15#include <sms_app.h>
dfb56d6b 16
17
18/* ingres_date_and_time: passed a unix time_t, returns a string that ingres
19 * can parse to obtain that time.
20 */
21
22static char *month_name[] = {
23 "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
24 "nov", "dec"
25 };
26
27
28char *ingres_date(), *ingres_time();
29
30char *ingres_date_and_time(l)
31long l;
32{
33 char *ans = NULL, *date, *time;
34
35 if ((date = ingres_date(l)) && (time = ingres_time(l))) {
36 char buf[BUFSIZ];
37 sprintf(buf, "%s %s", date, time);
38 ans = strsave(buf);
39 }
40 if (date)
41 free(date);
42 if (time)
43 free(time);
44 return ans;
45}
46
47char *ingres_time(t)
48 long t;
49{
50 struct tm *tm;
51
52 if (t == (long) 0)
53 (void) time(&t);
54
55 if ((tm = localtime(&t)) == (struct tm *) NULL) {
56 return NULL;
57 } else {
58 char buf[BUFSIZ];
59
60 sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
61 tm->tm_sec);
62 return strsave(buf);
63 }
64}
65
66char *ingres_date(t)
67 long t;
68{
69 struct tm *tm;
70
71 if (t == (long) 0)
72 (void) time(&t);
73
74 if ((tm = localtime(&t)) == (struct tm *) NULL) {
75 return NULL;
76 } else {
77 char buf[BUFSIZ];
78
79 sprintf(buf, "%02d-%3.3s-%04d", tm->tm_mday,
80 month_name[tm->tm_mon], 1900 + tm->tm_year);
81 return strsave(buf);
82 }
83}
84
70c18c18 85
86fix_file(targetfile)
87char *targetfile;
88{
89 char oldfile[64], filename[64];
90
91 sprintf(oldfile, "%s.old", targetfile);
92 sprintf(filename, "%s~", targetfile);
93 if (rename(targetfile, oldfile) == 0) {
94 if (rename(filename, targetfile) < 0) {
95 rename(oldfile, targetfile);
96 perror("Unable to install new file (rename failed)\n");
97 fprintf(stderr, "Filename = %s\n", targetfile);
98 exit(SMS_CCONFIG);
99 }
100 } else {
101 if (rename(filename, targetfile) < 0) {
102 perror("Unable to rename old file\n");
103 fprintf(stderr, "Filename = %s\n", targetfile);
104 exit(SMS_CCONFIG);
105 }
106 }
107 unlink(oldfile);
108}
109
110
111char *dequote(s)
112register char *s;
113{
114 char *last = s;
115
116 while (*s) {
117 if (*s == '"')
118 *s = '\'';
119 else if (*s != ' ')
120 last = s;
121 s++;
122 }
1889bd72 123 if (*last == ' ')
124 *last = '\0';
125 else
126 *(++last) = '\0';
70c18c18 127}
This page took 0.130327 seconds and 5 git commands to generate.