Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Saturday, October 17, 2026

Diff for libcfg+/src/cfg+.c between version 1.30 and 1.31

version 1.30, 2002/04/10 13:51:46 version 1.31, 2002/04/10 23:57:17
Line 220  cfg_free_context(con)
Line 220  cfg_free_context(con)
 }  }
   
         void          void
 cfg_print_error(con, errorcode)  cfg_print_error(con, errorcode, fh)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         const int errorcode;          const int errorcode;
           FILE *fh;
 {  {
         char *s;          char *s;
   
           s = cfg_get_error_str(con, errorcode);
   
           if (s == NULL)
                   fputs("not enough memory for error printing", fh);
   
           fputs(s, fh);
           free(s);
   }
   
           char *
   cfg_get_error_str(con, errorcode)
           const CFG_CONTEXT con;
           const int errorcode;
   {
           char *s;
           char *str_type  = con->type == CFG_LINE ? "on command line" : "in config file";
           char *str_pos = con->type == CFG_LINE ? /* "near" */ "at position"
                   : (con->flags & CFG_FILE_LINE_USAGE ? "on line" : "at position");
           char *str_opt   = cfg_get_cur_opt(con);
           char *str_arg   = cfg_get_cur_arg(con);
           char *str_filename = con->filename;
           int idx = cfg_get_cur_idx(con);
           int size;
   
           /*
              char *str_idx;
              char tmp_buf[21];
   
              if (con->type == CFG_LINE) {
              str_idx = con->argv[cfg_get_cur_idx(con)];
              }
              else {
              sprintf(str_idx, "%.20s", cfg_get_cur_idx(con))
              }
              */
           str_opt = str_opt == NULL ? "" : str_opt;
           str_arg = str_arg == NULL ? "" : str_arg;
           str_filename = str_filename == NULL ? "" : str_filename;
   
           /* WARNING: pay attention on possible buffer owerflow here; used constant
              must be enough to cover str_type, str_pos, str_idx and the rest
              of error message with deliminators. */
   
   #ifndef max /* Borrowed from libplaton. */
   #define max(a, b) (((a) > (b)) ? (a) : (b))
   #endif
   
           size = 300 + max(strlen(str_opt) + strlen(str_arg), strlen(str_filename));
   
           if ((s = (char *) malloc(sizeof(char) * size)) == NULL)
                   return NULL;
   
         switch (errorcode) {          switch (errorcode) {
   
                 /* case CFG_ERR_OK: */                  /* case CFG_ERR_OK: */
                 /* case CFG_ERROR_OK: */                  /* case CFG_ERROR_OK: */
                 case CFG_OK:                  case CFG_OK:
                         s = "no error";                          sprintf(s, "no error on %s", str_type);
                         break;                          break;
   
                         /* case CFG_ERR_NOARG: */                          /* case CFG_ERR_NOARG: */
                 case CFG_ERROR_NOARG:                  case CFG_ERROR_NOARG:
                         s = "argument is missing for option";                          sprintf(s, "argument is missing for option '%s' %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_NOTALLOWEDARG: */                          /* case CFG_ERR_NOTALLOWEDARG: */
                 case CFG_ERROR_NOTALLOWEDARG:                  case CFG_ERROR_NOTALLOWEDARG:
                         s = "argument is not allowed for option";                          sprintf(s, "option '%s' does not have allowed argument %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_BADOPT: */                          /* case CFG_ERR_BADOPT: */
                 case CFG_ERROR_BADOPT:                  case CFG_ERROR_BADOPT:
                         s = "option's argument could not be parsed";                          sprintf(s, "argument '%s' for option '%s' could not be parsed"
                                           " %s %d %s",
                                           str_arg, str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_BADQUOTE: */                          /* case CFG_ERR_BADQUOTE: */
                 case CFG_ERROR_BADQUOTE:                  case CFG_ERROR_BADQUOTE:
                         s = "error in quotations";                          sprintf(s, "error in quotations in option '%s' %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_BADNUMBER: */                          /* case CFG_ERR_BADNUMBER: */
                 case CFG_ERROR_BADNUMBER:                  case CFG_ERROR_BADNUMBER:
                         s = "option could not be converted to appropriate numeric type";                          sprintf(s, "argument '%s' for option '%s' could not be converted"
                                           " to appropriate numeric type %s %d %s",
                                           str_arg, str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_OVERFLOW: */                          /* case CFG_ERR_OVERFLOW: */
                 case CFG_ERROR_OVERFLOW:                  case CFG_ERROR_OVERFLOW:
                         s = "given number was too big or too small";                          sprintf(s, "given number '%s' was too big or too small in option"
                                           " '%s' %s %d %s",
                                           str_arg, str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_MULTI: */                          /* case CFG_ERR_MULTI: */
                 case CFG_ERROR_MULTI:                  case CFG_ERROR_MULTI:
                         s = "multiple arguments used for single option";                          sprintf(s, "multiple arguments used for single option '%s' %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_NOMEM: */                          /* case CFG_ERR_NOMEM: */
                 case CFG_ERROR_NOMEM:                  case CFG_ERROR_NOMEM:
                         s = "not enough memory";                          sprintf(s, "not enough memory");
                         break;                          break;
   
                         /* case CFG_ERR_STOP_STR: */                          /* case CFG_ERR_STOP_STR: */
                         /* case CFG_ERR_STOP_STR_FOUND: */                          /* case CFG_ERR_STOP_STR_FOUND: */
                         /* case CFG_ERROR_STOP_STR: */                          /* case CFG_ERROR_STOP_STR: */
                 case CFG_ERROR_STOP_STR_FOUND:                  case CFG_ERROR_STOP_STR_FOUND:
                         s = "stop string was found";                          sprintf(s, "stop string '%s' was found %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_NOEQUAL: */                          /* case CFG_ERR_NOEQUAL: */
                 case CFG_ERROR_NOEQUAL:                  case CFG_ERROR_NOEQUAL:
                         s = "no equal sign on the line";                          sprintf(s, "no equal sign founded %s %d %s",
                                           str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_UNKNOWN: */                          /* case CFG_ERR_UNKNOWN: */
                 case CFG_ERROR_UNKNOWN:                  case CFG_ERROR_UNKNOWN:
                         s = "unknown option";                          sprintf(s, "unknown option '%s' %s %d %s",
                                           str_opt, str_pos, idx, str_type);
                         break;                          break;
   
                         /* case CFG_ERR_FILE_NOT_FOUND: */                          /* case CFG_ERR_FILE_NOT_FOUND: */
                 case CFG_ERROR_FILE_NOT_FOUND:                  case CFG_ERROR_FILE_NOT_FOUND:
                         s = "file not found";                          sprintf(s, "config file '%s' was not found", str_filename);
                         break;                          break;
   
                         /* case CFG_ERR_SEEK_ERROR: */                          /* case CFG_ERR_SEEK_ERROR: */
                 case CFG_ERROR_SEEK_ERROR:                  case CFG_ERROR_SEEK_ERROR:
                         s = "file seek error";                          sprintf(s, "seek error in config file '%s'", str_filename);
                         break;                          break;
   
                         /* case CFG_ERR_INTERNAL: */                          /* case CFG_ERR_INTERNAL: */
                 case CFG_ERROR_INTERNAL:                  case CFG_ERROR_INTERNAL:
                         s = "internal error";                          sprintf(s, "libcfg internal error");
                 default:                  default:
                         s = "unknown error";                          sprintf(s, "unknown error (%d)", errorcode);
                         break;                          break;
         }          }
   
         printf(s);          return s;
 }  }
   
         const char*          char *
 cfg_get_error_str(errorcode)  cfg_get_static_error_str(errorcode)
         const int errorcode;          const int errorcode;
 {  {
         switch (errorcode) {          switch (errorcode) {
Line 515  main(argc, argv)
Line 581  main(argc, argv)
                                         "|  Error printing  |\n"                                          "|  Error printing  |\n"
                                         "+------------------+");                                          "+------------------+");
   
                         printf("*****");                          printf("***** ");
                         cfg_print_error(con, ret);                          cfg_print_error(con, ret, stdout);
                         putchar('\n');                          putchar('\n');
   
                         printf("***** %s error %d at %d: %s\n",                          printf("***** %s error %d at %d: %s\n",
                                         i == 0 ? "cmdline" : "cfgfile",                                          i == 0 ? "cmdline" : "cfgfile",
                                         ret, cfg_get_cur_idx(con),                                          ret, cfg_get_cur_idx(con),
                                         cfg_get_error_str(ret));                                          cfg_get_static_error_str(ret));
   
                         printf("***** opt = '%s', arg = '%s'",                          printf("***** opt = '%s', arg = '%s'",
                                         cfg_get_cur_opt(con), cfg_get_cur_arg(con));                                          cfg_get_cur_opt(con), cfg_get_cur_arg(con));

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top