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 ep/src/conf.c between version 1.23 and 1.24

version 1.23, 2002/04/25 10:59:59 version 1.24, 2002/05/27 16:46:19
Line 1 
Line 1 
 /*  /*
  * $Id$   * $Id$
  */   */
   
   /* Includes {{{ */
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 15 
Line 17 
 #include "proclink.h"  #include "proclink.h"
 #include "message.h"  #include "message.h"
 #include "conf.h"  #include "conf.h"
   /* }}} */
   
 /*  /* Static variables {{{ */
  * Static variables  
  */  
 static char *section_boundaries[2]       = {"[", "]"};  static char *section_boundaries[2]       = {"[", "]"};
 static char *name_vs_stream_separator[4] = {".", "..", "-", NULL};  static char *name_vs_stream_separator[4] = {".", "..", "-", NULL};
 static char *global_str                  = "Global";  static char *global_str                  = "Global";
 static char *process_str                 = "Process";  static char *process_str                 = "Process";
   /* }}} */
   
   /* Options structures (used only with libcfg context) {{{ */
 /*  
  * Options structures (used only with libcfg context)  
  */  
   
 static struct conf_struct_global global_cfg;  static struct conf_struct_global global_cfg;
 static struct conf_struct_process process_cfg;  static struct conf_struct_process process_cfg;
   /* }}} */
   
 /*  /* Options contexts {{{ */
  * Options contexts  
  */  
   
 static CFG_CONTEXT global_context = NULL;  static CFG_CONTEXT global_context = NULL;
 static CFG_CONTEXT process_context = NULL;  static CFG_CONTEXT process_context = NULL;
   /* }}} */
   
 /*  /* Global options {{{ */
  * Global options  
  */  
   
 static struct cfg_option global_options[] = {  static struct cfg_option global_options[] = {
         {"help", 'h', NULL, CFG_BOOLEAN + CFG_MULTI, (void *) &(global_cfg.help), 0},          {"help", 'h', NULL, CFG_BOOLEAN + CFG_MULTI, (void *) &(global_cfg.help), 0},
         {"quiet", 'q', "quiet", CFG_BOOLEAN, (void *) &(global_cfg.quiet), 0},          {"quiet", 'q', "quiet", CFG_BOOLEAN, (void *) &(global_cfg.quiet), 0},
Line 52  static struct cfg_option global_options[
Line 46  static struct cfg_option global_options[
         {"disable-user-config",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.disable_user_config),0},          {"disable-user-config",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.disable_user_config),0},
         {"case-insensitive-names",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.case_insensitive_names),0},          {"case-insensitive-names",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.case_insensitive_names),0},
         CFG_END_OF_LIST          CFG_END_OF_LIST
 };  }; /* }}} */
   
 /*  
  * Process options  
  */  
   
   /* Process options {{{ */
 static struct cfg_option process_options[] = {  static struct cfg_option process_options[] = {
         {"nice", 'N', "nice", CFG_INT, (void *) &(process_cfg.nice), 0},          {"nice", 'N', "nice", CFG_INT, (void *) &(process_cfg.nice), 0},
         {"name", 'n', "name", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.name), 0},          {"name", 'n', "name", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.name), 0},
Line 66  static struct cfg_option process_options
Line 57  static struct cfg_option process_options
         {"errput", 'e', "errput", CFG_STRING+CFG_MULTI_SEPARATED, (void *)&(process_cfg.fd_str[2]),0},          {"errput", 'e', "errput", CFG_STRING+CFG_MULTI_SEPARATED, (void *)&(process_cfg.fd_str[2]),0},
         {NULL, '\0', "command", CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI_SEPARATED,(void *)&(process_cfg.argv),0},          {NULL, '\0', "command", CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI_SEPARATED,(void *)&(process_cfg.argv),0},
         CFG_END_OF_LIST          CFG_END_OF_LIST
 };  }; /* }}} */
   
 /*  
  * Static function declarations  
  */  
   
   /* Static function declarations {{{ */
 static void print_cfg_error(const CFG_CONTEXT con);  static void print_cfg_error(const CFG_CONTEXT con);
 static char *get_user_config_filename(void);  static char *get_user_config_filename(void);
 static void clear_global_cfg(void);  static void clear_global_cfg(void);
Line 93  static int add_processes_to_proctable(
Line 81  static int add_processes_to_proctable(
                 PROCTABLE *p_ptbl,                  PROCTABLE *p_ptbl,
                 struct conf_struct_process **processes,                  struct conf_struct_process **processes,
                 int start_idx_size, int *start_idx);                  int start_idx_size, int *start_idx);
   /* }}} */
   
 /*  /*
  * Function definitions   * Function definitions
  */   */
   
 /*  /*      PARSING SCHEME (do not delete) {{{
  *      PARSING SCHEME (do not delete)  
  *      ------------------------------   *      ------------------------------
  *   *
  *      conf_cmdline_parse_process();   *      conf_cmdline_parse_process();
Line 122  static int add_processes_to_proctable(
Line 110  static int add_processes_to_proctable(
  *                      fail;   *                      fail;
  *              }   *              }
  *      }   *      }
  */   */ /* }}} */
   
         int          int
 conf_init(void)  conf_init(void)
 {  {/* {{{ */
         return check_context(&global_context, global_options)          return check_context(&global_context, global_options)
                 && check_context(&process_context, process_options);                  && check_context(&process_context, process_options);
 }  } /* }}} */
   
         void          void
 conf_destroy(void)  conf_destroy(void)
 {  { /* {{{ */
         if (global_context != NULL)          if (global_context != NULL)
                 cfg_free_context(global_context);                  cfg_free_context(global_context);
         if (process_context != NULL)          if (process_context != NULL)
                 cfg_free_context(process_context);                  cfg_free_context(process_context);
 }  } /* }}} */
   
         PROCTABLE          PROCTABLE
 conf_parse_all(argc, argv)  conf_parse_all(argc, argv)
         int    argc;          int    argc;
         char   **argv;          char   **argv;
 {  { /* {{{ */
         register int ret, i;          register int ret, i;
         struct conf_struct_global *global;          struct conf_struct_global *global;
         struct conf_struct_global *global_work;          struct conf_struct_global *global_work;
Line 201  conf_parse_all(argc, argv)
Line 189  conf_parse_all(argc, argv)
                 register char *filename;                  register char *filename;
   
                 if ((i == 0 && global->disable_global_config)                  if ((i == 0 && global->disable_global_config)
                                 || (i == 1 && ! global->disable_user_config))                                  || (i == 1 && global->disable_user_config))
                         continue;                          continue;
   
                 filename = i <= 0 ? conf_global_filename                  filename = i <= 0 ? conf_global_filename
Line 278  conf_parse_all(argc, argv)
Line 266  conf_parse_all(argc, argv)
   
 #if DEBUG  #if DEBUG
         {          {
                 register int i;                  register int dbg_i;
                 register char *names;                  register char *names;
                 register char *argvs;                  register char *argvs;
   
Line 286  conf_parse_all(argc, argv)
Line 274  conf_parse_all(argc, argv)
   
                 msg_debug_print("verbose = %d\n", global->verbose);                  msg_debug_print("verbose = %d\n", global->verbose);
   
                 for (i = 0; processes != NULL && processes[i] != NULL; i++) {                  for (dbg_i = 0; processes != NULL && processes[dbg_i] != NULL; dbg_i++) {
   
                         if (processes[i]->name != NULL)                          if (processes[dbg_i]->name != NULL)
                                 names = strdyn_implode_str(processes[i]->name, ", ");                                  names = strdyn_implode_str(processes[dbg_i]->name, ", ");
                         else                          else
                                 names = strdup("-- N/A --");                                  names = strdup("-- N/A --");
   
                         if (processes[i]->argv != NULL)                          if (processes[dbg_i]->argv != NULL)
                                 argvs = strdyn_implode_str(processes[i]->argv, " ");                                  argvs = strdyn_implode_str(processes[dbg_i]->argv, " ");
                         else                          else
                                 argvs = strdup("-- N/A --");                                  argvs = strdup("-- N/A --");
   
                         msg_debug_print("Process %d\n", i);                          msg_debug_print("Process %d\n", dbg_i);
                         msg_debug_print("  NAMES: %s\n", names);                          msg_debug_print("  NAMES: %s\n", names);
                         msg_debug_print("  ARGVS: %s\n", argvs);                          msg_debug_print("  ARGVS: %s\n", argvs);
   
Line 307  conf_parse_all(argc, argv)
Line 295  conf_parse_all(argc, argv)
                 }                  }
   
                 msg_debug_print("Indexes:\n");                  msg_debug_print("Indexes:\n");
                 for (i = 0; i < start_idx_size; i++)                  for (dbg_i = 0; dbg_i < start_idx_size; dbg_i++)
                         msg_debug_print("  %d -> %d\n", i, start_idx[i]);                          msg_debug_print("  %d -> %d\n", dbg_i, start_idx[dbg_i]);
         }          }
 #endif  #endif
   
Line 344  conf_parse_all(argc, argv)
Line 332  conf_parse_all(argc, argv)
         free_processes(&processes);          free_processes(&processes);
   
         return ptbl;          return ptbl;
 }  } /* }}} */
   
         int          int
 conf_cfgfile_parse(filename, global, processes)  conf_cfgfile_parse(filename, global, processes)
         char                       *filename;          char                       *filename;
         struct conf_struct_global  **global;          struct conf_struct_global  **global;
         struct conf_struct_process ***processes;          struct conf_struct_process ***processes;
 {  { /* {{{ */
         register int ret;          register int ret;
         int processes_size;          int processes_size;
         CFG_CONTEXT cur_context;          CFG_CONTEXT cur_context;
Line 381  conf_cfgfile_parse(filename, global, pro
Line 369  conf_cfgfile_parse(filename, global, pro
                         break;                          break;
                 }                  }
                 else {                  else {
                         int sec_no;                          register int   section_no;
                         char *section_str;                          register char *section_str;
   
                         section_str = cfg_get_cur_opt(cur_context);                          section_str = cfg_get_cur_opt(cur_context);
                         sec_no = is_cfgfile_section(section_str);                          section_no  = is_cfgfile_section(section_str);
   
                         if (sec_no > 0) {                          if (section_no > 0) {
                                 if (cur_context == process_context) {                                  if (cur_context == process_context) {
                                         if (! add_process_cfg_to_processes(processes,                                          if (! add_process_cfg_to_processes(processes,
                                                                 &processes_size))                                                                  &processes_size))
Line 396  conf_cfgfile_parse(filename, global, pro
Line 384  conf_cfgfile_parse(filename, global, pro
                                         clear_process_cfg();                                          clear_process_cfg();
                                 }                                  }
   
                                 if (sec_no == 1) { /* [Global] section */                                  if (section_no == 1) { /* [Global] section */
                                         cfg_set_cfgfile_context(global_context,                                          cfg_set_cfgfile_context(global_context,
                                                         cfg_get_cur_idx(cur_context), 0, NULL);                                                          cfg_get_cur_idx(cur_context), 0, NULL);
                                         cur_context = global_context;                                          cur_context = global_context;
Line 410  conf_cfgfile_parse(filename, global, pro
Line 398  conf_cfgfile_parse(filename, global, pro
                         else {                          else {
                                 msg_error_print("unknown section '%s' in config file '%s'\n",                                  msg_error_print("unknown section '%s' in config file '%s'\n",
                                                 section_str, filename);                                                  section_str, filename);
                                 ret = CFG_ERROR_UNKNOWN;                                  ret = CFG_ERROR_STOP_STR; /* CFG_ERROR_UNKNOWN */
                                 break;                                  break;
                         }                          }
                 }                  }
Line 424  conf_cfgfile_parse(filename, global, pro
Line 412  conf_cfgfile_parse(filename, global, pro
         if (! add_global_cfg_to_global(global))          if (! add_global_cfg_to_global(global))
                 return CFG_ERR_NOMEM;                  return CFG_ERR_NOMEM;
   
         if (ret != CFG_OK && ret != CFG_ERR_NOMEM && ret != CFG_ERR_FILE_NOT_FOUND)          switch (ret) {
                 print_cfg_error(cur_context);                  case CFG_OK:
                   case CFG_ERR_NOMEM:
                   case CFG_ERR_FILE_NOT_FOUND:
                   case CFG_ERR_STOP_STR_FOUND:
                           break;
                   default:
                           print_cfg_error(cur_context);
                           break;
           };
   
         return ret;          return ret;
 }  } /* }}} */
   
         int          int
 conf_cmdline_parse(argc, argv, global, processes)  conf_cmdline_parse(argc, argv, global, processes)
Line 436  conf_cmdline_parse(argc, argv, global, p
Line 432  conf_cmdline_parse(argc, argv, global, p
         char                       **argv;          char                       **argv;
         struct conf_struct_global  **global;          struct conf_struct_global  **global;
         struct conf_struct_process ***processes;          struct conf_struct_process ***processes;
 {  { /* {{{ */
         register int ret = CFG_OK, first_loop, index;          register int ret = CFG_OK, first_loop, index;
         int processes_size;          int processes_size;
         CFG_CONTEXT cur_context;          CFG_CONTEXT cur_context;
Line 486  conf_cmdline_parse(argc, argv, global, p
Line 482  conf_cmdline_parse(argc, argv, global, p
                         }                          }
   
                         if (cur_context == process_context) {                          if (cur_context == process_context) {
                                 if (! add_process_cfg_to_processes(processes,                                  if (! add_process_cfg_to_processes(processes, &processes_size))
                                                         &processes_size))  
                                         return CFG_ERR_NOMEM;                                          return CFG_ERR_NOMEM;
   
                                 clear_process_cfg();                                  clear_process_cfg();
Line 497  conf_cmdline_parse(argc, argv, global, p
Line 492  conf_cmdline_parse(argc, argv, global, p
                         cur_context = process_context;                          cur_context = process_context;
                         cfg_set_cmdline_context(cur_context, argc - index, argv + index);                          cfg_set_cmdline_context(cur_context, argc - index, argv + index);
                 }                  }
                 else                  else {
                         break;                          break;
                   }
         }          }
   
         /* Set returning parameters. */          /* Set returning parameters. */
Line 511  conf_cmdline_parse(argc, argv, global, p
Line 507  conf_cmdline_parse(argc, argv, global, p
         if (! add_global_cfg_to_global(global))          if (! add_global_cfg_to_global(global))
                 return CFG_ERR_NOMEM;                  return CFG_ERR_NOMEM;
   
         if (ret != CFG_OK && ret != CFG_ERR_NOMEM)          switch (ret) {
                 print_cfg_error(cur_context);                  case CFG_OK:
                   case CFG_ERR_NOMEM:
                   case CFG_ERR_STOP_STR_FOUND:
                           break;
                   default:
                           print_cfg_error(cur_context);
                           break;
           };
   
         return ret;          return ret;
 }  } /* }}} */
   
 /*  /*
  * Static function definitions   * Static function definitions
Line 524  conf_cmdline_parse(argc, argv, global, p
Line 527  conf_cmdline_parse(argc, argv, global, p
         static void          static void
 print_cfg_error(con)  print_cfg_error(con)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
 {  { /* {{{ */
         register char *s;          register char *s;
   
         if ((s = cfg_get_error_str(con)) == NULL) {          if ((s = cfg_get_error_str(con)) == NULL) {
Line 536  print_cfg_error(con)
Line 539  print_cfg_error(con)
         free(s);          free(s);
   
         return;          return;
 }  } /* }}} */
   
         static char *          static char *
 get_user_config_filename(void)  get_user_config_filename(void)
 {  { /* {{{ */
         register char *homedir, *filename;          register char *homedir, *filename;
   
         if ((homedir = getenv("HOME")) == NULL)          if ((homedir = getenv("HOME")) == NULL)
Line 558  get_user_config_filename(void)
Line 561  get_user_config_filename(void)
         strcpy(filename + strlen(filename), conf_user_filename);          strcpy(filename + strlen(filename), conf_user_filename);
   
         return filename;          return filename;
 }  } /* }}} */
   
         static void          static void
 clear_global_cfg(void)  clear_global_cfg(void)
 {  { /* {{{ */
         memset((void *) &global_cfg, '\0',          memset((void *) &global_cfg, '\0',
                         sizeof(struct conf_struct_global));                          sizeof(struct conf_struct_global));
 }  } /* }}} */
   
         static void          static void
 clear_process_cfg(void)  clear_process_cfg(void)
 {  { /* {{{ */
         memset((void *) &process_cfg, '\0',          memset((void *) &process_cfg, '\0',
                         sizeof(struct conf_struct_process));                          sizeof(struct conf_struct_process));
 }  } /* }}} */
   
         static int          static int
 check_context(context, options)  check_context(context, options)
         CFG_CONTEXT       *context;          CFG_CONTEXT       *context;
         struct cfg_option options[];          struct cfg_option options[];
 {  { /* {{{ */
         if (*context == NULL) {          if (*context == NULL) {
                 if ((*context = cfg_get_context(options)) == NULL)                  if ((*context = cfg_get_context(options)) == NULL)
                         return 0;                          return 0;
Line 596  check_context(context, options)
Line 599  check_context(context, options)
         }          }
   
         return 1;          return 1;
 }  } /* }}} */
   
         static int          static int
 is_cfgfile_section(section_str)  is_cfgfile_section(section_str)
         char *section_str;          char *section_str;
 {  { /* {{{ */
         register int secstr_size = strlen(section_str);          register int secstr_size = strlen(section_str);
         register int secb0_size  = strlen(section_boundaries[0]);          register int secb0_size  = strlen(section_boundaries[0]);
         register int secb1_size  = strlen(section_boundaries[1]);          register int secb1_size  = strlen(section_boundaries[1]);
Line 635  is_cfgfile_section(section_str)
Line 638  is_cfgfile_section(section_str)
         }          }
   
         return ret;          return ret;
 }  } /* }}} */
   
         static void          static void
 free_global(global)  free_global(global)
         struct conf_struct_global **global;          struct conf_struct_global **global;
 {  { /* {{{ */
         if (*global == NULL)          if (*global == NULL)
                 return;                  return;
   
Line 648  free_global(global)
Line 651  free_global(global)
   
         free(*global);          free(*global);
         *global = NULL;          *global = NULL;
 }  } /* }}} */
   
         static void          static void
 free_processes(processes)  free_processes(processes)
         struct conf_struct_process ***processes;          struct conf_struct_process ***processes;
 {  { /* {{{ */
         register int i, j;          register int i, j;
   
         if (*processes == NULL)          if (*processes == NULL)
Line 671  free_processes(processes)
Line 674  free_processes(processes)
   
         free(*processes);          free(*processes);
         *processes = NULL;          *processes = NULL;
 }  } /* }}} */
   
         static int          static int
 get_processes_index_by_name(processes, name)  get_processes_index_by_name(processes, name)
         struct conf_struct_process **processes;          struct conf_struct_process **processes;
         char                       *name;          char                       *name;
 {  { /* {{{ */
         register int i;          register int i;
   
         for (i = 0; processes != NULL && processes[i] != NULL; i++)          for (i = 0; processes != NULL && processes[i] != NULL; i++)
Line 686  get_processes_index_by_name(processes, n
Line 689  get_processes_index_by_name(processes, n
                         return i;                          return i;
   
         return -1;          return -1;
 }  } /* }}} */
   
         static int          static int
 add_global_cfg_to_global(global)  add_global_cfg_to_global(global)
         struct conf_struct_global **global;          struct conf_struct_global **global;
 {  { /* {{{ */
         *global = (struct conf_struct_global *)          *global = (struct conf_struct_global *)
                 malloc(sizeof(struct conf_struct_global));                  malloc(sizeof(struct conf_struct_global));
         if (*global == NULL)          if (*global == NULL)
Line 700  add_global_cfg_to_global(global)
Line 703  add_global_cfg_to_global(global)
         **global = global_cfg;          **global = global_cfg;
   
         return 1;          return 1;
 }  } /* }}} */
   
         static int          static int
 add_process_cfg_to_processes(processes, size)  add_process_cfg_to_processes(processes, size)
         struct conf_struct_process ***processes;          struct conf_struct_process ***processes;
         int                        *size;          int                        *size;
 {  { /* {{{ */
         register int items;          register int items;
   
         for (items = 0; *processes != NULL && (*processes)[items] != NULL; items++)          for (items = 0; *processes != NULL && (*processes)[items] != NULL; items++)
Line 735  add_process_cfg_to_processes(processes,
Line 738  add_process_cfg_to_processes(processes,
         (*processes)[items + 1] = NULL;          (*processes)[items + 1] = NULL;
   
         return 1;          return 1;
 }  } /* }}} */
   
         static int          static int
 add_processes_to_processes(dest_processes, src_processes)  add_processes_to_processes(dest_processes, src_processes)
         struct conf_struct_process ***dest_processes;          struct conf_struct_process ***dest_processes;
         struct conf_struct_process **src_processes;          struct conf_struct_process **src_processes;
 {  { /* {{{ */
         register int i, dest_size, src_size;          register int i, dest_size, src_size;
   
         if (dest_processes == NULL)          if (dest_processes == NULL)
Line 766  add_processes_to_processes(dest_processe
Line 769  add_processes_to_processes(dest_processe
         (*dest_processes)[dest_size + src_size] = NULL;          (*dest_processes)[dest_size + src_size] = NULL;
   
         return 1;          return 1;
 }  } /* }}} */
   
 /*  /*
  * XXX: TODO: FIXME: reindexing proctable! remove +1 above too   * XXX: TODO: FIXME: reindexing proctable! remove +1 above too
Line 778  add_processes_to_proctable(p_ptbl, proce
Line 781  add_processes_to_proctable(p_ptbl, proce
         struct conf_struct_process **processes;          struct conf_struct_process **processes;
         int                        start_idx_size;          int                        start_idx_size;
         int                        *start_idx;          int                        *start_idx;
 {  { /* {{{ */
         register int i, j, k, idx;          register int i, j, k, idx;
         register int resource_idx = 0;          register int resource_idx = 0;
         register int ptbl_size, new_ptbl_size;          register int ptbl_size, new_ptbl_size;
Line 972  add_processes_to_proctable(p_ptbl, proce
Line 975  add_processes_to_proctable(p_ptbl, proce
         }          }
   
         return 0;          return 0;
 }  } /* }}} */
   
   /* Modeline for ViM {{{
    * vim:set ts=4:
    * vim600:fdm=marker fdl=0 fdc=0:
    * }}} */
   

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

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