Diff for /libaitcfg/src/cfgprog.c between versions 1.1.2.3 and 1.1.2.4

version 1.1.2.3, 2025/01/30 14:34:25 version 1.1.2.4, 2025/01/30 23:55:08
Line 3 Line 3
   
   
 cfg_root_t cfg;  cfg_root_t cfg;
char cfgname[MAXPATHLEN], section[STRSIZ];char cfgname[MAXPATHLEN], outname[MAXPATHLEN], section[STRSIZ];
 FILE *out;
   
   
 static void  static void
Line 14  Usage(const char *prog) Line 15  Usage(const char *prog)
                 "==========================================\n"                  "==========================================\n"
                 " Syntax: %s [-options] <config> [attribute] [value]\n\n"                  " Syntax: %s [-options] <config> [attribute] [value]\n\n"
                 "\t-s <section>\tScope of attribute\n"                  "\t-s <section>\tScope of attribute\n"
                   "\t-o <file>\tWrite updated config to file\n"
                 "\t-w\t\tSet and write attribute\n"                  "\t-w\t\tSet and write attribute\n"
                 "\t-v\t\tVerbose, more -v more verbosity\n"                  "\t-v\t\tVerbose, more -v more verbosity\n"
                 "\t-h\t\tHelp, this help screen!\n",                   "\t-h\t\tHelp, this help screen!\n", 
Line 66  Set(const char *prog, int argc, char **argv) Line 68  Set(const char *prog, int argc, char **argv)
         EVERBS(1) printf("Set value %s for %s in scope %s from config %s\n",           EVERBS(1) printf("Set value %s for %s in scope %s from config %s\n", 
                         argv[1], argv[0], section, prog);                          argv[1], argv[0], section, prog);
   
           if (!*argv[1]) {
                   if (cfg_unsetAttribute(&cfg, section, argv[0]) < 1)
                           return 3;
           } else if (cfg_setAttribute(&cfg, section, argv[0], argv[1]) < 1)
                           return 3;
   
           if (*outname) {
                   out = fopen(outname, "w");
                   if (!out) {
                           printf("Error:: can't create file %s #%d - %s\n", 
                                           outname, errno, strerror(errno));
                           return 2;
                   }
           }
   
           if (cfgWriteConfigRaw(out, &cfg, 42)) {
                   printf("Error:: can't write config #%d - %s\n", 
                                   cfg_GetErrno(), cfg_GetError());
                   if (*outname)
                           fclose(out);
                   return 2;
           }
   
           if (*outname)
                   fclose(out);
         return 0;          return 0;
 }  }
   
Line 78  main(int argc, char **argv) Line 105  main(int argc, char **argv)
         const char *prog;          const char *prog;
         char *str;          char *str;
   
           out = stdout;
   
         if (!argv || !*argv)          if (!argv || !*argv)
                 prog = "cfgprog";                  prog = "cfgprog";
         else if (!(prog = strrchr(*argv, '/')))          else if (!(prog = strrchr(*argv, '/')))
Line 85  main(int argc, char **argv) Line 114  main(int argc, char **argv)
         else          else
                 prog++;                  prog++;
   
        while ((ch = getopt(argc, argv, "hvws:")) != -1)        while ((ch = getopt(argc, argv, "hvws:o:")) != -1)
                 switch (ch) {                  switch (ch) {
                           case 'o':
                                   strlcpy(outname, optarg, sizeof outname);
                                   break;
                         case 'w':                          case 'w':
                                 run = Set;                                  run = Set;
                                 break;                                  break;

Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>