BEGIN { print "/* This file automatically generated */";
print "/* Do not edit */";
print "#include <stdio.h>";
+ print "#include \"dump_db.h\"";
print "/* This file automatically generated */" > "bkup1.qc";
print "/* Do not edit */" >> "bkup1.qc"
+ print "#include <stdio.h>" >> "bkup1.qc"
+ print "FILE *open_file();" >> "bkup1.qc"
print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.qc"
}
printf ")\n"
printf "## {\n"
for (i = 0; i < count; i++) {
- if (i != 0) print "\t\tdump_str(f, \":\");"
+ if (i != 0) print "\t\tdump_sep(f);"
printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]
}
printf "\t\tdump_nl(f);\n"
* 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
+ * Revision 1.2 1987-07-13 03:52:53 wesommer
+ * Modified to pass lint, do better backups.
*
+Revision 1.1 87/07/11 19:51:05 wesommer
+Initial revision
+
*
*/
#include <stdio.h>
#include <sys/file.h>
+#include <ctype.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");
}
prefix = argv[1];
+ bzero(act, 128);
+
+ act[':']=1;
+ act['\\']=1;
+ act[127]=2;
+ for (i=0; i<' '; i++) act[i]=2;
+
## ingres sms
do_backups(prefix);
exit(0);
}
-FILE *open_file(prefix, suffix)
- char *prefix, *suffix;
-{
- char name[BUFSIZ];
- int fd;
- FILE *f;
-
- strcpy(name, prefix);
- 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);
-}
-
dump_int(f, n)
FILE *f;
int n;
{
char buf[1024];
- sprintf(buf, "%d", n);
+ (void) sprintf(buf, "%d", n);
dump_str(f, buf);
}
-dump_nl(f)
+wpunt()
{
- dump_str(f, "\n");
+ punt("can't write backup file");
}
-/*
- * Should check that we're not printing non-printing characters or
- * ':' characters here (??? recovery if we do??)
- */
-
dump_str(f, str)
- FILE *f;
- char *str;
-{
- register int len = strlen(str);
-
- if (fwrite(str, 1, len, f) != len) punt("short write");
-}
-
-
-punt(msg)
- char *msg;
+ register FILE *f;
+ register char *str;
{
- perror(msg);
-## exit
- exit(1);
+ register char *ibp = 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)
punt("Unable to fflush");
if (fsync(fileno(stream)) != 0)
punt("Unable to fsync");
- fclose(stream);
+ (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);
+}
+
/*
* Local Variables:
* mode: c