]> andersk Git - moira.git/blob - gen/util.c
eliminate use of the `register' keyword: let the compiler decide
[moira.git] / gen / util.c
1 /* $Header$
2  *
3  * Utility routines used by the MOIRA extraction programs.
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>.
8  */
9
10
11 #include <mit-copyright.h>
12 #include <stdio.h>
13 #include <sys/time.h>
14 #include <moira.h>
15 #include <moira_site.h>
16
17 extern void sqlglm(char buf[], int *, int *);
18
19 fix_file(char *targetfile)
20 {
21   char oldfile[64], filename[64];
22
23   sprintf(oldfile, "%s.old", targetfile);
24   sprintf(filename, "%s~", targetfile);
25   if (rename(targetfile, oldfile) == 0)
26     {
27       if (rename(filename, targetfile) < 0)
28         {
29           rename(oldfile, targetfile);
30           perror("Unable to install new file (rename failed)\n");
31           fprintf(stderr, "Filename = %s\n", targetfile);
32           exit(MR_CCONFIG);
33         }
34     }
35   else
36     {
37       if (rename(filename, targetfile) < 0)
38         {
39           perror("Unable to rename old file\n");
40           fprintf(stderr, "Filename = %s\n", targetfile);
41           exit(MR_CCONFIG);
42         }
43     }
44   unlink(oldfile);
45 }
46
47
48 char *dequote(char *s)
49 {
50   char *last = s;
51
52   while (*s)
53     {
54       if (*s == '"')
55         *s = '\'';
56       else if (*s != ' ')
57         last = s;
58       s++;
59     }
60   if (*last == ' ')
61     *last = '\0';
62   else
63     *(++last) = '\0';
64   return s;
65 }
66
67
68 db_error(int code)
69 {
70   extern char *whoami;
71   char buf[256];
72   int bufsize = 256, len = 0;
73
74   if (code == -1013)
75     {
76       com_err(whoami, 0, "build cancelled by user");
77       exit(MR_ABORT);
78     }
79
80   com_err(whoami, MR_DBMS_ERR, " code %d\n", code);
81   sqlglm(buf, &bufsize, &len);
82   buf[len] = 0;
83   com_err(whoami, 0, "SQL error text = %s", buf);
84   critical_alert("DCM", "%s build encountered DATABASE ERROR %d\n%s",
85                  whoami, code, buf);
86   exit(MR_DBMS_ERR);
87 }
This page took 0.053106 seconds and 5 git commands to generate.