]> andersk Git - moira.git/blame - backup/dump_db.qc
Changed /u1/sms/backup to /u1/sms/bin
[moira.git] / backup / dump_db.qc
CommitLineData
6fb7536b 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
8 * This program dumps the SMS database to a series of output files
9 * which can be later read back into SMS in the event of a crash.
10 *
11 * $Log$
d55654f4 12 * Revision 1.2 1987-07-13 03:52:53 wesommer
13 * Modified to pass lint, do better backups.
6fb7536b 14 *
d55654f4 15Revision 1.1 87/07/11 19:51:05 wesommer
16Initial revision
17
6fb7536b 18 *
19 */
20
21#ifndef lint
22static char *rcsid_dump_db_c = "$Header$";
23#endif lint
24
25#include <stdio.h>
26#include <sys/file.h>
d55654f4 27#include <ctype.h>
28
29/* putc without the line buffer hair */
30
31#define putc1(x, p) (--(p)->_cnt >= 0 ?\
32 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
33 _flsbuf((unsigned char)(x), p))
6fb7536b 34
35FILE *open_file();
36
d55654f4 37char act[128];
38
6fb7536b 39main(argc, argv)
40 int argc;
41 char **argv;
42{
43 char *prefix;
d55654f4 44 register int i;
6fb7536b 45
46 if (argc != 2) {
47 fprintf(stderr, "Usage: smsbackup prefix\n");
48 exit(1);
49 }
50 prefix = argv[1];
51
d55654f4 52 bzero(act, 128);
53
54 act[':']=1;
55 act['\\']=1;
56 act[127]=2;
57 for (i=0; i<' '; i++) act[i]=2;
58
6fb7536b 59## ingres sms
60
61 do_backups(prefix);
62
63## exit
64 exit(0);
65}
66
6fb7536b 67dump_int(f, n)
68 FILE *f;
69 int n;
70{
71 char buf[1024];
d55654f4 72 (void) sprintf(buf, "%d", n);
6fb7536b 73 dump_str(f, buf);
74}
75
d55654f4 76wpunt()
6fb7536b 77{
d55654f4 78 punt("can't write backup file");
6fb7536b 79}
80
6fb7536b 81dump_str(f, str)
d55654f4 82 register FILE *f;
83 register char *str;
6fb7536b 84{
d55654f4 85 register char *ibp = str;
86 register int c; /* PCC doesn't put chars in registers.. */
87 for (; c = *ibp; ibp++) {
88 c = toascii(c); /* punt 8th bit */
89 switch(act[c]) {
90 register int t;
91 case 1:
92 if (putc1('\\', f) < 0) wpunt();
93 /* fall thru.. */
94 case 0:
95 if (putc1(c, f) < 0) wpunt();
96
97 break;
98 case 2:
99 if (putc1('\\', f) < 0) wpunt();
100 t = ((c>>6)&7) + '0';
101 if (putc1(t,f) < 0) wpunt();
102 t = ((c>>3)&7) + '0';
103 if (putc1(t,f) < 0) wpunt();
104 t = (c&7) + '0';
105 if (putc1(t,f) < 0) wpunt();
106 fprintf(stderr, "control character \\%03o\n", c);
107 break;
108
109 default:
110 punt("Can't get here");
111 }
112 }
6fb7536b 113}
114
115safe_close(stream)
116 FILE *stream;
117{
118 if (fflush(stream) == EOF)
119 punt("Unable to fflush");
120 if (fsync(fileno(stream)) != 0)
121 punt("Unable to fsync");
d55654f4 122 (void) fclose(stream);
6fb7536b 123}
124
d55654f4 125FILE *open_file(prefix, suffix)
126 char *prefix, *suffix;
127{
128 char name[BUFSIZ];
129 int fd;
130 FILE *f;
131
132 (void) strcpy(name, prefix);
133 (void) strcat(name, suffix);
134
135 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
136 if (fd < 0) {
137 punt(name);
138 }
139 f = fdopen(fd, "w");
140 if (f == NULL) {
141 fprintf(stderr, "fdopen of ");
142 punt(name);
143 }
144 fprintf(stderr, "Working on %s\n", name);
145 return(f);
146}
147
6fb7536b 148/*
149 * Local Variables:
150 * mode: c
151 * c-indent-level: 4
152 * c-continued-statement-offset: 4
153 * c-brace-offset: -4
154 * c-argdecl-indent: 4
155 * c-label-offset: -4
156 * End:
157 */
This page took 0.106445 seconds and 5 git commands to generate.