]> andersk Git - moira.git/blob - dbck/fix.qc
print message about not attempting to fix error
[moira.git] / dbck / fix.qc
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
15 static char fix_qc_rcsid[] = "$Header$";
16
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");
32     modified(_table);
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");
70     modified(table);
71 ##}
72
73
74 int single_fix(msg, preen)
75 char *msg;
76 int preen;
77 {
78     int lmode;
79
80     lmode = mode;
81     if (mode == MODE_PREEN) {
82         if (preen)
83           lmode = MODE_YES;
84         else
85           lmode = MODE_NO;
86     }
87
88     switch (lmode) {
89     case MODE_ASK:
90         if (!prompt(msg))
91           break;
92     case MODE_YES:
93         return(1);
94         break;
95     case MODE_NO:
96         ;
97     }
98     return(0);
99 }
100
101
102 generic_fix(sq, pfunc, msg, ffunc, preen)
103 struct save_queue *sq;
104 char *msg;
105 int (*pfunc)(), (*ffunc)();
106 int preen;
107 {
108     int id;
109
110     while (sq_get_data(sq, &id)) {
111         if ((*pfunc)(id) == 0 && single_fix(msg, preen))
112           (*ffunc)(id);
113     }
114     sq_destroy(sq);
115 }
116
117
118 int prompt(msg)
119 char *msg;
120 {
121     char buf[BUFSIZ];
122 ##  extern int dcmenable;
123
124     while (1) {
125         printf("%s (Y/N/Q)? ", msg);
126         fflush(stdout);
127         gets(buf);
128         if (buf[0] == 'Y' || buf[0] == 'y')
129           return(1);
130         if (buf[0] == 'N' || buf[0] == 'n')
131           return(0);
132         if (buf[0] == 'Q' || buf[0] == 'q') {
133             if (prompt("Are you sure you want to quit")) {
134                 if (prompt("Save database changes")) {
135 ##                  end transaction
136                     cleanup();
137                     exit(0);
138                 } else {
139 ##                  abort
140 ##                  replace values (value = dcmenable)
141 ##                      where values.name = "dcm_enable"
142 ##                  exit
143                     exit(1);
144                 }
145             }
146         }
147     }
148 }
149
150
151 /**
152  ** set_next_object_id - set next object id in values table
153  **
154  ** Inputs: object - object name in values table and in objects
155  **         table - name of table objects are found in
156  **
157  ** - called before an APPEND operation to set the next object id to
158  **   be used for the new record to the next free value
159  **
160  **/
161
162 int set_next_object_id(object, table)
163     char *object;
164     char *table;
165 ##{
166 ##  char *name, *tbl;
167 ##  int rowcount, exists, value;
168
169     name = object;
170     tbl = table;
171 ##  range of v is values
172 ##  repeat retrieve (value = v.#value) where v.#name = @name
173 ##  inquire_equel(rowcount = "rowcount")
174     if (rowcount != 1)
175         return(SMS_NO_ID);
176
177 ##  retrieve (exists = any(tbl.name where tbl.name = value))
178 ##  inquire_equel(rowcount = "rowcount")
179     if (rowcount != 1)
180         return(SMS_NO_ID);
181     while (exists) {
182         value++;
183         if (value > MAX_ID_VALUE)
184             value = MIN_ID_VALUE;
185 ##      retrieve (exists = any(tbl.name where tbl.name = value))
186     }
187
188     printf("setting ID %s to %d\n", name, value);
189 ##  repeat replace v (#value = @value) where v.#name = @name
190     modified("values");
191     return(SMS_SUCCESS);
192 ##}
193
194
195 ##generic_fix_id(table, idfield, txtfield, oldid, name)
196 ##char *table;
197 ##char *idfield;
198 ##char *txtfield;
199 ##int oldid;
200 ##char *name;
201 ##{
202 ##  int rowcount, id;
203
204     set_next_object_id(table, idfield);
205 ##  retrieve (id = values.value) where values.#name = idfield
206 ##  replace table (idfield = values.value) where values.#name = idfield and
207 ##      table.idfield = oldid and table.txtfield = name
208 ##  inquire_equel(rowcount = "rowcount")
209     if (rowcount == 1)
210       printf("Fixed\n");
211     else
212       printf("Not fixed, rowcount = %d\n", rowcount);
213     modified(table);
214     return(id);
215 ##}
This page took 0.058505 seconds and 5 git commands to generate.