void get_autonom_settings_from_bus() { autonomSettings = get_data(); }
bool BinAsm::finds_labels() { unsigned int lc = 0; unsigned int errc = 0; unsigned int offset = 0; uint16_t opd = 0; std::string err = ""; std::vector<std::string> lines=split_text(_src); std::vector<std::string>::iterator lit = lines.begin(); for (;lit!=lines.end();lit++) { lc++; std::vector<std::string> w=split_line(*lit); if (!w.size()) continue; if (get_op(w[0])) { offset++; if (w.size() < 3) continue; opd=0; get_b(w[1],opd,err); if (opd) offset++; opd=0; get_a(w[2],opd,err); if (opd) offset++; } else if (get_sop(w[0],err) && !err.size()) { offset++; if (w.size() < 2) continue; opd=0; get_a(w[1],opd,err); if (opd) offset++; } else { std::vector<std::string>::iterator wit = w.begin(); Label l; l.line = lc; l.offset = offset; l.name = std::string(); for (;wit!=w.end();wit++) { if (wit->size() < 2) continue; if ((*wit)[wit->size()-1] == ':') { l.name = wit->substr(0,wit->size()-1); break; } else if ((*wit)[0] == ':') { l.name = wit->substr(1,wit->size()); break; } } if (_labels.find(l.name)!=_labels.end()) { err="label " + l.name + " redefined"; print_error(lc, false,err); errc++; } else if (l.name.size()) { _labels[l.name]=l; } } uint16_t* data = new uint16_t[lit->size()]; offset += get_data(*lit, data,err); delete data; } return !errc; }
#include <vector> std::vector<unsigned> get_data() { std::vector<unsigned> result; while (result.size() != 10000000u) { result.push_back(result.size()); } std::random_shuffle(result.begin(), result.end()); return result; } auto data = get_data(); #ifdef USE_EXCEPTIONS unsigned process_data() { try { for (unsigned n : data) { if (n == data.size()) // never happens { std::cout << "THROW " << n << std::endl; throw n; } }
no_inline void operator()(int index) { test_data const & data = get_data(index); for (int i = 0; i != 16; ++i) q.decrease(handles[i], data[i] + (1<<max_data)); }
void *thread_serialcomm(void *parm) { struct serialsosurce *ss = (struct serialsosurce*)parm; RESTART: while (1) { usleep(1000); struct serialcommand *sc = get_data(ss->req, NULL); int ret; // clean serial // struct timeval tv_clean; // memset(&tv_clean, 0, sizeof(struct timeval)); // tv_clean.tv_sec = 0; // tv_clean.tv_usec = 0; // // fd_set rfds_clean; // FD_ZERO(&rfds_clean); // FD_SET(ss->fd, &rfds_clean); // // int ret = select(ss->fd+1, &rfds_clean, NULL, NULL, &tv_clean); // if (ret == -1) { // DEBUG("select error\n"); // free(sc); // goto RESTART; // } else if (ret == 0) { // DEBUG("never happen\n"); // free(sc); // goto RESTART; // } else { // char tmp[4096]; // read(ss->fd, tmp, 4096); // DEBUG("clean plc serial buffer\n"); // } if (_check_command(sc->buf, sc->sz) == 0) { DEBUG("cmd error\n"); free(sc); goto RESTART; } int num = 0; if (sc->buf[1] == 0x30) { // DATA size + STX(1 byte) + ETX(1 byte) + SUM(2 byte) num = ((sc->buf[6]-'0')*10 + (sc->buf[7]-'0'))*2+4; } else { num = 1; } if (num > 64*2+4) { free(sc); goto RESTART; } // write command ret = safe_write(ss->fd, sc->buf, sc->sz); if (ret < 0) { free(sc); goto RESTART; } ss->stats.n_send++; char resp[4096]; memset(resp, 0, sizeof(resp)); int sz = 0; char *p_resp = resp; for (;;) { struct timeval tv; memset(&tv, 0, sizeof(struct timeval)); tv.tv_sec = 5; tv.tv_usec = 0; fd_set rfds; FD_ZERO(&rfds); FD_SET(ss->fd, &rfds); ret = select(ss->fd+1, &rfds, NULL, NULL, &tv); if (ret == -1) { DEBUG("select error\n"); free(sc); goto RESTART; } else if (ret == 0) { DEBUG("time expired\n"); free(sc); goto RESTART; } else { int cnt = read(ss->fd, p_resp, num); if (cnt == 0) { DEBUG("serial error\n"); free(sc); goto RESTART; } num -= cnt; p_resp += cnt; sz += cnt; if (num == 0) { // call cb ss->stats.n_recv++; sc->cb(sc->cxt, resp, sz); break; } } } // free something free(sc); } return (void *)NULL; }
int ctp_simulate_ps_operate(void* self, uint32_t command, void* buff_in, int size_in, void* buff_out, int size_out, int* actualout) { int err=0; int value; hwm_sensor_data* sensor_data; struct ctp_simulate_priv *obj = (struct ctp_simulate_priv *)self; switch (command) { case SENSOR_DELAY: CTP_PS_LOG("SENSOR_DELAY \n"); break; case SENSOR_ENABLE: CTP_PS_LOG("[FT_PS] SENSOR_ENABLE \n"); if((buff_in == NULL) || (size_in < sizeof(int))) { CTP_PS_LOG("Enable sensor parameter error!\n"); err = -EINVAL; } else { value = *(int *)buff_in; if(value) { if(err != pls_enable()) { CTP_PS_LOG("enable ps fail: %d\n", err); return -1; } set_bit(CMC_BIT_PS, &obj->enable); } else { if(err != pls_disable()) { printk("disable ps fail: %d\n", err); return -1; } clear_bit(CMC_BIT_PS, &obj->enable); } } break; case SENSOR_GET_DATA: //printk("[FT_PS] SENSOR_GET_DATA \n"); if((buff_out == NULL) || (size_out< sizeof(hwm_sensor_data))) { CTP_PS_LOG("get sensor data parameter error!\n"); err = -EINVAL; } else { sensor_data = (hwm_sensor_data *)buff_out; CTP_PS_LOG("SENSOR_GET_DATA"); //mdelay(160); //printk("[FT_PS] ps_operate ps data=%d!\n",get_data()); sensor_data->values[0] = get_data(); sensor_data->value_divide = 1; sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM; } break; default: break; } return 0; }
T* get_data(STD::vector<T,Allocator> const & v) { return get_data(const_cast<STD::vector<T,Allocator>&>(v)); }
void chat_command_handler::do_network_send_req_arg() { if (get_data(1).empty()) return command_failed_need_arg(1); do_network_send(); }
void chat_command_handler::do_log() { chat_handler_.change_logging(get_data()); }
void chat_command_handler::do_emote() { chat_handler_.send_chat_message("/me " + get_data(), allies_only_); }
void chat_command_handler::do_network_send() { chat_handler_.send_command(get_cmd(), get_data()); }
void get_float_from_bus() { floatMessage[floatCounter] = get_data(); floatCounter += 1; }
void get_command_from_bus() { command[currentCommand] = get_data(); currentCommand += 1; }
void get_char_from_bus() { message[messageCounter] = get_data(); messageCounter += 1; messageLength = messageCounter; }
/** * rewrites the request URI of msg by calculating a rule, using * crc32 for hashing. The request URI is used to determine tree node * the given _user is used to determine the routing tree. * * @param msg the current SIP message * @param _uri the URI to determine the route tree (string or pseudo-variable) * @param _domain the requested routing domain * * @return 1 on success, -1 on failure */ int user_route_uri(struct sip_msg * _msg, char * _uri, char * _domain) { pv_elem_t *model; str uri, user, str_domain, ruser, ruri; struct sip_uri puri; int carrier_id, domain, index; domain = (int)(long)_domain; struct rewrite_data * rd = NULL; struct carrier_tree * ct = NULL; if (!_uri) { LM_ERR("bad parameter\n"); return -1; } if (parse_sip_msg_uri(_msg) < 0) { return -1; } /* Retrieve uri from parameter */ model = (pv_elem_t*)_uri; if (pv_printf_s(_msg, model, &uri)<0) { LM_ERR("cannot print the format\n"); return -1; } if (parse_uri(uri.s, uri.len, &puri) < 0) { LM_ERR("Error while parsing URI\n"); return -5; } user = puri.user; str_domain = puri.host; ruser.s = _msg->parsed_uri.user.s; ruser.len = _msg->parsed_uri.user.len; ruri.s = _msg->parsed_uri.user.s; ruri.len = _msg->parsed_uri.user.len; do { rd = get_data(); } while (rd == NULL); if ((carrier_id = load_user_carrier(&user, &str_domain)) < 0) { release_data(rd); return -1; } else if (carrier_id == 0) { index = rd->default_carrier_index; } else { if ((ct = get_carrier_tree(carrier_id, rd)) == NULL) { if (fallback_default) { index = rd->default_carrier_index; } else { LM_ERR("desired routing tree with id %i doesn't exist\n", carrier_id); release_data(rd); return -1; } } else { index = ct->index; } } release_data(rd); return carrier_rewrite_msg(index, domain, &ruri, _msg, &ruser, shs_call_id, alg_crc32); }
static void parse_command_line(int argc, char *argv[], train_info_t *train, sm_info_t *sm, data_info_t *data, classify_t *clssfy, char *out) { char n_dtr[MAX_BUF], n_ltr[MAX_BUF]; char n_mix[MAX_BUF]; char n_clssfy[MAX_BUF]; char ch; while((ch = getopt(argc, argv, "c:n:s:o:t:T:")) != -1) { switch(ch) { case 'c': _char_replace(optarg, ',', ' '); sscanf(optarg, "%d %s", &clssfy->numclass, n_clssfy); printf("[c]%s:%d,%s[%ld]\n", optarg, clssfy->numclass, n_clssfy, strlen(n_clssfy)); break; case 'n': _char_replace(optarg, ',', ' '); sscanf(optarg, "%d %d %d %d %s", &train->iteration, &train->batchsize, &train->mininumcase, &train->nummix, n_mix); printf("[n]%s:%dx%dx%dx%d,%s[%ld]\n", optarg, train->iteration, train->batchsize, train->mininumcase, train->nummix, n_mix, strlen(n_mix)); break; case 's': _char_replace(optarg, ',', ' '); construct_sm(sm, optarg); printf("[s]%s\n", optarg); break; case 'o': strncpy(out, optarg, MAX_BUF); break; case 't': _char_replace(optarg, ',', ' '); sscanf(optarg, "%d %d %d %s %s", &data->channelcase, &data->numchannel, &data->numcase, n_dtr, n_ltr); printf("[t]%s:%d,%s[%ld],%s[%ld]\n", optarg, data->numcase, n_dtr, strlen(n_dtr), n_ltr, strlen(n_ltr)); break; default: fprintf(stderr, "don't know [%c]\n", ch); exit(0); } } fprintf(stdout, "other para:\n" "\ttraindata|tainlabel:%s|%s\n" "\tmix|classify:%s|%s\n", n_dtr, n_ltr, n_mix, n_clssfy); clssfy->lencase = sm->numhid; clssfy->numcase = train->mininumcase * train->nummix; clssfy_build(clssfy); clssfy->w = malloc(clssfy->lencase * clssfy->numclass * sizeof(double)); if (clssfy->w == NULL) { fprintf(stderr, "malloc clssfy->w error!\n"); exit(0); } get_data(n_clssfy, clssfy->w, clssfy->lencase * clssfy->numclass * sizeof(double)); _pr_train_info(train, "train info"); _pr_sm_info(sm, "sm info"); _pr_data_info(data, "train data info"); _pr_classify(clssfy, "clssfy"); data->data = (uint8_t *) malloc((long)data->numcase * data->channelcase * data->numchannel * sizeof(uint8_t)); data->labels = (int *) malloc(data->numcase * sizeof(int)); if (!(data->data && data->labels)) { fprintf(stderr, "malloc error!\n"); exit(0); } get_data(n_ltr, data->labels, data->numcase * sizeof(int)); get_data(n_dtr, data->data, (long)data->numcase * data->channelcase * data->numchannel * sizeof(uint8_t)); train->mix = (double *) malloc(train->nummix * data->numchannel * sizeof(double)); if (!train->mix) { fprintf(stderr, "malloc error!\n"); exit(0); } get_data(n_mix, train->mix, train->nummix * data->numchannel * sizeof(double)); }
int main(int argc, char *argv[]) { int opt; int can; struct ifreq ifr; struct sockaddr_can addr; struct canfd_frame frame; struct iovec iov; struct msghdr msg; struct cmsghdr *cmsg; struct timeval tv, timeout_config = { 0, 0 }; fd_set rdfs; char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))]; int running = 1; int nbytes, maxdlen; int ret; int seed = 0; int door_id, signal_id, speed_id; SDL_Event event; while ((opt = getopt(argc, argv, "rs:dh?")) != -1) { switch(opt) { case 'r': randomize = 1; break; case 's': seed = atoi(optarg); break; case 'd': debug = 1; break; case 'h': case '?': default: Usage(NULL); break; } } if (optind >= argc) Usage("You must specify at least one can device"); if (seed && randomize) Usage("You can not specify a seed value AND randomize the seed"); // Create a new raw CAN socket can = socket(PF_CAN, SOCK_RAW, CAN_RAW); if(can < 0) Usage("Couldn't create raw socket"); addr.can_family = AF_CAN; memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, argv[optind], strlen(argv[optind])); printf("Using CAN interface %s\n", ifr.ifr_name); if (ioctl(can, SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); exit(1); } addr.can_ifindex = ifr.ifr_ifindex; // CAN FD Mode setsockopt(can, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)); iov.iov_base = &frame; iov.iov_len = sizeof(frame); msg.msg_name = &addr; msg.msg_namelen = sizeof(addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = &ctrlmsg; msg.msg_controllen = sizeof(ctrlmsg); msg.msg_flags = 0; if (bind(can, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); return 1; } init_car_state(); door_id = DEFAULT_DOOR_ID; signal_id = DEFAULT_SIGNAL_ID; speed_id = DEFAULT_SPEED_ID; if (randomize || seed) { if(randomize) seed = time(NULL); srand(seed); door_id = (rand() % 2046) + 1; signal_id = (rand() % 2046) + 1; speed_id = (rand() % 2046) + 1; door_pos = rand() % 9; signal_pos = rand() % 9; speed_pos = rand() % 8; printf("Seed: %d\n", seed); } SDL_Window *window = NULL; SDL_Surface *screenSurface = NULL; if(SDL_Init ( SDL_INIT_VIDEO ) < 0 ) { printf("SDL Could not initializes\n"); exit(40); } window = SDL_CreateWindow("IC Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if(window == NULL) { printf("Window could not be shown\n"); } renderer = SDL_CreateRenderer(window, -1, 0); SDL_Surface *image = IMG_Load(get_data("ic.png")); SDL_Surface *needle = IMG_Load(get_data("needle.png")); SDL_Surface *sprites = IMG_Load(get_data("spritesheet.png")); base_texture = SDL_CreateTextureFromSurface(renderer, image); needle_tex = SDL_CreateTextureFromSurface(renderer, needle); sprite_tex = SDL_CreateTextureFromSurface(renderer, sprites); speed_rect.x = 212; speed_rect.y = 175; speed_rect.h = needle->h; speed_rect.w = needle->w; // Draw the IC redraw_ic(); /* For now we will just operate on one CAN interface */ while(running) { while( SDL_PollEvent(&event) != 0 ) { switch(event.type) { case SDL_QUIT: running = 0; break; } } nbytes = recvmsg(can, &msg, 0); if (nbytes < 0) { perror("read"); return 1; } if ((size_t)nbytes == CAN_MTU) maxdlen = CAN_MAX_DLEN; else if ((size_t)nbytes == CANFD_MTU) maxdlen = CANFD_MAX_DLEN; else { fprintf(stderr, "read: incomplete CAN frame\n"); return 1; } for (cmsg = CMSG_FIRSTHDR(&msg); cmsg && (cmsg->cmsg_level == SOL_SOCKET); cmsg = CMSG_NXTHDR(&msg,cmsg)) { if (cmsg->cmsg_type == SO_TIMESTAMP) tv = *(struct timeval *)CMSG_DATA(cmsg); else if (cmsg->cmsg_type == SO_RXQ_OVFL) //dropcnt[i] = *(__u32 *)CMSG_DATA(cmsg); fprintf(stderr, "Dropped packet\n"); } // if(debug) fprint_canframe(stdout, &frame, "\n", 0, maxdlen); if(frame.can_id == door_id) update_door_status(&frame, maxdlen); if(frame.can_id == signal_id) update_signal_status(&frame, maxdlen); if(frame.can_id == speed_id) update_speed_status(&frame, maxdlen); } SDL_DestroyTexture(base_texture); SDL_DestroyTexture(needle_tex); SDL_DestroyTexture(sprite_tex); SDL_FreeSurface(image); SDL_FreeSurface(needle); SDL_FreeSurface(sprites); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); IMG_Quit(); SDL_Quit(); return 0; }
void process_field(DRIVE_PARAMS *drive_params, uint8_t track[], int trk_offset, int length, FIELD_L field_def[], int a1_list[], int *a1_list_ndx, int a1_list_len) { int ndx = 0; uint64_t value; int i; int data_set; int crc_start = 0; int crc_end = -1; int field_filled = 0; //printf("Process field called start %d\n",trk_offset); while (field_def[ndx].len_bytes != -1) { data_set = 0; switch (field_def[ndx].type) { case FIELD_FILL: if (field_def[ndx].byte_offset_bit_len + field_def[ndx].len_bytes > length) { msg(MSG_FATAL, "Track overflow field fill %d, %d, %d\n", field_def[ndx].byte_offset_bit_len, field_def[ndx].len_bytes, length); exit(1); } memset(&track[field_def[ndx].byte_offset_bit_len], field_def[ndx].value, field_def[ndx].len_bytes); data_set = 1; if (field_def[ndx].op != OP_SET) { msg(MSG_FATAL, "Only OP_SET currently supported for FIELD_FILL\n"); exit(1); } break; case FIELD_CYL: value = get_cyl(); break; case FIELD_HEAD: value = get_head(); break; case FIELD_SECTOR: value = get_sector(); break; case FIELD_LBA: value = get_lba(drive_params); break; case FIELD_HDR_CRC: if (crc_end == -1) { crc_end = field_def[ndx].byte_offset_bit_len - 1; } value = get_check_value(&track[crc_start], crc_end - crc_start + 1, &drive_params->header_crc, mfm_controller_info[drive_params->controller].header_check); break; case FIELD_DATA_CRC: if (crc_end == -1) { crc_end = field_def[ndx].byte_offset_bit_len - 1; } value = get_check_value(&track[crc_start], crc_end - crc_start + 1, &drive_params->data_crc, mfm_controller_info[drive_params->controller].data_check); break; case FIELD_MARK_CRC_START: crc_start = field_def[ndx].byte_offset_bit_len; data_set = 1; break; case FIELD_MARK_CRC_END: crc_end = field_def[ndx].byte_offset_bit_len; data_set = 1; break; case FIELD_TRK_DATA: get_data(drive_params, &track[field_def[ndx].byte_offset_bit_len]); data_set = 1; inc_sector(drive_params); break; case FIELD_BAD_BLOCK: value = 0; break; case FIELD_A1: if (*a1_list_ndx >= a1_list_len) { msg(MSG_FATAL, "A1 list overflow\n"); exit(1); } a1_list[(*a1_list_ndx)++] = trk_offset + field_def[ndx].byte_offset_bit_len; value = 0xa1; break; default: msg(MSG_FATAL, "Unknown field_def type %d\n",field_def[ndx].type); exit(1); } if (data_set) { field_filled = MAX(field_filled, field_def[ndx].byte_offset_bit_len + field_def[ndx].len_bytes - 1); } else if (!data_set && field_def[ndx].bit_list == NULL) { field_filled = MAX(field_filled, field_def[ndx].byte_offset_bit_len + field_def[ndx].len_bytes - 1); //printf("value %lld len %d %d %d\n",value, field_def[ndx].byte_offset_bit_len , field_def[ndx].len_bytes, length); if (field_def[ndx].byte_offset_bit_len + field_def[ndx].len_bytes > length) { msg(MSG_FATAL, "Track overflow field update %d %d %d\n", field_def[ndx].byte_offset_bit_len, field_def[ndx].len_bytes, length); exit(1); } value <<= (sizeof(value) - field_def[ndx].len_bytes) * 8; for (i = 0; i < field_def[ndx].len_bytes; i++) { int wbyte = (value >> (sizeof(value)*8 - 8)); if (field_def[ndx].op == OP_XOR) { track[field_def[ndx].byte_offset_bit_len + i] ^= wbyte; } else { track[field_def[ndx].byte_offset_bit_len + i] = wbyte; } value <<= 8; } } else {
int8_t StreamPeer::get_8() { uint8_t buf[1]; get_data(buf, 1); return buf[0]; }
void generic_worker_thread::do_work( ) { bool could_work; int number_units_of_work = 0; bool only_run_thread_queue = false; do { could_work = false; coroutine work_to_do; if ( run_next ) { work_to_do = std::move( run_next.get( ) ); run_next = boost::none; goto do_work; } while ( get_internals( ).thread_queue_size > 0 ) { if ( get_internals( ).thread_queue.try_dequeue( work_to_do ) ) { --get_internals( ).thread_queue_size; goto do_work; } } while ( get_data( ).work_queue_prio_size > 0 && !only_run_thread_queue ) { if ( get_data( ).work_queue_prio.try_dequeue_from_producer( internals->ptok_prio, work_to_do ) || get_data( ).work_queue_prio.try_dequeue( work_to_do ) ) { --get_data( ).work_queue_prio_size; goto do_work; } } while ( get_data( ).work_queue_size > 0 && !only_run_thread_queue ) { if ( get_data( ).work_queue.try_dequeue_from_producer( internals->ptok, work_to_do ) || get_data( ).work_queue.try_dequeue( work_to_do ) ) { --get_data( ).work_queue_size; goto do_work; } if ( get_data( ).work_queue_prio.try_dequeue_from_producer( internals->ptok_prio, work_to_do ) || get_data( ).work_queue_prio.try_dequeue( work_to_do ) ) { --get_data( ).work_queue_prio_size; goto do_work; } } could_work = false; break; do_work: ++get_data( ).working_threads; BOOST_SCOPE_EXIT_ALL( & ) { --get_data( ).working_threads; }; if ( !work_to_do.can_be_run_by_thread( this_wthread ) ) { // we reschedule it and hope it is run by a different thread. LOG( ) << "Rescheduling cor: " << work_to_do.get_id( ) << " thr id: " << boost::this_thread::get_id( ); global_thr_pool.schedule( std::move( work_to_do ), true ); only_run_thread_queue = true; continue; } ++number_units_of_work; could_work = true; running_coroutine = &work_to_do; work_to_do.set_forbidden_thread( nullptr ); work_to_do.switch_to_from( *master_coroutine ); assert( running_coroutine == &work_to_do ); if ( *after_yield ) { ( *after_yield )( std::move( work_to_do ) ); *after_yield = nullptr; } running_coroutine = master_coroutine; // if we think that other threads are waiting apart // from this one, we wake them up. global_thr_pool.plat_wakeup_threads( ); } while ( could_work ); LOG( ) << "Thread " << boost::this_thread::get_id( ) << " performed " << number_units_of_work; }
const T* get_data(STD::valarray<T> const& v) { return get_data(const_cast<STD::valarray<T>&>(v)); }
/* * Generate a section header cache made up of information derived * from the program headers. * * entry: * file - Name of object * fd - Open file handle for object * elf - ELF descriptor * ehdr - Elf header * cache, shnum - Addresses of variables to receive resulting * cache and number of sections. * * exit: * On success, *cache and *shnum are set, and True (1) is returned. * On failure, False (0) is returned. * * note: * The cache returned by this routine must be freed using * fake_shdr_cache_free(), and not by a direct call to free(). * Otherwise, memory will leak. */ int fake_shdr_cache(const char *file, int fd, Elf *elf, Ehdr *ehdr, Cache **cache, size_t *shnum) { /* * The C language guarantees that a structure of homogeneous * items will receive exactly the same layout in a structure * as a plain array of the same type. Hence, this structure, which * gives us by-name or by-index access to the various section * info descriptors we maintain. * * We use this for sections where * - Only one instance is allowed * - We need to be able to access them easily by * name (for instance, when mining the .dynamic * section for information to build them up. * * NOTE: These fields must be in the same order as the * SINFO_T_ type codes that correspond to them. Otherwise, * they will end up in the wrong order in the cache array, * and the sh_link/sh_info fields may be wrong. */ struct { /* Note: No entry is needed for SINFO_T_NULL */ SINFO dyn; SINFO dynstr; SINFO dynsym; SINFO ldynsym; SINFO hash; SINFO syminfo; SINFO symsort; SINFO tlssort; SINFO verneed; SINFO verdef; SINFO versym; SINFO interp; SINFO cap; SINFO capinfo; SINFO capchain; SINFO unwind; SINFO move; SINFO rel; SINFO rela; SINFO preinitarr; SINFO initarr; SINFO finiarr; } sec; static const size_t sinfo_n = sizeof (sec) / sizeof (sec.dyn); SINFO *secarr = (SINFO *) &sec; /* * Doubly linked circular list, used to track sections * where multiple sections of a given type can exist. * seclist is the root of the list. Its sinfo field is not * used --- it serves to anchor the root of the list, allowing * rapid access to the first and last element in the list. */ SINFO_LISTELT seclist; FSTATE fstate; size_t ndx; size_t num_sinfo, num_list_sinfo; SINFO *sinfo; SINFO_LISTELT *sinfo_list; Cache *_cache; fstate.file = file; fstate.fd = fd; fstate.ehdr = ehdr; if (elf_getphdrnum(elf, &fstate.phnum) == -1) { failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM)); return (0); } if ((fstate.phdr = elf_getphdr(elf)) == NULL) { failure(file, MSG_ORIG(MSG_ELF_GETPHDR)); return (0); } bzero(&sec, sizeof (sec)); /* Initialize "by-name" sec info */ seclist.next = seclist.prev = &seclist; /* Empty circular list */ /* * Go through the program headers and look for information * we can use to synthesize section headers. By far the most * valuable thing is a dynamic section, the contents of * which point at all sections used by ld.so.1. */ for (ndx = 0; ndx < fstate.phnum; ndx++) { /* * A program header with no file size does * not have a backing section. */ if (fstate.phdr[ndx].p_filesz == 0) continue; switch (fstate.phdr[ndx].p_type) { default: /* Header we can't use. Move on to next one */ continue; case PT_DYNAMIC: sec.dyn.type = SINFO_T_DYN; sinfo = &sec.dyn; break; case PT_INTERP: sec.interp.type = SINFO_T_INTERP; sinfo = &sec.interp; break; case PT_NOTE: if ((sinfo = sinfo_list_alloc(&fstate, &seclist)) == NULL) continue; sinfo->type = SINFO_T_NOTE; break; case PT_SUNW_UNWIND: case PT_SUNW_EH_FRAME: sec.unwind.type = SINFO_T_UNWIND; sinfo = &sec.unwind; break; case PT_SUNWCAP: sec.cap.type = SINFO_T_CAP; sinfo = &sec.cap; break; } /* * Capture the position/extent information for * the header in the SINFO struct set up by the * switch statement above. */ sinfo->vaddr = fstate.phdr[ndx].p_vaddr; sinfo->offset = fstate.phdr[ndx].p_offset; sinfo->size = fstate.phdr[ndx].p_filesz; } /* * If we found a dynamic section, look through it and * gather information about the sections it references. */ if (sec.dyn.type == SINFO_T_DYN) (void) get_data(&fstate, &sec.dyn); if ((sec.dyn.type == SINFO_T_DYN) && (sec.dyn.data->d_buf != NULL)) { Dyn *dyn; for (dyn = sec.dyn.data->d_buf; dyn->d_tag != DT_NULL; dyn++) { switch (dyn->d_tag) { case DT_HASH: sec.hash.type = SINFO_T_HASH; sec.hash.vaddr = dyn->d_un.d_ptr; break; case DT_STRTAB: sec.dynstr.type = SINFO_T_DYNSTR; sec.dynstr.vaddr = dyn->d_un.d_ptr; break; case DT_SYMTAB: sec.dynsym.type = SINFO_T_DYNSYM; sec.dynsym.vaddr = dyn->d_un.d_ptr; break; case DT_RELA: sec.rela.type = SINFO_T_RELA; sec.rela.vaddr = dyn->d_un.d_ptr; break; case DT_RELASZ: sec.rela.size = dyn->d_un.d_val; break; case DT_STRSZ: sec.dynstr.size = dyn->d_un.d_val; break; case DT_REL: sec.rel.type = SINFO_T_REL; sec.rel.vaddr = dyn->d_un.d_ptr; break; case DT_RELSZ: sec.rel.size = dyn->d_un.d_val; break; case DT_INIT_ARRAY: sec.initarr.type = SINFO_T_INITARR; sec.initarr.vaddr = dyn->d_un.d_ptr; break; case DT_INIT_ARRAYSZ: sec.initarr.size = dyn->d_un.d_val; break; case DT_FINI_ARRAY: sec.finiarr.type = SINFO_T_FINIARR; sec.finiarr.vaddr = dyn->d_un.d_ptr; break; case DT_FINI_ARRAYSZ: sec.finiarr.size = dyn->d_un.d_val; break; case DT_PREINIT_ARRAY: sec.preinitarr.type = SINFO_T_PREINITARR; sec.preinitarr.vaddr = dyn->d_un.d_ptr; break; case DT_PREINIT_ARRAYSZ: sec.preinitarr.size = dyn->d_un.d_val; break; case DT_SUNW_CAPINFO: sec.capinfo.type = SINFO_T_CAPINFO; sec.capinfo.vaddr = dyn->d_un.d_ptr; break; case DT_SUNW_CAPCHAIN: sec.capchain.type = SINFO_T_CAPCHAIN; sec.capchain.vaddr = dyn->d_un.d_ptr; break; case DT_SUNW_SYMTAB: sec.ldynsym.type = SINFO_T_LDYNSYM; sec.ldynsym.vaddr = dyn->d_un.d_ptr; break; case DT_SUNW_SYMSZ: sec.ldynsym.size = dyn->d_un.d_val; break; case DT_SUNW_SYMSORT: sec.symsort.type = SINFO_T_SYMSORT; sec.symsort.vaddr = dyn->d_un.d_ptr; break; case DT_SUNW_SYMSORTSZ: sec.symsort.size = dyn->d_un.d_val; break; case DT_SUNW_TLSSORT: sec.tlssort.type = SINFO_T_TLSSORT; sec.tlssort.vaddr = dyn->d_un.d_ptr; break; case DT_SUNW_TLSSORTSZ: sec.tlssort.size = dyn->d_un.d_val; break; case DT_MOVETAB: sec.move.type = SINFO_T_MOVE; sec.move.vaddr = dyn->d_un.d_ptr; break; case DT_MOVESZ: sec.move.size = dyn->d_un.d_val; break; case DT_SYMINFO: sec.syminfo.type = SINFO_T_SYMINFO; sec.syminfo.vaddr = dyn->d_un.d_ptr; break; case DT_SYMINSZ: sec.syminfo.size = dyn->d_un.d_val; break; case DT_VERSYM: sec.versym.type = SINFO_T_VERSYM; sec.versym.vaddr = dyn->d_un.d_ptr; break; case DT_VERDEF: sec.verdef.type = SINFO_T_VERDEF; sec.verdef.vaddr = dyn->d_un.d_ptr; break; case DT_VERDEFNUM: sec.verdef.vercnt = dyn->d_un.d_val; sec.verdef.size = sizeof (Verdef) * dyn->d_un.d_val; break; case DT_VERNEED: sec.verneed.type = SINFO_T_VERNEED; sec.verneed.vaddr = dyn->d_un.d_ptr; break; case DT_VERNEEDNUM: sec.verneed.vercnt = dyn->d_un.d_val; sec.verneed.size = sizeof (Verneed) * dyn->d_un.d_val; break; } } } /* * Different sections depend on each other, and are meaningless * without them. For instance, even if a .dynsym exists, * no use can be made of it without a dynstr. These relationships * fan out: Disqualifying the .dynsym will disqualify the hash * section, and so forth. * * Disqualify sections that don't have the necessary prerequisites. */ /* Things that need the dynamic string table */ if (sec.dynstr.size == 0) sec.dynstr.type = SINFO_T_NULL; if (sec.dynstr.type != SINFO_T_DYNSTR) { sinfo_free(&sec.dyn, 1); /* Data already fetched */ sec.dynsym.type = SINFO_T_NULL; sec.dynsym.type = SINFO_T_NULL; sec.verdef.type = SINFO_T_NULL; sec.verneed.type = SINFO_T_NULL; } /* * The length of the hash section is encoded in its first two * elements (nbucket, and nchain). The length of the dynsym, * ldynsym, and versym are not given in the dynamic section, * but are known to be the same as nchain. * * If we don't have a hash table, or cannot read nbuckets and * nchain, we have to invalidate all of these. */ if (sec.hash.type == SINFO_T_HASH) { Word nbucket; Word nchain; size_t total; if (hash_size(&fstate, &sec.hash, &nbucket, &nchain, &total) == 0) { sec.hash.type = SINFO_T_NULL; } else { /* Use these counts to set sizes for related sections */ sec.hash.size = total * sizeof (Word); sec.dynsym.size = nchain * sizeof (Sym); sec.versym.size = nchain * sizeof (Versym); /* * The ldynsym size received the DT_SUNW_SYMSZ * value, which is the combined size of .dynsym * and .ldynsym. Now that we have the dynsym size, * use it to lower the ldynsym size to its real size. */ if (sec.ldynsym.size > sec.dynsym.size) sec.ldynsym.size -= sec.dynsym.size; } } /* * If the hash table is not present, or if the call to * hash_size() failed, then discard the sections that * need it to determine their length. */ if (sec.hash.type != SINFO_T_HASH) { sec.dynsym.type = SINFO_T_NULL; sec.ldynsym.type = SINFO_T_NULL; sec.versym.type = SINFO_T_NULL; } /* * The runtime linker does not receive size information for * Verdef and Verneed sections. We have to read their data * in pieces and calculate it. */ if ((sec.verdef.type == SINFO_T_VERDEF) && (verdefneed_size(&fstate, &sec.verdef) == 0)) sec.verdef.type = SINFO_T_NULL; if ((sec.verneed.type == SINFO_T_VERNEED) && (verdefneed_size(&fstate, &sec.verneed) == 0)) sec.verneed.type = SINFO_T_NULL; /* Discard any section with a zero length */ ndx = sinfo_n; for (sinfo = secarr; ndx-- > 0; sinfo++) if ((sinfo->type != SINFO_T_NULL) && (sinfo->size == 0)) sinfo->type = SINFO_T_NULL; /* Things that need the dynamic symbol table */ if (sec.dynsym.type != SINFO_T_DYNSYM) { sec.ldynsym.type = SINFO_T_NULL; sec.hash.type = SINFO_T_NULL; sec.syminfo.type = SINFO_T_NULL; sec.versym.type = SINFO_T_NULL; sec.move.type = SINFO_T_NULL; sec.rel.type = SINFO_T_NULL; sec.rela.type = SINFO_T_NULL; } /* Things that need the dynamic local symbol table */ if (sec.ldynsym.type != SINFO_T_DYNSYM) { sec.symsort.type = SINFO_T_NULL; sec.tlssort.type = SINFO_T_NULL; } /* * Look through the results and fetch the data for any sections * we have found. At the same time, count the number. */ num_sinfo = num_list_sinfo = 0; ndx = sinfo_n; for (sinfo = secarr; ndx-- > 0; sinfo++) { if ((sinfo->type != SINFO_T_NULL) && (sinfo->data == NULL)) (void) get_data(&fstate, sinfo); if (sinfo->data != NULL) num_sinfo++; } for (sinfo_list = seclist.next; sinfo_list != &seclist; sinfo_list = sinfo_list->next) { sinfo = &sinfo_list->sinfo; if ((sinfo->type != SINFO_T_NULL) && (sinfo->data == NULL)) (void) get_data(&fstate, sinfo); if (sinfo->data != NULL) num_list_sinfo++; } /* * Allocate the cache array and fill it in. The cache array * ends up taking all the dynamic memory we've allocated * to build up sec and seclist, so on success, we have nothing * left to clean up. If we can't allocate the cache array * though, we have to free up everything else. */ *shnum = num_sinfo + num_list_sinfo + 1; /* Extra for 1st NULL sec. */ if ((*cache = _cache = malloc((*shnum) * sizeof (Cache))) == NULL) { int err = errno; (void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC), file, strerror(err)); sinfo_free(secarr, num_sinfo); sinfo_list_free_all(&seclist); return (0); } *_cache = cache_init; _cache++; ndx = 1; for (sinfo = secarr; num_sinfo > 0; sinfo++) { if (sinfo->data != NULL) { _cache->c_scn = NULL; _cache->c_shdr = sinfo->shdr; _cache->c_data = sinfo->data; _cache->c_name = (char *)sinfo_data[sinfo->type].name; _cache->c_ndx = ndx++; _cache++; num_sinfo--; } } for (sinfo_list = seclist.next; num_list_sinfo > 0; sinfo_list = sinfo_list->next) { sinfo = &sinfo_list->sinfo; if (sinfo->data != NULL) { _cache->c_scn = NULL; _cache->c_shdr = sinfo->shdr; _cache->c_data = sinfo->data; _cache->c_name = (char *)sinfo_data[sinfo->type].name; _cache->c_ndx = ndx++; _cache++; num_list_sinfo--; } } return (1); }
// START FUNC DECL int ext_approx_frequent( char *tbl, char *fld, char *cfld, char *outtbl, char *str_min_freq, char *str_max_err, int *ptr_is_good ) // STOP FUNC DECL { int status = 0; TBL_REC_TYPE outtbl_rec; int outtbl_id; TBL_REC_TYPE tbl_rec; int tbl_id; FLD_REC_TYPE fld_rec; int fld_id; FLD_REC_TYPE cfld_rec; int cfld_id; FLD_REC_TYPE out_val_fld_rec; int out_val_fld_id; FLD_REC_TYPE out_cnt_fld_rec; int out_cnt_fld_id; FLD_REC_TYPE nn_fld_rec; int nn_fld_id; FLD_REC_TYPE nn_cfld_rec; int nn_cfld_id; char *fld_X = NULL; size_t fld_nX = 0; char *nn_fld_X = NULL; size_t nn_fld_nX = 0; char *out_val_X = NULL; size_t out_val_nX = 0; char *out_cnt_X = NULL; size_t out_cnt_nX = 0; char *cfld_X = NULL; size_t cfld_nX = 0; int fldsz = 0; size_t filesz = 0; long long nR = 0, nR_out = 0, actual_nR_out = 0; int out_val_ddir_id = -1, out_val_fileno = -1; int out_cnt_ddir_id = -1, out_cnt_fileno = -1; long long min_freq; long long max_err; if ( ( tbl == NULL ) || ( *tbl == '\0' ) ) { go_BYE(-1); } if ( ( fld == NULL ) || ( *fld == '\0' ) ) { go_BYE(-1); } if ( ( outtbl == NULL ) || ( *outtbl == '\0' ) ) { go_BYE(-1); } if ( ( str_min_freq == NULL ) || ( *str_min_freq == '\0' ) ) { go_BYE(-1); } if ( ( str_max_err == NULL ) || ( *str_max_err == '\0' ) ) { go_BYE(-1); } if ( strcmp(tbl, outtbl) == 0 ) { go_BYE(-1); } status = stoI8(str_min_freq, &min_freq); cBYE(status); status = stoI8(str_max_err, &max_err); cBYE(status); if ( min_freq <= 1 ) { go_BYE(-1); } if ( max_err <= 1 ) { go_BYE(-1); } if ( ( min_freq - max_err ) < 1 ) { go_BYE(-1); } status = is_tbl(tbl, &tbl_id, &tbl_rec); cBYE(status); if ( tbl_id < 0 ) { go_BYE(-1); } nR = tbl_rec.nR; status = is_fld(NULL, tbl_id, fld, &fld_id, &fld_rec, &nn_fld_id,&nn_fld_rec); cBYE(status); if ( fld_id < 0 ) { go_BYE(-1); } status = get_data(fld_rec, &fld_X, &fld_nX, false); cBYE(status); if ( fld_rec.fldtype != I4 ) { go_BYE(-1); } // Get nn field for f1 if if it exists if ( nn_fld_id >= 0 ) { status = get_data(nn_fld_rec, &nn_fld_X, &nn_fld_nX, false); cBYE(status); if ( ( cfld == NULL ) && ( *cfld == '\0' ) ) { go_BYE(-1); } cfld_X = nn_fld_X; } else { if ( ( cfld == NULL ) && ( *cfld == '\0' ) ) { status = is_fld(NULL, tbl_id, cfld, &cfld_id, &cfld_rec, &nn_cfld_id,&nn_cfld_rec); cBYE(status); if ( cfld_id < 0 ) { go_BYE(-1); } status = get_data(cfld_rec, &cfld_X, &cfld_nX, false); cBYE(status); if ( cfld_rec.fldtype != I1 ) { go_BYE(-1); } } else { cfld_X = NULL; } } // TODO P3: Compute sum of cfld here and send to Kishore. // Compute worst case for nR_out nR_out = nR / ( min_freq - max_err ); zero_fld_rec(&out_cnt_fld_rec); out_cnt_fld_rec.fldtype = I4; // Note that count is I4 status = get_fld_sz(out_cnt_fld_rec.fldtype, &fldsz); cBYE(status); filesz = nR_out * fldsz; status = mk_temp_file(filesz, &out_cnt_ddir_id, &out_cnt_fileno); cBYE(status); status = q_mmap(out_cnt_ddir_id, out_cnt_fileno, &out_cnt_X, &out_cnt_nX, true); cBYE(status); zero_fld_rec(&out_val_fld_rec); out_val_fld_rec.fldtype = fld_rec.fldtype; status = get_fld_sz(out_val_fld_rec.fldtype, &fldsz); cBYE(status); filesz = nR_out * fldsz; status = mk_temp_file(filesz, &out_val_ddir_id, &out_val_fileno); cBYE(status); status = q_mmap(out_val_ddir_id, out_val_fileno, &out_val_X, &out_val_nX, true); cBYE(status); // Now the real work begins status = approx_frequent((int *)fld_X, (char *)cfld_X, nR, min_freq, max_err, (int *)out_val_X, (int *)out_cnt_X, nR_out, &actual_nR_out, ptr_is_good); cBYE(status); // truncate output as needed if ( actual_nR_out <= 0 ) { go_BYE(-1); } status = get_fld_sz(out_val_fld_rec.fldtype, &fldsz); cBYE(status); filesz = actual_nR_out * fldsz; status = q_trunc(out_val_ddir_id, out_val_fileno, filesz); cBYE(status); status = get_fld_sz(I4, &fldsz); cBYE(status); filesz = actual_nR_out * fldsz; status = q_trunc(out_cnt_ddir_id, out_cnt_fileno, filesz); cBYE(status); //---------------------------------------- char strbuf[32]; zero_string(strbuf, 32); sprintf(strbuf, "%lld", actual_nR_out); status = add_tbl(outtbl, strbuf, &outtbl_id, &outtbl_rec); cBYE(status); status = add_fld(outtbl_id, "cnt", out_cnt_ddir_id, out_cnt_fileno, &out_cnt_fld_id, &out_cnt_fld_rec); cBYE(status); status = add_fld(outtbl_id, fld, out_val_ddir_id, out_val_fileno, &out_val_fld_id, &out_val_fld_rec); cBYE(status); BYE: rs_munmap(fld_X, fld_nX); rs_munmap(out_val_X, out_val_nX); rs_munmap(out_cnt_X, out_cnt_nX); return status ; }
void InferenceStatistics::add_subset(const Subset &s, AssignmentContainer *ss) { subsets_[s] = get_data(s, ss); }
void main(){ FILE *infile,*outfile; char currch,nextch,*ch,chp[100]; staggered_list *listpointer,*root=create_list_with_file("B:keywords"); int dat,length_of; TOKEN *token,t; int g2_001_DATA_A; int g3_001_DOUBLE_SUBTREE_A; int g4_001_SINGLE_SUBTREE_A; int g5_001_KEYWORD_OR_WORD_A; /**************************************************************************/ /**************************************************************************/ /******************** DRIVING PROCEDURE B:\ALSCAN *********************/ /**************************************************************************/ PROCEDURE_DIVISION: /**/ /** takes the output from allinescan*/ /** which is one line with all the cobol*/ /** details on it, rather than cobol details*/ /** */ /** being spread across a number of lines*/ /**/ C1_001_SCAN: goto C1_002_SCAN_START; C1_002_SCAN_START_EX: goto C1_003_LINES; C1_003_LINES_EX: goto C1_013_EOF; C1_013_EOF_EX: goto veryend; /**/ C1_002_SCAN_START: /*001*/ infile=open_input("b:\\testout.dat"); /*003*/ currch=getc(infile); if(currch!=EOF) nextch=getc(infile); /*033*/ token=&t; /*021*/ outfile=open_output("b:\\testout2.dat"); goto C1_002_SCAN_START_EX; /**/ C1_003_LINES: C1_004_LINE_EX: if(!( /*C01*/ (currch==EOF) )) goto C1_004_LINE; goto C1_003_LINES_EX; /**/ C1_004_LINE: goto C1_005_LINE_START; C1_005_LINE_START_EX: goto C1_006_CHUNKS; C1_006_CHUNKS_EX: goto C1_012_BACKSLASH_N; C1_012_BACKSLASH_N_EX: goto C1_004_LINE_EX; /**/ C1_005_LINE_START: /*016*/ /*printf("START OF LINE\n");*/ goto C1_005_LINE_START_EX; /**/ C1_006_CHUNKS: C1_007_CHUNK_EX: if(!( /*C02*/ (currch=='\n') )) goto C1_007_CHUNK; goto C1_006_CHUNKS_EX; /**/ C1_007_CHUNK: goto C1_008_START_CHUNK; C1_008_START_CHUNK_EX: goto C1_009_BLANKS; C1_009_BLANKS_EX: goto C1_011_DATA; C1_011_DATA_EX: goto C1_007_CHUNK_EX; /**/ C1_008_START_CHUNK: /*005*/ ch=chp; goto C1_008_START_CHUNK_EX; /**/ C1_009_BLANKS: C1_010_BLANK_EX: if(!( /*C03*/ (currch!=' ') )) goto C1_010_BLANK; goto C1_009_BLANKS_EX; /**/ C1_010_BLANK: /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C1_010_BLANK_EX; /**/ C1_011_DATA: g2_001_DATA_A=0; goto C2_001_DATA; C2_001_EXIT01: goto C1_011_DATA_EX; /**/ C1_012_BACKSLASH_N: /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); /*015*/ /*printf("END LINE TOKEN\n");*/ /*getchar();*/ goto C1_012_BACKSLASH_N_EX; /**/ C1_013_EOF: /*002*/ close_file(infile); /*022*/ close_file(outfile); goto C1_013_EOF_EX; /**/ C2_001_DATA: goto C2_002_DATA; C2_002_DATA_EX: C2_001_DATA_A: switch(g2_001_DATA_A){ case 0 : goto C2_001_EXIT01;break; } /**/ C2_002_DATA: if(( /*C06*/ (currch=='"' || currch=='\'') )) goto C2_003_NON_NUMERI_C_LITERAL; if(( /*C07*/ (currch=='(') )) goto C2_008_OPEN_BRACE; if(( /*C08*/ (currch==')') )) goto C2_010_CLOSE_BRACE; if(( /*C15*/ (currch=='.') )) goto C2_012_FULLSTOP; if(( /*C09*/ (currch!='"' && currch!='\'' && currch!='(' && currch!=')' && currch!='.' && currch!='\n') )) goto C2_014_WORD; C2_003_NON_NUMERI_C_LITERAL_EX: C2_008_OPEN_BRACE_EX: C2_010_CLOSE_BRACE_EX: C2_012_FULLSTOP_EX: C2_014_WORD_EX: goto C2_002_DATA_EX; /**/ C2_003_NON_NUMERI_C_LITERAL: if(( /*C04*/ (currch=='"') )) goto C2_004_DOUBLE_QUOTE; if(( /*C05*/ (currch=='\'') )) goto C2_006_SINGLE_QUOTE; C2_004_DOUBLE_QUOTE_EX: C2_006_SINGLE_QUOTE_EX: goto C2_003_NON_NUMERI_C_LITERAL_EX; /**/ C2_004_DOUBLE_QUOTE: goto C2_005_DOUBLE_SUBTREE; C2_005_DOUBLE_SUBTREE_EX: goto C2_004_DOUBLE_QUOTE_EX; /**/ C2_005_DOUBLE_SUBTREE: g3_001_DOUBLE_SUBTREE_A=0; goto C3_001_DOUBLE_SUBTREE; C3_001_EXIT01: goto C2_005_DOUBLE_SUBTREE_EX; /**/ C2_006_SINGLE_QUOTE: goto C2_007_SINGLE_SUBTREE; C2_007_SINGLE_SUBTREE_EX: goto C2_006_SINGLE_QUOTE_EX; /**/ C2_007_SINGLE_SUBTREE: g4_001_SINGLE_SUBTREE_A=0; goto C4_001_SINGLE_SUBTREE; C4_001_EXIT01: goto C2_007_SINGLE_SUBTREE_EX; /**/ C2_008_OPEN_BRACE: goto C2_009_BRACE; C2_009_BRACE_EX: goto C2_008_OPEN_BRACE_EX; /**/ C2_009_BRACE: /*008*/ /*printf("open brace\n");*/ /*024*/ token->token_type=OPEN_BRACE; token->value.keyword_number=OPEN_BRACE; /*023*/ write_token(outfile,token); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C2_009_BRACE_EX; /**/ C2_010_CLOSE_BRACE: goto C2_011_PARENTHESI; C2_011_PARENTHESI_EX: goto C2_010_CLOSE_BRACE_EX; /**/ C2_011_PARENTHESI: /*009*/ /*printf("close brace\n");*/ /*025*/ token->token_type=CLOSE_BRACE; token->value.keyword_number=CLOSE_BRACE; /*023*/ write_token(outfile,token); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C2_011_PARENTHESI_EX; /**/ C2_012_FULLSTOP: goto C2_013_PERIOD; C2_013_PERIOD_EX: goto C2_012_FULLSTOP_EX; /**/ C2_013_PERIOD: /*014*/ /*printf("fullstop\n");*/ /*026*/ token->token_type=FULLSTOP; token->value.keyword_number=FULLSTOP; /*023*/ write_token(outfile,token); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C2_013_PERIOD_EX; /**/ C2_014_WORD: goto C2_015_KEYWORD_OR_WORD; C2_015_KEYWORD_OR_WORD_EX: goto C2_014_WORD_EX; /**/ C2_015_KEYWORD_OR_WORD: g5_001_KEYWORD_OR_WORD_A=0; goto C5_001_KEYWORD_OR_WORD; C5_001_EXIT01: goto C2_015_KEYWORD_OR_WORD_EX; /**/ C3_001_DOUBLE_SUBTREE: goto C3_002_START_QUOTE; C3_002_START_QUOTE_EX: goto C3_003_THE_IN_BETWEEN; C3_003_THE_IN_BETWEEN_EX: goto C3_007_END_QUOTE; C3_007_END_QUOTE_EX: C3_001_DOUBLE_SUBTREE_A: switch(g3_001_DOUBLE_SUBTREE_A){ case 0 : goto C3_001_EXIT01;break; } /**/ C3_002_START_QUOTE: /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); /*011*/ length_of=0; /*005*/ ch=chp; /*006*/ *ch='\0'; goto C3_002_START_QUOTE_EX; /**/ C3_003_THE_IN_BETWEEN: C3_004_CHAR_SEQUENCE_EX: if(!( /*C11*/ (currch=='"' && nextch!='"') )) goto C3_004_CHAR_SEQUENCE; goto C3_003_THE_IN_BETWEEN_EX; /**/ C3_004_CHAR_SEQUENCE: if(( /*C13*/ (currch=='"' && nextch=='"') )) goto C3_005_QUOTE_QUOTE; if(!( /*C13*/ (currch=='"' && nextch=='"') )) goto C3_006_ANY_OTHER; C3_005_QUOTE_QUOTE_EX: C3_006_ANY_OTHER_EX: goto C3_004_CHAR_SEQUENCE_EX; /**/ C3_005_QUOTE_QUOTE: /*012*/ length_of++; /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C3_005_QUOTE_QUOTE_EX; /**/ C3_006_ANY_OTHER: /*012*/ length_of++; /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C3_006_ANY_OTHER_EX; /**/ C3_007_END_QUOTE: /*013*/ token->token_type=NON_NUMERIC_LITERAL_LENGTH; token->value.keyword_number=length_of; /*023*/ write_token(outfile,token); /*007*/ /*printf("string token for %s\n",chp);*/ /*029*/ token->token_type=NON_NUMERIC_LITERAL; token->value.string=chp; /*023*/ write_token(outfile,token); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C3_007_END_QUOTE_EX; /**/ C4_001_SINGLE_SUBTREE: goto C4_002_START_QUOTE; C4_002_START_QUOTE_EX: goto C4_003_THE_IN_BETWEEN; C4_003_THE_IN_BETWEEN_EX: goto C4_007_END_QUOTE; C4_007_END_QUOTE_EX: C4_001_SINGLE_SUBTREE_A: switch(g4_001_SINGLE_SUBTREE_A){ case 0 : goto C4_001_EXIT01;break; } /**/ C4_002_START_QUOTE: /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); /*011*/ length_of=0; /*005*/ ch=chp; /*006*/ *ch='\0'; goto C4_002_START_QUOTE_EX; /**/ C4_003_THE_IN_BETWEEN: C4_004_CHAR_SEQUENCE_EX: if(!( /*C12*/ (currch=='\'' && nextch!='\'') )) goto C4_004_CHAR_SEQUENCE; goto C4_003_THE_IN_BETWEEN_EX; /**/ C4_004_CHAR_SEQUENCE: if(( /*C14*/ (currch=='\'' && nextch=='\'') )) goto C4_005_SIN_QUOTE_SIN_QUOTE; if(!( /*C14*/ (currch=='\'' && nextch=='\'') )) goto C4_006_ANY_OTHER; C4_005_SIN_QUOTE_SIN_QUOTE_EX: C4_006_ANY_OTHER_EX: goto C4_004_CHAR_SEQUENCE_EX; /**/ C4_005_SIN_QUOTE_SIN_QUOTE: /*012*/ length_of++; /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C4_005_SIN_QUOTE_SIN_QUOTE_EX; /**/ C4_006_ANY_OTHER: /*012*/ length_of++; /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C4_006_ANY_OTHER_EX; /**/ C4_007_END_QUOTE: /*013*/ token->token_type=NON_NUMERIC_LITERAL_LENGTH; token->value.keyword_number=length_of; /*023*/ write_token(outfile,token); /*007*/ /*printf("string token for %s\n",chp);*/ /*029*/ token->token_type=NON_NUMERIC_LITERAL; token->value.string=chp; /*023*/ write_token(outfile,token); /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C4_007_END_QUOTE_EX; /**/ C5_001_KEYWORD_OR_WORD: goto C5_002_KEYWORD_WORD_BCKTR; C5_002_KEYWORD_WORD_BCKTR_EX: C5_001_KEYWORD_OR_WORD_A: switch(g5_001_KEYWORD_OR_WORD_A){ case 0 : goto C5_001_EXIT01;break; } /**/ C5_002_KEYWORD_WORD_BCKTR: goto C5_003_KEYWORD; C5_003_KEYWORD_EX: C5_008_NON_KEYWORD_EX: goto C5_002_KEYWORD_WORD_BCKTR_EX; /**/ C5_003_KEYWORD: goto C5_004_KEYWORD_START; C5_004_KEYWORD_START_EX: goto C5_005_KEYWORD_CHARS; C5_005_KEYWORD_CHARS_EX: goto C5_007_KEYWORD_END; C5_007_KEYWORD_END_EX: goto C5_003_KEYWORD_EX; /**/ C5_004_KEYWORD_START: /*005*/ ch=chp; /*011*/ length_of=0; /*017*/ listpointer=root; /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*018*/ listpointer=check_pointer(listpointer,currch); /*012*/ length_of++; if(( /*Q01*/ (!isupper(currch)) && currch!='-' )) goto C5_008_NON_KEYWORD; if(( /*Q02*/ listpointer==NULL )) goto C5_008_NON_KEYWORD; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C5_004_KEYWORD_START_EX; /**/ C5_005_KEYWORD_CHARS: C5_006_KEYWORD_CHAR_EX: if(!( /*C10*/ (currch==' ' || currch=='\n' || currch=='(' || currch==')' || currch=='.') )) goto C5_006_KEYWORD_CHAR; goto C5_005_KEYWORD_CHARS_EX; /**/ C5_006_KEYWORD_CHAR: /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*012*/ length_of++; /*018*/ listpointer=check_pointer(listpointer,currch); if(( /*Q01*/ (!isupper(currch)) && currch!='-' )) goto C5_008_NON_KEYWORD; if(( /*Q02*/ listpointer==NULL )) goto C5_008_NON_KEYWORD; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C5_006_KEYWORD_CHAR_EX; /**/ C5_007_KEYWORD_END: /*019*/ dat=get_data(listpointer); if(( /*Q03*/ dat==NULL )) goto C5_008_NON_KEYWORD; /*020*/ /*printf("keyword - %s number %d",chp,dat);*/ /*027*/ token->token_type=KEYWORD; token->value.keyword_number=dat; /*023*/ write_token(outfile,token); goto C5_007_KEYWORD_END_EX; /**/ C5_008_NON_KEYWORD: goto C5_009_START_NON; C5_009_START_NON_EX: goto C5_010_CHARS; C5_010_CHARS_EX: goto C5_012_END_WORD; C5_012_END_WORD_EX: goto C5_008_NON_KEYWORD_EX; /**/ C5_009_START_NON: /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C5_009_START_NON_EX; /**/ C5_010_CHARS: C5_011_CHAR_EX: if(!( /*C10*/ (currch==' ' || currch=='\n' || currch=='(' || currch==')' || currch=='.') )) goto C5_011_CHAR; goto C5_010_CHARS_EX; /**/ C5_011_CHAR: /*030*/ *ch=currch; /*031*/ ch++; /*006*/ *ch='\0'; /*012*/ length_of++; /*004*/ currch=nextch; if(nextch!=EOF) nextch=getc(infile); goto C5_011_CHAR_EX; /**/ C5_012_END_WORD: /*010*/ /*printf("word token for %s\n",chp);*/ /*032*/ token->token_type=NON_KEYWORD_LENGTH; token->value.keyword_number=length_of; /*023*/ write_token(outfile,token); /*028*/ token->token_type=NON_KEYWORD; token->value.string=chp; /*023*/ write_token(outfile,token); /*013*/ token->token_type=NON_NUMERIC_LITERAL_LENGTH; token->value.keyword_number=length_of; goto C5_012_END_WORD_EX; /**/ /* Data Analysis Map*/ /**/ /* ------------- Data Analysis By -------------*/ /**/ /* BOX TYPE OPERATION ALLOCATION*/ /* Tree name: SCAN*/ /**/ /* Leaf : 6 Operations: 11*/ /* Quits : 0*/ /* Selections: 0*/ /* Sequences : 3*/ /* Iterations: 3*/ /* Backtracks: 0*/ /* Subtrees : 1 --> DATA*/ /**/ /* Tree name: DATA*/ /**/ /* Leaf : 3 Operations: 12*/ /* Quits : 0*/ /* Selections: 2*/ /* Sequences : 7*/ /* Iterations: 0*/ /* Backtracks: 0*/ /* Subtrees : 3 --> DOUBLE-SUBTREE*/ /* SINGLE-SUBTREE*/ /* KEYWORD_OR-WORD*/ /**/ /* Tree name: DOUBLE-SUBTREE*/ /**/ /* Leaf : 4 Operations: 21*/ /* Quits : 0*/ /* Selections: 1*/ /* Sequences : 1*/ /* Iterations: 1*/ /* Backtracks: 0*/ /* Subtrees : 0*/ /**/ /* Tree name: SINGLE-SUBTREE*/ /**/ /* Leaf : 4 Operations: 21*/ /* Quits : 0*/ /* Selections: 1*/ /* Sequences : 1*/ /* Iterations: 1*/ /* Backtracks: 0*/ /* Subtrees : 0*/ /**/ /* Tree name: KEYWORD_OR-WORD*/ /**/ /* Leaf : 6 Operations: 31*/ /* Quits : 5*/ /* Selections: 0*/ /* Sequences : 3*/ /* Iterations: 2*/ /* Backtracks: 1*/ /* Subtrees : 0*/ /**/ /**/ /**/ veryend: ; }
unsigned int InferenceStatistics::get_number_of_assignments(Subset subset) const { return get_data(subset).size; }
void BinAsm::save(const std::string& filename) { uint32_t allocsize=0x10000; uint32_t filesize=0; int error_count=0; uint16_t* buff = new uint16_t[allocsize]; unsigned int lc = 0; uint16_t opcode = 0; std::vector<std::string> lines=split_text(_src); std::vector<std::string>::iterator lit = lines.begin(); for (;lit!=lines.end();lit++) { lc++; std::string err = std::string(); std::vector<std::string> w=split_line(*lit); if (!w.size()) continue; opcode = 0; if (filesize > allocsize - lit->size() - 3) { std::cerr << "fatal error: assembling file is too big"; std::cerr << "cannot be used on dcpu-16" << std::endl; break; } if (w[0].size() && (w[0][w[0].size()-1] == ':' || w[0][0] == ':')) { continue; } if ((opcode = get_op(w[0]))) { if (w.size() != 3) { err = "instruction " + w[0]; err += " need 2 arguments"; } else { uint16_t a_word=0, b_word=0; opcode |= ((get_b(w[1],b_word,err) & 0x1F) << 5); if (err.size()) { print_error(lc,false,err); error_count++; } opcode |= (get_a(w[2],a_word,err) << 10); buff[filesize]=opcode; filesize++; if (a_word) { buff[filesize]=a_word; filesize++; } if (b_word) { buff[filesize]=b_word; filesize++; } } } else if ((opcode=get_sop(w[0],err)) && !err.size()) { if (w.size() != 2) { err = "special instruction " + w[0]; err += " need 1 argument"; } else { uint16_t a_word=0; opcode = ((opcode & 0x1F) << 5); opcode |= (get_a(w[1],a_word,err) << 10); buff[filesize]=opcode; filesize++; if (a_word) { buff[filesize]=a_word; filesize++; } } } else { if (w[0]=="dat"||w[0]==".dat"||w[0]=="DAT"||w[0]==".DAT") err=""; filesize += get_data(*lit, &(buff[filesize]),err); } if (err.size()) { print_error(lc,false,err); error_count++; } } if (error_count) { std::cerr << "assembling terminated with " << error_count; std::cerr << " error(s)" << std::endl; } else { FILE* f = fopen(filename.c_str(), "wb"); if (!f) std::cerr << "error: cannot open output file " << filename << std::endl; fswitchendian(buff, filesize); fwrite(buff,2,filesize,f); fclose(f); std::cout << "assembling " << filename; std::cout << " terminated final size " << filesize*2; std::cout << " bytes" << std::endl; } delete buff; }
Assignments InferenceStatistics::get_sample_assignments(Subset subset) const { return get_data(subset).sample; }
int main() { /** * I've included some basic code for opening a UDP socket in C, * binding to a empheral port, printing out the port number. * * I've also included a very simple transport protocol that simply * acknowledges every received packet. It has a header, but does * not do any error handling (i.e., it does not have sequence * numbers, timeouts, retries, a "window"). You will * need to fill in many of the details, but this should be enough to * get you started. */ // first, open a UDP socket int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // next, construct the local port struct sockaddr_in out; out.sin_family = AF_INET; out.sin_port = htons(0); out.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(sock, (struct sockaddr *) &out, sizeof(out))) { perror("bind"); exit(1); } struct sockaddr_in tmp; int len = sizeof(tmp); if (getsockname(sock, (struct sockaddr *) &tmp, (socklen_t *) &len)) { perror("getsockname"); exit(1); } mylog("[bound] %d\n", ntohs(tmp.sin_port)); // wait for incoming packets struct sockaddr_in in; socklen_t in_len = sizeof(in); // construct the socket set fd_set socks; // construct the timeout struct timeval t; t.tv_sec = 30; t.tv_usec = 0; // our receive buffer int buf_len = 1500; void* buf = malloc(buf_len); int eof_hit = 0; unsigned int eof_seq = 0; // wait to receive, or for a timeout while (1) { FD_ZERO(&socks); FD_SET(sock, &socks); if (select(sock + 1, &socks, NULL, NULL, &t)) { int received; if ((received = recvfrom(sock, buf, buf_len, 0, (struct sockaddr *) &in, (socklen_t *) &in_len)) < 0) { perror("recvfrom"); free(buf); exit(1); } //dump_packet(buf, received); header *myheader = get_header(buf); char *data = get_data(buf); unsigned int myh_seq = myheader->sequence; if (myheader->magic == MAGIC) { if (myheader->eof) { mylog("[recv eof]\n"); eof_hit = 1; eof_seq = myh_seq; } else { write_out(myh_seq, data, myheader->length); } if (eof_hit && sequence == eof_seq) { mylog("[send eof ack]\n"); header *responseheader = make_header(sequence, 0, 1, 1); free(buf); if (sendto(sock, responseheader, sizeof(header), 0, (struct sockaddr *) &in, (socklen_t) sizeof(in)) < 0) { perror("sendto"); exit(1); } mylog("[completed]\n"); exit(0); } else { mylog("[send ack] %d\n", sequence); header *responseheader = make_header(sequence, 0, 0, 1); if (sendto(sock, responseheader, sizeof(header), 0, (struct sockaddr *) &in, (socklen_t) sizeof(in)) < 0) { perror("sendto"); free(buf); exit(1); } } } else { mylog("[recv corrupted packet]\n"); } } else { mylog("[error] timeout occurred\n"); free(buf); exit(1); } } free(buf); return 0; }
void get_control_settings_from_bus() { controlSettings[currentSetting] = get_data(); currentSetting = 0; }