Пример #1
0
int conf_set(char *parameter, char *value)
{
    SETTING *s;
    if ((s = set_find(parameter)) == NULL)
    {   /* can only set existing settings */
        log(LOG_WARNING, "No such configuration symbol: %s", parameter);
        log(LOG_WARNING, "Assuming that %s is a setting of type STRING",parameter);
        set_add(SET_STRING, parameter, "");
        s = set_find(parameter);
    }

    switch (s->type)
    {
    case SET_BOOL:
        set_set(s, (strcmp(value, "yes") == 0 && atoi(value) == 1)?1:0);
        break;
    case SET_FLOAT:
        set_set(s, atof(value));
        break;
    case SET_INT:
        set_set(s, atol(value));
        break;
    case SET_STRING:
    case SET_LONGSTRING:
        set_set(s, value);
        break;
    }

    return 0;
}
Пример #2
0
static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
{
  char *name = newsplit(&buf);

  if (!name || !name[0])
    return 1;

  if (!strcasecmp(u->handle, conf.bot->nick)) {
    set_noshare = 1;
    var_set_by_name(conf.bot->nick, name, buf[0] ? buf : NULL);
    set_noshare = 0;
  /* var_set_by_name() called set_user(), no need to do it again... */
  } 
  /* not else if as the hub might have gotten a botset for itself */
  if (conf.bot->hub || conf.bot->localhub) {
  /* only hubs need to bother saving this stuff, leaf bots just store it in vars[] */
    struct xtra_key *xk = (struct xtra_key *) my_calloc(1, sizeof(struct xtra_key));

    xk->key = strdup(name);
    xk->data = (buf && buf[0]) ? strdup(buf) : NULL;
    set_set(u, e, xk);	/* set the USERENTRY */
  }
  return 1;
}
Пример #3
0
void detect_last_diagram_number(void)
{
   long l=0;
   FILE *input_file=NULL;
   char tmp[MAX_STR_LEN], *ptr;
   int i;
   long max_diagram_number;
      max_diagram_number = (sizeof(int) < 4 )?MAX_DIAGRAM_NUMBER_S:MAX_DIAGRAM_NUMBER_L;
      input_file=open_system_file(input_name);

      /* Go to the <end of input file>-100 -- we want to determine
      the number of diagram: */

       /*go to end of file:*/
      if(fseek(input_file, 0L, SEEK_END)) halt(DISKPROBLEM,NULL);
       /*get position:*/
      if((l=ftell(input_file))==-1) halt(DISKPROBLEM,NULL);
       /*go back for 100 bytes:*/
      if(fseek(input_file, (l>100)?(l-100):0L, SEEK_SET))
         halt(DISKPROBLEM,NULL);
      *tmp=0;l=0;
      do{
        if((i=s_pos("*--#] d",tmp))!=-1){
           ptr=tmp+i+7;
           while((*ptr!=':')&&(*ptr))ptr++;
           *ptr=0;
           sscanf(tmp+i+7,"%ld",&l);
        }
      }while(fgets(tmp, MAX_STR_LEN, input_file)!=NULL);
      close_file(&input_file);
      if(l==0)halt(CURRUPTEDINPUT,input_name);
      if(l>max_diagram_number)halt(MAXDIAGRAM,NULL);
      /* Now l == last diagran number.*/
      if(start_diagram==0)
         start_diagram=1;
      if((finish_diagram==0)||(finish_diagram>l))
         finish_diagram=l;
      if (start_diagram>finish_diagram){
         sprintf(tmp, WRRONGSTARTNUMBER,start_diagram,finish_diagram);
         halt(tmp,NULL);
      }
      /* Now we know size of the dmask*/
      dmask_size=l/250 + 1;
      dmask=get_mem(dmask_size,sizeof(set_of_char));
      if(xi_list_top!=NULL){
         struct list_struct *top=xi_list_top;
            while(top!=NULL){
               if(top->from < start_diagram)
                  top->from=start_diagram;
               if(top->to > finish_diagram)
                  top->to=finish_diagram;
               for(l=top->from;!(l>top->to);l++){
                 if(top->xi=='x')/*ATTENTION! We use inverse order!*/
                   set_set((l % 250),dmask[l / 250]);
                 else/*ATTENTION! We use inverse order!*/
                   set_del((l % 250),dmask[l / 250]);
               }
               xi_list_top=top->next;
               free_mem(&top);
               top=xi_list_top;
            }
      }
      if (is_bit_set(&mode,bitBROWS))
        diagram=get_mem(finish_diagram-start_diagram+1,
           sizeof(struct diagram_struct));
}/*detect_last_diagram_number*/
Пример #4
0
/* Processes one :set statement.  Returns zero on success. */
static int
process_option(const char arg[])
{
	char option[OPTION_NAME_MAX + 1];
	int err;
	const char *p;
	opt_t *opt;

	p = skip_alphas(arg);

	snprintf(option, p - arg + 1, "%s", arg);

	if(strcmp(option, "all") == 0)
	{
		print_options();
		return 0;
	}

	opt = get_option(option);
	if(opt == NULL)
	{
		text_buffer_addf("%s: %s", "Unknown option", arg);
		return 1;
	}

	err = 0;
	if(*p == '\0')
	{
		opt_t *o = find_option(option);
		if(o != NULL)
		{
			if(o->type == OPT_BOOL)
				err = set_on(opt);
			else
				err = set_print(o);
		}
		else if(strncmp(option, "no", 2) == 0)
		{
			err = set_off(opt);
		}
		else if(strncmp(option, "inv", 3) == 0)
		{
			err = set_inv(opt);
		}
	}
	else if(char_is_one_of(ENDING_CHARS, *p))
	{
		if(*(p + 1) != '\0')
		{
			text_buffer_addf("%s: %s", "Trailing characters", arg);
			return 1;
		}
		if(*p == '!')
			err = set_inv(opt);
		else if(*p == '?')
			err = set_print(opt);
		else
			err = set_reset(opt);
	}
	else if(strncmp(p, "+=", 2) == 0)
	{
		err = set_add(opt, p + 2);
	}
	else if(strncmp(p, "-=", 2) == 0)
	{
		err = set_remove(opt, p + 2);
	}
	else if(*p == '=' || *p == ':')
	{
		err = set_set(opt, p + 1);
	}
	else
	{
		text_buffer_addf("%s: %s", "Trailing characters", arg);
	}

	if(err)
	{
		text_buffer_addf("%s: %s", "Invalid argument", arg);
	}
	return err;
}