Debian Codegraph @

w4/dump.c

raw
1 /* File: dump.c
2 * Author: Jean Thierry-Mieg ([email protected])
3 * Copyright (C) J Thierry-Mieg and R Durbin, 1992
4 * -------------------------------------------------------------------
5 * Acedb is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
19 * -------------------------------------------------------------------
20 * This file is part of the ACEDB genome database package, written by
21 * Richard Durbin (MRC LMB, UK) [email protected], and
22 * Jean Thierry-Mieg (CRBM du CNRS, France) [email protected]
23 *
24 * Description:
25 * Exported functions:
26 * HISTORY:
27 * Last edited: Oct 20 08:47 2006 (edgrif)
28 * * Apr 20 16:18 1999 (edgrif): Remove dump window if user aborts.
29 * * Aug 18 10:00 1998 (rd):
30 * - split dumpPossible() into lexIsKeyVisible() and dumpClassPossible
31 * - remove dumpKey1() as unnecessary
32 * * Aug 3 11:29 1998 (rd):
33 * - user can dump to any directory. Also changed the error format for
34 * - errors form dump to class \t name \t error mess.
35 * * Apr 3 16:18 1997 (rd)
36 * * Jun 21 17:05 1992 (mieg): arranged so the dump file can be read back
37 * Created: Sun Feb 16 01:31:41 1992 (mieg)
38 * CVS info: $Id: dump.c,v 1.77 2006/10/20 08:12:49 edgrif Exp $
39 *-------------------------------------------------------------------
40 */
41
42 #include <setjmp.h>
43 #include <wh/acedb.h>
44 #include <wh/aceio.h>
45 #include <wh/dbpath.h>
46 #include <wh/lex.h>
47 #include <wh/a.h>
48 #include <wh/bs.h>
49 #include <wh/dump.h>
50 #include <wh/pick.h>
51 #include <wh/session.h>
52 #include <wh/query.h>
53 #include <whooks/sysclass.h>
54 #include <whooks/classes.h>
55 #include <wh/java.h>
56
57 #ifndef NON_GRAPHIC
58 #include <wh/graph.h>
59 #include <wh/display.h>
60 #endif
61
62
63
64 /******************************************************************/
65 /****************** globals used elsewhere ************************/
66 /******************************************************************/
67
68 DumpFuncType dumpFunc[256] ;
69
70
71 static BOOL dumpKey2(ACEOUT dump_out, KEY key, char style, COND cond) ;
72
73
74 /****************** internal globals ******************************/
75
76 /* Naming patterns for dump files, used to contruct dump file names, if the */
77 /* dump is of a single class then the classname is included in the filename. */
78 /* The regex's could be made more exact but these are probably good enough. */
79 /* */
80 #define DUMPNAME "%sdump_%s_%c.%d"
81 #define DUMPNAME_CLASS "%sdump_%s_%c_%s.%d"
82 #define DUMPNAME_REGEXP "dump_*_*.1.ace"
83 #define DUMPALLNAME_REGEXP "dump_*_*.*.ace"
84
85
86 /* Dump size limits in terms of objects or bytes. */
87 /* lower bound. Most systems limit files to 2GB, hence this is 1 GB */
88 #define MAX_OBJECTS_IN_DUMP 20000
89 #define MAX_BYTES_IN_DUMP 100000000L
90
91
92
93 static Array doNotDumpKeySet = NULL ;
94
95 static char dumpDir[DIR_BUFFER_SIZE] = ""; /* use this to choose where to dump too */
96 static BOOL dumpSetDirectory (void);
97
98 static Array trapKeys = NULL, trapMessages = NULL ;
99
100 #ifndef NON_GRAPHIC
101
102 static MENUOPT dumpMenu[]=
103 {
104 { graphDestroy,"Quit"},
105 { help,"Help"},
106 { 0,0}
107 };
108
109 static Graph dumpGraph = 0;
110
111 #endif /* NON_GRAPHIC */
112
113
114
115 /*********************************************/
116 /************* public routine ****************/
117 /*********************************************/
118
119
120
121 /* Small utility useful for debugging, you just insert dumpObj() calls were you need to see them,
122 * obj is dumped to stdout. */
123 void dumpObj(OBJ obj)
124 {
125 ACEOUT std_out ;
126
127 std_out = aceOutCreateToStdout(0) ;
128
129 dumpKeyBeautifully(std_out, bsKey(obj), 'h', 0) ;
130
131 aceOutDestroy(std_out) ;
132
133 return ;
134 }
135
136
137
138 /* RD 980817: split dumpPossible() into dumpKeyPossible() and
139 dumpClassPossible(). I want dumpKeyPossible to be used for all key
140 listing, e.g. in keysetdisplay, list and show commands in tace.
141 dumpClassPossible will be used by the complete dump code.
142
143 NB I allow protected classes (including XREF and Model classes) to
144 be seen by dumpKeyPossible(), so we can see them in keysets and
145 display them, and also list and show them from tace. But they
146 still fail dumpClassPossible() so will not be in full dumps. This
147 is a change. Is that OK?
148
149 RD 980819: dumpKeyPossible() is the same as lexIsKeyVisible(), not
150 surprisingly, so I supressed it.
151 */
152
153 BOOL dumpClassPossible (int classe, char style)
154 {
155 classe &= 0xff ;
156
157 if (pickList[classe].type == 'A')
158 return dumpFunc[classe] ? TRUE : FALSE ;
159
160 if (pickList[classe].private) /* private to kernel, nobody's business */
161 return FALSE ;
162
163 /* protected classes can not be parsed, so can't be dumped in ace style
164 * XREF classed are created on the fly by the kernel
165 */
166 if ((style == 'a' || style == 'A' || style == 0) &&
167 ( pickXref(classe) || pickList[classe].protected))
168 return FALSE ;
169
170 if (!lexMaxVisible(classe))
171 return FALSE ;
172
173 if (classe == _VUserSession && !dumpTimeStamps)
174 /* the UserSession objects are meaningless
175 * without timestamps */
176 return FALSE;
177
178 return TRUE ;
179 } /* dumpClassPossible */
180
181 /*********************************************************/
182
183 BOOL dumpKeyBeautifully (ACEOUT dump_out, KEY key, char style, COND cond)
184 {
185 return dumpKey2 (dump_out, key, style, cond) ;
186 }
187
188 /*********************************************************/
189
190 BOOL dumpKey (ACEOUT dump_out, KEY key)
191 {
192 return dumpKey2 (dump_out, key, 0, 0) ;
193 }
194
195
196 /*************** Internal routines ***********************/
197
198 static BOOL dumpKey2 (ACEOUT dump_out, KEY key, char style, COND cond)
199 {
200 OBJ obj ;
201 int classe = 0, oldc = 0 ;
202 BOOL notEmpty = FALSE ;
203
204 if (doNotDumpKeySet && keySetFind (doNotDumpKeySet, key, 0))
205 return FALSE ;
206
207 if (!lexIsKeyVisible (key))
208 return FALSE ;
209
210 /* test for tag now, to avoid writing an object name line.
211 cond is a compiled query built in the calling routine
212 queryFind3 uses bIndexFind() and only makes obj if necessary
213 */
214 obj = 0 ;
215 if (cond && !queryFind3 (cond, &obj, key))
216 { if (obj) bsDestroy (obj) ;
217 return FALSE ;
218 }
219
220 if (pickType(key) == 'A' && !(style == 'j' || style == 'J' || style == 'k' || style == 'K' || style == 'C'))
221 style = 0 ; /* can only dump arrays in .ace and java and AceC */
222
223 /* write object name line for .ace files */
224 if (style == 0 || style == 'a' || style == 'A')
225 {
226 char *tsPref="", *tsVal="", *tsPost="";
227
228 if (dumpTimeStamps && lexCreationUserSession(key))
229 {
230 tsPref = " -O \"";
231 tsPost = "\"";
232 tsVal = name(lexCreationUserSession(key));
233 }
234 notEmpty = TRUE ;
235
236 aceOutPrint (dump_out, "%s : %s%s%s%s\n",
237 className(key), freeprotect (name(key)),
238 tsPref, tsVal, tsPost) ;
239 }
240
241 switch (pickType (key))
242 {
243 case 'A':
244 switch (style)
245 {
246 case 'C':
247 {
248 classe = class(key) ;
249 notEmpty = TRUE ;
250 if (iskey(key) == 2)
251 {
252 if (classe == _VDNA)
253 { dnaDumpKeyCstyle (dump_out, key); }
254 else if (classe == _VPeptide)
255 { peptideDumpKeyCstyle (dump_out, key); }
256 }
257 else
258 {
259 char buf[2] ;
260 char *cp = name(key) ;
261
262 buf[0] = 'n' ; buf[0] = class(key) ; /* bug? */
263 aceOutBinary( dump_out, buf, 2 );
264 aceOutBinary( dump_out, cp, strlen(cp)+1);
265 buf[0] = '#' ;
266 aceOutBinary( dump_out, buf, 1 );
267 }
268 break ;
269 }
270 case 'j': case 'J': /* java dumping */
271 case 'k': case 'K': /* fixed up 'java' dumping for AcePerl */
272 classe = class(key) ;
273 if (iskey(key) == 2)
274 {
275 if (classe == _VDNA)
276 { javaDumpDNA (dump_out, key); }
277 else if (classe == _VPeptide)
278 { javaDumpPeptide (dump_out, key); }
279 else if (classe == _VKeySet)
280 { notEmpty = TRUE ; javaDumpKeySet (dump_out, key); }
281 else if (classe == _VLongText)
282 { notEmpty = TRUE ; javaDumpLongText (dump_out, key); }
283 }
284 else
285 switch (style)
286 {
287 case 'j': case 'k':
288 notEmpty = TRUE ;
289 aceOutPrint (dump_out, "?%s?%s?\n", className(key),
290 freejavaprotect(name(key))) ;
291 break ;
292 case 'J': case 'K':
293 notEmpty = TRUE ;
294 if (oldc != classe)
295 {
296 oldc = classe ;
297 aceOutPrint (dump_out, "?%s", className (key)) ;
298 }
299 else
300 aceOutPrint (dump_out, "#", className (key)) ;
301 if (iskey(key)==2)
302 aceOutPrint (dump_out, "?%s?\n",
303 freejavaprotect(name(key))) ;
304 else
305 aceOutPrint (dump_out, "!%s?\n",
306 freejavaprotect(name(key))) ;
307 default:
308 break ;
309 }
310 break ;
311 default:
312 if (dumpFunc[class(key)])
313 {
314 if (iskey (key)==2)
315 notEmpty = TRUE ;
316 dumpFunc[class(key)] (dump_out, key) ;
317 }
318 break ;
319 }
320 break ;
321 case 'B':
322 if (obj || (obj = bsCreate (key)))
323 {
324 notEmpty = TRUE ;
325 switch (style)
326 {
327 case 0: case 'a': case 'A': /* ace format */
328 if (class(key) == _VModel)
329 {
330 aceOutPrint (dump_out, "// a model can not be dumped in .ace format\n") ;
331 }
332 else
333 bsAceDump (obj, dump_out, (cond != 0) ? TRUE : FALSE) ;
334 break ;
335 default:
336 niceDump (dump_out, obj, style) ;
337 break ;
338 }
339 }
340 else
341 switch (style)
342 {
343 case 'j': case 'k':
344 notEmpty = TRUE ;
345 aceOutPrint (dump_out, "?%s?%s?\n",className(key),
346 freejavaprotect(name(key))) ;
347 break ;
348
349 case 'J': case 'K':
350 notEmpty = TRUE ;
351 if (oldc != classe)
352 {
353 oldc = classe ;
354 aceOutPrint (dump_out, "?%s", className (key)) ;
355 }
356 else
357 aceOutPrint (dump_out, "#", className (key)) ; /* RD 000615 - what is className(key) here for? */
358 if (iskey(key)==2)
359 aceOutPrint (dump_out, "?%s?\n",
360 freejavaprotect(name(key))) ;
361 else
362 aceOutPrint (dump_out, "!%s?\n",
363 freejavaprotect(name(key))) ;
364 break;
365
366 case 'C':
367 notEmpty = TRUE ;
368 {
369 char buf[2] ;
370 char *cp = name(key) ;
371
372 buf[0] = 'n' ; buf[1] = class(key) ;
373 aceOutBinary( dump_out, buf, 2) ;
374 aceOutBinary( dump_out, cp, strlen(cp) + 1) ;
375 buf[0] = '\n' ;
376 buf[1] = '#' ;
377 aceOutBinary ( dump_out, buf,2) ;
378 }
379 break ;
380
381 case 'p':
382 notEmpty = TRUE ;
383 /* hack to get an OBJ struct from an empty object,
384 * so we can use the routines in nicedump to output
385 * the obj-name in perl-style with correct quote-marks */
386 obj = bsUpdate (key);
387 niceDump (dump_out, obj, style);
388 break;
389
390 default:
391 break ;
392 }
393 break ;
394 }
395 if (obj) bsDestroy (obj) ;
396
397 /* always leave a blank line after dumped object */
398 if (notEmpty)
399 {
400 aceOutPrint (dump_out, "\n") ;
401 }
402
403 return TRUE ;
404 } /* dumpKey2 */
405
406
407 /*********************************************/
408 /*********************************************/
409
410
411 static KEY dumpClass (ACEOUT dump_out, KEY k, int t, int *nk, int *no, int *ne)
412 {
413 jmp_buf jmpBuf ;
414 static jmp_buf *oldJmpBuf ; /* static to avoid volatile problems */
415 /* NB following must be volatile to ensure there when jump back */
416 volatile KEY kVolatile = 0 ;
417 long int filepos;
418
419 *nk = *no = *ne = 0 ;
420
421 while (lexNext(t,&k))
422 { (*nk)++ ;
423
424 kVolatile = k ;
425 if (!setjmp (jmpBuf))
426 {
427 oldJmpBuf = messCatchCrash (&jmpBuf) ;
428 if (dumpKey2 (dump_out, k, 0, 0))
429 (*no)++ ;
430 }
431 else /* an error caught in messCrash() */
432 {
433 if (!trapKeys)
434 {
435 trapKeys = arrayCreate(32,KEY);
436 trapMessages = arrayCreate(32,char*);
437 }
438 (*ne)++ ;
439 array(trapKeys,arrayMax(trapKeys),KEY) = kVolatile ;
440 array(trapMessages,arrayMax(trapMessages),char*) = strnew (messCaughtMessage(), 0) ;
441 }
442
443 messCatchCrash (oldJmpBuf) ; /* restore value for enclosing function */
444
445 if (!aceOutStreamPos (dump_out, &filepos))
446 filepos = 0; /* so second cond. below won't fail */
447
448 if ((*no > MAX_OBJECTS_IN_DUMP) || (filepos > MAX_BYTES_IN_DUMP))
449 return k;
450 }
451
452 return 0;
453 } /* dumpClass */
454
455 /******************************************/
456 #ifndef NON_GRAPHIC
457
458 static void dumpDestroy(void)
459 {
460 dumpGraph = 0 ;
461 }
462
463 #endif /* NON_GRAPHIC */
464 /******************************************/
465
466 static ACEOUT dumpOpenOutput(BOOL newDump, char *classname, int nn)
467 {
468 static char letter ;
469 static char date[12] ;
470 char name[DIR_BUFFER_SIZE+FIL_BUFFER_SIZE] ;
471 ACEOUT dump_out;
472
473 if (newDump)
474 {
475 letter = 'A' ;
476 strcpy (date, timeShow (timeParse ("today"))) ;
477
478 if (classname)
479 sprintf (name, DUMPNAME_CLASS, dumpDir, date, letter, classname, nn) ;
480 else
481 sprintf (name, DUMPNAME, dumpDir, date, letter, nn) ;
482 while (filCheckName (name, "ace", "r"))
483 {
484 ++letter ;
485 if (classname)
486 sprintf (name, DUMPNAME_CLASS, dumpDir, date, letter, classname, nn) ;
487 else
488 sprintf (name, DUMPNAME, dumpDir, date, letter, nn) ;
489 }
490 }
491 else
492 if (classname)
493 sprintf (name, DUMPNAME_CLASS, dumpDir, date, letter, classname, nn) ;
494 else
495 sprintf (name, DUMPNAME, dumpDir, date, letter, nn);
496
497 strcat (name, ".ace");
498
499
500 #ifdef NON_GRAPHIC
501
502 if (!(dump_out = aceOutCreateToFile(name, "w", 0)))
503 messout ("Dump could not open the output file.");
504
505 #else /* !NON_GRAPHIC */
506
507 if (!(dump_out = aceOutCreateToFile(name, "w", 0)))
508 graphText ("Dump could not open the output file.", 5, 5) ;
509 else
510 if (newDump && !classname)
511 graphText (messprintf ("Ready to dump into : %s", name), 2, 3) ;
512 graphRedraw () ;
513
514 #endif /* !NON_GRAPHIC */
515
516 return dump_out ;
517 } /* dumpOpenOutput */
518
519 /********************************************/
520
521 static void dump1Check (void)
522 {
523 #ifndef NON_GRAPHIC
524 static char directory[DIR_BUFFER_SIZE] = "";
525 static char filename[FIL_BUFFER_SIZE] = "parse_log";
526 #endif
527 ACEOUT err_out = NULL;
528 int i;
529
530 if (trapKeys)
531 {
532 messout ("%d errors occurred during dump", arrayMax(trapKeys)) ;
533 messdump ("DUMP ERROR: %d errors on dumping\n", arrayMax(trapKeys)) ;
534 #ifndef NON_GRAPHIC
535 strcpy (directory, dumpDir);
536
537 err_out =
538 aceOutCreateToChooser ("Choose file to dump the errors to",
539 directory, filename, "err", "w", 0);
540 if (!err_out)
541 messout ("Writing errors to logfile (database/log.wrm)") ;
542 else
543 aceOutPrint (err_out, "%d errors on dumping\n",
544 arrayMax(trapKeys)) ;
545 #endif
546
547 for (i = 0 ; i < arrayMax(trapKeys) ; i++)
548 {
549 if (err_out)
550 aceOutPrint (err_out, "%s\t%s\t%s\n",
551 className(arr(trapKeys,i,KEY)),
552 name(arr(trapKeys,i,KEY)),
553 arr(trapMessages, i, char*)) ;
554 else
555 messdump ("%s\t%s\t%s\n",
556 className(arr(trapKeys,i,KEY)),
557 name(arr(trapKeys,i,KEY)),
558 arr(trapMessages, i, char*)) ;
559
560 messfree (arr(trapMessages, i, char*)) ;
561 }
562
563 #ifdef NON_GRAPHIC
564 messout ("Errors written to logfile (database/log.wrm)");
565 #endif
566
567 arrayDestroy (trapKeys) ;
568 arrayDestroy (trapMessages) ;
569
570 if (err_out)
571 aceOutDestroy (err_out);
572 }
573
574 return;
575 } /* dump1Check */
576
577
578 /* Menu function, called from main window menus. */
579 /* */
580 /* Dump the whole database giving the user various options. */
581 /* */
582 void dumpAll (void)
583 {
584 dumpTimeStamps = messQuery ("Do you want to dump timestamps?") ;
585 dumpComments = messQuery ("Do you want to dump comments?") ;
586
587 if (dumpSetDirectory())
588 dumpAllNonInteractive (0, FALSE) ;
589
590 return ;
591 }
592
593
594 /* Menu function, called from main window menus. */
595 /* */
596 /* Allows user to choose which dump set they want to read in and then calls */
597 /* the general routine to do the reading in. */
598 /* */
599 void dumpReadAll(void)
600 {
601 BOOL status = TRUE ;
602 char dirSelection[DIR_BUFFER_SIZE] = "" ;
603 char fileSelection[FIL_BUFFER_SIZE] = "" ;
604 ACEIN parse_in = NULL ;
605
606 if (!sessionGainWriteAccess())
607 {
608 messerror ("Sorry, cannot get write access !");
609 status = FALSE ;
610 }
611
612 if (status)
613 {
614 if (!getcwd(dirSelection, DIR_BUFFER_SIZE))
615 {
616 char *dirname = NULL ;
617
618 messerror("Unable to retrieve current working directory, "
619 "using database directory instead.") ;
620
621 dirname = dbPathMakeFilName("", "", "", 0) ;
622 if (!strcpy(dirSelection, dirname))
623 messcrash("Serious internal error, unable to find database directory.") ;
624
625 messfree(dirname) ;
626 }
627 }
628
629 if (status)
630 {
631 /* Display only ace dump filenames in the file chooser. */
632 strcpy(fileSelection, DUMPALLNAME_REGEXP) ;
633 parse_in = aceInCreateFromChooser("Choose file \"" DUMPNAME_REGEXP "\" of the dump",
634 dirSelection, fileSelection,
635 "ace", "r", 0) ;
636 if (parse_in)
637 {
638 Stack s = NULL ;
639 ACEOUT result_out = NULL ;
640
641 s = stackCreate(30) ;
642 stackTextOnly(s) ;
643 result_out = aceOutCreateToStack(s, 0) ;
644
645 status = dumpDoReadAll(parse_in, result_out, TRUE, dirSelection, fileSelection) ;
646
647 if (!status)
648 messerror("%s", popText(s)) ;
649 else
650 messout("%s", popText(s)) ;
651
652 aceOutDestroy(result_out) ;
653 stackDestroy(s) ;
654 }
655 else
656 {
657 /* Currently there's nothing to do here. */
658 /* Either user clicked CANCEL, or there was an error which will */
659 /* already have been reported. */
660 }
661 }
662
663 return ;
664 }
665
666
667 /* General function to read in a set of dumps. */
668 /* */
669 /* Read in a database dump. The dump may be split across a set of files */
670 /* which have will have the naming convention: */
671 /* */
672 /* dump_<date>_<dump-id>(_<classname>).<dump-file-num>.ace */
673 /* */
674 /* e.g. dump_2001-09-05_A.1.ace */
675 /* or dump_2001-09-05_A_Sequence.1.ace */
676 /* */
677 /* so dump-id is a letter identifying a particular dump and dump-file-num */
678 /* is a digit identifying a particular file within that dump and this */
679 /* may be optionally followed by a classname to show that dumps only */
680 /* contain that class. */
681 /* */
682 /* Returns TRUE if all files in a database dump were successfully read in, */
683 /* FALSE otherwise (e.g. when perhaps only some files could be read in). */
684 /* */
685 /* NOTE: the code is of course very sensitive to the above format, if you */
686 /* change it you will almost certainly have to change the code (e.g. the bit */
687 /* that finds the dump prefix). */
688 /* */
689 /* UUUUGGGGHHHH, I'm not happy about the "interactive" flag, the routine */
690 /* could be rewritten to avoid this by providing a separate routine to */
691 /* create the dump pattern which would only be called for interactive */
692 /* apps... */
693 BOOL dumpDoReadAll(ACEIN parse_in, ACEOUT result_out, BOOL interactive,
694 char *dirSelection, char *fileSelection)
695 {
696 BOOL status = TRUE ;
697 char dump_prefix[FIL_BUFFER_SIZE] = "" ;
698 char *dump_name = NULL ;
699 BOOL dump_stats = FALSE ;
700 Stack s = NULL ;
701 ACEOUT parse_out = NULL ;
702 #define DUMP_ERR "Aborting dump reading:"
703
704 if (!parse_in)
705 messcrash("acein argument to dumpDoReadAll() is NULL.") ;
706
707 if (!result_out)
708 messcrash("aceout argument to dumpDoReadAll() is NULL.") ;
709
710 if (!dirSelection)
711 dirSelection = "." ;
712
713 if (!fileSelection)
714 messcrash("filename argument to dumpDoReadAll() is NULL.") ;
715
716 if (!isWriteAccess())
717 {
718 if (!sessionGainWriteAccess())
719 {
720 aceOutPrint(result_out, "Sorry, cannot get write access !") ;
721 status = FALSE ;
722 }
723 }
724
725 if (status)
726 {
727 /* Check the selected name to see if it fits the format for the first */
728 /* of a set of dump files. */
729 if (regExpMatch(fileSelection, DUMPNAME_REGEXP) != 1)
730 {
731 aceOutPrint(result_out, "Sorry, the name of the file you chose (%s)"
732 " is not the right format for the first file of an ace dump"
733 " i.e. it must be of the pattern \"" DUMPNAME_REGEXP "\".",
734 fileSelection) ;
735 status = FALSE ;
736 }
737 else
738 {
739 /* Get hold of the first part of the dump file name so we can use */
740 /* it look for further dump files. */
741 int bytes = 0 ;
742 char *dump_num_ptr = NULL ;
743
744 dump_num_ptr = strrchr(fileSelection, '1') ;
745 bytes = dump_num_ptr - &fileSelection[0] ;
746 memcpy(dump_prefix, fileSelection, bytes) ;
747 dump_prefix[bytes + 1] = '\0' ; /* paranoia */
748 }
749 }
750
751
752 /* As this is potentially a very time consuming process, give the user a */
753 /* chance to abort, but only if we running interactively. */
754 if (status && interactive)
755 {
756 /* should this be for interactive stuff only ???? */
757 if (!messQuery("Dumpset \"%s*.ace\" will be read in,"
758 " do you want to proceed", dump_prefix))
759 status = FALSE ;
760 }
761
762 /* Loop round reading all the dump files for one database dump. Each time */
763 /* we collect up the parsing stats for that dump file. */
764 if (status)
765 {
766 BOOL file_found = TRUE, file_parsed = TRUE ;
767 int dump_num = 1 ;
768
769 dump_name = hprintf(0, "%s/%s", dirSelection, fileSelection) ;
770
771
772 s = stackCreate(30) ;
773 stackTextOnly(s) ;
774 parse_out = aceOutCreateToStack(s, 0) ;
775
776 if (aceOutPrint(parse_out, "Parse Stats for dumpset \"%s*.ace\"\n",
777 dump_prefix) != ESUCCESS)
778 messcrash("Unable to write to output stack for dump parse messages") ;
779
780 while (file_found && file_parsed)
781 {
782 if (aceOutPrint(parse_out, "\nFile \"%s\":\n",
783 dump_name) != ESUCCESS)
784 messcrash("Unable to write to output stack for dump parse messages") ;
785
786
787 file_parsed = doParseAceIn(parse_in, parse_out, 0, FALSE, TRUE) ; /* destroys parse_in */
788 parse_in = NULL ;
789
790 if (!file_parsed)
791 {
792 aceOutPrint(parse_out, DUMP_ERR " parsing of dump file %s failed.", dump_name);
793 status = FALSE ;
794 }
795 else
796 {
797 dump_stats = TRUE ; /* print stats at end. */
798
799 /* Get next dump file if there is one. */
800 dump_num++ ;
801 messfree(dump_name) ;
802 dump_name = hprintf(0, "%s/%s%d.ace", dirSelection, dump_prefix, dump_num) ;
803 if (filCheckName(dump_name, NULL, "e"))
804 {
805 if (filCheckName(dump_name, NULL, "r"))
806 {
807 parse_in = aceInCreateFromFile(dump_name, "r", "", 0) ;
808 if (!parse_in)
809 {
810 aceOutPrint(parse_out, DUMP_ERR " could not open dump file %s",
811 dump_name);
812 status = file_found = FALSE ;
813 }
814 }
815 else
816 {
817 aceOutPrint(parse_out, DUMP_ERR " could not read dump file %s", dump_name);
818 status = file_found = FALSE ;
819 }
820 }
821 else
822 file_found = FALSE ;
823 }
824 }
825 }
826
827
828 /* Print out summary of parse stats for files read in so far. */
829 if (parse_out)
830 aceOutPrint(result_out, "%s", popText(s)) ;
831
832 /* Clean up stuff. */
833 if (parse_in)
834 aceInDestroy(parse_in) ;
835 if (dump_name)
836 messfree(dump_name) ;
837 if (parse_out)
838 aceOutDestroy(parse_out) ;
839 if (s)
840 stackDestroy(s) ;
841
842 return status ;
843 }
844
845
846
847
848 void dumpAllNonInteractive (char *dir, BOOL split)
849 {
850 int nk, ne, no , t , total = 0, nfile = 0 ;
851 KEY cKey, key=0 ;
852 ACEOUT dump_out;
853 long int filepos;
854 #ifndef NON_GRAPHIC
855 int box = 0, line = 0 ;
856
857 if(!graphActivate(dumpGraph))
858 {
859 dumpGraph = displayCreate("DtDump");
860 graphMenu (dumpMenu);
861 graphTextBounds (80,100) ;
862 graphRegister(DESTROY,dumpDestroy) ;
863 graphColor (BLACK) ;
864 }
865 else
866 {
867 graphPop() ;
868 graphClear();
869 }
870 #endif /* NON_GRAPHIC */
871
872 if (dir)
873 strcpy (dumpDir, dir) ;
874
875 if (!split)
876 {
877 dump_out = dumpOpenOutput(TRUE, 0, ++nfile);
878 if (!dump_out)
879 goto end;
880 }
881 else
882 dump_out = 0;
883
884 #ifndef NON_GRAPHIC
885
886 graphText(messprintf("Session %d", thisSession.session),
887 4, 2) ;
888 graphText ("Any object in the keyset called DoNotDump will be jumped",
889 4, 6) ;
890 graphRedraw () ;
891
892 /* If user does not want to proceed get rid of the dump window. */
893 if (!messQuery("Should I proceed ?"))
894 {
895 graphDestroy() ;
896 return ;
897 }
898
899 line = 8 ;
900
901 graphText ("Dumping classes ", 4, line++) ;
902 graphRedraw () ;
903 #endif /* NON_GRAPHIC */
904
905 if (lexword2key ("DoNotDump",&cKey,_VKeySet))
906 doNotDumpKeySet = arrayGet(cKey, KEY, "k") ;
907 for (t = 5; t<256 ; t++)
908 if (lexMax(t))
909 if (dumpClassPossible(t, 'a'))
910 {
911 if (split)
912 {
913 BOOL first;
914 if (dump_out)
915 {
916 aceOutPrint (dump_out,
917 "\n\n // End of this dump file \n\n") ;
918 aceOutDestroy (dump_out);
919 total = 0;
920 first = FALSE;
921 }
922 else
923 first = TRUE;
924 dump_out = dumpOpenOutput (first, pickClass2Word(t),
925 ++nfile);
926 if (!dump_out)
927 break;
928 }
929 aceOutPrint (dump_out,
930 "\n\n // Class %s \n\n", pickClass2Word(t)) ;
931 if ((key = dumpClass (dump_out, key, t, &nk, &no, &ne)))
932 {
933 total = 0;
934 t--; /* class not complete, continue; */
935 }
936 else
937 {
938 if (split)
939 nfile = 0;
940 #ifndef NON_GRAPHIC
941 box = graphBoxStart() ;
942 graphText (messprintf ("Class %s : %d keys, %d obj, %d errors",
943 pickClass2Word(t),
944 nk,no, ne) , 4, line++) ;
945 graphBoxEnd () ;
946 graphBoxDraw(box,BLACK,WHITE) ;
947 #endif /* NON_GRAPHIC */
948 }
949 if (!aceOutStreamPos (dump_out, &filepos))
950 filepos = 0;
951
952 if (!split && (((total += no) > MAX_OBJECTS_IN_DUMP) ||
953 (filepos > MAX_BYTES_IN_DUMP)))
954 {
955 aceOutPrint (dump_out,
956 "\n\n // End of this dump file \n\n") ;
957 aceOutDestroy (dump_out);
958 total = 0 ;
959 #ifndef NON_GRAPHIC
960 graphText("Starting a new dump file", 8, line += 3) ;
961 #endif
962 dump_out = dumpOpenOutput(FALSE, split ? pickClass2Word(t) : 0, ++nfile) ;
963 if (!dump_out)
964 break;
965
966 }
967 }
968 end:
969 if (dump_out)
970 {
971 aceOutPrint (dump_out, "\n\n // End of this dump file \n\n") ;
972 aceOutDestroy (dump_out);
973 }
974 else
975 #ifdef NON_GRAPHIC
976 messout ("Failed to open dump file, aborting dump.\n");
977 #else /* !NON_GRAPHIC */
978 graphText("Failed to open dump file, cannot complete dump.",8,line);
979 #endif /* !NON_GRAPHIC */
980
981 keySetDestroy (doNotDumpKeySet) ;
982 #ifndef NON_GRAPHIC
983 graphRedraw() ;
984 #endif /* !NON_GRAPHIC */
985
986 dump1Check();
987 dumpTimeStamps = FALSE ;
988 dumpDir[0] = '\0';
989
990 return;
991 } /* dumpAllNonInteractive */
992
993 /************************************************************/
994
995 static BOOL dumpSetDirectory (void)
996 {
997 static char directory[DIR_BUFFER_SIZE] = "";
998 static char filename[FIL_BUFFER_SIZE] = "";
999 FILE *f = 0;
1000
1001 f = filqueryopen (directory, filename, "", "rd",
1002 "Choose directory for dump files");
1003 if (!f)
1004 return FALSE;
1005 filclose (f);
1006
1007 sprintf (dumpDir,"%s/", directory);
1008
1009 return TRUE;
1010 } /* dumpSetDirectory */
1011
1012 /********************* eof **********************************/