main() { unsigned int m[5] ; int i, ii ; for ( i = 0 ; i < 5*32 ; i++ ) { for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0xffffffff ; } reset_mask( m, i ) ; for ( ii = 4 ; ii >= 0 ; ii-- ) { printf(" %08x ", m[ii]) ; } printf("\n") ; } for ( i = 0 ; i < 5*32 ; i++ ) { for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0x0 ; } set_mask( m, i ) ; for ( ii = 4 ; ii >= 0 ; ii-- ) { printf(" %08x ", m[ii]) ; } printf("\n") ; } for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0x0 ; } set_mask( m, 82 ) ; for ( i = 0 ; i < 5*32 ; i++ ) { printf("%d %0d\n",i,get_mask(m,i) ) ; } }
void pin_function(PinName pin, int function) { volatile uint32_t *pio_func_reg; /* Set the function for the given pin */ pio_func_reg = func_reg (pin); *pio_func_reg = (*pio_func_reg & ~(clr_mask(pin))) | set_mask(pin, function); /* Power the pin */ #ifdef TARGET_SARA_NBIOT /* On Sara NBIoT, GPIO pin 19 has to be high to power GPIO pins 0 to 10 */ if ((pin >= p0) && (pin <= p10)) { /* Grab pin 19 as a GPIO if we don't have it already */ if (get_owner(p19) != 0x03) { pio_func_reg = func_reg (p19); *pio_func_reg = (*pio_func_reg & ~(clr_mask(p19))) | set_mask(p19, 1); /* 1 == PIN_FUNCTION_GPIO */ MBED_ASSERT (get_owner(p19) == 0x03); } /* Set pin 19 to be an output and to be high */ GPIO_DIR |= (1ul << p19); GPIO_OUT_BITSET = (1ul << p19); /* Note: the level on pins 6 to 10 is controlled by the protocol * processor to be the VCC level required by the SIM. The * application has no control over this. */ } /* The power to GPIOs 11 to 19 is fed directly from pin 51 of the module */ #endif }
void mbc3_timer(GBContext *gb) { MBC3Context *mbc = (MBC3Context*)gb->mbc_context; if (!mbc->is_latched && !(mbc->rtc[MBC3_RTC_FLAGS] & MASK_RTC_HALT)) { mbc->rtc[MBC3_RTC_SECONDS]++; while (mbc->rtc[MBC3_RTC_SECONDS] >= 60) { mbc->rtc[MBC3_RTC_SECONDS] -= 60; mbc->rtc[MBC3_RTC_MINUTES]++; while (mbc->rtc[MBC3_RTC_MINUTES] >= 60) { mbc->rtc[MBC3_RTC_MINUTES] -= 60; mbc->rtc[MBC3_RTC_HOURS]++; while (mbc->rtc[MBC3_RTC_HOURS] >= 24) { mbc->rtc[MBC3_RTC_HOURS] -= 24; mbc->rtc[MBC3_RTC_DAYLOW]++; if (mbc->rtc[MBC3_RTC_DAYLOW] == 0) { if (mbc->rtc[MBC3_RTC_FLAGS] & MASK_RTC_DAYHIGH) { set_mask(mbc->rtc[MBC3_RTC_FLAGS], MASK_RTC_OVERFLOW, 0xFF); } else { set_mask(mbc->rtc[MBC3_RTC_FLAGS], MASK_RTC_DAYHIGH, 0xFF); } } } } } //printf("%d:%d:%d\n", mbc->rtc[MBC3_RTC_HOURS], mbc->rtc[MBC3_RTC_MINUTES], mbc->rtc[MBC3_RTC_SECONDS]); } }
// h = train(dummy, X,Y, var_cat_mask, T,J,v, node_size); void train(int nlhs,mxArray *plhs[], int nrhs,const mxArray *prhs[]) { /* Input */ MLData tr; // training tr X set_X(prhs[1], tr.X); // response Y set_Y(prhs[2], tr.Y); // var_cat_mask set_mask(prhs[3], tr.var_type); // T int T = (int)mxGetScalar(prhs[4]); // J int J = (int)mxGetScalar(prhs[5]); // v double v = (double)mxGetScalar(prhs[6]); // node_size int node_size = (int)mxGetScalar(prhs[7]); /* train */ tr.problem_type = PROBLEM_CLS; tr.preprocess(); booster_t* pbooster = new booster_t; pbooster->param_.T = T; pbooster->param_.v = v; pbooster->param_.J = J; pbooster->param_.ns = node_size; pbooster->train(&tr); /*Output*/ plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); double* pp = mxGetPr(plhs[0]); *pp = (long long) pbooster; }
static void cancel_fd(oop_source *x,int fd,oop_event event) { if (fd < array_size) { struct file_handler * const h = &array[fd]; h->f[event] = NULL; set_mask(fd); } }
int set_addr(const char *name, char *addr_string) { struct sockaddr_in addr; addr.sin_family = AF_INET; char *slash = strchr(addr_string, '/'); if(slash) { /* we're given the netmask here, so do things */ *slash = 0; slash++; int smask = strtol(slash, 0, 10); if(smask < 1 || smask > 32) { fprintf(stderr, "ifc: invalid netmask\n"); return -1; } char tmp[32]; convert_mask(smask, tmp); if(set_mask(name, tmp)) { fprintf(stderr, "ifc: unable to set netmask\n"); return -1; } } if(inet_aton(addr_string, &addr.sin_addr) == 0) { fprintf(stderr, "ifc: invalid address '%s'.\n", addr_string); return -1; } return do_set_addr(name, &addr); }
int main(int argc, char *argv[]) { int matrix[M][N] = { {3, 2, 1, 0, 4}, {1, 0, 1, 0, 4}, {1, 1, 3, 1, 3}, {1, 1, 2, 3, 2} }; int mask[M][N]; prepare_mask(matrix, mask); find_zero(matrix, mask); printf("BEFORE\n"); print_matrix(matrix); set_mask(matrix, mask); /* {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {1, 0, 3, 0, 3}, {1, 0, 2, 0, 2} */ printf("AFTER\n"); print_matrix(matrix); return 0; }
void RankHardLossLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* label = bottom[1]->cpu_data(); int count = bottom[0]->count(); int num = bottom[0]->num(); int dim = bottom[0]->count() / bottom[0]->num(); RankParameter rank_param = this->layer_param_.rank_param(); int neg_num = rank_param.neg_num(); // 4 int pair_size = rank_param.pair_size(); // 5 float hard_ratio = rank_param.hard_ratio(); float rand_ratio = rank_param.rand_ratio(); float margin = rank_param.margin(); Dtype* dis_data = dis_.mutable_cpu_data(); Dtype* mask_data = mask_.mutable_cpu_data(); set_mask(bottom); Dtype loss = 0; int cnt = neg_num * num / pair_size * 2; for(int i = 0; i < num; i += pair_size) { for(int j = 0; j < num; j ++) { if(mask_data[i * num + j] == 0) continue; Dtype tloss1 = max(Dtype(0), dis_data[i * num + i + 1] - dis_data[i * num + j] + Dtype(margin)); Dtype tloss2 = max(Dtype(0), dis_data[i * num + i + 1] - dis_data[(i + 1) * num + j] + Dtype(margin)); loss += tloss1 + tloss2; } } loss = loss / cnt; top[0]->mutable_cpu_data()[0] = loss; }
void set_change_member(unsigned *set, int k, boolean value) { int ndx = set_ndx(k); unsigned int mask = set_mask(k); asc_assert(NULL != set); if(value) { set[ndx] |= mask; } else { set[ndx] &= ~mask; } }
int ft_putwchar(wchar_t c, int count) { char **final; FT_INIT(char *, bin_value, ft_strnew(33)); FT_INIT(int, i, 0); FT_INIT(int, octet, 0); bin_value = ft_itoa_base((int)c, 2); if (ft_strlen(bin_value) <= 7) return (ftp_putchar((char)c)); else if (ft_strlen(bin_value) <= 11) final = set_mask(bin_value, MASK_2); else if (ft_strlen(bin_value) > 11 && ft_strlen(bin_value) <= 16)
ui::menu::menu() { set_position(window::center.x,window::center.y); fill_color=default_fillcolor; border_color=default_bordercolor; set_texture(default_texture); set_mask(default_mask); set_title("menu"); title.set_font("helvetica",18); subtitle.set_font("helvetica",12); subtitle.hide(); layout=default_layout; spacing=default_spacing; margin=default_margin; bordered=true; std::clog<<"object#"<<number<<"(menu)"<<" created.\n"; }
/* * Initializes UART and XBee network parameters * Returns 0 on success, non-zero on failure * ip is string of lowest 8 bits of IP address, represented * as a decimal string */ uint8_t xbee_init( char* ip ) { uint8_t ret = 0; // Set the frame receive handler frame_recv_handler( frame_rx_handler ); set_IP_addr_mode(); if( !(ret = cts) ) // Yes, it's supposed to be a single '=', cts is set everytime we transmit data { set_SSID(); if( !(ret = cts) ) { set_encryption_type(); if( !(ret = cts) ) { set_encryption_password(); #if USE_DHCP == 1 if( !(ret = cts) ) { set_IP_address( ip ); #if USE_GM == 1 if( !(ret = cts) ) { set_mask(); if( !(ret = cts) ) { set_gateway(); } } #endif /* USE_GM == 1 */ } #endif /* USE_DHCP = 1 */ } } } return ret; }
static int am_uart_startup(struct uart_port *port) { struct am_uart_port * info = &am_ports[port->line]; am_uart_t *uart = uart_addr[info->line]; unsigned long mode; #ifdef PRINT_DEBUG if(info->line == DEBUG_PORT_ID) printk("%s\n", __FUNCTION__); #endif mutex_lock(&info->info_mutex); set_mask(&uart->mode, UART_RXRST|UART_TXRST|UART_CLEAR_ERR); clear_mask(&uart->mode, UART_RXRST|UART_TXRST|UART_CLEAR_ERR); mode = readl(&uart->mode); mode |= UART_RXENB | UART_TXENB; writel(mode, &uart->mode); mutex_unlock(&info->info_mutex); return 0; }
void mc_main() { __asm__("j7 7"); int core = corenum(); if(core == 2){ wait_after_done = 0; s_processor = new_processor("Processor1"); s_tasks = new_tasks(names, 3); //puts(s_tasks[0].name); //puts(s_tasks[1].name); //puts(s_tasks[2].name); putchar(s_tasks[0].index+'0'); putchar(s_tasks[1].index+'0'); putchar(s_tasks[2].index+'0'); init_tasks(s_processor, s_tasks, 3); /* for(int i=0;i<3;i++)*/ /*{*/ /*j=0;*/ /*while(s_tasks[i].name[j])*/ /*putchar(s_tasks[i].name[j++]);*/ /*putchar(10);*/ /*}*/ wait_after_done = 1; // Called concurrently in all cores except core #1, after mc_init returns //set timer interrupt handler set_handlerR((int)isr); //set timer interrupt intervals set_timerInterval(CLOCK_TO_MS); //set interrupt enable putchar('f'); set_mask(0); task_3(); while (1); } else while(1); }
static void on_fd(oop_source *x,int fd,oop_event event,oop_call_fd *f,void *d) { struct file_handler *h; if (fd >= array_size) { const int new_size = fd + 1; struct file_handler * const new_array = oop_realloc(array,new_size * sizeof(*new_array)); if (NULL == new_array) return; /* YUCK */ array = new_array; while (array_size != new_size) { int i; for (i = 0; i < OOP_NUM_EVENTS; ++i) array[array_size].f[i] = NULL; ++array_size; } } h = &array[fd]; assert(NULL == h->f[event] && NULL != f); h->f[event] = f; h->d[event] = d; set_mask(fd); }
//processes sentence and creates derivations //returns tail of the derivation OPTION *get_derivation(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, int do_free_partials) { /* if (ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE && !ap->is_synt_early_reduce) { fprintf(stderr, "Error: exhaustive internal syntactic projectivization with late reduce strategy is not supported\n"); exit(EXIT_FAILURE); } if (ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE && !ap->is_srl_early_reduce) { fprintf(stderr, "Error: exhaustive internal SRL projectivization with late reduce strategy is not supported\n"); exit(EXIT_FAILURE); } */ //Debug // printf("Next sentence ============\n"); ASSERT(ap->input_offset == 0 || ap->input_offset == 1); STACK st; st.size = 0; STACK srl_st; srl_st.size = 0; //OPTION *head = create_option(SYNT_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM); OPTION *head = create_option(SRL_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM); ///st_push(&head->srl_stack, 0); //JH allow 0 as an SRL argument set_links(ap, mp, head, sent); ///printf("new sentence\n");/// OPTION *opt = head; while (opt->queue != sent->len + 1) { //get next possible actions ACTION_SET as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); //===================== SYNTAX ====================================================== if (ap->is_synt_early_reduce && as.acts[RED]) { int s = st_peek(&opt->stack); if (everything_complete(opt->pt, sent, s)) { if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) { opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } //check LA if (as.acts[LA]) { int d = st_peek(&opt->stack); int h = opt->queue; if (sent->head[d] == h) { //create sequence of LA operations //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, LA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_la_label, mp->deprel_num); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); //opt->previous_option->pt = NULL; set_links(ap, mp, opt, sent); opt = create_option(SYNT_STEP, 1, LA, sent->deprel[d], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); //opt->previous_option->pt = NULL; pt_add_link(opt->pt, h, d, sent->deprel[d]); opt->pt->right_connections_num[d]++; if (ap->intern_synt_deproj == DEPROJ_NO) { st_pop(&opt->stack); } else { // Do Nothing!!! } set_links(ap, mp, opt, sent); //DEBUG //printf("LA\n"); continue; } } //check RA if (as.acts[RA]) { int d = opt->queue; int h = st_peek(&opt->stack); //when agrees if (sent->head[d] == h) { //means if stack is not empty or we can make RA with empty stack if (h != 0 || (ap->parsing_mode >= 3 && sent->deprel[d] != ROOT_DEPREL // can do only once && opt->pt->nodes[d].deprel == ROOT_DEPREL)) { //create sequence of RA operations //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, RA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_ra_label, mp->deprel_num); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SYNT_STEP, 1, RA, sent->deprel[d], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); pt_add_link(opt->pt, h, d, sent->deprel[d]); if (h != 0) { opt->pt->right_connections_num[h]++; } set_links(ap, mp, opt, sent); //DEBUG //printf("RA\n"); continue; } } } // check FLIP if (as.acts[FLIP] && ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE) { int s = st_peek(&opt->stack); int s_already_conns = opt->pt->right_connections_num[s]; int s_under = st_look(&opt->stack, 1); int s_under_already_conns = opt->pt->right_connections_num[s_under]; int top_is_usl = (sent->synt_right_degree[s] == s_already_conns); int under_top_is_usl = (sent->synt_right_degree[s_under] == s_under_already_conns); if (ap->is_synt_early_reduce || (!top_is_usl && !under_top_is_usl) ) { // s_under will be active earlier than s if (lexicograph_ignore_double_entries_comp( sent->synt_right_indices[s_under] + s_under_already_conns, sent->synt_right_degree[s_under] - s_under_already_conns, sent->synt_right_indices[s] + s_already_conns, sent->synt_right_degree[s] - s_already_conns) < 0) { //create sequence of reduce operation //update queue and stack opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); //DEBUG printf("(SYNT) FLIP\n"); continue; } } else { // if a top word can be reduce from the top if (top_is_usl) { int first_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree); if (first_usf > 0) { // first 'useful' word in the stack should be attached to front of queue -- start remioving useless words // next words will be removed on the next rounds int next_connection = sent->synt_right_indices[first_usf][opt->pt->right_connections_num[first_usf]]; if (next_connection == opt->queue) { ASSERT(as.acts[RED]); opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } else { // if int second_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree); ASSERT(second_usf != s_under); if (second_usf > 0) { int second_usf_already_conns = opt->pt->right_connections_num[second_usf]; if (lexicograph_ignore_double_entries_comp( sent->synt_right_indices[second_usf] + second_usf_already_conns, sent->synt_right_degree[second_usf] - second_usf_already_conns, sent->synt_right_indices[s] + s_already_conns, sent->synt_right_degree[s] - s_already_conns) < 0) { opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); ASSERT(as.acts[RED]); opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); // DEBUG printf("FLIP, followed by RED\n"); //printf("RED, preceded by FLIP\n"); continue; } } } // !top_is_usl } // !ap->is_synt_early_reduce } // FLIP //check SWITCH if (as.acts[SWITCH]) { int q = opt->queue; if (left_part_complete(opt->pt, sent, q)) { //if atached to root with not ROOT_DEPREL and parsing_mode >= 3 then RA, not SHIFT should be peformed //option sent->deprel[q] == opt->pt->nodes[q]->deprel - relates to RA- + SHIFT sequence and means that RA- is actually preformed //and q is already attached if (sent->head[q] != 0 || ap->parsing_mode < 3 || (ap->parsing_mode >= 3 && (sent->deprel[q] == ROOT_DEPREL || sent->deprel[q] == opt->pt->nodes[q].deprel))) { opt = create_option(SRL_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); /* opt = create_option(SYNT_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); */ TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("SWITCH\n"); continue; } } } //check RED if (!ap->is_synt_early_reduce && as.acts[RED]) { int s = st_peek(&opt->stack); if (everything_complete(opt->pt, sent, s)) { if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) { opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } // check FLIP if (as.acts[FLIP] && ap->intern_synt_deproj != DEPROJ_EXHAUSTIVE) { opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); //DEBUG printf("(SYNT) FLIP\n"); continue; } //===================== WORD PREDICTION ============================================= if (as.acts[SHIFT]) { //create sequence of shift operation //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, SHIFT, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_pos, get_pos_out_num()); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_word_prediction_seq(ap, mp, sent, opt, do_free_partials); //DEBUG //printf("SHIFT\n"); continue; } //===================== SRL ====================================================== if (ap->is_srl_early_reduce && as.acts[SRL_RED]) { int srl_s = st_peek(&opt->srl_stack); if (srl_everything_complete(opt->ps, sent, srl_s)) { opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); //DEBUG // printf("SRL_RED\n"); continue; } } //check SRL_LA int q_bank = sent->bank[opt->queue]; ///if (q_bank >= 0)/// /// printf("srl_la 0: %d %d; %d %d\n", q_bank, as.acts[SRL_LA[q_bank]], st_peek(&opt->srl_stack), opt->queue);/// if (q_bank >= 0 && as.acts[SRL_LA[q_bank]]) { int d = st_peek(&opt->srl_stack); int h = opt->queue; int role = next_srl_role(0, sent, h, d); ///printf("srl_la 1: %d %d %d\n", d, h, role);/// if (role >= 0) { int i = 0; for (; role >= 0; role = next_srl_role(i, sent, h, d)) { i++; //create sequence of SRL_LA operations //update queue and stack opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_LA[q_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_la_label[q_bank], mp->role_num[q_bank]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, SRL_LA[q_bank], role, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_add_link(opt->ps, h, d, role); opt->ps->right_connections_num[d]++; set_links(ap, mp, opt, sent); //DEBUG //printf("SRL_LA[%d]\n", q_bank); } continue; } } q_bank = -1; //check SRL_RA int s_bank = sent->bank[st_peek(&opt->srl_stack)]; if (s_bank >= 0 && as.acts[SRL_RA[s_bank]]) { int d = opt->queue; int h = st_peek(&opt->srl_stack); int role = next_srl_role(0, sent, h, d); ///printf("srl_ra: %d %d %d\n", d, h, role);/// //when agrees if (role >= 0) { int i = 0; for (; role >= 0; role = next_srl_role(i, sent, h, d)) { ASSERT(i == 0); i++; //create sequence of RA operations //update queue and stack opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_RA[s_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_ra_label[s_bank], mp->role_num[s_bank]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, SRL_RA[s_bank], role, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_add_link(opt->ps, h, d, role); opt->ps->right_connections_num[h]++; set_links(ap, mp, opt, sent); //DEBUG //printf("SRL-RA[%d]\n", s_bank); } // role continue; } } if (as.acts[SRL_FLIP] && ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE) { int srl_s = st_peek(&opt->srl_stack); int srl_s_already_conns = opt->ps->right_connections_num[srl_s]; int srl_s_under = st_look(&opt->srl_stack, 1); int srl_s_under_already_conns = opt->ps->right_connections_num[srl_s_under]; int top_is_usl = (sent->srl_right_degree[srl_s] == srl_s_already_conns); int under_top_is_usl = (sent->srl_right_degree[srl_s_under] == srl_s_under_already_conns); if (ap->is_srl_early_reduce || (!top_is_usl && !under_top_is_usl) ) { // srl_s_under will be active earlier than srl_s if (lexicograph_ignore_double_entries_comp( sent->srl_right_indices[srl_s_under] + srl_s_under_already_conns, sent->srl_right_degree[srl_s_under] - srl_s_under_already_conns, sent->srl_right_indices[srl_s] + srl_s_already_conns, sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); //DEBUG //TMP printf("SRL_FLIP\n"); continue; } } else { // if a top word can be reduce from the top if (top_is_usl) { int first_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree); if (first_usf > 0) { // first 'useful' word in the stack should be attached to front of queue -- start remioving useless words // next words will be removed on the next rounds int next_connection = sent->srl_right_indices[first_usf][opt->ps->right_connections_num[first_usf]]; if (next_connection == opt->queue) { ASSERT(as.acts[SRL_RED]); opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); continue; //DEBUG //printf("SRL_RED, useless reduction\n"); } } } else { // if int second_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree); ASSERT(second_usf != srl_s_under); if (second_usf > 0) { int second_usf_already_conns = opt->ps->right_connections_num[second_usf]; if (lexicograph_ignore_double_entries_comp( sent->srl_right_indices[second_usf] + second_usf_already_conns, sent->srl_right_degree[second_usf] - second_usf_already_conns, sent->srl_right_indices[srl_s] + srl_s_already_conns, sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); ASSERT(as.acts[SRL_RED]); opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); // DEBUG printf("SRL_FLIP, followed by SRL_RED\n"); //printf("SRL_RED, preceded by SRL_FLIP\n"); continue; } } } // !top_is_usl } // !ap->is_synt_early_reduce } // FLIP //check SRL_SWITCH if (as.acts[SRL_SWITCH]) { int q = opt->queue; if (srl_left_part_complete(opt->ps, sent, q)) { opt = create_option(SYNT_STEP, 1, SRL_SWITCH, SRL_SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("SRL_SWITCH\n"); continue; } } //check SRL_RED if (!ap->is_srl_early_reduce && as.acts[SRL_RED]) { int srl_s = st_peek(&opt->srl_stack); if (srl_everything_complete(opt->ps, sent, srl_s)) { opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("SRL_RED\n"); continue; } } if (as.acts[PREDIC_NO]) { int q = opt->queue; if (sent->sense[q] < 0) { opt = create_option(SRL_STEP, 1, PREDIC_NO, PREDIC_NO, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("PREDIC_NO\n"); continue; } } if (as.acts[PREDIC_YES]) { int q = opt->queue; int q_sense = sent->sense[q]; if (q_sense >= 0) { int q_bank = sent->bank[q]; int q_lemma = sent->lemma[q]; //create sequence of predicate prediction operations opt = create_option(SRL_STEP, 0, opt->previous_act, PREDIC_YES, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sense[q_bank][q_lemma][0], mp->sense_num[q_bank][q_lemma]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, PREDIC_YES, q_sense, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_set_sense(opt->ps, q, q_sense); set_links(ap, mp, opt, sent); //DEBUG //printf("PREDIC_YES\n"); continue; } } if (as.acts[SRL_FLIP] && ap->intern_srl_deproj != DEPROJ_EXHAUSTIVE) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("SRL_FLIP\n"); continue; } // if stalled in syntactic part if (IS_NOW_SYNTAX(opt->previous_act)) { //DEBUG printf("STALLED IN SYNTAX\n"); } else { //DEBUG printf("STALLED IN SRL\n"); } ASSERT(0); if (IS_NOW_SYNTAX(opt->previous_act)) { fprintf(stderr, "(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); printf("(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); } else { //TMP fprintf(stderr, "(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); //TMP printf("(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); } fprintf(stderr, "Try changing PARSING_ORDER in the configuration file to a larger value\n"); // printf("%s\n", print_sent(sent, 1)); //TODO this should be a fatal error fprintf(stderr, "Warning: returning partial derivation\n"); DEF_ALLOC(as_final, ACTION_SET); bzero(as_final, sizeof(ACTION_SET)); set_mask(mp, opt, as_final); free(as_final); TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps)); return opt; //TODO restore! //exit(1); } //DEBUG //TMP printf("==== SENT FINISHED ===== \n"); if (!check_pt_t_equality(opt->pt, sent)) { fprintf(stderr, "Presumably: bug in parsing or in input file (e.g. NON-PROJECTIVITY): resulting syntactic trees do not match\n"); exit(1); } if (!check_ps_t_equality(opt->ps, sent)) { fprintf(stderr, "Presumably: bug in SRL parsing or in input file (e.g. NON-PROJECTIVITY): resulting predicate argument structures do not match\n"); } DEF_ALLOC(as, ACTION_SET); bzero(as, sizeof(ACTION_SET)); set_mask(mp, opt, as); free(as); TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps)); return opt; }
/** **=========================================================================== ** ** Abstract: main program ** **=========================================================================== */ int main(void) { #if SYS_STARTUP == 0 SystemInit(); #endif nvic_init(); // настройка векторов прерываний led_init(); // инициализация светодиода, индицирующего работу процессора init_calendar(); // инициализация календаря _SPI_init(); // SPI для внешней FRAM // чтение заводских установок read_data(0x7B,0x00,128,(unsigned char*)&_Sys.FR.b1[0]); read_data(0x7B,0x80,128,(unsigned char*)&_Sys.FR.b1[0x80]); read_data(0x7C,0x00,128,(unsigned char*)&_Sys.FR.b1[0x100]); read_data(0x7C,0x80,128,(unsigned char*)&_Sys.FR.b1[0x180]); read_data(0x7D,0x00,128,(unsigned char*)&_Sys.FR.b1[0x200]); read_data(0x7D,0x80,128,(unsigned char*)&_Sys.FR.b1[0x280]); read_data(0x7E,0x00,128,(unsigned char*)&_Sys.FR.b1[0x300]); read_data(0x7E,0x80,128,(unsigned char*)&_Sys.FR.b1[0x380]); // чтение системных настроек контроллера //read_data(0x7F,0x58,1,&rf_ch); read_data(0x7F,0x00,6,(unsigned char*)&_Sys.Mem.b1[0]); _Sys.Adr=_Sys.Mem.b1[0]; if((_Sys.Adr==0)||(_Sys.Adr==0xFF)) _Sys.Adr=0x01; _Sys.Can1_Baudrate=_Sys.Mem.b1[1]; if(_Sys.Can1_Baudrate>5) _Sys.Can1_Baudrate=5; _Sys.Can1_Type = _Sys.Mem.b1[2]; if(_Sys.Can1_Type>1) _Sys.Can1_Type=0; _Sys.Can2_Baudrate=_Sys.Mem.b1[3]; if(_Sys.Can2_Baudrate>5) _Sys.Can2_Baudrate=5; _Sys.Can2_Type = _Sys.Mem.b1[4]; if(_Sys.Can2_Type>1) _Sys.Can2_Type=0; emu_mode = _Sys.Mem.b1[5]; if(emu_mode>2) emu_mode=0; read_data(0x7F,0x4C,4,ip_addr);set_ip(ip_addr); read_data(0x7F,0x50,6,mac_addr);set_mac(mac_addr); read_data(0x7F,0x5A,4,ip_gate);set_gate(ip_gate); read_data(0x7F,0x5E,1,&modbus_master_emu); read_data(0x7F,0x5F,4,ip_mask);set_mask(ip_mask); #if FRAM_YEAR read_data(0x7F,0x56,1,(unsigned char*)×.year); if(times.year>99) times.year=0; #endif read_data(0x7F,0x57,1,(unsigned char*)&pult_dis); read_data(0x7F,0x59,1,(unsigned char*)&sd_dis); /* read_data(0x7F,0x5A,32,ssid_name); read_data(0x7F,0x7A,32,wifi_password); read_data(0x7F,0x9A,1,&wifi_type); read_data(0x7F,0x9B,4,wifi_ip);*/ // начальные значения номеров строк пульта _Sys.S1=0x00;_Sys.S2=0x00;_Sys.S3=0x00;_Sys.S4=0x00; // системные миллисекундные задачи xTaskCreate( R1Task, ( signed portCHAR * ) "R1", configMINIMAL_STACK_SIZE*2, NULL, R1_TASK_PRIORITY, NULL ); xTaskCreate( R5Task, ( signed portCHAR * ) "R5", configMINIMAL_STACK_SIZE*2, NULL, R5_TASK_PRIORITY, NULL ); xTaskCreate( R10Task, ( signed portCHAR * ) "R10", configMINIMAL_STACK_SIZE*2, NULL, R10_TASK_PRIORITY, NULL ); xTaskCreate( R100Task, ( signed portCHAR * ) "R100", configMINIMAL_STACK_SIZE*2, NULL, R100_TASK_PRIORITY, NULL ); xTaskCreate( R1000Task, ( signed portCHAR * ) "R1000", configMINIMAL_STACK_SIZE*2, NULL, R1000_TASK_PRIORITY, NULL ); // служебная вспомогательная задача (светодиод,фильтр ацп,...) xTaskCreate( prvFlashTask, (signed portCHAR *) "Flash", configMINIMAL_STACK_SIZE*2, NULL, mainFLASH_TASK_PRIORITY, NULL ); // стандартный пульт или коммуникационный канал if(pult_dis!=0x31) xTaskCreate( LCDTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*2, NULL, LCD_TASK_PRIORITY, NULL ); else xTaskCreate( PultCanTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*5, NULL, Canal_TASK_PRIORITY, NULL ); // задача обработки входов/выходов включая модули расширения xTaskCreate( InOutTask, ( signed portCHAR * ) "InOut", configMINIMAL_STACK_SIZE*2, NULL, InOut_TASK_PRIORITY, NULL ); // два основных коммуникационных канала RS485 if(_Sys.Can1_Type==0) xTaskCreate( BinCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); else xTaskCreate( AsciiCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); if(_Sys.Can2_Type==0) xTaskCreate( BinCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); else xTaskCreate( AsciiCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); // WIFI задачи /* if(wifi_ip[0]) { xTaskCreate( WIFITask, ( signed portCHAR * ) "Wifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY, NULL ); xTaskCreate( SCAN_WIFITask, ( signed portCHAR * ) "SCANWifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY+1, NULL ); }*/ // проводной ethernet if(ip_addr[0]) xTaskCreate( EthTask, ( signed portCHAR * ) "Eth", configMINIMAL_STACK_SIZE*3, NULL, ETH_TASK_PRIORITY, NULL ); // задача работы с sd картой if(sd_dis==0x31) xTaskCreate( ArchiveTask, ( signed portCHAR * ) "SD_Task", configMINIMAL_STACK_SIZE*2, NULL, SD_TASK_PRIORITY, NULL ); Relkon_init(); // блок инициализации - формируется верхним уровнем (раздел #init релкона) init_timer(); // аппаратный таймер для определения загрузки процессора vTaskStartScheduler(); // старт планировщика задач while (1){} }
//TODO don't forget to move pt OPTION_LIST *process_opt(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, OPTION **new_b_options, int *new_cand_num, OPTION *opt, OPTION_LIST *ol) { /* if ol longer than QUEUE_SIZE_LIMIT, then prune to half that length. Requires calling with opt=NULL to initialize count */ static int queue_size; if (opt == NULL) { queue_size = 0; OPTION_LIST *ol2; for (ol2 = ol; ol2 != NULL; ol2 = ol2->prev) queue_size++; return ol; } queue_size--; ASSERT(opt->outputs.num == ACTION_NUM); double min_lprob = - MAXDOUBLE; double min_lprob_with_pred = -MAXDOUBLE; if (*new_cand_num == ap->beam) { min_lprob = new_b_options[ap->beam - 1]->lprob - max_word_pred_lprob(ap, mp, sent, new_b_options, *new_cand_num, opt); min_lprob_with_pred = new_b_options[ap->beam - 1]->lprob; } //do not need to consider if (opt->lprob < min_lprob) { pt_free(&(opt->pt)); ps_free(&(opt->ps)); free_options(opt); return ol; } //they are not yet computed ACTION_SET as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); comp_option(ap, mp, opt); // ----------------------- SYNTAX ----------------------------------------------- //check SHIFT (first because it is the operation that updates candidate list) if (as.acts[SHIFT]) { if (log(opt->outputs.q[SHIFT]) + opt->lprob >= min_lprob) { //create sequence of shift operation //update queue and stack //TODO Implement more efficiently pruning after each decision OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, SHIFT, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_pos, get_pos_out_num()); int pos = sent->pos[opt->period + ap->input_offset]; int feat = sent->feat_out[opt->period + ap->input_offset]; int word = sent->word_out[opt->period + ap->input_offset]; set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); if (log(as_opt->outputs.q[pos]) + as_opt->lprob < min_lprob_with_pred) { pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); free_option(as_opt); } else { OPTION *last_opt = create_word_prediction_seq(ap, mp, sent, as_opt, 1); OPTION *feat_opt = last_opt->previous_option->previous_option; comp_option(ap, mp, feat_opt); if (log(feat_opt->outputs.q[feat]) + feat_opt->lprob < min_lprob_with_pred) { pt_free(&(last_opt->pt)); ps_free(&(last_opt->ps)); OPTION *po = last_opt->previous_option, *ppo = last_opt->previous_option->previous_option; free_option(last_opt); free_option(po); free_option(ppo); free_option(as_opt); } else { OPTION *word_opt = last_opt->previous_option; comp_option(ap, mp, word_opt); // if (log(word_opt->outputs.q[word]) + word_opt->lprob < min_lprob_with_pred) { if (log(word_opt->outputs.q[word]) + word_opt->lprob < min_lprob_with_pred + SMALL_POS_VAL) { pt_free(&(last_opt->pt)); ps_free(&(last_opt->ps)); OPTION *po = last_opt->previous_option, *ppo = last_opt->previous_option->previous_option; free_option(last_opt); free_option(po); free_option(ppo); free_option(as_opt); } else { fill_lprob(last_opt); add_to_best_list(ap, new_b_options, new_cand_num, last_opt); } } } } } //update if (*new_cand_num == ap->beam) { min_lprob = new_b_options[ap->beam - 1]->lprob - max_word_pred_lprob(ap, mp, sent, new_b_options, *new_cand_num, opt); min_lprob_with_pred = new_b_options[ap->beam - 1]->lprob; // not necessary, but could save space: //ol = prune_options(ol, min_lprob); } //check LA if (as.acts[LA]) { int d = st_peek(&opt->stack); int h = opt->queue; if (log(opt->outputs.q[LA]) + opt->lprob >= min_lprob) { //create sequence of LA operations //update queue and stack OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, LA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_la_label, mp->deprel_num); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double deprel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_DEPREL_SIZE]; int fanout = get_best_labels(ap, as_opt, deprel_min_prob, mp->deprel_num, best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SYNT_STEP, 1, LA, best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); pt_add_link(new_opt->pt, h, d, best_rels[i]); if (ap->intern_synt_deproj == DEPROJ_NO) { st_pop(&new_opt->stack); } else { // Do nothing } set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } //check RA if (as.acts[RA]) { int d = opt->queue; int h = st_peek(&opt->stack); //when agrees if (log(opt->outputs.q[RA]) + opt->lprob >= min_lprob) { //create sequence of RA operations //update queue and stack OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, RA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_ra_label, mp->deprel_num); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double deprel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_DEPREL_SIZE]; int fanout = get_best_labels(ap, as_opt, deprel_min_prob, mp->deprel_num, best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SYNT_STEP, 1, RA, best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); pt_add_link(new_opt->pt, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } //TODO Try processing immediately SHIFT operation //should speed-up (it will make it way to best_list and //prune other optinos) } } //check RED if (as.acts[RED]) { if (log(opt->outputs.q[RED]) + opt->lprob >= min_lprob) { //create sequence of reduce operation //update queue and stack OPTION *as_opt = create_option_light(SYNT_STEP, 1, RED, RED, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); st_pop(&as_opt->stack); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } //check SWITCH if (as.acts[SWITCH]) { if (log(opt->outputs.q[SWITCH]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); // OPTION *as_opt = create_option_light(SYNT_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, // pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } // ----------------------- SEMANTICS ----------------------------------------------- //check PREDIC_NO if (as.acts[PREDIC_NO]) { if (log(opt->outputs.q[PREDIC_NO]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, PREDIC_NO, PREDIC_NO, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } if (as.acts[PREDIC_YES]) { int q = opt->queue; int q_bank = sent->bank[q]; int q_lemma = sent->lemma[q]; if (log(opt->outputs.q[PREDIC_YES]) + opt->lprob >= min_lprob) { //create sequence of predicate prediction operations OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, PREDIC_YES, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sense[q_bank][q_lemma][0], mp->sense_num[q_bank][q_lemma]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double sense_min_prob = exp(min_lprob - as_opt->lprob); int best_senses[MAX_SENSE_SIZE]; int fanout = get_best_labels(ap, as_opt, sense_min_prob, mp->sense_num[q_bank][q_lemma], best_senses); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, PREDIC_YES, best_senses[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_set_sense(new_opt->ps, q, best_senses[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } //check SRL_LA int q_bank = sent->bank[opt->queue]; if (q_bank >= 0 && as.acts[SRL_LA[q_bank]]) { int d = st_peek(&opt->srl_stack); int h = opt->queue; if (log(opt->outputs.q[SRL_LA[q_bank]]) + opt->lprob >= min_lprob) { //create sequence of SRL_LA operations //update queue and stack OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_LA[q_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_la_label[q_bank], mp->role_num[q_bank]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double rel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_ROLE_SIZE]; int fanout = get_best_labels(ap, as_opt, rel_min_prob, mp->role_num[q_bank], best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, SRL_LA[q_bank], best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_add_link(new_opt->ps, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } q_bank = -1; //check SRL_RA int s_bank = sent->bank[st_peek(&opt->srl_stack)]; if (s_bank >= 0 && as.acts[SRL_RA[s_bank]]) { int d = opt->queue; int h = st_peek(&opt->srl_stack); if (log(opt->outputs.q[SRL_RA[s_bank]]) + opt->lprob >= min_lprob) { //create sequence of RA operations //update queue and stack OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_RA[s_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_ra_label[s_bank], mp->role_num[s_bank]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double rel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_ROLE_SIZE]; int fanout = get_best_labels(ap, as_opt, rel_min_prob, mp->role_num[s_bank], best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, SRL_RA[s_bank], best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_add_link(new_opt->ps, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } s_bank = -1; //check SRL_RED if (as.acts[SRL_RED]) { if (log(opt->outputs.q[SRL_RED]) + opt->lprob >= min_lprob) { //create sequence of reduce operation //update queue and stack OPTION *as_opt = create_option_light(SRL_STEP, 1, SRL_RED, SRL_RED, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); st_pop(&as_opt->srl_stack); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } //check SRL_SWITCH if (as.acts[SRL_SWITCH]) { if (log(opt->outputs.q[SRL_SWITCH]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SYNT_STEP, 1, SRL_SWITCH, SRL_SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } if (as.acts[SRL_FLIP]) { if (log(opt->outputs.q[SRL_FLIP]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, SRL_FLIP, SRL_FLIP, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); int srl_s = st_pop(&as_opt->srl_stack); int srl_s_under = st_pop(&as_opt->srl_stack); st_push(&as_opt->srl_stack, srl_s); st_push(&as_opt->srl_stack, srl_s_under); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } pt_free(&(opt->pt)); ps_free(&(opt->ps)); opt->pt = NULL; opt->ps = NULL; if (opt->next_options->prev == NULL) { free_options(opt); } if (queue_size > QUEUE_SIZE_LIMIT) { printf("Warning: indiscriminately pruning search queue from length %d to %d\n", queue_size, (int) (QUEUE_SIZE_LIMIT / 1.5)); OPTION_LIST *ol2; int cnt = 0; for (ol2 = ol; ol2 != NULL; ol2 = ol2->prev) { cnt++; if (cnt > (int) (QUEUE_SIZE_LIMIT / 1.5)) { // reduce to 2/3 of limit prune_options(ol2, 0.0); break; } } queue_size = cnt - 1; } return ol; }
int main(int argc, char** argv) { pcap_dumper_t *dumper; pcap_t *p; struct pcap_pkthdr header; u_char *packet; int i; struct sockaddr *sin_src; struct sockaddr *sin_net; struct sockaddr *sin_dst; struct sockaddr *sin_mask; int sendsize; struct options_args opts; FILE* fp_domain; char * domain; int q_class; int q_type; /** * * headers */ struct ether_header *eth; struct iphdr *ip; struct ip6_hdr *ip6; struct udphdr *udp; u_char *dns; setoptions(argc, argv, &opts); header.ts.tv_sec = 0; header.ts.tv_usec = 0; packet = calloc(sizeof (u_char) * 4096, 1); sin_src = calloc(sizeof (struct sockaddr_storage), 1); sin_net = calloc(sizeof (struct sockaddr_storage), 1); sin_dst = calloc(sizeof (struct sockaddr_storage), 1); sin_mask = calloc(sizeof (struct sockaddr_storage), 1); domain = calloc(sizeof (char) * 1024, 1); if(packet == NULL || sin_src == NULL || sin_net == NULL || sin_dst == NULL || sin_mask == NULL || domain == NULL) { return -1; } /** * * ETHERNET static */ eth = (struct ether_header *) packet; if (ether_setaddr(opts.smac, &(eth->ether_shost)) < 0) { fprintf(stderr, "smac error\n"); return 1; } if (ether_setaddr(opts.dmac, &(eth->ether_dhost)) < 0) { fprintf(stderr, "dmac error\n"); return 1; } /** * * IP static */ if (getipaddr(opts.dip, sin_dst, opts.family) < 0) { fprintf(stderr, "dip error\n"); return 2; } if (getipaddr(opts.snet, sin_net, opts.family) < 0) { fprintf(stderr, "sip error\n"); return 2; } if (sin_net->sa_family != sin_dst->sa_family) { fprintf(stderr, "IP family doesn't match\n"); return 2; } set_mask(sin_mask, sin_net->sa_family, opts.smask); if (sin_net->sa_family == AF_INET) { eth->ether_type = htons(ETHERTYPE_IP); ip = (struct iphdr *) (packet + ETHER_HDR_LEN); ip->daddr = ((struct sockaddr_in *) sin_dst)->sin_addr.s_addr; ip->version = 4; ip->ihl = 5; // no opts ip->frag_off = 0; ip->id = 0; ip->protocol = IPPROTO_UDP; ip->tos = 0; ip->ttl = IPDEFTTL; udp = (struct udphdr *) (((void *) ip) + IP_HDR_LEN); } else if (sin_net->sa_family == AF_INET6) { eth->ether_type = htons(ETHERTYPE_IPV6); ip6 = (struct ip6_hdr *) (packet + ETHER_HDR_LEN); ip6->ip6_vfc = 6 << 4; ip6->ip6_hlim = IPDEFTTL; ip6->ip6_nxt = IPPROTO_UDP; memcpy(&(ip6->ip6_dst), &(((struct sockaddr_in6 *) sin_dst)->sin6_addr), 16); udp = (struct udphdr *) (((void *) ip6) + IP6_HDR_LEN); } else { fprintf(stderr, "Family unknown\n"); return 2; } /** * * UDP static */ udp->check = 0; udp->dest = htons(53); /** * * DNS static */ dns = (u_char *) (((void *) udp) + UDP_HDR_LEN); p = pcap_open_dead(DLT_EN10MB, PCAP_SNAPLEN); dumper = pcap_dump_open(p, opts.out_file_name); if(dumper == NULL) { fprintf(stderr, "Can't open output file\n"); pcap_close(p); return 3; } init_domain_file(&fp_domain, opts.in_file_name); if (fp_domain == NULL) { fprintf(stderr, "Can't open queries file\n"); pcap_dump_close(dumper); pcap_close(p); return 4; } for (i = 0; i < opts.count; i++) { /** * * DNS dynamic */ nextdomain(fp_domain, &domain, &q_type, &q_class); sendsize = res_mkquery(QUERY, domain, q_class, q_type, NULL, 0, NULL, dns, PACKETSZ); /** * * UDP dynamic */ udp->source = htons(rand()); udp->len = htons(sendsize + UDP_HDR_LEN); /** * * IP dynamic */ get_rand_addr(sin_net, sin_mask, sin_src); if (sin_net->sa_family == AF_INET) { ip->saddr = ((struct sockaddr_in *) sin_src)->sin_addr.s_addr; ip->tot_len = htons(sendsize + UDP_HDR_LEN + (ip->ihl * 4)); header.len = sendsize + UDP_HDR_LEN + (ip->ihl * 4) + ETHER_HDR_LEN; ip->check = 0; ip->check = inet_cksum(ip, (ip->ihl * 4)); } else if (sin_net->sa_family == AF_INET6) { memcpy(&(ip6->ip6_src), &(((struct sockaddr_in6 *) sin_src)->sin6_addr), 16); ip6->ip6_plen = htons(sendsize + UDP_HDR_LEN); header.len = sendsize + UDP_HDR_LEN + sizeof (struct ip6_hdr) +ETHER_HDR_LEN; } header.caplen = header.len; if (header.len > opts.mtu) { fprintf(stderr, "too long: %s needs %d MTU is %d\n", domain,header.len, opts.mtu); } else { pcap_dump(dumper, &header, packet); } } pcap_dump_close(dumper); pcap_close(p); fclose(fp_domain); return (EXIT_SUCCESS); }
int main(int argc, char** argv) { u_char *packet; int i; uint32_t ck; struct sockaddr *sin_src; struct sockaddr *sin_net; struct sockaddr *sin_dst; struct sockaddr *sin_mask; struct ip6_pseudo_hdr ps_hdr; int sendsize; struct options opts; FILE* fp_domain; char * domain; struct writer_info wi; int pkt_len; double speed_limit; double pkt_sent; int q_class; int q_type; pthread_t thread; pthread_create(&thread,NULL,readliner,&speed_limit); sleeper = 50; pkt_sent = 0; speed_limit = 50000; /** * * headers */ struct ether_header *eth; struct iphdr *ip; struct ip6_hdr *ip6; struct udphdr *udp; u_char *dns; u_char dns_opt[] = {00, 00, 0x29, 0x08, 00, 00, 00, 00, 00, 00, 00}; setoptions(argc, argv, &opts); packet = calloc(sizeof (u_char) * 4096, 1); sin_src = calloc(sizeof (struct sockaddr_storage), 1); sin_net = calloc(sizeof (struct sockaddr_storage), 1); sin_dst = calloc(sizeof (struct sockaddr_storage), 1); sin_mask = calloc(sizeof (struct sockaddr_storage), 1); domain = calloc(sizeof (char) * 1024, 1); //domain = NULL; if (packet == NULL || sin_src == NULL || sin_net == NULL || sin_dst == NULL || sin_mask == NULL || domain == NULL) { return -1; } /** * * ETHERNET static */ eth = (struct ether_header *) packet; if (ether_setaddr(opts.smac, &(eth->ether_shost)) < 0) { fprintf(stderr, "smac error:%s\n"); return 1; } if (ether_setaddr(opts.dmac, &(eth->ether_dhost)) < 0) { fprintf(stderr, "dmac error\n"); return 1; } /** * * IP static */ if (getipaddr(opts.dip, sin_dst, opts.family) < 0) { fprintf(stderr, "dip error\n"); return 2; } if (getipaddr(opts.snet, sin_net, opts.family) < 0) { fprintf(stderr, "sip error\n"); return 2; } if (sin_net->sa_family != sin_dst->sa_family) { fprintf(stderr, "IP family doesn't match\n"); return 2; } set_mask(sin_mask, sin_net->sa_family, opts.smask); if (sin_net->sa_family == AF_INET) { eth->ether_type = htons(ETHERTYPE_IP); ip = (struct iphdr *) (packet + ETHER_HDR_LEN); ip->daddr = ((struct sockaddr_in *) sin_dst)->sin_addr.s_addr; ip->version = 4; ip->ihl = 5; // no opts ip->frag_off = 0; ip->id = 0; ip->protocol = IPPROTO_UDP; ip->tos = 0; ip->ttl = IPDEFTTL; udp = (struct udphdr *) (((void *) ip) + IP_HDR_LEN); } else if (sin_net->sa_family == AF_INET6) { eth->ether_type = htons(ETHERTYPE_IPV6); ip6 = (struct ip6_hdr *) (packet + ETHER_HDR_LEN); ip6->ip6_vfc = 6 << 4; ip6->ip6_hlim = IPDEFTTL; ip6->ip6_nxt = IPPROTO_UDP; memcpy(&(ip6->ip6_dst), &(((struct sockaddr_in6 *) sin_dst)->sin6_addr), 16); udp = (struct udphdr *) (((void *) ip6) + IP6_HDR_LEN); } else { fprintf(stderr, "Family unknown\n"); return 2; } /** * * UDP static */ //udp->check = 0; udp->dest = htons(53); /** * * DNS static */ dns = (u_char *) (((void *) udp) + UDP_HDR_LEN); wopen(&wi,&opts); init_domain_file(&fp_domain, opts.in_file_name); if (fp_domain == NULL) { fprintf(stderr, "Can't open queries file\n"); wclose(&wi); return 4; } for (i = 0; i < opts.count; i++) { if(pkt_sent >= sleeper) { speed_calc(pkt_sent,speed_limit, &sleeper); pkt_sent = 0; usleep(1); } /** * * DNS dynamic */ if(nextdomain(fp_domain, &domain, &q_type, &q_class)) { printf("Can't read next domain\n"); exit(1); } sendsize = res_mkquery(QUERY, domain, q_class, q_type, NULL, 0, NULL, dns, PACKETSZ); dns[11] = 1; memcpy(dns + sendsize, dns_opt, 11); sendsize += 11; /** * * UDP dynamic */ udp->source = htons(rand()); udp->len = htons(sendsize + UDP_HDR_LEN); udp->check = 0; /** * * IP dynamic */ get_rand_addr(sin_net, sin_mask, sin_src); if (sin_net->sa_family == AF_INET) { ip->saddr = ((struct sockaddr_in *) sin_src)->sin_addr.s_addr; ip->tot_len = htons(sendsize + UDP_HDR_LEN + (ip->ihl * 4)); pkt_len = sendsize + UDP_HDR_LEN + (ip->ihl * 4) + ETHER_HDR_LEN; ip->check = 0; ip->check = inet_cksum(ip, (ip->ihl * 4), 0); } else if (sin_net->sa_family == AF_INET6) { memcpy(&(ip6->ip6_src), &(((struct sockaddr_in6 *) sin_src)->sin6_addr), 16); ip6->ip6_plen = htons(sendsize + UDP_HDR_LEN); pkt_len = sendsize + UDP_HDR_LEN + sizeof (struct ip6_hdr) +ETHER_HDR_LEN; ps_hdr.src = ip6->ip6_src; ps_hdr.dst = ip6->ip6_dst; ps_hdr.len = udp->len; ps_hdr.nh = ntohs(17); ck = inet_cksum(&ps_hdr, sizeof (ps_hdr), 0); udp->check = inet_cksum(udp, sendsize + UDP_HDR_LEN, (~ck)&0xffff); } if (pkt_len > opts.mtu) { fprintf(stderr, "too long: %s needs %d MTU is %d\n", domain, pkt_len, opts.mtu); } else { wwrite(&wi,packet,pkt_len); } pkt_sent++; } wclose(&wi); fclose(fp_domain); return (EXIT_SUCCESS); }
int main(int argc, char **argv) { int c; int read = 1; /* by default, we read data and print it out. operation modes that * write settings change this to 0. */ const char *name = 0; /* parse options to look for the interface name... */ opterr = 0; while((c = getopt(argc, argv, "hi:")) != -1) { switch(c) { case 'h': usage(); break; case 'i': name = optarg; break; } } /* reset getopt() and set the things */ optind = 0; opterr = 1; while((c = getopt(argc, argv, "u:s:n:m:i:hb:")) != -1) { switch(c) { case 'u': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_flag(name, optarg, 1)) exit(1); break; case 's': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_flag(name, optarg, 0)) exit(1); break; case 'n': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_addr(name, optarg)) exit(1); break; case 'b': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_broad_addr(name, optarg)) exit(1); break; case 'm': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_mask(name, optarg)) exit(1); break; case 't': read = 0; if(!name) { fprintf(stderr, "ifc: no interface specified\n"); exit(1); } if(set_mtu(name, optarg)) exit(1); break; case 'i': break; default: exit(1); } } if(read) read_stats(name); return 0; }
/* * File Selector input routine that takes control of the mouse * and keyboard, searchs and sort the directory, draws the file * selector, interacts with the user to determine a selection * or change of path, and returns to the application with * the selected path, filename, and exit button. */ WORD fs_input(BYTE *pipath, BYTE *pisel, WORD *pbutton, BYTE *pilabel) { register WORD touchob, value, fnum; WORD curr, count, sel; WORD mx, my; LONG tree; ULONG bitmask; BYTE *ad_fpath, *ad_fname, *ad_ftitle; WORD drive; WORD dclkret, cont, newlist, newsel, newdrive; register BYTE *pstr; GRECT pt; BYTE locstr[LEN_ZPATH+1], mask[LEN_ZFNAME+1], selname[LEN_FSNAME]; OBJECT *obj; TEDINFO *tedinfo; curr = 0; count = 0; /* get out quick if path is */ /* nullptr or if pts to null. */ if (pipath == NULL) return(FALSE); /* if path string is empty, */ /* set reasonable default */ if (*pipath == '\0') { strcpy(pipath,"A:\\*.*"); *pipath += dos_gdrv(); } /* get memory for the filename buffer */ /* & the array that points to it */ for (nm_files = MAX_NM_FILES; nm_files >= MIN_NM_FILES; nm_files /= 2) { ad_fsnames = (BYTE *)dos_alloc(nm_files*(LEN_FSNAME+sizeof(BYTE *))); if (ad_fsnames) break; } if (!ad_fsnames) return(FALSE); g_fslist = (LONG *)(ad_fsnames+nm_files*LEN_FSNAME); strcpy(locstr, pipath); tree = ad_fstree; /* init strings in form */ obj = ((OBJECT *)tree) + FTITLE; tedinfo = (TEDINFO *)obj->ob_spec; ad_ftitle = (BYTE *)tedinfo->te_ptext; set_mask(mask, locstr); /* save caller's mask */ strcpy(ad_ftitle, mask); /* & copy to title line */ obj = ((OBJECT *)tree) + FSDIRECT; tedinfo = (TEDINFO *)obj->ob_spec; ad_fpath = (BYTE *)tedinfo->te_ptext; inf_sset(tree, FSDIRECT, locstr); obj = ((OBJECT *)tree) + FSSELECT; tedinfo = (TEDINFO *)obj->ob_spec; ad_fname = (BYTE *)tedinfo->te_ptext; fmt_str(pisel, selname); /* selname[] is without dot */ inf_sset(tree, FSSELECT, selname); obj = ((OBJECT *)tree) + FSTITLE; obj->ob_spec = pilabel ? (LONG)pilabel : (LONG)rs_str(ITEMSLCT); /* set drive buttons */ obj = ((OBJECT *)tree) + DRIVE_OFFSET; for (drive = 0, bitmask = 1; drive < NM_DRIVES; drive++, bitmask <<= 1, obj++) { if (drvbits & bitmask) obj->ob_state &= ~DISABLED; else obj->ob_state |= DISABLED; } select_drive(tree,locstr[0]-'A',0); /* set clip and start */ /* form fill-in by */ /* drawing the form */ gsx_sclip(&gl_rfs); fm_dial(FMD_START, &gl_rfs); ob_draw(tree, ROOT, 2); /* init for while loop */ /* by forcing initial */ /* fs_newdir call */ sel = 0; newsel = FALSE; cont = newlist = TRUE; while( cont ) { touchob = (newlist) ? 0x0 : fm_do(tree, FSSELECT); gsx_mxmy(&mx, &my); if ( newlist ) { fs_sel(sel, NORMAL); if ( (touchob == FSOK) || (touchob == FSCANCEL) ) ob_change(tree, touchob, NORMAL, TRUE); inf_sset(tree, FSDIRECT, locstr); pstr = fs_pspec(locstr, NULL); strcpy(pstr, mask); fs_newdir(locstr, mask, tree, &count); curr = 0; sel = touchob = 0; newlist = FALSE; } value = 0; dclkret = ((touchob & 0x8000) != 0); switch( (touchob &= 0x7fff) ) { case FSOK: case FSCANCEL: cont = FALSE; break; case FUPAROW: case FDNAROW: value = 1; break; case FSVSLID: ob_actxywh(tree, FSVELEV, &pt); /* anemic slidebars pt.g_x -= 3; pt.g_w += 6; */ if ( !inside(mx, my, &pt) ) { touchob = (my <= pt.g_y) ? FUPAROW : FDNAROW; value = NM_NAMES; break; } /* drop through */ case FSVELEV: fm_own(TRUE); value = gr_slidebox(tree, FSVSLID, FSVELEV, TRUE); fm_own(FALSE); value = curr - mul_div(value, count-NM_NAMES, 1000); if (value >= 0) touchob = FUPAROW; else { touchob = FDNAROW; value = -value; } break; case F1NAME: case F2NAME: case F3NAME: case F4NAME: case F5NAME: case F6NAME: case F7NAME: case F8NAME: case F9NAME: fnum = touchob - F1NAME + 1; if ( fnum > count ) break; if ( (sel) && (sel != fnum) ) fs_sel(sel, NORMAL); if ( sel != fnum) { sel = fnum; fs_sel(sel, SELECTED); } /* get string and see */ /* if file or folder */ inf_sget(tree, touchob, selname); if (selname[0] == ' ') /* a file was selected */ { /* copy to selection */ newsel = TRUE; if (dclkret) cont = FALSE; } else /* a folder was selected: */ { /* insert name before mask */ pstr = fs_pspec(locstr, NULL); unfmt_str(selname+1, pstr); pstr += strlen(pstr); *pstr++ = '\\'; strcpy(pstr, mask); newlist = TRUE; } break; case FCLSBOX: pstr = fs_back(locstr, NULL); if (*pstr-- != '\\') /* ignore strange path string */ break; if (*pstr != ':') /* not at root of drive, so back up */ { pstr = fs_back(locstr, pstr); if (*pstr == '\\') /* we must have at least X:\ */ strcpy(pstr+1, mask); } newlist = TRUE; break; default: drive = touchob - DRIVE_OFFSET; if ((drive < 0) || (drive >= NM_DRIVES))/* not for us */ break; if (drive == locstr[0] - 'A') /* no change */ break; obj = ((OBJECT *)tree) + touchob; if (obj->ob_state & DISABLED) /* non-existent drive */ break; strcpy(locstr, "A:\\*.*"); locstr[0] += drive; newdrive = TRUE; break; } if (!newlist && !newdrive && path_changed(locstr)) /* path changed manually */ { if (ad_fpath[0] != locstr[0]) /* drive has changed */ newdrive = TRUE; else newlist = TRUE; strcpy(locstr, ad_fpath); } if (newdrive) { select_drive(tree, touchob-DRIVE_OFFSET,1); newdrive = FALSE; newlist = TRUE; } if (newlist) { inf_sset(tree, FSDIRECT, locstr); set_mask(mask, locstr); /* set mask */ selname[1] = '\0'; /* selected is empty */ newsel = TRUE; } if (newsel) { strcpy(ad_fname, selname + 1); ob_draw(tree, FSSELECT, MAX_DEPTH); if (!cont) ob_change(tree, FSOK, SELECTED, TRUE); newsel = FALSE; } if (value) curr = fs_nscroll(tree, &sel, curr, count, touchob, value); } /* return path and */ /* file name to app */ strcpy(pipath, locstr); unfmt_str(ad_fname, selname); strcpy(pisel, selname); /* start the redraw */ fm_dial(FMD_FINISH, &gl_rfs); /* return exit button */ *pbutton = inf_what(tree, FSOK, FSCANCEL); dos_free((LONG)ad_fsnames); return( TRUE ); }
void init_timer(){ remap_pic(0x20, 0x28); set_mask(0, 0xFE); set_timer(); }