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