void uiview_search_addch(int ch) { if(ispunct(ch) || isalnum(ch) || (ch == ' ')) { if(searchstr_pos < searchstr_len) { memmove(&(searchstr[searchstr_pos + 1]), &(searchstr[searchstr_pos]), searchstr_len - searchstr_pos); } searchstr[searchstr_pos] = (char)ch; searchstr_pos++; searchstr_len++; search_selected = 0; } else { switch(ch) { case '\n': /* Play selected track */ { track_t *track = g_slist_nth_data(search_results, search_selected); if(track) { list_enqueue_insert_first_track(track); model_next(); } uiview_set_search(0); } break; case KEY_IC: /* Enqueue selected track */ { track_t *track = g_slist_nth_data(search_results, search_selected); if(track) { list_enqueue_insert_first_track(track); } } break; case KEY_LEFT: if(searchstr_pos > 0) { searchstr_pos--; } break; case KEY_RIGHT: if(searchstr_pos < searchstr_len) { searchstr_pos++; } break; case KEY_UP: if(search_selected > 0) { search_selected--; } break; case KEY_DOWN: if(search_selected < ((int)g_slist_length(search_results) - 1)) { search_selected++; } break; case KEY_BACKSPACE: if(searchstr_pos > 0) { if(searchstr_pos < searchstr_len) { memmove(&(searchstr[searchstr_pos - 1]), &(searchstr[searchstr_pos]), searchstr_len - searchstr_pos); } searchstr_pos--; searchstr_len--; searchstr[searchstr_len] = '\0'; search_selected = 0; } break; case 27: uiview_set_search(0); break; default: break; } } }
void EnigmaCrypt::FilterTableHelper(char* SrceTable_, char* DestTable_) { int Valid_[20]; size_t i, x, y, len; int InitialVal_; len = strlen(SrceTable_); InitialVal_ = (_Filter & POS_FILTER) ? 0:1; for (y = 0; y < 10; y++) Valid_[y] = InitialVal_; for (y = 10; y < 20; y++) Valid_[y] = 1; if (_Filter) { for (x = i = 0; i < len; i++) { if (_Filter & ALPHANUM & ~POS_FILTER) Valid_[0] = isalnum(SrceTable_[i]); else if (_Filter & NOT_ALPHANUM & ~NEG_FILTER) Valid_[10] = !isalnum(SrceTable_[i]); if (_Filter & ALPHA & ~POS_FILTER) Valid_[1] = isalpha(SrceTable_[i]); else if (_Filter & NOT_ALPHA & ~NEG_FILTER) Valid_[11] = !isalpha(SrceTable_[i]); if (_Filter & DIGIT & ~POS_FILTER) Valid_[2] = isdigit(SrceTable_[i]); else if (_Filter & NOT_DIGIT & ~NEG_FILTER) Valid_[12] = !isdigit(SrceTable_[i]); if (_Filter & LOWER & ~POS_FILTER) Valid_[3] = islower(SrceTable_[i]); else if (_Filter & NOT_LOWER & ~NEG_FILTER) Valid_[13] = !islower(SrceTable_[i]); if (_Filter & UPPER & ~POS_FILTER) Valid_[4] = isupper(SrceTable_[i]); else if (_Filter & NOT_UPPER & ~NEG_FILTER) Valid_[14] = !isupper(SrceTable_[i]); if (_Filter & GRAPH & ~POS_FILTER) Valid_[5] = isgraph(SrceTable_[i]); else if (_Filter & NOT_GRAPH & ~NEG_FILTER) Valid_[15] = !isgraph(SrceTable_[i]); if (_Filter & PRINT & ~POS_FILTER) Valid_[6] = isprint(SrceTable_[i]); else if (_Filter & NOT_PRINT & ~NEG_FILTER) Valid_[16] = !isprint(SrceTable_[i]); if (_Filter & PUNCT & ~POS_FILTER) Valid_[7] = ispunct(SrceTable_[i]); else if (_Filter & NOT_PUNCT & ~NEG_FILTER) Valid_[17] = !ispunct(SrceTable_[i]); if (_Filter & SPACE & ~POS_FILTER) Valid_[8] = isspace(SrceTable_[i]) && (SrceTable_[i] == SPACE_CHAR); else if (_Filter & NOT_SPACE & ~NEG_FILTER) Valid_[18] = !isspace(SrceTable_[i]); Valid_[9] = Valid_[0] || Valid_[1] || Valid_[2] || Valid_[3] || Valid_[4] || Valid_[5] || Valid_[6] || Valid_[7] || Valid_[8]; Valid_[19] = Valid_[10] && Valid_[11] && Valid_[12] && Valid_[13] && Valid_[14] && Valid_[15] && Valid_[16] && Valid_[17] && Valid_[18]; if (Valid_[9] && Valid_[19]) DestTable_[x++] = SrceTable_[i]; for (y = 0; y < 10; y++) Valid_[y] = InitialVal_; for (y = 10; y < 20; y++) Valid_[y] = 1; } } else { x = strlen(SrceTable_); memcpy(DestTable_, SrceTable_, strlen(SrceTable_) + 1); } DestTable_[x] = 0; }
int main(int argc, char *argv[]) { if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); exit(0); } int c; int on = 0; initMessenger(); //if keyfiles exist if(argc > 4){ if(strncmp(argv[4], "nokey", 6) < 0){ //load_key(); } } else { load_key(); } m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; uint32_t i; for(i = 0; i < 32; i++) { if(self_public_key[i] < 16) { strcpy(idstring1[i],"0"); } else { strcpy(idstring1[i], ""); } sprintf(idstring2[i], "%hhX",self_public_key[i]); } strcpy(idstring0,"[i] your ID: "); for(i=0; i<32; i++) { strcat(idstring0,idstring1[i]); strcat(idstring0,idstring2[i]); } initscr(); noecho(); raw(); getmaxyx(stdscr,y,x); new_lines(idstring0); new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)"); strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); if (resolved_address != -1) { bootstrap_ip_port.ip.i = resolved_address; } else { exit(1); } DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); nodelay(stdscr, TRUE); while(true) { if (on == 0 && DHT_isconnected()) { new_lines("[i] connected to DHT\n[i] define username with /n"); on = 1; } doMessenger(); c_sleep(1); do_refresh(); c = getch(); if (c == ERR || c == 27) continue; getmaxyx(stdscr, y, x); if (c == '\n') { line_eval(lines, line); strcpy(line, ""); } else if (c == 127) { line[strlen(line) - 1] = '\0'; } else if (isalnum(c) || ispunct(c) || c == ' ') { strcpy(line, appender(line, (char) c)); } } endwin(); return 0; }
void StdIspunct(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Integer = ispunct(Param[0]->Val->Integer); }
bool CGrammarItem::AddAttribute(string Name, string Value, MorphLanguageEnum Language, string& ErrorStr) { if (Value.length() > 0) if (Value[0] == '"') { if ( (Value.length()<2) || (Value[Value.length() - 1] != '"')) { ErrorStr = Format("no matching quotation mark for attribute value \"%s\"",Value.c_str()); return false; }; Value = Value.substr(1, Value.length()-2); }; if (Name == "root") { m_bSynMain = true; return true; }; if (Name == "type") { m_TokenType = StringToTokenType(Value); if (m_TokenType == OTHER_TOKEN_TYPE) { ErrorStr = Format("unknown token type:%s ",Value.c_str()); return false; } }; if (Name == "hom") { if (Value == "yes") m_bCanHaveManyHomonyms = true; else if (Value == "no") m_bCanHaveManyHomonyms = false; else { ErrorStr = Format("Bad value for attribute \"hom\" (\"%s\"). It can be \"yes\" or \"no\"",Value.c_str()); return false; }; if (m_TokenType == OTHER_TOKEN_TYPE) m_TokenType = (Language == morphRussian) ? RLE : LLE; return true; }; if (Name == "grm") { m_MorphPattern.m_GrmAttribute = Value; if (m_TokenType == OTHER_TOKEN_TYPE) m_TokenType = (Language == morphRussian) ? RLE : LLE; return true; }; if (Name == "form") { m_Token = Value; RmlMakeUpper(m_Token, Language); m_ItemStrId = Value; if ( (m_TokenType == OTHER_TOKEN_TYPE) && !m_Token.empty()) { if (ispunct((BYTE)m_Token[0])) m_TokenType = PUNCTUAT; else if (isdigit((BYTE)m_Token[0])) m_TokenType = NUM; else if (Language == morphRussian) { if (CheckLanguage(m_Token, Language)) m_TokenType = RLE; } else { if (CheckLanguage(m_Token, Language)) m_TokenType = LLE; } }; return true; }; if (Name == "register") { if (Value == "AA") m_Register = UpUp; else if (Value == "aa") m_Register = LowLow; else if (Value == "Aa") m_Register = UpLow; else { ErrorStr = Format("Bad value for attribute \"register\" (\"%s\"). It can be \"AA\", \"aa\" or \"Aa\"",Value.c_str()); return false; }; if (m_TokenType == OTHER_TOKEN_TYPE) m_TokenType = (Language == morphRussian) ? RLE : LLE; return true; }; if (Name == "filename") { Value = GetPathByFile(CurrentSourceFileName) + Value; if (m_TokenType == OTHER_TOKEN_TYPE) m_TokenType = (Language == morphRussian) ? RLE : LLE; } m_Attributes[Name] = Value; return true; };
string ciph(string text, string k) { //Encription engine for(int i = 0, j = 0; i < strlen(k) && j < strlen(text);) { if(isupper(text[j]) && islower(k[i])) { if(text[j] == 90) { text[j] = text[j] + k[i] - 97 - 25; i++; j++; } else if(isblank(text[j]) || isdigit(text[j]) || ispunct(text[j])) { j++; } else { if(text[j] + k[i] <= 187) { text[j] = text[j] + k[i] - 97; i++; j++; } else { text[j] = text[j] + k[i] - 97 - 26; } } } else if(isupper(text[j]) && isupper(k[i])) { if(text[j] == 90) { text[j] = text[j] + k[i] - 65 - 25; i++; j++; } else if(isblank(text[j]) || isdigit(text[j]) || ispunct(text[j])) { j++; } else if(text[j] + k[i] <= 155) { text[j] = text[j] + k[i] - 65; i++; j++; } else { text[j] = text[j] + k[i] - 65 - 26; i++; j++; } } else if(islower(text[j]) && isupper(k[i])) { if(text[j] == 122) { text[j] = text[j] + k[i] - 65 - 25; i++; j++; } else if(isblank(text[j]) || isdigit(text[j]) || ispunct(text[j])) { j++; } else { if(text[j] + k[i] <= 187) { text[j] = text[j] + k[i] - 65; i++; j++; } else { text[j] = text[j] + k[i] - 65 - 26; i++; j++; } } } else { if(text[j] == 122) { text[j] = text[j] + k[i] - 97 - 25; i++; j++; } else if(isblank(text[j]) || isdigit(text[j]) || ispunct(text[j])) { j++; } else { if(text[j] + k[i] <= 219) { text[j] = text[j] + k[i] - 97; i++; j++; } else { text[j] = text[j] + k[i] - 97 - 26; i++; j++; } } } if(i == strlen(k)) { i = 0; } } return text; }
LexemVector tokenize( const std::string & expression) { struct Graph { char ch; Token token; }; static Graph graph[] = { {'+', TOKEN_PLUS}, {'-', TOKEN_MINUS}, {'*', TOKEN_MULTIPLY}, {'/', TOKEN_DIVIDE}, {'%', TOKEN_PERCENT}, {'^', TOKEN_EXPONENTIATION}, {'?', TOKEN_QUESTION}, {',', TOKEN_COMMA}, {':', TOKEN_COLON}, {';', TOKEN_SEMI}, {'(', TOKEN_LPAREN}, {')', TOKEN_RPAREN}, {'[', TOKEN_LBRACK}, {']', TOKEN_RBRACK}, {'=', TOKEN_ASSIGN}, {'<', TOKEN_LESS}, {'>', TOKEN_GREATER}, {'|', TOKEN_ARITHMETIC_OR}, {'&', TOKEN_ARITHMETIC_AND}, {'!', TOKEN_NOT} }; struct Digraph { char ch1; char ch2; Token token; }; static Digraph digraph[] = { {'=', '=', TOKEN_EQUAL}, {'!', '=', TOKEN_NOT_EQUAL}, {'>', '=', TOKEN_GREATER_EQUAL}, {'<', '=', TOKEN_LESS_EQUAL}, {'|', '|', TOKEN_LOGICAL_OR}, {'&', '&', TOKEN_LOGICAL_AND} }; LexemVector lex_vector; const char *it = expression.c_str(); while (*it != '\0') { if (std::isspace(*it) || ::iscntrl(*it)) ++it; // Parse constant [0-9]*(\.[0-9*])?(E([+-]?[0-9]*))? // take unary plus and minus into account else if (std::isdigit(*it) || *it == '.' || ((*it == '-' || *it == '+') && (std::isdigit(*(it + 1)) || *(it + 1) == '.') && (lex_vector.empty() || lex_vector.back().getToken() == TOKEN_COMMA || lex_vector.back().getToken() == TOKEN_LPAREN || is_operator(lex_vector.back().getToken())))) { bool is_real = false; const char *from = it; if (*it == '-' || *it == '+') ++it; while (std::isdigit(*it)) ++it; if (*it == '.') { is_real = true; ++it; while (std::isdigit(*it)) ++it; } if (*from == '.' && it == from + 1) throw std::runtime_error(std::string("'.' is not a valid real number ") + *it); if (*it == '.') throw std::runtime_error(std::string("'.' is not a valid real number ") + *it); if (std::toupper(*it) == 'E') { is_real = true; ++it; if (*it == '+' || *it == '-') { ++it; } while (std::isdigit(*it)) { ++it; } } if (is_real) lex_vector.push_back(Lexem(TOKEN_REAL_CONSTANT, from, it)); else lex_vector.push_back(Lexem(TOKEN_INTEGER_CONSTANT, from, it)); } // Parse literal else if (*it == '"') { std::string s; ++it; for (; *it && *it != '"'; ++it) { if (*it == '\\') { ++it; if (*it) switch (*it) { case '"': s += '"'; break; case '\\': s += '\\'; break; case 'n': s += '\n'; break; default: s += *it; } } else s += *it; } ++it; lex_vector.push_back(Lexem(TOKEN_LITERAL, s.c_str())); } // Parse identifier [a-zA-Z][a-zA-Z0-9_.]* else if (std::isalpha(*it)) { const char *from = it; while (std::isalpha(*it) || std::isdigit(*it) || *it == '_' || *it == '.') ++it; lex_vector.push_back(Lexem(TOKEN_IDENTIFIER, from, it)); } // Parse graphs and digraphs else if (ispunct(*it)) { const char *from = it; if (*(it + 1) != '\0') { for (size_t i = 0; i < sizeof(digraph)/sizeof(digraph[0]); ++i) { if (*it == digraph[i].ch1 && *(it + 1) == digraph[i].ch2) { ++it; ++it; lex_vector.push_back(Lexem(digraph[i].token, from, it)); goto next_token; } } } for (size_t i = 0; i < sizeof(graph)/sizeof(graph[0]); ++i) if (*it == graph[i].ch) { ++it; lex_vector.push_back(Lexem(graph[i].token, from, it)); goto next_token; } throw std::runtime_error(std::string("std::expreval::tokenize: Invalid graphic character '") + *it + "'"); } else throw std::runtime_error("Impossible expression parse error"); next_token: continue; } lex_vector.push_back(Lexem(TOKEN_END, "")); return lex_vector; }
static int UnDosLine( char *const line, const char *const curdir, size_t curdirlen, char *fname, size_t fnamesize, int *ftype, longest_int *fsize, time_t *ftime) { char *cp; int hour, year; char *filestart; char *sizestart; struct tm ftm; /* * 0123456789012345678901234567890123456789012345678901234567890123456789 04-27-99 10:32PM 270158 Game booklet.pdf 03-11-99 10:03PM <DIR> Get A3d Banner We also try to parse the format from CMD.EXE, which is similar: 03/22/2001 06:23p 62,325 cls.pdf * */ cp = line; if ( isdigit((int) cp[0]) && isdigit((int) cp[1]) && ispunct((int) cp[2]) && isdigit((int) cp[3]) && isdigit((int) cp[4]) && ispunct((int) cp[5]) && isdigit((int) cp[6]) && isdigit((int) cp[7]) ) { (void) memset(&ftm, 0, sizeof(struct tm)); ftm.tm_isdst = -1; cp[2] = '\0'; ftm.tm_mon = atoi(cp + 0); if (ftm.tm_mon > 0) ftm.tm_mon -= 1; cp[5] = '\0'; ftm.tm_mday = atoi(cp + 3); if ((isdigit((int) cp[8])) && (isdigit((int) cp[9]))) { /* Four-digit year */ cp[10] = '\0'; year = atoi(cp + 6); if (year > 1900) year -= 1900; ftm.tm_year = year; /* years since 1900 */ cp += 11; } else { /* Two-digit year */ cp[8] = '\0'; year = atoi(cp + 6); if (year < 98) year += 100; ftm.tm_year = year; /* years since 1900 */ cp += 9; } for (;;) { if (*cp == '\0') return (-1); if (isdigit((int) *cp)) break; cp++; } cp[2] = '\0'; hour = atoi(cp); if (((cp[5] == 'P') || (cp[5] == 'p')) && (hour < 12)) hour += 12; else if (((cp[5] == 'A') || (cp[5] == 'a')) && (hour == 12)) hour -= 12; ftm.tm_hour = hour; cp[5] = '\0'; ftm.tm_min = atoi(cp + 3); *ftime = mktime(&ftm); if (*ftype == (time_t) -1) return (-1); cp += 6; *ftype = '-'; for (;;) { if (*cp == '\0') return (-1); if ((*cp == '<') && (cp[1] == 'D')) { /* found <DIR> */ *ftype = 'd'; cp += 5; break; /* size field will end up being empty string */ } else if ((*cp == '<') && (cp[1] == 'J')) { /* found <JUNCTION> * * Will we ever really see this? * IIS from Win2000sp1 sends <DIR> * for FTP, but CMD.EXE prints * <JUNCTION>. */ *ftype = 'd'; cp += 10; break; } else if (isdigit((int) *cp)) { break; } else { cp++; } } sizestart = cp; for (;;) { if (*cp == '\0') return (-1); #ifdef HAVE_MEMMOVE if (*cp == ',') { /* Yuck -- US Locale dependency */ memmove(cp, cp + 1, strlen(cp + 1) + 1); } #endif if (!isdigit((int) *cp)) { *cp++ = '\0'; break; } cp++; } if (fsize != NULL) { #if defined(HAVE_LONG_LONG) && defined(SCANF_LONG_LONG) if (*ftype == 'd') *fsize = 0; else (void) sscanf(sizestart, SCANF_LONG_LONG, fsize); #elif defined(HAVE_LONG_LONG) && defined(HAVE_STRTOQ) if (*ftype == 'd') *fsize = 0; else *fsize = (longest_int) strtoq(sizestart, NULL, 0); #else *fsize = (longest_int) 0; if (*ftype != 'd') { long fsize2 = 0L; (void) sscanf(sizestart, "%ld", &fsize2); *fsize = (longest_int) fsize2; } #endif } for (;;) { if (*cp == '\0') return (-1); if (!isspace((int) *cp)) { break; } cp++; } filestart = cp; if (curdirlen == 0) { (void) Strncpy(fname, filestart, fnamesize); } else { (void) Strncpy(fname, curdir, fnamesize); (void) Strncat(fname, filestart, fnamesize); } return (0); } return (-1); } /* UnDosLine */
static void Colourise_Doc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler) { int state = sID::DEFAULT; char chNext = styler[startPos]; int lengthDoc = startPos + length; // create a buffer large enough to take the largest chunk... char *buffer = new char[length]; int bufferCount = 0; // this assumes that we have 2 keyword list in conf.properties WordList &directives = *keywordLists[0]; WordList ¶ms = *keywordLists[1]; WordList &USERDEF = *keywordLists[2]; // go through all provided text segment // using the hand-written state machine shown below styler.StartAt(startPos); styler.StartSegment(startPos); for (int i = startPos; i < lengthDoc; i++) { char ch = chNext; chNext = styler.SafeGetCharAt(i + 1); if (styler.IsLeadByte(ch)) { chNext = styler.SafeGetCharAt(i + 2); i++; continue; } switch(state) { case sID::DEFAULT: if( ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') { // whitespace is simply ignored here... styler.ColourTo(i,sID::DEFAULT); break; } else if( ch == '#' ) { // signals the start of a comment... state = sID::COMMENT; styler.ColourTo(i,sID::COMMENT); } else if( ch == '.' /*|| ch == '/'*/) { // signals the start of a file... state = sID::EXTENSION; styler.ColourTo(i,sID::EXTENSION); } else if( ch == '"') { state = sID::STRING; styler.ColourTo(i,sID::STRING); } else if( ispunct(ch) ) { // signals an operator... // no state jump necessary for this // simple case... styler.ColourTo(i,sID::OPERATOR); } else if( isalpha(ch) ) { // signals the start of an identifier bufferCount = 0; buffer[bufferCount++] = static_cast<char>(tolower(ch)); state = sID::IDENTIFIER; } else if( isdigit(ch) ) { // signals the start of a number bufferCount = 0; buffer[bufferCount++] = ch; //styler.ColourTo(i,sID::NUMBER); state = sID::NUMBER; } else { // style it the default style.. styler.ColourTo(i,sID::DEFAULT); } break; case sID::COMMENT: // if we find a newline here, // we simply go to default state // else continue to work on it... if( ch == '\n' || ch == '\r' ) { state = sID::DEFAULT; } else { styler.ColourTo(i,sID::COMMENT); } break; case sID::EXTENSION: // if we find a non-alphanumeric char, // we simply go to default state // else we're still dealing with an extension... if( isalnum(ch) || (ch == '_') || (ch == '-') || (ch == '$') || (ch == '/') || (ch == '.') || (ch == '*') ) { styler.ColourTo(i,sID::EXTENSION); } else { state = sID::DEFAULT; chNext = styler[i--]; } break; case sID::STRING: // if we find the end of a string char, we simply go to default state // else we're still dealing with an string... if( (ch == '"' && styler.SafeGetCharAt(i-1)!='\\') || (ch == '\n') || (ch == '\r') ) { state = sID::DEFAULT; } styler.ColourTo(i,sID::STRING); break; case sID::IDENTIFIER: // stay in CONF_IDENTIFIER state until we find a non-alphanumeric if( isalnum(ch) || (ch == '_') || (ch == '-') || (ch == '/') || (ch == '$') || (ch == '.') || (ch == '*')) { buffer[bufferCount++] = static_cast<char>(tolower(ch)); } else { state = sID::DEFAULT; buffer[bufferCount] = '\0'; // check if the buffer contains a keyword, and highlight it if it is a keyword... if(directives.InList(buffer)) { styler.ColourTo(i-1,sID::DIRECTIVE ); } else if(params.InList(buffer)) { styler.ColourTo(i-1,sID::PARAMETER ); } else if(USERDEF.InList(buffer)) { styler.ColourTo(i-1,sID::USERDEF ); } else if(strchr(buffer,'/') || strchr(buffer,'.')) { styler.ColourTo(i-1,sID::EXTENSION); } else { styler.ColourTo(i-1,sID::DEFAULT); } // push back the faulty character chNext = styler[i--]; } break; case sID::NUMBER: // stay in CONF_NUMBER state until we find a non-numeric if( isdigit(ch) || ch == '.') { buffer[bufferCount++] = ch; } else { state = sID::DEFAULT; buffer[bufferCount] = '\0'; // Colourize here... if( strchr(buffer,'.') ) { // it is an IP address... styler.ColourTo(i-1,sID::IP); } else { // normal number styler.ColourTo(i-1,sID::NUMBER); } // push back a character chNext = styler[i--]; } break; } } delete []buffer; }
char process_simpletext(tgui_Window *win, tgui_Obj *obj){ int ox, oy, x, maxx, bctr; unsigned key; char *buf = malloc (sizeof(char)*(obj->width+1)); strcpy(buf, obj->data); ox = win->x1 + 1 + obj->x; oy = win->y1 + 2 + obj->y; x=ox; revers(0); cputsxy(x,oy, buf); revers(1); cputc(' '); revers(0); maxx=x+obj->width; x=x+strlen(buf); bctr=strlen(buf); gotoxy(x, oy); cursor(1); do { key = cgetc(); //gotoxy(3,22); cprintf("%d",key); if (isalnum(key) || ispunct(key) || key==32) { if (x<=maxx){ revers(0); cputcxy(x,oy,key); buf[bctr]=key; ++bctr; buf[bctr]='\0'; ++x; revers(1); cputc(' '); revers(0); } } if (key == CH_CURS_LEFT|| key == CH_DEL){ if (x>ox) { if (x<=maxx)cputcxy(x, oy, '_'); --bctr; buf[bctr]='\0'; --x; gotoxy(x,oy); revers(1); cputc(' '); revers(0); } } } while (key!=CH_ENTER && key!=CH_F1 ); cursor(0); if (key==CH_ENTER ) { revers(0); if (x<maxx) cputcxy(x,oy, ' '); strcpy(obj->data, buf); } //ESCAPE if (key==CH_F1) { revers(1); cputsxy(ox, oy, obj->data); } //textcolor(win->color); free(buf); return key; } // end of process_simple_text
int ispunct_l(int c, locale_t l) { return ispunct(c); }
int advanced_check(char *userhost, int ipstat) { register int retval = TRUE; char *up = NULL, *p, *thisseg; int numdots = 0, segno = 0, numseg, i = 0; char *ipseg[10 + 2]; char safebuffer[512] = ""; /* buffer strtok_r() can mess up to its heart's content...;> */ strlcpy(safebuffer, userhost, sizeof safebuffer); #define userhost safebuffer #define IP_WILDS_OK(x) ((x)<2? 0 : 1) if (ipstat == UNSURE) { ipstat = TRUE; for (; *up; up++) { if (*up == '.') numdots++; if (!isdigit(*up) && !ispunct(*up)) { ipstat = FALSE; continue; } } if (numdots != 3) ipstat = FALSE; if (numdots < 1 || numdots > 9) return (0); } /* fill in the segment set */ { int l = 0; for (segno = 0, i = 0, thisseg = strtok_r(userhost, ".", &p); thisseg; thisseg = strtok_r(NULL, ".", &p), i++) { l = strlen(thisseg) + 2; ipseg[segno] = calloc(1, l); strncpy(ipseg[segno++], thisseg, l); } } if (segno < 2 && ipstat == TRUE) retval = FALSE; numseg = segno; if (ipstat == TRUE) for (i = 0; i < numseg; i++) { if (!IP_WILDS_OK(i) && (index(ipseg[i], '*') || index(ipseg[i], '?'))) retval = FALSE; /* The person who wrote this function was braindead --Stskeeps */ /* MyFree(ipseg[i]); */ } else { int wildsok = 0; for (i = 0; i < numseg; i++) { /* for hosts, let the mask extent all the way to the second-level domain... */ wildsok = 1; if (i == numseg || (i + 1) == numseg) wildsok = 0; if (wildsok == 0 && (index(ipseg[i], '*') || index(ipseg[i], '?'))) { retval = FALSE; } /* MyFree(ipseg[i]); */ } } return (retval); #undef userhost #undef IP_WILDS_OK }
static void TestCType() { char c; for(c='a';c<='z';++c) { TEST(isalnum(c)); TEST(isalpha(c)); TEST(!iscntrl(c)); TEST(!isdigit(c)); TEST(isgraph(c)); TEST(islower(c)); TEST(isprint(c)); TEST(!ispunct(c)); TEST(!isspace(c)); TEST(!isupper(c)); TEST(c >= 'a' && c <= 'f' ? isxdigit(c) : !isxdigit(c)); } for(c='A';c<='Z';++c) { TEST(isalnum(c)); TEST(isalpha(c)); TEST(!iscntrl(c)); TEST(!isdigit(c)); TEST(isgraph(c)); TEST(!islower(c)); TEST(isprint(c)); TEST(!ispunct(c)); TEST(!isspace(c)); TEST(isupper(c)); TEST(c >= 'A' && c <= 'F' ? isxdigit(c) : !isxdigit(c)); } for(c='0';c<='9';++c) { TEST(isalnum(c)); TEST(!isalpha(c)); TEST(!iscntrl(c)); TEST(isdigit(c)); TEST(isgraph(c)); TEST(!islower(c)); TEST(isprint(c)); TEST(!ispunct(c)); TEST(!isspace(c)); TEST(!isupper(c)); TEST(isxdigit(c)); } for(c=0;c<' ';++c) { TEST(!isalnum(c)); TEST(!isalpha(c)); TEST(iscntrl(c)); TEST(!isdigit(c)); TEST(!isgraph(c)); TEST(!islower(c)); TEST(!isprint(c)); TEST(!ispunct(c)); if(c != '\t' && c != '\n' && c != '\r' && c != '\v' && c != '\f') { TEST(!isspace(c)); } else { TEST(isspace(c)); } TEST(!isupper(c)); } }
int GetOption ( int argc, char** argv, char* pszValidOpts, char** ppszParam) { static int iArg = 1; char chOpt; char* psz = NULL; char* pszParam = NULL; if (iArg < argc) { psz = &(argv[iArg][0]); if (*psz == '-' || *psz == '/') { // we have an option specifier chOpt = argv[iArg][1]; if (isalnum(chOpt) || ispunct(chOpt)) { // we have an option character psz = strchr(pszValidOpts, chOpt); if (psz != NULL) { // option is valid, we want to return chOpt if (psz[1] == ':') { // option can have a parameter psz = &(argv[iArg][2]); if (*psz == '\0') { // must look at next argv for param if (iArg+1 < argc) { psz = &(argv[iArg+1][0]); if (*psz == '-' || *psz == '/') { // next argv is a new option, so param // not given for current option } else { // next argv is the param iArg++; pszParam = psz; } } else { // reached end of args looking for param } } else { // param is attached to option pszParam = psz; } } else { // option is alone, has no parameter } } else { // option specified is not in list of valid options chOpt = -1; pszParam = &(argv[iArg][0]); } } else { // though option specifier was given, option character // is not alpha or was was not specified chOpt = -1; pszParam = &(argv[iArg][0]); } } else { // standalone arg given with no option specifier chOpt = 1; pszParam = &(argv[iArg][0]); } } else { // end of argument list chOpt = 0; } iArg++; *ppszParam = pszParam; optind = iArg-1; return (chOpt); }
static void vc_scan(struct song_metadata *psong, const char *comment, const size_t length) { char strbuf[1024]; if(length > (sizeof(strbuf) - 1)) { if( strncasecmp(comment, "LYRICS=", 7) != 0 ) { DPRINTF(E_WARN, L_SCANNER, "Vorbis %.*s too long [%s]\n", (index(comment, '=')-comment), comment, psong->path); } return; } strncpy(strbuf, comment, length); strbuf[length] = '\0'; // ALBUM, ARTIST, PUBLISHER, COPYRIGHT, DISCNUMBER, ISRC, EAN/UPN, LABEL, LABELNO, // LICENSE, OPUS, SOURCEMEDIA, TITLE, TRACKNUMBER, VERSION, ENCODED-BY, ENCODING, // -- foollowing tags are muliples // COMPOSER, ARRANGER, LYRICIST, AUTHOR, CONDUCTOR, PERFORMER, ENSEMBLE, PART // PARTNUMBER, GENRE, DATE, LOCATION, COMMENT if(!strncasecmp(strbuf, "ALBUM=", 6)) { if( *(strbuf+6) ) psong->album = strdup(strbuf + 6); } else if(!strncasecmp(strbuf, "ARTIST=", 7)) { if( *(strbuf+7) ) psong->contributor[ROLE_ARTIST] = strdup(strbuf + 7); } else if(!strncasecmp(strbuf, "ARTISTSORT=", 11)) { psong->contributor_sort[ROLE_ARTIST] = strdup(strbuf + 11); } else if(!strncasecmp(strbuf, "TITLE=", 6)) { if( *(strbuf+6) ) psong->title = strdup(strbuf + 6); } else if(!strncasecmp(strbuf, "TRACKNUMBER=", 12)) { psong->track = atoi(strbuf + 12); } else if(!strncasecmp(strbuf, "DISCNUMBER=", 11)) { psong->disc = atoi(strbuf + 11); } else if(!strncasecmp(strbuf, "GENRE=", 6)) { if( *(strbuf+6) ) psong->genre = strdup(strbuf + 6); } else if(!strncasecmp(strbuf, "DATE=", 5)) { if(length >= (5 + 10) && isdigit(strbuf[5 + 0]) && isdigit(strbuf[5 + 1]) && ispunct(strbuf[5 + 2]) && isdigit(strbuf[5 + 3]) && isdigit(strbuf[5 + 4]) && ispunct(strbuf[5 + 5]) && isdigit(strbuf[5 + 6]) && isdigit(strbuf[5 + 7]) && isdigit(strbuf[5 + 8]) && isdigit(strbuf[5 + 9])) { // nn-nn-yyyy strbuf[5 + 10] = '\0'; psong->year = atoi(strbuf + 5 + 6); } else { // year first. year is at most 4 digit. strbuf[5 + 4] = '\0'; psong->year = atoi(strbuf + 5); } } else if(!strncasecmp(strbuf, "COMMENT=", 8)) { if( *(strbuf+8) ) psong->comment = strdup(strbuf + 8); } else if(!strncasecmp(strbuf, "MUSICBRAINZ_ALBUMID=", 20)) { psong->musicbrainz_albumid = strdup(strbuf + 20); } else if(!strncasecmp(strbuf, "MUSICBRAINZ_TRACKID=", 20)) { psong->musicbrainz_trackid = strdup(strbuf + 20); } else if(!strncasecmp(strbuf, "MUSICBRAINZ_TRACKID=", 20)) { psong->musicbrainz_trackid = strdup(strbuf + 20); } else if(!strncasecmp(strbuf, "MUSICBRAINZ_ARTISTID=", 21)) { psong->musicbrainz_artistid = strdup(strbuf + 21); } else if(!strncasecmp(strbuf, "MUSICBRAINZ_ALBUMARTISTID=", 26)) { psong->musicbrainz_albumartistid = strdup(strbuf + 26); } }
void lex(FILE *fp) { int i=0; char *toktype=0; char token[MAXLEN]; int curr_char = fgetc(fp); while (curr_char != '\0') { if ( isspace(curr_char) ) { curr_char = fgetc(fp); } else if (isalpha(curr_char) || curr_char=='_') { while ( (isalnum(curr_char) || curr_char=='_') && i<MAXLEN ) { token[i] = curr_char; curr_char = fgetc(fp); i++; } if (search(kw_strings, NUMBER_OF_KEYWORDS, token) == 1 ) toktype = "Keyword"; else toktype = "Identifier"; token[i] = '\0' ; parse(token, toktype); memset(&token[0], 0, sizeof(token)); // Clear token } // Keyword or identifier else if ( curr_char == '"' ) { token[i] = curr_char; curr_char = fgetc(fp); i++; while ( ( curr_char != '"') && curr_char != '\0' && i<MAXLEN) { token[i] = curr_char; curr_char = fgetc(fp); i++; } token[i] = curr_char; // Append the last quote. token[i+1] = '\0' ; // Append null char. curr_char = fgetc(fp); // Move on from last quote. toktype = "String" ; parse(token, toktype); memset(&token[0], 0, sizeof(token)); // Clear token } // String else if ( isdigit(curr_char) ) { while (isdigit(curr_char) && curr_char != '\0' && i<MAXLEN) { token[i] = curr_char; curr_char = fgetc(fp); i++; } toktype = "Number" ; parse(token, toktype); memset(&token[0], 0, sizeof(token)); // Clear token } // Number else if ( ispunct(curr_char) && curr_char != '_' && curr_char != '"' ) { token[i] = curr_char; curr_char = fgetc(fp); i++; while (ispunct(curr_char) && curr_char != '\0' && i<MAXLEN) { token[i] = curr_char; curr_char = fgetc(fp); i++; } toktype = "Punct" ; parse(token, toktype); memset(&token[0], 0, sizeof(token)); // Clear token } // Punct else { exit(0); } memset(&token[0], 0, sizeof(token)); // Clear token i = 0; // Reset i. } // while c != '\0' exit(0) ; } // lex()
/* This function builds a set of character tables for use by PCRE2 and returns a pointer to them. They are build using the ctype functions, and consequently their contents will depend upon the current locale setting. When compiled as part of the library, the store is obtained via a general context malloc, if supplied, but when DFTABLES is defined (when compiling the dftables auxiliary program) malloc() is used, and the function has a different name so as not to clash with the prototype in pcre2.h. Arguments: none when DFTABLES is defined else a PCRE2 general context or NULL Returns: pointer to the contiguous block of data */ #ifdef DFTABLES /* Included in freestanding dftables.c program */ static const uint8_t *maketables(void) { uint8_t *yield = (uint8_t *)malloc(tables_length); #else /* Not DFTABLES, compiling the library */ PCRE2_EXP_DEFN const uint8_t * PCRE2_CALL_CONVENTION pcre2_maketables(pcre2_general_context *gcontext) { uint8_t *yield = (uint8_t *)((gcontext != NULL)? gcontext->memctl.malloc(tables_length, gcontext->memctl.memory_data) : malloc(tables_length)); #endif /* DFTABLES */ int i; uint8_t *p; if (yield == NULL) return NULL; p = yield; /* First comes the lower casing table */ for (i = 0; i < 256; i++) *p++ = tolower(i); /* Next the case-flipping table */ for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i); /* Then the character class tables. Don't try to be clever and save effort on exclusive ones - in some locales things may be different. Note that the table for "space" includes everything "isspace" gives, including VT in the default locale. This makes it work for the POSIX class [:space:]. From release 8.34 is is also correct for Perl space, because Perl added VT at release 5.18. Note also that it is possible for a character to be alnum or alpha without being lower or upper, such as "male and female ordinals" (\xAA and \xBA) in the fr_FR locale (at least under Debian Linux's locales as of 12/2005). So we must test for alnum specially. */ memset(p, 0, cbit_length); for (i = 0; i < 256; i++) { if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7); if (isupper(i)) p[cbit_upper + i/8] |= 1 << (i&7); if (islower(i)) p[cbit_lower + i/8] |= 1 << (i&7); if (isalnum(i)) p[cbit_word + i/8] |= 1 << (i&7); if (i == '_') p[cbit_word + i/8] |= 1 << (i&7); if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7); if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7); if (isgraph(i)) p[cbit_graph + i/8] |= 1 << (i&7); if (isprint(i)) p[cbit_print + i/8] |= 1 << (i&7); if (ispunct(i)) p[cbit_punct + i/8] |= 1 << (i&7); if (iscntrl(i)) p[cbit_cntrl + i/8] |= 1 << (i&7); } p += cbit_length; /* Finally, the character type table. In this, we used to exclude VT from the white space chars, because Perl didn't recognize it as such for \s and for comments within regexes. However, Perl changed at release 5.18, so PCRE changed at release 8.34. */ for (i = 0; i < 256; i++) { int x = 0; if (isspace(i)) x += ctype_space; if (isalpha(i)) x += ctype_letter; if (isdigit(i)) x += ctype_digit; if (isxdigit(i)) x += ctype_xdigit; if (isalnum(i) || i == '_') x += ctype_word; /* Note: strchr includes the terminating zero in the characters it considers. In this instance, that is ok because we want binary zero to be flagged as a meta-character, which in this sense is any character that terminates a run of data characters. */ if (strchr("\\*+?{^.$|()[", i) != 0) x += ctype_meta; *p++ = x; } return yield; }
static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *event) { SpaceText *st = CTX_wm_space_text(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); int draw = 0, tools = 0, swallow = 0, scroll = 1; Text *text = CTX_data_edit_text(C); int retval = OPERATOR_RUNNING_MODAL; (void)text; if (st->doplugins && texttool_text_is_active(st->text)) { if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST; if (texttool_docs_get()) tools |= TOOL_DOCUMENT; } switch (event->type) { case LEFTMOUSE: if (event->val == KM_PRESS) { if (text_do_suggest_select(st, ar)) swallow = 1; else { if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; retval = OPERATOR_FINISHED; } draw = 1; } break; case MIDDLEMOUSE: if (event->val == KM_PRESS) { if (text_do_suggest_select(st, ar)) { confirm_suggestion(st->text); text_update_line_edited(st->text->curl); swallow = 1; } else { if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; retval = OPERATOR_FINISHED; } draw = 1; } break; case ESCKEY: if (event->val == KM_PRESS) { draw = swallow = 1; if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; else draw = swallow = 0; retval = OPERATOR_CANCELLED; } break; case RETKEY: case PADENTER: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { confirm_suggestion(st->text); text_update_line_edited(st->text->curl); swallow = 1; draw = 1; } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1; retval = OPERATOR_FINISHED; } break; case LEFTARROWKEY: case BACKSPACEKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { if (event->ctrl) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } else { /* Work out which char we are about to delete/pass */ if (st->text->curl && st->text->curc > 0) { char ch = st->text->curl->line[st->text->curc - 1]; if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) { get_suggest_prefix(st->text, -1); text_pop_suggest_list(); } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; } break; case RIGHTARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { if (event->ctrl) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } else { /* Work out which char we are about to pass */ if (st->text->curl && st->text->curc < st->text->curl->len) { char ch = st->text->curl->line[st->text->curc + 1]; if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) { get_suggest_prefix(st->text, 1); text_pop_suggest_list(); } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; } break; case PAGEDOWNKEY: scroll = SUGG_LIST_SIZE - 1; /* fall-through */ case WHEELDOWNMOUSE: case DOWNARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_DOCUMENT) { doc_scroll++; swallow = 1; draw = 1; } else if (tools & TOOL_SUGG_LIST) { SuggItem *sel = texttool_suggest_selected(); if (!sel) { texttool_suggest_select(texttool_suggest_first()); } else { while (sel && scroll--) { if (sel != texttool_suggest_last() && sel->next) { texttool_suggest_select(sel->next); sel = sel->next; } else { texttool_suggest_select(texttool_suggest_first()); sel = texttool_suggest_first(); } } } text_pop_suggest_list(); swallow = 1; draw = 1; } } break; case PAGEUPKEY: scroll = SUGG_LIST_SIZE - 1; /* fall-through */ case WHEELUPMOUSE: case UPARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_DOCUMENT) { if (doc_scroll > 0) doc_scroll--; swallow = 1; draw = 1; } else if (tools & TOOL_SUGG_LIST) { SuggItem *sel = texttool_suggest_selected(); while (sel && scroll--) { if (sel != texttool_suggest_first() && sel->prev) { texttool_suggest_select(sel->prev); sel = sel->prev; } else { texttool_suggest_select(texttool_suggest_last()); sel = texttool_suggest_last(); } } text_pop_suggest_list(); swallow = 1; draw = 1; } } break; case RIGHTSHIFTKEY: case LEFTSHIFTKEY: break; #if 0 default: if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw = 1; if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1; #endif } if (draw) { ED_area_tag_redraw(sa); } // if (swallow) { // retval = OPERATOR_RUNNING_MODAL; // } if (texttool_suggest_first()) { if (retval != OPERATOR_RUNNING_MODAL) { text_autocomplete_free(C, op); } return retval; } else { text_autocomplete_free(C, op); return OPERATOR_FINISHED; } }
bool char_class (const unsigned char c, const unsigned int flags) { if (!flags) return false; if (flags & CC_ANY) return true; if ((flags & CC_NULL) && c == '\0') return true; if ((flags & CC_ALNUM) && isalnum (c)) return true; if ((flags & CC_ALPHA) && isalpha (c)) return true; if ((flags & CC_ASCII) && isascii (c)) return true; if ((flags & CC_CNTRL) && iscntrl (c)) return true; if ((flags & CC_DIGIT) && isdigit (c)) return true; if ((flags & CC_PRINT) && (c >= 32 && c != 127)) /* allow ascii non-control and UTF-8, consider DEL to be a control */ return true; if ((flags & CC_PUNCT) && ispunct (c)) return true; if ((flags & CC_SPACE) && isspace (c)) return true; if ((flags & CC_XDIGIT) && isxdigit (c)) return true; if ((flags & CC_BLANK) && (c == ' ' || c == '\t')) return true; if ((flags & CC_NEWLINE) && c == '\n') return true; if ((flags & CC_CR) && c == '\r') return true; if ((flags & CC_BACKSLASH) && c == '\\') return true; if ((flags & CC_UNDERBAR) && c == '_') return true; if ((flags & CC_DASH) && c == '-') return true; if ((flags & CC_DOT) && c == '.') return true; if ((flags & CC_COMMA) && c == ',') return true; if ((flags & CC_COLON) && c == ':') return true; if ((flags & CC_SLASH) && c == '/') return true; if ((flags & CC_SINGLE_QUOTE) && c == '\'') return true; if ((flags & CC_DOUBLE_QUOTE) && c == '\"') return true; if ((flags & CC_REVERSE_QUOTE) && c == '`') return true; if ((flags & CC_AT) && c == '@') return true; if ((flags & CC_EQUAL) && c == '=') return true; return false; }
static void handle_elif() #endif { if (iftop) { if (iftop->state == EXPECT_ELSE) { /* last cond was false... */ int cond; ifstate_t *p = iftop; /* pop previous condition */ iftop = p->next; FREE((char *) p); #ifdef LEXER *--outp = '\0'; add_input(sp); #endif cond = cond_get_exp(0); #ifdef LEXER if (*outp++) { yyerror("Condition too complex in #elif"); while (*outp++); #else if (*outp != '\n') { yyerror("Condition too complex in #elif"); #endif } else handle_cond(cond); } else {/* EXPECT_ENDIF */ /* * last cond was true...skip to end of * conditional */ skip_to("endif", (char *) 0); } } else { yyerrorp("Unexpected %celif"); } } static void handle_else (void) { if (iftop) { if (iftop->state == EXPECT_ELSE) { iftop->state = EXPECT_ENDIF; } else { skip_to("endif", (char *) 0); } } else { yyerrorp("Unexpected %cendif"); } } static void handle_endif (void) { if (iftop && (iftop->state == EXPECT_ENDIF || iftop->state == EXPECT_ELSE)) { ifstate_t *p = iftop; iftop = p->next; FREE((char *) p); } else { yyerrorp("Unexpected %cendif"); } } #define BNOT 1 #define LNOT 2 #define UMINUS 3 #define UPLUS 4 #define MULT 1 #define DIV 2 #define MOD 3 #define BPLUS 4 #define BMINUS 5 #define LSHIFT 6 #define RSHIFT 7 #define LESS 8 #define LEQ 9 #define GREAT 10 #define GEQ 11 #define EQ 12 #define NEQ 13 #define BAND 14 #define XOR 15 #define BOR 16 #define LAND 17 #define LOR 18 #define QMARK 19 static char _optab[] = {0, 4, 0, 0, 0, 26, 56, 0, 0, 0, 18, 14, 0, 10, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 50, 40, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, 1}; static char optab2[] = {BNOT, 0, 0, LNOT, '=', NEQ, 7, 0, 0, UMINUS, 0, BMINUS, 10, UPLUS, 0, BPLUS, 10, 0, 0, MULT, 11, 0, 0, DIV, 11, 0, 0, MOD, 11, 0, '<', LSHIFT, 9, '=', LEQ, 8, 0, LESS, 8, 0, '>', RSHIFT, 9, '=', GEQ, 8, 0, GREAT, 8, 0, '=', EQ, 7, 0, 0, 0, '&', LAND, 3, 0, BAND, 6, 0, '|', LOR, 2, 0, BOR, 4, 0, 0, XOR, 5, 0, 0, QMARK, 1}; #define optab1 (_optab-' ') static int cond_get_exp (int priority) { int c; int value, value2, x; #ifdef LEXER do c = exgetc(); while (is_wspace(c)); if (c == '(') { #else if ((c = exgetc()) == '(') { #endif value = cond_get_exp(0); #ifdef LEXER do c = exgetc(); while (is_wspace(c)); if (c != ')') { yyerror("bracket not paired in #if"); if (!c) *--outp = '\0'; } #else if ((c = exgetc()) != ')') yyerrorp("bracket not paired in %cif"); #endif } else if (ispunct(c)) { if (!(x = optab1[c])) { yyerrorp("illegal character in %cif"); return 0; } value = cond_get_exp(12); switch (optab2[x - 1]) { case BNOT: value = ~value; break; case LNOT: value = !value; break; case UMINUS: value = -value; break; case UPLUS: value = value; break; default: yyerrorp("illegal unary operator in %cif"); } } else { int base; if (!isdigit(c)) { #ifdef LEXER if (!c) { #else if (c == '\n') { #endif yyerrorp("missing expression in %cif"); } else yyerrorp("illegal character in %cif"); return 0; } value = 0; if (c != '0') base = 10; else { c = *outp++; if (c == 'x' || c == 'X') { base = 16; c = *outp++; } else base = 8; } for (;;) { if (isdigit(c)) x = -'0'; else if (isupper(c)) x = -'A' + 10; else if (islower(c)) x = -'a' + 10; else break; x += c; if (x > base) break; value = value * base + x; c = *outp++; } outp--; } for (;;) { #ifdef LEXER do c = exgetc(); while (is_wspace(c)); if (!ispunct(c)) break; #else if (!ispunct(c = exgetc())) break; #endif if (!(x = optab1[c])) break; value2 = *outp++; for (;; x += 3) { if (!optab2[x]) { outp--; if (!optab2[x + 1]) { yyerrorp("illegal operator use in %cif"); return 0; } break; } if (value2 == optab2[x]) break; } if (priority >= optab2[x + 2]) { if (optab2[x]) *--outp = value2; break; } value2 = cond_get_exp(optab2[x + 2]); switch (optab2[x + 1]) { case MULT: value *= value2; break; case DIV: if (value2) value /= value2; else yyerrorp("division by 0 in %cif"); break; case MOD: if (value2) value %= value2; else yyerrorp("modulo by 0 in %cif"); break; case BPLUS: value += value2; break; case BMINUS: value -= value2; break; case LSHIFT: value <<= value2; break; case RSHIFT: value >>= value2; break; case LESS: value = value < value2; break; case LEQ: value = value <= value2; break; case GREAT: value = value > value2; break; case GEQ: value = value >= value2; break; case EQ: value = value == value2; break; case NEQ: value = value != value2; break; case BAND: value &= value2; break; case XOR: value ^= value2; break; case BOR: value |= value2; break; case LAND: value = value && value2; break; case LOR: value = value || value2; break; case QMARK: #ifdef LEXER do c = exgetc(); while (isspace(c)); if (c != ':') { yyerror("'?' without ':' in #if"); outp--; return 0; } #else if ((c = exgetc()) != ':') yyerrorp("'?' without ':' in %cif"); #endif if (value) { cond_get_exp(1); value = value2; } else value = cond_get_exp(1); break; } } outp--; return value; } static void handle_cond (int c) { ifstate_t *p; if (!c) skip_to("else", "endif"); p = ALLOCATE(ifstate_t, TAG_COMPILER, "handle_cond"); p->next = iftop; iftop = p; p->state = c ? EXPECT_ENDIF : EXPECT_ELSE; }
int xml_get_token(XML_PARSER* parser, XML_TOKEN* token) { if(parser->state == XML_STATE_ERROR) { token->str = ""; token->length = 0; token->type = XML_TOKEN_ERROR; return 0; } if(parser->state == XML_STATE_END_DOCUMENT) { token->type = XML_TOKEN_END_DOCUMENT; return 0; } if(parser->has_token) { parser->has_token = 0; *token = parser->pushed_back_token; return token->type != XML_TOKEN_END_DOCUMENT && token->type != XML_TOKEN_ERROR; } if(parser->state == XML_STATE_FIND_ELEMENT) { int text_found = 0; const char* begin = parser->pos; while(*parser->pos && *parser->pos != '<') { if(isalnum(*parser->pos) || ispunct(*parser->pos)) { text_found = 1; } ++parser->pos; } if(!*parser->pos) { ERROR_AND_RETURN(parser->elements, "unexpected end of document"); ERROR_AND_RETURN(text_found, "text found at top level"); parser->state = XML_STATE_END_DOCUMENT; token->type = XML_TOKEN_END_DOCUMENT; return 0; } if(text_found) { token->type = XML_TOKEN_TEXT; token->str = begin; token->length = parser->pos - begin; return 1; } else { const char* begin = parser->pos+1; if(*begin == '?') { parser->pos = strstr(begin,"?>"); ERROR_AND_RETURN(parser->pos == NULL, "End of DTD not found"); parser->pos += 2; return xml_get_token(parser, token); } else if(*begin == '/') { --parser->elements; ++begin; parser->pos = strchr(begin,'>'); ERROR_AND_RETURN(parser->pos == NULL, "unexpected end of document"); token->type = XML_TOKEN_END_ELEMENT; token->str = begin; token->length = parser->pos - token->str; ++parser->pos; return 1; } else { ++parser->elements; token->str = parser->pos; while(*parser->pos && *parser->pos != ' ' && *parser->pos != '>' && *parser->pos != '/') { ++parser->pos; } ERROR_AND_RETURN(!*parser->pos, "unexpected end of document"); token->type = XML_TOKEN_BEGIN_ELEMENT; token->str = begin; token->length = parser->pos - token->str; if(*parser->pos == '>') { ++parser->pos; parser->state = XML_STATE_FIND_ELEMENT; } else { parser->state = XML_STATE_FIND_ATTRIBUTE; } return 1; } } } else if(parser->state == XML_STATE_FIND_ATTRIBUTE) { while(*parser->pos == ' ') { ++parser->pos; } ERROR_AND_RETURN(!*parser->pos, "unexpected end of document"); if(*parser->pos == '/') { --parser->elements; token->type = XML_TOKEN_END_ELEMENT; token->str = ""; token->length = 0; ++parser->pos; while(*parser->pos != '>') { ERROR_AND_RETURN(!*parser->pos, "unexpected end of document"); ERROR_AND_RETURN(isalpha(*parser->pos) || ispunct(*parser->pos), "unexpected characters at end of element"); ++parser->pos; } } else if(isalpha(*parser->pos)) { token->type = XML_TOKEN_ATTR_NAME; token->str = parser->pos; parser->pos = strchr(token->str, '='); ERROR_AND_RETURN(parser->pos == NULL, "unexpected end of document"); token->length = parser->pos - token->str; parser->state = XML_STATE_FIND_VALUE; return 1; } else if(*parser->pos == '>') { ++parser->pos; parser->state = XML_STATE_FIND_ELEMENT; return xml_get_token(parser, token); } else { SET_ERROR("unexpected characters when searching for attribute"); return 0; } } else if(parser->state == XML_STATE_FIND_VALUE) { ++parser->pos; while(*parser->pos && *parser->pos != '"') { ERROR_AND_RETURN(!isspace(*parser->pos), "unexpected character when searching for value"); ++parser->pos; } ERROR_AND_RETURN(!*parser->pos, "unexpected end of document"); token->str = parser->pos+1; parser->pos = strchr(token->str,'"'); ERROR_AND_RETURN(parser->pos == NULL, "unexpected end of document"); token->length = parser->pos - token->str; token->type = XML_TOKEN_ATTR_VALUE; ++parser->pos; parser->state = XML_STATE_FIND_ATTRIBUTE; return 1; } else { SET_ERROR("bad state"); return 0; } }
/*************************************************************************** * input_string() * Read input from the user ... on the widget layer. *********************************************************************PROTO*/ char * input_string(SDL_Surface *screen, int x, int y, int opaque) { int pos; char c; char retval[1024]; SDL_Surface *text, *ctext; SDL_Color tc, cc; SDL_Rect rect; SDL_Event event; Uint32 text_color = int_input_color0; Uint32 cursor_color = int_input_color1; Uint32 our_black = opaque ? int_solid_black : int_black; memset(retval, 0, sizeof(retval)); retval[0] = ' '; pos = 1; SDL_GetRGB(text_color, screen->format, &tc.r, &tc.g, &tc.b); SDL_GetRGB(cursor_color, screen->format, &cc.r, &cc.g, &cc.b); ctext = TTF_RenderText_Blended(font, "_", cc); Assert(ctext); while (1) { int changed = 0; /* did they change the text string? */ int blink = 1; /* toggle the blinking the cursor */ Uint32 flip_when = SDL_GetTicks(); /* display the current string */ text = TTF_RenderText_Blended(font, retval, tc); Assert(text); rect.x = x; rect.y = y; rect.w = text->w; rect.h = text->h; SDL_BlitSurface(text, NULL, widget_layer, &rect); /* OK to ignore the intervening flame layer */ SDL_BlitSurface(text, NULL, screen, &rect); SDL_UpdateSafe(screen, 1, &rect); rect.x += rect.w; rect.w = ctext->w; rect.h = ctext->h; changed = 0; while (!changed) { if (SDL_GetTicks() > flip_when) { if (blink) { SDL_BlitSurface(ctext, NULL, screen, &rect); SDL_BlitSurface(ctext, NULL, widget_layer, &rect); } else { SDL_FillRect(widget_layer, &rect, our_black); SDL_FillRect(screen, &rect, our_black); SDL_BlitSurface(flame_layer, &rect, screen, &rect); SDL_BlitSurface(widget_layer, &rect, screen, &rect); } SDL_UpdateSafe(screen, 1, &rect); flip_when = SDL_GetTicks() + 400; blink = !blink; } if (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { changed = 1; switch (event.key.keysym.sym) { case SDLK_RETURN: return strdup(retval + 1); case SDLK_BACKSPACE: if (pos > 1) pos--; retval[pos] = 0; rect.x = x; rect.w = text->w + ctext->w; SDL_FillRect(widget_layer, &rect, our_black); SDL_FillRect(screen, &rect, our_black); SDL_BlitSurface(flame_layer, &rect, screen, &rect); SDL_BlitSurface(widget_layer, &rect, screen, &rect); SDL_UpdateSafe(screen, 1, &rect); break; default: c = event.key.keysym.unicode; if (c == 0) break; SDL_FillRect(widget_layer, &rect, our_black); SDL_FillRect(screen, &rect, our_black); SDL_BlitSurface(flame_layer, &rect, screen, &rect); SDL_BlitSurface(widget_layer, &rect, screen, &rect); SDL_UpdateSafe(screen, 1, &rect); if (isalpha(c) || isdigit(c) || isspace(c) || ispunct(c)) retval[pos++] = c; break; } } } else atris_run_flame(); } SDL_FreeSurface(text); } }
static int isthisnonword(MMIOT *f, int i) { return isthisspace(f, i) || ispunct(peek(f,i)); }
void parse(option * c, const char *file) { FILE *f; // unsigned int line_number//, i; char line[BUFSIZ]; int leftside; char key[BUFSIZ], value[BUFSIZ]; // char *arg, *cmt, *opt; char *p; struct stat defshell_stat; char *shell; int found = FALSE; unsigned int x=0;//, y=0; bzero(c, sizeof (struct s_option)); // Set up some defaults strcpy(c->logdir, LOGDIR); c->fdl='-'; strcpy(c->defshell, "/bin/sh"); c->priority=-1; // No defaults here c->facility=-1; // or here... c->clearenvironment=1; f = fopen(file, "r"); if (f==NULL) { fprintf(stderr,"Warning: No config file found. Using compiled-in defaults:\nLogdir\t%s\nDefault Shell:\t%s\nSyslog disabled\n",c->logdir, c->defshell); // Just run with the defaults, ignore the rest return; } while (fgets(line, BUFSIZ-1, f)) { p=strchr(line,'='); if (!p) { // fprintf(stderr, "Invalid line in config file: %s\n",line); continue; } leftside=1; key[0]=value[0]=0; if (line[0]=='#') continue; // Ignore comments, blank lines // Trim the whitespace, split into key/value for (x=0 ; x<strlen(line);x++) if (!isspace(line[x])) { if (line[x]=='=') { leftside=0; continue; } if (leftside) strncat(key, &line[x], 1); else strncat(value, &line[x], 1); } // fprintf(stderr, "Parsed key [%s] and value [%s]\n",key, value); if(strcmp(key,"throttlebps")==0) c->bytespersecond=strtol(value,NULL,10); if (strcmp(key,"-cargallow")==0) { strcat(c->argallow,"$"); strcat(c->argallow,value); strcat(c->argallow,"$"); } if (strcmp(key,"logdir")==0) strcpy(c->logdir,value); if (strcmp(key,"clearenvironment")==0) { if(strncmp(value,"no",2)==0) { c->clearenvironment=0; } else c->clearenvironment=1; } if (strcmp(key,"defaultshell")==0) strcpy(c->defshell,value); if (strcmp(key,"delimiter")==0) c->fdl=value[0]; if (strcmp(key,"syslog.facility")==0) { // I really hate the way this is done... found = FALSE; #ifdef LOG_AUTH if (!strcmp(value, "LOG_AUTH")) { c->facility = LOG_AUTH; found = TRUE; } #endif /* LOG_AUTH */ #ifdef LOG_AUTHPRIV if (!strcmp(value, "LOG_AUTHPRIV")) { c->facility = LOG_AUTHPRIV; found = TRUE; } #endif /* LOG_AUTHPRIV */ #ifdef LOG_CRON if (!strcmp(value, "LOG_CRON")) { c->facility = LOG_CRON; found = TRUE; } #endif /* LOG_CRON */ #ifdef LOG_DAEMON if (!strcmp(value, "LOG_DAEMON")) { c->facility = LOG_DAEMON; found = TRUE; } #endif /* LOG_DAEMON */ #ifdef LOG_FTP if (!strcmp(value, "LOG_FTP")) { c->facility = LOG_FTP; found = TRUE; } #endif /* LOG_FTP */ #ifdef LOG_KERN if (!strcmp(value, "LOG_KERN")) { c->facility = LOG_KERN; found = TRUE; } #endif /* LOG_KERN */ #ifdef LOG_LOCAL0 if (!strcmp(value, "LOG_LOCAL0")) { c->facility = LOG_LOCAL0; found = TRUE; } #endif /* LOG_LOCAL0 */ #ifdef LOG_LOCAL1 if (!strcmp(value, "LOG_LOCAL1")) { c->facility = LOG_LOCAL1; found = TRUE; } #endif /* LOG_LOCAL1 */ #ifdef LOG_LOCAL2 if (!strcmp(value, "LOG_LOCAL2")) { c->facility = LOG_LOCAL2; found = TRUE; } #endif /* LOG_LOCAL2 */ #ifdef LOG_LOCAL3 if (!strcmp(value, "LOG_LOCAL3")) { c->facility = LOG_LOCAL3; found = TRUE; } #endif /* LOG_LOCAL3 */ #ifdef LOG_LOCAL4 if (!strcmp(value, "LOG_LOCAL4")) { c->facility = LOG_LOCAL4; found = TRUE; } #endif /* LOG_LOCAL4 */ #ifdef LOG_LOCAL5 if (!strcmp(value, "LOG_LOCAL5")) { c->facility = LOG_LOCAL5; found = TRUE; } #endif /* LOG_LOCAL5 */ #ifdef LOG_LOCAL6 if (!strcmp(value, "LOG_LOCAL6")) { c->facility = LOG_LOCAL6; found = TRUE; } #endif /* LOG_LOCAL6 */ #ifdef LOG_LOCAL7 if (!strcmp(value, "LOG_LOCAL7")) { c->facility = LOG_LOCAL7; found = TRUE; } #endif /* LOG_LOCAL7 */ #ifdef LOG_LPR if (!strcmp(value, "LOG_LPR")) { c->facility = LOG_LPR; found = TRUE; } #endif /* LOG_LPR */ #ifdef LOG_MAIL if (!strcmp(value, "LOG_MAIL")) { c->facility = LOG_MAIL; found = TRUE; } #endif /* LOG_MAIL */ #ifdef LOG_NEWS if (!strcmp(value, "LOG_NEWS")) { c->facility = LOG_NEWS; found = TRUE; } #endif /* LOG_NEWS */ #ifdef LOG_SYSLOG if (!strcmp(value, "LOG_SYSLOG")) { c->facility = LOG_SYSLOG; found = TRUE; } #endif /* LOG_SYSLOG */ #ifdef LOG_USER if (!strcmp(value, "LOG_USER")) { c->facility = LOG_USER; found = TRUE; } #endif /* LOG_USER */ #ifdef LOG_UUCP if (!strcmp(value, "LOG_UUCP")) { c->facility = LOG_UUCP; found = TRUE; } #endif /* LOG_UUCP */ if (found == FALSE) { fprintf(stderr,"Invalid syslog.facility in config file\n"); exit(-1); } } if (strcmp(key,"syslog.priority")==0) { int found = FALSE; #ifdef LOG_EMERG if (!strcmp(value, "LOG_EMERG")) { c->priority = LOG_EMERG; found = TRUE; } #endif /* LOG_EMERG */ #ifdef LOG_ALERT if (!strcmp(value, "LOG_ALERT")) { c->priority = LOG_ALERT; found = TRUE; } #endif /* LOG_ALERT */ #ifdef LOG_CRIT if (!strcmp(value, "LOG_CRIT")) { c->priority = LOG_CRIT; found = TRUE; } #endif /* LOG_CRIT */ #ifdef LOG_ERR if (!strcmp(value, "LOG_ERR")) { c->priority = LOG_ERR; found = TRUE; } #endif /* LOG_ERR */ #ifdef LOG_WARNING if (!strcmp(value, "LOG_WARNING")) { c->priority = LOG_WARNING; found = TRUE; } #endif /* LOG_WARNING */ #ifdef LOG_NOTICE if (!strcmp(value, "LOG_NOTICE")) { c->priority = LOG_NOTICE; found = TRUE; } #endif /* LOG_NOTICE */ #ifdef LOG_INFO if (!strcmp(value, "LOG_INFO")) { c->priority = LOG_INFO; found = TRUE; } #endif /* LOG_INFO */ #ifdef LOG_DEBUG if (!strcmp(value, "LOG_DEBUG")) { c->priority = LOG_DEBUG; found = TRUE; } #endif /* LOG_DEBUG */ if (found == FALSE) { fprintf(stderr, "%s: syslog.priority: level '%s' is unknown.\n", file, value); exit(EXIT_FAILURE); } } } // Validation // delimiter if (!ispunct(c->fdl)) { fprintf(stderr,"%s: delimiter [%c] must be punctuation\n",file, c->fdl); exit(EXIT_FAILURE); } // defaultshell #ifdef HAVE_GETUSERSHELL setusershell(); while ((shell = (char *)getusershell())) if (!strcmp(shell, c->defshell)) found = TRUE; endusershell(); if (!found) { fprintf(stderr, "default shell '%s' is not in /etc/shells.\n", c->defshell); exit(EXIT_FAILURE); } #endif /* HAVE_GETUSERSHELL */ if ((stat(c->defshell, &defshell_stat)) == -1) { fprintf(stderr, "default shell '%s': %s (%i)\n", value, strerror(errno), errno); exit(EXIT_FAILURE); } fclose(f); }
int pmatch_quot(char **P_PtrPtr, char **S_PtrPtr, int *Flags) { int result=MATCH_FAIL, OldFlags; char P_Char, S_Char, *OldPos; P_Char=**P_PtrPtr; S_Char=**S_PtrPtr; switch (P_Char) { case 'b': if (S_Char=='\b') result=MATCH_ONE; break; case 'e': if (S_Char==27) result=MATCH_ONE; break; //escape case 'n': if (S_Char=='\n') result=MATCH_ONE; break; case 'r': if (S_Char=='\r') result=MATCH_ONE; break; case 't': if (S_Char==' ') result=MATCH_ONE; break; case 'l': if (islower(S_Char)) result=MATCH_ONE; break; case 'x': result=MATCH_HEX; break; case 'A': if (isalpha(S_Char)) result=MATCH_ONE; break; case 'B': if (isalnum(S_Char)) result=MATCH_ONE; break; case 'D': if (isdigit(S_Char)) result=MATCH_ONE; break; case 'S': if (isspace(S_Char)) result=MATCH_ONE; break; case 'P': if (ispunct(S_Char)) result=MATCH_ONE; break; case 'X': if (isxdigit(S_Char)) result=MATCH_ONE; break; case 'U': if (isupper(S_Char)) result=MATCH_ONE; break; case '+': result=MATCH_SWITCH_ON; break; case '-': result=MATCH_SWITCH_OFF; break; default: if (S_Char==P_Char) result=MATCH_ONE; break; } switch (result) { case MATCH_ONE: (*P_PtrPtr)++; break; case MATCH_HEX: if (! pmatch_ascii((*P_PtrPtr)+1,S_Char,MATCH_HEX)) return(MATCH_FAIL); (*P_PtrPtr)+=2; break; case MATCH_OCTAL: if (! pmatch_ascii((*P_PtrPtr)+1,S_Char,MATCH_OCTAL)) return(MATCH_FAIL); (*P_PtrPtr)+=3; break; case MATCH_SWITCH_ON: case MATCH_SWITCH_OFF: //some switches need to be applied in order for a pattern to match //(like the case-insensitive switch) others should only be applied if //it matches. So we apply the switch, but if the subsequent pmatch_char fails //we unapply it OldFlags=*Flags; OldPos=*P_PtrPtr; (*P_PtrPtr)++; //go past the + or - to the actual type pmatch_switch(**P_PtrPtr, result, Flags); (*P_PtrPtr)++; result=pmatch_char(P_PtrPtr, S_PtrPtr, Flags); if ((result==MATCH_FAIL) || (result==MATCH_CONT)) { *P_PtrPtr=OldPos; *Flags=OldFlags; } return(result); break; case MATCH_FAIL: if (*Flags & PMATCH_SUBSTR) return(MATCH_CONT); return(MATCH_FAIL); break; } return(MATCH_ONE); }
void Lexer::next() { // Top-level lexer routine. This function reads in characters one at a // time and attempts to match them to tokens. token(Token::NONE); while (token() == Token::NONE) { if (char_ == '\n') { location_.first_column = 1; location_.first_line = line_+1; } else { location_.first_column = column_+1; location_.first_line = line_; } location_.first_offset = offset_; token_[front_].location(location_); value(""); if (char_ == '\n' && input_ == &std::cin) { token(Token::END); } else if (char_ == '\n' && !ignore_newline_) { read(); value(""); token(Token::SEPARATOR); ignore_newline_ = true; } else if (char_ == '/' && token(-1).is_operator() && token(-1) != Token::RIGHT_PARENS) { regex(); expect_comment_ = false; } else if (isdigit(char_)) { number_or_dot(); expect_comment_ = false; } else if (isupper(char_)) { type_or_const(); expect_comment_ = false; } else if (islower(char_) || char_ == '_') { ident_or_keyword(); expect_comment_ = false; } else if (char_ == '@') { special(); expect_comment_ = false; } else if (char_ == '"') { string(); expect_comment_ = false; } else if (char_ == '\'') { string_or_char(); expect_comment_ = false; } else if (char_ == '#') { comment(); } else if (ispunct(char_)) { operator_or_typevar(); } else if (isspace(char_)) { read(); token(Token::NONE); } else if (char_ == EOF) { token(Token::END); } else { token(Token::ERROR); read(); } location_.last_column = column_; location_.last_line = line_; location_.last_offset = offset_; token_[front_].location(location_); } if (env_->dump_lex() && location_.file->is_input_file()) { if (token(0) == Token::SEPARATOR) { Stream::stout() << "eol "; } else { Stream::stout() << token(0) << " "; } Stream::stout()->flush(); } front_ = (front_+1)%LEXER_LOOKAHEAD; }
bool Symbol::IsSymbol(unsigned char sym) { return isspace(sym) || isblank(sym) || ispunct(sym); }
int str_ispunct(int i) { assert(i >= -1 && i < 256); return ispunct(i); }
int main(int argc, char *argv[]) { int on = 0; int c = 0; int i = 0; char *filename = "data"; char idstring[200] = {0}; if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); exit(0); } for(i = 0; i < argc; i++) { if (argv[i] == NULL){ break; } else if(argv[i][0] == '-') { if(argv[i][1] == 'h') { print_help(); exit(0); } else if(argv[i][1] == 'f') { if(argv[i + 1] != NULL) filename = argv[i + 1]; else { fputs("[!] you passed '-f' without giving an argument!\n", stderr); } } } } initMessenger(); load_key(filename); m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_statusmessage(print_statuschange); initscr(); noecho(); raw(); getmaxyx(stdscr, y, x); new_lines("/h for list of commands"); get_id(idstring); new_lines(idstring); strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); if (resolved_address != 0) bootstrap_ip_port.ip.i = resolved_address; else exit(1); unsigned char *binary_string = hex_string_to_bin(argv[3]); DHT_bootstrap(bootstrap_ip_port, binary_string); free(binary_string); nodelay(stdscr, TRUE); while(true) { if (on == 0 && DHT_isconnected()) { new_lines("[i] connected to DHT\n[i] define username with /n"); on = 1; } doMessenger(); c_sleep(1); do_refresh(); c = getch(); if (c == ERR || c == 27) continue; getmaxyx(stdscr, y, x); if (c == '\n') { line_eval(line); strcpy(line, ""); } else if (c == 8 || c == 127) { line[strlen(line)-1] = '\0'; } else if (isalnum(c) || ispunct(c) || c == ' ') { strcpy(line, appender(line, (char) c)); } } endwin(); return 0; }
int main(void) { unsigned char *s; int c; prclass("ispunct", &ispunct); prclass("isdigit", &isdigit); prclass("islower", &islower); prclass("isupper", &isupper); prclass("isalpha", &isalpha); prclass("isalnum", &isalnum); for (s = (unsigned char *) "0123456789"; *s; s++) assert(isdigit(*s) && isxdigit(*s)); for (s = (unsigned char *) "abcdefABCDEF"; *s; s++) assert(isxdigit(*s)); for (s = (unsigned char *) "abcdefghijklmnopqrstuvwxyz"; *s; s++) assert(islower(*s)); for (s = (unsigned char *) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; *s; s++) assert(isupper(*s)); for (s = (unsigned char *) "!\"#%&'();<=>?[\\]*+,-./:^_{|}~"; *s; s++) assert(ispunct(*s)); for (s = (unsigned char *) "\f\n\r\t\v"; *s; s++) assert(isspace(*s) && iscntrl(*s)); assert(isspace(' ') && isprint(' ')); assert(iscntrl('\a') && iscntrl('\b')); for (c = EOF; c <= UCHAR_MAX; c++) { if (isdigit(c)) assert(isalnum(c)); if (isupper(c)) assert(isalpha(c)); if (islower(c)) assert(isalpha(c)); if (isalpha(c)) assert(isalnum(c) && !isdigit(c)); if (isalnum(c)) assert(isgraph(c) && !ispunct(c)); if (ispunct(c)) assert(isgraph(c)); if (isgraph(c)) assert(isprint(c)); if (isspace(c)) assert(c==' ' || !isprint(c)); if (iscntrl(c)) assert(!isalnum(c)); } for (s = (unsigned char *) "0123456789"; *s; s++) assert((isdigit)(*s) && (isxdigit)(*s)); for (s = (unsigned char *) "abcdefABCDEF"; *s; s++) assert((isxdigit)(*s)); for (s = (unsigned char *) "abcdefghijklmnopqrstuvwxyz"; *s; s++) assert((islower)(*s)); for (s = (unsigned char *) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; *s; s++) assert((isupper)(*s)); for (s = (unsigned char *) "!\"#%&'();<=>?[\\]*+,-./:^_{|}~"; *s; s++) assert((ispunct)(*s)); for (s = (unsigned char *) "\f\n\r\t\v"; *s; s++) assert((isspace)(*s) && (iscntrl)(*s)); assert((isspace)(' ') && (isprint)(' ')); assert((iscntrl)('\a') && (iscntrl)('\b')); for (c = EOF; c <= UCHAR_MAX; c++) { if ((isdigit)(c)) assert((isalnum)(c)); if ((isupper)(c)) assert((isalpha)(c)); if ((islower)(c)) assert((isalpha)(c)); if ((isalpha)(c)) assert((isalnum)(c) && !(isdigit)(c)); if ((isalnum)(c)) assert((isgraph)(c) && !(ispunct)(c)); if ((ispunct)(c)) assert((isgraph)(c)); if ((isgraph)(c)) assert((isprint)(c)); if ((isspace)(c)) assert(c == ' ' || !(isprint)(c)); if ((iscntrl)(c)) assert(!(isalnum)(c)); } puts("SUCCESS testing <ctype.h>"); return 0; }