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