int main(int argc, char** argv) { char * inputNumber; intu originBase; if (argc==1) { inputNumber = (char*) malloc (DEFAULT_LENGTH); interactiveModePrompt(inputNumber, originBase); printf("%u\n",convertToDecimal(inputNumber,originBase)); } else if (argc==2) { if (!strcmp(argv[1],"--help")||!strcmp(argv[1],"-h")) { printCStr(argv[0],0); printf(" [input-number] [original-base]\n" "\n" "Both arguments are optional, in which case the program launches\n" "interactive move. However, you must supply both arguments if you\n" "choose not to run interactive mode.\n" "\n" "input-number: a number of arbitrary base to be converted into base 10.\n" "\tIf larger than base 10, use A-Z or a-z for digits greater than 9.\n" "\tThe program will complain if the variable contains any other values\n" "\tor starts with a 0.\n" "\n" "original-base: the number of this base for conversion purposes. Because\n" "\tthe program uses A-Z for digits larger than 9, you cannot specify a base\n" "\tlarger than 36 for this number. The program will complain if you exceed\n" "\tthis value.\n"); exit(NO_ERROR); } fprintf(stderr,"Incorrect usage.\n" "This program requires either zero arguments to enter interactive mode," "or two arguments to enter automatic mode.\n" "Usage:"); printCStr(argv[0],1); fprintf(stderr," [input-number] [original-base]\n" "\n" "You may specify \"--help\" or \'-h\' as the first argument if you do not" "know what sorts of input the program expects to see.\n"); exit(ERR_NOARGS); } else { inputNumber = (char*) malloc (strlen(argv[0])); originBase = static_cast<intu>(atoi(argv[1])); printf("%u\n",convertToDecimal(inputNumber,originBase)); } return 0; }
int go_burnin_ctl_thread(void *pdata) { extern lua_State *L; extern int burnin_run; extern int burnin_kill; extern int leave; extern int fresh_display; char tmpstr[128]={0}; char *tmp = NULL; int hours = 0; time_t now; FILE *fp = NULL; gettimeofday(&t1, NULL); hours = getTableNumElement(L, "con", "BURNIN_RUN_TIME"); printf("I will burnin for %d hours.\n", hours); system( "mkdir -p /root/logs/"); if ((fp = fopen( "/root/logs/control.txt", "w")) == NULL) { printf("Error when create control.txt\n"); exit(1); } time( &now); sprintf( tmpstr, "start: %s\n", ctime( &now)); printf( " %s \n", tmpstr); fprintf(fp, "%s\n", tmpstr); fflush(fp); fclose(fp); sleep(2); // for test gettimeofday(&t2, NULL); gettimeofday(&t3, NULL); while(1) { gettimeofday(&t2, NULL); if( burnin_kill || (t2.tv_sec - t1.tv_sec)> 60 * hours ) { if ( (t2.tv_sec -t3.tv_sec)/60 >= 10){ t3 = t2; if ((fp = fopen( "/root/logs/control.txt", "a")) == NULL) { printf("Error when create control.txt\n"); exit(1); } time( &now); sprintf( tmpstr, "run : %s\n", ctime( &now)); printf( " %s\n", tmpstr); fprintf(fp, "%s\n", tmpstr); fflush(fp); fclose(fp); } extern int ITEM_NUMBER; int i = 0; char run_file[1024] = {0}; char *path = (char *)getTableElement(L, "con", "PATH"); sprintf( run_file, "%sburnin/control/run.lua",path); // clear the global running flag burnin_kill = 0; burnin_run = 0; fresh_display = 0; SDL_Delay(1000); for (i=0; i < ITEM_NUMBER; i++) { if (threads[i]) { SDL_KillThread(threads[i]); threads[i] = NULL; } } printf("Burnin threads have been killed!\n"); SDL_Delay(500); // control the life time of other thread run(L, run_file); break; } SDL_Delay(5000); } char *pnt = "ALL Items are OK!!"; printCStr( pnt, (W_WIDTH - (strlen(pnt)*8))/2, W_HEIGHT / 2, 0x00008000); printf("Control thread exit!\n"); refreshWin(); SDL_Delay(1000); if ((fp = fopen( "/root/logs/control.txt", "a")) == NULL) { printf("Error when create control.txt\n"); exit(1); } time( &now); sprintf( tmpstr, "end : %s\n", ctime( &now)); printf( " %s\n", tmpstr); fprintf(fp, "%s\n", tmpstr); fflush(fp); fclose(fp); leave = 1; SDL_Delay(30000); refreshWin(); return 0; }