// We've just read a '<!' at position starti, // so this may be a comment or other ignored section, or it may // be just a literal string if there is no close before end of file // (other browsers do that). // The accepted practice seems to be (note: contrary to SGML spec!): // If see <!--, look for --> to close, or if none, > to close. // If see <!(not --), look for > to close. // If no close before end of file, leave original characters in as literal data. // // If we see ignorable stuff, return Comment. // Else return nil (caller should back up and try again when more data arrives, // unless at end of file, in which case caller should just make '<' a data token). static int comment(TokenSource* ts) { int nexti; int havecomment; int c; nexti = ts->i; havecomment = 0; c = getchar(ts); if(c == '-') { c = getchar(ts); if(c == '-') { if(findstr(ts, L"-->")) havecomment = 1; else backup(ts, nexti); } } if(!havecomment) { if(c == '>') havecomment = 1; else if(c >= 0) { if(findstr(ts, L">")) havecomment = 1; } } if(havecomment) return Comment; return -1; }
// Returns pointer to first export entry for a given module name and library static SceLibraryEntryTable *find_exports(const char *module, const char *lib) { // Search for module name char *p, *foundModule; foundModule = (void *)GAME_MEMORY_START; do { foundModule = findstr(module, foundModule, 0x0A000000 - (uintptr_t)foundModule); if (foundModule == NULL) { return NULL; } // Search for library name next to module name (1 KiB size enough I guess) p = findstr(lib, foundModule, 1024); if (p != NULL) { // Search for pointer to library name close to library name p = findw((uintptr_t)p, (void *)(p - 1024), 1024); } foundModule += 1024; } while (p == NULL); return (void *)p; }
int read_wav_header(FILE *fp) { char txt[5] = "\0\0\0\0"; char buff[4]; int byte, p=0; char fmt_[5] = "fmt "; char data[5] = "data"; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "RIFF", 4)) return -1; // pos_WAVE = 8L if (fread(txt, 1, 4, fp) < 4) return -1; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "WAVE", 4)) return -1; // pos_fmt = 12L for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; buff[p % 4] = byte; p++; if (p==4) p=0; if (findstr(buff, fmt_, p) == 4) break; } if (fread(buff, 1, 4, fp) < 4) return -1; if (fread(buff, 1, 2, fp) < 2) return -1; if (fread(buff, 1, 2, fp) < 2) return -1; channels = buff[0] + (buff[1] << 8); if (fread(buff, 1, 4, fp) < 4) return -1; memcpy(&sample_rate, buff, 4); if (fread(buff, 1, 4, fp) < 4) return -1; if (fread(buff, 1, 2, fp) < 2) return -1; byte = buff[0] + (buff[1] << 8); if (fread(buff, 1, 2, fp) < 2) return -1; bits_sample = buff[0] + (buff[1] << 8); for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; buff[p % 4] = byte; p++; if (p==4) p=0; if (findstr(buff, data, p) == 4) break; } if (fread(buff, 1, 4, fp) < 4) return -1; fprintf(stderr, "sample_rate: %d\n", sample_rate); fprintf(stderr, "bits : %d\n", bits_sample); fprintf(stderr, "channels : %d\n", channels); if ((bits_sample != 8) && (bits_sample != 16)) return -1; samples_per_bit = sample_rate/(float)BAUD; fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit); return 0; }
int read_wav_header(FILE *fp) { char txt[4+1] = "\0\0\0\0"; unsigned char dat[4]; int byte, p=0; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "RIFF", 4)) return -1; if (fread(txt, 1, 4, fp) < 4) return -1; // pos_WAVE = 8L if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "WAVE", 4)) return -1; // pos_fmt = 12L for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; txt[p % 4] = byte; p++; if (p==4) p=0; if (findstr(txt, "fmt ", p) == 4) break; } if (fread(dat, 1, 4, fp) < 4) return -1; if (fread(dat, 1, 2, fp) < 2) return -1; if (fread(dat, 1, 2, fp) < 2) return -1; channels = dat[0] + (dat[1] << 8); if (fread(dat, 1, 4, fp) < 4) return -1; memcpy(&sample_rate, dat, 4); //sample_rate = dat[0]|(dat[1]<<8)|(dat[2]<<16)|(dat[3]<<24); if (fread(dat, 1, 4, fp) < 4) return -1; if (fread(dat, 1, 2, fp) < 2) return -1; //byte = dat[0] + (dat[1] << 8); if (fread(dat, 1, 2, fp) < 2) return -1; bits_sample = dat[0] + (dat[1] << 8); // pos_dat = 36L + info for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; txt[p % 4] = byte; p++; if (p==4) p=0; if (findstr(txt, "data", p) == 4) break; } if (fread(dat, 1, 4, fp) < 4) return -1; fprintf(stderr, "sample_rate: %d\n", sample_rate); fprintf(stderr, "bits : %d\n", bits_sample); fprintf(stderr, "channels : %d\n", channels); if ((bits_sample != 8) && (bits_sample != 16)) return -1; samples_per_bit = sample_rate/(float)BAUD_RATE; fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit); return 0; }
STDMETHODIMP CBDictionary::Split(BSTR bstrExpression, BSTR bstrKeyDelimiter, BSTR bstrDelimiter) { int nCount; int strKeyDelimiterLength = ::SysStringLen(bstrKeyDelimiter); int strDelimiterLength = ::SysStringLen(bstrDelimiter); BSTR pstr, pstr1; CBVariant varKey; VARIANT varValue; CRBMap<CBVariant, CComVariant>::CPair* pPair; static VARIANT varEmpty; varKey.vt = VT_BSTR; VariantInit(&varValue); varValue.vt = VT_BSTR; nCount = ::SysStringLen(bstrExpression); m_cs.Enter(); while(nCount > 0) { pstr = findstr(bstrExpression, nCount, bstrDelimiter); pstr1 = findstr(bstrExpression, pstr - bstrExpression, bstrKeyDelimiter); varKey.bstrVal = ::SysAllocStringLen(bstrExpression, pstr1 - bstrExpression); if(pstr1 < pstr)pstr1 += strKeyDelimiterLength; varValue.bstrVal = ::SysAllocStringLen(pstr1, pstr - pstr1); pPair = m_mapItems.Lookup(varKey); if(pPair == NULL) { pPair = (CRBMap<CBVariant, CComVariant>::CPair*)m_mapItems.SetAt(varKey, varEmpty); m_posArray.Add(pPair); }else VariantClear(&pPair->m_value); SysFreeString(varKey.bstrVal); CopyMemory(&pPair->m_value, &varValue, sizeof(VARIANT)); nCount -= pstr + strDelimiterLength - bstrExpression; bstrExpression = pstr + strDelimiterLength; } m_cs.Leave(); varKey.vt = VT_EMPTY; return S_OK; }
int main(int argc, char *argv[]) { printf("%d \n", argc); for(int i = 0 ; i < argc ; i++) { printf("%d : %s \n", i, argv[i]); } char* string = argv[1]; char* result = strdup(string); char* stringdup = strdup(string); int stringLength = strlen(string); char* word = strtok(stringdup, " "); while(word != NULL){ printf("word : |%s|\n", word); int wordLength = strlen(word); int i = findstr(word, string); printf("|%s| index in %s : %d\n",word, string, i); int from = i ; int to = i + wordLength - 1; printf("from : %d, to : %d\n", from , to ); ReverseString(result, from, to); printf("Result --> %s\n", result); word = strtok(NULL, " "); } free(stringdup); ReverseString(result, 0 , strlen(result) - 1); printf("Final Result: %s\n", result); }
/* * Define a user named label to have the offset of the next opcode. * * given: * name label name */ void definelabel(char *name) { register LABEL *lp; /* current label */ long i; /* current label index */ i = findstr(&labelnames, name); if (i >= 0) { lp = &labels[i]; if (lp->l_offset >= 0) { scanerror(T_NULL, "Label \"%s\" is multiply defined", name); return; } setlabel(lp); return; } if (labelcount >= MAXLABELS) { scanerror(T_NULL, "Too many labels in use"); return; } lp = &labels[labelcount++]; lp->l_chain = -1L; lp->l_offset = (long)curfunc->f_opcodecount; lp->l_name = addstr(&labelnames, name); clearopt(); }
int dodfined ( /* replaces defined commands with 0 or 1 */ char *ln) { int b, c, d, pflag; pflag = FALSE; while (b = findstr (1, ln, " defined ")) { c = b + 8; /* point to next token */ if (ln[c] == '(') { c += 2; /* point to identifier token */ pflag = TRUE; } d = dodef (ln, c - 1); /* returns TRUE if defined, FALSE if not defined */ while (ln[++c] != ' ') /* get space at end of identifier */ ; if (pflag) { if (ln[++c] == ')' && ln[++c] == ' ') ; else doerr (3, c); /* No end ) */ } ln[b] = d + '0'; /* replace defined with 0 or 1 */ strcpy (&ln[++b], &ln[c]); } }
/* * Return the index which identifies an element name. * Returns minus one if the element name is unknown. * * given: * name element name */ int findelement(char *name) { if (elements.h_list == NULL) return -1; return findstr(&elements, name); }
/* * Find the user function with the specified name, and return its index. * If the function does not exist, its name is added to the function table * and an error will be generated when it is called if it is still undefined. * * given: * name name of function */ long adduserfunc(char *name) { long index; /* index of function */ index = findstr(&funcnames, name); if (index >= 0) return index; if (funccount >= funcavail) { functions = (FUNC **) realloc(functions, sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE)); if (functions == NULL) { math_error("Failed to reallocate function table"); /*NOTREACHED*/ } funcavail += FUNCALLOCSIZE; } if (addstr(&funcnames, name) == NULL) { math_error("Cannot save function name"); /*NOTREACHED*/ } index = funccount++; functions[index] = NULL; return index; }
/* * Define a (possibly) new element name for an object. * Returns an index which identifies the element name. */ int addelement(char *name) { STRINGHEAD *hp; int index; hp = &elements; if (hp->h_list == NULL) initstr(hp); index = findstr(hp, name); if (index >= 0) return index; if (addstr(hp, name) == NULL) { math_error("Cannot allocate element name"); /*NOTREACHED*/ } return findstr(hp, name); }
int findskill(const char *s) { if (!_strcmpl(s, "horse")) return SK_HORSE_TRAINING; if (!_strcmpl(s, "entertain")) return SK_ENTERTAINMENT; return findstr(skillnames, s, MAXSKILLS); }
/* * get index of defined user function with specified name, or -1 if there * is none or if it has been undefined */ long getuserfunc(char *name) { long index; index = findstr(&funcnames, name); if (index >= 0 && functions[index] != NULL) return index; return -1L; }
/* * Check an object name to see if it is currently defined. * If so, the index for the object type is returned. * If the object name is currently unknown, then -1 is returned. */ int checkobject(char *name) { STRINGHEAD *hp; hp = &objectnames; if (hp->h_list == NULL) return -1; return findstr(hp, name); }
/* * Add a possibly new parameter variable definition. * Returns the index of the variable into the parameter symbol table. * Minus one indicates the symbol could not be added. * * given: * name name of parameter variable */ long addparam(char *name) { long index; /* current symbol index */ index = findstr(¶mnames, name); if (index >= 0) return index; index = paramnames.h_count; (void) addstr(¶mnames, name); curfunc->f_paramcount++; return index; }
/* * Add a possibly new local variable definition. * Returns the index of the variable into the local symbol table. * Minus one indicates the symbol could not be added. * * given: * name name of local variable */ long addlocal(char *name) { long index; /* current symbol index */ index = findstr(&localnames, name); if (index >= 0) return index; index = localnames.h_count; (void) addstr(&localnames, name); curfunc->f_localcount++; return index; }
/* * Remove user defined function */ void rmuserfunc(char *name) { long index; /* index of function */ index = findstr(&funcnames, name); if (index < 0) { fprintf(stderr, "%s() has never been defined\n", name); return; } if (functions[index] == NULL) return; freenumbers(functions[index]); free(functions[index]); if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) printf("%s() undefined\n", name); functions[index] = NULL; }
int main() { str input_string, pattern; int p; printf("please input a string:\n"); // scanf %s 读取个字符串 //scanf("%s", input_string.string); gets(input_string.string); printf("please input the pattern:\n"); //scanf("%s", pattern.string); gets(pattern.string); printf("string is %s\npattern is %s\n", input_string.string, pattern.string); input_string.len = strlen(input_string.string); pattern.len = strlen(pattern.string); p = findstr(input_string, pattern); printf("p = %d\n", p); if (p == -1) printf("No, matching!\n"); else printf("Matching! the postion is %d.\n", p); return 0; }
f_selxbuffer() { register char *ans; register struct buffer *b; b = last_buf; /* This is default */ ans = ask("Select existing buffer (%s): ", b->b_name); if (ans == 0) /* Aborted */ return; if (*ans != 0) { for (b = buf_head; b != 0; b = b->b_next) if (findstr(ans, b->b_name)) break; if (b == 0) ding("That isn't a substring of any buffer name!"); } chkfree(ans); if (b != 0) { saytoo(" => "); sayntoo(b->b_name); sel_buf(b); } }
//find unsigned string::find(const char c,unsigned n,unsigned start) const{ return findstr(&c,1,start,n);}
int read_wav_header(FILE *fp) { char txt[5] = "\0\0\0\0"; char buff[4]; int byte, num, i; long p = 0, pos_fmt, pos_dat; char fmt_[5] = "fmt "; char data[5] = "data"; if (fseek(fp, 0L, SEEK_SET)) return -1; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "RIFF", 4)) return -1; if (fseek(fp, 8L, SEEK_SET)) return -1; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "WAVE", 4)) return -1; // pos_fmt = 12L for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; buff[p % 4] = byte; p++; if (findstr(buff, fmt_, p) == 4) break; } pos_fmt = ftell(fp)-4; //fprintf(stderr, "pos_fmt %ld\n", pos_fmt); if (fseek(fp, pos_fmt+10, SEEK_SET)) return -1; num = 0; for (i = 0; i < 2; i++) { if ( (byte=fgetc(fp)) == EOF ) return -1; num |= (byte << (8*i)); } channels = num; // if (fseek(fp, pos_fmt+12L, SEEK_SET)) return -1; // 24L num = 0; for (i = 0; i < 4; i++) { if ( (byte=fgetc(fp)) == EOF ) return -1; num |= (byte << (8*i)); } sample_rate = num; if (fseek(fp, pos_fmt+22, SEEK_SET)) return -1; // 34L num = 0; for (i = 0; i < 2; i++) { if ( (byte=fgetc(fp)) == EOF ) return -1; num |= (byte << (8*i)); } bits_sample = num; // pos_dat = 36L for ( ; ; ) { if ( (byte=fgetc(fp)) == EOF ) return -1; buff[p % 4] = byte; p++; if (findstr(buff, data, p) == 4) break; } pos_dat = ftell(fp)-4; //fprintf(stderr, "pos_dat %ld\n", pos_dat); /* if (fseek(fp, 36L, SEEK_SET)) return -1; if (fread(txt, 1, 4, fp) < 4) return -1; if (strncmp(txt, "data", 4)) return -1; */ if (fseek(fp, pos_dat+8, SEEK_SET)) return -1; // 44L fprintf(stderr, "sample_rate: %d\n", sample_rate); fprintf(stderr, "bits : %d\n", bits_sample); fprintf(stderr, "channels : %d\n", channels); if ((bits_sample != 8) && (bits_sample != 16)) return -1; samples_per_bit = sample_rate/(float)BAUD_RATE; fprintf(stderr, "samples/bit: %.2f\n", samples_per_bit); return 0; }
bool sbbs_t::answer() { char str[MAX_PATH+1],str2[MAX_PATH+1],c; char tmp[(MAX_PATH > CRYPT_MAX_TEXTSIZE ? MAX_PATH:CRYPT_MAX_TEXTSIZE)+1]; char tmpname[CRYPT_MAX_TEXTSIZE+1]; char path[MAX_PATH+1]; int i,l,in; struct tm tm; useron.number=0; answertime=logontime=starttime=now=time(NULL); /* Caller ID is IP address */ SAFECOPY(cid,client_ipaddr); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); safe_snprintf(str,sizeof(str),"%s %s %s %02d %u Node %3u" ,hhmmtostr(&cfg,&tm,str2) ,wday[tm.tm_wday] ,mon[tm.tm_mon],tm.tm_mday,tm.tm_year+1900,cfg.node_num); logline("@ ",str); safe_snprintf(str,sizeof(str),"%s %s [%s]", connection, client_name, cid); logline("@+:",str); if(client_ident[0]) { safe_snprintf(str,sizeof(str),"Identity: %s",client_ident); logline("@*",str); } online=ON_REMOTE; if(sys_status&SS_RLOGIN) { if(incom(1000)==0) { for(i=0;i<(int)sizeof(str)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str[i]=in; } str[i]=0; for(i=0;i<(int)sizeof(str2)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str2[i]=in; } str2[i]=0; for(i=0;i<(int)sizeof(terminal)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; terminal[i]=in; } terminal[i]=0; lprintf(LOG_DEBUG,"Node %d RLogin: '******' / '%.*s' / '%s'" ,cfg.node_num ,LEN_ALIAS*2,str ,LEN_ALIAS*2,str2 ,terminal); SAFECOPY(rlogin_term, terminal); SAFECOPY(rlogin_name, str2); SAFECOPY(rlogin_pass, str); /* Truncate terminal speed (e.g. "/57600") from terminal-type string (but keep full terminal type/speed string in rlogin_term): */ truncstr(terminal,"/"); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir); if(!findstr(client.addr,path)) { SAFECOPY(tmp, rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s" ,cfg.node_num,path); useron.number=0; hangup(); } } } else lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); } if(rlogin_name[0]==0) { lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num); sys_status&=~SS_RLOGIN; } } if(!(telnet_mode&TELNET_MODE_OFF)) { /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); /* Will suppress Go Ahead */ request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); /* Retrieve terminal type and speed from telnet client --RS */ request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE); request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED); request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION); request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE); request_telnet_opt(TELNET_DO,TELNET_NEW_ENVIRON); } #ifdef USE_CRYPTLIB if(sys_status&SS_SSH) { pthread_mutex_lock(&ssh_mutex); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, tmpname, &i); tmpname[i]=0; SAFECOPY(rlogin_name, tmpname); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, tmp, &i); tmp[i]=0; SAFECOPY(rlogin_pass, tmp); pthread_mutex_unlock(&ssh_mutex); lprintf(LOG_DEBUG,"Node %d SSH login: '******'" ,cfg.node_num, tmpname); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, tmpname); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); /* crash here Sept-12-2010 str 0x06b3fc4c "(0000) Guest FAILED Password attempt: '*****@*****.**'" and Oct-6-2010 str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261] */ logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } useron.number=0; hangup(); } } else lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); } #endif /* Detect terminal type */ mswait(200); rioctl(IOFI); /* flush input buffer */ putcom( "\r\n" /* locate cursor at column 1 */ "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */ "\x1b[255B" /* locate cursor as far down as possible */ "\x1b[255C" /* locate cursor as far right as possible */ "\b_" /* need a printable at this location to actually move cursor */ "\x1b[6n" /* Get cursor position */ "\x1b[u" /* restore cursor position */ "\x1b[!_" /* RIP? */ "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm? */ "\x1b[0m_" /* "Normal" colors */ "\x1b[2J" /* clear screen */ "\x1b[H" /* home cursor */ "\xC" /* clear screen (in case not ANSI) */ "\r" /* Move cursor left (in case previous char printed) */ ); i=l=0; tos=1; lncntr=0; safe_snprintf(str, sizeof(str), "%s %s", VERSION_NOTICE, COPYRIGHT_NOTICE); strip_ctrl(str, str); center(str); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ c=incom(100)&0x7f; if(c==0) continue; i=0; if(l==0 && c!=ESC) // response must begin with escape char continue; str[l++]=c; if(c=='R') { /* break immediately if ANSI response */ mswait(500); break; } } while((c=(incom(100)&0x7f))!=0 && l<(int)sizeof(str)-1) str[l++]=c; str[l]=0; if(l) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'" ,cfg.node_num,tmp); if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') { int x,y; if(terminal[0]==0) SAFECOPY(terminal,"ANSI"); autoterm|=(ANSI|COLOR); if(sscanf(str+2,"%u;%u",&y,&x)==2) { lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u" ,cfg.node_num, x, y); /* Sanity check the coordinates in the response: */ if(x>=40 && x<=255) cols=x; if(y>=10 && y<=255) rows=y; } } truncsp(str); if(strstr(str,"RIPSCRIP")) { if(terminal[0]==0) SAFECOPY(terminal,"RIP"); logline("@R",strstr(str,"RIPSCRIP")); autoterm|=(RIP|COLOR|ANSI); } else if(strstr(str,"Are you the gatekeeper?")) { if(terminal[0]==0) SAFECOPY(terminal,"HTML"); logline("@H",strstr(str,"Are you the gatekeeper?")); autoterm|=HTML; } } else if(terminal[0]==0) SAFECOPY(terminal,"DUMB"); rioctl(IOFI); /* flush left-over or late response chars */ if(!autoterm && str[0]) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'" ,cfg.node_num, tmp); } /* AutoLogon via IP or Caller ID here */ if(!useron.number && !(sys_status&SS_RLOGIN) && (startup->options&BBS_OPT_AUTO_LOGON) && cid[0]) { useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid); if(useron.number) { getuserdat(&cfg, &useron); if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V'))) useron.number=0; } } if(!online) return(false); if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */ SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate); logline("@S",str); node_connection = (ushort)cur_rate; SAFEPRINTF(connection,"%lu",cur_rate); SAFECOPY(cid,"Unknown"); SAFECOPY(client_name,"Unknown"); if(telnet_location[0]) { /* Caller-ID info provided */ SAFEPRINTF(str, "CID: %s", telnet_location); logline("@*",str); SAFECOPY(cid,telnet_location); truncstr(cid," "); /* Only include phone number in CID */ char* p=telnet_location; FIND_WHITESPACE(p); SKIP_WHITESPACE(p); if(*p) { SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */ } } SAFECOPY(client.addr,cid); SAFECOPY(client.host,client_name); client_on(client_socket,&client,TRUE /* update */); } else { if(telnet_location[0]) { /* Telnet Location info provided */ SAFEPRINTF(str, "Telnet Location: %s", telnet_location); logline("@*",str); } } useron.misc&=~TERM_FLAGS; useron.misc|=autoterm; SAFECOPY(useron.comp,client_name); if(!useron.number && rlogin_name[0]!=0 && !(cfg.sys_misc&SM_CLOSED) && !matchuser(&cfg, rlogin_name, /* Sysop alias: */FALSE)) { lprintf(LOG_INFO,"Node %d UNKNOWN %s-specified USERNAME: %s, starting new user signup",cfg.node_num,client.protocol,rlogin_name); bprintf("%s: %s\r\n", text[UNKNOWN_USER], rlogin_name); newuser(); } if(!useron.number) { /* manual/regular logon */ /* Display ANSWER screen */ rioctl(IOSM|PAUSE); sys_status|=SS_PAUSEON; SAFEPRINTF(str,"%sanswer",cfg.text_dir); SAFEPRINTF(path,"%s.rip",str); if((autoterm&RIP) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.html",str); if((autoterm&HTML) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.ans",str); if((autoterm&ANSI) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.asc",str); if(fexistcase(path)) printfile(path, P_NOABORT); } } } sys_status&=~SS_PAUSEON; exec_bin(cfg.login_mod,&main_csi); } else /* auto logon here */ if(logon()==false) return(false); if(!useron.number) hangup(); /* Save the IP to the user's note */ if(cid[0]) { SAFECOPY(useron.note,cid); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note); } /* Save host name to the user's computer description */ if(client_name[0]) { SAFECOPY(useron.comp,client_name); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp); } if(!online) return(false); if(!(sys_status&SS_USERON)) { errormsg(WHERE,ERR_CHK,"User not logged on",0); hangup(); return(false); } if(useron.pass[0]) loginSuccess(startup->login_attempt_list, &client_addr); return(true); }
unsigned string::find(const char* str,unsigned n,unsigned start) const{ return findstr(str,strlen(str),start,n);}
BOOL DLLCALL trashcan(scfg_t* cfg, const char* insearchof, const char* name) { char fname[MAX_PATH+1]; return(findstr(insearchof,trashcan_fname(cfg,name,fname,sizeof(fname)))); }
unsigned string::find(const string& str,unsigned n,unsigned start) const{ return findstr(str.data,str.datalen,start,n);}
/* * Define a (possibly) new class of objects. * The list of indexes for the element names is also specified here, * and the number of elements defined for the object. * * given: * name name of object type * indices table of indices for elements * count number of elements defined for the object */ int defineobject(char *name, int indices[], int count) { OBJECTACTIONS *oap; /* object definition structure */ STRINGHEAD *hp; OBJECTACTIONS **newobjects; int index; hp = &objectnames; if (hp->h_list == NULL) initstr(hp); index = findstr(hp, name); if (index >= 0) { /* * Object is already defined. Give an error unless this * new definition is exactly the same as the old one. */ oap = objects[index]; if (oap->oa_count == count) { for (index = 0; ; index++) { if (index >= count) return 0; if (oap->oa_elements[index] != indices[index]) break; } } return 1; } if (hp->h_count >= maxobjcount) { if (maxobjcount == 0) { newobjects = (OBJECTACTIONS **) malloc( OBJALLOC * sizeof(OBJECTACTIONS *)); maxobjcount = OBJALLOC; } else { maxobjcount += OBJALLOC; newobjects = (OBJECTACTIONS **) realloc(objects, maxobjcount * sizeof(OBJECTACTIONS *)); } if (newobjects == NULL) { math_error("Allocation failure for new object type"); /*NOTREACHED*/ } objects = newobjects; } oap = (OBJECTACTIONS *) malloc(objectactionsize(count)); name = addstr(hp, name); if ((oap == NULL) || (name == NULL)) { math_error("Cannot allocate object type"); /*NOTREACHED*/ } oap->oa_count = count; for (index = OBJ_MAXFUNC; index >= 0; index--) oap->oa_indices[index] = -1; for (index = 0; index < count; index++) oap->oa_elements[index] = indices[index]; index = findstr(hp, name); oap->oa_index = index; objects[index] = oap; return 0; }
static int set_wsec(char *ifname, void *credential, int mode) { char tmp[128]; unsigned char psk_mode = 0; WpsEnrCred *cred = (WpsEnrCred *)credential; char prefix[] = "wlXXXXXXXXXX_"; bool b_wps_version2 = false; char *value; value = nvram_get("wps_version2"); if (value && !strcmp(value, "enabled")) b_wps_version2 = true; /* empty credential check */ if (cred->ssidLen == 0) { TUTRACE((TUTRACE_INFO, "Ignore apply new credential because ssid is empty\n")); return 0; } TUTRACE((TUTRACE_INFO, "nvram set key = %s keyMgmt = %s ssid = %s(b_configured)\n", cred->nwKey, cred->keyMgmt, cred->ssid)); /* convert os name to wl name */ if (osifname_to_nvifname(ifname, prefix, sizeof(prefix)) != 0) { TUTRACE((TUTRACE_INFO, "Convert to nvname failed\n")); return 0; } strcat(prefix, "_"); /* Check credential */ if (findstr(cred->keyMgmt, "WPA-PSK")) psk_mode |= 1; if (findstr(cred->keyMgmt, "WPA2-PSK")) psk_mode |= 2; /* for version 2, force psk2 if psk1 is on */ if (b_wps_version2 && (psk_mode & 1)) { psk_mode |= 2; } switch (psk_mode) { case 1: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk"); break; case 2: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk2 "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk2"); break; case 3: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk psk2 "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "pskpsk2"); break; default: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), ""); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "open"); break; } if (findstr(cred->keyMgmt, "SHARED")) { wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "1"); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "shared"); } else wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "0"); /* set SSID */ wps_osl_set_conf(strcat_r(prefix, "ssid", tmp), cred->ssid); if (psk_mode) { wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled"); wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0"); } /* for version 2, force aes if tkip is on */ if (b_wps_version2 && (cred->encrType & WPS_ENCRTYPE_TKIP)) { cred->encrType |= WPS_ENCRTYPE_AES; } /* set Encr type */ if (cred->encrType == WPS_ENCRTYPE_NONE) { wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled"); wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0"); } else if (cred->encrType == WPS_ENCRTYPE_WEP) wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "enabled"); else if (cred->encrType == WPS_ENCRTYPE_TKIP) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip"); else if (cred->encrType == WPS_ENCRTYPE_AES) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "aes"); else if (cred->encrType == (WPS_ENCRTYPE_TKIP | WPS_ENCRTYPE_AES)) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip+aes"); else wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip"); if (cred->encrType == WPS_ENCRTYPE_WEP) { char buf[16] = {0}; sprintf(buf, "%d", cred->wepIndex); wps_osl_set_conf(strcat_r(prefix, "key", tmp), buf); sprintf(buf, "key%d", cred->wepIndex); set_wep_key(strcat_r(prefix, buf, tmp), cred->nwKey, cred->nwKeyLen); if ((cred->nwKeyLen == 5) || (cred->nwKeyLen == 10)) wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "1"); else wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "2"); } else { /* set key */ if (cred->nwKeyLen < 64) { wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), cred->nwKey); } else { char temp_key[65] = {0}; memcpy(temp_key, cred->nwKey, 64); temp_key[64] = 0; wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), temp_key); } } /* Disable nmode for WEP and TKIP for TGN spec */ switch (cred->encrType) { case WPS_ENCRTYPE_WEP: case WPS_ENCRTYPE_TKIP: wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "0"); break; default: wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "-1"); break; } nvram_set("w_Setting", "1"); return 1; }
/* - search field '0x0029 1010' for string MosaicRefAcqTimes * - from there, find text formatted floats * - stop at AutoInlineImageFilterEnabled, if found */ static int check_for_mosaic_slice_times(PRV_ELEMENT_ITEM * elementItem) { unsigned el_gr = DCM_TAG_GROUP(elementItem->element.tag); unsigned el_el = DCM_TAG_ELEMENT(elementItem->element.tag); int el_len = elementItem->element.length; char start_txt[] = "MosaicRefAcqTimes"; char end_txt[] = "AutoInlineImageFilterEnabled"; siemens_slice_times_t * ST = & g_siemens_slice_times; /* global struct */ char * instr, * mstr; /* input string and Mosaic string addr */ char * s2; /* second search string, posn of AutoInline... */ char * pstr; /* position pointer, for reading times */ int rem, rem2 = 0; /* remainder counts */ int off, c, rv, diff; /* offset and counter vars */ float stime; /* any read slice time */ /* if this is not the correct element, nothing to do */ if( el_gr != 0x0029 || el_el != 0x1010 ) return 0; /* we are in the correct field, start by clearing old results */ ST->nused = 0; /* input string is field text, mstr is resulting MosaicRef text pointer */ instr = (char *)elementItem->element.d.ot; mstr = findstr(instr, start_txt, el_len); if( ! mstr ) { if( g_MDH_verb > 2 ) fprintf(stderr, "-- CFMST, no Mosaic string\n"); return 0; } off = mstr - instr; /* offset of Mosaic string into field */ rem = el_len - off; /* remaining length of field */ /* secondary remainder to be until any AutoInline... string */ s2 = findstr(mstr, end_txt, rem); if( s2 ) rem2 = s2 - mstr; else rem2 = 0; if( g_MDH_verb > 1 ) fprintf(stderr, "== found %s in 0x0029 1010\n" " off = %d of %d bytes (rem %d, %d)\n", start_txt, off, el_len, rem, rem2); if( s2 ) rem = rem2; /* after verbose, update remaining length */ if( rem <= 0 ) return 0; process_csa_data((unsigned char *)instr, el_len, g_MDH_verb, g_MDH_verb>3, start_txt); /* in really verbose mode, print out raw text */ if( g_MDH_verb > 3 ) { unsigned char * ucp = (unsigned char *)mstr; fprintf(stderr, "-- remaining spaced hex or digit or '.' :\n"); for(c=0; c<rem; c++) if( isdigit(mstr[c]) || mstr[c]=='.' ) fprintf(stderr," '%c'",mstr[c]); else fprintf(stderr," %02x", ucp[c]); fprintf(stderr, "(end)done\n"); } if( g_MDH_verb > 1 ) fprintf(stderr,"\n++ found %d slice times\n", ST->nused); return 0; }
int prep (void) /* Check for preprocessor commands */ { int b, c; char *ln; ln = line; while (*(++ln) == '#' || *ln == ' ') /* locate first directive character */ ; if ( ! *ln) /* NULL directive */ return (killine ()); /* fprintf(stderr,"prep - line=%s\n",ln); */ if (strcmp2 (ln, "if ") || strcmp2 (ln, "ifdef ") || strcmp2 (ln, "ifndef ")) { /* fprintf(stderr,"prep - calling doif(%s)\n",ln); */ doif (ln); return (killine ()); } if (strcmp2 (ln, "else")) { doelse (); return (killine ()); } if (strcmp2 (ln, "endif")) { doendif (); return (killine ()); } if (strcmp2 (ln, "elif ")) { doelif (ln); return (killine ()); } if (procsw) { if (strcmp2 (ln, "define ")) { c = getident (ln, 7) + 2; /* get end of identifier */ splittok (ln, c); /* tokenize rest of line */ dodefine (strlen (line), &ln[7] - line); /* store #define info */ /* fprintf(stderr,"PREP (after dodef): line=|%s|\n",line); */ tstdupdef (); /* Check for def duplication and fix */ return (killine ()); /* Discard #define line */ } if (strcmp2 (ln, "include ")) { doinclude (&ln[8]); /* open include file */ return (killine ()); /* Discard #include line */ } if (strcmp2 (ln, "undef ")) { /* fprintf(stderr,"prep - undef found %s\n",ln); */ doundef (&ln[6]); /* remove undef identifier from def table */ /* fprintf(stderr,"prep - doundef done\n"); */ return (killine ()); /* Discard #undef line */ } if (strcmp2 (ln, "error ")) { fprintf (stderr, "User error - %s\n", &ln[6]); /* print error */ return (killine ()); /* Discard #error line */ } if (strcmp2 (ln, "asm")) { for (;;) /* send all following lines through for assembler */ { getln (0); if (eflag) break; if (findstr (1, line, "#endasm")) break; if (cflag) puts ("#2"); else printf ("#pragma asm "); printf ("%s\n", line); } if (eflag && cflag) /* error only in Microware mode (no #endasm) */ doerr (18, 1); return (killine ()); } if (strcmp2 (ln, "pragma ")) { dopragma (ln + 7); return (killine ()); } if (strcmp2 (ln, "line ")) { doline (ln + 5); return (killine ()); } doerr (17, 1); /* Illegal preprocessor directive */ return (killine ()); } }
int findspell(const char *s) { return findstr(spellnames, s, MAXSPELLS); }