]> andersk Git - moira.git/blobdiff - backup/dump_db.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / backup / dump_db.qc
index 820f9e5e51bde815229d5b3605f22d8f440f3415..b468ca16d3941e2efb5837c50a9a3c381284952b 100644 (file)
@@ -3,16 +3,13 @@
  *     $Author$
  *     $Header$
  *
- *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *     (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 SMS database to a series of output files
  * which can be later read back into SMS in the event of a crash.
  * 
- *     $Log$
- *     Revision 1.1  1987-07-11 19:51:05  wesommer
- *     Initial revision
- *
- *
  */
 
 #ifndef lint
@@ -21,14 +18,26 @@ static char *rcsid_dump_db_c = "$Header$";
 
 #include <stdio.h>
 #include <sys/file.h>
+#include <ctype.h>
+#include <mit-copyright.h>
+#include "dump_db.h"
+
+/* putc without the line buffer hair */
+
+#define putc1(x, p)    (--(p)->_cnt >= 0 ?\
+       (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
+               _flsbuf((unsigned char)(x), p))
 
 FILE *open_file();
 
+char act[128];
+
 main(argc, argv)
     int argc;
     char **argv;
 {
     char *prefix;
+    register int i;
     
     if (argc != 2) {
        fprintf(stderr, "Usage: smsbackup prefix\n");
@@ -36,14 +45,82 @@ main(argc, argv)
     }
     prefix = argv[1];
 
-##  ingres sms 
+    bzero(act, 128);
+
+    act[SEP_CHAR]=1;
+    act['\\']=1;
+    act[127]=2;
+    for (i=0; i<' '; i++) act[i]=2;
     
+##  ingres sms 
+##  set lockmode session where level = table
+##  begin transaction
+
     do_backups(prefix);
-    
+
+##  end transaction    
 ##  exit
     exit(0);
 }
 
+dump_int(f, n)
+    FILE *f;
+    int n;
+{
+    char buf[1024];
+    (void) sprintf(buf, "%d", n);
+    dump_str(f, buf);
+}
+
+wpunt()
+{
+    punt("can't write backup file");
+}
+
+dump_str(f, str)
+    register FILE *f;
+    register char *str;
+{
+    char  *strtrim();
+    register char *ibp = strtrim(str);
+    register int c;            /* PCC doesn't put chars in registers.. */
+    for (; c = *ibp; ibp++) {
+       c = toascii(c);         /* punt 8th bit */
+       switch(act[c]) {
+           register int t;
+       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");
+       }
+    }
+}
+
+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;
 {
@@ -51,8 +128,8 @@ FILE *open_file(prefix, suffix)
     int fd;
     FILE *f;
     
-    strcpy(name, prefix);
-    strcat(name, suffix);
+    (void) strcpy(name, prefix);
+    (void) strcat(name, suffix);
 
     fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
     if (fd < 0) {
@@ -67,60 +144,31 @@ FILE *open_file(prefix, suffix)
     return(f);
 }
 
-dump_int(f, n)
-    FILE *f;
-    int n;
-{
-    char buf[1024];
-    sprintf(buf, "%d", n);
-    dump_str(f, buf);
-}
-
-dump_nl(f)
-{
-    dump_str(f, "\n");
-}
 
 /*
- * Should check that we're not printing non-printing characters or
- * ':' characters here (??? recovery if we do??)
+ * Trim whitespace off both ends of a string.
  */
-
-dump_str(f, str)
-    FILE *f;
-    char *str;
+char *strtrim(save)
+    register char *save;
 {
-    register int len = strlen(str);
-
-    if (fwrite(str, 1, len, f) != len) punt("short write");
-}
-
+    register char *t, *s;
+
+    s = save;
+    while (isspace(*s)) s++;
+    /* skip to end of string */
+    if (*s == '\0') {
+       *save = '\0';
+       return(save);
+    }
 
-punt(msg)
-       char *msg;
-{
-       perror(msg);
-##     exit
-       exit(1);
+    for (t = s; *t; t++) continue; 
+    while (t > s) {
+       --t;
+       if (!isspace(*t)) {
+           t++;
+           break;
+       }
+    }
+    *t = '\0';
+    return s;
 }
-
-safe_close(stream)
-       FILE *stream;
-{
-       if (fflush(stream) == EOF)
-               punt("Unable to fflush");
-       if (fsync(fileno(stream)) != 0) 
-               punt("Unable to fsync");
-       fclose(stream);
-}      
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
This page took 0.058977 seconds and 4 git commands to generate.