2 parse.c - General string parsing routines.
3 Copyright 1999 Jonathan McDowell for Project Purple
5 19/09/1999 - Started writing.
14 struct strll *addtoend(struct strll *current, char *newstr)
16 struct strll *new, *tmp;
18 if ((new=malloc(sizeof(struct strll)))==NULL) {
30 while (tmp->next!=NULL) tmp=tmp->next;
37 int parseline(struct cfginf commands[], const char *commandline)
41 char command[CMDLEN], *pos=NULL;
44 if (commands==NULL || commandline==NULL || strlen(commandline)==0) return 0;
46 if ((params=strdup(commandline))==NULL) {
50 while (params[strlen(params)-1]<' ') params[strlen(params)-1]=0;
52 if ((pos=strchr(params, ' '))!=NULL) {
54 if (strlen(params)>=CMDLEN) {
55 /* Hah. No buffer overflow here. (Egg on face approaching....) */
59 strncpy(command, params, CMDLEN);
61 memmove(params, pos+1, strlen(commandline)-strlen(params));
63 if (strlen(params)>=CMDLEN) {
64 /* Hah. No buffer overflow here. (Egg on face approaching....) */
68 strncpy(command, params, CMDLEN);
72 while (strlen(commands[loop].command)>0 && strcasecmp(command, commands[loop].command)!=0) {
76 if (strlen(commands[loop].command)==0) {
79 if (commands[loop].type==0 && params==NULL) {
82 switch (commands[loop].type) {
83 case 1: *((char **) commands[loop].var) = params;
85 case 2: *((int *) commands[loop].var) = str2bool(params);
88 case 3: *((int *) commands[loop].var) = atoi(params);
91 case 4: *((struct strll **) commands[loop].var) = addtoend(*((struct strll **) commands[loop].var), params);
101 int str2bool(const char *buf)
103 if (strcasecmp("TRUE", buf) == 0 || strcmp("1", buf) == 0 ||
104 strcasecmp("Y", buf) == 0 || strcasecmp("YES", buf) == 0 ||
105 strcasecmp("T", buf) == 0) return 1;
107 if (strcasecmp("FALSE", buf) == 0 || strcmp("0", buf) == 0 ||
108 strcasecmp("N", buf) == 0 || strcasecmp("NO", buf) == 0 ||
109 strcasecmp("F", buf) == 0) return 0;