]> andersk Git - moira.git/blame - gen/util.c
Code style cleanup. (No functional changes)
[moira.git] / gen / util.c
CommitLineData
dfb56d6b 1/* $Header$
2 *
2ce085d2 3 * Utility routines used by the MOIRA 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>
2ce085d2 14#include <moira.h>
15#include <moira_site.h>
dfb56d6b 16
9c04b191 17extern void sqlglm(char buf[], int *, int *);
dfb56d6b 18
5eaef520 19fix_file(char *targetfile)
70c18c18 20{
5eaef520 21 char oldfile[64], filename[64];
70c18c18 22
5eaef520 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);
70c18c18 33 }
5eaef520 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);
70c18c18 42 }
43 }
5eaef520 44 unlink(oldfile);
70c18c18 45}
46
47
5eaef520 48char *dequote(register char *s)
70c18c18 49{
5eaef520 50 char *last = s;
70c18c18 51
5eaef520 52 while (*s)
53 {
54 if (*s == '"')
55 *s = '\'';
56 else if (*s != ' ')
57 last = s;
58 s++;
70c18c18 59 }
5eaef520 60 if (*last == ' ')
61 *last = '\0';
62 else
63 *(++last) = '\0';
64 return s;
70c18c18 65}
fff24f1c 66
67
5eaef520 68db_error(int code)
fff24f1c 69{
5eaef520 70 extern char *whoami;
71 char buf[256];
72 int bufsize = 256, len = 0;
b272e93d 73
5eaef520 74 if (code == -1013)
75 {
76 com_err(whoami, 0, "build cancelled by user");
77 exit(MR_ABORT);
f7e4d69e 78 }
79
5eaef520 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);
fff24f1c 87}
This page took 0.093803 seconds and 5 git commands to generate.