~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/cull/cull_dump_scan.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
#include <ctype.h>
 
36
 
 
37
/* do not compile in monitoring code */
 
38
#ifndef NO_SGE_COMPILE_DEBUG
 
39
#define NO_SGE_COMPILE_DEBUG
 
40
#endif
 
41
 
 
42
#include "sgermon.h"
 
43
#include "cull_dump_scan.h"
 
44
#include "cull_listP.h"
 
45
#include "cull_multitypeP.h"
 
46
#include "cull_lerrnoP.h"
 
47
#include "basis_types.h"
 
48
 
 
49
#include "uti/sge_dstring.h"
 
50
#include "uti/sge_stdio.h"
 
51
#include "uti/sge_string.h"
 
52
 
 
53
#define READ_LINE_LENGHT 255
 
54
 
 
55
#define INDENT_STRING      "   "
 
56
 
 
57
static int space_comment(char *s);
 
58
 
 
59
static int fGetLine(FILE *fp, char *line, int max_line);
 
60
static int fGetBra(FILE *fp);
 
61
static int fGetKet(FILE *fp);
 
62
static int fGetDescr(FILE *fp, lDescr *dp);
 
63
static int fGetInt(FILE *fp, lInt *value);
 
64
static int fGetUlong(FILE *fp, lUlong *value);
 
65
static int fGetString(FILE *fp, lString *value);
 
66
static int fGetHost(FILE *fp, lHost *value);
 
67
static int fGetFloat(FILE *fp, lFloat *value);
 
68
static int fGetDouble(FILE *fp, lDouble *value);
 
69
static int fGetLong(FILE *fp, lLong *value);
 
70
static int fGetChar(FILE *fp, lChar *value);
 
71
static int fGetBool(FILE *fp, lBool *value);
 
72
static int fGetList(FILE *fp, lList **value);
 
73
static int fGetObject(FILE *fp, lListElem **value);
 
74
 
 
75
/****** cull/dump_scan/lDumpDescr() ****************************************
 
76
*  NAME
 
77
*     lDumpDescr() -- Write a descriptor (for debugging purpose)
 
78
*
 
79
*  SYNOPSIS
 
80
*     int lDumpDescr(FILE *fp, const lDescr *dp, int indent) 
 
81
*
 
82
*  FUNCTION
 
83
*     Write a descriptor (for debugging purpose) 
 
84
*
 
85
*  INPUTS
 
86
*     FILE *fp         - file pointer 
 
87
*     const lDescr *dp - descriptor 
 
88
*     int indent       -  
 
89
*
 
90
*  RESULT
 
91
*     int - error state
 
92
*         0 - OK
 
93
*        -1 - Error
 
94
******************************************************************************/
 
95
int lDumpDescr(FILE *fp, const lDescr *dp, int indent) 
 
96
{
 
97
   int i, ret = ~EOF;
 
98
   char space[256];
 
99
 
 
100
   DENTER(CULL_LAYER, "lDumpDescr");
 
101
 
 
102
   space[0] = '\0';
 
103
   for (i = 0; i < indent; i++)
 
104
      strcat(space, INDENT_STRING);
 
105
 
 
106
   if (!fp) {
 
107
      LERROR(LEFILENULL);
 
108
      DEXIT;
 
109
      return -1;
 
110
   }
 
111
   ret = fprintf(fp, "%s{ /* DESCR BEGIN */\n", space);
 
112
 
 
113
   if (!dp) {
 
114
      LERROR(LEDESCRNULL);
 
115
      DEXIT;
 
116
      return -1;
 
117
   }
 
118
   ret = fprintf(fp, "%s/* NUMBER OF DESCR FIELDS */ %d\n", space, 
 
119
                 lCountDescr(dp));
 
120
 
 
121
   for (i = 0; dp[i].mt != lEndT && ret != EOF; i++) {
 
122
      ret = fprintf(fp, "%s/* %-20.20s */ { %d, %d }\n", space, 
 
123
                    lNm2Str(dp[i].nm), dp[i].nm, dp[i].mt);
 
124
   }
 
125
 
 
126
   ret = fprintf(fp, "%s} /* DESCR END */\n", space);
 
127
 
 
128
   DEXIT;
 
129
   return (ret == EOF) ? -1 : 0;
 
130
}
 
131
 
 
132
/****** cull/dump_scan/lUndumpDescr() ****************************************
 
133
*  NAME
 
134
*     lUndumpDescr() -- Read a descriptor from file (debug) 
 
135
*
 
136
*  SYNOPSIS
 
137
*     lDescr* lUndumpDescr(FILE *fp) 
 
138
*
 
139
*  FUNCTION
 
140
*     Read a descriptor from file (for debugging purposes) 
 
141
*
 
142
*  INPUTS
 
143
*     FILE *fp - file stream 
 
144
*
 
145
*  RESULT
 
146
*     lDescr* - descriptor 
 
147
*******************************************************************************/
 
148
lDescr *lUndumpDescr(FILE *fp) 
 
149
{
 
150
   int n, i;
 
151
   lDescr *dp = NULL;
 
152
 
 
153
   DENTER(CULL_LAYER, "lUndumpDescr");
 
154
 
 
155
   if (!fp) {
 
156
      LERROR(LEFILENULL);
 
157
      DEXIT;
 
158
      return NULL;
 
159
   }
 
160
 
 
161
   /* read bra */
 
162
   if (fGetBra(fp)) {
 
163
      printf("bra is missing\n");
 
164
      LERROR(LESYNTAX);
 
165
      DEXIT;
 
166
      return NULL;
 
167
   }
 
168
 
 
169
   /* read Descriptor Count */
 
170
   if (fGetInt(fp, &n)) {
 
171
      printf("reading integer from dump file failed\n");
 
172
      LERROR(LEFIELDREAD);
 
173
      DEXIT;
 
174
      return NULL;
 
175
   }
 
176
 
 
177
   if (!(dp = (lDescr *) malloc(sizeof(lDescr) * (n + 1)))) {
 
178
      LERROR(LEMALLOC);
 
179
      DEXIT;
 
180
      return NULL;
 
181
   }
 
182
 
 
183
   for (i = 0; i < n; i++) {
 
184
      /* read descriptor */
 
185
      if (fGetDescr(fp, &(dp[i]))) {
 
186
         LERROR(LEFGETDESCR);
 
187
         DEXIT;
 
188
         return NULL;
 
189
      }
 
190
   }
 
191
   dp[i].nm = NoName;
 
192
   dp[i].mt = lEndT;
 
193
   dp[i].ht = NULL;
 
194
 
 
195
   /* read ket */
 
196
   if (fGetKet(fp)) {
 
197
      printf("ket is missing");
 
198
      free(dp);
 
199
      LERROR(LESYNTAX);
 
200
      DEXIT;
 
201
      return NULL;
 
202
   }
 
203
 
 
204
   DEXIT;
 
205
   return dp;
 
206
}
 
207
 
 
208
/****** cull/dump_scan/lDumpElem() ********************************************
 
209
*  NAME
 
210
*     lDumpElem() -- Dump a given element into a file 
 
211
*
 
212
*  SYNOPSIS
 
213
*     int lDumpElem(const char *fname, const lListElem *ep, int indent) 
 
214
*
 
215
*  FUNCTION
 
216
*     Dump a given element into a file 
 
217
*
 
218
*  INPUTS
 
219
*     const char *fname   - filename 
 
220
*     const lListElem *ep - element 
 
221
*     int indent          - 
 
222
*
 
223
*  RESULT
 
224
*     int - error state
 
225
*        -1 - Error
 
226
*         0 - OK
 
227
*
 
228
*  NOTES
 
229
*     MT-NOTE: lDumpElem() is not MT safe
 
230
******************************************************************************/
 
231
int lDumpElem(const char *fname, const lListElem *ep, int indent) 
 
232
{
 
233
   int ret;
 
234
   FILE *fp;
 
235
 
 
236
   fp = fopen(fname, "w");
 
237
   if (fp != NULL) {
 
238
      ret = lDumpElemFp(fp, ep, indent);
 
239
      FCLOSE(fp);
 
240
   } else {
 
241
      LERROR(LEOPEN);
 
242
      ret = -1;
 
243
   }
 
244
   return ret;
 
245
FCLOSE_ERROR:
 
246
   LERROR(LECLOSE);
 
247
   return -1;
 
248
}
 
249
 
 
250
/****** cull/dump_scan/lDumpElemFp() ******************************************
 
251
*  NAME
 
252
*     lDumpElemFp() -- Dump a given element into FILE stream 
 
253
*
 
254
*  SYNOPSIS
 
255
*     int lDumpElemFp(FILE *fp, const lListElem *ep, int indent) 
 
256
*
 
257
*  FUNCTION
 
258
*     Dump a given element into FILE stream
 
259
*
 
260
*  INPUTS
 
261
*     FILE *fp            - file stream 
 
262
*     const lListElem *ep - element 
 
263
*     int indent          - 
 
264
*
 
265
*  RESULT
 
266
*     int - error state
 
267
*         0 - OK
 
268
*        -1 - Error 
 
269
*
 
270
*  NOTES
 
271
*     MT-NOTE: lDumpElemFp() is not MT safe
 
272
******************************************************************************/
 
273
int lDumpElemFp(FILE *fp, const lListElem *ep, int indent) 
 
274
{
 
275
   int i, ret = ~EOF;
 
276
   lList *tlp;
 
277
   lListElem *tep;
 
278
   char space[256];
 
279
   const char *str;
 
280
   dstring dstr = DSTRING_INIT;
 
281
 
 
282
   DENTER(CULL_LAYER, "lDumpElemFp");
 
283
 
 
284
   space[0] = '\0';
 
285
   for (i = 0; i < indent; i++)
 
286
      strcat(space, INDENT_STRING);
 
287
 
 
288
   if (!fp) {
 
289
      LERROR(LEFILENULL);
 
290
      DEXIT;
 
291
      return -1;
 
292
   }
 
293
   if (!ep) {
 
294
      LERROR(LEELEMNULL);
 
295
      DEXIT;
 
296
      return -1;
 
297
   }
 
298
 
 
299
   ret = fprintf(fp, "%s{ \n", space);
 
300
   for (i = 0, ret = 0; ep->descr[i].nm != NoName && ret != EOF; i++) {
 
301
      char *tok = NULL;
 
302
 
 
303
      switch (mt_get_type(ep->descr[i].mt)) {
 
304
      case lIntT:
 
305
         ret = fprintf(fp, "%s/* %-20.20s */ %d\n",
 
306
                     space, lNm2Str(ep->descr[i].nm), lGetPosInt(ep, i));
 
307
         break;
 
308
      case lUlongT:
 
309
         ret = fprintf(fp, "%s/* %-20.20s */ " sge_u32 "\n",
 
310
                   space, lNm2Str(ep->descr[i].nm), lGetPosUlong(ep, i));
 
311
         break;
 
312
      case lStringT:
 
313
         str = lGetPosString(ep, i);
 
314
         /* quote " inside str */
 
315
         if ((tok = sge_strtok(str, "\"")) != NULL) {
 
316
            sge_dstring_append(&dstr, tok);
 
317
            while ((tok=sge_strtok(NULL, "\"")) != NULL) {
 
318
               sge_dstring_append(&dstr, "\\\"");
 
319
               sge_dstring_append(&dstr, tok);
 
320
            }
 
321
         }
 
322
         str = sge_dstring_get_string(&dstr);
 
323
         ret = fprintf(fp, "%s/* %-20.20s */ \"%s\"\n",
 
324
                  space, lNm2Str(ep->descr[i].nm), str != NULL ? str : "");
 
325
         sge_dstring_clear(&dstr);
 
326
         break;
 
327
      case lHostT:
 
328
         str = lGetPosHost(ep, i);
 
329
         ret = fprintf(fp, "%s/* %-20.20s */ \"%s\"\n",
 
330
                  space, lNm2Str(ep->descr[i].nm), str != NULL ? str : "");
 
331
         break;
 
332
      case lFloatT:
 
333
         ret = fprintf(fp, "%s/* %-20.20s */ %f\n",
 
334
                   space, lNm2Str(ep->descr[i].nm), lGetPosFloat(ep, i));
 
335
         break;
 
336
      case lDoubleT:
 
337
         ret = fprintf(fp, "%s/* %-20.20s */ %f\n",
 
338
                  space, lNm2Str(ep->descr[i].nm), lGetPosDouble(ep, i));
 
339
         break;
 
340
      case lLongT:
 
341
         ret = fprintf(fp, "%s/* %-20.20s */%ld \n",
 
342
                    space, lNm2Str(ep->descr[i].nm), lGetPosLong(ep, i));
 
343
         break;
 
344
      case lCharT:
 
345
         ret = fprintf(fp, "%s/* %-20.20s */ %c\n",
 
346
                    space, lNm2Str(ep->descr[i].nm), lGetPosChar(ep, i));
 
347
         break;
 
348
      case lBoolT:
 
349
         ret = fprintf(fp, "%s/* %-20.20s */ %d\n",
 
350
                    space, lNm2Str(ep->descr[i].nm), lGetPosBool(ep, i));
 
351
         break;
 
352
      case lRefT:
 
353
         ret = fprintf(fp, "%s/* %-20.20s */ %ld\n",
 
354
                    space, lNm2Str(ep->descr[i].nm), (long)lGetPosRef(ep, i));
 
355
         break;
 
356
      case lObjectT:
 
357
         if ((tep = lGetPosObject(ep, i)) == NULL)
 
358
            ret = fprintf(fp, "%s/* %-20.20s */ none\n",
 
359
                          space, lNm2Str(ep->descr[i].nm));
 
360
         else {
 
361
            ret = fprintf(fp, "%s/* %-20.20s */ object\n",
 
362
                          space, lNm2Str(ep->descr[i].nm));
 
363
            if (ret != EOF)
 
364
               ret = lDumpObject(fp, tep, indent + 1);
 
365
         }
 
366
         break;
 
367
      case lListT:
 
368
         if ((tlp = lGetPosList(ep, i)) == NULL)
 
369
            ret = fprintf(fp, "%s/* %-20.20s */ empty\n",
 
370
                          space, lNm2Str(ep->descr[i].nm));
 
371
         else {
 
372
            ret = fprintf(fp, "%s/* %-20.20s */ full\n",
 
373
                          space, lNm2Str(ep->descr[i].nm));
 
374
            if (ret != EOF)
 
375
               ret = lDumpList(fp, tlp, indent + 1);
 
376
         }
 
377
         break;
 
378
      }
 
379
   }
 
380
   sge_dstring_free(&dstr);
 
381
 
 
382
   ret = fprintf(fp, "%s}\n", space);
 
383
 
 
384
   DEXIT;
 
385
   return (ret == EOF) ? -1 : 0;
 
386
}
 
387
 
 
388
/****** cull/dump_scan/lDumpObject() ********************************************
 
389
*  NAME
 
390
*     lDumpObject() -- Writes an object to a FILE stream
 
391
*
 
392
*  SYNOPSIS
 
393
*     int lDumpObject(FILE *fp, const lListElem *ep, int indent) 
 
394
*
 
395
*  FUNCTION
 
396
*     Writes an object to a FILE stream. 
 
397
*
 
398
*  INPUTS
 
399
*     FILE *fp             - file stream 
 
400
*     const lListElem *ep  - object 
 
401
*     int indent           - 
 
402
*
 
403
*  RESULT
 
404
*     int - error state
 
405
*         0 - OK
 
406
*        -1 - Error
 
407
*******************************************************************************/
 
408
int lDumpObject(FILE *fp, const lListElem *ep, int indent) 
 
409
{
 
410
   int i, ret = ~EOF;
 
411
 
 
412
   char space[256];
 
413
 
 
414
   DENTER(CULL_LAYER, "lDumpObject");
 
415
 
 
416
   space[0] = '\0';
 
417
   for (i = 0; i < indent; i++)
 
418
      strcat(space, INDENT_STRING);
 
419
 
 
420
   if (!fp) {
 
421
      LERROR(LEFILENULL);
 
422
      DEXIT;
 
423
      return -1;
 
424
   }
 
425
   if (!ep) {
 
426
      LERROR(LEELEMNULL);
 
427
      DEXIT;
 
428
      return -1;
 
429
   }
 
430
 
 
431
   ret = fprintf(fp, "%s{ /* OBJECT BEGIN */\n", space);
 
432
 
 
433
   ret = lDumpDescr(fp, ep->descr, indent);
 
434
 
 
435
   ret = lDumpElemFp(fp, ep, indent);
 
436
 
 
437
   ret = fprintf(fp, "%s} /* OBJECT END */\n", space);
 
438
 
 
439
   DEXIT;
 
440
   return (ret == EOF) ? -1 : 0;
 
441
 
 
442
}
 
443
/****** cull/dump_scan/lDumpList() ********************************************
 
444
*  NAME
 
445
*     lDumpList() -- Writes a list to a FILE stream
 
446
*
 
447
*  SYNOPSIS
 
448
*     int lDumpList(FILE *fp, const lList *lp, int indent) 
 
449
*
 
450
*  FUNCTION
 
451
*     Writes a list to a FILE stream. 
 
452
*
 
453
*  INPUTS
 
454
*     FILE *fp        - file stream 
 
455
*     const lList *lp - list 
 
456
*     int indent      - 
 
457
*
 
458
*  RESULT
 
459
*     int - error state
 
460
*         0 - OK
 
461
*        -1 - Error
 
462
*
 
463
*  NOTES
 
464
*     MT-NOTE: lDumpList() is not MT safe
 
465
*******************************************************************************/
 
466
int lDumpList(FILE *fp, const lList *lp, int indent) 
 
467
{
 
468
   lListElem *ep;
 
469
   int i, ret = ~EOF;
 
470
 
 
471
   char space[256];
 
472
 
 
473
   DENTER(CULL_LAYER, "lDumpList");
 
474
 
 
475
   space[0] = '\0';
 
476
   for (i = 0; i < indent; i++)
 
477
      strcat(space, INDENT_STRING);
 
478
 
 
479
   if (!fp) {
 
480
      LERROR(LEFILENULL);
 
481
      DEXIT;
 
482
      return -1;
 
483
   }
 
484
   if (!lp) {
 
485
      LERROR(LELISTNULL);
 
486
      DEXIT;
 
487
      return -1;
 
488
   }
 
489
 
 
490
   ret = fprintf(fp, "%s{ /* LIST BEGIN */\n", space);
 
491
 
 
492
   ret = fprintf(fp, "%s/* LISTNAME               */ \"%s\"\n", space, 
 
493
                 lGetListName(lp));
 
494
   ret = fprintf(fp, "%s/* NUMBER OF ELEMENTS     */ %d\n", space, 
 
495
                 lGetNumberOfElem(lp));
 
496
 
 
497
   ret = lDumpDescr(fp, lGetListDescr(lp), indent);
 
498
 
 
499
   for (ep = lFirst(lp); ep && ret != EOF; ep = lNext(ep))
 
500
      ret = lDumpElemFp(fp, ep, indent);
 
501
 
 
502
   ret = fprintf(fp, "%s} /* LIST END */\n", space);
 
503
 
 
504
   DEXIT;
 
505
   return (ret == EOF) ? -1 : 0;
 
506
 
 
507
}
 
508
/****** cull/dump_scan/lUndumpElem() ******************************************
 
509
*  NAME
 
510
*     lUndumpElem() -- Read element from FILE stream 
 
511
*
 
512
*  SYNOPSIS
 
513
*     lListElem* lUndumpElem(FILE *fp, const lDescr *dp) 
 
514
*
 
515
*  FUNCTION
 
516
*     Read element from FILE stream 
 
517
*
 
518
*  INPUTS
 
519
*     FILE *fp         - file stream 
 
520
*     const lDescr *dp - descriptor 
 
521
*
 
522
*  RESULT
 
523
*     lListElem* - Read element 
 
524
******************************************************************************/
 
525
lListElem *lUndumpElem(const char *fname, const lDescr *dp) 
 
526
{
 
527
   lListElem *ep = NULL;
 
528
   FILE *fp;
 
529
 
 
530
   DENTER(CULL_LAYER, "lUndumpElemFp");
 
531
 
 
532
   fp = fopen(fname, "r");
 
533
   if (fp == NULL) {
 
534
      LERROR(LEOPEN);
 
535
   } else {
 
536
      ep = lUndumpElemFp(fp, dp);
 
537
   }
 
538
 
 
539
   DEXIT;
 
540
   return ep;
 
541
}
 
542
 
 
543
/****** cull/dump_scan/lUndumpElemFp() ******************************************
 
544
*  NAME
 
545
*     lUndumpElemFp() -- Read element from FILE stream 
 
546
*
 
547
*  SYNOPSIS
 
548
*     lListElem* lUndumpElemFp(FILE *fp, const lDescr *dp) 
 
549
*
 
550
*  FUNCTION
 
551
*     Read element from FILE stream 
 
552
*
 
553
*  INPUTS
 
554
*     FILE *fp         - file stream 
 
555
*     const lDescr *dp - descriptor 
 
556
*
 
557
*  RESULT
 
558
*     lListElem* - Read element 
 
559
******************************************************************************/
 
560
lListElem *lUndumpElemFp(FILE *fp, const lDescr *dp) 
 
561
{
 
562
   lListElem *ep;
 
563
   int n, i;
 
564
   int ret = 0;
 
565
   char *str;
 
566
   u_long32 dummy;
 
567
 
 
568
   DENTER(CULL_LAYER, "lUndumpElemFp");
 
569
 
 
570
   if (!fp) {
 
571
      LERROR(LEFILENULL);
 
572
      DEXIT;
 
573
      return NULL;
 
574
   }
 
575
   if (!dp) {
 
576
      LERROR(LEDESCRNULL);
 
577
      DEXIT;
 
578
      return NULL;
 
579
   }
 
580
   if (!(ep = lCreateElem(dp))) {
 
581
      LERROR(LECREATEELEM);
 
582
      DEXIT;
 
583
      return NULL;
 
584
   }
 
585
 
 
586
   if ((n = lCountDescr(dp)) <= 0) {
 
587
      LERROR(LECOUNTDESCR);
 
588
      lFreeElem(&ep);
 
589
      DEXIT;
 
590
      return NULL;
 
591
   }
 
592
 
 
593
   /* read bra */
 
594
   if (fGetBra(fp)) {
 
595
      printf("bra is missing\n");
 
596
      LERROR(LESYNTAX);
 
597
      lFreeElem(&ep);
 
598
      DEXIT;
 
599
      return NULL;
 
600
   }
 
601
 
 
602
   for (i = 0; i < n && ret == 0; i++) {
 
603
      switch (mt_get_type(dp[i].mt)) {
 
604
      case lIntT:
 
605
         ret = fGetInt(fp, &(ep->cont[i].i));
 
606
         break;
 
607
      case lUlongT:
 
608
         ret = fGetUlong(fp, &(ep->cont[i].ul));
 
609
         break;
 
610
      case lStringT:
 
611
         ret = fGetString(fp, &str);
 
612
         lSetPosString(ep, i, str);
 
613
         free(str);             /* fGetString strdup's */
 
614
         break;
 
615
      case lHostT:
 
616
         ret = fGetHost(fp, &str);
 
617
         lSetPosHost(ep, i, str);
 
618
         free(str);             /* fGetHost strdup's */
 
619
         break;
 
620
      case lFloatT:
 
621
         ret = fGetFloat(fp, &(ep->cont[i].fl));
 
622
         break;
 
623
      case lDoubleT:
 
624
         ret = fGetDouble(fp, &(ep->cont[i].db));
 
625
         break;
 
626
      case lLongT:
 
627
         ret = fGetLong(fp, &(ep->cont[i].l));
 
628
         break;
 
629
      case lCharT:
 
630
         ret = fGetChar(fp, &(ep->cont[i].c));
 
631
         break;
 
632
      case lBoolT:
 
633
         ret = fGetBool(fp, &(ep->cont[i].b));
 
634
         break;
 
635
      case lRefT:
 
636
         /* we will not undump references! But we have to skip the line! */
 
637
         ret = fGetUlong(fp, &dummy);
 
638
         ep->cont[i].ref = NULL;
 
639
         break;
 
640
      case lObjectT:
 
641
         ret = fGetObject(fp, &(ep->cont[i].obj));
 
642
         break;
 
643
      case lListT:
 
644
         ret = fGetList(fp, &(ep->cont[i].glp));
 
645
         break;
 
646
      default:
 
647
         lFreeElem(&ep);
 
648
         unknownType("lUndumpElemFp");
 
649
      }
 
650
   }
 
651
 
 
652
   /* error handling for loop */
 
653
   if (ret != 0) {
 
654
      lFreeElem(&ep);
 
655
      LERROR(LEFIELDREAD);
 
656
      DEXIT;
 
657
      return NULL;
 
658
   }
 
659
 
 
660
   /* read ket */
 
661
   if (fGetKet(fp)) {
 
662
      lFreeElem(&ep);
 
663
      printf("ket is missing\n");
 
664
      LERROR(LESYNTAX);
 
665
      DEXIT;
 
666
      return NULL;
 
667
   }
 
668
 
 
669
   DEXIT;
 
670
   return ep;
 
671
}
 
672
 
 
673
/****** cull/dump_scan/lUndumpObject() ******************************************
 
674
*  NAME
 
675
*     lUndumpObject() -- Reads a by lDumpList dumped dump 
 
676
*
 
677
*  SYNOPSIS
 
678
*     lListElem* lUndumpObject(FILE *fp) 
 
679
*
 
680
*  FUNCTION
 
681
*     Reads a by lDumpList dumped dump into the memory. 
 
682
*
 
683
*  INPUTS
 
684
*     FILE *fp         - file pointer 
 
685
*
 
686
*  RESULT
 
687
*     lListElem* - Read list element
 
688
*
 
689
*  NOTES
 
690
*
 
691
******************************************************************************/
 
692
lListElem *lUndumpObject(FILE *fp) 
 
693
{
 
694
   lListElem *ep;
 
695
   lDescr *dp = NULL;
 
696
 
 
697
   DENTER(CULL_LAYER, "lUndumpObject");
 
698
 
 
699
   if (!fp) {
 
700
      LERROR(LEFILENULL);
 
701
      DEXIT;
 
702
      return NULL;
 
703
   }
 
704
   /* read bra */
 
705
   if (fGetBra(fp)) {
 
706
      printf("bra is missing\n");
 
707
      LERROR(LESYNTAX);
 
708
      DEXIT;
 
709
      return NULL;
 
710
   }
 
711
 
 
712
   /* read Descriptor from file */
 
713
   if ((dp = lUndumpDescr(fp)) == NULL) {
 
714
      LERROR(LEFGETDESCR);
 
715
      DEXIT;
 
716
      return NULL;
 
717
   }
 
718
 
 
719
   if (lCountDescr(dp) <= 0) {
 
720
      LERROR(LECOUNTDESCR);
 
721
      free(dp);
 
722
      DEXIT;
 
723
      return NULL;
 
724
   }
 
725
 
 
726
   if ((ep = lUndumpElemFp(fp, dp)) == NULL) {
 
727
      LERROR(LEUNDUMPELEM);
 
728
      free(dp);
 
729
      DEXIT;
 
730
      return NULL;
 
731
   }
 
732
 
 
733
   free(dp);
 
734
 
 
735
   /* read ket */
 
736
   if (fGetKet(fp)) {
 
737
      lFreeElem(&ep);
 
738
      printf("ket is missing\n");
 
739
      LERROR(LESYNTAX);
 
740
      DEXIT;
 
741
      return NULL;
 
742
   }
 
743
 
 
744
   DEXIT;
 
745
   return ep;
 
746
}
 
747
 
 
748
/****** cull/dump_scan/lUndumpList() ******************************************
 
749
*  NAME
 
750
*     lUndumpList() -- Reads a by lDumpList dumped dump 
 
751
*
 
752
*  SYNOPSIS
 
753
*     lList* lUndumpList(FILE *fp, const char *name, const lDescr *dp) 
 
754
*
 
755
*  FUNCTION
 
756
*     Reads a by lDumpList dumped dump into the memory. 
 
757
*
 
758
*  INPUTS
 
759
*     FILE *fp         - file pointer 
 
760
*     const char *name - new name of list or NULL if the old name in the
 
761
*                        dumpfile should be used as listname 
 
762
*     const lDescr *dp - new list descriptor or NULL if the old list
 
763
*                        descriptor should be used as list descriptor 
 
764
*
 
765
*  RESULT
 
766
*     lList* - Read list 
 
767
*
 
768
*  NOTES
 
769
*     Actually a type/name matching is only performed for the list
 
770
*     itself and not for its sublists.
 
771
*     If an implementation of changed sublist descriptors is desired
 
772
*     we can probably use the following syntax for lUndumpList.
 
773
*     lList* lUndumpList(fp, name, formatstring, ...)
 
774
*     with formatstring like "%T(%I -> %T(%I->%T))" and the varargs 
 
775
*     list: ".....", lDescr1, fieldname1, lDescr2, fieldname2, lDescr3
 
776
*     or write a wrapper around lUndumpList which parses this format and 
 
777
*     hands over the varargs list to lUndumpList
 
778
******************************************************************************/
 
779
lList *lUndumpList(FILE *fp, const char *name, const lDescr *dp) 
 
780
{
 
781
   lList *lp = NULL;
 
782
   lListElem *fep, *ep;
 
783
   lDescr *fdp = NULL;
 
784
   int i, j, nelem, n, k;
 
785
   int *found;
 
786
   char *oldname;
 
787
 
 
788
   DENTER(CULL_LAYER, "lUndumpList");
 
789
 
 
790
   if (!fp) {
 
791
      LERROR(LEFILENULL);
 
792
      DEXIT;
 
793
      return NULL;
 
794
   }
 
795
 
 
796
   /* read bra */
 
797
   if (fGetBra(fp)) {
 
798
      printf("bra is missing\n");
 
799
      LERROR(LESYNTAX);
 
800
      DEXIT;
 
801
      return NULL;
 
802
   }
 
803
   /* read listname */
 
804
   if (fGetString(fp, &oldname)) {
 
805
      printf("fGetString failed\n");
 
806
      LERROR(LEFIELDREAD);
 
807
      DEXIT;
 
808
      return NULL;
 
809
   }
 
810
 
 
811
   /* read number of elems */
 
812
   if (fGetInt(fp, &nelem)) {
 
813
      printf("fGetInt failed\n");
 
814
      LERROR(LEFIELDREAD);
 
815
      DEXIT;
 
816
      return NULL;
 
817
   }
 
818
 
 
819
   /* read Descriptor from file */
 
820
   if (!(fdp = lUndumpDescr(fp))) {
 
821
      LERROR(LEFGETDESCR);
 
822
      DEXIT;
 
823
      return NULL;
 
824
   }
 
825
 
 
826
   if (!dp)                     /* dp is NULL, use lDescr from dumpfile */
 
827
      dp = fdp;
 
828
 
 
829
   /* use old name (from file) if name is NULL */
 
830
   if (!(lp = lCreateList((name) ? name : oldname, dp))) {
 
831
      LERROR(LECREATELIST);
 
832
      DEXIT;
 
833
      return NULL;
 
834
   }
 
835
   free(oldname);               /* fGetString strdup's */
 
836
 
 
837
   if ((n = lCountDescr(dp)) <= 0) {
 
838
      LERROR(LECOUNTDESCR);
 
839
      lFreeList(&lp);
 
840
      DEXIT;
 
841
      return NULL;
 
842
   }
 
843
 
 
844
   if (!(found = (int *) malloc(sizeof(int) * n))) {
 
845
      LERROR(LEMALLOC);
 
846
      lFreeList(&lp);
 
847
      DEXIT;
 
848
      return NULL;
 
849
   }
 
850
 
 
851
   /* Initialize found array */
 
852
   for (i = 0; i < n; i++)
 
853
      found[i] = -1;
 
854
 
 
855
   /* Here warnings are displayed if there are additional or missing fields */
 
856
   for (j = 0; fdp[j].nm != NoName; j++) {
 
857
      for (i = 0; i < n; i++) {
 
858
         if (dp[i].nm == fdp[j].nm &&
 
859
             dp[i].mt == fdp[j].mt) {
 
860
            if (found[i] != -1)
 
861
               DPRINTF(("lUndumpList: field %s found twice\n",
 
862
                        lNm2Str(dp[i].nm)));
 
863
            found[i] = j;
 
864
            break;
 
865
         }
 
866
      }
 
867
      if (i == n)
 
868
         DPRINTF(("lUndumpList: field %s not needed\n", lNm2Str(fdp[j].nm)));
 
869
   }
 
870
 
 
871
   for (i = 0; i < n; i++)
 
872
      if (found[i] == -1)
 
873
         DPRINTF(("lUndumpList: field %s not found\n", lNm2Str(dp[i].nm)));
 
874
 
 
875
   /* LOOP OVER THE LIST ELEMENTS */
 
876
   for (k = 0; k < nelem; k++) {
 
877
      if (!(fep = lUndumpElemFp(fp, fdp))) {
 
878
         LERROR(LEUNDUMPELEM);
 
879
         lFreeList(&lp);
 
880
         free(found);
 
881
         DEXIT;
 
882
         return NULL;
 
883
      }
 
884
 
 
885
      if (!(ep = lCreateElem(dp))) {
 
886
         lFreeList(&lp);
 
887
         free(found);
 
888
         LERROR(LECREATEELEM);
 
889
         DEXIT;
 
890
         return NULL;
 
891
      }
 
892
 
 
893
      for (i = 0; i < n; i++) {
 
894
         if (found[i] == -1) {
 
895
            continue;
 
896
         } else if (lCopySwitchPack(fep, ep, found[i], i, true, NULL, NULL) == -1) {
 
897
            lFreeList(&lp);
 
898
            lFreeElem(&ep);
 
899
            free(found);
 
900
            LERROR(LECOPYSWITCH);
 
901
            DEXIT;
 
902
            return NULL;
 
903
         }
 
904
      }
 
905
      lFreeElem(&fep);
 
906
      if (lAppendElem(lp, ep) == -1) {
 
907
         lFreeList(&lp);
 
908
         lFreeElem(&ep);
 
909
         free(found);
 
910
         LERROR(LEAPPENDELEM);
 
911
         DEXIT;
 
912
         return NULL;
 
913
      }
 
914
 
 
915
   }
 
916
 
 
917
   /* read ket */
 
918
   if (fGetKet(fp)) {
 
919
      lFreeList(&lp);
 
920
      printf("ket is missing\n");
 
921
      LERROR(LESYNTAX);
 
922
      DEXIT;
 
923
      return NULL;
 
924
   }
 
925
 
 
926
   DEXIT;
 
927
   return lp;
 
928
}
 
929
 
 
930
static int space_comment(char *s) 
 
931
{
 
932
   char *p, *t;
 
933
 
 
934
   DENTER(CULL_LAYER, "space_comment");
 
935
 
 
936
   while ((t = strstr(s, "/*"))) {
 
937
      if (!(p = strstr(t + 2, "*/"))) {
 
938
         DEXIT;
 
939
         return -1;
 
940
      }
 
941
      while (t < p + 2)
 
942
         *t++ = ' ';
 
943
   }
 
944
   DEXIT;
 
945
   return 0;
 
946
 
 
947
}
 
948
 
 
949
static int fGetLine(FILE *fp, char *line, int max_line) 
 
950
{
 
951
   DENTER(CULL_LAYER, "fGetLine");
 
952
 
 
953
   if (!fp) {
 
954
      LERROR(LEFILENULL);
 
955
      DEXIT;
 
956
      return -1;
 
957
   }
 
958
 
 
959
   if (!(fgets(line, max_line, fp))) {
 
960
      LERROR(LEFGETS);
 
961
      DEXIT;
 
962
      return -1;
 
963
   }
 
964
   if (space_comment(line)) {
 
965
      LERROR(LESPACECOMMENT);
 
966
      DEXIT;
 
967
      return -1;
 
968
   }
 
969
 
 
970
   DEXIT;
 
971
   return 0;
 
972
}
 
973
 
 
974
static int fGetBra(FILE *fp) 
 
975
{
 
976
   char s[READ_LINE_LENGHT + 1];
 
977
 
 
978
   DENTER(CULL_LAYER, "fGetBra");
 
979
 
 
980
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
981
      LERROR(LEFGETLINE);
 
982
      DEXIT;
 
983
      return -1;
 
984
   }
 
985
 
 
986
   DEXIT;
 
987
   return strstr(s, "{") ? 0 : -1;
 
988
}
 
989
 
 
990
static int fGetKet(FILE *fp) 
 
991
{
 
992
   char s[READ_LINE_LENGHT + 1];
 
993
 
 
994
   DENTER(CULL_LAYER, "fGetKet");
 
995
 
 
996
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
997
      LERROR(LEFGETLINE);
 
998
      DEXIT;
 
999
      return -1;
 
1000
   }
 
1001
 
 
1002
   DEXIT;
 
1003
   return strstr(s, "}") ? 0 : -1;
 
1004
}
 
1005
 
 
1006
static int fGetDescr(FILE *fp, lDescr *dp) 
 
1007
{
 
1008
   char s[READ_LINE_LENGHT + 1];
 
1009
   int mt, nm;
 
1010
   char bra[2], comma[2], ket[2];
 
1011
 
 
1012
   DENTER(CULL_LAYER, "fGetDescr");
 
1013
 
 
1014
   if (!fp) {
 
1015
      LERROR(LEFILENULL);
 
1016
      DEXIT;
 
1017
      return -1;
 
1018
   }
 
1019
 
 
1020
   if (!dp) {
 
1021
      LERROR(LEDESCRNULL);
 
1022
      DEXIT;
 
1023
      return -1;
 
1024
   }
 
1025
 
 
1026
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1027
      LERROR(LEFGETLINE);
 
1028
      DEXIT;
 
1029
      return -1;
 
1030
   }
 
1031
 
 
1032
   /* 
 
1033
      We use this strange form of scanf to skip the 
 
1034
      white space at the beginning. scanf is magic isn't it?
 
1035
    */
 
1036
   if (sscanf(s, "%1s %d %1s %d %1s", bra, &nm, comma, &mt, ket) != 5) {
 
1037
      LERROR(LESSCANF);
 
1038
      DEXIT;
 
1039
      return -1;
 
1040
   }
 
1041
 
 
1042
   if (bra[0] != '{' || comma[0] != ',' || ket[0] != '}') {
 
1043
      LERROR(LESYNTAX);
 
1044
      DEXIT;
 
1045
      return -1;
 
1046
   }
 
1047
 
 
1048
   dp->nm = nm;
 
1049
   dp->mt = mt;
 
1050
   dp->ht = NULL;
 
1051
 
 
1052
   DEXIT;
 
1053
   return 0;
 
1054
}
 
1055
 
 
1056
static int fGetInt(FILE *fp, int *ip) 
 
1057
{
 
1058
   char s[READ_LINE_LENGHT + 1];
 
1059
 
 
1060
   DENTER(CULL_LAYER, "fGetInt");
 
1061
 
 
1062
   if (!fp) {
 
1063
      LERROR(LEFILENULL);
 
1064
      DEXIT;
 
1065
      return -1;
 
1066
   }
 
1067
 
 
1068
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1069
      LERROR(LEFGETLINE);
 
1070
      DEXIT;
 
1071
      return -1;
 
1072
   }
 
1073
 
 
1074
   if (sscanf(s, "%d", ip) != 1) {
 
1075
      LERROR(LESSCANF);
 
1076
      DEXIT;
 
1077
      return -1;
 
1078
   }
 
1079
 
 
1080
   DEXIT;
 
1081
   return 0;
 
1082
}
 
1083
 
 
1084
static int fGetUlong(FILE *fp, lUlong *up) 
 
1085
{
 
1086
   char s[READ_LINE_LENGHT + 1];
 
1087
 
 
1088
   DENTER(CULL_LAYER, "fGetUlong");
 
1089
 
 
1090
   if (!fp) {
 
1091
      LERROR(LEFILENULL);
 
1092
      DEXIT;
 
1093
      return -1;
 
1094
   }
 
1095
 
 
1096
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1097
      LERROR(LEFGETLINE);
 
1098
      DEXIT;
 
1099
      return -1;
 
1100
   }
 
1101
 
 
1102
   if (sscanf(s, sge_u32, up) != 1) {
 
1103
      LERROR(LESSCANF);
 
1104
      DEXIT;
 
1105
      return -1;
 
1106
   }
 
1107
 
 
1108
   DEXIT;
 
1109
   return 0;
 
1110
}
 
1111
 
 
1112
static int fGetString(FILE *fp, lString *tp) 
 
1113
{
 
1114
   int i, j;
 
1115
   char line[READ_LINE_LENGHT + 1];
 
1116
   dstring sp = DSTRING_INIT;
 
1117
   const char *s;
 
1118
 
 
1119
   DENTER(CULL_LAYER, "fGetString");
 
1120
 
 
1121
   if (!fp) {
 
1122
      LERROR(LEFILENULL);
 
1123
      DEXIT;
 
1124
      return -1;
 
1125
   }
 
1126
   if (fGetLine(fp, line, READ_LINE_LENGHT)) {
 
1127
      LERROR(LEFGETLINE);
 
1128
      DEXIT;
 
1129
      return -1;
 
1130
   }
 
1131
   s = line;
 
1132
 
 
1133
   while (isspace((int) *s)) {
 
1134
      s++;
 
1135
   }
 
1136
   if (*s++ != '"') {
 
1137
      LERROR(LESYNTAX);
 
1138
      DEXIT;
 
1139
      return -1;
 
1140
   }
 
1141
   for (i = 0; s[i] != '\0' && s[i] != '"'; i++) {
 
1142
      if (s[i] == '\\') {
 
1143
         i++;
 
1144
      }
 
1145
      sge_dstring_append_char(&sp, s[i]);
 
1146
   }
 
1147
   if (s[i] != '"') {
 
1148
      bool done = false;
 
1149
      /* String is diveded by a newline */
 
1150
      while ( !done ) {
 
1151
         if (fGetLine(fp, line, READ_LINE_LENGHT)) {
 
1152
            sge_dstring_free(&sp);
 
1153
            LERROR(LEFGETLINE);
 
1154
            DEXIT;
 
1155
            return -1;
 
1156
         }
 
1157
         s = line;
 
1158
         for (j = 0; s[j] != '\0' && s[j] != '"'; j++, i++) {
 
1159
            sge_dstring_append_char(&sp, s[j]);
 
1160
         }
 
1161
         if (s[j] == '"') {
 
1162
            done = true;
 
1163
            break;
 
1164
         }
 
1165
      }
 
1166
   }
 
1167
 
 
1168
   s = sge_dstring_get_string(&sp);
 
1169
   if (s == NULL) {
 
1170
      *tp = strdup(""); 
 
1171
   } else {
 
1172
      *tp = strdup(s);
 
1173
   }
 
1174
 
 
1175
   sge_dstring_free(&sp);
 
1176
 
 
1177
   if (!(*tp)) {
 
1178
      LERROR(LESTRDUP);
 
1179
      DEXIT;
 
1180
      return -1;
 
1181
   }
 
1182
 
 
1183
   DEXIT;
 
1184
   return 0;
 
1185
}
 
1186
 
 
1187
static int fGetHost(FILE *fp, lHost *tp) 
 
1188
{
 
1189
   int i;
 
1190
   char line[READ_LINE_LENGHT + 1];
 
1191
   char sp[READ_LINE_LENGHT + 1];
 
1192
   char *s;
 
1193
 
 
1194
   DENTER(CULL_LAYER, "fGetHost");
 
1195
 
 
1196
   if (!fp) {
 
1197
      LERROR(LEFILENULL);
 
1198
      DEXIT;
 
1199
      return -1;
 
1200
   }
 
1201
 
 
1202
   if (fGetLine(fp, line, READ_LINE_LENGHT)) {
 
1203
      LERROR(LEFGETLINE);
 
1204
      DEXIT;
 
1205
      return -1;
 
1206
   }
 
1207
   s = line;
 
1208
 
 
1209
   while (isspace((int) *s))
 
1210
      s++;
 
1211
   if (*s++ != '"') {
 
1212
      LERROR(LESYNTAX);
 
1213
      DEXIT;
 
1214
      return -1;
 
1215
   }
 
1216
   for (i = 0; s[i] != '\0' && s[i] != '"'; i++)
 
1217
      sp[i] = s[i];
 
1218
   if (s[i] != '"') {
 
1219
      LERROR(LESYNTAX);
 
1220
      DEXIT;
 
1221
      return -1;
 
1222
   }
 
1223
   sp[i] = '\0';
 
1224
 
 
1225
   if (!(*tp = strdup(sp))) {
 
1226
      LERROR(LESTRDUP);
 
1227
      DEXIT;
 
1228
      return -1;
 
1229
   }
 
1230
 
 
1231
   DEXIT;
 
1232
   return 0;
 
1233
}
 
1234
 
 
1235
static int fGetFloat(FILE *fp, lFloat *flp) 
 
1236
{
 
1237
   char s[READ_LINE_LENGHT + 1];
 
1238
 
 
1239
   DENTER(CULL_LAYER, "fGetFloat");
 
1240
 
 
1241
   if (!fp) {
 
1242
      LERROR(LEFILENULL);
 
1243
      DEXIT;
 
1244
      return -1;
 
1245
   }
 
1246
 
 
1247
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1248
      LERROR(LEFGETLINE);
 
1249
      DEXIT;
 
1250
      return -1;
 
1251
   }
 
1252
 
 
1253
   if (sscanf(s, "%f", flp) != 1) {
 
1254
      LERROR(LESSCANF);
 
1255
      DEXIT;
 
1256
      return -1;
 
1257
   }
 
1258
 
 
1259
   DEXIT;
 
1260
   return 0;
 
1261
}
 
1262
 
 
1263
static int fGetDouble(FILE *fp, lDouble *dp) 
 
1264
{
 
1265
   char s[READ_LINE_LENGHT + 1];
 
1266
 
 
1267
   DENTER(CULL_LAYER, "fGetDouble");
 
1268
 
 
1269
   if (!fp) {
 
1270
      LERROR(LEFILENULL);
 
1271
      DEXIT;
 
1272
      return -1;
 
1273
   }
 
1274
 
 
1275
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1276
      LERROR(LEFGETLINE);
 
1277
      DEXIT;
 
1278
      return -1;
 
1279
   }
 
1280
 
 
1281
   if (sscanf(s, "%lf", dp) != 1) {
 
1282
      LERROR(LESSCANF);
 
1283
      DEXIT;
 
1284
      return -1;
 
1285
   }
 
1286
 
 
1287
   DEXIT;
 
1288
   return 0;
 
1289
}
 
1290
 
 
1291
static int fGetLong(FILE *fp, lLong *lp) 
 
1292
{
 
1293
   char s[READ_LINE_LENGHT + 1];
 
1294
 
 
1295
   DENTER(CULL_LAYER, "fGetLong");
 
1296
 
 
1297
   if (!fp) {
 
1298
      LERROR(LEFILENULL);
 
1299
      DEXIT;
 
1300
      return -1;
 
1301
   }
 
1302
 
 
1303
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1304
      LERROR(LEFGETLINE);
 
1305
      DEXIT;
 
1306
      return -1;
 
1307
   }
 
1308
 
 
1309
   if (sscanf(s, "%ld", lp) != 1) {
 
1310
      LERROR(LESSCANF);
 
1311
      DEXIT;
 
1312
      return -1;
 
1313
   }
 
1314
 
 
1315
   DEXIT;
 
1316
   return 0;
 
1317
}
 
1318
 
 
1319
static int fGetChar(FILE *fp, lChar *cp) 
 
1320
{
 
1321
   char s[READ_LINE_LENGHT + 1];
 
1322
 
 
1323
   DENTER(CULL_LAYER, "fGetChar");
 
1324
 
 
1325
   if (!fp) {
 
1326
      LERROR(LEFILENULL);
 
1327
      DEXIT;
 
1328
      return -1;
 
1329
   }
 
1330
 
 
1331
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1332
      LERROR(LEFGETLINE);
 
1333
      DEXIT;
 
1334
      return -1;
 
1335
   }
 
1336
 
 
1337
   if (sscanf(s, "%c", cp) != 1) {
 
1338
      LERROR(LESSCANF);
 
1339
      DEXIT;
 
1340
      return -1;
 
1341
   }
 
1342
 
 
1343
   DEXIT;
 
1344
   return 0;
 
1345
}
 
1346
 
 
1347
static int fGetBool(FILE *fp, lBool *cp) 
 
1348
{
 
1349
   char s[READ_LINE_LENGHT + 1];
 
1350
   int i = 0;
 
1351
 
 
1352
   DENTER(CULL_LAYER, "fGetBool");
 
1353
 
 
1354
   if (!fp) {
 
1355
      LERROR(LEFILENULL);
 
1356
      DEXIT;
 
1357
      return -1;
 
1358
   }
 
1359
 
 
1360
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1361
      LERROR(LEFGETLINE);
 
1362
      DEXIT;
 
1363
      return -1;
 
1364
   }
 
1365
 
 
1366
   if (sscanf(s, "%d", &i) != 1) {
 
1367
      LERROR(LESSCANF);
 
1368
      DEXIT;
 
1369
      return -1;
 
1370
   }
 
1371
 
 
1372
   *cp = i;
 
1373
 
 
1374
   DEXIT;
 
1375
   return 0;
 
1376
}
 
1377
 
 
1378
static int fGetList(FILE *fp, lList **lpp) 
 
1379
{
 
1380
   char s[READ_LINE_LENGHT + 1];
 
1381
 
 
1382
   DENTER(CULL_LAYER, "fGetList");
 
1383
 
 
1384
   if (fp == NULL) {
 
1385
      LERROR(LEFILENULL);
 
1386
      DEXIT;
 
1387
      return -1;
 
1388
   }
 
1389
 
 
1390
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1391
      LERROR(LEFGETLINE);
 
1392
      DEXIT;
 
1393
      return -1;
 
1394
   }
 
1395
   
 
1396
   if (strstr(s, "empty") != NULL)
 
1397
      *lpp = NULL;              /* empty sublist */
 
1398
   else {
 
1399
/*
 
1400
      if (strstr(s, "full") == 0) {
 
1401
         LERROR(LESYNTAX);
 
1402
         DEXIT;
 
1403
         return -1;
 
1404
      }
 
1405
*/
 
1406
      if ((*lpp = lUndumpList(fp, NULL, NULL)) == NULL) {
 
1407
         LERROR(LEUNDUMPLIST);
 
1408
         DEXIT;
 
1409
         return -1;
 
1410
      }
 
1411
   }
 
1412
 
 
1413
   DEXIT;
 
1414
   return 0;
 
1415
}
 
1416
 
 
1417
static int fGetObject(FILE *fp, lListElem **epp) 
 
1418
{
 
1419
   char s[READ_LINE_LENGHT + 1];
 
1420
 
 
1421
   DENTER(CULL_LAYER, "fGetObject");
 
1422
 
 
1423
   if (fp == NULL) {
 
1424
      LERROR(LEFILENULL);
 
1425
      DEXIT;
 
1426
      return -1;
 
1427
   }
 
1428
 
 
1429
   if (fGetLine(fp, s, READ_LINE_LENGHT)) {
 
1430
      LERROR(LEFGETLINE);
 
1431
      DEXIT;
 
1432
      return -1;
 
1433
   }
 
1434
 
 
1435
   if (strstr(s, "none") != NULL)
 
1436
      *epp = NULL;              /* no object stored */
 
1437
   else {
 
1438
      if (strstr(s, "object") == 0) {
 
1439
         LERROR(LESYNTAX);
 
1440
         DEXIT;
 
1441
         return -1;
 
1442
      }
 
1443
 
 
1444
      if ((*epp = lUndumpObject(fp)) == NULL) {
 
1445
         LERROR(LEUNDUMPELEM);
 
1446
         DEXIT;
 
1447
         return -1;
 
1448
      }
 
1449
      (*epp)->status = OBJECT_ELEM;
 
1450
   }
 
1451
 
 
1452
   DEXIT;
 
1453
   return 0;
 
1454
}