]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
dfb56d6b | 2 | * |
2ce085d2 | 3 | * Utility routines used by the MOIRA extraction programs. |
0a5ff702 | 4 | * |
7ac48069 | 5 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
dfb56d6b | 8 | */ |
9 | ||
0a5ff702 | 10 | #include <mit-copyright.h> |
2ce085d2 | 11 | #include <moira.h> |
12 | #include <moira_site.h> | |
dfb56d6b | 13 | |
7ac48069 | 14 | #include <stdio.h> |
15 | #include <unistd.h> | |
16 | ||
17 | #include "util.h" | |
18 | ||
19 | RCSID("$Header$"); | |
20 | ||
a589d269 | 21 | /* Julian day of the UNIX epoch (January 1, 1970) */ |
22 | #define UNIX_EPOCH 2440588 | |
23 | ||
9c04b191 | 24 | extern void sqlglm(char buf[], int *, int *); |
dfb56d6b | 25 | |
7ac48069 | 26 | void fix_file(char *targetfile) |
70c18c18 | 27 | { |
5eaef520 | 28 | char oldfile[64], filename[64]; |
70c18c18 | 29 | |
5eaef520 | 30 | sprintf(oldfile, "%s.old", targetfile); |
31 | sprintf(filename, "%s~", targetfile); | |
32 | if (rename(targetfile, oldfile) == 0) | |
33 | { | |
34 | if (rename(filename, targetfile) < 0) | |
35 | { | |
36 | rename(oldfile, targetfile); | |
37 | perror("Unable to install new file (rename failed)\n"); | |
38 | fprintf(stderr, "Filename = %s\n", targetfile); | |
39 | exit(MR_CCONFIG); | |
70c18c18 | 40 | } |
5eaef520 | 41 | } |
42 | else | |
43 | { | |
44 | if (rename(filename, targetfile) < 0) | |
45 | { | |
46 | perror("Unable to rename old file\n"); | |
47 | fprintf(stderr, "Filename = %s\n", targetfile); | |
48 | exit(MR_CCONFIG); | |
70c18c18 | 49 | } |
50 | } | |
5eaef520 | 51 | unlink(oldfile); |
70c18c18 | 52 | } |
53 | ||
54 | ||
44d12d58 | 55 | char *dequote(char *s) |
70c18c18 | 56 | { |
5eaef520 | 57 | char *last = s; |
70c18c18 | 58 | |
5eaef520 | 59 | while (*s) |
60 | { | |
61 | if (*s == '"') | |
62 | *s = '\''; | |
63 | else if (*s != ' ') | |
64 | last = s; | |
65 | s++; | |
70c18c18 | 66 | } |
5eaef520 | 67 | if (*last == ' ') |
68 | *last = '\0'; | |
69 | else | |
70 | *(++last) = '\0'; | |
71 | return s; | |
70c18c18 | 72 | } |
fff24f1c | 73 | |
a589d269 | 74 | time_t unixtime(char *timestring) |
75 | { | |
76 | time_t t; | |
77 | ||
78 | t = strtol(timestring, ×tring, 10) - UNIX_EPOCH; | |
79 | t = t * 24 + strtol(timestring, ×tring, 10); | |
80 | t = t * 60 + strtol(timestring, ×tring, 10); | |
81 | t = t * 60 + strtol(timestring, ×tring, 10); | |
82 | ||
83 | return t; | |
84 | } | |
fff24f1c | 85 | |
7ac48069 | 86 | void db_error(int code) |
fff24f1c | 87 | { |
5eaef520 | 88 | extern char *whoami; |
89 | char buf[256]; | |
90 | int bufsize = 256, len = 0; | |
b272e93d | 91 | |
5eaef520 | 92 | if (code == -1013) |
93 | { | |
94 | com_err(whoami, 0, "build cancelled by user"); | |
95 | exit(MR_ABORT); | |
f7e4d69e | 96 | } |
97 | ||
5eaef520 | 98 | com_err(whoami, MR_DBMS_ERR, " code %d\n", code); |
99 | sqlglm(buf, &bufsize, &len); | |
100 | buf[len] = 0; | |
101 | com_err(whoami, 0, "SQL error text = %s", buf); | |
a816420b | 102 | critical_alert(whoami, "DCM", "%s build encountered DATABASE ERROR %d\n%s", |
5eaef520 | 103 | whoami, code, buf); |
104 | exit(MR_DBMS_ERR); | |
fff24f1c | 105 | } |