]> andersk Git - moira.git/commitdiff
Initial revision
authormar <mar>
Mon, 10 Aug 1992 14:17:47 +0000 (14:17 +0000)
committermar <mar>
Mon, 10 Aug 1992 14:17:47 +0000 (14:17 +0000)
backup/dump_db.dc [new file with mode: 0644]
backup/dumprest.dc [new file with mode: 0644]
backup/rest_db.dc [new file with mode: 0644]

diff --git a/backup/dump_db.dc b/backup/dump_db.dc
new file mode 100644 (file)
index 0000000..6dc214a
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ *     $Source$
+ *     $Author$
+ *     $Header$
+ *
+ *     (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.
+ * 
+ */
+
+#ifndef lint
+static char *rcsid_dump_db_c = "$Header$";
+#endif lint
+
+#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");
+       exit(1);
+    }
+    prefix = argv[1];
+
+    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();
+           fprintf(stderr, "control character \\%03o\n", c);
+           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;
+{
+    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);
+}
+
+
+/*
+ * Trim whitespace off both ends of a string.
+ */
+char *strtrim(save)
+    register char *save;
+{
+    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;
+       }
+    }
+    *t = '\0';
+    return s;
+}
diff --git a/backup/dumprest.dc b/backup/dumprest.dc
new file mode 100644 (file)
index 0000000..580836a
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ *     $Source$
+ *     $Author$
+ *     $Header$
+ *
+ *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
+ *
+ */
+
+#ifndef lint
+static char *rcsid_dumprest_qc = "$Header$";
+#endif lint
+
+#include <stdio.h>
+#include <sys/file.h>
+#include <strings.h>
+#include <mit-copyright.h>
+
+punt(msg)
+       char *msg;
+{
+       perror(msg);
+##     exit
+       exit(1);
+}
+
+
+
+
+/*
+ * 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:
+ */
diff --git a/backup/rest_db.dc b/backup/rest_db.dc
new file mode 100644 (file)
index 0000000..21bd707
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ *     $Source$
+ *     $Author$
+ *     $Header$
+ *
+ *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
+ * 
+ */
+
+#ifndef lint
+static char *rcsid_rest_db_qc = "$Header$";
+#endif lint
+
+#include <sys/file.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <mit-copyright.h>
+#include "dump_db.h"
+
+
+/*ARGSUSED*/
+main(argc, argv)
+    int argc;
+    char **argv;
+{
+    char buf[BUFSIZ];
+    char *prefix;
+    
+    if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
+       printf("I didn't think so\n");
+       exit(1);
+    }
+    if (!yes_or_no("Have you initialized an empty database named smstemp?")) {
+       printf("You should have\n");
+       exit(1);
+    }
+    
+    printf("Opening database: ");
+    (void) fflush(stdout);
+##     ingres smstemp
+
+    printf(" done\n");
+
+    printf("Prefix of backup to restore: ");
+    (void) fflush(stdout);
+    if (gets(buf) == NULL) {
+       return 1;
+    }
+    prefix = buf;
+       
+    if (!yes_or_no("Are you SURE?")) {
+       printf("I didn't think so\n");
+       exit(1);
+    }
+    do_restores(prefix);
+    printf("Restore complete\n");
+##     exit
+    exit(0);
+    /*NOTREACHED*/
+}
+
+yes_or_no(prompt)
+    char *prompt;
+{
+    char buf[BUFSIZ];
+    int ret;
+    
+    int tt = open("/dev/tty", O_RDWR, 0);
+    FILE *o, *i;
+    
+    register char *cp;
+    
+    if (tt < 0) return 0;
+    
+    (void) fflush(stdout);
+    (void) fflush(stderr);
+    o = fdopen(dup(tt), "w");    
+    i = fdopen(dup(tt), "r");
+    (void) close(tt);    
+
+    for (;;) {
+       fprintf(o, "%s (yes or no): ", prompt);
+       (void) fflush(o);
+       if (fgets(buf, BUFSIZ, i) == NULL) goto err;
+       for (cp = buf; *cp; cp++) {
+           if (isupper(*cp)) *cp=tolower(*cp);
+       }
+       if (strcmp(buf, "yes\n") == 0) {
+           ret = 1; goto out;
+       }
+       if (strcmp(buf, "no\n") == 0) {
+           ret = 0; goto out;
+       }
+    }
+
+err:
+    ret = 0;
+
+out:
+    (void) fclose(o);
+    (void) fclose(i);
+    return ret;
+}
+
+int parse_int(f)
+    register FILE *f;
+{
+    register int c;
+    register int val = 0;
+    register int sign = 1;
+    while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') {
+       if (c == '-') sign = -1;
+       else if (isdigit(c)) {
+           val *= 10;
+           val += (c - '0');
+       } else (void) fprintf(stderr,"non-digit in numeric field\n");
+    }
+    (void) ungetc(c, f);
+    return(val * sign);
+}
+
+void parse_str(f, buf, len)
+    register FILE *f;
+    register char *buf;
+    register int len;          /* incl trailing NULL */
+{
+    register int c;
+
+    while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len > 0) {
+       if (c == '\\') {
+           c = getc(f);
+           if (isdigit(c)) {
+               /* Expect three-digit octal number.. */
+               register int c1, c2;
+               c1 = getc(f);
+               c2 = getc(f);
+               if (!isdigit(c1) || !isdigit(c2)) 
+                   punt("Broken \\###");
+               /* Convert to ASCII code: */
+               *buf++ =  (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
+           } else if (c == '\\' || c == SEP_CHAR) {
+               *buf++ = c;
+               --len;
+           } else punt ("Broken '\\'");
+       } else {
+           *buf++ = c;
+           --len;
+       }
+    }
+    if (c == EOF)
+       return;
+    
+    if (c != EOF && c != SEP_CHAR && c != '\n') {
+       fprintf(stderr, "Field too wide, truncated\n");
+       while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n');
+       (void) ungetc(c, f);
+    } else {
+       *buf++ = 0;
+       (void) ungetc(c, f);
+    }
+}
+    
+void parse_sep(f)
+    FILE *f;
+{
+    if (getc(f) != SEP_CHAR) punt("Expected Separator");
+}
+void parse_nl(f)
+    FILE *f;
+{
+    if (getc(f) != '\n') punt("Expected newline");
+}
+
+
+FILE *open_file(prefix, suffix)
+    char *prefix, *suffix;
+{
+    char name[BUFSIZ];
+    int fd;
+    FILE *f;
+    
+    (void) strcpy(name, prefix);
+    (void) strcat(name, suffix);
+
+    fd = open(name, O_RDONLY, 0);
+    if (fd < 0) {
+       punt(name);
+    }
+    f = fdopen(fd, "r");
+    if (f == NULL) {
+       fprintf(stderr, "fdopen of ");
+       punt(name);
+    }
+    fprintf(stderr, "Working on %s\n", name);
+    return(f);
+}
This page took 0.438482 seconds and 5 git commands to generate.