00001 #include <stdlib.h>
00002 #include <string.h>
00003 #include "hdbcontr.h"
00004 #include "galias.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 hdbcontr::hdbcontr()
00015 {
00016 hdbtype = nohdb;
00017 hdbfmtr = hdbfmts = text;
00018 rmold = no;
00019 rmold_id = -1;
00020 hdbnamer[0] = 0;
00021 hdbnames[0] = 0;
00022 selother_r = selother_s = NULL;
00023 selother_id = NULL;
00024 }
00025
00026
00027
00028
00029
00030
00031
00032
00033 hdbcontr::~hdbcontr()
00034 {
00035 delete [] selother_r;
00036 delete [] selother_s;
00037 for (long i=0; i<selelemr.n; i++)
00038 delete [] selother_id[i];
00039 delete [] selother_id;
00040
00041 }
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void hdbcontr::read(XFILE *in)
00055 {
00056 long i,j;
00057
00058 xfscanf (in, "%k%m", "hdbackup", &hdbackuptype_kwdset, (int *)&hdbtype);
00059 if (hdbtype)
00060 {
00061 switch(hdbtype)
00062 {
00063 case hdbr_single:
00064 case hdbr_multiple:
00065
00066 xfscanf(in, "%k%m", "hdbackup_fmtr", &hdbackupfmttype_kwdset, (int *)&hdbfmtr);
00067
00068 xfscanf(in, " %a", hdbnamer);
00069
00070 xfscanf(in, "%k", "elems_saved");
00071 selelemr.read(in);
00072 switch (selelemr.st)
00073 {
00074 case sel_no:
00075 break;
00076 case sel_all:
00077 case sel_range:
00078 case sel_list:
00079 xfscanf(in, "%k", "other_comp");
00080 selother_r = new sel[selelemr.n];
00081 selother_id = new long*[selelemr.n];
00082 memset(selother_id, 0, sizeof(*selother_id)*selelemr.n);
00083 for (i=0; i<selelemr.n; i++)
00084 {
00085 selother_r[i].read(in);
00086 selother_id[i] = new long[selother_r[i].n];
00087 memset(selother_id[i], 0, sizeof(*selother_id[i])*selother_r[i].n);
00088 for (j=0; j<selother_r[i].n; j++)
00089 {
00090 xfscanf(in, "%k%ld", "other_id", selother_id[i]+j);
00091 selother_id[i][j]--;
00092 }
00093 }
00094 break;
00095 default:
00096 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00097 abort();
00098 }
00099 break;
00100 case hdbs_single:
00101 case hdbs_multiple:
00102
00103 xfscanf(in, "%k%m", "hdbackup_fmts", &hdbackupfmttype_kwdset, (int *)&hdbfmts);
00104 xfscanf(in, "%k%m","hdbackup_rm_old", &answertype_kwdset, (int *)&rmold);
00105 if (hdbfmts==text)
00106 xfscanf(in,"%k%ld","precision",&prec);
00107
00108 xfscanf(in, " %a", hdbnames);
00109
00110 xfscanf(in, "%k", "elems_other");
00111 selelems.read(in);
00112 switch (selelems.st)
00113 {
00114 case sel_no:
00115 break;
00116 case sel_all:
00117 case sel_range:
00118 case sel_list:
00119 xfscanf(in, "%k", "other_comp");
00120 selother_s = new sel[selelems.n];
00121 for (i=0; i<selelems.n; i++)
00122 selother_s[i].read(in);
00123 break;
00124 default:
00125 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00126 abort();
00127 }
00128 break;
00129 case hdbrs_single:
00130 case hdbrs_multiple:
00131
00132 xfscanf(in, "%k%m", "hdbackup_fmtr", &hdbackupfmttype_kwdset, (int *)&hdbfmtr);
00133
00134 xfscanf(in, " %a", hdbnamer);
00135
00136 xfscanf(in, "%k", "elems_saved");
00137 selelemr.read(in);
00138 switch (selelemr.st)
00139 {
00140 case sel_no:
00141 break;
00142 case sel_all:
00143 case sel_range:
00144 case sel_list:
00145 xfscanf(in, "%k", "other_comp");
00146 selother_r = new sel[selelemr.n];
00147 selother_id = new long*[selelemr.n];
00148 memset(selother_id, 0, sizeof(*selother_id)*selelemr.n);
00149 for (i=0; i<selelemr.n; i++)
00150 {
00151 selother_r[i].read(in);
00152 selother_id[i] = new long[selother_r[i].n];
00153 memset(selother_id[i], 0, sizeof(*selother_id[i])*selother_r[i].n);
00154 for (j=0; j<selother_r[i].n; j++)
00155 {
00156 xfscanf(in, "%k%ld", "other_id", selother_id[i]+j);
00157 selother_id[i][j]--;
00158 }
00159 }
00160 break;
00161 default:
00162 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00163 abort();
00164 }
00165
00166 xfscanf(in, "%k%m", "hdbackup_fmts", &hdbackupfmttype_kwdset, (int *)&hdbfmts);
00167 xfscanf(in, "%k%m","hdbackup_rm_old", &answertype_kwdset, (int *)&rmold);
00168 if (hdbfmts==text)
00169 xfscanf(in,"%k%ld","precision",&prec);
00170
00171 xfscanf(in, " %a", hdbnames);
00172
00173 xfscanf(in, "%k", "elems_other");
00174 selelems.read(in);
00175 switch (selelems.st)
00176 {
00177 case sel_no:
00178 break;
00179 case sel_all:
00180 case sel_range:
00181 case sel_list:
00182 xfscanf(in, "%k", "other_comp");
00183 selother_s = new sel[selelems.n];
00184 for (i=0; i<selelems.n; i++)
00185 selother_s[i].read(in);
00186 break;
00187 default:
00188 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00189 abort();
00190 }
00191 break;
00192 case hdbr_nonloc:
00193
00194 xfscanf(in, "%k%m", "hdbackup_fmtr", &hdbackupfmttype_kwdset, (int *)&hdbfmtr);
00195
00196 xfscanf(in, " %a", hdbnamer);
00197 break;
00198 case hdbs_nonloc:
00199
00200 xfscanf(in, "%k%m", "hdbackup_fmts", &hdbackupfmttype_kwdset, (int *)&hdbfmts);
00201
00202 xfscanf(in, " %a", hdbnames);
00203 break;
00204 case hdbrs_nonloc:
00205
00206 xfscanf(in, "%k%m", "hdbackup_fmtr", &hdbackupfmttype_kwdset, (int *)&hdbfmtr);
00207
00208 xfscanf(in, " %a", hdbnamer);
00209
00210 xfscanf(in, "%k%m", "hdbackup_fmts", &hdbackupfmttype_kwdset, (int *)&hdbfmts);
00211
00212 xfscanf(in, " %a", hdbnames);
00213 break;
00214 default:
00215 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00216 }
00217 }
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 void hdbcontr::print(FILE *out)
00233 {
00234 long i, j;
00235
00236 fprintf(out, "%d", hdbtype);
00237 switch(hdbtype)
00238 {
00239 case nohdb:
00240 fprintf(out, "\n");
00241 break;
00242 case hdbr_single:
00243 case hdbr_multiple:
00244
00245 fprintf(out, " %d\n", hdbfmtr);
00246
00247 fprintf(out,"%s\n", hdbnamer);
00248
00249 selelemr.print(out);
00250 switch (selelemr.st)
00251 {
00252 case sel_no:
00253 break;
00254 case sel_all:
00255 case sel_range:
00256 case sel_list:
00257 for (i=0; i<selelemr.n; i++)
00258 {
00259 selother_r[i].print(out);
00260 for(j=0; j<selother_r[i].n; j++)
00261 fprintf(out, " %ld\n", selother_id[i][j]);
00262 }
00263 break;
00264 default:
00265 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00266 abort();
00267 }
00268 break;
00269 case hdbs_single:
00270 case hdbs_multiple:
00271
00272 fprintf(out, " %d", hdbfmts);
00273 fprintf(out, " %d", (int)rmold);
00274 if (hdbfmts==text)
00275 fprintf(out, " %ld", prec);
00276 fprintf(out, "\n");
00277
00278 fprintf(out, "%s\n", hdbnames);
00279
00280 selelems.print(out);
00281 switch (selelems.st)
00282 {
00283 case sel_no:
00284 break;
00285 case sel_all:
00286 case sel_range:
00287 case sel_list:
00288 for (i=0; i<selelems.n; i++)
00289 selother_s[i].print(out);
00290 break;
00291 default:
00292 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00293 abort();
00294 }
00295 break;
00296 case hdbrs_single:
00297 case hdbrs_multiple:
00298
00299 fprintf(out, " %d\n", hdbfmtr);
00300
00301 fprintf(out, "%s\n", hdbnamer);
00302
00303 selelemr.print(out);
00304 switch (selelemr.st)
00305 {
00306 case sel_no:
00307 break;
00308 case sel_all:
00309 case sel_range:
00310 case sel_list:
00311 for (i=0; i<selelemr.n; i++)
00312 {
00313 selother_r[i].print(out);
00314 for(j=0; j<selother_r[i].n; j++)
00315 fprintf(out, "%ld\n", selother_id[i][j]);
00316 }
00317 break;
00318 default:
00319 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00320 abort();
00321 }
00322
00323 fprintf(out, " %d", hdbfmts);
00324 fprintf(out, " %d", (int)rmold);
00325 if (hdbfmts==text)
00326 fprintf(out, " %ld", prec);
00327 fprintf(out, "\n");
00328
00329 fprintf(out, "%s\n", hdbnames);
00330
00331 selelems.print(out);
00332 switch (selelems.st)
00333 {
00334 case sel_no:
00335 break;
00336 case sel_all:
00337 case sel_range:
00338 case sel_list:
00339 for (i=0; i<selelems.n; i++)
00340 selother_s[i].print(out);
00341 break;
00342 default:
00343 print_err("unknown type of selection is required", __FILE__, __LINE__, __func__);
00344 abort();
00345 }
00346 break;
00347 case hdbr_nonloc:
00348
00349 fprintf(out, " %d\n", hdbfmtr);
00350
00351 fprintf(out, "%s\n", hdbnamer);
00352 break;
00353 case hdbs_nonloc:
00354
00355 fprintf(out, "%d", hdbfmts);
00356
00357 fprintf(out, "%s\n", hdbnames);
00358 break;
00359 case hdbrs_nonloc:
00360
00361 fprintf(out, " %d\n", hdbfmtr);
00362
00363 fprintf(out, "%s\n", hdbnamer);
00364
00365 fprintf(out, " %d\n", hdbfmts);
00366
00367 fprintf(out, "%s\n", hdbnames);
00368 break;
00369 default:
00370 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00371 }
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 long hdbcontr::restore_stat(void)
00386 {
00387 long ret;
00388
00389 switch(hdbtype)
00390 {
00391 case hdbr_single:
00392 case hdbrs_single:
00393 case hdbr_multiple:
00394 case hdbrs_multiple:
00395 ret=1;
00396 break;
00397 default:
00398 ret=0;
00399 }
00400 return ret;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 long hdbcontr::save_stat(void)
00415 {
00416 long ret;
00417
00418 switch(hdbtype)
00419 {
00420 case hdbs_single:
00421 case hdbrs_single:
00422 case hdbs_multiple:
00423 case hdbrs_multiple:
00424 ret=1;
00425 break;
00426 default:
00427 ret=0;
00428 }
00429 return ret;
00430 }