int main(int argc, char *argv[]) { int sprite_policy = 1; int cmap_policy = 1; int wait_msec = WAIT_MSEC; struct itimerval value, ovalue; struct sigaction sig_act; int i; scale_log2 = 0; cheat_mode = 0; for (i=1; i<argc; i++){ if (!strcmp("-speed", argv[i])) sprite_policy = 0; else if (!strcmp("-fast", argv[i])) sprite_policy = 0; else if (!strcmp("-doublesize", argv[i])) scale_log2 = 1; else if (!strcmp("-private", argv[i])) cmap_policy = 0; else if (!strcmp("-fit", argv[i])) cmap_policy = 0; else if (!strcmp("-cheat", argv[i])) cheat_mode = 1; else if (!strcmp("-display", argv[i])) win::set_disp_string(argv[++i]); else if (!strcmp("-wait", argv[i])) wait_msec = atoi(argv[++i]); else if (!strcmp("-hiscores", argv[i])) put_score(); else put_usage(); } wbase .event(ClientMessage, &client_message_callback); wscore.event(ClientMessage, &client_message_callback); wbase .event(FocusIn, &focus_in_callback ); wbase .event(FocusOut, &focus_out_callback ); wbase .event(KeyPress, &key_press_callback ); wbase .event(KeyRelease, &key_release_callback ); wchip .event(ButtonPress, &button_press_callback ); wchip .event(ButtonRelease, &button_release_callback); wchip .event(MotionNotify, &motion_callback ); wchip .event(LeaveNotify, &leave_callback ); wbase.make(NULL, 0, 0, MARGIN * 3 + ((WSIZE + MAP_SIZEX) << scale_log2), MARGIN * 2 + (WSIZE << scale_log2), cmap_policy); wchip.make(&wbase, MARGIN, MARGIN, WSIZE << scale_log2, WSIZE << scale_log2, (SCREEN_SIZEX + WSIZE) << scale_log2, (SCREEN_SIZEY + WSIZE) << scale_log2, 320 << scale_log2, 240 << scale_log2, sprite_policy); wradar.make(&wbase, MARGIN * 2 + (WSIZE << scale_log2), MARGIN + ((WSIZE - MAP_SIZEY) << scale_log2), MAP_SIZEX << scale_log2, MAP_SIZEY << scale_log2); wscore.make(NULL, 0, 0, WSCORE_SIZEX, WSCORE_SIZEY); if (link_tiff(spdata, wbase, wchip)) return 1; wbase.title("xkobo"); wbase.set_wm_close(); wbase.hold_size(); wbase.font(NORMAL_FONT); wbase.foreground(wbase.alloc_color(65535, 65535, 65535)); wbase.background(wbase.alloc_color(0, 0, 0)); wbase.map(); wbase.clear(); wchip.foreground(wbase.alloc_color(65535, 65535, 65535)); wchip.background(wbase.alloc_color(0, 0, 0)); wchip.setborder(wbase.alloc_color(0, 0, 0)); wchip.erase_cursor(); wchip.map(); wradar.foreground(wbase.alloc_color(65535, 65535, 65535)); wradar.background(wbase.alloc_color(0, 0, 0)); wradar.setborder(wbase.alloc_color(0, 0, 0)); wradar.map(); wscore.title("xkobo-score"); wscore.set_wm_close(); wscore.hold_size(); wscore.font(NORMAL_FONT); wscore.foreground(wbase.alloc_color(65535, 65535, 50000)); wscore.background(wbase.alloc_color(0, 0, 0)); wscore.map(); wscore.clear(); rand_num.init(); manage.init(); memset(&sig_act, 0, sizeof(sig_act)); sig_act.sa_handler = sig_handle; sigaction(SIGALRM, &sig_act, 0); value.it_interval.tv_sec = 0; value.it_interval.tv_usec = wait_msec * 1000; value.it_value.tv_sec = 0; value.it_value.tv_usec = wait_msec * 1000; setitimer(ITIMER_REAL, &value, &ovalue); for (;;){ if (wait_msec && (signal_delivered == 0)) pause(); signal_delivered = 0; if (manage.mainloop()) break; } return 0; }
int cafe_mainX(int ac,const char *av[],FILE *out,FILE *log) { const char *arg; int ai; int period; CStr(cwd,1024); const char *Root = 0; IStr(Rtop,1024); const char *tops[1024]; /**/ const char *top; int topx,tx; int cacheonly = 0,wonly = 0; CStr(ls_optsb,128); CStr(args,64*1024); refQStr(ap,args); /**/ const char *ax = &args[sizeof(args)-1]; const char *pp; int fnot = 0; minit_icache(); topx = 0; LOG = out; if( ac == 1 ){ put_usage(LOG,av[0]); exit(0); } NOW = time(0); for( ai = 1; ai < ac; ai++ ){ arg = av[ai]; pp = ap; ap = catarg1(args,AVStr(ap),arg); if( ax <= ap ){ break; } if( strncmp(arg,"-root=",6) == 0 ){ Root = arg+6; }else if( strcmp(arg,"-not") == 0 ){ fnot = ai+1; }else if( strcmp(arg,"-ign") == 0 ){ ++ai; ap = (char*)pp; }else if( strcmp(arg,"-log") == 0 || strcmp(arg,"-err") == 0 ){ if( ++ai < ac ){ LOG = setlog(av[ai]); ap = (char*)pp; } }else if( strcmp(arg,"-utime") == 0 ){ F_UATIME = 1; }else if( strcmp(arg,"-atime") == 0 ){ if( ++ai < ac ){ ap = catarg1(args,AVStr(ap),av[ai]); period = get_period(av[ai]); if( period < 0 ) A_FROM = NOW + period; else A_TILL = NOW - period; } }else if( strcmp(arg,"-mtime") == 0 ){ if( ++ai < ac ){ ap = catarg1(args,AVStr(ap),av[ai]); period = get_period(av[ai]); if( period < 0 ) M_FROM = NOW + period; else M_TILL = NOW - period; } }else if( strcmp(arg,"-asize") == 0 ){ if( ++ai < ac ){ ap = catarg1(args,AVStr(ap),av[ai]); REM_SIZE = atoi(av[ai]); } }else if( strcmp(arg,"-name") == 0 ){ if( ++ai < ac ){ F_NAME_NOT = (fnot == ai-1); F_NAME = av[ai]; } }else if( strcmp(arg,"-type") == 0 ){ if( ++ai < ac ){ F_TYPE = av[ai]; } }else if( strncmp(arg,"-ls",3) == 0 ){ F_LSFORM = 1; if( arg[3] == 0 ) strcpy(ls_optsb,"dl"); else sprintf(ls_optsb,"d%s",&arg[3]); ls_opts = ls_optsb; }else if( strncmp(arg,"-du",3) == 0 ){ F_DU = 1; if( strchr(&arg[3],'s') == 0 ) F_DIR = 1; if( strchr(&arg[3],'a') != 0 ) F_PRINT = 1; }else if( strcmp(arg,"-s") == 0 ){ F_DIR = 0; }else if( strncmp(arg,"-ic",3) == 0 || strncmp(arg,"-iw",3) == 0 || strncmp(arg,"-ir",3) == 0 ){ if( arg[3] ) icachedir = &arg[3]; else icachedir = "/tmp/cafe"; if( strncmp(arg,"-ir",3) == 0 ) cacheonly = 1; if( strncmp(arg,"-iw",3) == 0 ) wonly = 1; }else if( strncmp(arg,"-mv",3) == 0 ){ F_MOVE = 1; }else if( strcmp(arg,"-h") == 0 ){ F_FOLLOW_SYMLINK = 1; }else if( strcmp(arg,"-m") == 0 ){ F_FOLLOW_MOUNT = 1; }else if( strcmp(arg,"-v") == 0 ){ F_VERBOSE = 1; }else if( strcmp(arg,"-a") == 0 ){ /* ignore */ }else if( strncmp(arg,"-p",2) == 0 ){ F_PRINT = 1; }else if( strcmp(arg,"-sum") == 0 ){ F_SUMMARY = 1; }else if( strcmp(arg,"-rm") == 0 ){ F_REMOVE = 1; }else if( arg[0] == '-' ){ if( atoi(&arg[1]) ) N_LIST = atoi(&arg[1]); }else{ if( elnumof(tops)-2 <= topx ){ continue; } tops[topx++] = arg; tops[topx] = 0; ap = (char*)pp; } } XsetVStrEnd(AVStr(ap),0); if( topx == 0 ){ tops[topx++] = "."; tops[topx] = 0; } if( !F_PRINT && !F_LSFORM && !F_DU && !F_SUMMARY ){ F_DU = 1; } if( icachedir != NULL && !fileIsdir(icachedir) ){ if( mkdir(icachedir,0755) != 0 ){ errlog("%s: can't make inode cache directory: %s\n", av[0],icachedir); exit(1); } } IGNRETS getcwd(cwd,sizeof(cwd)); CWD = cwd; for( tx = 0; tx < topx; tx++ ){ top = tops[tx]; if( Root ){ IStr(tmp,1024); strcpy(tmp,""); chdir_cwd(AVStr(tmp),top,0); strcpy(Rtop,Root); if( *tmp == '/' ) ovstrcpy(tmp,tmp+1); if( *tmp ){ if( strtailchr(Rtop) != '/' ) strcat(Rtop,"/"); strcat(Rtop,tmp); } top = Rtop; } if( LOG != stdout ) if( LOG != out ) errlog("%s %s\n",top,args); if( !icachedir || !cacheonly ) find0(LOG,Root,top); /* find0(LOG,top); */ if( icachedir != NULL ) if( !wonly ) find_icache(LOG,top,N_LIST); if( F_SUMMARY ) summary(LOG,top); } if( LOG != out ) fclose(LOG); return 0; }