/** * Find a boolean option (like quiet,noapic,nosmp....) * * @cmdline: the cmdline string * @option: option string to look for * * Returns the position of that @option (starts counting with 1) * or 0 on not found. */ int cmdline_find_option_bool(const char *cmdline, const char *option) { char c; int len, pos = 0, wstart = 0; const char *opptr = NULL; enum { st_wordstart = 0, /* Start of word/after whitespace */ st_wordcmp, /* Comparing this word */ st_wordskip, /* Miscompare, skip */ } state = st_wordstart; if (!cmdline) return -1; /* No command line */ len = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE); if (!len) return 0; while (len--) { c = *(char *)cmdline++; pos++; switch (state) { case st_wordstart: if (!c) return 0; else if (myisspace(c)) break; state = st_wordcmp; opptr = option; wstart = pos; /* fall through */ case st_wordcmp: if (!*opptr) if (!c || myisspace(c)) return wstart; else state = st_wordskip; else if (!c) return 0; else if (c != *opptr++) state = st_wordskip; else if (!len) /* last word and is matching */ return wstart; break; case st_wordskip: if (!c) return 0; else if (myisspace(c)) state = st_wordstart; break; } } return 0; /* Buffer overrun */ }
int cmdline_find_option_bool(const char *option) { u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr; addr_t cptr; char c; int pos = 0, wstart = 0; const char *opptr = NULL; enum { st_wordstart, st_wordcmp, st_wordskip, } state = st_wordstart; if (!cmdline_ptr || cmdline_ptr >= 0x100000) return -1; cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000) { c = rdfs8(cptr++); pos++; switch (state) { case st_wordstart: if (!c) return 0; else if (myisspace(c)) break; state = st_wordcmp; opptr = option; wstart = pos; case st_wordcmp: if (!*opptr) if (!c || myisspace(c)) return wstart; else state = st_wordskip; else if (!c) return 0; else if (c != *opptr++) state = st_wordskip; break; case st_wordskip: if (!c) return 0; else if (myisspace(c)) state = st_wordstart; break; } } return 0; }
/* * Find a boolean option (like quiet,noapic,nosmp....) * * Returns the position of that option (starts counting with 1) * or 0 on not found */ int __cmdline_find_option_bool(u32 cmdline_ptr, const char *option) { addr_t cptr; char c; int pos = 0, wstart = 0; const char *opptr = NULL; enum { st_wordstart, /* Start of word/after whitespace */ st_wordcmp, /* Comparing this word */ st_wordskip, /* Miscompare, skip */ } state = st_wordstart; if (!cmdline_ptr || cmdline_ptr >= 0x100000) return -1; /* No command line, or inaccessible */ cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000) { c = rdfs8(cptr++); pos++; switch (state) { case st_wordstart: if (!c) return 0; else if (myisspace(c)) break; state = st_wordcmp; opptr = option; wstart = pos; /* fall through */ case st_wordcmp: if (!*opptr) if (!c || myisspace(c)) return wstart; else state = st_wordskip; else if (!c) return 0; else if (c != *opptr++) state = st_wordskip; break; case st_wordskip: if (!c) return 0; else if (myisspace(c)) state = st_wordstart; break; } } return 0; /* Buffer overrun */ }
/* mostly duplicated from cvs/src/ignore.c */ static void ign_add(const char* ign, std::vector<std::string>& ignlist) { if (!ign || !*ign) return; int ign_hold = ignlist.empty() ? -1 : (int) ignlist.size(); bool escape = false; for (; *ign; ign++) { /* ignore whitespace before the token */ if (myisspace(*ign)) continue; /* * if we find a single character !, we must re-set the ignore list * (saving it if necessary). We also catch * as a special case in a * global ignore file as an optimization */ char next = *(ign+1); if ((!*(ign+1) || myisspace(*(ign+1))) && (*ign == '!' || *ign == '*')) { /* temporarily reset the ignore list */ if (ign_hold >= 0) { ignlist.erase(ignlist.begin(), ignlist.begin() + ign_hold); ign_hold = -1; } continue; } // Find the end of this token, treating "\ " as an escaped space const char* mark; escape = false; for (mark = ign; *mark && (escape || !myisspace(*mark)); mark++) { escape = false; if (*mark == '\\') escape = true; } std::string token(ign, mark-ign); FindAndReplace<std::string>(token, "\\\\", "\\"); ignlist.push_back(token); if (*mark) ign = mark; else ign = mark - 1; } }
int picolParseSep(picolParser *p) { p->start = p->p; while(myisspace(*p->p) || (*p->p=='\\' && *(p->p+1)=='\n')) { p->p++; p->len--; } RETURN_PARSED(PT_SEP); }
int myatoi(char s[]) { int i; int sign = 1; int num = 0; for(i = 0; myisspace(s[i]); i++) ; if(s[i] == '-') { sign = -1; i++; } else if(s[i] == '+') { sign = 1; i++; } for(; s[i] != '\0'; i++) { if(myisdigit(s[i])) num = num*10 + (s[i] - '0'); else { printf("unexpect token \'%c\'\n",s[i]); return 0; } printf("%d: %d\n",i,num); } return sign * num; }
int Formula::eval_mul(char *&s, Args *args, bool *vars) const { int left = eval_atom(s, args, vars); while (*s) { if (myisspace(*s)) { ++s; } else if(*s == '*') { left *= eval_atom(++s, args, vars); } else if(*s == '/') { if (int right = eval_atom(++s, args, vars)) left /= right; } else if(*s == '%') { if (int right = eval_atom(++s, args, vars)) left %= right; } else { break; } } return left; }
int Formula::eval_neq(char *&s, Args *args, bool *vars) const { int left = eval_sum(s, args, vars); while (*s) { if (myisspace(*s)) { ++s; } else if (*s == '<') { // this is needed due to side effects caused by min() macro... int tmp = eval_sum(++s, args, vars); left = min(left, tmp); } else if (*s == '>') { // this is needed due to side effects caused by max() macro... int tmp = eval_sum(++s, args, vars); left = max(left, tmp); } else { break; } } return left; }
int Formula::eval_atom(char *&s, Args *args, bool *vars) const { while (*s) { if (myisspace(*s)) { ++s; } else if (*s == '(') { int res = eval_neq(++s, args, vars); if (*s == ')') ++s; return res; } else if ((*s == '+') || (*s == '-')) { int sign = 1; if (*s == '-') sign = -1; return sign * eval_neq(++s, args, vars); } else if (*s == '!') { return !eval_neq(++s, args, vars); } else if ((*s >= '0') && (*s <= '9')) { int res = 0; while ((*s >= '0') && (*s <= '9')) res = res * 10 + *s++ - '0'; return res; } else { if (!args) return 0; char buf[1024]; char *bufptr = buf; while (((*s >= '0') && (*s <= '9')) || ((*s >= 'a') && (*s <= 'z')) || ((*s >= 'A') && (*s <= 'A')) || (*s == '_') || (*s == '.')) *bufptr++ = *s++; *bufptr = 0; int res = args->get(buf); if (vars) *vars = true; return res; } } return 0; }
int Formula::eval_sum(char *&s, Args *args, bool *vars) const { int left = eval_mul(s, args, vars); while (*s) { if (myisspace(*s)) { ++s; } else if (*s == '+') { left += eval_mul(++s, args, vars); } else if (*s == '-') { left -= eval_mul(++s, args, vars); } else { break; } } return left; }
/* * Find a non-boolean option, that is, "option=argument". In accordance * with standard Linux practice, if this option is repeated, this returns * the last instance on the command line. * * Returns the length of the argument (regardless of if it was * truncated to fit in the buffer), or -1 on not found. */ int __cmdline_find_option(u32 cmdline_ptr, const char *option, char *buffer, int bufsize) { addr_t cptr; char c; int len = -1; const char *opptr = NULL; char *bufptr = buffer; enum { st_wordstart, /* Start of word/after whitespace */ st_wordcmp, /* Comparing this word */ st_wordskip, /* Miscompare, skip */ st_bufcpy /* Copying this to buffer */ } state = st_wordstart; if (!cmdline_ptr || cmdline_ptr >= 0x100000) return -1; /* No command line, or inaccessible */ cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000 && (c = rdfs8(cptr++))) { switch (state) { case st_wordstart: if (myisspace(c)) break; /* else */ state = st_wordcmp; opptr = option; /* fall through */ case st_wordcmp: if (c == '=' && !*opptr) { len = 0; bufptr = buffer; state = st_bufcpy; } else if (myisspace(c)) { state = st_wordstart; } else if (c != *opptr++) { state = st_wordskip; } break; case st_wordskip: if (myisspace(c)) state = st_wordstart; break; case st_bufcpy: if (myisspace(c)) { state = st_wordstart; } else { if (len < bufsize-1) *bufptr++ = c; len++; } break; } } if (bufsize) *bufptr = '\0'; return len; }
int picolParseEol(picolParser *p) { p->start = p->p; while(myisspace(*p->p) || *p->p == ';') { p->p++; p->len--; } RETURN_PARSED(PT_EOL); }
/************************************************************** * NAME * loadent * ARGS * infile - file to load from * outfile - file to output noload records to * DESCR * Load an entry into the structures. * RETRN * Pointer to entry structure, NULL at eof or error. */ char *loadent( FILE *infile, FILE *outfile ) { char *endent; /* End of entry */ int recmark_in; /* Note record marker already in */ int noload; /* TRUE if noload marker detected in record 0.2q BJY */ if ( eofseen ) /* If eof seen last time */ return( NULL ); /* Return eof */ endent = dicent; /* Init end of entry */ *endent++ = '\n'; /* 0.2l BJY start record with nl */ *endent = '\0'; /* Init entry content to null */ recmark_in = FALSE; /* Init record mark in */ noload = FALSE; /* begin 0.2q BJY */ while ( TRUE ) { #ifdef NO_NOLOAD /* 0.2s BJY */ if ( recmark_in && ( !strncmp( noloadmark, line, noloadmarklen ) /* may be a nl after */ && myisspace( *(line+noloadmarklen) ) ) ) /* marker instead of space */ { noload = TRUE; /* signal finding a noload record */ } #endif if ( !strncmp( recmark, line, recmarklen ) ) /* If line is record mark */ { if ( !recmark_in ) /* If no rec mark in yet */ recmark_in = TRUE; /* Remember this one */ #ifdef NO_NOLOAD /* 0.2s BJY */ else if ( noload ) /* begin 0.2q BJY */ { fputs( dicent + 1, outfile ); /* output noload record now */ endent = dicent; /* reinitialize for new record */ *endent++ = '\n'; /* 0.2l BJY start record with nl */ *endent = '\0'; noload = FALSE; /* end 0.2q BJY */ } #endif else /* Else return entry */ break; } #ifdef JUNK /* Leave Shoebox number line in */ if ( strncmp( "\\_no", line, 4 ) ) /* If not shoebox number field */ #endif { strcpy( endent, line ); /* Copy line into entry */ endent += strlen( line ); /* Update end of entry */ } /* * The following tests for overflow of entry, which should * never happen. But if it does, the code tries to make * sure the dictionary is not mangled. */ if ( endent > endent_max ) /* If overflow of entry */ break; /* Return first part */ if ( !fgets ( line, MAXLINE, infile ) ) /* Get next line */ { eofseen = TRUE; /* If none, remember eof */ if ( recmark_in && noload ) /* begin 0.2q BJY */ { /* don't process the last record */ fputs( dicent + 1, outfile ); /* output noload record now */ *(dicent+1) = '\0'; /* return blank record */ } /* end 0.2q BJY */ break; } } return( dicent ); }
/************************************************************** * NAME * applyrules * ARGS * rules - list of rules to apply * dicent - entry to apply rules to * DESC * Apply rules to dic entry to add allomorphs. * RETN * Pointer to modified entry. * * Major mods 5/95 0.2r BJY moved code into new func apply_rule() */ char *applyrules( Rule *rules, char *dicent ) { Allo *al; /* temporary allo pointer */ Rule *ru; /* Temp rule */ char *s, *t; /* Temp string pointer */ int i; /* Index for cat array */ char *base; /* Base form */ char remchar; /* Removed char */ char *alloname; if ( !rules ) /* If no rules, return */ return( dicent ); num_apps = 0; /* Clear number of rules applied */ allolist = NULL; /* Clear list of allos already in entry */ newallolist = NULL; /* 0.2r BJY */ s = strnlstr( dicent, basemark ); /* Find base */ /* 0.2l BJY */ if ( !s ) /* If no base, return */ return( dicent ); s += basemarklen; /* Move to start of base */ /* Find end of base */ for ( t = s; /* Stop at space or cutoff char */ *t && !myisspace( *t ) && !( *t == cut_char ); t++ ); remchar = *t; /* Remember char after base */ *t = '\0'; /* Terminate base */ base = mystrdup( s ); /* Copy base */ *t = remchar; /* Restore char after base */ s = strnlstr( dicent, catmark ); /* Find category line */ /* 0.2l BJY */ if ( !s ) /* If no cat, use null */ cat[0] = NULL; else { for ( t = s; *t && !(*t == comment_char) && !(*t == '\n'); t++ ) /* Find comment or end of line */ ; remchar = *t; /* Remember char */ *t = '\0'; /* Cut off commment, if any */ s = mystrdup( s ); /* Copy cat line */ *t = remchar; /* Restore char after cats */ i = 0; /* Init index */ while ( *(s = nextwd( s ) ) ) /* While another cat */ cat[i++] = s; /* Remember it */ cat[i] = NULL; /* Terminate list with null */ } /* Make a list of allos already in entry */ allolist = NULL; /* Clear list of allos */ s = dicent - 1; while ( (s = strnlstr( s + 1, allomark )) != NULL ) /* While another allo */ /* 0.2l BJY */ { s += allomarklen; /* Move to start of allo */ s = skipwhite(s); /* wm: 0.2k: skip white space */ for ( t = s; *t && !myisspace( *t ); t++ ) /* Find end of allo */ ; remchar = *t; /* Remember char after allo */ *t = '\0'; /* Terminate allo */ add_allo( s ); /* Add allo to list */ *t = remchar; /* Restore char after allo */ } for ( ru = rules; ru; ru = ru->next ) /* For each rule */ { /* begin 0.2r BJY */ if ( *ru->match || *ru->repl ) /* don't apply 0 -> 0 rule to new allos */ { for ( al = newallolist; al; al = al->next ) { /* now try on each PHONRULE generated allo */ /* for ( s = al->name; s && !myisspace( *s ); s++)*/ /* find end of name */ /* ;*/ s = strchr( al->name, ' ' ); if ( s ) *s = '\0'; alloname = mystrdup( al->name ); if ( s ) *s = ' '; /* restore space */ apply_rule( alloname, ru, dicent, al ); } } base = apply_rule( base, ru, dicent, NULL ); /* try rule on base word */ /* set base in case changed by base rule 0.2s BJY */ } /* end 0.2r BJY */ if ( base_becomes_allo /* If allo is base */ && !in_allolist( base ) ) /* And not already in */ insert_line( allomark, base, after_allos( dicent ) ); /* Insert it into the entry */ num_ents++; /* Count sentence */ if ( do_monitor ) /* If monitor, give dot */ { if (num_apps == 0) /* hab 0.2p Conformed to standard practice */ putc('.', stderr); else if (num_apps < 10) putc('0'+num_apps, stderr); else putc('>', stderr); if ( num_ents % 100 == 0 ) /* wm 0.2k: number by 100s */ fprintf( stderr, " %5d", num_ents ); if ( num_ents % 10 == 0 ) fprintf( stderr, " " ); if ( num_ents % 50 == 0 ) fprintf( stderr, "\n" ); } return( dicent ); /* Return modified sent */ } /* function applyrules */
int cmdline_find_option(const char *option, char *buffer, int bufsize) { u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr; addr_t cptr; char c; int len = -1; const char *opptr = NULL; char *bufptr = buffer; enum { st_wordstart, st_wordcmp, st_wordskip, st_bufcpy } state = st_wordstart; if (!cmdline_ptr || cmdline_ptr >= 0x100000) return -1; cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000 && (c = rdfs8(cptr++))) { switch (state) { case st_wordstart: if (myisspace(c)) break; state = st_wordcmp; opptr = option; case st_wordcmp: if (c == '=' && !*opptr) { len = 0; bufptr = buffer; state = st_bufcpy; } else if (myisspace(c)) { state = st_wordstart; } else if (c != *opptr++) { state = st_wordskip; } break; case st_wordskip: if (myisspace(c)) state = st_wordstart; break; case st_bufcpy: if (myisspace(c)) { state = st_wordstart; } else { if (len < bufsize-1) *bufptr++ = c; len++; } break; } } if (bufsize) *bufptr = '\0'; return len; }
/* * Find a non-boolean option, that is, "option=argument". In accordance * with standard Linux practice, if this option is repeated, this returns * the last instance on the command line. * * Returns the length of the argument (regardless of if it was * truncated to fit in the buffer), or -1 on not found. */ int __cmdline_find_option(u32 cmdline_ptr, const char *option, char *buffer, int bufsize) { addr_t cptr; char c; int len = -1; const char *opptr = NULL; char *bufptr = buffer; enum { st_wordstart, /* Start of word/after whitespace */ st_wordcmp, /* Comparing this word */ st_wordskip, /* Miscompare, skip */ st_bufcpy /* Copying this to buffer */ } state = st_wordstart; if (!cmdline_ptr || cmdline_ptr >= 0x100000) // cmdline 포인터가 없거나 1M이상이면 에러 return -1; /* No command line, or inaccessible */ cptr = cmdline_ptr & 0xf; // cmdline_ptr의 오프셋 set_fs(cmdline_ptr >> 4); // cmdline_ptr의 세그먼트 값 // cmdline에서 옵션을 찾는다. while (cptr < 0x10000 && (c = rdfs8(cptr++))) { switch (state) { case st_wordstart: if (myisspace(c)) // 맨 처음 혹은 스페이스(<32)가 여러개 오면 break 해버린다. break; /* else */ state = st_wordcmp; // 구분자 후에 문자가 있으면 wordcmp로 상태 변환 opptr = option; // 찾을 옵션 /* fall through */ // 아래로 계속된다. case st_wordcmp: if (c == '=' && !*opptr) { len = 0; // 길이 리셋 bufptr = buffer; state = st_bufcpy; // 일치한다. bufcpy로 상태전환 } else if (myisspace(c)) { state = st_wordstart; // "="이 없다. 다시 비교 } else if (c != *opptr++) { state = st_wordskip; // 일치하지 않음 } break; // 문자가 일치한다. cmp 상태 그대로 다시 비교 case st_wordskip: // skip은 문자열이 일치하지 않은 상태 if (myisspace(c)) // 구분자가 오면 새로 비교 시작 state = st_wordstart; break; case st_bufcpy: if (myisspace(c)) { state = st_wordstart; // 구분자가 오기전까지 복사 } else { if (len < bufsize-1) *bufptr++ = c; // 버퍼 크기를 넘지 않으면 복사 len++; } break; } } if (bufsize) *bufptr = '\0'; // 버퍼 끝은 NUL return len; // 옵션 길이를 리턴. 일치하는게 없으면 -1 }