]>
Commit | Line | Data |
---|---|---|
d2543f8c | 1 | /* $Header$ |
2 | * | |
3 | * User interface routines for dbck (SMS database consistency checker) | |
4 | * | |
5 | * (c) Copyright 1988 by the Massachusetts Institute of Technology. | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <mit-copyright.h> | |
11 | #include <sms.h> | |
12 | #include <stdio.h> | |
13 | #include "dbck.h" | |
14 | ||
afda48e8 | 15 | static char fix_qc_rcsid[] = "$Header$"; |
16 | ||
d2543f8c | 17 | |
18 | ##char *_table; | |
19 | ##char *_idfield; | |
20 | ||
21 | ##generic_ffunc(id) | |
22 | ##int id; | |
23 | ##{ | |
24 | ## int rowcount; | |
25 | ||
26 | ## delete _table where _table._idfield = id | |
27 | ## inquire_equel(rowcount = "rowcount") | |
28 | if (rowcount > 0) | |
29 | printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); | |
30 | else | |
31 | printf("Not deleted\n"); | |
afda48e8 | 32 | modified(_table); |
d2543f8c | 33 | ##} |
34 | ||
35 | ||
36 | generic_delete(sq, pfunc, table, idfield, preen) | |
37 | struct save_queue *sq; | |
38 | void (*pfunc)(); | |
39 | char *table, *idfield; | |
40 | int preen; | |
41 | { | |
42 | _table = table; | |
43 | _idfield = idfield; | |
44 | generic_fix(sq, pfunc, "Delete", generic_ffunc, preen); | |
45 | } | |
46 | ||
47 | ||
48 | single_delete(table, idfield, id) | |
49 | char *table, *idfield; | |
50 | int id; | |
51 | { | |
52 | _table = table; | |
53 | _idfield = idfield; | |
54 | generic_ffunc(id); | |
55 | } | |
56 | ||
57 | ||
58 | ##zero_fix(table, zrfield, idfield, id) | |
59 | ##char *table, *zrfield, *idfield; | |
60 | ##int id; | |
61 | ##{ | |
62 | ## int rowcount; | |
63 | ||
64 | ## replace table (zrfield = 0) where table.idfield = id | |
65 | ## inquire_equel(rowcount = "rowcount") | |
66 | if (rowcount > 0) | |
67 | printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); | |
68 | else | |
69 | printf("Not fixed\n"); | |
afda48e8 | 70 | modified(table); |
d2543f8c | 71 | ##} |
72 | ||
73 | ||
d2543f8c | 74 | int single_fix(msg, preen) |
75 | char *msg; | |
76 | int preen; | |
77 | { | |
3c76a16c | 78 | if (mode == MODE_PREEN) |
79 | return(preen); | |
d2543f8c | 80 | |
3c76a16c | 81 | switch (mode) { |
d2543f8c | 82 | case MODE_ASK: |
83 | if (!prompt(msg)) | |
84 | break; | |
85 | case MODE_YES: | |
86 | return(1); | |
87 | break; | |
88 | case MODE_NO: | |
89 | ; | |
90 | } | |
91 | return(0); | |
92 | } | |
93 | ||
94 | ||
afda48e8 | 95 | generic_fix(sq, pfunc, msg, ffunc, preen) |
96 | struct save_queue *sq; | |
97 | char *msg; | |
98 | int (*pfunc)(), (*ffunc)(); | |
99 | int preen; | |
100 | { | |
101 | int id; | |
102 | ||
103 | while (sq_get_data(sq, &id)) { | |
104 | if ((*pfunc)(id) == 0 && single_fix(msg, preen)) | |
105 | (*ffunc)(id); | |
106 | } | |
107 | sq_destroy(sq); | |
108 | } | |
109 | ||
110 | ||
d2543f8c | 111 | int prompt(msg) |
112 | char *msg; | |
113 | { | |
114 | char buf[BUFSIZ]; | |
115 | ## extern int dcmenable; | |
116 | ||
117 | while (1) { | |
118 | printf("%s (Y/N/Q)? ", msg); | |
119 | fflush(stdout); | |
120 | gets(buf); | |
121 | if (buf[0] == 'Y' || buf[0] == 'y') | |
122 | return(1); | |
123 | if (buf[0] == 'N' || buf[0] == 'n') | |
124 | return(0); | |
125 | if (buf[0] == 'Q' || buf[0] == 'q') { | |
126 | if (prompt("Are you sure you want to quit")) { | |
127 | if (prompt("Save database changes")) { | |
128 | ## end transaction | |
afda48e8 | 129 | cleanup(); |
d2543f8c | 130 | exit(0); |
131 | } else { | |
afda48e8 | 132 | ## abort |
133 | ## replace values (value = dcmenable) | |
134 | ## where values.name = "dcm_enable" | |
135 | ## exit | |
136 | exit(1); | |
d2543f8c | 137 | } |
138 | } | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | ||
144 | /** | |
145 | ** set_next_object_id - set next object id in values table | |
146 | ** | |
147 | ** Inputs: object - object name in values table and in objects | |
148 | ** table - name of table objects are found in | |
149 | ** | |
150 | ** - called before an APPEND operation to set the next object id to | |
151 | ** be used for the new record to the next free value | |
152 | ** | |
153 | **/ | |
154 | ||
155 | int set_next_object_id(object, table) | |
156 | char *object; | |
157 | char *table; | |
158 | ##{ | |
159 | ## char *name, *tbl; | |
160 | ## int rowcount, exists, value; | |
161 | ||
162 | name = object; | |
163 | tbl = table; | |
164 | ## range of v is values | |
165 | ## repeat retrieve (value = v.#value) where v.#name = @name | |
166 | ## inquire_equel(rowcount = "rowcount") | |
167 | if (rowcount != 1) | |
168 | return(SMS_NO_ID); | |
169 | ||
170 | ## retrieve (exists = any(tbl.name where tbl.name = value)) | |
171 | ## inquire_equel(rowcount = "rowcount") | |
172 | if (rowcount != 1) | |
173 | return(SMS_NO_ID); | |
174 | while (exists) { | |
175 | value++; | |
176 | if (value > MAX_ID_VALUE) | |
177 | value = MIN_ID_VALUE; | |
178 | ## retrieve (exists = any(tbl.name where tbl.name = value)) | |
179 | } | |
180 | ||
afda48e8 | 181 | printf("setting ID %s to %d\n", name, value); |
d2543f8c | 182 | ## repeat replace v (#value = @value) where v.#name = @name |
afda48e8 | 183 | modified("values"); |
d2543f8c | 184 | return(SMS_SUCCESS); |
185 | ##} | |
186 | ||
187 | ||
188 | ##generic_fix_id(table, idfield, txtfield, oldid, name) | |
189 | ##char *table; | |
190 | ##char *idfield; | |
191 | ##char *txtfield; | |
192 | ##int oldid; | |
193 | ##char *name; | |
194 | ##{ | |
195 | ## int rowcount, id; | |
196 | ||
197 | set_next_object_id(table, idfield); | |
198 | ## retrieve (id = values.value) where values.#name = idfield | |
199 | ## replace table (idfield = values.value) where values.#name = idfield and | |
200 | ## table.idfield = oldid and table.txtfield = name | |
201 | ## inquire_equel(rowcount = "rowcount") | |
202 | if (rowcount == 1) | |
203 | printf("Fixed\n"); | |
204 | else | |
205 | printf("Not fixed, rowcount = %d\n", rowcount); | |
afda48e8 | 206 | modified(table); |
d2543f8c | 207 | return(id); |
208 | ##} |