void diag_set(char what, const char *arg) { DIAG_INIT; switch (what) { const struct wordent *keywd; case 'y': diagopts.syslog = true; if (arg && arg[0]) { if ((keywd = keyw(facilitynames, arg, sizeof(facilitynames)/sizeof(struct wordent))) == NULL) { Error1("unknown syslog facility \"%s\"", arg); } else { diagopts.logfacility = (int)(size_t)keywd->desc; } } openlog(diagopts.progname, LOG_PID, diagopts.logfacility); if (diagopts.logfile != NULL && diagopts.logfile != stderr) { fclose(diagopts.logfile); } diagopts.logfile = NULL; break; case 'f': if (diagopts.logfile != NULL && diagopts.logfile != stderr) { fclose(diagopts.logfile); } if ((diagopts.logfile = fopen(arg, "a")) == NULL) { Error2("cannot open log file \"%s\": %s", arg, strerror(errno)); } break; case 's': if (diagopts.logfile != NULL && diagopts.logfile != stderr) { fclose(diagopts.logfile); } diagopts.logfile = stderr; break; /* logging to stderr is default */ case 'p': diagopts.progname = arg; openlog(diagopts.progname, LOG_PID, diagopts.logfacility); break; case 'd': --diagopts.msglevel; break; case 'u': diagopts.micros = true; break; default: msg(E_ERROR, "unknown diagnostic option %c", what); } }
int getcommtype(const char *commname) { struct wordent commnames[] = { { "pipes", (void *)XIOCOMM_PIPES }, { "pty", (void *)XIOCOMM_PTY }, { "ptys", (void *)XIOCOMM_PTYS }, { "socketpair", (void *)XIOCOMM_SOCKETPAIR }, { "socketpairs", (void *)XIOCOMM_SOCKETPAIRS }, { "tcp", (void *)XIOCOMM_TCP }, { "tcp4", (void *)XIOCOMM_TCP4 }, { "tcp4listen", (void *)XIOCOMM_TCP4_LISTEN }, { NULL } } ; const struct wordent *comm_ent; comm_ent = keyw((struct wordent *)commnames, commname, sizeof(commnames)/sizeof(struct wordent)); if (!comm_ent) { return -1; } return (int)comm_ent->desc; }
static xiosingle_t *xioparse_single(const char **addr) { xiofile_t *xfd; xiosingle_t *sfd; struct addrname *ae; const struct addrdesc *addrdesc = NULL; const char *ends[4+1]; const char *hquotes[] = { "'", NULL } ; const char *squotes[] = { "\"", NULL } ; const char *nests[] = { "'", "'", "(", ")", "[", "]", "{", "}", NULL } ; char token[512], *tokp; size_t len; int i; /* init */ i = 0; /*ends[i++] = xioopts.chainsep;*/ /* default: "|" */ ends[i++] = xioopts.pipesep; /* default: "!!" */ ends[i++] = ","/*xioopts.comma*/; /* default: "," */ ends[i++] = ":"/*xioopts.colon*/; /* default: ":" */ ends[i++] = NULL; if ((xfd = xioallocfd()) == NULL) { return NULL; } sfd = &xfd->stream; sfd->argc = 0; len = sizeof(token); tokp = token; if (nestlex(addr, &tokp, &len, ends, hquotes, squotes, nests, true, true, false) < 0) { Error2("keyword too long, in address \"%s%s\"", token, *addr); } *tokp = '\0'; /*! len? */ ae = (struct addrname *) keyw((struct wordent *)&addressnames, token, sizeof(addressnames)/sizeof(struct addrname)-1); if (ae) { addrdesc = ae->desc; /* keyword */ if ((sfd->argv[sfd->argc++] = strdup(token)) == NULL) { Error1("strdup(\"%s\"): out of memory", token); } } else { if (false) { ; #if WITH_FDNUM } else if (isdigit(token[0]&0xff) && token[1] == '\0') { Info1("interpreting address \"%s\" as file descriptor", token); addrdesc = &addr_fd; if ((sfd->argv[sfd->argc++] = strdup("FD")) == NULL) { Error("strdup(\"FD\"): out of memory"); } if ((sfd->argv[sfd->argc++] = strdup(token)) == NULL) { Error1("strdup(\"%s\"): out of memory", token); } /*! check argc overflow */ #endif /* WITH_FDNUM */ #if WITH_GOPEN } else if (strchr(token, '/')) { Info1("interpreting address \"%s\" as file name", token); addrdesc = &addr_gopen; if ((sfd->argv[sfd->argc++] = strdup("GOPEN")) == NULL) { Error("strdup(\"GOPEN\"): out of memory"); } if ((sfd->argv[sfd->argc++] = strdup(token)) == NULL) { Error1("strdup(\"%s\"): out of memory", token); } /*! check argc overflow */ #endif /* WITH_GOPEN */ } else { Error1("unknown device/address \"%s\"", token); /*!!! free something*/ return NULL; } } sfd->tag = XIO_TAG_RDWR; sfd->addr = addrdesc; while (!strncmp(*addr, xioopts.paramsep, strlen(xioopts.paramsep))) { *addr += strlen(xioopts.paramsep); len = sizeof(token); tokp = token; if (nestlex(addr, &tokp, &len, ends, hquotes, squotes, nests, true, true, false) != 0) { Error2("syntax error in address \"%s%s\"", token, *addr); } *tokp = '\0'; if ((sfd->argv[sfd->argc++] = strdup(token)) == NULL) { Error1("strdup(\"%s\"): out of memory", token); } } if (parseopts(addr, addrdesc->groups, &sfd->opts) < 0) { free(xfd); return NULL; } return sfd; }
int getToken (char tp[], char att[],int *Line) { char ch,ch_str[25],str[25],seps[15]=" \t\n,'\"<>",oper[]="*-;+={}()|<>/"; int j, ll; if(f1==NULL) { printf("file not found"); exit(0); } while( 1 ) { if( buff[0] != '\0') { ch=buff[0]; buff[0]='\0'; } else if ( (ch=fgetc(f1)) == EOF) return 1; for(j=0;j<=13;j++) { if(ch==oper[j]) if( i>0 ) { buff[0]=ch; str[i]='\0'; keyw(str, tp ,att); } else { ch_str[0]=ch; if ( (ch= fgetc(f1))==ch_str[0] ) {ch_str[1]=ch; ch_str[2]='\0';} else if ( ch_str[0]=='!' && ch=='=') {ch_str[1]=ch; ch_str[2]='\0';} else {ch_str[1]='\0'; buff[0]=ch;} if( ch_str[0]=='{' || ch_str[0]=='}' || ch_str[0]==';'|| ch_str[0]=='('|| ch_str[0]==')') strcpy(tp,"punctuator"); else strcpy(tp,"operator"); strcpy(att,ch_str); op++; i=-1; } } for(j=0;j<=14;j++) { if(i==-1) break; if(ch==seps[j]) { if(ch=='#') { ll=0; while(ch!='>') { ch=fgetc(f1); ch_str[ll]=ch; ll++; } printf("%s is a header file\n",ch_str); strcpy(tp,"header"); strcpy(att,ch_str); break; } if(ch=='\n') { (*Line)++; } if(ch=='\'') { ll=0; do { ch=fgetc(f1); ch_str[ll]=ch; ll++; } while(ch!='\''); ch_str[ll-1]='\0'; strcpy(tp,"charactor"); strcpy(att,ch_str); i=-1; break; } str[i]='\0'; keyw(str, tp ,att); } } if(i==-1) { i=0; break; } else if (i==-2) { i=0; } else { str[i]=ch; i++; } } //getch(); return 0; }