SCOPE2 int search_wid(int adr, int len, int wid, int up) { // The first character in the string is the Forth count field. int str, ptr; int length; int dictp; for ( dictp = TOKEN(up + DATA(voc_unum + wid)); dictp != 0; dictp = TOKEN(to_link(dictp)) ) { length = name_len(dictp); if (len != length) { continue; } str = to_name_adr(dictp); ptr = adr; for ( ; length != 0; --length ) { if ( CHARS(str++) != CHARS(ptr++) ) break; } if (length == 0) return dictp; } return (0); // Not found }
/* ------------------------------------------------------------------------ */ static kbool_t Lisp_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace) { KImportPackage(ns, "Syntax.CStyleBitwiseOperator", trace); KDEFINE_SYNTAX SYNTAX[] = { #define TOKEN(T) KSymbol_##T { TOKEN(ADD), SYNFLAG_CParseFunc,0, Precedence_CStylePrefixOperator, {SUGARFUNC Expression_LispOperator}, {SUGAR methodTypeFunc},}, { TOKEN(SUB), SYNFLAG_CParseFunc,0, Precedence_CStylePrefixOperator, {SUGARFUNC Expression_LispOperator}, {SUGAR methodTypeFunc},}, { TOKEN(MUL), SYNFLAG_CParseFunc,0, Precedence_CStylePrefixOperator, {SUGARFUNC Expression_LispOperator}, {SUGAR methodTypeFunc},}, { TOKEN(DIV), SYNFLAG_CParseFunc,0, Precedence_CStylePrefixOperator, {SUGARFUNC Expression_LispOperator}, {SUGAR methodTypeFunc},}, { TOKEN(MOD), SYNFLAG_CParseFunc,0, Precedence_CStylePrefixOperator, {SUGARFUNC Expression_LispOperator}, {SUGAR methodTypeFunc},}, { KSymbol_END, }, /* sentinental */ }; SUGAR kNameSpace_DefineSyntax(kctx, ns, SYNTAX, trace); return true; }
void _gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errmsg_len) { if (unlikely (caf_is_finalized)) { const char msg[] = "Failed to deallocate coarray - " "there are stopped images"; if (stat) { *stat = STAT_STOPPED_IMAGE; if (errmsg_len > 0) { int len = ((int) sizeof (msg) - 1 > errmsg_len) ? errmsg_len : (int) sizeof (msg) - 1; memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); } return; } caf_runtime_error (msg); } _gfortran_caf_sync_all (NULL, NULL, 0); if (stat) *stat = 0; free (TOKEN (*token)[caf_this_image-1]); free (*token); }
void logon () { int len; char *sn = PARAM_SCREEN_NAME; char *pass; char login[11]; stream_t stream; u_int16_t streamid = htons(0x16); log (LOG_NOTICE, _("Loging into provider as '%s'\n"), sn); get_password (sn, &pass); len = strlen (sn); if (len < 10) { strncpy (login, sn, len); memset (&login[len], ' ', 10 - len); sn = login; sn[10]=0; } stream_init(&stream); stream_put(&stream, sizeof(streamid), &streamid); add_atom(&stream, UNI_PID, UNI_START_STREAM, 0); add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 1); add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_INDEX, 5); add_atom(&stream, DE_PID , DE_DATA, sn); add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0); add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0); add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 2); add_atom(&stream, DE_PID , DE_DATA, pass); add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0); add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 16); add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_INDEX, 1); add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0); add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0); add_atom(&stream, UNI_PID, UNI_END_STREAM, 0); fdo_send (TOKEN ("Dd"), stream.data, stream.used); stream_destroy(&stream); fdo_unregister (TOKEN ("SD")); fdo_register (TOKEN ("At"), login_confirm); fdo_register (TOKEN ("AT"), atom_handler); fdo_register (TOKEN ("at"), atom_handler); }
void _gfortran_caf_finalize (void) { while (caf_static_list != NULL) { caf_static_t *tmp = caf_static_list->prev; free (TOKEN (caf_static_list->token)[caf_this_image-1]); free (TOKEN (caf_static_list->token)); free (caf_static_list); caf_static_list = tmp; } if (!caf_mpi_initialized) MPI_Finalize (); caf_is_finalized = 1; }
void CParser::SortBlock(CStack *op, CStack *var) { SItem *ptrOp, *ptrVar, *ptrVarPrev; bool moved; if (!op) return; do { moved = false; ptrOp = op->top; ptrVar = var->top; ptrVarPrev = NULL; while (ptrOp->next) // до конца стека { if (TOKEN(ptrOp) == tBeg) break; // конец блока /* 1 */ if (PRIOR(ptrOp) >= PRIOR(ptrOp->next)) { ptrOp = ptrOp->next; ptrVarPrev = ptrVar; ptrVar = PtrPlusNum(ptrOp, VarCount(TOKEN(ptrOp))); continue; } /* 2 */ swap_tokens(ptrOp, ptrOp->next); /* 3 */ int pos = VarCount(TOKEN(ptrOp))-1; pos = max(pos, 1)-1; move( PtrPlusNum(ptrVar, pos), // начало VarCount(TOKEN(ptrOp->next)), // длина ptrVarPrev, // куда var->top ); /* 4 */ moved = true; break; } // while (ptrOp->next) } while (moved); // пока не будет перестановок }
SCOPE2 void place_name(int adr, int len, int previous, int up) { int i; int rdp; rdp = V(DP); // Place the string, then the length byte for (i = 0; i < len; i++) { TOKEN(rdp++) = CHARS(adr++); } TOKEN(rdp++) = len; V(DP) = rdp; linkcomma(previous); tokstore(V(DP), up + LASTP); }
SCOPE2 void header(int adr, int len, int up) { int canstr; int threadp = up + DATA(voc_unum + T(CURRENT)); canstr = alcanonical(adr, len, up); cfwarn(canstr, len, up); place_name(canstr, len, TOKEN(threadp), up); // Link into vocabulary search list and remember lfa for hide/reveal tokstore(V(DP), threadp); }
// Handle system information variables and print their value, returns the number of // characters appended to buff int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) { if (TOKEN("si_chip_id")) { return os_sprintf(buff, "0x%x", system_get_chip_id()); } else if (TOKEN("si_freeheap")) { return os_sprintf(buff, "%dKB", system_get_free_heap_size()/1024); } else if (TOKEN("si_uptime")) { uint32 t = system_get_time() / 1000000; // in seconds return os_sprintf(buff, "%dd%dh%dm%ds", t/(24*3600), (t/(3600))%24, (t/60)%60, t%60); } else if (TOKEN("si_boot_version")) { return os_sprintf(buff, "%d", system_get_boot_version()); } else if (TOKEN("si_boot_address")) { return os_sprintf(buff, "0x%x", system_get_userbin_addr()); } else if (TOKEN("si_cpu_freq")) { return os_sprintf(buff, "%dMhz", system_get_cpu_freq()); } else { return 0; } }
results = mt->fetchResults(); #ifdef STRUS_LOWLEVEL_DEBUG strus::utils::printResults( std::cout, std::vector<strus::SegmenterPosition>(), results); std::cout << "nof matches " << results.size() << std::endl; strus::analyzer::PatternMatcherStatistics stats = mt->getStatistics(); strus::utils::printStatistics( std::cerr, stats); #endif return results; } typedef strus::PatternMatcherInstanceInterface PT; static const Pattern testPatterns[32] = { {"seq[3]_1_2", {{Operation::Term,TOKEN(1),1}, {Operation::Term,TOKEN(2),2}, {Operation::Expression,0,0,PT::OpSequence,3,0,2}}, {1,0} }, {"seq[2]_1_2", {{Operation::Term,TOKEN(1),1}, {Operation::Term,TOKEN(2),2}, {Operation::Expression,0,0,PT::OpSequence,2,0,2}}, {1,0} }, {"seq[1]_1_2", {{Operation::Term,TOKEN(1),1}, {Operation::Term,TOKEN(2),2}, {Operation::Expression,0,0,PT::OpSequence,1,0,2}}, {1,0}
{ "Ddr2", nvboot_memory_type_ddr2 }, { "Ddr", nvboot_memory_type_ddr }, { "LpDdr2", nvboot_memory_type_lpddr2 }, { "LpDdr", nvboot_memory_type_lpddr }, { NULL, 0 } }; #define TOKEN(name) \ token_##name, field_type_u32, NULL field_item s_sdram_field_table_t132[] = { { "MemoryType", token_memory_type, field_type_enum, s_nvboot_memory_type_table_t132 }, { "PllMInputDivider", TOKEN(pllm_input_divider) }, { "PllMFeedbackDivider", TOKEN(pllm_feedback_divider) }, { "PllMStableTime", TOKEN(pllm_stable_time) }, { "PllMSetupControl", TOKEN(pllm_setup_control) }, { "PllMSelectDiv2", TOKEN(pllm_select_div2) }, { "PllMPDLshiftPh45", TOKEN(pllm_pdlshift_ph45) }, { "PllMPDLshiftPh90", TOKEN(pllm_pdlshift_ph90) }, { "PllMPDLshiftPh135", TOKEN(pllm_pdlshift_ph135) }, { "PllMKCP", TOKEN(pllm_kcp) }, { "PllMKVCO", TOKEN(pllm_kvco) }, { "EmcBctSpare0", TOKEN(emc_bct_spare0) }, { "EmcBctSpare1", TOKEN(emc_bct_spare1) }, { "EmcBctSpare2", TOKEN(emc_bct_spare2) }, { "EmcBctSpare3", TOKEN(emc_bct_spare3) }, { "EmcBctSpare4", TOKEN(emc_bct_spare4) }, { "EmcBctSpare5", TOKEN(emc_bct_spare5) },
{ "Ddr", nvboot_memory_type_ddr }, { "LpDdr2", nvboot_memory_type_lpddr2 }, { "LpDdr4", nvboot_memory_type_lpddr4 }, { "LpDdr", nvboot_memory_type_lpddr }, { NULL, 0 } }; #define TOKEN(name) \ token_##name, field_type_u32, NULL field_item s_sdram_field_table_t210[] = { { "MemoryType", token_memory_type, field_type_enum, s_nvboot_memory_type_table_t210 }, { "PllMInputDivider", TOKEN(pllm_input_divider) }, { "PllMFeedbackDivider", TOKEN(pllm_feedback_divider) }, { "PllMStableTime", TOKEN(pllm_stable_time) }, { "PllMSetupControl", TOKEN(pllm_setup_control) }, { "PllMPostDivider", TOKEN(pllm_post_divider) }, { "PllMKCP", TOKEN(pllm_kcp) }, { "PllMKVCO", TOKEN(pllm_kvco) }, { "EmcBctSpare0", TOKEN(emc_bct_spare0) }, { "EmcBctSpare1", TOKEN(emc_bct_spare1) }, { "EmcBctSpare2", TOKEN(emc_bct_spare2) }, { "EmcBctSpare3", TOKEN(emc_bct_spare3) }, { "EmcBctSpare4", TOKEN(emc_bct_spare4) }, { "EmcBctSpare5", TOKEN(emc_bct_spare5) }, { "EmcBctSpare6", TOKEN(emc_bct_spare6) }, { "EmcBctSpare7", TOKEN(emc_bct_spare7) }, { "EmcBctSpare8", TOKEN(emc_bct_spare8) },
SCOPE2 void tokstore(int token, int adr) { TOKEN(adr) = token; }
int parse_config_file(char *filename, int open_or_die) { int fd, i,j, n, err, in_sensor, s_start_line=0; float fl; int xyz[] = { 0, 0, 0 }; char *s; for(i=0;i<3;i++) for(j=0;j<CARRIER_SUBCHANS;j++) carrier_remap[i][j]=-1; if(!(sensor=malloc(sensors_max*sizeof(struct sensor_def)))) diag(SS_PARSER|DIE,"Out of memory (sensor array)\n"); if((fd=open(filename,O_RDONLY))==-1) { if(open_or_die) diag(SS_PARSER|DIERR,"Cannot open config file `%s'",filename); else { diag(SS_PARSER|INFO,"Default config file `%s' not found\n",filename); return 0; } } in_sensor=0; config.need_serial=config.need_pipe=0; if(!fetch(fd)) return 0; while(read_token(fd,1)==1) { if(*token=='#') { read_eol(fd); continue; } if(TOKEN("VideoDevice")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.video_device)) { if(!(config.video_device=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } if(TOKEN("VideoNorm")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_INT(config.norm)) { if(TOKEN("PAL")) config.norm=VIDEO_MODE_PAL; else if(TOKEN("NTSC")) config.norm=VIDEO_MODE_NTSC; else if(TOKEN("SECAM")) config.norm=VIDEO_MODE_SECAM; else if(TOKEN("PAL-NC")) config.norm=3; else if(TOKEN("PAL-M")) config.norm=4; else if(TOKEN("PAL-N")) config.norm=5; else if(TOKEN("NTSC-JP")) config.norm=6; else if(TOKEN("AUTO")) config.norm=VIDEO_MODE_AUTO; else error("Invalid TV norm"); } CHECK_EOL(fd); continue; } if(TOKEN("AudioCaptureDevice")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.audio_in_device)) { if(!(config.audio_in_device=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } if(TOKEN("AudioPlaybackDevice")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.audio_out_device)) { if(!(config.audio_out_device=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } TEST_PARAM("Channel",config.channel,n>=0 && n<=65535); TEST_PARAM("FrameRate",config.frame_rate,n>=0 && n<=65535); TEST_PARAM("VideoAudioInput",config.video_audio_input,n>=0 && n<=65535); TEST_PARAM("VideoAudioVolume",config.video_audio_volume,n>=0 && n<=65535); if(TOKEN("Palette")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_INT(config.monochrome)) { if(TOKEN("Mono")) config.monochrome=1; else if(!TOKEN("Color")) { error("Invalid palette"); break; } } CHECK_EOL(fd); continue; } if(TOKEN("FrameSize")) { if(READ(fd)!=1) { synerr(); break; } if((s=strchr(token,'x'))==0) { synerr(); break; } *s=0; if(UNSET_INT(config.capx)) { if((config.capx=atoi(token))<=0 || (config.capy=atoi(s+1))<=0) error("Invalid FrameSize parameter"); } CHECK_EOL(fd); continue; } if(TOKEN("ImageFilters")) { while(READ(fd)==1) { if(TOKEN("UpsideDown")) config.image_filters^=IMAGE_FILTER_INVERT|IMAGE_FILTER_FLIP; else if(TOKEN("Invert")) config.image_filters^=IMAGE_FILTER_INVERT; else if(TOKEN("Flip")) config.image_filters^=IMAGE_FILTER_FLIP; else error("Invalid ImageFilters parameter"); } /*CHECK_EOL(fd);*/ continue; } TEST_PARAM("JpegQuality",config.jpeg_quality,n>=0 && n<=100); if(TOKEN("TunerFreq")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_FLOAT(config.tuner_freq)) { if(sscanf(token,"%f",&fl)==1) { if(fl<=0) error("Invalid TunerFreq parameter"); else config.tuner_freq=fl; } else synerr(); } CHECK_EOL(fd); continue; } if(TOKEN("Audio")) { while(READ(fd)==1) ; diag(SS_PARSER|INFO,"Ignoring deprecated `Audio' directive at line %d\n", line); continue; } if(TOKEN("AddressFamily")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_INT(config.address_family)) { // AF_* are >=0 if(TOKEN("any")) config.address_family=AF_UNSPEC; else if(TOKEN("inet")) config.address_family=AF_INET; else if(TOKEN("inet6")) config.address_family=AF_INET6; else error("Invalid AddressFamily parameter"); } CHECK_EOL(fd); continue; } TEST_PARAM("TCPPort",config.tcp_base_port,n>0 && n<=65535); TEST_PARAM("TCPAudioPort",config.tcp_audio_port,n>0 && n<=65535); if(TOKEN("SerialPort")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.serial_port)) { if(!(config.serial_port=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } TEST_PARAM("MaxStreamingClients",config.max_clients,n>=0); TEST_PARAM("ControlTimeout",config.control_timeout,n>0); TEST_PARAM("ClientTimeout",config.client_timeout,n>0); TEST_PARAM("ClientAckTimeout",config.client_ack_timeout,n>0); if(TOKEN("Greeting")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.greeting)) { if(!(config.greeting=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } if(TOKEN("NamedPipe")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.named_pipe)) { if(!(config.named_pipe=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } if(TOKEN("LogFile")) { if(READ(fd)!=1) { synerr(); break; } if(UNSET_STRING(config.log_file)) { if(!(config.log_file=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); } CHECK_EOL(fd); continue; } if(TOKEN("Device")) { if(in_sensor) { synerr(); break; } in_sensor=1; continue; } if(TOKEN("{")) { if(in_sensor==1) { in_sensor=2; s_start_line=line; if(sensors==sensors_max) { sensors_max+=15; diag(SS_PARSER|DEBUG,"expanding device array to %d\n",sensors_max); sensor=realloc(sensor,sizeof(struct sensor_def)*sensors_max); if(!sensor) diag(SS_PARSER|DIE,"Out of memory (device array)\n"); } sensor[sensors].link=-1; sensor[sensors].widget='\0'; sensor[sensors].cfmin=sensor[sensors].cfmax=0; sensor[sensors].imin=0; sensor[sensors].imax=65535; sensor[sensors].name=sensor[sensors].hint=""; sensor[sensors].dir=SD_R; sensor[sensors].notifier=-1; CHECK_EOL(fd); continue; } else { synerr(); break; } } if(in_sensor==2) { if(TOKEN("Direction")) { if(READ(fd)!=1) { synerr(); break; } if(TOKEN("readwrite") || TOKEN("rw")) sensor[sensors].dir=SD_RW; else if(TOKEN("read") ||TOKEN("r")) sensor[sensors].dir=SD_R; /*else if(TOKEN("write")||TOKEN("w")) sensor[sensors].dir=SD_W;*/ else { error("Invalid direction"); break; } CHECK_EOL(fd); continue; } if(TOKEN("Notifier")) { if(READ(fd)!=1) { synerr(); break; } if(TOKEN("Device")) sensor[sensors].notifier=NT_DEVICE; else if(TOKEN("Client")) sensor[sensors].notifier=NT_CLIENT; else if(!TOKEN("None")) { error("Invalid notifier value"); break; } CHECK_EOL(fd); continue; } if(TOKEN("Name")) { if(READ(fd)!=1) { synerr(); break; } if(!(sensor[sensors].name=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); CHECK_EOL(fd); continue; } if(TOKEN("Hint")) { if(READ(fd)!=1) { synerr(); break; } if(!(sensor[sensors].hint=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); CHECK_EOL(fd); continue; } if(TOKEN("Visual")) { if(READ(fd)!=1) { synerr(); break; } if(TOKEN("slider")) sensor[sensors].widget='t'; else if(TOKEN("slider_x")) { if(xyz[0]) error("Multiple assignments to slider_x"); xyz[0]=1; sensor[sensors].widget='x'; } else if(TOKEN("slider_y")) { if(xyz[1]) error("Multiple assignments to slider_y"); xyz[1]=1; sensor[sensors].widget='y'; } else if(TOKEN("slider_z")) { if(xyz[2]) error("Multiple assignments to slider_z"); xyz[2]=1; sensor[sensors].widget='z'; } else if(TOKEN("gauge")) sensor[sensors].widget='p'; else { error("Invalid visual"); break; } CHECK_EOL(fd); continue; } if(TOKEN("Range")) { if(READ(fd)!=1) { synerr(); break; } if(sscanf(token,"%d",&sensor[sensors].imin)==0) { synerr(); break; } if(READ(fd)!=1) { synerr(); break; } if(sscanf(token,"%d",&sensor[sensors].imax)==0) { synerr(); break; } CHECK_EOL(fd); if(sensor[sensors].imax<=sensor[sensors].imin) { error("Invalid device range"); } continue; } if(TOKEN("Remap")) { if(READ(fd)!=1) { synerr(); break; } if(!(sensor[sensors].cfmin=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); if(READ(fd)!=1) { synerr(); break; } if(!(sensor[sensors].cfmax=strdup(token))) diag(SS_PARSER|DIE,"Out of memory\n"); CHECK_EOL(fd); continue; } #if 0 if(TOKEN("Init")) { if(READ(fd)!=1) { synerr(); break; } CHECK_EOL(fd); continue; } #endif if(TOKEN("Carrier")) { int link, id; if(READ(fd)!=1) { synerr(); break; } if(TOKEN("pipe")) { link=LINK_PIPE; config.need_pipe=1; } else if(TOKEN("serial")) { link=LINK_SERIAL; config.need_serial=1; } else if(TOKEN("internal")) link=LINK_INTERNAL; else { error("Invalid link type"); break; } if(READ(fd)!=1) { synerr(); break; } if(sscanf(token,"%d",&id)==0) { synerr(); break; } if(id<0||id>=CARRIER_SUBCHANS) error("Channel out of range"); carrier_remap[link][id]=sensors; sensor[sensors].link=link; sensor[sensors].channel=id; /*diag(SS_PARSER|DEBUG,"Mapping link %d subchan %d to device %d\n", link,id,sensors);*/ CHECK_EOL(fd); continue; } if(!TOKEN("}")) { error("Unrecognized token"); read_eol(fd); } } if(TOKEN("}")) { if(in_sensor==2) { in_sensor=0; err=0; if(sensor[sensors].notifier==-1) { if(sensor[sensors].link==LINK_INTERNAL) sensor[sensors].notifier=NT_CLIENT; else sensor[sensors].notifier=NT_DEVICE; } if(sensor[sensors].link==-1) { diag(SS_PARSER|ERROR,"Undefined link for device %d (starting at line %d)\n", sensors,s_start_line); err=1; } if(sensor[sensors].link==LINK_PIPE && sensor[sensors].dir!=SD_R) { diag(SS_PARSER|ERROR,"Illegal direction for device %d (starting at line %d): only `Read' allowed here\n", sensors,s_start_line); err=1; } #if 0 if(sensor[sensors].name==0) { diag(SS_PARSER|ERROR,"Missing name for device %d (starting at line %d)\n", sensors,s_start_line); err=1; } #endif if(sensor[sensors].widget=='\0') { if(!strcasecmp(sensor[sensors].name,"Pan")) { if(xyz[0]) error("Multiple assignments to slider_x"); sensor[sensors].widget='x'; xyz[0]=1; } else if(!strcasecmp(sensor[sensors].name,"Tilt")) { if(xyz[1]) error("Multiple assignments to slider_y"); sensor[sensors].widget='y'; xyz[1]=1; } else if(!strcasecmp(sensor[sensors].name,"Zoom")) { if(xyz[2]) error("Multiple assignments to slider_z"); sensor[sensors].widget='z'; xyz[2]=1; } } if(sensor[sensors].widget=='\0') { diag(SS_PARSER|ERROR, "Undefined visual for device %d (starting at line %d)\n", sensors,s_start_line); err=1; } if(sensor[sensors].cfmin==0) { /* .cfmax==0 too */ char buff[12]; snprintf(buff,12,"%d",sensor[sensors].imin); if(!(sensor[sensors].cfmin=strdup(buff))) diag(SS_PARSER|DIE,"Out of memory\n"); snprintf(buff,12,"%d",sensor[sensors].imax); if(!(sensor[sensors].cfmax=strdup(buff))) diag(SS_PARSER|DIE,"Out of memory\n"); } if(err) return 1; sensors++; continue; } else { synerr(); break; } } error("Unrecognized token"); read_eol(fd); } if(!syn && in_sensor) { diag(SS_PARSER|ERROR,"Incomplete definition for device %d (starting at line %d)\n", sensors,s_start_line); syn=1; } close(fd); line--; /* diag(SS_PARSER|DEBUG,"Parsed %d line%s\n",line,line==1?"":"s"); */ return syn; }
void CBProfilerExecDlg::ParseCallGraph(const wxArrayString& msg, wxProgressDialog &progress, const size_t maxcount, size_t& count) { // Setting colums names outputCallGraphArea->InsertColumn(0, _T("index"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(1, _T("% time"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(2, _T("self"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(3, _T("children"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(4, _T("called"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(5, _T("name")); // Jump header lines progress.Update(count,_("Parsing call graph information. Please wait...")); while ( (count < maxcount) && (msg[count].Find(_T("index % time")) == -1) ) { if ((count%10) == 0) progress.Update(count); ++count; } ++count; // Parsing Call Graph size_t next(0); wxListItem item; wxString TOKEN; // setting listctrl default text colour for secondary lines const wxColour COLOUR(wxTheColourDatabase->Find(_T("GREY"))); for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if ( (TOKEN.IsEmpty()) || (TOKEN.Find(wxChar(0x0C)) != -1) ) break; outputCallGraphArea->InsertItem(count,_T("")); char first_char = TOKEN.GetChar(0); // treating the empty separator lines if (first_char == '-') { outputCallGraphArea->SetItem(next, 0, _T("")); item.Clear(); item.SetId(next); item.SetBackgroundColour(*wxLIGHT_GREY); outputCallGraphArea->SetItem(item); } else { outputCallGraphArea->SetItem(next, 0, TOKEN(0,6).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 1, TOKEN(6,6).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 2, TOKEN(12,8).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 3, TOKEN(20,8).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 4, TOKEN(28,17).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 5, TOKEN.Mid(45)); if (first_char != '[') { outputCallGraphArea->SetItemTextColour(next,COLOUR); } } ++next; } // Resize columns outputCallGraphArea->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(3, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(4, wxLIST_AUTOSIZE ); outputCallGraphArea->SetColumnWidth(5, wxLIST_AUTOSIZE); // Printing Call Graph Help wxString output_help; for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if (TOKEN.Find(wxChar(0x0C)) != -1) break; output_help << TOKEN << _T("\n"); } outputHelpCallGraphArea->SetValue(output_help); ++count; }
size_t http_parser_execute (http_parser *parser, const http_parser_settings *settings, const char *data, size_t len) { char c, ch; int8_t unhex_val; const char *p = data, *pe; int64_t to_read; enum state state; enum header_states header_state; uint64_t index = parser->index; uint64_t nread = parser->nread; /* We're in an error state. Don't bother doing anything. */ if (HTTP_PARSER_ERRNO(parser) != HPE_OK) { return 0; } state = (enum state) parser->state; header_state = (enum header_states) parser->header_state; if (len == 0) { switch (state) { case s_body_identity_eof: CALLBACK2(message_complete); return 0; case s_dead: case s_start_req_or_res: case s_start_res: case s_start_req: return 0; default: SET_ERRNO(HPE_INVALID_EOF_STATE); return 1; } } /* technically we could combine all of these (except for url_mark) into one variable, saving stack space, but it seems more clear to have them separated. */ const char *header_field_mark = 0; const char *header_value_mark = 0; const char *url_mark = 0; if (state == s_header_field) header_field_mark = data; if (state == s_header_value) header_value_mark = data; if (state == s_req_path || state == s_req_schema || state == s_req_schema_slash || state == s_req_schema_slash_slash || state == s_req_port || state == s_req_query_string_start || state == s_req_query_string || state == s_req_host || state == s_req_fragment_start || state == s_req_fragment) url_mark = data; for (p=data, pe=data+len; p != pe; p++) { ch = *p; if (PARSING_HEADER(state)) { ++nread; /* Buffer overflow attack */ if (nread > HTTP_MAX_HEADER_SIZE) { SET_ERRNO(HPE_HEADER_OVERFLOW); goto error; } } switch (state) { case s_dead: /* this state is used after a 'Connection: close' message * the parser will error out if it reads another message */ SET_ERRNO(HPE_CLOSED_CONNECTION); goto error; case s_start_req_or_res: { if (ch == CR || ch == LF) break; parser->flags = 0; parser->content_length = -1; CALLBACK2(message_begin); if (ch == 'H') state = s_res_or_resp_H; else { parser->type = HTTP_REQUEST; goto start_req_method_assign; } break; } case s_res_or_resp_H: if (ch == 'T') { parser->type = HTTP_RESPONSE; state = s_res_HT; } else { if (ch != 'E') { SET_ERRNO(HPE_INVALID_CONSTANT); goto error; } parser->type = HTTP_REQUEST; parser->method = HTTP_HEAD; index = 2; state = s_req_method; } break; case s_start_res: { parser->flags = 0; parser->content_length = -1; CALLBACK2(message_begin); switch (ch) { case 'H': state = s_res_H; break; case CR: case LF: break; default: SET_ERRNO(HPE_INVALID_CONSTANT); goto error; } break; } case s_res_H: STRICT_CHECK(ch != 'T'); state = s_res_HT; break; case s_res_HT: STRICT_CHECK(ch != 'T'); state = s_res_HTT; break; case s_res_HTT: STRICT_CHECK(ch != 'P'); state = s_res_HTTP; break; case s_res_HTTP: STRICT_CHECK(ch != '/'); state = s_res_first_http_major; break; case s_res_first_http_major: if (ch < '1' || ch > '9') { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_major = ch - '0'; state = s_res_http_major; break; /* major HTTP version or dot */ case s_res_http_major: { if (ch == '.') { state = s_res_first_http_minor; break; } if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_major *= 10; parser->http_major += ch - '0'; if (parser->http_major > 999) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } break; } /* first digit of minor HTTP version */ case s_res_first_http_minor: if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor = ch - '0'; state = s_res_http_minor; break; /* minor HTTP version or end of request line */ case s_res_http_minor: { if (ch == ' ') { state = s_res_first_status_code; break; } if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor *= 10; parser->http_minor += ch - '0'; if (parser->http_minor > 999) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } break; } case s_res_first_status_code: { if (!IS_NUM(ch)) { if (ch == ' ') { break; } SET_ERRNO(HPE_INVALID_STATUS); goto error; } parser->status_code = ch - '0'; state = s_res_status_code; break; } case s_res_status_code: { if (!IS_NUM(ch)) { switch (ch) { case ' ': state = s_res_status; break; case CR: state = s_res_line_almost_done; break; case LF: state = s_header_field_start; break; default: SET_ERRNO(HPE_INVALID_STATUS); goto error; } break; } parser->status_code *= 10; parser->status_code += ch - '0'; if (parser->status_code > 999) { SET_ERRNO(HPE_INVALID_STATUS); goto error; } break; } case s_res_status: /* the human readable status. e.g. "NOT FOUND" * we are not humans so just ignore this */ if (ch == CR) { state = s_res_line_almost_done; break; } if (ch == LF) { state = s_header_field_start; break; } break; case s_res_line_almost_done: STRICT_CHECK(ch != LF); state = s_header_field_start; break; case s_start_req: { if (ch == CR || ch == LF) break; parser->flags = 0; parser->content_length = -1; CALLBACK2(message_begin); if (!IS_ALPHA(ch)) { SET_ERRNO(HPE_INVALID_METHOD); goto error; } start_req_method_assign: parser->method = (enum http_method) 0; index = 1; switch (ch) { case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break; case 'D': parser->method = HTTP_DELETE; break; case 'G': parser->method = HTTP_GET; break; case 'H': parser->method = HTTP_HEAD; break; case 'L': parser->method = HTTP_LOCK; break; case 'M': parser->method = HTTP_MKCOL; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH */ break; case 'N': parser->method = HTTP_NOTIFY; break; case 'O': parser->method = HTTP_OPTIONS; break; case 'P': parser->method = HTTP_POST; /* or PROPFIND or PROPPATCH or PUT or PATCH */ break; case 'R': parser->method = HTTP_REPORT; break; case 'S': parser->method = HTTP_SUBSCRIBE; break; case 'T': parser->method = HTTP_TRACE; break; case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE */ break; default: SET_ERRNO(HPE_INVALID_METHOD); goto error; } state = s_req_method; break; } case s_req_method: { if (ch == '\0') { SET_ERRNO(HPE_INVALID_METHOD); goto error; } const char *matcher = method_strings[parser->method]; if (ch == ' ' && matcher[index] == '\0') { state = s_req_spaces_before_url; } else if (ch == matcher[index]) { ; /* nada */ } else if (parser->method == HTTP_CONNECT) { if (index == 1 && ch == 'H') { parser->method = HTTP_CHECKOUT; } else if (index == 2 && ch == 'P') { parser->method = HTTP_COPY; } else { goto error; } } else if (parser->method == HTTP_MKCOL) { if (index == 1 && ch == 'O') { parser->method = HTTP_MOVE; } else if (index == 1 && ch == 'E') { parser->method = HTTP_MERGE; } else if (index == 1 && ch == '-') { parser->method = HTTP_MSEARCH; } else if (index == 2 && ch == 'A') { parser->method = HTTP_MKACTIVITY; } else { goto error; } } else if (index == 1 && parser->method == HTTP_POST) { if (ch == 'R') { parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */ } else if (ch == 'U') { parser->method = HTTP_PUT; } else if (ch == 'A') { parser->method = HTTP_PATCH; } else { goto error; } } else if (index == 2 && parser->method == HTTP_UNLOCK && ch == 'S') { parser->method = HTTP_UNSUBSCRIBE; } else if (index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { parser->method = HTTP_PROPPATCH; } else { SET_ERRNO(HPE_INVALID_METHOD); goto error; } ++index; break; } case s_req_spaces_before_url: { if (ch == ' ') break; if (ch == '/' || ch == '*') { MARK(url); state = s_req_path; break; } /* Proxied requests are followed by scheme of an absolute URI (alpha). * CONNECT is followed by a hostname, which begins with alphanum. * All other methods are followed by '/' or '*' (handled above). */ if (IS_ALPHA(ch) || (parser->method == HTTP_CONNECT && IS_NUM(ch))) { MARK(url); state = (parser->method == HTTP_CONNECT) ? s_req_host : s_req_schema; break; } SET_ERRNO(HPE_INVALID_URL); goto error; } case s_req_schema: { if (IS_ALPHA(ch)) break; if (ch == ':') { state = s_req_schema_slash; break; } SET_ERRNO(HPE_INVALID_URL); goto error; } case s_req_schema_slash: STRICT_CHECK(ch != '/'); state = s_req_schema_slash_slash; break; case s_req_schema_slash_slash: STRICT_CHECK(ch != '/'); state = s_req_host; break; case s_req_host: { if (IS_HOST_CHAR(ch)) break; switch (ch) { case ':': state = s_req_port; break; case '/': state = s_req_path; break; case ' ': /* The request line looks like: * "GET http://foo.bar.com HTTP/1.1" * That is, there is no path. */ CALLBACK(url); state = s_req_http_start; break; case '?': state = s_req_query_string_start; break; default: SET_ERRNO(HPE_INVALID_HOST); goto error; } break; } case s_req_port: { if (IS_NUM(ch)) break; switch (ch) { case '/': state = s_req_path; break; case ' ': /* The request line looks like: * "GET http://foo.bar.com:1234 HTTP/1.1" * That is, there is no path. */ CALLBACK(url); state = s_req_http_start; break; case '?': state = s_req_query_string_start; break; default: SET_ERRNO(HPE_INVALID_PORT); goto error; } break; } case s_req_path: { if (IS_URL_CHAR(ch)) break; switch (ch) { case ' ': CALLBACK(url); state = s_req_http_start; break; case CR: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_req_line_almost_done; break; case LF: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_header_field_start; break; case '?': state = s_req_query_string_start; break; case '#': state = s_req_fragment_start; break; default: SET_ERRNO(HPE_INVALID_PATH); goto error; } break; } case s_req_query_string_start: { if (IS_URL_CHAR(ch)) { state = s_req_query_string; break; } switch (ch) { case '?': break; /* XXX ignore extra '?' ... is this right? */ case ' ': CALLBACK(url); state = s_req_http_start; break; case CR: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_req_line_almost_done; break; case LF: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_header_field_start; break; case '#': state = s_req_fragment_start; break; default: SET_ERRNO(HPE_INVALID_QUERY_STRING); goto error; } break; } case s_req_query_string: { if (IS_URL_CHAR(ch)) break; switch (ch) { case '?': /* allow extra '?' in query string */ break; case ' ': CALLBACK(url); state = s_req_http_start; break; case CR: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_req_line_almost_done; break; case LF: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_header_field_start; break; case '#': state = s_req_fragment_start; break; default: SET_ERRNO(HPE_INVALID_QUERY_STRING); goto error; } break; } case s_req_fragment_start: { if (IS_URL_CHAR(ch)) { state = s_req_fragment; break; } switch (ch) { case ' ': CALLBACK(url); state = s_req_http_start; break; case CR: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_req_line_almost_done; break; case LF: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_header_field_start; break; case '?': state = s_req_fragment; break; case '#': break; default: SET_ERRNO(HPE_INVALID_FRAGMENT); goto error; } break; } case s_req_fragment: { if (IS_URL_CHAR(ch)) break; switch (ch) { case ' ': CALLBACK(url); state = s_req_http_start; break; case CR: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_req_line_almost_done; break; case LF: CALLBACK(url); parser->http_major = 0; parser->http_minor = 9; state = s_header_field_start; break; case '?': case '#': break; default: SET_ERRNO(HPE_INVALID_FRAGMENT); goto error; } break; } case s_req_http_start: switch (ch) { case 'H': state = s_req_http_H; break; case ' ': break; default: SET_ERRNO(HPE_INVALID_CONSTANT); goto error; } break; case s_req_http_H: STRICT_CHECK(ch != 'T'); state = s_req_http_HT; break; case s_req_http_HT: STRICT_CHECK(ch != 'T'); state = s_req_http_HTT; break; case s_req_http_HTT: STRICT_CHECK(ch != 'P'); state = s_req_http_HTTP; break; case s_req_http_HTTP: STRICT_CHECK(ch != '/'); state = s_req_first_http_major; break; /* first digit of major HTTP version */ case s_req_first_http_major: if (ch < '1' || ch > '9') { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_major = ch - '0'; state = s_req_http_major; break; /* major HTTP version or dot */ case s_req_http_major: { if (ch == '.') { state = s_req_first_http_minor; break; } if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_major *= 10; parser->http_major += ch - '0'; if (parser->http_major > 999) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } break; } /* first digit of minor HTTP version */ case s_req_first_http_minor: if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor = ch - '0'; state = s_req_http_minor; break; /* minor HTTP version or end of request line */ case s_req_http_minor: { if (ch == CR) { state = s_req_line_almost_done; break; } if (ch == LF) { state = s_header_field_start; break; } /* XXX allow spaces after digit? */ if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor *= 10; parser->http_minor += ch - '0'; if (parser->http_minor > 999) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } break; } /* end of request line */ case s_req_line_almost_done: { if (ch != LF) { SET_ERRNO(HPE_LF_EXPECTED); goto error; } state = s_header_field_start; break; } case s_header_field_start: header_field_start: { if (ch == CR) { state = s_headers_almost_done; break; } if (ch == LF) { /* they might be just sending \n instead of \r\n so this would be * the second \n to denote the end of headers*/ state = s_headers_almost_done; goto headers_almost_done; } c = TOKEN(ch); if (!c) { SET_ERRNO(HPE_INVALID_HEADER_TOKEN); goto error; } MARK(header_field); index = 0; state = s_header_field; switch (c) { case 'c': header_state = h_C; break; case 'p': header_state = h_matching_proxy_connection; break; case 't': header_state = h_matching_transfer_encoding; break; case 'u': header_state = h_matching_upgrade; break; default: header_state = h_general; break; } break; } case s_header_field: { c = TOKEN(ch); if (c) { switch (header_state) { case h_general: break; case h_C: index++; header_state = (c == 'o' ? h_CO : h_general); break; case h_CO: index++; header_state = (c == 'n' ? h_CON : h_general); break; case h_CON: index++; switch (c) { case 'n': header_state = h_matching_connection; break; case 't': header_state = h_matching_content_length; break; default: header_state = h_general; break; } break; /* connection */ case h_matching_connection: index++; if (index > sizeof(CONNECTION)-1 || c != CONNECTION[index]) { header_state = h_general; } else if (index == sizeof(CONNECTION)-2) { header_state = h_connection; } break; /* proxy-connection */ case h_matching_proxy_connection: index++; if (index > sizeof(PROXY_CONNECTION)-1 || c != PROXY_CONNECTION[index]) { header_state = h_general; } else if (index == sizeof(PROXY_CONNECTION)-2) { header_state = h_connection; } break; /* content-length */ case h_matching_content_length: index++; if (index > sizeof(CONTENT_LENGTH)-1 || c != CONTENT_LENGTH[index]) { header_state = h_general; } else if (index == sizeof(CONTENT_LENGTH)-2) { header_state = h_content_length; } break; /* transfer-encoding */ case h_matching_transfer_encoding: index++; if (index > sizeof(TRANSFER_ENCODING)-1 || c != TRANSFER_ENCODING[index]) { header_state = h_general; } else if (index == sizeof(TRANSFER_ENCODING)-2) { header_state = h_transfer_encoding; } break; /* upgrade */ case h_matching_upgrade: index++; if (index > sizeof(UPGRADE)-1 || c != UPGRADE[index]) { header_state = h_general; } else if (index == sizeof(UPGRADE)-2) { header_state = h_upgrade; } break; case h_connection: case h_content_length: case h_transfer_encoding: case h_upgrade: if (ch != ' ') header_state = h_general; break; default: assert(0 && "Unknown header_state"); break; } break; } if (ch == ':') { CALLBACK(header_field); state = s_header_value_start; break; } if (ch == CR) { state = s_header_almost_done; CALLBACK(header_field); break; } if (ch == LF) { CALLBACK(header_field); state = s_header_field_start; break; } SET_ERRNO(HPE_INVALID_HEADER_TOKEN); goto error; } case s_header_value_start: { if (ch == ' ' || ch == '\t') break; MARK(header_value); state = s_header_value; index = 0; if (ch == CR) { CALLBACK(header_value); header_state = h_general; state = s_header_almost_done; break; } if (ch == LF) { CALLBACK(header_value); state = s_header_field_start; break; } c = LOWER(ch); switch (header_state) { case h_upgrade: parser->flags |= F_UPGRADE; header_state = h_general; break; case h_transfer_encoding: /* looking for 'Transfer-Encoding: chunked' */ if ('c' == c) { header_state = h_matching_transfer_encoding_chunked; } else { header_state = h_general; } break; case h_content_length: if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); goto error; } parser->content_length = ch - '0'; break; case h_connection: /* looking for 'Connection: keep-alive' */ if (c == 'k') { header_state = h_matching_connection_keep_alive; /* looking for 'Connection: close' */ } else if (c == 'c') { header_state = h_matching_connection_close; } else { header_state = h_general; } break; default: header_state = h_general; break; } break; } case s_header_value: { if (ch == CR) { CALLBACK(header_value); state = s_header_almost_done; break; } if (ch == LF) { CALLBACK(header_value); goto header_almost_done; } c = LOWER(ch); switch (header_state) { case h_general: break; case h_connection: case h_transfer_encoding: assert(0 && "Shouldn't get here."); break; case h_content_length: if (ch == ' ') break; if (!IS_NUM(ch)) { SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); goto error; } parser->content_length *= 10; parser->content_length += ch - '0'; break; /* Transfer-Encoding: chunked */ case h_matching_transfer_encoding_chunked: index++; if (index > sizeof(CHUNKED)-1 || c != CHUNKED[index]) { header_state = h_general; } else if (index == sizeof(CHUNKED)-2) { header_state = h_transfer_encoding_chunked; } break; /* looking for 'Connection: keep-alive' */ case h_matching_connection_keep_alive: index++; if (index > sizeof(KEEP_ALIVE)-1 || c != KEEP_ALIVE[index]) { header_state = h_general; } else if (index == sizeof(KEEP_ALIVE)-2) { header_state = h_connection_keep_alive; } break; /* looking for 'Connection: close' */ case h_matching_connection_close: index++; if (index > sizeof(CLOSE)-1 || c != CLOSE[index]) { header_state = h_general; } else if (index == sizeof(CLOSE)-2) { header_state = h_connection_close; } break; case h_transfer_encoding_chunked: case h_connection_keep_alive: case h_connection_close: if (ch != ' ') header_state = h_general; break; default: state = s_header_value; header_state = h_general; break; } break; } case s_header_almost_done: header_almost_done: { STRICT_CHECK(ch != LF); state = s_header_value_lws; switch (header_state) { case h_connection_keep_alive: parser->flags |= F_CONNECTION_KEEP_ALIVE; break; case h_connection_close: parser->flags |= F_CONNECTION_CLOSE; break; case h_transfer_encoding_chunked: parser->flags |= F_CHUNKED; break; default: break; } break; } case s_header_value_lws: { if (ch == ' ' || ch == '\t') state = s_header_value_start; else { state = s_header_field_start; goto header_field_start; } break; } case s_headers_almost_done: headers_almost_done: { STRICT_CHECK(ch != LF); if (parser->flags & F_TRAILING) { /* End of a chunked request */ CALLBACK2(message_complete); state = NEW_MESSAGE(); break; } nread = 0; if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) { parser->upgrade = 1; } /* Here we call the headers_complete callback. This is somewhat * different than other callbacks because if the user returns 1, we * will interpret that as saying that this message has no body. This * is needed for the annoying case of recieving a response to a HEAD * request. */ if (settings->on_headers_complete) { switch (settings->on_headers_complete(parser)) { case 0: break; case 1: parser->flags |= F_SKIPBODY; break; default: parser->state = state; SET_ERRNO(HPE_CB_headers_complete); return p - data; /* Error */ } } /* Exit, the rest of the connect is in a different protocol. */ if (parser->upgrade) { CALLBACK2(message_complete); return (p - data) + 1; } if (parser->flags & F_SKIPBODY) { CALLBACK2(message_complete); state = NEW_MESSAGE(); } else if (parser->flags & F_CHUNKED) { /* chunked encoding - ignore Content-Length header */ state = s_chunk_size_start; } else { if (parser->content_length == 0) { /* Content-Length header given but zero: Content-Length: 0\r\n */ CALLBACK2(message_complete); state = NEW_MESSAGE(); } else if (parser->content_length > 0) { /* Content-Length header given and non-zero */ state = s_body_identity; } else { if (parser->type == HTTP_REQUEST || http_should_keep_alive(parser)) { /* Assume content-length 0 - read the next */ CALLBACK2(message_complete); state = NEW_MESSAGE(); } else { /* Read body until EOF */ state = s_body_identity_eof; } } } break; } case s_body_identity: to_read = MIN(pe - p, (int64_t)parser->content_length); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; parser->content_length -= to_read; if (parser->content_length == 0) { CALLBACK2(message_complete); state = NEW_MESSAGE(); } } break; /* read until EOF */ case s_body_identity_eof: to_read = pe - p; if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; } break; case s_chunk_size_start: { assert(nread == 1); assert(parser->flags & F_CHUNKED); unhex_val = unhex[(unsigned char)ch]; if (unhex_val == -1) { SET_ERRNO(HPE_INVALID_CHUNK_SIZE); goto error; } parser->content_length = unhex_val; state = s_chunk_size; break; } case s_chunk_size: { assert(parser->flags & F_CHUNKED); if (ch == CR) { state = s_chunk_size_almost_done; break; } unhex_val = unhex[(unsigned char)ch]; if (unhex_val == -1) { if (ch == ';' || ch == ' ') { state = s_chunk_parameters; break; } SET_ERRNO(HPE_INVALID_CHUNK_SIZE); goto error; } parser->content_length *= 16; parser->content_length += unhex_val; break; } case s_chunk_parameters: { assert(parser->flags & F_CHUNKED); /* just ignore this shit. TODO check for overflow */ if (ch == CR) { state = s_chunk_size_almost_done; break; } break; } case s_chunk_size_almost_done: { assert(parser->flags & F_CHUNKED); STRICT_CHECK(ch != LF); nread = 0; if (parser->content_length == 0) { parser->flags |= F_TRAILING; state = s_header_field_start; } else { state = s_chunk_data; } break; } case s_chunk_data: { assert(parser->flags & F_CHUNKED); to_read = MIN(pe - p, (int64_t)(parser->content_length)); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; } if (to_read == parser->content_length) { state = s_chunk_data_almost_done; } parser->content_length -= to_read; break; } case s_chunk_data_almost_done: assert(parser->flags & F_CHUNKED); STRICT_CHECK(ch != CR); state = s_chunk_data_done; break; case s_chunk_data_done: assert(parser->flags & F_CHUNKED); STRICT_CHECK(ch != LF); state = s_chunk_size_start; break; default: assert(0 && "unhandled state"); SET_ERRNO(HPE_INVALID_INTERNAL_STATE); goto error; } } CALLBACK(header_field); CALLBACK(header_value); CALLBACK(url); parser->state = state; parser->header_state = header_state; parser->index = index; parser->nread = nread; return len; error: if (HTTP_PARSER_ERRNO(parser) == HPE_OK) { SET_ERRNO(HPE_UNKNOWN); } return (p - data); }
enum ttype lexer_gettoken(char **pval) { assert(NULL == *pval); int tkn_start = 0; int tkn_len = 0; SEEK_TO_NONBLANK; if ('%' == *pos) { /* skip percent symbol */ pos++; TOKEN_START; SEEK_TO_EOW; TOKEN_VALUE; TOKEN(TAG); } else if ('.' == *pos) { /* skip dot symbol */ pos++; TOKEN_START; SEEK_TO_EO_CSS_NAME; TOKEN_VALUE; TOKEN(CLASS); } else if ('#' == *pos) { /* skip sharp symbol */ pos++; TOKEN_START; SEEK_TO_EO_CSS_NAME; TOKEN_VALUE; TOKEN(ID); } else if ('"' == *pos) { /* skip open qoute */ pos++; TOKEN_START; SEEK_BEFORE_CLOSE_QT; TOKEN_VALUE; /* skip close quote */ pos++; TOKEN(CDATA); } else if ('=' == *pos) { TOKEN_START; pos++; TOKEN(EQL); } else if ('\t' == *pos) { TOKEN_START; pos++; TOKEN(INDENT); } else if ('(' == *pos) { TOKEN_START; pos++; TOKEN(LBRACKET); } else if (')' == *pos) { TOKEN_START; pos++; TOKEN(RBRACKET) } else if (isalpha(*pos)){
/* Give some pretty, formatted output */ int mr4kd_sprintf ( char *dest, char *name, uint32_t instruction, uint32_t pc, char *fmt ) { /* ** Format specifiers: ** - %rs ** - %rt ** - %rd ** ** - %fs ** - %ft ** - %fd ** ** - %cp Coprocessor register ** ** - %ff FP mode (single, double etc) ** - %fc FP compare condition ** ** - %ih Immediate (hex) ** - %id Immediate (dec) ** - %br Branch address ** - %jm Jump target ** ** - %co COP # ** ** - %ns Name ** - %nc Name with COP number ** - %nf Name with FP format ** ** - %sa Shift amount ** ** - %SP Remainder spacing */ int s = 0; /* Source */ int d = 0; /* Dest */ uint16_t token; /* Scan the format string for specifiers */ for( s = 0; fmt[s]; s++ ) { /* No token? */ if( fmt[s] != '%' ) { dest[d++] = fmt[s]; continue; } /* Got token, read it in */ token = (fmt[s + 1] << 8 | fmt[s + 2]); /* Check */ switch( token ) { /* GPRs */ case TOKEN('r', 's'): d += mr4kd_rcpy_gpr( &dest[d], _RS(instruction) ); break; case TOKEN('r', 't'): d += mr4kd_rcpy_gpr( &dest[d], _RT(instruction) ); break; case TOKEN('r', 'd'): d += mr4kd_rcpy_gpr( &dest[d], _RD(instruction) ); break; /* FPRs */ case TOKEN('f', 's'): d += mr4kd_rcpy_fpr( &dest[d], _FS(instruction) ); break; case TOKEN('f', 't'): d += mr4kd_rcpy_fpr( &dest[d], _FT(instruction) ); break; case TOKEN('f', 'd'): d += mr4kd_rcpy_fpr( &dest[d], _FD(instruction) ); break; /* COP */ case TOKEN('c', 'p'): d += sprintf( &dest[d], "%s", registers_a_cop[_FS(instruction)] ); break; /* Immediate (hex) */ case TOKEN('i', 'h'): d += sprintf( &dest[d], MR4KD_FLAG_GET(MR4KD_HLOWER) ? "0x%04x" : "0x%04X", _IMMEDIATE(instruction) ); break; /* Immediate (decimal) */ case TOKEN('i', 'd'): d += sprintf( &dest[d], "%i", (int)((short)_IMMEDIATE(instruction)) ); break; /* Branch address */ case TOKEN('b', 'r'): d += sprintf( &dest[d], MR4KD_FLAG_GET(MR4KD_HLOWER) ? "0x%08x" : "0x%08X", ((unsigned int)pc + 4 + (short)(instruction & 0xFFFF) * 4) ); break; /* Jump target */ case TOKEN('j', 'm'): d += sprintf( &dest[d], MR4KD_FLAG_GET(MR4KD_HLOWER) ? "0x%08x" : "0x%08X", _TARGET(instruction) | (pc & 0xF0000000) ); break; /* Coprocessor number */ case TOKEN('c', 'o'): d += sprintf( &dest[d], "%u", _COP(instruction) ); break; /* Shift amount */ case TOKEN('s', 'a'): d += sprintf( &dest[d], "%u", _SHAM(instruction) ); break; /* Floating point compare mode */ case TOKEN('f', 'c'): d += sprintf( &dest[d], "%s", fp_compare_types[instruction & 0xF] ); break; /* Floating point mode */ case TOKEN('f', 'f'): d += sprintf( &dest[d], "%c", fpu_fmt_names[_FMT(instruction) - 16] ); break; /* Spacing! */ case TOKEN('S', 'P'): d += sprintf( &dest[d], "%*s", (int)-((mr4kd_conf >> 24) - d), " "); break; /* Instruction name - regular (no space) */ case TOKEN('n', '0'): { int i; char nb[32]; /* Convert to the proper case */ for( i = 0; name[i]; i++ ) nb[i] = ( mr4kd_conf & MR4KD_OLOWER ) ? tolower((uint8_t)name[i]) : toupper((uint8_t)name[i]); /* Copy it to dest */ d += sprintf( &dest[d], "%.*s", i, nb ); } break; /* Instruction name - regular */ case TOKEN('n', 's'): { int i; char nb[32]; /* Convert to the proper case */ for( i = 0; name[i]; i++ ) nb[i] = ( mr4kd_conf & MR4KD_OLOWER ) ? tolower((uint8_t)name[i]) : toupper((uint8_t)name[i]); /* Copy it to dest */ d += sprintf( &dest[d], "%*.*s", (int)-(mr4kd_conf >> 24), i, nb ); } break; /* Instruction name - with COP# */ case TOKEN('n', 'c'): { int i; char nb[32]; /* Convert to the proper case */ for( i = 0; name[i]; i++ ) nb[i] = ( mr4kd_conf & MR4KD_OLOWER ) ? tolower((uint8_t)name[i]) : toupper((uint8_t)name[i]); /* Copy number */ i += sprintf( &nb[i], "%u", _COP(instruction) ); /* Copy it to dest */ d += sprintf( &dest[d], "%*.*s", (int)-(mr4kd_conf >> 24), i, nb ); } break; /* Floating point format */ case TOKEN('n', 'f'): { int i; char nb[32]; /* Convert to the proper case */ for( i = 0; name[i]; i++ ) nb[i] = ( mr4kd_conf & MR4KD_OLOWER ) ? tolower((uint8_t)name[i]) : toupper((uint8_t)name[i]); /* Copy the precision mode */ i += sprintf( &nb[i], ".%c",( mr4kd_conf & MR4KD_OLOWER ) ? tolower((uint8_t)fpu_fmt_names[_FMT(instruction)-16]) : toupper((uint8_t)fpu_fmt_names[_FMT(instruction)-16]) ); /* Copy it to dest */ d += sprintf( &dest[d], "%*.*s", (int)-(mr4kd_conf >> 24), i, nb ); } break; } /* Update source pointer */ s += 2; } /* Null terminate output */ dest[d] = 0; /* Return chars processed */ return d; }
void * _gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, int *stat, char *errmsg, int errmsg_len) { void *local; int err; if (unlikely (caf_is_finalized)) goto error; /* Start MPI if not already started. */ if (caf_num_images == 0) _gfortran_caf_init (NULL, NULL); /* Token contains only a list of pointers. */ local = malloc (size); *token = malloc (sizeof (mpi_token_t) * caf_num_images); if (unlikely (local == NULL || *token == NULL)) goto error; /* token[img-1] is the address of the token in image "img". */ err = MPI_Allgather (&local, sizeof (void*), MPI_BYTE, TOKEN (*token), sizeof (void*), MPI_BYTE, MPI_COMM_WORLD); if (unlikely (err)) { free (local); free (*token); goto error; } if (type == CAF_REGTYPE_COARRAY_STATIC) { caf_static_t *tmp = malloc (sizeof (caf_static_t)); tmp->prev = caf_static_list; tmp->token = *token; caf_static_list = tmp; } if (stat) *stat = 0; return local; error: { char *msg; if (caf_is_finalized) msg = "Failed to allocate coarray - there are stopped images"; else msg = "Failed to allocate coarray"; if (stat) { *stat = caf_is_finalized ? STAT_STOPPED_IMAGE : 1; if (errmsg_len > 0) { int len = ((int) strlen (msg) > errmsg_len) ? errmsg_len : (int) strlen (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); } } else caf_runtime_error (msg); } return NULL; }
/* lex a source buffer for a program */ L_TOKEN* LexSourceBuffer(const char* source_buffer, char** stripped, GRAMMAR_TABLE table) { const char* buffer; char* format; int* lineNumbers; int line; int size; int i, j; int a, b; L_TOKEN* start = NULL; L_TOKEN* end = NULL; buffer = source_buffer; size = strlen(buffer); // count lines lineNumbers = (int*)malloc((size+1)*sizeof(int)); line = 0; for (i = 0; i <= size; i++) { lineNumbers[i] = line; if (buffer[i] == '\n') line++; } // strip clean format = (char*)malloc(size+1); j = 0; for (i = 0; i < size; i++) { if (buffer[i] == '/' && buffer[i+1] == '/') { // inline comments while (i < size && buffer[i] != '\n') i++; i--; } else if (buffer[i] == '/' && buffer[i+1] == '*') { // multiline comments i++; i++; while (i < size - 1 && (buffer[i] != '*' || buffer[i+1] != '/')) { i++; } i++; } #ifdef IGNORE_MACROS else if (buffer[i] == '#') { while (i < size && buffer[i] != '\n') i++; i--; } #endif #ifdef SEMICOLON_COMMENTS else if (buffer[i] == ';') { while (i < size && buffer[i] != '\n') i++; i--; } #endif else if (isSpace(buffer[i])) { // whitespace format[j] = ' '; lineNumbers[j] = lineNumbers[i]; while (i < size && isSpace(buffer[i])) { if (buffer[i] == '\n') { format[j] = '\n'; lineNumbers[j] = lineNumbers[i]; } i++; } i--; j++; } else if (buffer[i] == '"' || buffer[i] == '\'') { char quote = buffer[i]; // string format[j++] = buffer[i++]; while (i < size - 1 && buffer[i] != quote) { if (buffer[i] == '\\') { lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i++]; } lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i++]; } lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i]; } else { // character lineNumbers[j] = lineNumbers[i]; format[j] = buffer[i]; j++; } } format[j] = 0; size = j; // lex // printf("Lexing...\n\n"); for (i = 0; i < size; i++) { line = lineNumbers[i]; if (isAlpha(format[i])) { a = i; // alpha while (i < size && (isAlpha(format[i]) || isNumeric(format[i]) || format[i] == '_')) { i++; } b = i; LexAddBlock(&start, &end, IDENTIFIER(format, a, b, line, table)); i--; } else if (isNumeric(format[i])) { // numeric a = i; while (i < size && isNumeric(format[i])) { i++; } if (format[i] == '.') { i++; while (i < size && isNumeric(format[i])) { i++; } b = i; LexAddBlock(&start, &end, FLOAT(format, a, b, line)); i--; } else { b = i; LexAddBlock(&start, &end, INTEGER(format, a, b, line)); i--; } } else if (format[i] == '"' || format[i] == '\'') { char delimiter = format[i]; // string a = i++; while (i < size && format[i] != delimiter) { i++; } b = i++; LexAddBlock(&start, &end, STRING(format, a, b+1, line)); i--; } else if (isGlyph(format[i])) { a = i; b = 0; // symbol while (i < size && isGlyph(format[i])) { i++; if (FindToken(&format[a], i - a, table)) b = i; } b = b ? b : i; LexAddBlock(&start, &end, TOKEN(format, a, b, line, table)); i = b - 1; } else if (format[i] == '\n') { #ifdef LEX_NEWLINES // end line LexAddBlock(&start, &end, NEWLINE(line)); #endif } else if (format[i] == ' ') { // whitespace } else { // ? PrintLexing(start); printf("Syntax error on line %i: ", line+1); printf("Illegal token %i.\n", format[i]); FreeLexing(start, format); *stripped = 0; return NULL; } } #ifdef LEX_NEWLINES // add newline to the end LexAddBlock(&start, &end, NEWLINE(line)); #endif // add $ to the end LexAddBlock(&start, &end, EOFSYMBOL(line)); free(lineNumbers); *stripped = format; return start; }
** usemtl name if numUsemtlPtr == NULL ** o name if numOPtr == NULL ** s state if numS == undefined ** v 3floats if numF == 0u ** f N(3 to 4 uint) if N <= numV ** * ** Converting faces to triangles ** Vertices must be 3floats */ #define TOKEN(NAME, FUN) {(NAME), strlen((NAME)), (FUN)} #define NTOKENS (sizeof(g_tokens) / sizeof(*g_tokens)) #define EMPTY_LINE (NTOKENS + 1) static const t_token g_tokens[] = { TOKEN("f ", &op_match_f), TOKEN("v ", &op_match_v), TOKEN("vt ", &op_match_vt), TOKEN("vn ", &op_match_vn), TOKEN("#", &op_match_comment), TOKEN("g", &op_match_group), TOKEN("s ", &op_match_smooth), TOKEN("mtllib ", &op_match_mtllib), TOKEN("usemtl ", &op_match_usemtl), TOKEN("o ", &op_match_name), }; static int get_index(char buf[BFSZ], char const *endptr) { size_t i; static size_t j = 0;