Switch to unified view

a/src/utils/conftree.cpp b/src/utils/conftree.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.6 2006-03-22 14:25:46 dockes Exp $  (C) 2003 J.F.Dockes";
2
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.7 2006-11-08 06:56:41 dockes Exp $  (C) 2003 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
124
124
125
    }
125
    }
126
}
126
}
127
127
128
128
129
ConfSimple::ConfSimple(int readonly, bool tildexp)
130
{
131
    data = 0;
132
    dotildexpand = tildexp;
133
    status = readonly ? STATUS_RO : STATUS_RW;
134
}
135
129
ConfSimple::ConfSimple(string *d, int readonly, bool tildexp)
136
ConfSimple::ConfSimple(string *d, int readonly, bool tildexp)
130
{
137
{
131
    data = d;
138
    data = d;
132
    dotildexpand = tildexp;
139
    dotildexpand = tildexp;
133
    status = readonly ? STATUS_RO : STATUS_RW;
140
    status = readonly ? STATUS_RO : STATUS_RW;
...
...
263
    if (sortwalk(swalker, &output) != WALK_CONTINUE) {
270
    if (sortwalk(swalker, &output) != WALK_CONTINUE) {
264
        return 0;
271
        return 0;
265
    }
272
    }
266
    return 1;
273
    return 1;
267
    } else {
274
    } else {
268
  // ??
275
  // No backing store, no writing
269
    return 0;
276
    return 1;
270
    }
277
    }
271
}
278
}
272
279
273
int ConfSimple::erase(const string &nm, const string &sk)
280
int ConfSimple::erase(const string &nm, const string &sk)
274
{
281
{
...
...
296
    if (sortwalk(swalker, &output) != WALK_CONTINUE) {
303
    if (sortwalk(swalker, &output) != WALK_CONTINUE) {
297
        return 0;
304
        return 0;
298
    }
305
    }
299
    return 1;
306
    return 1;
300
    } else {
307
    } else {
301
  // ??
302
    return 0;
308
    return 1;
303
    }
309
    }
304
}
310
}
305
311
306
int ConfSimple::set(const char *nm, const char *value, const char *sk)
312
int ConfSimple::set(const char *nm, const char *value, const char *sk)
307
{
313
{
...
...
420
const char *longvalue = 
426
const char *longvalue = 
421
"Donnees012345678901234567890123456789012345678901234567890123456789AA"
427
"Donnees012345678901234567890123456789012345678901234567890123456789AA"
422
"0123456789012345678901234567890123456789012345678901234567890123456789FIN"
428
"0123456789012345678901234567890123456789012345678901234567890123456789FIN"
423
    ;
429
    ;
424
430
425
void stringtest() 
431
void memtest(ConfSimple &c) 
426
{
432
{
427
    string s;
428
    ConfSimple c(&s);
429
    cout << "Initial:" << endl;
433
    cout << "Initial:" << endl;
430
    c.list();
434
    c.list();
431
    if (c.set("nom", "avec nl \n 2eme ligne", "")) {
435
    if (c.set("nom", "avec nl \n 2eme ligne", "")) {
432
    fprintf(stderr, "set with embedded nl succeeded !\n");
436
    fprintf(stderr, "set with embedded nl succeeded !\n");
433
    exit(1);
437
    exit(1);
...
...
454
    "[-w]  : read/write test.\n"
458
    "[-w]  : read/write test.\n"
455
    "[-s]  : string parsing test. Filename must hold parm 'strings'\n"
459
    "[-s]  : string parsing test. Filename must hold parm 'strings'\n"
456
    "[-q] nm sect : subsection test: look for nm in 'sect' which can be ''\n"
460
    "[-q] nm sect : subsection test: look for nm in 'sect' which can be ''\n"
457
    "[-d] nm sect : delete nm in 'sect' which can be ''\n"
461
    "[-d] nm sect : delete nm in 'sect' which can be ''\n"
458
    "[-S] : string io test. No filename in this case\n"
462
    "[-S] : string io test. No filename in this case\n"
463
    "[-V] : volatile config test. No filename in this case\n"
459
    ;
464
    ;
460
465
461
void Usage() {
466
void Usage() {
462
    fprintf(stderr, "%s:%s\n", thisprog, usage);
467
    fprintf(stderr, "%s:%s\n", thisprog, usage);
463
    exit(1);
468
    exit(1);
...
...
467
#define OPT_w     0x2 
472
#define OPT_w     0x2 
468
#define OPT_q     0x4
473
#define OPT_q     0x4
469
#define OPT_s     0x8
474
#define OPT_s     0x8
470
#define OPT_S     0x10
475
#define OPT_S     0x10
471
#define OPT_d     0x20
476
#define OPT_d     0x20
477
#define OPT_V     0x40
472
478
473
int main(int argc, char **argv)
479
int main(int argc, char **argv)
474
{
480
{
475
    const char *nm = 0;
481
    const char *nm = 0;
476
    const char *sub = 0;
482
    const char *sub = 0;
...
...
483
    if (!(**argv))
489
    if (!(**argv))
484
        /* Cas du "adb - core" */
490
        /* Cas du "adb - core" */
485
        Usage();
491
        Usage();
486
    while (**argv)
492
    while (**argv)
487
        switch (*(*argv)++) {
493
        switch (*(*argv)++) {
488
      case 'w':   op_flags |= OPT_w; break;
489
      case 's':   op_flags |= OPT_s; break;
490
      case 'S':   op_flags |= OPT_S; break;
491
        case 'd':   
494
        case 'd':   
492
        op_flags |= OPT_d;
495
        op_flags |= OPT_d;
493
        if (argc < 3)  
496
        if (argc < 3)  
494
            Usage();
497
            Usage();
495
        nm = *(++argv);argc--;
498
        nm = *(++argv);argc--;
...
...
500
        if (argc < 3)  
503
        if (argc < 3)  
501
            Usage();
504
            Usage();
502
        nm = *(++argv);argc--;
505
        nm = *(++argv);argc--;
503
        sub = *(++argv);argc--;       
506
        sub = *(++argv);argc--;       
504
        goto b1;
507
        goto b1;
508
      case 's':   op_flags |= OPT_s; break;
509
      case 'S':   op_flags |= OPT_S; break;
510
      case 'V':   op_flags |= OPT_S; break;
511
      case 'w':   op_flags |= OPT_w; break;
505
512
506
        default: Usage();   break;
513
        default: Usage();   break;
507
        }
514
        }
508
    b1: argc--; argv++;
515
    b1: argc--; argv++;
509
    }
516
    }
510
517
511
    if ((op_flags & OPT_S)) {
518
    if ((op_flags & OPT_S)) {
512
    if (argc != 0)
519
    if (argc != 0)
513
        Usage();
520
        Usage();
514
    stringtest();
521
    string s;
522
  ConfSimple c(&s);
523
  memtest(c);
524
    } else if  ((op_flags & OPT_V)) {
525
  if (argc != 0)
526
      Usage();
527
  string s;
528
  ConfSimple c;
529
  memtest(c);
515
    } else {
530
    } else {
516
    if (argc < 1)
531
    if (argc < 1)
517
        Usage();
532
        Usage();
518
533
519
    const char *filename = *argv++;argc--;
534
    const char *filename = *argv++;argc--;