]> andersk Git - moira.git/blobdiff - gen/util.c
Build shared libmoira via libtool.
[moira.git] / gen / util.c
index 8bbe23900bb0e24bd17a78bbbb96a3527ec88257..607bf8546e5673ce78c5a2cb733fabd19545193c 100644 (file)
-/* $Header$
+/* $Id$
  *
  * Utility routines used by the MOIRA extraction programs.
  *
- *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
- *  For copying and distribution information, please see the file
- *  <mit-copyright.h>.
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-
 #include <mit-copyright.h>
-#include <stdio.h>
-#include <sys/time.h>
 #include <moira.h>
 #include <moira_site.h>
 
+#include <stdio.h>
+#include <unistd.h>
+
+#include "util.h"
 
-fix_file(targetfile)
-char *targetfile;
+RCSID("$Header$");
+
+/* Julian day of the UNIX epoch (January 1, 1970) */
+#define UNIX_EPOCH 2440588
+
+extern void sqlglm(char buf[], int *, int *);
+
+void fix_file(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(MR_CCONFIG);
+  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(MR_CCONFIG);
        }
-    } else {
-       if (rename(filename, targetfile) < 0) {
-           perror("Unable to rename old file\n");
-           fprintf(stderr, "Filename = %s\n", targetfile);
-           exit(MR_CCONFIG);
+    }
+  else
+    {
+      if (rename(filename, targetfile) < 0)
+       {
+         perror("Unable to rename old file\n");
+         fprintf(stderr, "Filename = %s\n", targetfile);
+         exit(MR_CCONFIG);
        }
     }
-    unlink(oldfile);
+  unlink(oldfile);
 }
 
 
-char *dequote(s)
-register char *s;
+char *dequote(char *s)
 {
-    char *last = s;
-
-    while (*s) {
-       if (*s == '"')
-         *s = '\'';
-       else if (*s != ' ')
-         last = s;
-       s++;
+  char *last = s;
+
+  while (*s)
+    {
+      if (*s == '"')
+       *s = '\'';
+      else if (*s != ' ')
+       last = s;
+      s++;
     }
-    if (*last == ' ')
-      *last = '\0';
-    else
-      *(++last) = '\0';
-    return(s);
+  if (*last == ' ')
+    *last = '\0';
+  else
+    *(++last) = '\0';
+  return s;
 }
 
+time_t unixtime(char *timestring)
+{
+  time_t t;
+
+  t = strtol(timestring, &timestring, 10) - UNIX_EPOCH;
+  t = t * 24 + strtol(timestring, &timestring, 10);
+  t = t * 60 + strtol(timestring, &timestring, 10);
+  t = t * 60 + strtol(timestring, &timestring, 10);
 
+  return t;
+}
 
-db_error(code)
-int code;
+void db_error(int code)
 {
-    extern char *whoami;
-
-    com_err(whoami, MR_INGRES_ERR, " code %d\n", code);
-    if (code == -49900 || code == -37000 || code == 17700)
-      exit(MR_DEADLOCK);
-    critical_alert("DCM", "%s build encountered DATABASE ERROR %d",
-                  whoami, code);
-    exit(MR_INGRES_ERR);
+  extern char *whoami;
+  char buf[256];
+  int bufsize = 256, len = 0;
+
+  if (code == -1013)
+    {
+      com_err(whoami, 0, "build cancelled by user");
+      exit(MR_ABORT);
+    }
+
+  com_err(whoami, MR_DBMS_ERR, " code %d\n", code);
+  sqlglm(buf, &bufsize, &len);
+  buf[len] = 0;
+  com_err(whoami, 0, "SQL error text = %s", buf);
+  critical_alert(whoami, "DCM", "%s build encountered DATABASE ERROR %d\n%s",
+                whoami, code, buf);
+  exit(MR_DBMS_ERR);
 }
This page took 0.086493 seconds and 4 git commands to generate.