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.5 2006-01-23 13:32:28 dockes Exp $  (C) 2003 J.F.Dockes";
2
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.6 2006-03-22 14:25:46 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
...
...
199
    map<string, string>::iterator s;
199
    map<string, string>::iterator s;
200
    if ((s = ss->second.find(nm)) == ss->second.end()) 
200
    if ((s = ss->second.find(nm)) == ss->second.end()) 
201
    return 0;
201
    return 0;
202
    value = s->second;
202
    value = s->second;
203
    return 1;
203
    return 1;
204
}
205
 
206
const char *ConfSimple::get(const char *nm, const char *sk)
207
{
208
    if (status == STATUS_ERROR)
209
  return 0;
210
    if (sk == 0)
211
  sk = "";
212
    // Find submap
213
    map<string, map<string, string> >::iterator ss;
214
    if ((ss = submaps.find(sk)) == submaps.end()) 
215
  return 0;
216
217
    // Find named value
218
    map<string, string>::iterator s;
219
    if ((s = ss->second.find(nm)) == ss->second.end()) 
220
  return 0;
221
    return (s->second).c_str();
222
}
204
}
223
205
224
static ConfSimple::WalkerCode swalker(void *f, const string &nm, 
206
static ConfSimple::WalkerCode swalker(void *f, const string &nm, 
225
                      const string &value)
207
                      const string &value)
226
{
208
{
...
...
538
520
539
    if (op_flags & OPT_w) {
521
    if (op_flags & OPT_w) {
540
        ConfSimple parms(filename);
522
        ConfSimple parms(filename);
541
        if (parms.getStatus() != ConfSimple::STATUS_ERROR) {
523
        if (parms.getStatus() != ConfSimple::STATUS_ERROR) {
542
        // It's ok for the file to not exist here
524
        // It's ok for the file to not exist here
543
      
525
      string value;
544
      const char *cp = parms.get("mypid");
526
      
545
      if (cp) {
527
      if (parms.get("mypid", value)) {
546
            printf("Value for mypid is '%s'\n", cp);
528
            printf("Value for mypid is '%s'\n", value.c_str());
547
        } else {
529
        } else {
548
            printf("mypid not set\n");
530
            printf("mypid not set\n");
549
        }
531
        }
550
      cp = parms.get("unstring");
532
      
551
      if (cp) {
533
      if (parms.get("unstring", value)) {
552
            printf("Value for unstring is '%s'\n", cp);
534
            printf("Value for unstring is '%s'\n", value.c_str());
553
        } else {
535
        } else {
554
            printf("unstring not set\n");
536
            printf("unstring not set\n");
555
      }
556
      string myval;
557
      if (parms.get(string("unstring"), myval, "")) {
558
          printf("std::string value for 'unstring' is '%s'\n", 
559
             myval.c_str());
560
      } else {
561
          printf("unstring not set (std::string)\n");
562
        }
537
        }
563
        }
538
        }
564
        char spid[100];
539
        char spid[100];
565
        sprintf(spid, "%d", getpid());
540
        sprintf(spid, "%d", getpid());
566
        parms.set("mypid", spid);
541
        parms.set("mypid", spid);