int main(void) { SkipListPtr list; double usec, usec2, usec3, usec4; list = N(SLCreate)(); printf( "list at %p\n", list); print(list); printf("\n==============================\n\n"); N(SLInsert)(list, 123, NULL); N(SLInsert)(list, 213, NULL); N(SLInsert)(list, 50, NULL); print(list); printf("\n==============================\n\n"); print_neighbors(list, 0); print_neighbors(list, 50); print_neighbors(list, 51); print_neighbors(list, 123); print_neighbors(list, 200); print_neighbors(list, 213); print_neighbors(list, 256); printf("\n==============================\n\n"); N(SLDelete)(list, 50); print(list); printf("\n==============================\n\n"); N(SLDump)(list); N(SLDestroy)(list); printf("\n==============================\n\n"); usec = do_time(100, 10000); usec2 = do_time(1000, 500); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 1000.0/100.0, usec2 / usec); usec3 = do_time(10000, 50); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 10000.0/100.0, usec3 / usec); usec4 = do_time(100000, 4); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 100000.0/100.0, usec4 / usec); return 0; }
static void do_cmd(int client, char *buf) { char *cp = buf+strlen(buf)-1; while ((*cp == '\n') || (*cp == '\r')) { *cp-- = '\0'; // Remove trailing terminators } printf("Command: %s\n", buf); if (strncmp(buf, "ls", 2) == 0) { do_ls(client, buf); } else if (strncmp(buf, "show_all", 8) == 0) { do_show_all(client, buf); } else if (strncmp(buf, "show", 4) == 0) { do_show(client, buf); } else if (strncmp(buf, "time", 4) == 0) { do_time(client, buf); } else if (strncmp(buf, "get", 3) == 0) { do_get(client, buf); } else if (strncmp(buf, "rm", 2) == 0) { do_rm(client, buf); } else { fdprintf(client, "Unknown command: %s\n", buf); } }
void do_times(const T x[], int nloop, Teuchos::Array<double>& times) { int i = 0; times[i++] = do_time(x, nloop, F<T,1>()); times[i++] = do_time(x, nloop, F<T,2>()); times[i++] = do_time(x, nloop, F<T,3>()); times[i++] = do_time(x, nloop, F<T,4>()); times[i++] = do_time(x, nloop, F<T,5>()); times[i++] = do_time(x, nloop, F<T,10>()); times[i++] = do_time(x, nloop, F<T,15>()); times[i++] = do_time(x, nloop, F<T,20>()); }
void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi) { timelib_sll res = 0; do_adjust_relative(time); do_adjust_special(time); res += do_years(time->y); res += do_months(time->m, time->y); res += do_days(time->d); res += do_time(time->h, time->i, time->s); time->sse = res; res += do_adjust_timezone(time, tzi); time->sse = res; time->sse_uptodate = 1; }
void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi) { timelib_sll res = 0; do_adjust_special_early(time); do_adjust_relative(time); do_adjust_special(time); res += do_years(time->y); res += do_months(time->m, time->y); res += do_days(time->d); res += do_time(time->h, time->i, time->s); time->sse = res; res += do_adjust_timezone(time, tzi); time->sse = res; time->sse_uptodate = 1; time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = time->relative.first_last_day_of = 0; }
int main( int argc, char **argv ) { int i; while ( (i = getopt( argc, argv, "b:D:H:w:f:n:i:t:r:R:" )) != EOF ) { switch( i ) { case 'b': /* base DN of a tree of user DNs */ base = strdup( optarg ); break; case 'D': binder = strdup( optarg ); break; case 'H': /* the server uri */ uri = strdup( optarg ); break; case 'w': pass = strdup( optarg ); break; case 't': /* the duration to run */ if ( lutil_atoi( &tdur, optarg ) != 0 ) { usage( argv[0] ); } break; case 'i': /* the time interval */ if ( lutil_atoi( &interval, optarg ) != 0 ) { usage( argv[0] ); } break; case 'r': /* the uid range */ if ( sscanf(optarg, "%d:%d", &r1lo, &r1hi) != 2 ) { usage( argv[0] ); } break; case 'R': /* percentage:2nd uid range */ if ( sscanf(optarg, "%d:%d:%d", &r2per, &r2lo, &r2hi) != 3 ) { usage( argv[0] ); } break; case 'f': filter = optarg; break; case 'n': if ( lutil_atoi( &threads, optarg ) != 0 || threads < 1 ) { usage( argv[0] ); } break; default: usage( argv[0] ); break; } } if ( tdur == 0 || r1hi <= r1lo ) usage( argv[0] ); r1per = 100 - r2per; if ( r1per < 1 ) usage( argv[0] ); r1binds = calloc( threads*4, sizeof( int )); r2binds = r1binds + threads; r1old = (int *)r2binds + threads; r2old = r1old + threads; do_time( ); exit( EXIT_SUCCESS ); }
int do_redirection(char *input) //redircetion { char *command_path,*real_command; char *out_filename,*in_filename; char **parsed_command; int len,status,i,j,k,back=0,fd_out=0,fd_in=0,flag_out=0,flag_in=0; pid_t pid; back=is_back(input); len=strlen(input); out_filename=(char *)malloc((len+1)*(sizeof(char))); in_filename=(char *)malloc((len+1)*(sizeof(char))); real_command=(char *)malloc((len+1)*(sizeof(char))); for(i=0; i<len; i++) { if (input[i]!='>' && input[i]!='<') real_command[i]=input[i]; else { if (input[i]=='>') flag_out=1; if (input[i]=='<') flag_in=1; break; } } real_command[i]='\0'; i++; if(flag_out==1 && input[i]=='>') { flag_out=2; i++; } else if (flag_in==1 && input[i]=='<') { flag_in=2; i++; } while ((input[i]==' ' || input[i]==' ') && i<len) i++; j=0; out_filename[0]='\0'; in_filename[0]='\0'; if(flag_out>0) { while (i<=len) { if(input[i]=='<') { out_filename[j]='\0'; break; } out_filename[j]=input[i]; i++; j++; } } if(flag_in>0) { while (i<=len) { if (input[i]=='>') { in_filename[j]='\0'; break; } in_filename[j]=input[i]; i++; j++; } } if (i<len) { j=0; if (flag_out>0 && input[i]=='<') { i++; flag_in=1; if(input[i]=='>') { flag_in=2; i++; } while ((input[i]==' ' || input[i]==' ') && i<len) i++; while (i<=len) { in_filename[j]=input[i]; i++; j++; } } else if (flag_in>0 && input[i]=='>') { i++; flag_out=1; if(input[i]=='>') { flag_out=2; i++; } while ((input[i]==' ' || input[i]==' ') && i<len) i++; while (i<=len) { out_filename[j]=input[i]; i++; j++; } } else { fprintf(stderr,"ERROR!can't find the file!\n"); return -1; } } //for debug /*printf("real_command: %s\n",real_command); printf("out_filename: %s\n",out_filename); printf("in_filename: %s\n",in_filename);*/ k=number(real_command); parsed_command=parse(real_command); if(strcmp(parsed_command[0],"cd")==0 || strcmp(parsed_command[0], "echo") == 0 || strcmp(parsed_command[0], "viewproc") == 0 || strcmp(parsed_command[0], "time")==0) //build-in functions { if(strcmp(parsed_command[0], "cd") == 0) //cd { do_cd(parsed_command); } else if(strcmp(parsed_command[0], "echo") == 0) //echo { if (pid=fork() == 0) { if(flag_out==1) fd_out = open(out_filename,O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); if(flag_out==2) fd_out = open(out_filename, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR ); if(fd_out==-1) { printf("Open out %s error \n", out_filename); return -1; } if(flag_out>0) { if(dup2(fd_out, STDOUT_FILENO) == -1) { fprintf(stderr,"Redirect Standard Out Error !\n"); exit(1); } } do_echo(real_command); exit(1); } else { //parent if(back==0) pid=waitpid(pid, &status, 0); else pid=waitpid(pid, &status, WNOHANG); } } else if(strcmp(parsed_command[0], "viewproc") == 0) //viewproc { if (pid=fork() == 0) { if(flag_out==1) fd_out = open(out_filename,O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); if(flag_out==2) fd_out = open(out_filename, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR ); if(fd_out==-1) { printf("Open out %s error \n", out_filename); return -1; } if(flag_out>0) { if(dup2(fd_out, STDOUT_FILENO) == -1) { fprintf(stderr,"Redirect Standard Out Error !\n"); exit(1); } } do_viewproc(parsed_command[1]); close(flag_out); exit(1); } else { //parent if(back==0) pid=waitpid(pid, &status, 0); else pid=waitpid(pid, &status, WNOHANG); } } else if(strcmp(parsed_command[0], "time") == 0) //time { gettimeofday(&tpstart,0); do_time(real_command); } for(i=0;i<k;i++) free(parsed_command[i]); free(parsed_command); free(real_command); return 1; } command_path=is_file_exist(parsed_command[0]); if(command_path==NULL) //can't find the order { fprintf(stderr,"This is command is not founded ?!\n"); // free space for(i=0;i<k;i++) free(parsed_command[i]); free(parsed_command); free(real_command); return -1; } if((pid = fork()) == 0) { if(flag_out==1) fd_out = open(out_filename,O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); if(flag_out==2) fd_out = open(out_filename, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR ); if(flag_in==1) fd_in = open(in_filename, O_RDONLY, S_IRUSR|S_IWUSR ); if(flag_in==2) fd_in = open(in_filename, O_RDONLY, S_IRUSR|S_IWUSR ); if(fd_out==-1) { printf("Open out %s error \n", out_filename); return -1; } if(fd_in==-1) { fprintf(stderr,"Open in %s error \n", in_filename); return -1; } if(flag_out>0) { if(dup2(fd_out, STDOUT_FILENO) == -1) { fprintf(stderr,"Redirect Standard Out Error !\n"); exit(1); } } if(flag_in>0) { if (dup2(fd_in,STDIN_FILENO)==-1) { fprintf(stderr,"Redirect Standard Out Error !\n"); exit(1); } } execv(command_path,parsed_command); exit(1); } else { //parent if(back==0) pid=waitpid(pid, &status, 0); else pid=waitpid(pid, &status, WNOHANG); } //free space free(out_filename); free(in_filename); free(command_path); for(i=0;i<k;i++) free(parsed_command[i]); free(parsed_command); return 1; }
static void print_proc(void) { char tty[16]; snprintf(tty, sizeof tty, "%3d,%-3d", (P_tty >> 8) & 0xff, P_tty & 0xff); switch (ps_format) { case 0: printf("%5d %s %s", P_pid, tty, do_time(P_utime + P_stime)); break; case 'o': printf("%d\n", P_pid); return; /* don't want the command */ case 'l': printf("%03x %c %5d %5d %5d - %3d %3d - " "%5ld %06x %s %s", (unsigned)P_flags & 0x777, P_state, P_euid, P_pid, P_ppid, (int)P_priority, (int)P_nice, P_vsize >> (page_shift - 10), (unsigned)(P_wchan & 0xffffff), tty, do_time(P_utime + P_stime) ); break; case 'f': printf("%5d %5d %5d - - %s %s", P_euid, P_pid, P_ppid, tty, do_time(P_utime + P_stime) ); break; case 'j': printf("%5d %5d %5d %s %s", P_pid, P_pgrp, P_session, tty, do_time(P_utime + P_stime) ); break; case 'u' | 0x80: printf("%5d %5d - - %5ld %5ld %s %c - %s", P_euid, P_pid, P_vsize, P_rss, tty, P_state, do_time(P_utime + P_stime) ); break; case 'v' | 0x80: printf("%5d %s %c %s %6d - - %5d -", P_pid, tty, P_state, do_time(P_utime + P_stime), (int)P_maj_flt, (int)P_rss); break; case 'j' | 0x80: printf("%5d %5d %5d %5d %s %5d %c %5d %s", P_ppid, P_pid, P_pgrp, P_session, tty, P_tpgid, P_state, P_euid, do_time(P_utime + P_stime) ); break; case 'l' | 0x80: printf("%03x %5d %5d %5d %3d %3d " "%5ld %4ld %06x %c %s %s", (unsigned)P_flags & 0x777, P_euid, P_pid, P_ppid, (int)P_priority, (int)P_nice, P_vsize, P_rss, (unsigned)(P_wchan & 0xffffff), P_state, tty, do_time(P_utime + P_stime) ); break; default: break; } if (show_args) printf(" [%s]\n", P_cmd); else printf(" %s\n", P_cmd); }