unsigned int HTMLProject::AddLabel(const HTMLLabel *label) { int i; static unsigned int lastFile=0; if ( (i=FindLabel(label)) <0 ) { // construction du small label smallLabel *newLabel = new smallLabel; lastFile = AddFile(label->fname.String(),lastFile); newLabel->file = lastFile; newLabel->label = label->lname; /*// on cherche le bon endroit pour insérer le small label int p = labelList->CountItems(); if (p>1) { do p--; while ( (p>=1) && ((smallLabel*)labelList->ItemAt(p))->file > lastFile); } // p=0 est un lien spécial: celui de la page d'intro labelList->AddItem(newLabel,p); return (p); */ labelList->AddItem(newLabel); return(labelList->CountItems()-1); } else return (unsigned int)i; }
void CScriptLabelMan::AddLabelL(const TDesC& aLabelName,const TLinePosition& aPosition) /** Add a label with name aLabelName and position aPosition to the array if it is not already in the array. @param aLabelName a reference to label name. @param aPosition a reference to script position. */ { if (aLabelName.Length()>KMaxLabelLength) User::Leave(KErrLabelNameTooLong); TLinePosition dummyPos; if (FindLabel(aLabelName,dummyPos)==KErrNotFound) { TLabel label; label.iName.CopyF(aLabelName); label.iPosition=aPosition; iLabelArray->AppendL(label); } else { // Encountered a label name that already exists - If it's // in EXACTLY the same place in the script as the existing // instance then it's actually the SAME label re-visited as // a result of executing a loop/branch operation, if it's in // a different place then it's an error in the script... if ((aPosition.iLineCount != dummyPos.iLineCount) || (aPosition.iOffset != dummyPos.iOffset)) { User::Leave(KErrAlreadyExists); } } }
void LabelManager::CreateLabel(LPCTSTR name) { if (mNumLabels == MAX_LABELS) { // Ignore attempts to create more labels than we can handle return; } if (FindLabel(name) != NULL) { // Ignore attempts to create the same label twice return; } // Create the label Label *label = new Label; if (!label->Create(name, mInstance)) { TRACE2("%s: Couldn't create label: %s", MODULE_NAME, name); delete label; return; } // Add it to the list mLabels[mNumLabels++] = label; }
void ActorInfo::FinishSequence(const char *jumplab, int offset) { statelabel_t *s = FindLabel(new_label.c_str()); if (s) { // replace existing sequence // discard old states if (s->dyn_states && s->label_states) free(s->label_states); } else { // add a new sequence labels.resize(labels.size() + 1); s = &labels.back(); strncpy(s->label, new_label.c_str(), SL_LEN); } int n = s->num_states = new_states.size(); s->dyn_states = true; // set label_states if (n) { // allocate label_states s->label_states = static_cast<state_t*>(malloc(n * sizeof(state_t))); state_t *st = s->label_states; for (int j=0; j < n; j++, st++) { *st = new_states[j]; st->nextstate = st + 1; } } else { s->label_states = NULL; } // fill in jump data if (jumplab) { strncpy(s->jumplabel, jumplab, SL_LEN); // either a label, or "" denoting S_NULL } else { // loop to first state in sequence (equivalent to "goto current_label", but save some effort here) s->jumplabel[0] = 1; // HACK } s->jumplabelnum = -2; // means "needs to be set" s->jumpoffset = offset; // So far so good, now we only need to fix nextstate pointer for last state in sequence // and check that jumplabel is good, but for that we need _all_ the state definitions... // This happens in UpdateSequences(). }
//从脚本文件的label处开始读取脚本命令,结果存入scripts bool CScript::Run(char* strFilePath, std::queue<std::string>* scripts, char* strLabel) { char* strCmd; std::string strCmdName; //打开脚本文件 if(OpenFile(strFilePath)) { m_nFileOffset = 0; //若传入指定label,计算指定label的文件偏移量 if(strcmp(strLabel,"") != 0) { if (FindLabel(strLabel) == 0) return false; } while(1) { strCmd = ReadCommand(); //读取一条命令 TrimSpace(strCmd); //去除首尾空字符 strCmdName.assign(GetCommandName(strCmd)); //命令为return,结束当前读取操作 if(strlen(strCmd) == 0 || stricmp(strCmd, "return") == 0) { SAFE_DELETE(strCmd); strCmdName.clear(); return true; } //读取的为标号,跳过该标号 else if (strCmd[strlen(strCmd)-1] == ':') { SAFE_DELETE(strCmd); strCmdName.clear(); continue; } // RunCommand(strCmd); //执行 scripts->push(std::string(strCmd)); //交命令加入结果列表中 SAFE_DELETE(strCmd); strCmdName.clear(); } } SAFE_DELETE(strCmd); strCmdName.clear(); return false; }
label_handle GetLabel( label_id label ) { //========================================== // Get a label. label_entry *le; le = FindLabel( label ); if( le->handle == NULL ) { le->handle = BENewLabel(); } return( le->handle ); }
back_handle GetFmtLabel( label_id label ) { //============================================= // Get a format label. label_entry *le; le = FindLabel( label ); if( le->handle == NULL ) { le->handle = BENewBack( NULL ); le->label |= FORMAT_LABEL; } return( le->handle ); }
void AnalyzePseudoInstr(size_t index, char *command, char str[MAX_INSTR_FIELD_NUM][MAX_INSTR_FIELD_STR_LEN]){ //extract element and place into the str array char line[MAX_INSTR_FIELD_STR_LEN]; char *oldCommand = command; size_t i = 0; for(i = 1; *pseudoInstrTable[index].pseudoInstr[i] != 0; i++){ //for every field of pseudo_instruction if((command = GetStr(line, command)) == oldCommand)//extract a string ERROR("Wrong Pseudo instruction syntax"); //do not have corresponding field #ifdef PSEUDO_BUG puts("After getStr"); #endif char *grammar = pseudoInstrTable[index].pseudoInstr[i]; if(strcmp(grammar, "rs") == 0){ strcpy(str[rs], line); } else if(strcmp(grammar, "rt") == 0){ strcpy(str[rt], line); } if(strcmp(grammar, "rd") == 0){ strcpy(str[rd], line); } else if(strcmp(grammar, "immediate") == 0){ strcpy(str[immediate], line); #ifdef PSEUDO_BUG puts("inside analyze: immediate:"); printf("immediate: %s\n", immediate); #endif } else if(strcmp(grammar, "label") == 0){ strcpy(str[label], line); reg_type immed; if(FindLabel(line, &immed)){ sprintf(str[immediate], "%d", immed); #ifdef PSEUDO_BUG printf("str[immediate]: %s\n", str[immediate]); #endif } } //place element to }//end of for every field of pseudo_instruction }
wxString KbdShortcutList::FormatShortCut(const wxString& label, bool includename, bool parentheses) { int index = FindLabel(label); if (index < 0) return wxEmptyString; wxASSERT(index >= 0 && index < (int)m_shortcuts.Count()); wxString shortcut = m_shortcuts[index].GetShortcut(); if (shortcut.Length() > 0) { if (parentheses) { shortcut = wxT("(") + shortcut + wxT(")"); if (!includename) shortcut = wxT(" ") + shortcut; } if (includename) shortcut = m_shortcuts[index].GetName() + wxT("\t") + shortcut; } else if (includename) { shortcut = m_shortcuts[index].GetName(); } return shortcut; }
NUMBER problem::CrossValidation(const int nr_fold, const NUMBER C,const NUMBER p) { int max_nr_class = 16; int nr_class = 0; int *label = (int*)malloc(max_nr_class*sizeof(int)); for(int i=0;i<l;i++) { int this_label = y[i]; int j; for(j=0;j<nr_class;j++) if(this_label == label[j]) break; if(j == nr_class) { if(nr_class == max_nr_class) { max_nr_class *= 2; label = (int *)realloc(label,max_nr_class*sizeof(int)); } label[nr_class] = this_label; ++nr_class; } } num_class = nr_class; if(labels) delete[] labels; labels = new int[nr_class]; std::copy(label,label+nr_class,labels); free(label); int *fold_start = new int[nr_fold+1]; int *perm = new int[l]; for(int i=0;i<l;i++) perm[i]=i; for(int i=0;i<l;i++) { int j = i+rand()%(l-i); std::swap(perm[i],perm[j]); } for(int i=0;i<=nr_fold;i++) fold_start[i]=i*l/nr_fold; int* pd = new int[l]; int* gt = new int[l]; for(int i=0;i<nr_fold;i++) { int begin = fold_start[i]; int end = fold_start[i+1]; int j,k; problem subprob; subprob.n = n; subprob.l = l-(end-begin); subprob.indexes = new int*[subprob.l]; subprob.values = new NUMBER*[subprob.l]; subprob.y = new int[subprob.l]; subprob.index_buf = index_buf; // This is required to compute offset for 'logxplus' subprob.value_buf = value_buf; subprob.allocated = allocated; k=0; for(j=0;j<begin;j++) { subprob.indexes[k] = indexes[perm[j]]; subprob.values[k] = values[perm[j]]; subprob.y[k] = y[perm[j]]; ++k; } for(j=end;j<l;j++) { subprob.indexes[k] = indexes[perm[j]]; subprob.values[k] = values[perm[j]]; subprob.y[k] = y[perm[j]]; ++k; } model submodel; subprob.Train(submodel,C,p); for(j=begin;j<end;j++) { gt[j] = FindLabel(y[j]); pd[perm[j]] = FindLabel(submodel.PredictValues(indexes[perm[j]],values[perm[j]],submodel._dec_values)); } submodel.~model(); subprob.index_buf = NULL; // avoiding double free subprob.value_buf = NULL; subprob.allocated = 0; subprob.Clear(); } NUMBER acc, accavg; ComputeAccuracies(l,num_class,gt,pd,acc,accavg); std::cout<<"Overall accuracy = "<<acc<<std::endl; std::cout<<"Average accuracy = "<<accavg<<std::endl; delete[] pd; delete[] gt; delete[] fold_start; return acc; }
/*adds and item to the final file layout*/ void AddItemToLayout(Cmd tempRecord,CmdQueue layoutQueue) { int relativePos,staticPos,i=0; char *tmpItem=NULL,*errmsg=NULL,*binary=NULL; char static *rememberMe=NULL; labelNode* tmpLabelNode; linkageNode* link; FIX_NULL_STRING(errmsg); FIX_NULL_STRING(rememberMe); FIX_NULL_STRING(tmpItem); if(tempRecord->kind=='d')/* for .string and .data */ { relativePos=ConvertCharToInt(tempRecord->decimal_address); staticPos=IC+relativePos; strcpy(tempRecord->decimal_address,ConvertIntToCharByBase(staticPos,ConversionToAddress,10)); strcpy(tempRecord->base_12_address,ConvertIntToCharByBase(staticPos,ConversionToAddress,12)); tempRecord->kind=' '; } if(strcmp(tempRecord->command,"?")==0) /* waiting for addresses calculation */ { relativePos=ConvertCharToInt(tempRecord->decimal_address); FIX_NULL_STRING(tmpItem); strcpy(tmpItem,tempRecord->operands); if(tmpItem[0]=='*') tmpLabelNode=FindLabel(_labels,tmpItem+1); else tmpLabelNode=FindLabel(_labels,tmpItem); if(tmpLabelNode==NULL)/* if label is not defined in input files, lets check if it's declared as external */ { if(tmpItem[0]=='*') link=FindLinkage(&Linkage_List,tmpItem+1,EXTERN); else link=FindLinkage(&Linkage_List,tmpItem,EXTERN); if(link==NULL) { strcpy(errmsg,"the label '"); if(tmpItem[0]=='*') strcat(errmsg,tmpItem+1); else strcat(errmsg,tmpItem); strcat(errmsg,"' has no reference"); ErrorHandler(CompilingError,errmsg); return; } else { if(tmpItem[0]=='*') { strcpy(errmsg,"the label '"); strcpy(errmsg,tmpItem+1); strcpy(errmsg," is external and cannot be used as rational"); ErrorHandler(FatalError,errmsg); return; } else /* the label is external and is legal */ { strcpy(tempRecord->command,""); strcpy(tempRecord->operands,""); FIX_NULL_STRING(binary); strcpy(binary,ConvertIntToCharByBase(0,ConversionToBmcType,2)); tempRecord->bmc=CreateBmcCode(binary); tempRecord->kind='e'; strcpy(tempRecord->base_12_machine_code,ConvertIntToCharByBase(0,ConversionToBase_12_Code,12)); /* Add the EXTERN's address */ if(strcmp(link->lineNumber,"?")==0) /* first EXTERN use - remove and insert in order to sort it */ { RemoveItemFromLinkageList(&Linkage_List,"?",tmpItem); AddLinkageItem(&Linkage_List,EXTERN,tmpItem,tempRecord->base_12_address); } else /* the EXTERN has been used at least one time, we will add another field */ AddLinkageItem(&Linkage_List,EXTERN,tmpItem,tempRecord->base_12_address); } } } else { if(tmpItem[0]=='*') { staticPos=ConvertCharToInt(tmpLabelNode->Value_10); /* relativePos=staticPos-ConvertCharToInt(tempRecord->decimal_address);*/ relativePos=staticPos-ConvertCharToInt(rememberMe); /* calculate the address using the one we remembered */ strcpy(tempRecord->command,""); strcpy(tempRecord->operands,""); FIX_NULL_STRING(binary); strcpy(binary,ConvertIntToCharByBase(relativePos,ConversionToBmcType,2)); tempRecord->bmc=CreateBmcCode(binary); tempRecord->kind='a'; strcpy(tempRecord->base_12_machine_code,ConvertBinaryStringToBase12(binary)); rememberMe=NULL; } else { strcpy(tempRecord->command,""); strcpy(tempRecord->operands,""); FIX_NULL_STRING(binary); strcpy(binary,ConvertIntToCharByBase(ConvertCharToInt(tmpLabelNode->Value_10),ConversionToBmcType,2)); tempRecord->bmc=CreateBmcCode(binary); strcpy(tempRecord->base_12_machine_code,ConvertBinaryStringToBase12(binary)); tempRecord->kind='r'; } } if(tmpItem[0]=='*') { } } else /*check if command includes relational addressing, if it does, save it's address*/ { strcpy(tmpItem,tempRecord->operands); for(i=0;i<strlen(tmpItem);i++) { if(tmpItem[i]=='*') { strcpy(rememberMe,tempRecord->decimal_address); break; } } } CmdQueue_AddRecord(tempRecord,layoutQueue); }
bool CXtfReader::GetXYXPos(INT_PT& p_) { double _dX, _dY; string::size_type _tPosX ,_tPosY; _tPosY = FindLabel('Y'); if (_tPosY != string::npos) { m_nLinePos = _tPosY + 1; GetDouble(_dY); m_cModeInfo.cLastAxis = LABEL_asY; m_cModeInfo.cValid[LABEL_asY] = VALID_LABEL; p_.y = _dY * g_fDataMult; m_cModeInfo.nXYZ[LABEL_asY] = p_.y; } _tPosX = FindLabel('X'); if (_tPosX != string::npos) { m_nLinePos = _tPosX + 1; GetDouble(_dX); m_cModeInfo.cLastAxis = LABEL_asX; m_cModeInfo.cValid[LABEL_asX] = VALID_LABEL; p_.x = _dX * g_fDataMult; m_cModeInfo.nXYZ[LABEL_asX] = p_.x; } if ((_tPosY == string::npos) && (_tPosX == string::npos)) { if (m_cModeInfo.cLastAxis != INVALID_LABEL && FindFirstDigit(m_nLinePos)) { double _dVal; if (!GetDouble(_dVal)) return false; if (LABEL_asY == m_cModeInfo.cLastAxis) { p_.y = _dVal * g_fDataMult; m_cModeInfo.nXYZ[LABEL_asY] = p_.y; } else if (LABEL_asX == m_cModeInfo.cLastAxis) { p_.x = _dVal * g_fDataMult; m_cModeInfo.nXYZ[LABEL_asX] = p_.x; } else return false; } } else if (_tPosX == string::npos) { if (m_cModeInfo.cValid[LABEL_asX] == VALID_LABEL) { p_.x = m_cModeInfo.nXYZ[LABEL_asX]; } else return false; } else if (_tPosY == string::npos) { if (m_cModeInfo.cValid[LABEL_asY] == VALID_LABEL) { p_.y = m_cModeInfo.nXYZ[LABEL_asY]; } else return false; } return true; }
/** ** Fix labels */ static void FixLabels(lua_State *l) { for (size_t i = 0; i < LabelsLater.size(); ++i) { *LabelsLater[i].Anim = FindLabel(l, LabelsLater[i].Name); } }
bool ActorInfo::UpdateSequences() { int n = labels.size(); // set jumplabelnum for (int i=0; i<n; i++) { statelabel_t *p, *s = &labels[i]; if (s->jumplabelnum != -2) continue; // already ok (never changes even if new labels are added or old ones redefined!) const char *temp = s->jumplabel; if (!temp[0]) // empty string denotes S_NULL { s->jumplabelnum = -1; } else if (temp[0] == 1) // HACK, loop { s->jumplabelnum = s - &labels.front(); // TODO is this certain to work? would iterators be better? } else if ((p = FindLabel(temp))) { s->jumplabelnum = p - &labels.front(); } else { // label not found Error("Unknown state label '%s'.\n", temp); s->jumplabelnum = -1; // go to S_NULL } if (s->jumplabelnum == -1 && s->num_states == 0) { // handle "xxx: stop" s->dyn_states = false; s->label_states = &states[S_NULL]; s->num_states = 1; } } // now re-set nextstate pointer for the last state in _every_ sequence using jump* info for (int i=0; i<n; i++) { statelabel_t *s = &labels[i]; if (!s->dyn_states) continue; // don't mess with static statetable int j = s->jumplabelnum; if (j < 0) { if (s->num_states == 0) { I_Error("FIXME, unexpected\n"); } else s->label_states[s->num_states-1].nextstate = &states[S_NULL]; // offset is ignored } else { // check redirection #define MAX_REDIRECTS 10 // allow max. 10 redirects int k; for (k=0; !labels[j].num_states && k < MAX_REDIRECTS; k++) { // follow redirect j = labels[j].jumplabelnum; if (j < 0) I_Error("DECORATE: Redirect to bad label.\n"); } if (k >= MAX_REDIRECTS) I_Error("DECORATE: Too many redirects.\n"); // or a cyclic redirect, "a: goto b; b: goto a;" if (s->num_states) // for redirects, do nothing { // update last state if (s->jumpoffset < labels[j].num_states) s->label_states[s->num_states-1].nextstate = &labels[j].label_states[s->jumpoffset]; else I_Error("DECORATE: State offset too large.\n"); // TODO wrap offsets to next seqs? } } } // fill in shorthand state pointers for (int j=0; j<9; j++) (&spawnstate)[j] = NULL; // HACK for (int i=0; i<n; i++) { const char *temp = labels[i].label; for (int j=0; j<9; j++) { if (!strcasecmp(StandardLabels[j], temp)) { // found a match for this label (&spawnstate)[j] = labels[i].label_states; // HACK break; } } } if (!spawnstate) { Error("Actor '%d' has no spawnstate!\n", classname); spawnstate = &states[S_NULL]; return false; } return true; }
void predict(FILE *input, FILE *output) { int correct = 0; int total = 0; double error = 0; double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0; int svm_type=svm_get_svm_type(model); int nr_class=svm_get_nr_class(model); double *prob_estimates=NULL; int j; // This block by Jianxin Wu, for average accuracy computation int ii,label_index; // number of correct predictions in each category int* correct_sub = (int *)malloc(nr_class*sizeof(int)); for(ii=0;ii<nr_class;ii++) correct_sub[ii] = 0; // number of testing examples in each category int* total_sub = (int *)malloc(nr_class*sizeof(int)); for(ii=0;ii<nr_class;ii++) total_sub[ii] = 0; int* labels_avg = (int*)malloc(nr_class*sizeof(int)); svm_get_labels(model,labels_avg); if(predict_probability) { if (svm_type==NU_SVR || svm_type==EPSILON_SVR) printf("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g\n",svm_get_svr_probability(model)); else { int *labels=(int *) malloc(nr_class*sizeof(int)); svm_get_labels(model,labels); prob_estimates = (double *) malloc(nr_class*sizeof(double)); fprintf(output,"labels"); for(j=0;j<nr_class;j++) fprintf(output," %d",labels[j]); fprintf(output,"\n"); free(labels); } } max_line_len = 1024; line = (char *)malloc(max_line_len*sizeof(char)); while(readline(input) != NULL) { int i = 0; double target_label, predict_label; char *idx, *val, *label, *endptr; int inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0 label = strtok(line," \t"); target_label = strtod(label,&endptr); if(endptr == label) exit_input_error(total+1); while(1) { if(i>=max_nr_attr-1) // need one more for index = -1 { max_nr_attr *= 2; x = (struct svm_node *) realloc(x,max_nr_attr*sizeof(struct svm_node)); } idx = strtok(NULL,":"); val = strtok(NULL," \t"); if(val == NULL) break; errno = 0; x[i].index = (int) strtol(idx,&endptr,10); if(endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index) exit_input_error(total+1); else inst_max_index = x[i].index; errno = 0; x[i].value = strtod(val,&endptr); if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) exit_input_error(total+1); ++i; } x[i].index = -1; if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC)) { predict_label = svm_predict_probability(model,x,prob_estimates); fprintf(output,"%g",predict_label); for(j=0;j<nr_class;j++) fprintf(output," %g",prob_estimates[j]); fprintf(output,"\n"); } else { predict_label = svm_predict(model,x); fprintf(output,"%g\n",predict_label); } // This block by Jianxin Wu, for average accuracy label_index = FindLabel((int)target_label,labels_avg); total_sub[label_index]++; if(predict_label == target_label) correct_sub[label_index]++; if(predict_label == target_label) ++correct; error += (predict_label-target_label)*(predict_label-target_label); sump += predict_label; sumt += target_label; sumpp += predict_label*predict_label; sumtt += target_label*target_label; sumpt += predict_label*target_label; ++total; } if (svm_type==NU_SVR || svm_type==EPSILON_SVR) { printf("Mean squared error = %g (regression)\n",error/total); printf("Squared correlation coefficient = %g (regression)\n", ((total*sumpt-sump*sumt)*(total*sumpt-sump*sumt))/ ((total*sumpp-sump*sump)*(total*sumtt-sumt*sumt)) ); } else printf("Accuracy = %g%% (%d/%d) (classification)\n", (double)correct/total*100,correct,total); if(predict_probability) free(prob_estimates); // This block (till endo of function) by Jianxin WU // Print per-category accuracy and average accuracy of categories double sub_score = 0; int nonempty_category = 0; for(ii=0;ii<nr_class;ii++) { if(total_sub[ii]>0) { sub_score += (correct_sub[ii]*1.0/total_sub[ii]); nonempty_category++; } } printf("-----------\n"); for(ii=0;ii<nr_class;ii++) { printf("%d / %d (Category %d)\n",correct_sub[ii],total_sub[ii],labels_avg[ii]); } printf("-----------\n"); printf("Mean Accuray across classes = %g%%\n",sub_score*100.0/nonempty_category); free(correct_sub); free(total_sub); free(labels_avg); }