int main() { print_time(); return 0; }
int main(int argc, char * argv[]) { Dictionary dict; Sentence sent; char *dictionary_file=NULL; char *post_process_knowledge_file=NULL; char *constituent_knowledge_file=NULL; char *affix_file=NULL; int pp_on=TRUE; int af_on=TRUE; int cons_on=TRUE; int num_linkages, i; char input_string[MAXINPUT]; Label label = NO_LABEL; int parsing_space_leaked, reported_leak, dictionary_and_option_space; i = 1; if ((argc > 1) && (argv[1][0] != '-')) { /* the dictionary is the first argument if it doesn't begin with "-" */ dictionary_file = argv[1]; i++; } for (; i<argc; i++) { if (argv[i][0] == '-') { if (strcmp("-pp", argv[i])==0) { if ((post_process_knowledge_file != NULL) || (i+1 == argc)) print_usage(argv[0]); post_process_knowledge_file = argv[i+1]; i++; } else if (strcmp("-c", argv[i])==0) { if ((constituent_knowledge_file != NULL) || (i+1 == argc)) print_usage(argv[0]); constituent_knowledge_file = argv[i+1]; i++; } else if (strcmp("-a", argv[i])==0) { if ((affix_file != NULL) || (i+1 == argc)) print_usage(argv[0]); affix_file = argv[i+1]; i++; } else if (strcmp("-ppoff", argv[i])==0) { pp_on = FALSE; } else if (strcmp("-coff", argv[i])==0) { cons_on = FALSE; } else if (strcmp("-aoff", argv[i])==0) { af_on = FALSE; } else if (strcmp("-batch", argv[i])==0) { } else if (strncmp("-!", argv[i],2)==0) { } else { print_usage(argv[0]); } } else { print_usage(argv[0]); } } if (!pp_on && post_process_knowledge_file != NULL) print_usage(argv[0]); if (dictionary_file == NULL) { dictionary_file = "4.0.dict"; fprintf(stderr, "No dictionary file specified. Using %s.\n", dictionary_file); } if (af_on && affix_file == NULL) { affix_file = "4.0.affix"; fprintf(stderr, "No affix file specified. Using %s.\n", affix_file); } if (pp_on && post_process_knowledge_file == NULL) { post_process_knowledge_file = "4.0.knowledge"; fprintf(stderr, "No post process knowledge file specified. Using %s.\n", post_process_knowledge_file); } if (cons_on && constituent_knowledge_file == NULL) { constituent_knowledge_file = "4.0.constituent-knowledge"; fprintf(stderr, "No constituent knowledge file specified. Using %s.\n", constituent_knowledge_file); } opts = parse_options_create(); if (opts == NULL) { fprintf(stderr, "%s\n", lperrmsg); exit(-1); } panic_parse_opts = parse_options_create(); if (panic_parse_opts == NULL) { fprintf(stderr, "%s\n", lperrmsg); exit(-1); } setup_panic_parse_options(panic_parse_opts); parse_options_set_max_sentence_length(opts, 70); parse_options_set_panic_mode(opts, TRUE); parse_options_set_max_parse_time(opts, 30); parse_options_set_linkage_limit(opts, 1000); parse_options_set_short_length(opts, 10); dict = dictionary_create(dictionary_file, post_process_knowledge_file, constituent_knowledge_file, affix_file); if (dict == NULL) { fprintf(stderr, "%s\n", lperrmsg); exit(-1); } /* process the command line like commands */ for (i=1; i<argc; i++) { if ((strcmp("-pp", argv[i])==0) || (strcmp("-c", argv[i])==0) || (strcmp("-a", argv[i])==0)) { i++; } else if ((argv[i][0] == '-') && (strcmp("-ppoff", argv[i])!=0) && (argv[i][0] == '-') && (strcmp("-coff", argv[i])!=0) && (argv[i][0] == '-') && (strcmp("-aoff", argv[i])!=0)) { issue_special_command(argv[i]+1, opts, dict); } } dictionary_and_option_space = space_in_use; reported_leak = external_space_in_use = 0; verbosity = parse_options_get_verbosity(opts); while (fget_input_string(input_string, stdin, stdout, opts)) { if (space_in_use != dictionary_and_option_space + reported_leak) { fprintf(stderr, "Warning: %d bytes of space leaked.\n", space_in_use-dictionary_and_option_space-reported_leak); reported_leak = space_in_use - dictionary_and_option_space; } if ((strcmp(input_string, "quit\n")==0) || (strcmp(input_string, "exit\n")==0)) break; if (special_command(input_string, dict)) continue; if (parse_options_get_echo_on(opts)) { printf("%s", input_string); } if (parse_options_get_batch_mode(opts)) { label = strip_off_label(input_string); } sent = sentence_create(input_string, dict); if (sent == NULL) { if (verbosity > 0) fprintf(stderr, "%s\n", lperrmsg); if (lperrno != NOTINDICT) exit(-1); else continue; } if (sentence_length(sent) > parse_options_get_max_sentence_length(opts)) { sentence_delete(sent); if (verbosity > 0) { fprintf(stdout, "Sentence length (%d words) exceeds maximum allowable (%d words)\n", sentence_length(sent), parse_options_get_max_sentence_length(opts)); } continue; } /* First parse with cost 0 or 1 and no null links */ parse_options_set_disjunct_cost(opts, 2); parse_options_set_min_null_count(opts, 0); parse_options_set_max_null_count(opts, 0); parse_options_reset_resources(opts); num_linkages = sentence_parse(sent, opts); /* Now parse with null links */ if ((num_linkages == 0) && (!parse_options_get_batch_mode(opts))) { if (verbosity > 0) fprintf(stdout, "No complete linkages found.\n"); if (parse_options_get_allow_null(opts)) { parse_options_set_min_null_count(opts, 1); parse_options_set_max_null_count(opts, sentence_length(sent)); num_linkages = sentence_parse(sent, opts); } } if (parse_options_timer_expired(opts)) { if (verbosity > 0) fprintf(stdout, "Timer is expired!\n"); } if (parse_options_memory_exhausted(opts)) { if (verbosity > 0) fprintf(stdout, "Memory is exhausted!\n"); } if ((num_linkages == 0) && parse_options_resources_exhausted(opts) && parse_options_get_panic_mode(opts)) { print_total_time(opts); if (verbosity > 0) fprintf(stdout, "Entering \"panic\" mode...\n"); parse_options_reset_resources(panic_parse_opts); parse_options_set_verbosity(panic_parse_opts, verbosity); num_linkages = sentence_parse(sent, panic_parse_opts); if (parse_options_timer_expired(panic_parse_opts)) { if (verbosity > 0) fprintf(stdout, "Timer is expired!\n"); } } print_total_time(opts); if (parse_options_get_batch_mode(opts)) { batch_process_some_linkages(label, sent, opts); } else { process_some_linkages(sent, opts); } sentence_delete(sent); if (external_space_in_use != 0) { fprintf(stderr, "Warning: %d bytes of external space leaked.\n", external_space_in_use); } } if (parse_options_get_batch_mode(opts)) { print_time(opts, "Total"); fprintf(stderr, "%d error%s.\n", batch_errors, (batch_errors==1) ? "" : "s"); } parsing_space_leaked = space_in_use - dictionary_and_option_space; if (parsing_space_leaked != 0) { fprintf(stderr, "Warning: %d bytes of space leaked during parsing.\n", parsing_space_leaked); } parse_options_delete(panic_parse_opts); parse_options_delete(opts); dictionary_delete(dict); if (space_in_use != parsing_space_leaked) { fprintf(stderr, "Warning: %d bytes of dictionary and option space leaked.\n", space_in_use - parsing_space_leaked); } else if (parsing_space_leaked == 0) { fprintf(stderr, "Good news: no space leaked.\n"); } if (external_space_in_use != 0) { fprintf(stderr, "Warning: %d bytes of external space leaked.\n", external_space_in_use); } return 0; }
int main(int argc, char **argv) { enum state state; unsigned char command; struct timeval tval; struct packet pkt; /* Open a socket and start listening to a scpefied port */ open_udp_socket(); srand(time(NULL)); /* Startup: */ build_send_packet(BROADCAST, CMD_MASTERREQ, 0); /* Search for a master */ change_state(&state, STATE_STARTUP, &tval, NULL); for(;;) { struct timeval curtime; gettimeofday(&curtime, NULL); printf(" "); print_time(&curtime); /*printf(" TIME: %10d sec %10d usec\n", (unsigned int)curtime.tv_sec, (unsigned int)curtime.tv_usec);*/ recv_msg(&pkt, &tval); command = pkt.type; //printf("Command received = %d\n", command); switch(state | command) { /* STARTUP */ case(STATE_STARTUP | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_MASTERUP, 0); change_state(&state, STATE_MASTER, &tval, &master_timeout); break; case(STATE_STARTUP | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_SLAVEUP, 0); // no break; case(STATE_STARTUP | CMD_MASTERREQ): case(STATE_STARTUP | CMD_MASTERACK): case(STATE_STARTUP | CMD_ELECTION): change_state(&state, STATE_SLAVE, &tval, NULL); break; /* MASTER */ /* Launch a new thread and process separately? Prevents loss of messages */ case(STATE_MASTER | CMD_TIMEOUT): /* Does the Master needs to send his clock? */ build_send_packet(BROADCAST, CMD_CLOCKREQ, 1); //change_state(&state, STATE_MASTER, &tval, MASTER_TIMEOUT); /* Change to an intermediate state in order to wait for all slaves * to send their clocks. After the MASTER_ADJTIME_TIMEOUT no more clock * packets will be accepted and the "slow" slaves, if any, won't * be synchronized*/ change_state(&state, STATE_MASTER_ADJTIME, &tval, &master_adjtime_timeout); /* Possibly new thread? Non blocking function...*/ adjust_master_prepare(); break; case(STATE_MASTER | CMD_MASTERREQ): build_send_packet(pkt.ip, CMD_MASTERACK, 0); break; case(STATE_MASTER | CMD_QUIT): build_send_packet(pkt.ip, CMD_ACK, 0); change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_MASTER | CMD_ELECTION): case(STATE_MASTER | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_QUIT, 0); break; /* MASTER_ADJTIME */ case(STATE_MASTER_ADJTIME | CMD_CLOCKREQ_RESPONSE): /* Got time from client */ adjust_master_addslave(pkt.ip, &pkt.time); break; case(STATE_MASTER_ADJTIME | CMD_TIMEOUT): /* Calculate avg clocks and send to each slave his correction */ /* Restart the synchronization timer */ change_state(&state, STATE_MASTER, &tval, &master_timeout); adjust_master_calcandsend(); break; /* SLAVE */ case(STATE_SLAVE | CMD_CLOCKREQ): /* Send clock packet to master and change to an intermediate state * in order to wait for a synch packet */ build_send_packet(pkt.ip, CMD_CLOCKREQ_RESPONSE, 1); change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_SLAVE | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_ELECTION, 0); change_state(&state, STATE_CANDIDATE, &tval, &candidate_timeout); break; case(STATE_SLAVE | CMD_MASTERUP): build_send_packet(BROADCAST, CMD_SLAVEUP, 0); break; case(STATE_SLAVE | CMD_ELECTION): build_send_packet(pkt.ip, CMD_ACCEPT, 0); change_state(&state, STATE_ACCEPT, &tval, &accept_timeout); break; case(STATE_SLAVE | CMD_CLOCKSYNC): /* Receive packet from master, adjust local time and return to * your rightful state (slave of course... =])*/ adjust_slave_clock(&pkt.time); change_state(&state, STATE_SLAVE, &tval, NULL); break; /* CANDIDATE */ case(STATE_CANDIDATE | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_MASTERUP, 0); change_state(&state, STATE_MASTER, &tval, &master_timeout); break; case(STATE_CANDIDATE | CMD_ELECTION): build_send_packet(pkt.ip, CMD_REFUSE, 0); break; case(STATE_CANDIDATE | CMD_ACCEPT): build_send_packet(pkt.ip, CMD_ACK, 0); break; case(STATE_CANDIDATE | CMD_QUIT): case(STATE_CANDIDATE | CMD_REFUSE): build_send_packet(pkt.ip, CMD_ACK, 0); //no break case(STATE_CANDIDATE | CMD_MASTERREQ): change_state(&state, STATE_SLAVE, &tval, NULL); break; /* ACCEPT */ case(STATE_ACCEPT | CMD_TIMEOUT): change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_ACCEPT | CMD_ELECTION): build_send_packet(pkt.ip, CMD_REFUSE, 0); break; case(STATE_ACCEPT | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_SLAVEUP, 0); break; } } return 0; }
rtems_task Task_1( rtems_task_argument argument ) { rtems_event_set eventout; rtems_time_of_day time; rtems_status_code status; uint32_t index; puts( "TA1 - rtems_event_send - send RTEMS_EVENT_16 to TA2" ); status = rtems_event_send( Task_id[ 2 ], RTEMS_EVENT_16 ); directive_failed( status, "rtems_event_send" ); puts( "TA1 - rtems_event_receive - waiting forever on " "RTEMS_EVENT_14 and RTEMS_EVENT_15" ); status = rtems_event_receive( RTEMS_EVENT_14 | RTEMS_EVENT_15, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive" ); printf( "TA1 - RTEMS_EVENT_14 and RTEMS_EVENT_15 received - " "eventout => %08" PRIxrtems_event_set "\n", eventout ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_18 to TA2" ); status = rtems_event_send( Task_id[ 2 ], RTEMS_EVENT_18 ); directive_failed( status, "rtems_event_send" ); puts( "TA1 - rtems_event_receive - waiting with 10 second timeout " "on RTEMS_EVENT_14" ); status = rtems_event_receive( RTEMS_EVENT_14, RTEMS_DEFAULT_OPTIONS, 10 * rtems_clock_get_ticks_per_second(), &eventout ); directive_failed( status, "rtems_event_receive" ); printf( "TA1 - RTEMS_EVENT_14 received - eventout => " "%08" PRIxrtems_event_set "\n", eventout ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_19 to TA2" ); status = rtems_event_send( Task_id[ 2 ], RTEMS_EVENT_19 ); directive_failed( status, "rtems_event_send" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, "\n" ); rtems_test_pause(); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_18 to self after 5 seconds"); status = rtems_timer_fire_after( Timer_id[ 1 ], 5 * rtems_clock_get_ticks_per_second(), TA1_send_18_to_self_5_seconds, NULL ); directive_failed( status, "rtems_timer_fire_after 5 seconds" ); puts( "TA1 - rtems_event_receive - waiting forever on RTEMS_EVENT_18" ); status = rtems_event_receive( RTEMS_EVENT_18, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive of 18" ); printf( "TA1 - RTEMS_EVENT_18 received - eventout => %08" PRIxrtems_event_set "\n", eventout ); status = rtems_clock_get_tod( &time ); directive_failed( status, "TA1 rtems_clock_get_tod" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, "\n" ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_3 to self" ); status = rtems_event_send( RTEMS_SELF, RTEMS_EVENT_3 ); directive_failed( status, "rtems_event_send" ); puts( "TA1 - rtems_event_receive - RTEMS_EVENT_3 or " "RTEMS_EVENT_22 - NO_WAIT and ANY" ); status = rtems_event_receive( RTEMS_EVENT_3 | RTEMS_EVENT_22, RTEMS_NO_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive of 3 and 22" ); printf( "TA1 - RTEMS_EVENT_3 received - eventout => %08" PRIxrtems_event_set "\n", eventout ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_4 to self" ); status = rtems_event_send( RTEMS_SELF, RTEMS_EVENT_4 ); directive_failed( status, "rtems_event_send" ); puts ( "TA1 - rtems_event_receive - RTEMS_EVENT_4 or " "RTEMS_EVENT_5 - forever and ANY" ); status = rtems_event_receive( RTEMS_EVENT_4 | RTEMS_EVENT_5, RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive" ); printf( "TA1 - RTEMS_EVENT_4 received - eventout => %08" PRIxrtems_event_set "\n", eventout ); rtems_test_pause(); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_18 to self after 5 seconds"); status = rtems_timer_fire_after( Timer_id[ 1 ], 5 * rtems_clock_get_ticks_per_second(), TA1_send_18_to_self_5_seconds, NULL ); directive_failed( status, "rtems_timer_fire_after 5 seconds" ); puts( "TA1 - rtems_timer_cancel - cancelling timer for event RTEMS_EVENT_18"); status = rtems_timer_cancel( Timer_id[ 1 ] ); directive_failed( status, "rtems_timer_cancel" ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_8 to self after 60 seconds"); status = rtems_timer_fire_after( Timer_id[ 1 ], 60 * rtems_clock_get_ticks_per_second(), TA1_send_8_to_self_60_seconds, NULL ); directive_failed( status, "rtems_timer_fire_after 60 seconds" ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_9 to self after 60 seconds"); status = rtems_timer_fire_after( Timer_id[ 2 ], 60 * rtems_clock_get_ticks_per_second(), TA1_send_9_to_self_60_seconds, NULL ); directive_failed( status, "rtems_timer_fire_after 60 seconds" ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_10 to self after 60 seconds" ); status = rtems_timer_fire_after( Timer_id[ 3 ], 60 * rtems_clock_get_ticks_per_second(), TA1_send_10_to_self, NULL ); directive_failed( status, "rtems_timer_fire_after 60 seconds" ); puts( "TA1 - rtems_timer_cancel - cancelling timer for event RTEMS_EVENT_8" ); status = rtems_timer_cancel( Timer_id[ 1 ] ); directive_failed( status, "rtems_timer_cancel" ); build_time( &time, 2, 12, 1988, 8, 15, 0, 0 ); print_time( "TA1 - rtems_clock_set - ", &time, "\n" ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); puts( "TA1 - rtems_event_send - send RTEMS_EVENT_1 every second" ); status = rtems_timer_fire_after( Timer_id[ 1 ], rtems_clock_get_ticks_per_second(), TA1_send_1_to_self_every_second, NULL ); directive_failed( status, "rtems_timer_fire_after 1 second" ); for ( index = 0; index < 3; index++ ) { status = rtems_event_receive( RTEMS_EVENT_1, RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); printf( "TA1 - RTEMS_EVENT_1 received - eventout => %08" PRIxrtems_event_set " - ", eventout ); print_time( "at ", &time, "\n" ); if ( index < 2 ) { status = rtems_timer_reset( Timer_id[ 1 ] ); directive_failed( status, "rtems_timer_reset" ); }; } puts( "TA1 - rtems_timer_cancel - cancelling timer for event RTEMS_EVENT_1" ); status = rtems_timer_cancel( Timer_id[ 1 ] ); directive_failed( status, "rtems_timer_cancel" ); rtems_test_pause(); time.day = 13; puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 1 day" ); status = rtems_timer_fire_when( Timer_id[ 1 ], &time, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 1 day" ); time.hour = 7; puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 1 day" ); status = rtems_timer_fire_when( Timer_id[ 2 ], &time, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 1 day" ); time.hour = 8; /* so code below has correct time/date */ time.day = 14; puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 2 days" ); status = rtems_timer_fire_when( Timer_id[ 3 ], &time, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 2 days" ); puts("TA1 - rtems_timer_cancel - cancelling RTEMS_EVENT_11 to self in 1 day"); status = rtems_timer_cancel( Timer_id[ 1 ] ); directive_failed( status, "rtems_timer_cancel" ); puts( "TA1 - rtems_timer_cancel - cancelling RTEMS_EVENT_11 to self in 2 days" ); status = rtems_timer_cancel( Timer_id[ 3 ] ); directive_failed( status, "rtems_timer_cancel" ); puts( "TA1 - rtems_event_send - resending RTEMS_EVENT_11 to self in 2 days" ); status = rtems_timer_fire_when( Timer_id[ 3 ], &time, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 2 days" ); time.day = 15; print_time( "TA1 - rtems_clock_set - ", &time, "\n" ); status = rtems_clock_set( &time ); directive_failed( status, "TA1 rtems_clock_set" ); puts( "TA1 - rtems_event_receive - waiting forever on RTEMS_EVENT_11" ); status = rtems_event_receive( RTEMS_EVENT_11, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive" ); printf( "TA1 - RTEMS_EVENT_11 received - eventout => %08" PRIxrtems_event_set "\n", eventout ); rtems_test_pause(); puts( "TA1 - rtems_event_send/rtems_event_receive combination" ); status = rtems_timer_fire_after( Timer_id[ 1 ], 10, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_after 10 ticks" ); status = rtems_event_receive( RTEMS_EVENT_11, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &eventout ); directive_failed( status, "rtems_event_receive" ); build_time( &time, 2, 12, 1988, 8, 15, 0, 0 ); print_time( "TA1 - rtems_clock_set - ", &time, "\n" ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); time.day = 13; puts( "TA1 - rtems_event_receive all outstanding events" ); status = rtems_event_receive( RTEMS_ALL_EVENTS, RTEMS_NO_WAIT | RTEMS_EVENT_ANY, 0, &eventout ); fatal_directive_status( status, RTEMS_UNSATISFIED, "rtems_event_receive all events" ); puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_10 to self in 1 day" ); status = rtems_timer_fire_when( Timer_id[ 1 ], &time, TA1_send_10_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 1 day" ); time.day = 14; puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 2 days" ); status = rtems_timer_fire_when( Timer_id[ 2 ], &time, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_when 2 days" ); build_time( &time, 2, 12, 1988, 7, 15, 0, 0 ); print_time( "TA1 - rtems_clock_set - ", &time, "\n" ); puts( "TA1 - set time backwards" ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); status = rtems_event_receive( RTEMS_ALL_EVENTS, RTEMS_NO_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &eventout ); if ( eventout ) printf( "ERROR -0x%08" PRIxrtems_event_set " events received\n", eventout ); else puts( "TA1 - no events received" ); fatal_directive_status( status, RTEMS_UNSATISFIED, "rtems_event_receive all events" ); build_time( &time, 2, 14, 1988, 7, 15, 0, 0 ); print_time( "TA1 - rtems_clock_set - ", &time, "\n" ); puts( "TA1 - set time forwards (leave a timer)" ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); status = rtems_event_receive( RTEMS_ALL_EVENTS, RTEMS_NO_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &eventout ); if ( eventout == RTEMS_EVENT_10 ) puts( "TA1 - RTEMS_EVENT_10 received" ); else printf( "ERROR -0x%08" PRIxrtems_event_set " events received\n", eventout ); directive_failed( status, "rtems_event_receive all events" ); puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 100 ticks"); status = rtems_timer_fire_after( Timer_id[ 1 ], 100, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_after 100 ticks" ); puts( "TA1 - rtems_event_send - sending RTEMS_EVENT_11 to self in 200 ticks"); status = rtems_timer_fire_after( Timer_id[ 1 ], 200, TA1_send_11_to_self, NULL ); directive_failed( status, "rtems_timer_fire_after 200 ticks" ); /***** *****/ puts( "TA1 - rtems_event_send - send RTEMS_EVENT_4 to self" ); status = rtems_event_send( RTEMS_SELF, RTEMS_EVENT_4 ); directive_failed( status, "rtems_event_send" ); eventout = 0; puts( "TA1 - rtems_event_receive - RTEMS_EVENT_4 AND RTEMS_EVENT_5 - UNSATISFIED" ); status = rtems_event_receive( RTEMS_EVENT_4 | RTEMS_EVENT_5, RTEMS_NO_WAIT | RTEMS_EVENT_ALL, RTEMS_NO_TIMEOUT, &eventout ); fatal_directive_status( status, RTEMS_UNSATISFIED, "rtems_event_receive" ); /***** *****/ puts( "*** END OF TEST 11 ***" ); rtems_test_exit( 0 ); }
int main(int argc, char *argv[]) { struct timeval T1,T2 ; pthread_t *threads = NULL ; int thread_num = 0 ; char *store_name = NULL ; int mode = 0 ; if( argc != 4 ){ help() ; exit(1) ; } thread_num = atoi( argv[2] ) ; store_name = argv[1] ; mode = atoi(argv[3]) ; obj_store = store_name ; int a[10] = {0}; int q = 0 ; for(q = 0 ; q < 10 ; q++) a[q] = q; /* initialize parameter about stm operation*/ for(q = 0 ; q < 3100000 ; q++) static_key[q] = q; /* initialize key */ per_thread_count = TOTAL_COUNT / thread_num; /* count for per thread operation */ if(( threads == (pthread_t *)malloc(thread_num * sizeof(pthread_t))) == NULL){ perror("thread malloc error") ; exit(1); }/* thread create and error check */ int ret_val = 0 ; /*return value check */ if( mode == 1 ){ /* list insert operation */ ret_val = stm_pos_list_init(store_name) ; ret_val = stm_pos_list_open(store_name) ; }else if( mode == 2){ /* hash insert operation */ int rec_num = 8 ; /*hard coding will be changed */ ret_val = stm_pos_create_hashtable(store_name,rec_num,NULL,NULL); ret_val = stm_pos_hashtable_open(store_name) ; }else if(mode == 3){ /* btree insert operation */ ret_val = stm_pos_btree_init(store_name); ret_val = stm_pos_btree_open(store_name) ; } /* data structure init and open complete */ /* insert & remove operation part */ if( mode == 1 ){ gettimeofday(&T1,NULL); for(i = 0 ; i < threads_num ; i++){ if(pthread_create(&threads[i],NULL,stm_list_insert, (void*)&a[i])!=0){ fprintf(stderr,"error creating threads") ; exit(1) ; } } for(i = 0 ; i < threads_num ; i++){ if(pthread_join(threads[i],NULL)!=0){ fprintf(stderr,"error waiting threads") ; exit(1); } } gettimeofday(&T2,NULL) ; print_time(T1,T2); /*calculate total response time*/ stm_pos_list_close(store_name) ; }else if(mode == 2){ gettimeofday(&T1,NULL) ; for( i = 0 ; i < threads_num ; i++){ if(pthread_create(&threads[i],NULL,stm_hash_insert, (void*)&a[i])!=0){ fprintf(stderr,"error creating threads") ; exit(1) ; } } for( i = 0 ; i < threads_num ; i++){ if( pthread_join(threads[i],NULL)!=0){ fprintf(stderr,"error waiting threads") ; exit(1); } } gettimeofday(&T2,NULL) ; print_time(T1,T2); stm_pos_hashtable_close(store_name); }else if(mode == 3){ gettimeofday(&T1,NULL) ; for( i = 0 ; i < threads_num ; i++){ if(pthread_create(&threads[i],NULL,stm_btree_insert, (void*)&a[i])!=0){ fprintf(stderr,"error creating threads") ; exit(1) ; } } for( i = 0 ; i < threads_num ; i++){ if( pthread_join(threads[i],NULL)!=0){ fprintf(stderr,"error waiting threads") ; exit(1); } } gettimeofday(&T2,NULL) ; print_time(T1,T2); stm_pos_btree__close(store_name); } return 0 ; }
void set_time(void) { uint8_t mode = init_set_menu(2); uint8_t hour, min, sec; hour = time_h; min = time_m; sec = time_s; while (!check_timeout()) { if (just_pressed & 0x2) { just_pressed = 0; screenmutex++; if (mode == SET_TIME) { DEBUG(putstring("Set time hour")); // ok now its selected mode = SET_HOUR; // display instructions below print_menu_opts("change hr","set hour"); } else if (mode == SET_HOUR) { DEBUG(putstring("Set time min")); mode = SET_MIN; // display instructions below print_menu_opts("change min","set mins"); } else if (mode == SET_MIN) { DEBUG(putstring("Set time sec")); mode = SET_SEC; // display instructions below print_menu_opts("change sec","set secs"); } else { // done! DEBUG(putstring("done setting time")); mode = SET_TIME; // display instructions below print_menu_advance(); writei2ctime(sec, min, hour, 0, date_d, date_m, date_y); time_h = hour; time_m = min; time_s = sec; } print_time(hour,min,sec,mode); screenmutex--; } // was easter egg if ((just_pressed & 0x4) || (pressed & 0x4)) { just_pressed = 0; screenmutex++; if (mode == SET_HOUR) { hour = (hour+1) % 24; time_h = hour; } if (mode == SET_MIN) { min = (min+1) % 60; } if (mode == SET_SEC) { sec = (sec+1) % 60; } print_time(hour,min,sec,mode); screenmutex--; if (pressed & 0x4) delay_ms(200); } } }
int a2dp_write(a2dpData d, const void* buffer, int count) { struct bluetooth_data* data = (struct bluetooth_data*)d; uint8_t* src = (uint8_t *)buffer; int codesize; int err, ret = 0; long frames_left = count; int encoded; unsigned int written; const char *buff; int did_configure = 0; #ifdef ENABLE_TIMING uint64_t begin, end; DBG("********** a2dp_write **********"); begin = get_microseconds(); #endif err = check_for_start(data); if (err < 0) return err; pthread_mutex_lock(&data->mutex); codesize = data->codesize; while (frames_left >= codesize) { /* Enough data to encode (sbc wants 512 byte blocks) */ if (data->sbc.priv == NULL) { ERR("bad state"); ret = -EINVAL; goto done; } encoded = sbc_encode(&(data->sbc), src, codesize, data->buffer + data->count, sizeof(data->buffer) - data->count, &written); if (encoded <= 0) { ERR("Encoding error %d", encoded); goto done; } VDBG("sbc_encode returned %d, codesize: %d, written: %d\n", encoded, codesize, written); src += encoded; data->count += written; data->frame_count++; data->samples += encoded; data->nsamples += encoded/4; /* No space left for another frame then send or frame count limit reached */ if ((data->frame_count == 15) || (data->count + written >= data->link_mtu) || (data->count + written >= BUFFER_SIZE)) { VDBG("sending packet %d, count %d, link_mtu %u", data->seq_num, data->count, data->link_mtu); err = avdtp_write(data); if (err < 0) { pthread_mutex_unlock(&data->mutex); return err; } } ret += encoded; frames_left -= encoded; } if (frames_left > 0) ERR("%ld bytes left at end of a2dp_write\n", frames_left); done: pthread_mutex_unlock(&data->mutex); #ifdef ENABLE_TIMING end = get_microseconds(); print_time("a2dp_write total", begin, end); #endif return ret; }
int main (int argc, char **argv) { ssize_t ret_size; struct stat st; int ret, flags; int part_request; long long this_time; double part_min, part_max, time_min, time_max; double time_sum, time_sum2, time_mdev, time_avg; double part_sum, part_sum2, part_mdev, part_avg; long long time_now, time_next, period_deadline; setvbuf(stdout, NULL, _IOLBF, 0); parse_options(argc, argv); interval_ts.tv_sec = interval / 1000000; interval_ts.tv_nsec = (interval % 1000000) * 1000; if (!size) size = default_size; if (size <= 0) errx(1, "request size must be greather than zero"); #ifdef MAX_RW_COUNT if (size > MAX_RW_COUNT) warnx("this platform supports requests %u bytes at most", MAX_RW_COUNT); #endif if (wsize) temp_wsize = wsize; else if (size > temp_wsize) temp_wsize = size; flags = O_RDONLY; #if !defined(HAVE_POSIX_FADVICE) && !defined(HAVE_NOCACHE_IO) # if defined(HAVE_DIRECT_IO) direct |= !cached; # else if (!cached && !write_test) { warnx("non-cached read I/O not supported by this platform"); warnx("you can use write I/O to get reliable results"); cached = 1; } # endif #endif if (write_test) { flags = O_RDWR; make_request = do_pwrite; } if (async) aio_setup(); if (direct) #ifdef HAVE_DIRECT_IO flags |= O_DIRECT; #else errx(1, "direct I/O not supported by this platform"); #endif #ifdef __MINGW32__ flags |= O_BINARY; #endif if (stat(path, &st)) err(2, "stat \"%s\" failed", path); if (!S_ISDIR(st.st_mode) && write_test && write_test < 3) errx(2, "think twice, then use -WWW to shred this target"); if (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode)) { if (S_ISDIR(st.st_mode)) st.st_size = offset + temp_wsize; parse_device(st.st_dev); } else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) { fd = open(path, flags); if (fd < 0) err(2, "failed to open \"%s\"", path); if (get_device_size(fd, &st)) { if (!S_ISCHR(st.st_mode)) err(2, "block get size ioctl failed"); st.st_size = offset + temp_wsize; fstype = "character"; device = "device"; } else { device_size = st.st_size; fstype = "block"; device = "device "; } if (!cached && write_test && fdatasync(fd)) { warnx("fdatasync not supported by \"%s\", " "enable cached requests", path); cached = 1; } } else { errx(2, "unsupported destination: \"%s\"", path); } if (wsize > st.st_size || offset > st.st_size - wsize) errx(2, "target is too small for this"); if (!wsize) wsize = st.st_size - offset; if (size > wsize) errx(2, "request size is too big for this target"); ret = posix_memalign(&buf, 0x1000, size); if (ret) errx(2, "buffer allocation failed"); random_memory(buf, size); if (S_ISDIR(st.st_mode)) { fd = create_temp(path, "ioping.tmp"); if (fd < 0) err(2, "failed to create temporary file at \"%s\"", path); if (keep_file) { if (fstat(fd, &st)) err(2, "fstat at \"%s\" failed", path); if (st.st_size >= offset + wsize) #ifndef __MINGW32__ if (st.st_blocks >= (st.st_size + 511) / 512) #endif goto skip_preparation; } for (woffset = 0 ; woffset < wsize ; woffset += ret_size) { ret_size = size; if (woffset + ret_size > wsize) ret_size = wsize - woffset; if (woffset) random_memory(buf, ret_size); ret_size = pwrite(fd, buf, ret_size, offset + woffset); if (ret_size <= 0) err(2, "preparation write failed"); } skip_preparation: if (fsync(fd)) err(2, "fsync failed"); } else if (S_ISREG(st.st_mode)) { fd = open(path, flags); if (fd < 0) err(2, "failed to open \"%s\"", path); } if (!cached) { #ifdef HAVE_POSIX_FADVICE ret = posix_fadvise(fd, offset, wsize, POSIX_FADV_RANDOM); if (ret) err(2, "fadvise failed"); #endif #ifdef HAVE_NOCACHE_IO ret = fcntl(fd, F_NOCACHE, 1); if (ret) err(2, "fcntl nocache failed"); #endif } srandom(now()); if (deadline) deadline += now(); set_signal(); request = 0; woffset = 0; part_request = 0; part_min = time_min = LLONG_MAX; part_max = time_max = LLONG_MIN; part_sum = time_sum = 0; part_sum2 = time_sum2 = 0; time_now = now(); period_deadline = time_now + period_time; while (!exiting) { request++; part_request++; if (randomize) woffset = random() % (wsize / size) * size; #ifdef HAVE_POSIX_FADVICE if (!cached) { ret = posix_fadvise(fd, offset + woffset, size, POSIX_FADV_DONTNEED); if (ret) err(3, "fadvise failed"); } #endif if (write_test) shake_memory(buf, size); this_time = now(); ret_size = make_request(fd, buf, size, offset + woffset); if (ret_size < 0) { if (errno != EINTR) err(3, "request failed"); } else if (ret_size < size) warnx("request returned less than expected: %zu", ret_size); else if (ret_size > size) errx(3, "request returned more than expected: %zu", ret_size); time_now = now(); this_time = time_now - this_time; time_next = time_now + interval; part_sum += this_time; part_sum2 += this_time * this_time; if (this_time < part_min) part_min = this_time; if (this_time > part_max) part_max = this_time; if (!quiet) { print_size(ret_size); printf(" %s %s (%s %s", write_test ? "to" : "from", path, fstype, device); if (device_size) print_size(device_size); printf("): request=%d time=", request); print_time(this_time); printf("\n"); } if ((period_request && (part_request >= period_request)) || (period_time && (time_next >= period_deadline))) { part_avg = part_sum / part_request; part_mdev = sqrt(part_sum2 / part_request - part_avg * part_avg); printf("%d %.0f %.0f %.0f %.0f %.0f %.0f %.0f\n", part_request, part_sum, 1000000. * part_request / part_sum, 1000000. * part_request * size / part_sum, part_min, part_avg, part_max, part_mdev); time_sum += part_sum; time_sum2 += part_sum2; if (part_min < time_min) time_min = part_min; if (part_max > time_max) time_max = part_max; part_min = LLONG_MAX; part_max = LLONG_MIN; part_sum = part_sum2 = 0; part_request = 0; period_deadline = time_now + period_time; } if (!randomize) { woffset += size; if (woffset + size > wsize) woffset = 0; } if (exiting) break; if (stop_at_request && request >= stop_at_request) break; if (deadline && time_next >= deadline) break; if (interval) nanosleep(&interval_ts, NULL); } time_sum += part_sum; time_sum2 += part_sum2; if (part_min < time_min) time_min = part_min; if (part_max > time_max) time_max = part_max; time_avg = time_sum / request; time_mdev = sqrt(time_sum2 / request - time_avg * time_avg); if (batch_mode) { printf("%d %.0f %.0f %.0f %.0f %.0f %.0f %.0f\n", request, time_sum, 1000000. * request / time_sum, 1000000. * request * size / time_sum, time_min, time_avg, time_max, time_mdev); } else if (!quiet || (!period_time && !period_request)) { printf("\n--- %s (%s %s", path, fstype, device); if (device_size) print_size(device_size); printf(") ioping statistics ---\n"); print_int(request); printf(" requests completed in "); print_time(time_sum); printf(", "); print_size((long long)request * size); printf(" %s, ", write_test ? "written" : "read"); print_int(1000000. * request / time_sum); printf(" iops, "); print_size(1000000. * request * size / time_sum); printf("/s\n"); printf("min/avg/max/mdev = "); print_time(time_min); printf(" / "); print_time(time_avg); printf(" / "); print_time(time_max); printf(" / "); print_time(time_mdev); printf("\n"); } return 0; }
main () { static REAL aa[200][200],a[200][201],b[200],x[200]; REAL cray,ops,total,norma,normx; REAL resid,residn,eps,t1,tm,tm2; REAL epslon(),second(),kf; static int ipvt[200],n,i,ntimes,info,lda,ldaa,kflops; lda = 201; ldaa = 200; cray = .056; n = 100; fprintf(stdout,ROLLING);fprintf(stdout,PREC);fprintf(stdout,"Precision Linpack\n\n"); fprintf(stderr,ROLLING);fprintf(stderr,PREC);fprintf(stderr,"Precision Linpack\n\n"); ops = (2.0e0*(n*n*n))/3.0 + 2.0*(n*n); matgen(a,lda,n,b,&norma); t1 = second(); dgefa(a,lda,n,ipvt,&info); time[0][0] = second() - t1; t1 = second(); dgesl(a,lda,n,ipvt,b,0); time[1][0] = second() - t1; total = time[0][0] + time[1][0]; /* compute a residual to verify results. */ for (i = 0; i < n; i++) { x[i] = b[i]; } matgen(a,lda,n,b,&norma); for (i = 0; i < n; i++) { b[i] = -b[i]; } dmxpy(n,b,n,lda,x,a); // Optimized function resid = 0.0; normx = 0.0; for (i = 0; i < n; i++) { resid = (resid > fabs((double)b[i])) ? resid : fabs((double)b[i]); normx = (normx > fabs((double)x[i])) ? normx : fabs((double)x[i]); } eps = epslon((REAL)ONE); residn = resid/( n*norma*normx*eps ); printf(" norm. resid resid machep"); printf(" x[0]-1 x[n-1]-1\n"); printf(" %8.1f %16.8e%16.8e%16.8e%16.8e\n", (double)residn, (double)resid, (double)eps, (double)x[0]-1, (double)x[n-1]-1); fprintf(stderr," times are reported for matrices of order %5d\n",n); fprintf(stderr," dgefa dgesl total kflops unit"); fprintf(stderr," ratio\n"); time[2][0] = total; time[3][0] = ops/(1.0e3*total); time[4][0] = 2.0e3/time[3][0]; time[5][0] = total/cray; fprintf(stderr," times for array with leading dimension of%5d\n",lda); print_time(0); matgen(a,lda,n,b,&norma); t1 = second(); dgefa(a,lda,n,ipvt,&info); time[0][1] = second() - t1; t1 = second(); dgesl(a,lda,n,ipvt,b,0); time[1][1] = second() - t1; total = time[0][1] + time[1][1]; time[2][1] = total; time[3][1] = ops/(1.0e3*total); time[4][1] = 2.0e3/time[3][1]; time[5][1] = total/cray; matgen(a,lda,n,b,&norma); t1 = second(); dgefa(a,lda,n,ipvt,&info); time[0][2] = second() - t1; t1 = second(); dgesl(a,lda,n,ipvt,b,0); time[1][2] = second() - t1; total = time[0][2] + time[1][2]; time[2][2] = total; time[3][2] = ops/(1.0e3*total); time[4][2] = 2.0e3/time[3][2]; time[5][2] = total/cray; ntimes = NTIMES; tm2 = 0.0; t1 = second(); for (i = 0; i < ntimes; i++) { tm = second(); matgen(a,lda,n,b,&norma); tm2 = tm2 + second() - tm; dgefa(a,lda,n,ipvt,&info); } time[0][3] = (second() - t1 - tm2)/ntimes; t1 = second(); for (i = 0; i < ntimes; i++) { dgesl(a,lda,n,ipvt,b,0); } time[1][3] = (second() - t1)/ntimes; total = time[0][3] + time[1][3]; time[2][3] = total; time[3][3] = ops/(1.0e3*total); time[4][3] = 2.0e3/time[3][3]; time[5][3] = total/cray; print_time(1); print_time(2); print_time(3); matgen(aa,ldaa,n,b,&norma); t1 = second(); dgefa(aa,ldaa,n,ipvt,&info); time[0][4] = second() - t1; t1 = second(); dgesl(aa,ldaa,n,ipvt,b,0); time[1][4] = second() - t1; total = time[0][4] + time[1][4]; time[2][4] = total; time[3][4] = ops/(1.0e3*total); time[4][4] = 2.0e3/time[3][4]; time[5][4] = total/cray; matgen(aa,ldaa,n,b,&norma); t1 = second(); dgefa(aa,ldaa,n,ipvt,&info); time[0][5] = second() - t1; t1 = second(); dgesl(aa,ldaa,n,ipvt,b,0); time[1][5] = second() - t1; total = time[0][5] + time[1][5]; time[2][5] = total; time[3][5] = ops/(1.0e3*total); time[4][5] = 2.0e3/time[3][5]; time[5][5] = total/cray; matgen(aa,ldaa,n,b,&norma); t1 = second(); dgefa(aa,ldaa,n,ipvt,&info); time[0][6] = second() - t1; t1 = second(); dgesl(aa,ldaa,n,ipvt,b,0); time[1][6] = second() - t1; total = time[0][6] + time[1][6]; time[2][6] = total; time[3][6] = ops/(1.0e3*total); time[4][6] = 2.0e3/time[3][6]; time[5][6] = total/cray; ntimes = NTIMES; tm2 = 0; t1 = second(); for (i = 0; i < ntimes; i++) { tm = second(); matgen(aa,ldaa,n,b,&norma); tm2 = tm2 + second() - tm; dgefa(aa,ldaa,n,ipvt,&info); } time[0][7] = (second() - t1 - tm2)/ntimes; t1 = second(); for (i = 0; i < ntimes; i++) { dgesl(aa,ldaa,n,ipvt,b,0); } time[1][7] = (second() - t1)/ntimes; total = time[0][7] + time[1][7]; time[2][7] = total; time[3][7] = ops/(1.0e3*total); time[4][7] = 2.0e3/time[3][7]; time[5][7] = total/cray; /* the following code sequence implements the semantics of the Fortran intrinsics "nint(min(time[3][3],time[3][7]))" */ kf = (time[3][3] < time[3][7]) ? time[3][3] : time[3][7]; // CHANGED to GREATER // fprintf(stderr, "time[3][3] : %f, time[3][7] : %f\n", time[3][3], time[3][7]); kf = (kf > ZERO) ? (kf + .5) : (kf - .5); if (fabs((double)kf) < ONE) kflops = 0; else { kflops = floor(fabs((double)kf)); if (kf < ZERO) kflops = -kflops; } fprintf(stderr," times for array with leading dimension of%4d\n",ldaa); print_time(4); print_time(5); print_time(6); print_time(7); fprintf(stderr,ROLLING);fprintf(stderr,PREC); fprintf(stderr," Precision %5d Kflops ; %d Reps \n",kflops,NTIMES); }
void run_phase (phases_t phase, char *name, string_list_t *args) { char **argv; int argc = 1; string_item_t *p; char *output = NULL; char *input = NULL; boolean save_stderr = FALSE; int fdin, fdout; int forkpid; int waitpid; int waitstatus; int termsig; int num_maps; char *rld_path, *absoft_path; struct stat stat_buf; const boolean uses_message_system = (phase == P_f90_fe || phase == P_f90_cpp || phase == P_cppf90_fe); #if defined(__APPLE__) // pass -Wa,-W to assembler so we ignore unknowns int hack_as_W = 0; if (strcmp(name, "/usr/bin/gcc") == 0) { hack_as_W = 1; argc++; } #endif if (show_flag) { /* echo the command */ fprintf(stderr, "%s ", name); print_string_list(stderr, args); } if (!execute_flag) return; if (time_flag) init_time(); /* copy arg_list to argv format that exec wants */ for (p = args->head; p != NULL; p=p->next) { //bug# 581, bug #932, bug #1049 if (p->name == NULL) continue; argc++; } argv = (char **) malloc((argc+1)*sizeof(char*)); argv[0] = name; for (argc = 1, p = args->head; p != NULL; argc++, p=p->next) { //bug# 581, bug #932 if (p->name[0] == '\0') { argc--; continue; } /* don't put redirection in arg list */ if (strcmp(p->name, "<") == 0) { /* has input file */ input = p->next->name; break; } else if (strcmp(p->name, ">") == 0) { /* has output file */ output = p->next->name; break; } else if (strcmp(p->name, ">&") == 0) { /* has error output file */ output = p->next->name; save_stderr = TRUE; break; } argv[argc] = p->name; } #if defined(__APPLE__) if (hack_as_W) { #ifndef Is_True_On argv[argc++] = ""; // "-Wa,-W"; #endif } #endif argv[argc] = NULL; /* fork a process */ forkpid = fork(); if (forkpid == -1) { error("no more processes"); cleanup (); do_exit (RC_SYSTEM_ERROR); /* NOTREACHED */ } if (forkpid == 0) { char *my_path, *l_path, *l32_path, *nls_path, *env_path; /* child */ /* if we want memory stats, we have to wait for parent to connect to our /proc */ if (input != NULL) { if ((fdin = open (input, O_RDONLY)) == -1) { error ("cannot open input file %s", input); cleanup (); do_exit (RC_SYSTEM_ERROR); /* NOTREACHED */ } dup2 (fdin, fileno(stdin)); } if (output != NULL) { if ((fdout = creat (output, 0666)) == -1) { error ("cannot create output file %s", output); cleanup (); do_exit (RC_SYSTEM_ERROR); /* NOTREACHED */ } if (save_stderr) { dup2 (fdout, fileno(stderr)); } else { dup2 (fdout, fileno(stdout)); } } my_path = get_binutils_lib_path(); rld_path = get_phase_ld_library_path (phase); absoft_path = get_absoft_ld_library_path (phase); if (absoft_path != 0) asprintf(&my_path, "%s:%s", my_path, absoft_path); if (rld_path != 0) asprintf(&my_path, "%s:%s", my_path, rld_path); l_path = l32_path = my_path; if (ld_library_path) asprintf(&l_path, "%s:%s", my_path, ld_library_path); if (ld_libraryn32_path) asprintf(&l32_path, "%s:%s", my_path, ld_libraryn32_path); my_putenv("LD_LIBRARY_PATH", l_path); my_putenv("LD_LIBRARYN32_PATH", l32_path); // Set up NLSPATH, for the Fortran front end. nls_path = getenv("NLSPATH"); env_path = get_phase_dir(P_f90_fe); if (nls_path) { my_putenv("NLSPATH", "%s:%s/%%N.cat", nls_path, env_path); } else { my_putenv("NLSPATH", "%s/%%N.cat", env_path); } if (uses_message_system && getenv("ORIG_CMD_NAME") == NULL) my_putenv("ORIG_CMD_NAME", "%s", program_name); if (phase == P_f90_fe) { char *root; char *modulepath; int len; char *new_env; char *env_name = "FORTRAN_SYSTEM_MODULES="; char *env_val = "/usr/lib/f90modules"; root = getenv("TOOLROOT"); if (root != NULL) { len = strlen(env_val) + strlen(root) +3 + strlen(env_val); new_env = alloca(len); sprintf(new_env,"%s/%s:%s",root,env_val,env_val); env_val = new_env; } modulepath = string_copy(getenv("FORTRAN_SYSTEM_MODULES")); if (modulepath != NULL) { /* Append env_val to FORTRAN_SYSTEM_MODULES */ if (modulepath[strlen(modulepath)-1] == ':') { /* Just append env_val */ len = strlen(modulepath) + strlen(env_val) + 1; new_env = alloca(len); sprintf(new_env,"%s%s",modulepath,env_val); } else { /* append :env_val */ len = strlen(modulepath) + strlen(env_val) + 2; new_env = alloca(len); sprintf(new_env,"%s:%s",modulepath,env_val); } env_val = new_env; } my_putenv ("FORTRAN_SYSTEM_MODULES", "%s", env_val); } /* need to setenv COMPILER_PATH for collect to find ld */ my_putenv ("COMPILER_PATH", "%s", get_phase_dir(P_collect)); /* Tell IPA where to find the driver. */ #if defined(ABSOFT_EXTENSIONS) my_putenv ("COMPILER_BIN", "%s/" PSC_NAME_PREFIX "f90", get_executable_dir()); #else my_putenv ("COMPILER_BIN", "%s/" PSC_NAME_PREFIX "cc-" PSC_FULL_VERSION, get_executable_dir()); #endif my_execv(name, argv); } else { /* parent */ int procid; /* id of the /proc file */ while ((waitpid = wait (&waitstatus)) != forkpid) { if (waitpid == -1) { error("bad return from wait"); cleanup(); do_exit(RC_SYSTEM_ERROR); /* NOTREACHED */ } } if (time_flag) print_time(name); if (WIFSTOPPED(waitstatus)) { termsig = WSTOPSIG(waitstatus); error("STOPPED signal received from %s", name); cleanup(); do_exit(RC_SYSTEM_ERROR); /* NOTREACHED */ } else if (WIFEXITED(waitstatus)) { int status = WEXITSTATUS(waitstatus); extern int inline_t; boolean internal_err = FALSE; boolean user_err = FALSE; if (phase == P_prof) { /* Make sure the .cfb files were created before changing the STATUS to OKAY */ if (prof_file != NULL) { if (!(stat(fb_file, &stat_buf) != 0 && errno == ENOENT)) status = RC_OKAY; } else { internal_error("No count file was specified for a prof run"); perror(program_name); } } if (phase == P_f90_fe && keep_listing) { char *cif_file; cif_file = construct_given_name( drop_path(source_file), "T", TRUE); if (!(stat(cif_file, &stat_buf) != 0 && errno == ENOENT)) f90_fe_status = status; f90_fe_name = string_copy(name); /* Change the status to OKAY so that we can * execute the lister on the cif_file; we will * take appropriate action on this status once * the lister has finished executing. See below. */ status = RC_OKAY; } if (phase == P_lister) { if (status == RC_OKAY && f90_fe_status != RC_OKAY) { /* We had encountered an error in the F90_fe phase * but we ignored it so that we could execute the * lister on the cif file; we need to switch the * status to the status we received from F90_fe * and use the name of the F90_fe_phase, so that * we can issue a correct error message. */ status = f90_fe_status; name = string_copy(f90_fe_name); /* Reset f90_fe_status to OKAY for any further * compilations on other source files. */ f90_fe_status = RC_OKAY; } } switch (status) { case RC_OKAY: if (inline_t == UNDEFINED && is_matching_phase( get_phase_mask(phase), P_any_fe) ) { inline_t = FALSE; } break; case RC_NEED_INLINER: if (inline_t == UNDEFINED && is_matching_phase( get_phase_mask(phase), P_any_fe) ) { inline_t = TRUE; } /* completed successfully */ break; case RC_USER_ERROR: case RC_NORECOVER_USER_ERROR: case RC_SYSTEM_ERROR: case RC_GCC_ERROR: user_err = TRUE; break; case RC_OVERFLOW_ERROR: if (!ran_twice && phase == P_be) { /* try recompiling with larger limits */ ran_twice = TRUE; add_string (args, "-TENV:long_eh_offsets"); add_string (args, "-TENV:large_stack"); run_phase (phase, name, args); return; } internal_err = TRUE; break; case RC_INTERNAL_ERROR: internal_err = TRUE; break; default: internal_err = TRUE; break; } if (internal_err) { if (phase == P_ld || phase == P_ldplus || #ifdef KEY phase == P_gas || // bug 4846 #endif phase == P_gcpp || phase == P_gcpp_plus) { if (phase == P_gas) internal_error_occurred = 1; log_error("%s returned non-zero status %d", name, status); nomsg_error(status); } else { internal_error("%s returned non-zero status %d", name, status); } } else if (user_err) { /* assume phase will print diagnostics */ if (phase == P_c_gfe || phase == P_cplus_gfe) { nomsg_error(RC_INTERNAL_ERROR); } else if (!show_flag || save_stderr) { nomsg_error(RC_USER_ERROR); } else { error("%s returned non-zero status %d", name, status); } } ran_twice = FALSE; return; } else if(WIFSIGNALED(waitstatus)){ termsig = WTERMSIG(waitstatus); switch (termsig) { case SIGHUP: case SIGINT: case SIGQUIT: case SIGKILL: case SIGTERM: error("%s died due to signal %d", name, termsig); break; default: internal_error("%s died due to signal %d", name, termsig); break; } #ifndef __CYGWIN__ if(waitstatus & WCOREFLAG) { error("core dumped"); } #endif if (termsig == SIGKILL) { error("Probably caused by running out of swap space -- check %s", LOGFILE); } cleanup(); do_exit(RC_SYSTEM_ERROR); } else { /* cannot happen, I think! */ internal_error("driver exec'ing is confused"); return; } } }
int main(int argc, char * argv[]) { pinyin_option_t options = USE_TONE | PINYIN_INCOMPLETE; ChewingLargeTable largetable(options); FacadePhraseIndex phrase_index; FILE * gbfile = fopen("../../data/gb_char.table", "r"); if (NULL == gbfile) { fprintf(stderr, "open gb_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbfile); fseek(gbfile, 0L, SEEK_SET); phrase_index.load_text(1, gbfile); fclose(gbfile); FILE * gbkfile = fopen("../../data/gbk_char.table", "r"); if (NULL == gbkfile) { fprintf(stderr, "open gbk_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbkfile); fseek(gbkfile, 0L, SEEK_SET); phrase_index.load_text(2, gbkfile); fclose(gbkfile); MemoryChunk * new_chunk = new MemoryChunk; largetable.store(new_chunk); largetable.load(new_chunk); char* linebuf = NULL; size_t size = 0; while( getline(&linebuf, &size, stdin) ){ linebuf[strlen(linebuf)-1] = '\0'; if ( strcmp ( linebuf, "quit" ) == 0) break; FullPinyinParser2 parser; ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); parser.parse(options, keys, key_rests, linebuf, strlen(linebuf)); if (0 == keys->len) { fprintf(stderr, "Invalid input.\n"); continue; } guint32 start = record_time(); PhraseIndexRanges ranges; memset(ranges, 0, sizeof(PhraseIndexRanges)); guint8 min_index, max_index; phrase_index.get_sub_phrase_range(min_index, max_index); for (size_t i = min_index; i < max_index; ++i) { ranges[i] = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange)); } for (size_t i = 0; i < bench_times; ++i) { largetable.search(keys->len, (ChewingKey *)keys->data, ranges); } for (size_t i = min_index; i < max_index; ++i) { g_array_set_size(ranges[i], 0); } print_time(start, bench_times); largetable.search(keys->len, (ChewingKey *)keys->data, ranges); for (size_t i = min_index; i < max_index; ++i) { GArray * & range = ranges[i]; if (range) { if (range->len) printf("range items number:%d\n", range->len); for (size_t k = 0; k < range->len; ++k) { PhraseIndexRange * onerange = &g_array_index(range, PhraseIndexRange, k); printf("start:%d\tend:%d\n", onerange->m_range_begin, onerange->m_range_end); PhraseItem item; for ( phrase_token_t token = onerange->m_range_begin; token != onerange->m_range_end; ++token){ phrase_index.get_phrase_item( token, item); /* get phrase string */ gunichar2 buffer[MAX_PHRASE_LENGTH + 1]; item.get_phrase_string(buffer); char * string = g_utf16_to_utf8 ( buffer, item.get_phrase_length(), NULL, NULL, NULL); printf("%s\t", string); g_free(string); ChewingKey chewing_buffer[MAX_PHRASE_LENGTH]; size_t npron = item.get_n_pronunciation(); guint32 freq; for (size_t m = 0; m < npron; ++m){ item.get_nth_pronunciation(m, chewing_buffer, freq); for (size_t n = 0; n < item.get_phrase_length(); ++n){ printf("%s'", chewing_buffer[n].get_pinyin_string()); } printf("\b\t%d\t", freq); } } printf("\n"); } } g_array_set_size(range, 0); } g_array_free(keys, TRUE); g_array_free(key_rests, TRUE); } if (linebuf) free(linebuf); return 0; }
void displayRunner(const Trunner *runner) { char recordCopy[6], timelagCopy[6]; print_time(runner->record, recordCopy); print_time(runner->time_lag, timelagCopy); printf("%s- |record| %s |lag| %s\n", runner->name, recordCopy, timelagCopy); }
CELL clump(int in_fd, int out_fd, int diag, int print) { register int col; register int n; CELL NEW, OLD; CELL *temp_cell, *temp_clump; CELL *prev_in, *cur_in, *out_cell; CELL *prev_clump, *cur_clump; CELL X, LEFT; CELL *index, *renumber; CELL label; int nrows, ncols; int row; int len; int nalloc; long cur_time; char *cname; int cfd, csize; CELL cat; nrows = Rast_window_rows(); ncols = Rast_window_cols(); /* allocate clump index */ nalloc = INCR; index = (CELL *) G_malloc(nalloc * sizeof(CELL)); index[0] = 0; renumber = NULL; /* allocate CELL buffers two columns larger than current window */ len = (ncols + 2) * sizeof(CELL); prev_in = (CELL *) G_malloc(len); cur_in = (CELL *) G_malloc(len); prev_clump = (CELL *) G_malloc(len); cur_clump = (CELL *) G_malloc(len); out_cell = (CELL *) G_malloc(len); /* temp file for initial clump IDs */ cname = G_tempfile(); if ((cfd = open(cname, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) G_fatal_error(_("Unable to open temp file")); csize = ncols * sizeof(CELL); time(&cur_time); /* fake a previous row which is all NULL */ Rast_set_c_null_value(prev_in, ncols + 2); /* set left and right edge to NULL */ Rast_set_c_null_value(&cur_in[0], 1); Rast_set_c_null_value(&cur_in[ncols + 1], 1); /* initialize clump labels */ G_zero(cur_clump, len); G_zero(prev_clump, len); label = 0; /**************************************************** * PASS 1 * * pass thru the input, create initial clump labels * ****************************************************/ G_message(_("Pass 1 of 2...")); for (row = 0; row < nrows; row++) { Rast_get_c_row(in_fd, cur_in + 1, row); G_percent(row, nrows, 4); Rast_set_c_null_value(&X, 1); for (col = 1; col <= ncols; col++) { LEFT = X; X = cur_in[col]; if (Rast_is_c_null_value(&X)) { /* don't clump NULL data */ cur_clump[col] = 0; continue; } /* * if the cell value is different to the left and above * (diagonal: and above left and above right) * then we must start a new clump * * this new clump may eventually collide with another * clump and will have to be merged */ /* try to connect the current cell to an existing clump */ OLD = NEW = 0; /* same clump as to the left */ if (X == LEFT) { OLD = cur_clump[col] = cur_clump[col - 1]; } if (diag) { /* check above right, center, left, in that order */ n = 2; temp_clump = prev_clump + col + 1; temp_cell = prev_in + col + 1; do { if (X == *temp_cell) { cur_clump[col] = *temp_clump; if (OLD == 0) { OLD = *temp_clump; } else { NEW = *temp_clump; break; } } temp_cell--; temp_clump--; } while (n-- > 0); } else { /* check above */ if (X == prev_in[col]) { temp_clump = prev_clump + col; cur_clump[col] = *temp_clump; if (OLD == 0) { OLD = *temp_clump; } else { NEW = *temp_clump; } } } if (NEW == 0 || OLD == NEW) { /* ok */ if (OLD == 0) { /* start a new clump */ label++; cur_clump[col] = label; if (label >= nalloc) { nalloc += INCR; index = (CELL *) G_realloc(index, nalloc * sizeof(CELL)); } index[label] = label; } continue; } /* conflict! preserve NEW clump ID and change OLD clump ID. * Must go back to the left in the current row and to the right * in the previous row to change all the clump values as well. */ /* left of the current row from 1 to col - 1 */ temp_clump = cur_clump; n = col - 1; while (n-- > 0) { temp_clump++; /* skip left edge */ if (*temp_clump == OLD) *temp_clump = NEW; } /* right of previous row from col + 1 to ncols */ temp_clump = prev_clump; temp_clump += col; n = ncols - col; while (n-- > 0) { temp_clump++; /* skip col */ if (*temp_clump == OLD) *temp_clump = NEW; } /* modify the OLD index */ index[OLD] = NEW; } /* write initial clump IDs */ /* this works also with writing out cur_clump, but only * prev_clump is complete and will not change any more */ if (row > 0) { if (write(cfd, prev_clump + 1, csize) != csize) G_fatal_error(_("Unable to write to temp file")); } /* switch the buffers so that the current buffer becomes the previous */ temp_cell = cur_in; cur_in = prev_in; prev_in = temp_cell; temp_clump = cur_clump; cur_clump = prev_clump; prev_clump = temp_clump; } /* write last row with initial clump IDs */ if (write(cfd, prev_clump + 1, csize) != csize) G_fatal_error(_("Unable to write to temp file")); G_percent(1, 1, 1); /* generate a renumbering scheme */ G_message(_("Generating renumbering scheme...")); G_debug(1, "%d initial labels", label); /* allocate final clump ID */ renumber = (CELL *) G_malloc((label + 1) * sizeof(CELL)); renumber[0] = 0; cat = 1; G_percent(0, label, 1); for (n = 1; n <= label; n++) { G_percent(n, label, 1); OLD = n; NEW = index[n]; if (OLD != NEW) { renumber[n] = 0; /* find valid clump ID */ while (OLD != NEW) { OLD = NEW; NEW = index[OLD]; } index[n] = NEW; } else /* set final clump id */ renumber[n] = cat++; } /* rewind temp file */ lseek(cfd, 0, SEEK_SET); if (print) { fprintf(stdout, "clumps=%d\n", cat - 1); } else { /**************************************************** * PASS 2 * * apply renumbering scheme to initial clump labels * ****************************************************/ /* the input raster is no longer needed, * using instead the temp file with initial clump labels */ G_message(_("Pass 2 of 2...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 4); if (read(cfd, cur_clump, csize) != csize) G_fatal_error(_("Unable to read from temp file")); temp_clump = cur_clump; temp_cell = out_cell; for (col = 0; col < ncols; col++) { *temp_cell = renumber[index[*temp_clump]]; if (*temp_cell == 0) Rast_set_c_null_value(temp_cell, 1); temp_clump++; temp_cell++; } Rast_put_row(out_fd, out_cell, CELL_TYPE); } G_percent(1, 1, 1); } close(cfd); unlink(cname); print_time(&cur_time); return 0; }
void test_adjtime(void) { int sc; rtems_status_code status; struct timeval delta; struct timeval olddelta; rtems_time_of_day *the_tod; rtems_time_of_day tod; rtems_interval ticks; the_tod = &Dates[0]; print_time( "rtems_clock_set ", the_tod, "\n" ); status = rtems_clock_set( the_tod ); rtems_test_assert( !status ); delta.tv_sec = 0; delta.tv_usec = 0; olddelta.tv_sec = 0; olddelta.tv_usec = 0; puts( "adjtime - NULL delta - EINVAL" ); sc = adjtime( NULL, &olddelta ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EINVAL ); puts( "adjtime - delta out of range - EINVAL" ); delta.tv_usec = 1000000000; /* 100 seconds worth */ sc = adjtime( &delta, &olddelta ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EINVAL ); puts( "adjtime - delta too small - do nothing" ); delta.tv_sec = 0; delta.tv_usec = 1; sc = adjtime( &delta, &olddelta ); rtems_test_assert( sc == 0 ); puts( "adjtime - delta too small - do nothing, olddelta=NULL" ); sc = adjtime( &delta, NULL ); rtems_test_assert( sc == 0 ); puts( "adjtime - delta of one second forward, olddelta=NULL" ); delta.tv_sec = 1; delta.tv_usec = 0; sc = adjtime( &delta, NULL ); rtems_test_assert( sc == 0 ); puts( "adjtime - delta of one second forward" ); delta.tv_sec = 1; delta.tv_usec = 0; sc = adjtime( &delta, &olddelta ); rtems_test_assert( sc == 0 ); puts( "adjtime - delta of almost two seconds forward" ); delta.tv_sec = 1; delta.tv_usec = 1000000 - 1; sc = adjtime( &delta, &olddelta ); rtems_test_assert( sc == 0 ); /* * spin until over 1/2 of the way to the */ ticks = rtems_clock_get_ticks_per_second(); rtems_test_assert( ticks ); ticks /= 2; do { status = rtems_clock_get_tod( &tod ); rtems_test_assert( !status ); } while ( tod.ticks <= ticks ); puts( "adjtime - delta of almost one second forward which bumps second" ); delta.tv_sec = 0; delta.tv_usec = 1000000 - 1; sc = adjtime( &delta, &olddelta ); rtems_test_assert( sc == 0 ); status = rtems_clock_get_tod( &tod ); rtems_test_assert( !status ); print_time( "rtems_clock_get_tod ", &tod, "\n" ); }
int main(int argc, char **cargv) { int dbdata_type = 0; int yield = 0; open_db dbblock; open_db *dbm; EXIM_CURSOR *cursor; uschar **argv = USS cargv; uschar *key; uschar keybuffer[1024]; /* Check the arguments, and open the database */ dbdata_type = check_args(argc, argv, US"dumpdb", US""); dbm = dbfn_open(argv[1], argv[2], O_RDONLY, &dbblock); if (dbm == NULL) exit(1); /* Scan the file, formatting the information for each entry. Note that data is returned in a malloc'ed block, in order that it be correctly aligned. */ key = dbfn_scan(dbm, TRUE, &cursor); while (key != NULL) { dbdata_retry *retry; dbdata_wait *wait; dbdata_callout_cache *callout; dbdata_ratelimit *ratelimit; int count_bad = 0; int i, length; uschar *t; uschar name[MESSAGE_ID_LENGTH + 1]; void *value; /* Keep a copy of the key separate, as in some DBM's the pointer is into data which might change. */ if (Ustrlen(key) > sizeof(keybuffer) - 1) { printf("**** Overlong key encountered: %s\n", key); return 1; } Ustrcpy(keybuffer, key); value = dbfn_read_with_length(dbm, keybuffer, &length); if (value == NULL) fprintf(stderr, "**** Entry \"%s\" was in the key scan, but the record " "was not found in the file - something is wrong!\n", CS keybuffer); else { /* Note: don't use print_time more than once in one statement, since it uses a single buffer. */ switch(dbdata_type) { case type_retry: retry = (dbdata_retry *)value; printf(" %s %d %d %s\n%s ", keybuffer, retry->basic_errno, retry->more_errno, retry->text, print_time(retry->first_failed)); printf("%s ", print_time(retry->last_try)); printf("%s %s\n", print_time(retry->next_try), (retry->expired)? "*" : ""); break; case type_wait: wait = (dbdata_wait *)value; printf("%s ", keybuffer); t = wait->text; name[MESSAGE_ID_LENGTH] = 0; if (wait->count > WAIT_NAME_MAX) { fprintf(stderr, "**** Data for %s corrupted\n count=%d=0x%x max=%d\n", CS keybuffer, wait->count, wait->count, WAIT_NAME_MAX); wait->count = WAIT_NAME_MAX; yield = count_bad = 1; } for (i = 1; i <= wait->count; i++) { Ustrncpy(name, t, MESSAGE_ID_LENGTH); if (count_bad && name[0] == 0) break; if (Ustrlen(name) != MESSAGE_ID_LENGTH || Ustrspn(name, "0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ-") != MESSAGE_ID_LENGTH) { int j; fprintf(stderr, "**** Data for %s corrupted: bad character in message id\n", CS keybuffer); for (j = 0; j < MESSAGE_ID_LENGTH; j++) fprintf(stderr, "%02x ", name[j]); fprintf(stderr, "\n"); yield = 1; break; } printf("%s ", name); t += MESSAGE_ID_LENGTH; } printf("\n"); break; case type_misc: printf("%s %s\n", print_time(((dbdata_generic *)value)->time_stamp), keybuffer); break; case type_callout: callout = (dbdata_callout_cache *)value; /* New-style address record */ if (length == sizeof(dbdata_callout_cache_address)) { printf("%s %s callout=%s\n", print_time(((dbdata_generic *)value)->time_stamp), keybuffer, print_cache(callout->result)); } /* New-style domain record */ else if (length == sizeof(dbdata_callout_cache)) { printf("%s %s callout=%s postmaster=%s", print_time(((dbdata_generic *)value)->time_stamp), keybuffer, print_cache(callout->result), print_cache(callout->postmaster_result)); if (callout->postmaster_result != ccache_unknown) printf(" (%s)", print_time(callout->postmaster_stamp)); printf(" random=%s", print_cache(callout->random_result)); if (callout->random_result != ccache_unknown) printf(" (%s)", print_time(callout->random_stamp)); printf("\n"); } /* Old-style domain record, without separate timestamps. This code can eventually be thrown away, say in 5 years' time (it's now Feb 2003). */ else { printf("%s %s callout=%s postmaster=%s random=%s\n", print_time(((dbdata_generic *)value)->time_stamp), keybuffer, print_cache(callout->result), print_cache(callout->postmaster_result), print_cache(callout->random_result)); } break; case type_ratelimit: ratelimit = (dbdata_ratelimit *)value; printf("%s.%06d rate: %10.3f key: %s\n", print_time(ratelimit->time_stamp), ratelimit->time_usec, ratelimit->rate, keybuffer); break; } store_reset(value); } key = dbfn_scan(dbm, FALSE, &cursor); } dbfn_close(dbm); return yield; }
void print_station(struct station s) { printf("%s\t", s.station_name); print_time(s.arrival_time); printf("\n"); }
int main(int argc, char **cargv) { int dbdata_type; uschar **argv = USS cargv; uschar buffer[256]; uschar name[256]; void *reset_point = store_get(0); name[0] = 0; /* No name set */ /* Sort out the database type, verify what we are working on and then process user requests */ dbdata_type = check_args(argc, argv, US"fixdb", US""); printf("Modifying Exim hints database %s/db/%s\n", argv[1], argv[2]); for(;;) { open_db dbblock; open_db *dbm; void *record; dbdata_retry *retry; dbdata_wait *wait; dbdata_callout_cache *callout; dbdata_ratelimit *ratelimit; int i, oldlength; uschar *t; uschar field[256], value[256]; store_reset(reset_point); printf("> "); if (Ufgets(buffer, 256, stdin) == NULL) break; buffer[Ustrlen(buffer)-1] = 0; field[0] = value[0] = 0; /* If the buffer contains just one digit, or just consists of "d", use the previous name for an update. */ if ((isdigit((uschar)buffer[0]) && (buffer[1] == ' ' || buffer[1] == '\0')) || Ustrcmp(buffer, "d") == 0) { if (name[0] == 0) { printf("No previous record name is set\n"); continue; } (void)sscanf(CS buffer, "%s %s", field, value); } else { name[0] = 0; (void)sscanf(CS buffer, "%s %s %s", name, field, value); } /* Handle an update request */ if (field[0] != 0) { int verify = 1; dbm = dbfn_open(argv[1], argv[2], O_RDWR, &dbblock); if (dbm == NULL) continue; if (Ustrcmp(field, "d") == 0) { if (value[0] != 0) printf("unexpected value after \"d\"\n"); else printf("%s\n", (dbfn_delete(dbm, name) < 0)? "not found" : "deleted"); dbfn_close(dbm); continue; } else if (isdigit((uschar)field[0])) { int fieldno = Uatoi(field); if (value[0] == 0) { printf("value missing\n"); dbfn_close(dbm); continue; } else { record = dbfn_read_with_length(dbm, name, &oldlength); if (record == NULL) printf("not found\n"); else { time_t tt; int length = 0; /* Stops compiler warning */ switch(dbdata_type) { case type_retry: retry = (dbdata_retry *)record; length = sizeof(dbdata_retry) + Ustrlen(retry->text); switch(fieldno) { case 0: retry->basic_errno = Uatoi(value); break; case 1: retry->more_errno = Uatoi(value); break; case 2: if ((tt = read_time(value)) > 0) retry->first_failed = tt; else printf("bad time value\n"); break; case 3: if ((tt = read_time(value)) > 0) retry->last_try = tt; else printf("bad time value\n"); break; case 4: if ((tt = read_time(value)) > 0) retry->next_try = tt; else printf("bad time value\n"); break; case 5: if (Ustrcmp(value, "yes") == 0) retry->expired = TRUE; else if (Ustrcmp(value, "no") == 0) retry->expired = FALSE; else printf("\"yes\" or \"no\" expected=n"); break; default: printf("unknown field number\n"); verify = 0; break; } break; case type_wait: printf("Can't change contents of wait database record\n"); break; case type_misc: printf("Can't change contents of misc database record\n"); break; case type_callout: callout = (dbdata_callout_cache *)record; length = sizeof(dbdata_callout_cache); switch(fieldno) { case 0: callout->result = Uatoi(value); break; case 1: callout->postmaster_result = Uatoi(value); break; case 2: callout->random_result = Uatoi(value); break; default: printf("unknown field number\n"); verify = 0; break; } break; case type_ratelimit: ratelimit = (dbdata_ratelimit *)record; length = sizeof(dbdata_ratelimit); switch(fieldno) { case 0: if ((tt = read_time(value)) > 0) ratelimit->time_stamp = tt; else printf("bad time value\n"); break; case 1: ratelimit->time_usec = Uatoi(value); break; case 2: ratelimit->rate = Ustrtod(value, NULL); break; default: printf("unknown field number\n"); verify = 0; break; } break; } dbfn_write(dbm, name, record, length); } } } else { printf("field number or d expected\n"); verify = 0; } dbfn_close(dbm); if (!verify) continue; } /* The "name" q causes an exit */ else if (Ustrcmp(name, "q") == 0) return 0; /* Handle a read request, or verify after an update. */ dbm = dbfn_open(argv[1], argv[2], O_RDONLY, &dbblock); if (dbm == NULL) continue; record = dbfn_read_with_length(dbm, name, &oldlength); if (record == NULL) { printf("record %s not found\n", name); name[0] = 0; } else { int count_bad = 0; printf("%s\n", CS print_time(((dbdata_generic *)record)->time_stamp)); switch(dbdata_type) { case type_retry: retry = (dbdata_retry *)record; printf("0 error number: %d %s\n", retry->basic_errno, retry->text); printf("1 extra data: %d\n", retry->more_errno); printf("2 first failed: %s\n", print_time(retry->first_failed)); printf("3 last try: %s\n", print_time(retry->last_try)); printf("4 next try: %s\n", print_time(retry->next_try)); printf("5 expired: %s\n", (retry->expired)? "yes" : "no"); break; case type_wait: wait = (dbdata_wait *)record; t = wait->text; printf("Sequence: %d\n", wait->sequence); if (wait->count > WAIT_NAME_MAX) { printf("**** Data corrupted: count=%d=0x%x max=%d ****\n", wait->count, wait->count, WAIT_NAME_MAX); wait->count = WAIT_NAME_MAX; count_bad = 1; } for (i = 1; i <= wait->count; i++) { Ustrncpy(value, t, MESSAGE_ID_LENGTH); value[MESSAGE_ID_LENGTH] = 0; if (count_bad && value[0] == 0) break; if (Ustrlen(value) != MESSAGE_ID_LENGTH || Ustrspn(value, "0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ-") != MESSAGE_ID_LENGTH) { int j; printf("\n**** Data corrupted: bad character in message id ****\n"); for (j = 0; j < MESSAGE_ID_LENGTH; j++) printf("%02x ", value[j]); printf("\n"); break; } printf("%s ", value); t += MESSAGE_ID_LENGTH; } printf("\n"); break; case type_misc: break; case type_callout: callout = (dbdata_callout_cache *)record; printf("0 callout: %s (%d)\n", print_cache(callout->result), callout->result); if (oldlength > sizeof(dbdata_callout_cache_address)) { printf("1 postmaster: %s (%d)\n", print_cache(callout->postmaster_result), callout->postmaster_result); printf("2 random: %s (%d)\n", print_cache(callout->random_result), callout->random_result); } break; case type_ratelimit: ratelimit = (dbdata_ratelimit *)record; printf("0 time stamp: %s\n", print_time(ratelimit->time_stamp)); printf("1 fract. time: .%06d\n", ratelimit->time_usec); printf("2 sender rate: % .3f\n", ratelimit->rate); break; } } /* The database is closed after each request */ dbfn_close(dbm); } printf("\n"); return 0; }
int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("Naming_Test")); ACE_TCHAR temp_file [BUFSIZ]; ACE_Naming_Context *ns_context = 0; ACE_NEW_RETURN (ns_context, ACE_Naming_Context, -1); ACE_Name_Options *name_options = ns_context->name_options (); name_options->parse_args (argc, argv); /* ** NOTE! This is an experimental value and is not magic in any way. It ** works for me, on one system. It's needed because in the particular ** case here where the underlying mmap will allocate a small area and ** then try to grow it, it always moves it to a new location, which ** totally screws things up. I once tried forcing the realloc to do ** MAP_FIXED but that's not a good solution since it may overwrite other ** mapped areas of memory, like the heap, or the C library, and get very ** unexpected results. (Steve Huston, 24-August-2007) */ # if defined (linux) && defined (__x86_64__) name_options->base_address ((char*)0x3c00000000); #endif bool unicode = false; #if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR)) unicode = true; #endif /* ACE_WIN32 && ACE_USES_WCHAR */ if (unicode && name_options->use_registry () == 1) { name_options->namespace_dir (ACE_TEXT ("Software\\ACE\\Name Service")); name_options->database (ACE_TEXT ("Version 1")); } else { const ACE_TCHAR* pname = ACE::basename (name_options->process_name (), ACE_DIRECTORY_SEPARATOR_CHAR); // Allow the user to determine where the context file will be // located just in case the current directory is not suitable for // locking. We don't just set namespace_dir () on name_options // because that is not sufficient to work around locking problems // for Tru64 when the current directory is NFS mounted from a // system that does not properly support locking. ACE_TCHAR temp_dir [MAXPATHLEN]; if (ACE::get_temp_dir (temp_dir, MAXPATHLEN - 15) == -1) // -15 for ace-file-XXXXXX { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Temporary path too long, ") ACE_TEXT ("defaulting to current directory\n")), -1); } else { ACE_OS::chdir (temp_dir); } ACE_OS::strcpy (temp_file, pname); ACE_OS::strcat (temp_file, ACE_TEXT ("XXXXXX")); // Set the database name using mktemp to generate a unique file name name_options->database (ACE_OS::mktemp (temp_file)); } if (ns_context->open (ACE_Naming_Context::PROC_LOCAL, 1) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ns_context->open (PROC_LOCAL) %p\n"), ACE_TEXT ("failed")), -1); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("time to test %d iterations using %s\n"), ACE_NS_MAX_ENTRIES, name_options->use_registry () ? ACE_TEXT ("Registry") : ACE_TEXT ("ACE"))); ACE_Profile_Timer timer; timer.start (); // Add some bindings to the database test_bind (*ns_context); print_time (timer, "Binds"); timer.start (); // Should find the entries test_find (*ns_context, 1, 0); print_time (timer, "Successful Finds"); timer.start (); // Rebind with negative values test_rebind (*ns_context); print_time (timer, "Rebinds"); timer.start (); // Should find the entries test_find (*ns_context, -1, 0); print_time (timer, "Successful Finds"); timer.start (); // Should not find the entries test_find_failure (*ns_context); print_time (timer, "UnSuccessful Finds"); timer.start (); // Remove all bindings from database test_unbind (*ns_context); print_time (timer, "Unbinds"); ACE_OS::sprintf (temp_file, ACE_TEXT ("%s%s%s"), name_options->namespace_dir (), ACE_DIRECTORY_SEPARATOR_STR, name_options->database ()); delete ns_context; // Remove any existing files. No need to check return value here // since we don't care if the file doesn't exist. ACE_OS::unlink (temp_file); ACE_END_TEST; return 0; }
static void a2dp_sig_thread(void *d) { struct bluetooth_data *data = d; a2dp_state_t state = data->state; int err = 0; struct timeval tv; struct timespec ts; #ifdef ENABLE_TIMING uint64_t begin, end; begin = get_microseconds(); #endif gettimeofday(&tv, (struct timezone *) NULL); ts.tv_sec = tv.tv_sec + (WRITE_TIMEOUT / 1000); ts.tv_nsec = (tv.tv_usec + (WRITE_TIMEOUT % 1000) * 1000L ) * 1000L; pthread_mutex_lock(&data->mutex); while (state != A2DP_STATE_STARTED) { if (state == A2DP_STATE_NONE) __set_command(data, A2DP_CMD_INIT); else if (state == A2DP_STATE_INITIALIZED) __set_command(data, A2DP_CMD_CONFIGURE); else if (state == A2DP_STATE_CONFIGURED) { __set_command(data, A2DP_CMD_START); } again: err = pthread_cond_timedwait(&data->client_wait, &data->mutex, &ts); if (err) { /* don't timeout if we're done */ if (data->state == A2DP_STATE_STARTED) { err = 0; break; } if (err == ETIMEDOUT) { DBG(" Time out"); break; } goto again; } if (state == data->state) goto again; state = data->state; if (state == A2DP_STATE_NONE) { err = ENODEV; break; } } pthread_mutex_unlock(&data->mutex); #ifdef ENABLE_TIMING end = get_microseconds(); print_time("signalling process took", begin, end); #endif data->signalling_thread = 0; DBG("error returned is %d", err); /* pthread_cond_timedwait returns positive errors */ return; }
bool SerialLineIn::dispatch(void) { bool handled = false; DateTime now = RTC.nowDateTime(); switch (toupper(*buf)) { case 'D': // Dyymmdd: Set date handled = true; if ( strlen(buf) == 1 ) { print_time(); break; } if ( strlen(buf) != 7 ) { printf_P(PSTR("SERL Format: Dyymmdd\n\r")); break; } now = DateTime(2000+conv2d(buf+1),conv2d(buf+3),conv2d(buf+5),now.hour(),now.minute(),now.second()); RTC.adjust(now); print_time(); break; case 'T': // Thhmmss: Set time handled = true; if ( strlen(buf) != 7 ) { printf_P(PSTR("SERL Format: Dyymmdd\n\r")); break; } now = DateTime(now.year(),now.month(),now.day(),conv2d(buf+1),conv2d(buf+3),conv2d(buf+5)); RTC.adjust(now); print_time(); break; case '@': handled = true; // Special time values if ( !strcmp(buf+1,"N") ) { uint32_t when = events.whenNext(); #ifdef HAVE_FIRE_CAMERA if ( fire_camera.is_valid() ) when = fire_camera.whenNext(); #endif RTC.adjust(when); print_time(); } else if ( !strcmp(buf+1,"1") ) { events.reset(); #ifdef HAVE_FIRE_CAMERA fire_camera.invalidate(); #endif RTC.adjust(events.whenNext()); print_time(); } else if ( !strcmp(buf+1,"0") ) { RTC.adjust(DateTime(2011,1,1,0,0,0).unixtime()); print_time(); } else printf_P(PSTR("SERL Error: Unknown @ value: %s"),buf+1); break; case 'E': // E: Print EEPROM handled = true; logger.play(); break; case 'F': // F: Free memory handled = true; printf_P(PSTR("FREE %u\n\r"),freeMemory()); break; } return handled; }
static int avdtp_write(struct bluetooth_data *data) { int ret = 0; struct rtp_header *header; struct rtp_payload *payload; uint64_t now; long duration = data->frame_duration * data->frame_count; #ifdef ENABLE_TIMING uint64_t begin, end, begin2, end2; begin = get_microseconds(); #endif header = (struct rtp_header *)data->buffer; payload = (struct rtp_payload *)(data->buffer + sizeof(*header) + data->sizeof_scms_t); memset(data->buffer, 0, sizeof(*header) + sizeof(*payload) + data->sizeof_scms_t); if (data->sizeof_scms_t) { data->buffer[sizeof(*header)] = data->scms_t_cp_header; } payload->frame_count = data->frame_count; header->v = 2; header->pt = 1; header->sequence_number = htons(data->seq_num); header->timestamp = htonl(data->nsamples); header->ssrc = htonl(1); data->stream.revents = 0; #ifdef ENABLE_TIMING begin2 = get_microseconds(); #endif ret = poll(&data->stream, 1, POLL_TIMEOUT); #ifdef ENABLE_TIMING end2 = get_microseconds(); print_time("poll", begin2, end2); #endif long ahead = 0; now = get_microseconds(); if (data->next_write) { ahead = data->next_write - now; #ifdef ENABLE_TIMING DBG("duration: %ld, ahead: %ld", duration, ahead); #endif if (ahead > 0) { /* too fast, need to throttle */ usleep(ahead); } } else { data->next_write = now; } if (ahead <= -CATCH_UP_TIMEOUT * 1000) { /* fallen too far behind, don't try to catch up */ VDBG("ahead < %d, reseting next_write timestamp", -CATCH_UP_TIMEOUT * 1000); data->next_write = 0; } else { data->next_write += duration; } if (ret == 1 && data->stream.revents == POLLOUT) { #ifdef ENABLE_TIMING begin2 = get_microseconds(); #endif ret = send(data->stream.fd, data->buffer, data->count, MSG_NOSIGNAL); #ifdef ENABLE_TIMING end2 = get_microseconds(); print_time("send", begin2, end2); #endif if (ret < 0) { /* can happen during normal remote disconnect */ VDBG("send() failed: %d (errno %s)", ret, strerror(errno)); } if (ret == -EPIPE) { bluetooth_close(data); } } else { /* can happen during normal remote disconnect */ VDBG("poll() failed: %d (revents = %d, errno %s)", ret, data->stream.revents, strerror(errno)); } /* Reset buffer of data to send */ data->count = sizeof(struct rtp_header) + sizeof(struct rtp_payload) + data->sizeof_scms_t; data->frame_count = 0; data->samples = 0; data->seq_num++; #ifdef ENABLE_TIMING end = get_microseconds(); print_time("avdtp_write", begin, end); #endif return 0; /* always return success */ }
void Screen13() { rtems_time_of_day time; rtems_status_code status; status = rtems_io_close( 0xffff, 0x0000, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_close with bad major number" ); puts( "TA1 - rtems_io_close - RTEMS_INVALID_NUMBER" ); status = rtems_io_control( 0xffff, 0x00000, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_close with bad major number" ); puts( "TA1 - rtems_io_control - RTEMS_INVALID_NUMBER" ); status = rtems_io_initialize( 0xffff, 0x00000, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_initialize with bad major number" ); puts( "TA1 - rtems_io_initialize - RTEMS_INVALID_NUMBER" ); status = rtems_io_open( 0xffff, 0x00000, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_open with bad major number" ); puts( "TA1 - rtems_io_open - RTEMS_INVALID_NUMBER" ); status = rtems_io_read( 0xffff, 0x00000, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_read with bad major number" ); puts( "TA1 - rtems_io_read - RTEMS_INVALID_NUMBER" ); status = rtems_io_write( 0xffff, 0x0ffff, NULL); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_io_write with bad major number" ); puts( "TA1 - rtems_io_write - RTEMS_INVALID_NUMBER" ); build_time( &time, 12, 31, 2000, 23, 59, 59, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_set - ", &time, " - RTEMS_SUCCESSFUL\n" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, " - RTEMS_SUCCESSFUL\n" ); build_time( &time, 12, 31, 1999, 23, 59, 59, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_set - ", &time, " - RTEMS_SUCCESSFUL\n" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, " - RTEMS_SUCCESSFUL\n" ); build_time( &time, 12, 31, 2100, 23, 59, 59, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_set - ", &time, " - RTEMS_SUCCESSFUL\n" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, " - RTEMS_SUCCESSFUL\n" ); build_time( &time, 12, 31, 2099, 23, 59, 59, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_set - ", &time, " - RTEMS_SUCCESSFUL\n" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, " - RTEMS_SUCCESSFUL\n" ); build_time( &time, 12, 31, 1991, 23, 59, 59, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_set - ", &time, " - RTEMS_SUCCESSFUL\n" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_set" ); print_time( "TA1 - rtems_clock_get_tod - ", &time, " - RTEMS_SUCCESSFUL\n" ); }
/* main program */ int main(int argc,char *argv[]) { // double **a=allocm_mat(2,2),**b=allocm_mat(2,2),**c=allocm_mat(2,2); // a[0][0]=1.0; a[0][1]=2.0; /* initialize a */ // a[1][0]=2.0; a[1][1]=1.0; // b[0][0]=1.0; b[0][1]=2.0; /* initialize b */ //b[1][0]=3.0; b[1][1]=4.0; // c[0][0]=0.0; c[0][1]=0.0; /* initialize b */ // c[1][0]=0.0; c[1][1]=0.0; char * filenamea; char * filenameb; char * filenamec; /* read in size of matrix, number of processors */ if (argc!=5) { filenamea = "1000-A.mat"; filenameb = "1000-B.mat"; NUM_THREADS = 8; filenamec= "1000-C.mat"; } else { filenamea = argv[1]; filenameb = argv[2]; NUM_THREADS = atoi(argv[3]); filenamec= argv[4]; } read_matrix(filenamea,filenameb); pthread_mutex_init(&mc_mutex,NULL); /* initialize the lock */ double wall0 = get_wall_time(); mat_mult(); /* calculate A*B */ // printf("%8.4f%8.4f\n",c[0][0],c[0][1]); /* 7.0000 10.0000 */ // printf("%8.4f%8.4f\n",c[1][0],c[1][1]); /* 5.0000 8.0000 */ double wall1 = get_wall_time(); print_time(wall1-wall0); print_matrix(filenamec, mat_c, m_dim, p_dim); pthread_mutex_destroy(&mc_mutex); return(0); }
/* ------------------------------------------------------------- * MAIN: * Check all parameters passed on the command line, calculate * the date to be displayed, and display it. * ------------------------------------------------------------- */ int main( int argc, char **argv, char **envp ) { struct tm *time_var; time_t time_number; signed long time_offset; char *ptr; int i, date_override; char saved_command[MAX_PARM_LEN+1]; char saved_format[MAX_MASK_LEN+1]; char saved_startdate_override[13]; /* YYYYMMDDHHMM_ */ /* * Check to see what command line parameters we have */ if (argc < 2) { printf( "%s: (c)Mark Dickinson, 2001\n", argv[0] ); show_syntax(); exit( 1 ); } time_offset = 0; /* default, and start point for adjustments */ date_override = 0; /* use current system date and time */ strcpy(saved_format,"YYYYMMDD"); /* default */ i = 1; /* use a while loop instead of a for loop as we may * increment the counter ourselves */ while ( i < argc ) { ptr = argv[i]; i++; if (i >= argc) { printf( "Missing value for %s\n", ptr ); exit( 1 ); } strncpy( saved_command, ptr, MAX_PARM_LEN ); ptr = argv[i]; if (strncmp("-format",saved_command,7) == 0) { validate_format( ptr, saved_format ); } else if (strncmp("-workingdate",saved_command,12) == 0) { date_override = 1; strncpy( saved_startdate_override, ptr, 12 ); /* YYYYMMDDHHMM */ } else { time_offset = time_offset + check_parameter( saved_command, ptr ); } i++; } /* * Work out the new time and print the result. */ if (date_override == 1) { /* have to get the dst flag setting for this */ time_number = time(0); time_var = localtime( &time_number ); /* then workout the callers passed time */ time_number = make_time( (char *)&saved_startdate_override, time_var->tm_isdst ); } else { time_number = time(0); /* time now in seconds from 00:00, Jan 1 1970 */ } time_number = time_number + time_offset; if (strcmp("CTIME",saved_format) == 0) { printf( "%s", ctime( &time_number ) ); } else { time_var = localtime( &time_number ); print_time( time_var, saved_format ); } exit( 0 ); } /* end main */
void sigio_handler(int sig) { print_time(); }
int main(int argc, char *argv[]) { Globals globales; clock_t render_ticks; //tInitDataTicks, //tCleanDataTicks; std::string scene_desc_file, output_file, output_file_dir, output_file_path; // Redirigimos std::clog a un archivo de texto. CLog_Redir clogredir("log.txt"); // Y configuramos el logger. LOGCFG.headers = true; LOGCFG.level = DEBUG; bool end_status; LOG() << "main - Comprobando argumentos."; if(argc > 1) { for(int i = 1; i < argc; ++i) { if(argv[i][0] == '-') { // Procesamos las opciones. if(std::string(argv[i]) == "-h" || std::string(argv[i]) == "--help") { muestra_ayuda(argv[0]); return 0; } else if(std::string(argv[i]) == "-t" || std::string(argv[i]) == "--test") { globales.options |= Global_opts::kglb_do_test; } else if(std::string(argv[i]) == "-s" || std::string(argv[i]) == "--showaabb") { globales.options |= Global_opts::kglb_show_aabb; } else if(std::string(argv[i]) == "-c" || std::string(argv[i]) == "--contrib") { globales.options |= Global_opts::kglb_do_contrib; } } else { // Se proporciona fichero, anulamos el test. globales.options &= ~Global_opts::kglb_do_test; if(scene_desc_file.empty()) // Fichero de escena a renderizar scene_desc_file.assign(argv[i]); else // Fichero donde guardar la imagen output_file.assign(argv[i]); } } } LOG() << "main - ... hecho."; if((scene_desc_file.empty() || (argc < 2)) && !(globales.options & Global_opts::kglb_do_test)) { muestra_ayuda(argv[0]); return 0; } else { if(globales.options & Global_opts::kglb_do_test) { Test test; end_status = test.launch_test(); } else { LOG() << "main - Leyendo archivo..."; end_status = parse_file(&globales, scene_desc_file); LOG() << "main - ... hecho."; if(end_status) { render_ticks = clock(); // Start render loop if(globales.options & Global_opts::kglb_do_contrib) end_status = start_render_v2(&globales); else end_status = start_render(&globales); render_ticks = clock() - render_ticks; print_time("\n\nRender Time: ", static_cast<float>(render_ticks)/CLOCKS_PER_SEC); print_statistics(); if(output_file.empty()) { std::string temp; // Averiguamos el nombre del fichero. image_file_name(scene_desc_file, temp); // Añadimos la extension. output_file = temp + ".ppm"; output_file_dir = temp + "_dir.ppm"; output_file_path = temp + "_path.ppm"; } if(globales.options & Global_opts::kglb_do_contrib) globales.image->create_final_img(); globales.image->gamma_correct(2.2f); save_file(&globales, output_file, 0); if(globales.options & Global_opts::kglb_do_contrib) { save_file(&globales, output_file_dir, 1); save_file(&globales, output_file_path, 2); } } } } if(end_status) return 0; else return -1; }
pullmenu() { char scr[1200],s[80]; int x,y,i,goon,c; goon=1; onwait(); x=wherex(); y=wherey(); hidemouse(); gettext(13,5,61,16,scr); puttext(13,5,61,16,USERED); showmouse(); while(goon) { gotoxy(23,12); cprintf(" "); gotoxy(23,12); textcolor(LIGHTCYAN); inputlocal(s,30); strupr(s); switch(s[0]) { case 'Q': goon=0; break; case '1': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old Name: "); textcolor(LIGHTGRAY); cprintf("%s",user.name); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New Name: "); inputlocal(s,40); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); if(s[0]!=0 || stricmp(user.name,s)==0) { if(!ver_user(s)) strcpy(user.name,s); } break; case '2': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old User SL: "); textcolor(LIGHTGRAY); cprintf("%d",user.sl); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New User SL: "); textcolor(LIGHTGRAY); inputlocal(s,20); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); i=atoi(s); if(i >= 0 || i <= 255) user.sl=i; break; case '3': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old File SL: "); textcolor(LIGHTGRAY); cprintf("%d",user.filesl); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New File SL: "); textcolor(LIGHTGRAY); inputlocal(s,20); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); i=atoi(s); if(i >= 0 || i <= 255) user.filesl=i; break; case '4': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old Note: "); textcolor(LIGHTGRAY); cprintf("\"%s\"",user.note); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New Note: "); textcolor(LIGHTGRAY); inputlocal(s,40); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); if(s[0]!=0) strcpy(user.note,s); break; case '5': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old Time: "); textcolor(LIGHTGRAY); cprintf("%d",print_time()/60); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New Time: "); textcolor(LIGHTGRAY); inputlocal(s,20); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); if(s[0]!=0) { user.timeall=atoi(s)*60; timeleft=atoi(s)*60; } break; case '6': i=1; gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("User Flags: "); while(i) { goon=0; while(goon < 10) { gotoxy(27+goon,14); if(user.flags[goon]) { textcolor(LIGHTRED); cprintf("%d",goon); } else { textcolor(LIGHTGRAY); cprintf("%d",goon); } goon++; } gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("Enter flag to toggle [Q/Quit]: "); do { c=getch(); if(c=='Q' || c=='q') { gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); i=0; } } while(c < '0' || c > '10'); gotoxy(37,15); cprintf("%c",c); if(user.flags[c-48]) user.flags[c-48]=0; else user.flags[c-48]=1; gotoxy(37,15); cprintf(" "); } break; case '7': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old Password: "******"%s",user.pass); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New Password: "******" "); gotoxy(15,15); cprintf(" "); if(s[0]!=0) strcpy(user.pass,s); break; case '8': gotoxy(15,14); textcolor(LIGHTBLUE); cprintf("Old Filepoints: "); textcolor(LIGHTGRAY); cprintf("%d",user.filepoints); gotoxy(15,15); textcolor(LIGHTGREEN); cprintf("New Filepoints: "); inputlocal(s,40); gotoxy(15,14); cprintf(" "); gotoxy(15,15); cprintf(" "); if(s[0]!=0) user.filepoints=atoi(s); break; } } writeuser(); puttext(13,5,61,16,scr); gotoxy(x,y); offwait(); }
void set_time(struct time_t* time){ memcpy(¤t, time, sizeof(struct time_t)); print_time(); }
int main(int argc, char **argv) { char dict_path[] = "word.txt"; char text_path[] = "mogu.txt"; char new_word[] = "new_word"; int hash_size = 50; unsigned char buf[8192]; int fd; ssize_t read_size; int j; fkw_word_list_t *word_list; fkw_word_t *start; fkw_str_t text; fkw_dict_array_t *dict_array; dict_array = fkw_dict_array_init(hash_size); print_time("load dict start"); dict_array = fkw_load_dict(dict_array, dict_path); fkw_add_dict_word(dict_array, new_word, strlen(new_word)); print_time("load dict end"); fd = open(text_path, O_RDONLY); read_size = read(fd, buf, sizeof(buf)); printf("read_size=%d\n", read_size); text.len = read_size; text.data = buf; print_time("before seg"); word_list = fkw_full_seg(&text, dict_array); print_time("end seg"); //return; if (word_list->start == NULL){ close(fd); printf("no found"); return 0; } start = word_list->start; while(start){ printf("%s ", start->value.data); start = start->next; } if (fkw_dict_search(dict_array, new_word, strlen(new_word))){ printf("found new_word\n"); } else { printf("no found new word\n"); } // free res close(fd); fkw_free_dict(&dict_array); fkw_free_word_list(&word_list); return 0; }
static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch, struct problem_context *ctx) { e2fsck_t e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL; if (!ctx) goto no_context; switch (ch) { case '%': fputc('%', stdout); break; case 'b': #ifdef EXT2_NO_64_TYPE printf("%u", (unsigned long) ctx->blk); #else printf("%llu", (unsigned long long) ctx->blk); #endif break; case 'B': #ifdef EXT2_NO_64_TYPE printf("%d", ctx->blkcount); #else printf("%lld", (long long)ctx->blkcount); #endif break; case 'c': #ifdef EXT2_NO_64_TYPE printf("%u", (unsigned long) ctx->blk2); #else printf("%llu", (unsigned long long) ctx->blk2); #endif break; case 'd': printf("%u", ctx->dir); break; case 'g': printf("%d", ctx->group); break; case 'i': printf("%u", ctx->ino); break; case 'j': printf("%u", ctx->ino2); break; case 'm': printf("%s", error_message(ctx->errcode)); break; case 'N': #ifdef EXT2_NO_64_TYPE printf("%u", ctx->num); #else printf("%llu", (long long)ctx->num); #endif break; case 'p': print_pathname(fs, ctx->ino, 0); break; case 'P': print_pathname(fs, ctx->ino2, ctx->dirent ? ctx->dirent->inode : 0); break; case 'q': print_pathname(fs, ctx->dir, 0); break; case 'Q': print_pathname(fs, ctx->dir, ctx->ino); break; case 'S': printf("%u", get_backup_sb(NULL, fs, NULL, NULL)); break; case 's': printf("%s", ctx->str ? ctx->str : "NULL"); break; case 't': print_time((time_t) ctx->num); break; case 'T': print_time(e2fsck_ctx ? e2fsck_ctx->now : time(0)); break; case 'X': #ifdef EXT2_NO_64_TYPE printf("0x%x", ctx->num); #else printf("0x%llx", (long long)ctx->num); #endif break; default: no_context: printf("%%%c", ch); break; } }