]> andersk Git - moira.git/blobdiff - backup/dump_db.pc
add cleandir/distclean target
[moira.git] / backup / dump_db.pc
index b0dcecbcc24498c77f1de4ac358e2bb96beb8376..fda278e89e2062ba4d0c0f6b0bb364722e5efb17 100644 (file)
-/*
- *     $Source$
- *     $Author$
- *     $Header$
+/* $Id$
  *
- *     (c) Copyright 1988 by the Massachusetts Institute of Technology.
- *     For copying and distribution information, please see the file
- *     <mit-copyright.h>.
+ *     This program dumps the Moira database to a series of output files
+ * which can be later read back into Moira in the event of a crash.
  *
- *     This program dumps the SMS database to a series of output files
- * which can be later read back into SMS in the event of a crash.
- * 
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-#ifndef lint
-static char *rcsid_dump_db_c = "$Header$";
-#endif lint
-
-#include <stdio.h>
-#include <sys/file.h>
-#include <fcntl.h>
-#include <ctype.h>
 #include <mit-copyright.h>
-EXEC SQL INCLUDE sqlca;
+#include <moira.h>
 #include "dump_db.h"
 
-/* putc without the line buffer hair */
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
 
-#define putc1(x, p)    (--(p)->_cnt >= 0 ?\
-       (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
-               _flsbuf((unsigned char)(x), p))
+EXEC SQL INCLUDE sqlca;
 
-FILE *open_file();
+RCSID("$Header$");
 
-char act[257];
 EXEC SQL BEGIN DECLARE SECTION;
-char *db="moira";
+char *db = "moira";
 EXEC SQL END DECLARE SECTION;
 
-main(argc, argv)
-    int argc;
-    char **argv;
+int main(int argc, char **argv)
 {
-    char *prefix;
-    register int i;
-    
-    if (argc != 2) {
-       fprintf(stderr, "Usage: %s prefix\n", argv[0]);
-       exit(1);
-    }
-    prefix = argv[1];
+  char *prefix;
 
-    memset(act, 0, 256);
+  if (argc != 2)
+    {
+      fprintf(stderr, "Usage: %s prefix\n", argv[0]);
+      exit(1);
+    }
+  prefix = argv[1];
 
-    for (i=0; i<' '; i++) act[i]=2;
-    for (i=128; i<256; i++) act[i]=2;
-    act[SEP_CHAR]=1;
-    act['\\']=1;
-    act[127]=2;
-    
-    EXEC SQL CONNECT :db IDENTIFIED BY :db;
+  EXEC SQL CONNECT :db IDENTIFIED BY :db;
 
-    do_backups(prefix);
+  do_backups(prefix);
 
-    EXEC SQL COMMIT;
-    exit(0);
+  EXEC SQL COMMIT;
+  exit(0);
 }
 
-dump_int(f, n)
-    FILE *f;
-    int n;
+void dump_int(FILE *f, int n)
 {
-    char buf[1024];
-    (void) sprintf(buf, "%d", n);
-    dump_str(f, buf);
+  char buf[1024];
+  sprintf(buf, "%d", n);
+  dump_str(f, buf);
 }
 
-wpunt()
+void wpunt(void)
 {
-    punt("can't write backup file");
+  punt("can't write backup file");
 }
 
-dump_str(f, str)
-    register FILE *f;
-    register char *str;
+void dump_str(FILE *f, char *str)
 {
-    register char *ibp;
-    register int c;            /* PCC doesn't put chars in registers.. */
-    register int t;
-
-    for (ibp = str; c = (unsigned char) *ibp; ibp++) {
-       switch(act[c]) {
-       case 1:
-           if (putc1('\\', f) < 0) wpunt();
-           /* fall thru.. */
-       case 0:
-           if (putc1(c, f) < 0) wpunt();
-           
-           break;
-       case 2:
-           if (putc1('\\', f) < 0) wpunt();        
-           t = ((c>>6)&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           t = ((c>>3)&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           t = (c&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           break;
-           
-       default:
-           punt("Can't get here");
+  unsigned char *ibp, c;
+  int t;
+
+  for (ibp = str; (c = *ibp); ibp++)
+    {
+      if (c < 32 || c > 126 || c == SEP_CHAR || c == '\\')
+       {
+         if (putc('\\', f) < 0)
+           wpunt();
+         t = ((c >> 6) & 7) + '0';
+         if (putc(t, f) < 0)
+           wpunt();
+         t = ((c >> 3) & 7) + '0';
+         if (putc(t, f) < 0)
+           wpunt();
+         t = (c & 7) + '0';
+         if (putc(t, f) < 0)
+           wpunt();
        }
-    }
-}
-
-dump_bin(f, str)
-    register FILE *f;
-    register char *str;
-{
-    register char *ibp = str;
-    register int c;            /* PCC doesn't put chars in registers.. */
-    register int t;
-
-    for (; c = (unsigned char) *ibp; ibp++) {
-       switch(act[c]) {
-       case 1:
-           if (putc1('\\', f) < 0) wpunt();
-           /* fall thru.. */
-       case 0:
-           if (putc1(c, f) < 0) wpunt();
-           
-           break;
-       case 2:
-           if (putc1('\\', f) < 0) wpunt();        
-           t = ((c>>6)&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           t = ((c>>3)&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           t = (c&7) + '0';
-           if (putc1(t,f) < 0) wpunt();
-           break;
-           
-       default:
-           punt("Can't get here");
+      else
+       {
+         if (putc(c, f) < 0)
+           wpunt();
        }
     }
 }
 
-safe_close(stream)
-       FILE *stream;
-{
-       if (fflush(stream) == EOF)
-               punt("Unable to fflush");
-       if (fsync(fileno(stream)) != 0) 
-               punt("Unable to fsync");
-       (void) fclose(stream);
-}      
-
-FILE *open_file(prefix, suffix)
-    char *prefix, *suffix;
+void safe_close(FILE *stream)
 {
-    char name[BUFSIZ];
-    int fd;
-    FILE *f;
-    
-    (void) strcpy(name, prefix);
-    (void) strcat(name, suffix);
-
-    fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
-    if (fd < 0) {
-       punt(name);
-    }
-    f = fdopen(fd, "w");
-    if (f == NULL) {
-       fprintf(stderr, "fdopen of ");
-       punt(name);
-    }
-    fprintf(stderr, "Working on %s\n", name);
-    return(f);
+  if (fflush(stream) == EOF)
+    punt("Unable to fflush");
+  if (fsync(fileno(stream)) != 0)
+    punt("Unable to fsync");
+  fclose(stream);
 }
 
-
-/*
- * Trim whitespace off both ends of a string.
- */
-char *strtrim(save)
-    register char *save;
+FILE *open_file(char *prefix, char *suffix)
 {
-    register char *t, *s;
-
-    s = save;
-    while (isspace(*s)) s++;
-    /* skip to end of string */
-    if (*s == '\0') {
-       *save = '\0';
-       return(save);
-    }
-
-    for (t = s; *t; t++) continue; 
-    while (t > s) {
-       --t;
-       if (!isspace(*t)) {
-           t++;
-           break;
-       }
+  char name[BUFSIZ];
+  int fd;
+  FILE *f;
+
+  strcpy(name, prefix);
+  strcat(name, suffix);
+
+  fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
+  if (fd < 0)
+    punt(name);
+  f = fdopen(fd, "w");
+  if (!f)
+    {
+      fprintf(stderr, "fdopen of ");
+      punt(name);
     }
-    *t = '\0';
-    return s;
+  fprintf(stderr, "Working on %s\n", name);
+  return f;
 }
This page took 0.043477 seconds and 4 git commands to generate.