static void copy_into_tab(char **board, char *str, int flag) { int i; int j; init_counters(&i, &j); while (*str) { while (*str == ' ' || *str == '\t') str++; while (*str && ((*str != ' ' && *str != '\t' && flag == 0) || flag != 0)) { flag = check_quote(flag, *str); board[i][j++] = *str; str++; if (flag == 3 || flag == 4 || flag == 6) flag = 0; if (!(*str) || ((*str == '\t' || *str == ' ') && flag == 0)) { board[i++][j] = '\0'; j = 0; } } } board[i] = NULL; }
static int word_counter(char *str, int flag) { int i; int word_number; init_counters(&i, &word_number); while (str[i]) { while (str[i] == ' ' || str[i] == '\t') i++; if (str[i] && str[i] != ' ' && str[i] != '\t') { if (flag == 0) word_number++; while (str[i] && ((flag == 0 && str[i] != '\t' && str[i] != ' ') || (flag == 1 || flag == 2 || flag == 5))) { if (str[i] == '\'' || str[i] == '\"' || str[i] == '`') flag = check_quote(flag, str[i]); if (flag == 3 || flag == 4 || flag == 6) flag = 0; i++; } } } return (word_number); }
void nbspstats_update(void){ time_t now; now = time(NULL); /* * This function is now called from the periodic module, and therefore * this should not be used. * * if(difftime(now, g.nbspstats.time) < (double)g.nbspstats_logperiod_s) * return; */ update_stats_rtx_index(); g.nbspstats.time = now; nbspstats_report(g.statusfile); init_counters(); /* does not clear rtx_index */ }
static void do_test(int num, int thread_num) { flog_set_flush_interval(2); flog_set_level(FLOG_LEVEL_DEBUG); flog_set_buffer_size(MAX_BUFF_SIZE_PER_THREAD); if ( log_mode == FLOG_ASYNC_MODE ) { printf("current buffer size per-thread = %lu\n", flog_get_buffer_size()); } flog_set_roll_size(FILE_ROLL_SIZE); flog_register_event_callback(get_log_event); init_counters(); sleep(1); unsigned long long start_time = ftime_gettime(); int end = num / thread_num; pthread_t tid[thread_num]; int i = 0; for ( i = 0; i < thread_num; i++ ) { pthread_create(&tid[i], NULL, write_log, (void*)&end); } for ( i = 0; i < thread_num; i++ ) { pthread_join(tid[i], NULL); } unsigned long long end_time = ftime_gettime(); unsigned long long diff_usec = end_time - start_time; printf("pid=%d, tid=%lu, call interface time cost (usec):%llu write_msg:%d miss_msg:%d miss_rate:%f final:%f count/s\n", getpid(), pthread_self(), diff_usec, num, buff_full_count, (double)buff_full_count/(double)num, (double)num/((double)diff_usec/1000000)); printf("metrics:\n"); printf("\terror_write_count: %d\n", error_write_count); printf("\terror_async_push_count: %d\n", error_async_push_count); printf("\terror_async_pop_count: %d\n", error_async_pop_count); printf("\tlog_truncated_count: %d\n", log_truncated_count); printf("\tbuffer_full_count: %d\n", buff_full_count); }
int main(void) { DDRC |= (1<<PORTC6) | (1<<PORTC7); //init LEDs //servoTx; SERVO_init(); //Init servos USART_init(); init_counters(); set_counter_1(10000); initvar(); sei(); SERVO_update_EEPROM(BROADCASTING_ID); //move_to_std(); // ------ TESTCODE FOR READING SERVO ------- //servoGoto(1, 3.14/3, 0x200); SERVO_update_EEPROM(BROADCASTING_ID); // NOTE: needs to run once for SERVO_get position to work //---------------------------- _delay_ms(3000); reset_counter_1(); set_counter_1(3000); while(1) { /* uint8_t r = USART_getRotation(); uint8_t s = USART_getSpeed(); uint8_t d = USART_getDirection(); if(s != 0 || r != 50) { std_pos_flag = 0; reset_counter_1(); } move_robot(d, r, s); if(r == 50 && s == 0 && d == 0) { _delay_ms(50); //PORTD ^= (1<<PORTD5); cli(); USART_send_ready(); sei(); } */ /*change_z(-130); move_to_std(); for(int i = 0; i < 5; ++i) { move_robot(0,50,100); //_delay_ms(2000); } _delay_ms(1000); move_to_std(); _delay_ms(1000); */ climb(); //climb_all_one_leg(); //SERVO_update_data(12); //USART_SendValue(SERVO_get_load()); USART_DecodeRxFIFO(); _delay_ms(200); } }
void nbspstats_init(void){ init_counters(); g.nbspstats.products_rtx_index = 0; g.nbspstats.time = time(NULL); }
int main(void) { LED_INIT; //servoTx; sei(); USART_init(); MPU_init(); SERVO_init(); init_counters(); initvar(); SERVO_update_EEPROM(BROADCASTING_ID); wait(10); move_to_std(); wait_until_gyro_stable(); LED0_ON; USART_send_message("Gyro Stable"); // ------ TESTCODE FOR READING SERVO ------- //servoGoto(1, 3.14/3, 0x200); SERVO_update_EEPROM(BROADCASTING_ID); // NOTE: needs to run once for SERVO_get position to work //---------------------------- reset_counter_1(); set_counter_1(3000); uint8_t readyCounter = 0; while(1) { MPU_update(); if(USART_get_turn_flag()) { turn_degrees(USART_get_turn_angle(), USART_get_turn_dir()); } if(USART_get_climb_flag()) { climb(); } uint8_t r = USART_getRotation(); uint8_t s = USART_getSpeed(); uint8_t d = USART_getDirection(); if(s != 0 || r != 50) { std_pos_flag = 0; reset_counter_1(); readyCounter = 3; } move_robot(d, r, s); if(r == 50 && s == 0 && d == 0 && readyCounter) { cli(); USART_send_ready(); sei(); readyCounter--; } if(move_to_std_flag == 1) { move_to_std_flag = 0; move_to_std(); } /*climb(); for(int i = 0; i < 10; ++i) { move_robot(0,50,100); //wait(2000); } */ /* change_z(-120); move_to_std(); turn_degrees(180,1); // Takes a predecided number of steps forward // This is good when testing different things. wait(100); for(int i = 0; i < 10; ++i) { move_robot(0,50,100); //wait(2000); } */ USART_decode_rx_fifo(); } }
void main(void) { unsigned char cal_length, cal_dia; unsigned int length, dia, dia_offset, latest_l, latest_d; unsigned int tot_acc, mass_acc, timb_acc; unsigned int tot_num, mass_num, timb_num; unsigned int count1, count2, count3; OSCCON = 255; OSCTUNEbits.PLLEN = 1; TRISA = 0b00011111; PORTA = 0; ADCON1 = 0b00001101; TRISB = 0; PORTB = 0; TRISC = 0b00010000; PORTC = 0b00000000; TRISD = 0; PORTD = 0; TRISE = 0; PORTE = 0; init_display(); init_counters(); LED1 = 0; LED2 = 0; LED3 = 0; latest_l = 0; latest_d = 0; tot_acc = 0; tot_num = 0; timb_acc = 0; timb_num = 0; mass_acc = 0; mass_num = 0; cal_length = read_ad(0); cal_dia = read_ad(1); dia_offset = 2; while (1) { length = read_length(cal_length); dia = dia_offset + read_diameter(cal_dia); write_length(length); write_dia(dia); if (!CALIBRATE) { count1 = read_counter(1); count2 = read_counter(2); count3 = read_counter(3); cal_length = read_ad(0); cal_dia = read_ad(1); write_debug_info(cal_length, cal_dia, count1, count2, count3); } if (!RESET_DIA) { reset_dia(); } if (!RESET_LENGTH) { delay(20000); delay(20000); if (!RESET_LENGTH) { LED1 = 1; if (length >= 100) { tot_num = tot_num + 1; tot_acc = tot_acc + length / 100; latest_l = length; latest_d = dia; if (dia >= 15) { timb_num = timb_num + 1; timb_acc = timb_acc + length / 100; } else { mass_num = mass_num + 1; mass_acc = mass_acc + length / 100; } } reset_length(); while (!RESET_LENGTH) { write_length(0); write_dia(0); write_length(8); write_dia(8); } write_stats(latest_l, latest_d, tot_num, tot_acc, timb_num, timb_acc, mass_num, mass_acc); LED1 = 0; } } } }
/** Run the daemon. * @param[in] argc Number of arguments in \a argv. * @param[in] argv Arguments to program execution. */ int main(int argc, char **argv) { CurrentTime = time(NULL); thisServer.argc = argc; thisServer.argv = argv; thisServer.uid = getuid(); thisServer.euid = geteuid(); #ifdef MDEBUG mem_dbg_initialise(); #endif #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE) set_core_limit(); #endif umask(077); /* better safe than sorry --SRB */ memset(&me, 0, sizeof(me)); memset(&me_con, 0, sizeof(me_con)); cli_connect(&me) = &me_con; cli_fd(&me) = -1; parse_command_line(argc, argv); if (chdir(dpath)) { fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, strerror(errno)); return 2; } if (!set_userid_if_needed()) return 3; /* Check paths for accessibility */ if (!check_file_access(SPATH, 'S', X_OK) || !check_file_access(configfile, 'C', R_OK)) return 4; if (!init_connection_limits()) return 9; close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF))); /* daemon_init() must be before event_init() because kqueue() FDs * are, perversely, not inherited across fork(). */ daemon_init(thisServer.bootopt & BOOT_TTY); #ifdef DEBUGMODE /* Must reserve fd 2... */ if (debuglevel >= 0 && !(thisServer.bootopt & BOOT_TTY)) { int fd; if ((fd = open("/dev/null", O_WRONLY)) < 0) { fprintf(stderr, "Unable to open /dev/null (to reserve fd 2): %s\n", strerror(errno)); return 8; } if (fd != 2 && dup2(fd, 2) < 0) { fprintf(stderr, "Unable to reserve fd 2; dup2 said: %s\n", strerror(errno)); return 8; } } #endif event_init(MAXCONNECTIONS); setup_signals(); feature_init(); /* initialize features... */ log_init(*argv); set_nomem_handler(outofmemory); initload(); init_list(); init_hash(); init_class(); initwhowas(); initmsgtree(); initstats(); /* we need this for now, when we're modular this should be removed -- hikari */ ircd_crypt_init(); motd_init(); if (!init_conf()) { log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s", configfile); return 7; } if (thisServer.bootopt & BOOT_CHKCONF) { if (dbg_client) conf_debug_iline(dbg_client); fprintf(stderr, "Configuration file %s checked okay.\n", configfile); return 0; } debug_init(thisServer.bootopt & BOOT_TTY); if (check_pid()) { Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork")); exit(2); } init_server_identity(); uping_init(); stats_init(); IPcheck_init(); timer_add(timer_init(&connect_timer), try_connections, 0, TT_RELATIVE, 1); timer_add(timer_init(&ping_timer), check_pings, 0, TT_RELATIVE, 1); timer_add(timer_init(&destruct_event_timer), exec_expired_destruct_events, 0, TT_PERIODIC, 60); timer_add(timer_init(&mute_timer), check_expired_mutes, 0, TT_PERIODIC, 30); CurrentTime = time(NULL); SetMe(&me); cli_magic(&me) = CLIENT_MAGIC; cli_from(&me) = &me; make_server(&me); cli_serv(&me)->timestamp = TStime(); /* Abuse own link timestamp as start TS */ cli_serv(&me)->prot = atoi(MAJOR_PROTOCOL); cli_serv(&me)->up = &me; cli_serv(&me)->down = NULL; cli_handler(&me) = SERVER_HANDLER; SetYXXCapacity(&me, MAXCLIENTS); cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime; hAddClient(&me); write_pidfile(); init_counters(); Debug((DEBUG_NOTICE, "Server ready...")); log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready"); event_loop(); return 0; }
int main() { /* * The tests will be: * Feeding too much data. * Recovering and feeding an empty message. * Feeding a normal message. * Feeding a full-length message. * Feeding a message with separated \r and \n in the middle. * Feeding too much data again. * Recovering and feeding a normal message. */ static const char *blocks[] = { "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxx\r\n\r\nPRIVMSG gregor :We don't want any bugs ", "in here\r\n" "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789", "0123456789\r\n" "This is \ra weird message\r\r\n", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxx\r\n", "JOIN #kafka\r\n", NULL }; int i; int pipefd[2]; ssize_t l; int ret; ssize_t wret; struct reader r; struct buffer b; ret = pipe(pipefd); assert(ret == 0); ret = nonblock(pipefd[0]); assert(ret == 0); ret = buffer_create(&b, MAX_MESSAGE_LEN); assert(ret == 0); reader_init(&r, pipefd + 0, test_callback, &b); init_counters(); for (i = 0; blocks[i] != NULL; ++i) { l = (ssize_t)strlen(blocks[i]); wret = write(pipefd[1], blocks[i], l); assert(wret == l); read_and_callback(&r, NULL); } close(pipefd[1]); ++tests_counter; if (read_and_callback(&r, NULL) != 0) { printf("Unable to correctly receive EOF\n"); ++tests_failed; } else ++tests_passed; close(pipefd[0]); ret = buffer_destroy(&b); assert(ret == 0); return tests_summary(); }