public U0 DocProfile(U8 *filename,I64 flags) { I64 i,*cmd_stats=CAlloc(sizeof(I64)*DOCT_NUM_TYPES), *flags_stats=CAlloc(sizeof(I64)*64), *type_flags_stats=CAlloc(sizeof(I64)*64); //Note, word wrap is determined by //doc->win_task when a $LK,"CDoc","MN:CDoc"$ is recalculated //use $LK,"DocRecalc","MN:DocRecalc"$(). CDoc *doc=DocRead(filename,flags); //doc->root which is equal to doc is the //header of the CQue and represents the end-of-file marker. CDocEntry *doc_e=doc->root.next; while (doc_e!=doc) { cmd_stats[doc_e->type_u8]++; for (i=0; i<64; i++) if (Bt(&doc_e->flags1,i)) flags_stats[i]++; for (i=16; i<32; i++) if (Bt(&doc_e->type,i)) type_flags_stats[i]++; doc_e=doc_e->next; } DocDel(doc); "$$FG,PURPLE$$-------%s-------\n" ,filename; "$$FG,GREEN$$The lowest byte of the 32-bit 'doc_e->type', '$$FG,PURPLE$$doc_e->type.u8[0]$$FG,GREEN$$', is cmd and accessed with the union '$$FG,PURPLE$$doc_e->type_u8$$FG,GREEN$$'." "See $$LK,\"CDocEntry\",\"MN:CDocEntry\"$$, " "$$LK,\"Doc Type Defines\",\"MN:DOCT_TEXT\"$$ and $$LK,\"Doc Type Codes\",\"FF:::/TempleOS/Adam/Doc/Doc.CPP,ST_DOC_CMDS\"$$.\n$$FG$$"; for (i=0; i<DOCT_NUM_TYPES; i++) if (cmd_stats[i]) "%4Z:%d\n",i,"ST_DOC_CMDS",cmd_stats[i]; "\n$$FG,GREEN$$'$$FG,PURPLE$$doc_e->type.u8[1]$$FG,GREEN$$' is the screen color attr of the entry." "'$$FG,PURPLE$$doc_e->type.u16[1]$$FG,GREEN$$' is some flags for blinking and stuff." "See $$LK,\"Doc Type Flag Defines\",\"MN:DOCET_BLINK\"$$.\n$$FG$$"; for (i=16; i<32; i++) if (type_flags_stats[i]) "%4d:%d\n",i,type_flags_stats[i]; "$$FG,GREEN$$\n'$$FG,PURPLE$$doc_e->flags1$$FG,GREEN$$' is 64-bit." "See $$LK,\"Doc Flag Defines\",\"MN:DOCEf1_AUX_STR\"$$ and $$LK,\"Doc Flag Codes\",\"FF:::/TempleOS/Adam/Doc/Doc.CPP,ST_DOC_FLAGS\"$$.\n$$FG$$"; for (i=0; i<64; i++) if (flags_stats[i]) "%4Z:%d\n",i,"ST_DOC_FLAGS",flags_stats[i]; Free(cmd_stats); Free(flags_stats); PressAKey; NewLine; }
public CTaskSettings *SettingsPush(CTask *task=NULL,I64 flags=0) { //This is typically used at the start of an application. //It saves many settings so they can be restored //at the end of the application with $LK,"SettingsPop","MN:SettingsPop"$(). CTaskSettings *tempse; CDoc *doc; if (!task) task=Fs; if (!TaskValidate(task)) return NULL; tempse=CAlloc(sizeof(CTaskSettings),task); tempse->draw_it=task->draw_it; GetVGAPalette4(tempse->palette4); tempse->task_end_cb=task->task_end_cb; if (!(flags&TSF_SAME_SONG)) { if (tempse->song_task=task->song_task) { Suspend(task->song_task); Snd(0); } task->song_task=NULL; } if (tempse->animate_task=task->animate_task) Suspend(task->animate_task); task->animate_task=NULL; if (doc=DocPut(task)) { tempse->cursor=!Bt(&doc->flags,DOCf_HIDE_CURSOR); tempse->scroll=!Bt(&doc->flags,DOCf_NO_SCROLL_BARS); } tempse->left=task->win_left; tempse->right=task->win_right; tempse->top=task->win_top; tempse->bottom=task->win_bottom; tempse->scroll_x=task->win_scroll_x; tempse->scroll_y=task->win_scroll_y; tempse->scroll_z=task->win_scroll_z; tempse->win_inhibit=task->win_inhibit; MemCpy(&tempse->snap,&task->snap,sizeof(CSnap)); tempse->win_max_refresh=task->win_max_refresh; tempse->text_attr=task->text_attr; StrCpy(tempse->task_title,task->task_title); tempse->title_src =task->title_src; tempse->border_attr=task->border_attr; tempse->border_src =task->border_src; tempse->border=!Bt(&task->display_flags,DISPLAYf_NO_BORDER); tempse->preempt=Bt(&task->task_flags,TASKf_PREEMPT); if (TaskValidate(ws_task)) tempse->wordstat=TRUE; else tempse->wordstat=FALSE; tempse->next=task->next_settings; task->next_settings=tempse; return tempse; }
U0 PlaceSpring(MyMass *tempm1,MyMass *tempm2) { MySpring *temps=CAlloc(sizeof(MySpring)); temps->end1=tempm1; temps->end2=tempm2; temps->constant=10000; temps->rest_len=100; QueIns(temps,ode->last_spring); }
U0 PlaceMass(I64 x, I64 y) { MyMass *tempm=CAlloc(sizeof(MyMass)); tempm->mass=1.0; tempm->drag_profile_factor=100.0; tempm->x=x; tempm->y=y; tempm->radius=10*(Rand+0.25); QueIns(tempm,ode->last_mass); }
CFileAccess *FileAccessNew(U8 *_mask,Bool make_mask=FALSE,Bool make_dirs=FALSE) { Bool valid=TRUE,old_silent; U8 *buf,*mask,*temp_mask; CFileAccess *fa=CAlloc(sizeof(CFileAccess)); mask=MStrUtil(_mask, SUF_REM_LEADING|SUF_REM_TRAILING|SUF_REM_CTRL_CHARS); temp_mask=mask; fa->old_dir=StrNew(Fs->cur_dir); fa->old_prt=Fs->cur_prt; if (*mask && mask[1]==':') { if (Fs->cur_prt!=Drv2Prt(*mask)) if (!Drv(*mask)) valid=FALSE; mask+=2; } if (StrStr(mask,"HOME") && Fs->cur_prt!=Drv2Prt(*sys_acct)) Drv(*sys_acct); fa->p=Fs->cur_prt; PrtChk(fa->p); buf=MAlloc(StrLen(mask)+2); StrCpy(buf,mask); fa->mask=MAlloc(StrLen(mask)+2); StrLastRem(buf,"/",fa->mask); if (*mask=='/' && !*buf) StrCpy(buf,"/"); //If began with Dir, change to Dir. if (*buf && !Cd(buf,make_dirs)) valid=FALSE; if (valid && make_mask) { if (!*fa->mask) { Free(fa->mask); fa->mask=StrNew("*"); } else { if (!make_dirs || FileNameChk(fa->mask)) { old_silent=Silent(ON); //Try mask to see if Dir. If Dir, change to dir and set to "*". if (Cd(fa->mask,make_dirs)) { Free(fa->mask); fa->mask=StrNew("*"); } Silent(old_silent); } } } Free(buf); Free(temp_mask); if (!valid) { FileAccessDel(fa); fa=NULL; // throw(EXCEPT_FILE); } return fa; }
CFile *FOpen(U8 *filename,U8 *flags,I64 cnt=0) { //allows flags "r","w","w+". Include a "c" for contiguous. CFile *f=CAlloc(sizeof(CFile)); CFileAccess *fa; U8 *full_name; Bool contiguous=StrOcc(flags,'c'); f->cluster=INVALID_CLUSTER; f->fblk_num=0; if (cnt>0) f->max_blk=cnt-1; else f->max_blk=MAX_I64; f->file_cluster_num=INVALID_CLUSTER; full_name=FileNameAbs(filename); f->p=Drv2Prt(*full_name); if (f->p->type==PT_REDSEA) contiguous=TRUE; if (contiguous) { f->flags|=FF_CONTIGUOUS; if (f->p->type!=PT_REDSEA) { if (!(FileAttr(filename) & _ATTR_CONTIGUOUS)) throw(EXCEPT_FILE,2); } } f->cluster_buf=CAlloc(f->p->spc<<BLK_SIZE_BITS); if (StrOcc(flags,'w')) { f->flags=f->flags|FF_WRITE|FF_NEEDS_WRITE; if (StrOcc(flags,'+')) { if (FileFind(full_name,&f->de,FUF_JUST_FILES)) { Free(full_name); if (contiguous) f->max_blk=(FSize(f)+BLK_SIZE-1)>>BLK_SIZE_BITS-1; return f; } } else
U0 KeyMapFamily(U8 *family,CTask *task,I64 scf) { I64 i; U8 **entries=CAlloc(2*256*sizeof(U8 *)),st1[32],st2[32]; SPrintF(st1,"%s",family); SPrintF(st2,"%sSHIFT",family); KeyMapFamily2(entries ,st1,task,scf); KeyMapFamily2(entries+256,st2,task,scf+SCF_SHIFT); QSortI64(entries,2*256,&KMCompare); for (i=0;i<2*256;i++) if (entries[i]) { "" entries[i]; Free(entries[i]); } Free(entries); }
hypre_LGMRESFunctions * hypre_LGMRESFunctionsCreate( char * (*CAlloc) ( size_t count, size_t elt_size ), HYPRE_Int (*Free) ( char *ptr ), HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ), void * (*CreateVector) ( void *vector ), void * (*CreateVectorArray) ( HYPRE_Int size, void *vectors ), HYPRE_Int (*DestroyVector) ( void *vector ), void * (*MatvecCreate) ( void *A, void *x ), HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ), HYPRE_Int (*MatvecDestroy) ( void *matvec_data ), HYPRE_Real (*InnerProd) ( void *x, void *y ), HYPRE_Int (*CopyVector) ( void *x, void *y ), HYPRE_Int (*ClearVector) ( void *x ), HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ), HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ), HYPRE_Int (*PrecondSetup) ( void *vdata, void *A, void *b, void *x ), HYPRE_Int (*Precond) ( void *vdata, void *A, void *b, void *x ) ) { hypre_LGMRESFunctions * lgmres_functions; lgmres_functions = (hypre_LGMRESFunctions *) CAlloc( 1, sizeof(hypre_LGMRESFunctions) ); lgmres_functions->CAlloc = CAlloc; lgmres_functions->Free = Free; lgmres_functions->CommInfo = CommInfo; /* not in PCGFunctionsCreate */ lgmres_functions->CreateVector = CreateVector; lgmres_functions->CreateVectorArray = CreateVectorArray; /* not in PCGFunctionsCreate */ lgmres_functions->DestroyVector = DestroyVector; lgmres_functions->MatvecCreate = MatvecCreate; lgmres_functions->Matvec = Matvec; lgmres_functions->MatvecDestroy = MatvecDestroy; lgmres_functions->InnerProd = InnerProd; lgmres_functions->CopyVector = CopyVector; lgmres_functions->ClearVector = ClearVector; lgmres_functions->ScaleVector = ScaleVector; lgmres_functions->Axpy = Axpy; /* default preconditioner must be set here but can be changed later... */ lgmres_functions->precond_setup = PrecondSetup; lgmres_functions->precond = Precond; return lgmres_functions; }
U0 SysGlblsInit() { I64 i,j; U8 *m; CRAXRBCRCXRDX ee; CPUId(0x1,&ee); sys_cache_line_width=ee.rbx.u8[1]*8; QueInit(&sys_pci_dev_root); sys_rnd_seed = 93186752^GetTimeStamp; sys_focus_task=Fs; QueInit(&sys_macro_root); sys_dft_iso_name="::/Temp/CDDVD.ISO"; MemSet(mp_apic_ids,0,MP_MAX_PROCESSORS*sizeof(U8)); LBts(&adam_task->task_flags,TASKf_INIT_EXT);//So dbgger doesn't call $LK,"TaskInitExt","MN:TaskInitExt"$(). InDbg(ON); reverse_bits_table=CAlloc(256); for (i=0;i<256;i++) for (j=0;j<8;j++) if (Bt(&i,7-j)) LBts(reverse_bits_table+i,j); set_bits_table=CAlloc(256); for (i=0;i<256;i++) for (j=0;j<8;j++) if (Bt(&i,j)) set_bits_table[i]++; ext=CAlloc(EXT_TABLE_SIZE*sizeof(U8 *)); fp_mgets=&SysMGetS; fp_ctrl_alt_let_cbs=CAlloc(26*sizeof(U8 *)); ctrl_alt_let_descs=CAlloc(26*sizeof(U8 *));; ctrl_alt_let_in_irq_flags=0; psect_cache=CAlloc(PSECT_CACHE_SIZE*sizeof(CPSectCache)); psect_cache_index=0; StrCpy(sys_temp_filename,"HOME/Temp.TXT.Z"); MemSet(&sys_put_key_root,0,sizeof(CKeyDev)); QueInit(&sys_put_key_root); KeyDevAdd(&AKDInputFilterPutKey,&AKDInputFilterPutS,0x40000000,FALSE); KeyDevAdd(&AKDRawDisplayPutKey,&AKDRawDisplayPutS,0x60000000,FALSE); #exe { if (*kernel_cfg->acct_name) StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts/%s\");",kernel_cfg->sys_acct_drv,kernel_cfg->acct_name); else StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts\");",kernel_cfg->sys_acct_drv); StreamPutS("#exe{OptOff(OPTf_WARN_PAREN);}"); StreamPrintF("DskCacheInit(%s);",kernel_cfg->dsk_cache_size_exp); StreamPutS("#exe{OptOn(OPTf_WARN_PAREN);}"); };
CCtrl *SliderNew() { Bool old_preempt; CCtrl *c=CAlloc(sizeof(CCtrl)); c->win_task=Fs; c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP; c->type=CTRLT_GENERIC; c->state=&sld; MemSet(&sld,0,sizeof(CSliderState)); c->draw_it=&DrawSliderCtrl; c->left_click=&LeftClickSlider; c->update_derived_vals=&UpdateDerivedSliderCtrl; old_preempt=Preempt(OFF); QueIns(c,Fs->last_ctrl); TaskDerivedValsUpdate; Preempt(old_preempt); return c; }
CArcCtrl *ArcCtrlNew(Bool expand,Bool text_only) { CArcCtrl *c; c=CAlloc(sizeof(CArcCtrl)); if (expand) { c->stk_base=MAlloc(ARC_MAX_ENTRY+1); c->stk_ptr=c->stk_base; } if (text_only) c->min_bits=7; else c->min_bits=8; c->min_table_entry=1<<c->min_bits; c->free_index=c->min_table_entry; c->next_bits_in_use=c->min_bits+1; c->free_limit=1<<c->next_bits_in_use; c->saved_basecode=MAX_U32; c->entry_used=TRUE; ArcGetEntry(c); c->entry_used=TRUE; return c; }
CQueVectU8 *EdRICode(CDoc *doc) { CQueVectU8 *result; CRILex *rx=CAlloc(sizeof(CRILex)); rx->lx1=LexNew(NULL,LF_KEEP_NEW_LINES|LF_DONT_FREE_BUF,doc->filename.name); Free(rx->lx1->lfns[0].name); LexAttachDoc(rx->lx1,&rx->lx1->lfns[0],doc,,doc->cur_entry,doc->cur_data_col); rx->lx2=LexNew(NULL,LF_KEEP_NEW_LINES|LF_DONT_FREE_BUF,doc->filename.name); Free(rx->lx2->lfns[0].name); LexAttachDoc(rx->lx2,&rx->lx2->lfns[0],doc,,doc->cur_entry,doc->cur_data_col); rx->indent=QueVectU8New(doc->cur_entry->y); Lex(rx->lx1); EdRIStmt(rx,FALSE); LexDel(rx->lx1); LexDel(rx->lx2); result=rx->indent; Free(rx); return result; }
U0 EdCodeTools2(CDoc *doc,I64 tool_action) { Bool okay,unlock=DocLock(doc),start_of_line=TRUE; CDocEntry *doc_e,*doc_ne; I64 i,start_y,end_y,x,r,goto_line_num; U8 *b,*st,*st2,*prj_file; CTask *task=NULL; CSrvCmd *tempc; CQueVectU8 *indent; DocRecalc(doc); goto_line_num=doc->cur_entry->y+1; DocCaptureUndo(doc,TRUE); switch (tool_action) { case EF_CHK_COMPILE: okay=FALSE; if (doc->flags&DOCF_PLAIN_TEXT) DocFlagsToggle(doc,DOCF_PLAIN_TEXT); DocWrite(doc); task=Spawn(&SrvUserCmdLine,NULL,"Srv",,Fs); st2=CurDir; st=MSPrintF("Cd(\"%s\");",st2); tempc=TaskExeStrQue(task,Fs,st,1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER); Free(st2); Free(st); SetWinHorz(Fs->win_left,Fs->win_right, task); SetWinVert(Fs->win_top, Fs->win_bottom,task); if (ScanResult(tempc,&r)) { st=DirFile(doc->filename.name,,"PRJ.Z"), prj_file=FileNameAbs(st,FUF_Z_OR_NOT_Z); Free(st); if (FileFind(prj_file)) { st2=DirFile(prj_file), st=MSPrintF("Cd(\"%s\");",st2); Free(st2); tempc=TaskExeStrQue(task,Fs,st,1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER|1<<SVCf_FREE_ON_COMPLETE); Free(st); st=MSPrintF("\"$$WW,1$$\";Cmp(\"%s\",\"SysTemp\",\"SysTemp\");",prj_file); tempc=TaskExeStrQue(task,Fs,st,1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER); Free(st); if (ScanResult(tempc,&r)) if (!r) { tempc=TaskExeStrQue(task,Fs, "Load(\"SysTemp\",LDF_JUST_LOAD);",1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER); if (ScanResult(tempc,&r)) okay=TRUE; } tempc=TaskExeStrQue(task,Fs,"Del(\"SysTemp.*\");",1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER); ScanResult(tempc,&r); } else { Free(prj_file); st=DirFile(doc->filename.name,"Load","CPP.Z"); prj_file=FileNameAbs(st,FUF_Z_OR_NOT_Z); Free(st); if (FileFind(prj_file)) st=MSPrintF("\"$$WW,1$$\";ExeFile(\"%s\",TRUE);",prj_file); else st=MSPrintF("\"$$WW,1$$\";ExeFile(\"%s\",TRUE);",doc->filename.name); tempc=TaskExeStrQue(task,Fs,st,1<<SVCf_WAKE_MASTER|1<<SVCf_FOCUS_MASTER); Free(st); if (ScanResult(tempc,&r) && r) okay=TRUE; } Free(prj_file); } if (!okay) { PopUpOk("Has Errors"); while (LBts(&sys_semas[SYS_SEMA_FIX],0)) Yield; ToFileLine(sys_fix_file_line,&st,&i); LBtr(&sys_semas[SYS_SEMA_FIX],0); if (!StrCmp(st,doc->filename.name)) goto_line_num=i; Free(st); } break; case EF_REINDENT: if (EdGoToFun(doc,FALSE,FALSE)) { start_y=doc->cur_entry->y; indent=EdRICode(doc); DocUnlock(doc); Snd(2000); Sleep(150); Snd(0); Sleep(100); Snd(2000); Sleep(150); Snd(0); DocLock(doc); EdRemFunLeadingSpace(doc); DocLineNumGoTo(doc,start_y+1); doc_e=doc->cur_entry; end_y=start_y+indent->total_cnt; while (start_y<=doc_e->y<end_y) { if (doc_e!=doc && doc_e!=doc->cur_entry && !(doc_e->flags1&(DOCEG1_DONT_EDIT-DOCEF1_SCROLLING_X)) && !(doc_e->flags2&DOCEG2_DONT_EDIT)) { if (doc_e->type_u8==DOCT_NEW_LINE||doc_e->type_u8==DOCT_SOFT_NEW_LINE) start_of_line=TRUE; else { if (start_of_line) { i=QueVectU8Get(indent,doc_e->y)*C_INDENT_SPACES; x=doc_e->x+1; while (i>8) { doc_ne=CAlloc(sizeof(CDocEntryBase),doc->mem_task); doc_ne->type=DOCT_TAB | doc->settings_root.dft_text_attr << 8; doc_ne->x=x; doc_ne->y=doc_e->y; doc_ne->page_line_num=doc_e->page_line_num; QueIns(doc_ne,doc_e->last); i-=8; x+=8; } if (i>0) { b=MAlloc(i+1,doc->mem_task); MemSet(b,CH_SPACE,i); b[i]=0; doc_ne=CAlloc(sizeof(CDocEntryBase),doc->mem_task); doc_ne->type=DOCT_TEXT | doc->settings_root.dft_text_attr << 8; doc_ne->tag=b; doc_ne->max_col=1; doc_ne->x=x; doc_ne->y=doc_e->y; doc_ne->page_line_num=doc_e->page_line_num; QueIns(doc_ne,doc_e->last); } } start_of_line=FALSE; } } doc_e=doc_e->next; } QueVectU8Del(indent); } break; case EF_RENUM_ASM: if (EdGoToFun(doc,FALSE,TRUE)) { if (EdCurU8(doc)=='{') { EdCursorRight(doc); DocRecalc(doc); } else if (EdCurU8(doc)==':') { EdCursorRight(doc); if (EdCurU8(doc)==':') EdCursorRight(doc); DocRecalc(doc); } DocUnlock(doc); Snd(2000); Sleep(150); Snd(0); Sleep(100); Snd(2000); Sleep(150); Snd(0); DocLock(doc); EdRenumAsm(doc); } break; }
int main(int argc, char *argv[]) { char *gtm_fname=0; char *tlb_str=0; char *tlb_fname=0; int global_min=0x7FFFFFFF; int exact=0; int time_limit=0; int switch_cost=1, absence_cost=1, diff_cost=1; int subt1=-1, subt2=-1; for (int i=1;i<argc;i++) { if (argv[i][0]!='-') { if (gtm_fname==0) { gtm_fname=argv[i]; } else { printf("ERROR: Only one input file is allowed\n."); exit(1); } } else { if (strcmp("-cost", argv[i])==0) { const int no_costs=3; i++; if (argv[i][0]==0) { printf("Cost tuple cannot be empty\n"); exit(1); } for (int j=0;j<strlen(argv[i]);j++) { if (!isdigit(argv[i][j])) { printf("Invalid cost tuple %s\n", argv[i]); exit(1); } } if (strlen(argv[i])%no_costs!=0) { printf("Cost tuple %s length is not a multiple of %d.\n", argv[i], no_costs); exit(1); } int d=strlen(argv[i])/no_costs; switch_cost=0; diff_cost=0; absence_cost=0; int j=0; for (int k=0;k<d;k++) switch_cost=switch_cost*10+argv[i][j++]-'0'; for (int k=0;k<d;k++) absence_cost=absence_cost*10+argv[i][j++]-'0'; for (int k=0;k<d;k++) diff_cost=diff_cost*10+argv[i][j++]-'0'; } else if (strcmp("-switch", argv[i])==0) { switch_cost=atoi(argv[++i]); } else if (strcmp("-diff", argv[i])==0) { diff_cost=atoi(argv[++i]); } else if (strcmp("-absence", argv[i])==0) { absence_cost=atoi(argv[++i]); } else if (strcmp("-wsize", argv[i])==0) { wsize=atoi(argv[++i]); } else if (strcmp("-timelimit", argv[i])==0) { time_limit_str = argv[++i]; char *p = time_limit_str + strlen(time_limit_str)-1; if (*p == 'd') { time_limit = 24*3600; } else if (*p == 'h') { time_limit = 3600; } else if (*p == 'm') { time_limit = 60; } else if (*p == 's' || ('0'<=*p && *p<='9')) { time_limit = 1; } else { printf("Unknown option time limit %s\n", time_limit_str); exit(0); } //*p = 0; time_limit *= atoi(time_limit_str); } else if (strcmp("-min", argv[i])==0) { global_min=atoi(argv[++i]); } else if (strcmp("-maxcolor", argv[i])==0) { exact=0; max_color=atoi(argv[++i]); } else if (strcmp("-xmaxcolor", argv[i])==0) { exact=1; max_color=atoi(argv[++i]); } else if (strcmp("-tlbfile", argv[i])==0) { tlb_fname=argv[++i]; } else if (strcmp("-tlb", argv[i])==0) { tlb_str=argv[++i]; } else if (strcmp("-subtime", argv[i])==0) { subt1=atoi(argv[++i]); subt2=atoi(argv[++i]); assert(subt1<subt2); } else { printf("Unknown option %s\n", argv[i]); print_usage(argv[0]); } } } if (gtm_fname==0) { print_usage(argv[0]); exit(1); } if (access(gtm_fname, F_OK)!=0) { printf("Input file %s does not exist\n", gtm_fname); exit(1); } // load gtm file gtm_data gtm; if (load_gtmfile(gtm_fname, >m)) { printf("Error loading gtm file: %s\n", gtm_fname); exit(1); } const int group_count = gtm.group_count; const int ind_count = gtm.ind_count; const int time_count = gtm.time_count; const int max_time_size = gtm.max_time_size; const int exist_ind_count = gtm.exist_ind_count; int *time_first_group = gtm.time_first_group; const int *group_time = gtm.group_time; const int *group_size = gtm.group_size; linked_group **group_array = gtm.group_array; if (subt1==subt2 && subt1==-1) { // default subt1 = 0; subt2 = time_count; } if (max_color<=0) { for (int t=0;t<=time_count;t++) { if (time_first_group[t+1]-time_first_group[t]>max_color) { max_color = time_first_group[t+1]-time_first_group[t]; } } } if (max_time_size>max_color) { printf("Not enough colors. Need at least %d colors.\n", max_time_size); exit(1); } if (exact && group_count<max_color) { printf("Too many colors while exact is on: %d groups, %d group colors", group_count, max_color); exit(1); } /* debug linked_group *p; for (p=*group_array;p!=0;p=p->next) { printf("group %d time %d:", p->group, p->timestep); for (int i=0;i<p->member_count;i++) { printf(" %d", p->member[i]); } printf("\n"); } */ if (print_info>=2) { printf("%d group(s) %d timestep(s)\n", group_count, time_count); printf("%d observed individual(s) from %d allocated IDs\n", exist_ind_count, ind_count); printf("max color %d exact %s\n", max_color, exact?"on":"off"); printf("max time size %d\n", max_time_size); printf("cost %d %d %d\n", switch_cost, absence_cost, diff_cost); printf("initial min %d\n", global_min); if (time_limit<=0) { printf("no time limit\n"); } else { printf("time limit %s (%d sec)\n", time_limit_str, time_limit); } } int min_group_color[group_count]; int *time_lowerbound=0; // read/compute lower bounds if (tlb_str || tlb_fname) { time_lowerbound = CAlloc(time_count+1, sizeof(int)); int index=0; if (tlb_fname) { if (print_info>=2) printf("tlbfile %s:", tlb_fname); FILE *fp = fopen(tlb_fname, "r"); if (fp>0) { while (index<=time_count) { if (fscanf(fp, "%d", &time_lowerbound[index])!=1) break; index++; } fclose(fp); if (index==0) { fp=NULL; } else if (index!=time_count) { printf("ERROR: %d numbers are expected in tlb file %s but only %d found\n", time_count, tlb_fname, index); exit(1); } } if (fp<=0) { // possibly file doesn't exists fprintf(stderr, "tlbfile %s doesn't exist.\n", tlb_fname); exit(EXIT_FAILURE); } } else { if (print_info>=2) printf("tlb:"); while (index<=time_count) { if (sscanf(tlb_str, "%d", &time_lowerbound[index])!=1) break; index++; // advance tlb_str while(*tlb_str!=0 && ('0' > *tlb_str || *tlb_str > '9')) tlb_str++; while(*tlb_str!=0 && '0' <= *tlb_str && *tlb_str <= '9') tlb_str++; } } while (index<=time_count) { time_lowerbound[index++]==0; } if (print_info>=2) { // print tlb for (int t=0;t<=time_count;t++) { printf(" %d", time_lowerbound[t]); } printf("\n"); } } else { if (wsize>0) { if (print_info>=2) printf("tail lowerbounding enabled: window size %d\n", wsize); time_lowerbound = CAlloc(time_count+1, sizeof(int)); int lbs[time_count+1]; memset(lbs, 0, sizeof(int)*(time_count+1)); if (print_info>=2) printf("compute tail lowerbounds\n"); for (int t1=subt2;(t1-=wsize)>=subt1;) { int g0=time_first_group[t1], gn=time_first_group[t1+wsize]; if (print_info>=2) printf("g%d t%d -- g%d t%d ", g0+1, t1+1, gn, t1+wsize); fflush(stdout); int lb=0x7FFFFFFF; int rc = exhaustiveSearch(switch_cost, absence_cost, diff_cost, g0, group_array, gn, time_lowerbound, time_count, t1, t1+wsize, group_size, group_time, ind_count, &lb, min_group_color, 0, max_color<gn?max_color:gn, time_limit, 0, 1); if (print_info>=2) printf("lb %d\n", lb); for (int t=0;t<time_count;t++) { if (t1-t<0) break; lbs[t1-t] += lb; } } memcpy(time_lowerbound, lbs, sizeof(int)*(time_count+1)); if (print_info>=2) { printf("time lowerbound:"); for (int t=subt1;t<=subt2;t++) { printf(" %d", time_lowerbound[t]); } printf("\n"); } //return 0; } else { if (print_info>=2) printf("tail lowerbounding disabled\n"); } } // run exhaustive search if (print_info>=2) printf("start main loop\n"); fflush(stdout); int g1=time_first_group[subt1], g2=time_first_group[subt2]; global_min = exhaustiveSearch(switch_cost, absence_cost, diff_cost, g1, group_array, g2, time_lowerbound, time_count, subt1, subt2, group_size, group_time, ind_count, &global_min, min_group_color, exact, max_color, time_limit, print_info, 1); clear_linked_group(*group_array); Free(group_array); if (time_lowerbound) Free(time_lowerbound); return 0; }
StrCpy(sys_temp_filename,"HOME/Temp.TXT.Z"); MemSet(&sys_put_key_root,0,sizeof(CKeyDev)); QueInit(&sys_put_key_root); KeyDevAdd(&AKDInputFilterPutKey,&AKDInputFilterPutS,0x40000000,FALSE); KeyDevAdd(&AKDRawDisplayPutKey,&AKDRawDisplayPutS,0x60000000,FALSE); #exe { if (*kernel_cfg->acct_name) StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts/%s\");",kernel_cfg->sys_acct_drv,kernel_cfg->acct_name); else StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts\");",kernel_cfg->sys_acct_drv); StreamPutS("#exe{OptOff(OPTf_WARN_PAREN);}"); StreamPrintF("DskCacheInit(%s);",kernel_cfg->dsk_cache_size_exp); StreamPutS("#exe{OptOn(OPTf_WARN_PAREN);}"); }; pow10_I64=CAlloc(sizeof(F64)*(308+308+1)); for (i=-308;i<309;i++) pow10_I64[i+309]=Pow10(i); QueInit(&snd_record_root); snd_record_root.freq=0; snd_record_root.time_stamp=tT; //$AN,"Independent Heap Ctrl Example","Independent Heap Ctrl Example"$ i=1; //Rqst 1 blk, we might get more. m=MemBlksUncachedAlloc(&i,sys_code_bp); sys_uncached_heap=HeapCtrlIndependentInit(m,i*0x200000/0x200); ProgressBarsRst; date_fmt_map=MAlloc(DF_NUM); time_fmt_map=MAlloc(TF_NUM); DateTimeFmtMapsRst;