static void cmd_adjust(struct disklabel *lp, char *s, int fd) { struct disklabel dl; if (dk_ioctl(fd, DIOCGDEFLABEL, &dl) == -1) { warn("Cannot get default label"); return; } if (dl.d_secperunit != lp->d_secperunit) { char line[BUFSIZ]; int i = getinput(line, "Adjust disklabel sector from %" PRIu32 " to %" PRIu32 " [n]? ", lp->d_secperunit, dl.d_secperunit); if (i <= 0) return; if (line[0] != 'Y' && line[0] != 'y') return; lp->d_secperunit = dl.d_secperunit; return; } printf("Already at %" PRIu32 " sectors\n", dl.d_secperunit); return; }
void fillfields(struct FIELDLIST *list, int *aborted) { struct FIELD *field; int exitkey; int exitloop = 0; field = list->list; curs_set(1); do { getinput(list, field, &exitkey); switch (exitkey) { case 9: case KEY_DOWN: field = field->nextfield; break; case KEY_UP: field = field->prevfield; break; case 13: case 10: *aborted = 0; exitloop = 1; break; case 27: case 24: *aborted = 1; exitloop = 1; break; } } while (!exitloop); curs_set(0); }
input_handle createinput(char*name,int bsize,bufferlow callb,void*data) { input_handle hdl; if(getinput(name))return 0; hdl=malloc(sizeof(struct input_t)); if(inputbase){ hdl->next=inputbase; hdl->prev=inputbase->prev; inputbase->prev=hdl; hdl->prev->next=hdl; }else{ inputbase=hdl->next=hdl->prev=hdl; } hdl->bsize=bsize; hdl->buffer=malloc(bsize); hdl->bstart=hdl->blen=0; hdl->callback=callb; hdl->data=data; hdl->name=malloc(strlen(name)+1); strcpy(hdl->name,name); log(L_DEBUG,"created input %s, buffer size %i",name,bsize); return hdl; }
int main() { char buf[1024]; pid_t pid; int status; if (signal(SIGINT, sig_int) == SIG_ERR) { fprintf(stderr, "signal error: %s\n", strerror(errno)); exit(1); } while (getinput(buf, sizeof(buf))) { buf[strlen(buf) - 1] = '\0'; if((pid=fork()) == -1) { fprintf(stderr, "shell: can't fork: %s\n", strerror(errno)); continue; } else if (pid == 0) { /* child */ execlp(buf, buf, (char *)0); fprintf(stderr, "shell: couldn't exec %s: %s\n", buf, strerror(errno)); exit(EX_DATAERR); } if ((pid=waitpid(pid, &status, 0)) < 0) fprintf(stderr, "shell: waitpid error: %s\n", strerror(errno)); } exit(EX_OK); }
static void cmd_round(struct disklabel *lp, char *s, int fd) { int i; char line[BUFSIZ]; i = getinput(line, "Rounding [%s]: ", rounding ? "cylinders" : "sectors"); if (i <= 0) return; switch (line[0]) { case 'c': case 'C': rounding = 1; return; case 's': case 'S': rounding = 0; return; default: printf("Rounding can be (c)ylinders or (s)ectors\n"); return; } }
int main() { char *buffer; char *input; //struct promptinfo *prompt; if ((buffer=(char *)malloc(INPUT_MAX_LEN*(sizeof(char))))==0) { printf("error! can't malloc enough space for buffer\n"); return (0); } //prompt=(struct promptinfo*)malloc(sizeof(struct promptinfo)); //getpromptinfo(prompt); while(1) { prompt(); input = getinput(buffer); if (strcmp(input, "exit")==0) { printf("EXIT!\n"); exit(0); } if (strlen(input)!=0) interpreter(input); } return 0; }
INPUT *user_register(pUser puHead, INPUT *pu) { pu = getinput(pu); if (pu == NULL) return NULL; if ( !strcmp(pu->name, "admin") ) { strcpy(pu->name, ""); strcpy(pu->passwd, ""); return NULL; } pUser pchk = puHead;; while (pchk->next != NULL) { if (!strcmp(pchk->next->name, pu->name)) { printf("\t\t\t\t\tThe user name is exist.\n"); usleep(800000); return NULL; } pchk = pchk->next; } insert_user_tail(puHead, pu->name, pu->passwd, START_FUNDS); return pu; }
int main(){ int size; int i; printf("Please input the size of the vector to be transformed: "); size = getinput(); for (i=0; i<size;i++){ V[i] = rand()%100; } printf("Original vector:\n"); for (i= 0; i<size; i++) printf("%d\n", V[i]); printf("\n"); init_nbr(); moving(size); printf("Moving edge vector:\n"); for (i= 0; i<size; i++) printf("%d\n", V[i]); printf("\n"); }
int main(int argc, char * argv[]) { int sockfd; int newsockfd; char readbuf[SIZE]; char *read_request=malloc(MEMORYSIZE); long int port_num=0,default_port=9000; struct sigaction sa,sa_usr1; sa.sa_flags=0; sa.sa_handler=handle_signal; if(sigaction(SIGINT,&sa,NULL)==-1) exit(EXIT_FAILURE); if(sigaction(SIGTERM,&sa,NULL)==-1) exit(EXIT_FAILURE); sa_usr1.sa_flags=0; sa_usr1.sa_handler=handle_sigusr1; if(sigaction(SIGUSR1,&sa_usr1,NULL)==-1) exit(EXIT_FAILURE); printf("%d\n",getpid()); strategy=getinput(argc,argv,directory_name); printf("%d\n",portno); sockfd=startserver(portno); time(&server_start_time); //printf(ctime(&server_start_time)); if(strategy=='w') { //printf("Calling thread pool with %d %d\n",*thread_num,*buf_size); // active=0; dispatch_to_thread_pool(sockfd,directory_name); } else { while(active) { // check=1; newsockfd=accept(sockfd,(struct sockaddr*)NULL,NULL); if(newsockfd<0) { continue; } request_count++; if(newsockfd>0) dispatch_connection(read_request,strategy,newsockfd,directory_name); } } free(read_request); close(sockfd); printf("graceful exit\n"); return(0); }
int OK_ReplaceRDOnly( char *name ) { char reply[10]; printf( "The file '%s' is marked as read-only.\n" "Do you want it replaced (y/n)? ", name ); getinput( reply, 10 ); return( tolower( reply[0] ) == 'y' ); }
int OK_ToReplace( char *name ) /* 14-sep-91 */ { char reply[10]; printf( "A newer version of '%s' already exists.\n" "Do you want it replaced (y/n)? ", name ); getinput( reply, 10 ); return( tolower( reply[0] ) == 'y' ); }
int main(int argc, char *argv[]) { dispstr(0,"Welcome to the HMM program!\n"); #ifndef __STDC_IEC_559__ printf("WARNING: ISO/IEC 60559 not respected!\n"); #endif parse(argc, argv); dispstr(0,"Loading file...\n"); delays_mt input = getinput(); dispstr(0,"Sorting inputs...\n"); mysort(&input); //this offsets the timestamps to zero, and finds the min and max value of the delays. delay_mt ymin = input.delay[0]; delay_mt ymax = ymin; delay_mt current; time_mt tmin = input.time[0]; for(long long i = 0; i<input.length; i++) { input.time[i] = input.time[i] - tmin; current = input.delay[i]; if(current < ymin) ymin = current; if(current > ymax) ymax = current; } //now, we offset the delays to zero for(long long i = 0;i<input.length;i++) { //MINDELAY is an epsilon in order not to bug the algo input.delay[i] = input.delay[i] - ymin + MINDELAY; } struct params p; dispstr(0,"Initializing Markov parameters...\n"); initparams(&p, ymax); input.length = input.length/300; dispstr(0,"Training model...\n"); train(&p, &input, ymax); dispstr(0,"Writing results...\n"); write_results(&p); freeparams(&p); dispstr(0,"Done.\n"); return EXIT_SUCCESS; }
int main() { int c, len; char line[MAXLINE]; while((len = getinput(line, MAXLINE)) > 0) { reverse_print(line, len); } return 0; }
int ckkeywd(char *strval, char *keyword[], char *defstr, char *error, char *help, char *prompt) { int valid, i, n; char input[MAX_INPUT]; char defmesg[512]; char *ept; (void) sprintf(defmesg, "Please enter one of the following keywords: "); ept = defmesg + strlen(defmesg); for (i = 0; keyword[i]; ) { if (i) (void) strcat(ept, ", "); (void) strcat(ept, keyword[i++]); } (void) strcat(ept, ckquit ? ", q." : "."); if (!prompt) prompt = "Enter appropriate value"; start: putprmpt(stderr, prompt, keyword, defstr); if (getinput(input)) return (1); n = (int)strlen(input); if (n == 0) { if (defstr) { (void) strcpy(strval, defstr); return (0); } puterror(stderr, defmesg, error); goto start; } if (strcmp(input, "?") == 0) { puthelp(stderr, defmesg, help); goto start; } if (ckquit && (strcmp(input, "q") == 0)) { (void) strcpy(strval, input); return (3); } valid = 1; if (keyword) valid = !match(input, keyword); if (!valid) { puterror(stderr, defmesg, error); goto start; } (void) strcpy(strval, input); return (0); }
int main(void) { Matrix *matrix = input_matrix(); char *target = getinput(100, '\n', "\nInput the target word: "); search(matrix, matrix->rows, matrix->cols, target); free_matrix(matrix); return 0; }
int main() { int array[LENGTH]; int length; length = getinput(array); printdata(array, length, 0); sort(array, length); return(0); }
void Game::play(sf::RenderWindow* window) //This should be caled in MAIN in a loop while the app is open. { cout<<playerLives<< endl; getinput(); while(!paused) { draw(window); update(window); } }
/*main: Main Shell, calls parseinput until notified to exit */ int main(int argc, char *argv[]) { char buf[BUF_SIZE]; head = NULL; history_count = 0; history_head = NULL; history_tail = NULL; do { getinput(buf, sizeof(buf)); } while (parseinput(buf) == 1); return 0; }
int main(int argc, char *argv[]){ /* defines the wireless device that will be used */ if (argc < 2){ printf("enter wireless interface as argument, --help for help.\n"); return(0); } if ((argv[1][0] == '-' && argv[1][1] == 'h') || (argv[1][0] == '-' && argv[1][1] == '-' && argv[1][2] == 'h')){ print_help(); return 0; } dev = argv[1]; /* defines the nickname that will be send with your messages */ fputs("nick (max 10 char): ", stdout); fflush(stdout); fgets(nick, 10, stdin); for (i = 0; i < sizeof(nick); i++){ if (nick[i] == '\n'){ nick[i] = '\0'; } } /* makes sure no random garbage is stored in the array */ for (i = 99; i >= 0; i--){ text[i][0] = 0; } /* this function is a callback for the threads in threads.c */ void threads(int thread_choice){ switch (thread_choice){ case 1: /* listens for incoming messages */ get_beaconpacket(); break; case 2: /* takes care of the sending and displaying of messages */ fputs("enter message: ", stdout); fflush(stdout); while (1){ getinput(); } break; default: printf("ERROR: non valid input. Check the (*f)(x) in threads.c\n"); } } /* initiates the threading */ thread_init(threads); }
static void cmd_name(struct disklabel *lp, char *s, int fd) { char line[BUFSIZ]; int i; i = getinput(line, "Label name [%.*s]: ", (int) sizeof(lp->d_packname), lp->d_packname); if (i <= 0) return; (void) strncpy(lp->d_packname, line, sizeof(lp->d_packname)); }
int main(int argc, Char *argv[]) { /* main program */ long i; #ifdef MAC argc = 1; /* macsetup("Contml",""); */ argv[0] = "Contml"; #endif init(argc, argv); emboss_getoptions("fcontml", argc, argv); progname = argv[0]; ibmpc = IBMCRT; ansi = ANSICRT; firstset = true; doinit(); for (ith = 1; ith <= datasets; ith++) { getinput(); if (ith == 1) firstset = false; if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n\n", ith); if (progress) printf("\nData set # %ld:\n", ith); } for (jumb = 1; jumb <= njumble; jumb++) maketree(); if (usertree) for (i = 0; i < MAXSHIMOTREES; i++) free(l0gf[i]); } FClose(outfile); FClose(outtree); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("\nDone.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif ajPhyloFreqDel(&phylofreq); ajPhyloTreeDelarray(&phylotrees); ajFileClose(&embossoutfile); ajFileClose(&embossouttree); embExit(); return 0; }
/* 定义一个包括年、月、日的结构体变量,当输入年、 月、日数据后,计算该日是这一年中的第几天。 */ int main(void) { struct tag_date mydate; int ndays; getinput(&mydate); ndays = daysofyear(mydate); output(ndays); return 0; }
int main(void) { int iyear, imonth, idate; int idays; getinput(&iyear, &imonth, &idate); idays = dayofyear(iyear, imonth, idate); output(idays); return 0; }
int main(void) { int counter; int maxval=-1; datastruct* svalues[200]; for(counter=0;counter<200;counter++) { svalues[counter]=getinput(); if(!svalues[counter]) break; maxval=counter; } printmessage(svalues[maxval/2]); return 0; }
int main(){ char s[MAXLENGTH]; char t[MAXLENGTH]; getinput(t, MAXLENGTH); printf("Original input: %s\n", t); escape(s, t); printf("Escaped input: %s\n", s); unescape(s, t); printf("Un-escaped input: %s\n", s); }
static int get_bytes(FILE *fp, unsigned int n, char **ptr) /* for reading numeric input */ { char *s; register char *cp; int c1, c2; cp = s = malloc (n); if (!cp) return 0; while (n > 0) { if ((c1 = getinput (fp)) == EOF || c1 == '\n' || (c2 = getinput (fp)) == EOF || c2 == '\n') { free (s); return 0; } *cp = (char) ((hexvalues[c1] * 16) + hexvalues[c2]); cp++; n--; } *ptr = s; return 1; }
int main(int argc, Char *argv[]) { /* main program */ long i; #ifdef MAC argc = 1; /* macsetup("Contml",""); */ argv[0] = "Contml"; #endif init(argc, argv); progname = argv[0]; openfile(&infile,INFILE,"input file", "r",argv[0],infilename); openfile(&outfile,OUTFILE,"output file", "w",argv[0],outfilename); ibmpc = IBMCRT; ansi = ANSICRT; mulsets = false; firstset = true; datasets = 1; doinit(); if (trout) openfile(&outtree,OUTTREE,"output tree file", "w",argv[0],outtreename); for (ith = 1; ith <= datasets; ith++) { getinput(); if (ith == 1) firstset = false; if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n\n", ith); if (progress) printf("\nData set # %ld:\n", ith); } for (jumb = 1; jumb <= njumble; jumb++) maketree(); if (usertree) for (i = 0; i < MAXSHIMOTREES; i++) free(l0gf[i]); } FClose(outfile); FClose(outtree); FClose(infile); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("\nDone.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif return 0; }
int main() { int i; struct jobs * discard; getinput(); printf("\nWhich Scheduling scheme do you want to use?\n\n1.Preemptive\n2.Non-Preemptive\n\nEnter your choice : "); scanf("%d", &choice); printf("\n"); if(choice!=1 && choice !=2) { printf("invalid choice! Exiting...\n"); return 1; } while(Pri_Q_size==0) //simply loop until any process enters ready queue { ++time; checkjobs(); } while(active!=NULL || !queue_empty(IOhead)||Pri_Q_size>0) //enter if some process exists either in CPU(active) // or in ready queue or in I/Oqueue { IOdec(); //decrement IO burst if(active==NULL) { active=Pri_Q_remove(); //if no process is active, then insert the topmost process //in the ready queue into the CPU and reset the process time counter. processtime=0; } CPUdec(); //decrement CPU burst of active process ++time; checkjobs(); //check for newly arrived jobs } printf("\n\n"); return 0; }
void interact(struct disklabel *lp, int fd) { char line[BUFSIZ]; puts("Enter '?' for help"); for (;;) { int i = getinput(line, "partition>"); if (i == -1) return; if (i == 0) continue; if (runcmd(lp, line, fd) == -1) return; } }
/* Takes user input, checks value of card, updates the count and repeats until the user inputs X*/ void card_loop() { char card[3]; int val = 0; int count = 0; while(card[0] != 'X') { getinput(card); val = card_value(card); if (check_valid_value(val)){ puts("I don't understand that value!"); } else { print_value(val); update_count(val,&count); } } }