static void emit_decl_sampler_view(struct ureg_program *ureg, unsigned index, unsigned target, unsigned return_type_x, unsigned return_type_y, unsigned return_type_z, unsigned return_type_w ) { union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 3; out[0].decl.File = TGSI_FILE_SAMPLER_VIEW; out[0].decl.UsageMask = 0xf; out[1].value = 0; out[1].decl_range.First = index; out[1].decl_range.Last = index; out[2].value = 0; out[2].decl_sampler_view.Resource = target; out[2].decl_sampler_view.ReturnTypeX = return_type_x; out[2].decl_sampler_view.ReturnTypeY = return_type_y; out[2].decl_sampler_view.ReturnTypeZ = return_type_z; out[2].decl_sampler_view.ReturnTypeW = return_type_w; }
void xlsx_workbook_context::start_element(xmlns_id_t ns, xml_token_t name, const xml_attrs_t& attrs) { xml_token_pair_t parent = push_stack(ns, name); switch (name) { case XML_workbook: { xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN); print_attrs(get_tokens(), attrs); } break; case XML_sheets: xml_element_expected(parent, NS_ooxml_xlsx, XML_workbook); break; case XML_sheet: { xml_element_expected(parent, NS_ooxml_xlsx, XML_sheets); workbook_sheet_attr_parser func(&get_session_context()); func = for_each(attrs.begin(), attrs.end(), func); m_sheets.push_back(new xlsx_rel_sheet_info(func.get_sheet())); const xlsx_rel_sheet_info& info = m_sheets.back(); m_sheet_info.insert( opc_rel_extras_t::value_type(func.get_rid(), &info)); } break; default: warn_unhandled(); } }
static void emit_decl_semantic(struct ureg_program *ureg, unsigned file, unsigned index, unsigned semantic_name, unsigned semantic_index, unsigned usage_mask) { union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 3; out[0].decl.File = file; out[0].decl.UsageMask = usage_mask; out[0].decl.Semantic = 1; out[1].value = 0; out[1].decl_range.First = index; out[1].decl_range.Last = index; out[2].value = 0; out[2].decl_semantic.Name = semantic_name; out[2].decl_semantic.Index = semantic_index; }
void opc_relations_context::start_element(xmlns_id_t ns, xml_token_t name, const vector<xml_token_attr_t> &attrs) { xml_token_pair_t parent = push_stack(ns, name); switch (name) { case XML_Relationships: { xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN); print_attrs(get_tokens(), attrs); } break; case XML_Relationship: { rel_attr_parser func(&get_session_context(), &m_schema_cache); xml_element_expected(parent, NS_opc_rel, XML_Relationships); func = for_each(attrs.begin(), attrs.end(), func); const opc_rel_t& rel = func.get_rel(); if (rel.type) m_rels.push_back(rel); } break; default: warn_unhandled(); } }
static void emit_decl_fs(struct ureg_program *ureg, unsigned file, unsigned index, unsigned semantic_name, unsigned semantic_index, unsigned interpolate, unsigned cylindrical_wrap, unsigned centroid) { union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 4); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 4; out[0].decl.File = file; out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */ out[0].decl.Interpolate = 1; out[0].decl.Semantic = 1; out[1].value = 0; out[1].decl_range.First = index; out[1].decl_range.Last = index; out[2].value = 0; out[2].decl_interp.Interpolate = interpolate; out[2].decl_interp.CylindricalWrap = cylindrical_wrap; out[2].decl_interp.Centroid = centroid; out[3].value = 0; out[3].decl_semantic.Name = semantic_name; out[3].decl_semantic.Index = semantic_index; }
static void emit_decl_temps( struct ureg_program *ureg, unsigned first, unsigned last, boolean local, unsigned arrayid ) { union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, arrayid ? 3 : 2 ); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 2; out[0].decl.File = TGSI_FILE_TEMPORARY; out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[0].decl.Local = local; out[1].value = 0; out[1].decl_range.First = first; out[1].decl_range.Last = last; if (arrayid) { out[0].decl.Array = 1; out[2].value = 0; out[2].array.ArrayID = arrayid; } }
void ureg_emit_src( struct ureg_program *ureg, struct ureg_src src ) { unsigned size = 1 + (src.Indirect ? 1 : 0) + (src.Dimension ? (src.DimIndirect ? 2 : 1) : 0); union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size ); unsigned n = 0; assert(src.File != TGSI_FILE_NULL); assert(src.File < TGSI_FILE_COUNT); out[n].value = 0; out[n].src.File = src.File; out[n].src.SwizzleX = src.SwizzleX; out[n].src.SwizzleY = src.SwizzleY; out[n].src.SwizzleZ = src.SwizzleZ; out[n].src.SwizzleW = src.SwizzleW; out[n].src.Index = src.Index; out[n].src.Negate = src.Negate; out[0].src.Absolute = src.Absolute; n++; if (src.Indirect) { out[0].src.Indirect = 1; out[n].value = 0; out[n].ind.File = src.IndirectFile; out[n].ind.Swizzle = src.IndirectSwizzle; out[n].ind.Index = src.IndirectIndex; out[n].ind.ArrayID = src.ArrayID; n++; } if (src.Dimension) { out[0].src.Dimension = 1; out[n].dim.Dimension = 0; out[n].dim.Padding = 0; if (src.DimIndirect) { out[n].dim.Indirect = 1; out[n].dim.Index = src.DimensionIndex; n++; out[n].value = 0; out[n].ind.File = src.DimIndFile; out[n].ind.Swizzle = src.DimIndSwizzle; out[n].ind.Index = src.DimIndIndex; out[n].ind.ArrayID = src.ArrayID; } else { out[n].dim.Indirect = 0; out[n].dim.Index = src.DimensionIndex; } n++; } assert(n == size); }
xml_context_base* gnumeric_content_xml_context::create_child_context(xmlns_id_t ns, xml_token_t name) { if (ns == NS_gnumeric_gnm && name == XML_Sheet) { mp_child.reset(new gnumeric_sheet_context(get_session_context(), get_tokens(), mp_factory)); return mp_child.get(); } return NULL; }
/* Append the instruction tokens onto the declarations to build a * contiguous stream suitable to send to the driver. */ static void copy_instructions( struct ureg_program *ureg ) { unsigned nr_tokens = ureg->domain[DOMAIN_INSN].count; union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, nr_tokens ); memcpy(out, ureg->domain[DOMAIN_INSN].tokens, nr_tokens * sizeof out[0] ); }
static void emit_header( struct ureg_program *ureg ) { union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 ); out[0].header.HeaderSize = 2; out[0].header.BodySize = 0; out[1].processor.Processor = ureg->processor; out[1].processor.Padding = 0; }
void ureg_emit_texture_offset(struct ureg_program *ureg, const struct tgsi_texture_offset *offset) { union tgsi_any_token *out; out = get_tokens( ureg, DOMAIN_INSN, 1); out[0].value = 0; out[0].insn_texture_offset = *offset; }
int main() { char start, stop; int dir; while(get_tokens(&dir, &start, &stop) == 1) { print_tokens(&dir, &start, &stop); putchar('\n'); } return 0; }
static int console_command(console_state cs) { int i,o; int ntokens; char req[MAX_REQ]; char tokens[MAX_TOK][MAX_TOKLEN]; struct console_cmd_params_t p; memset(&p,0,sizeof(struct console_cmd_params_t)); p.cs = cs; switch (console_read(cs,req,sizeof(req))) { case -1: console_write(cs," cannot read command\n"); return CON_QUIT; case 0: return CON_CMD_NONE; default: // DBG_PRINT("wsim:con:main: read -%s-\n",req); break; } if ((ntokens = get_tokens(req,tokens,console_ui_delim)) == 0) { return console_cmd_help(&p); } for(i=0; i < cs->cmd_max ; i++) { if (strcasecmp(cs->commands[i].name,tokens[0]) == 0) { if (cs->commands[i].nb_option > (ntokens - 1)) { console_write(cs," incorrect number of arguments for %s\n",tokens[0]); return CON_CMD_ERROR; } for(o=0; o < ntokens; o++) { p.options[o] = tokens[o+1]; } p.nopt = ntokens - 1; return cs->commands[i].fun(&p); } } console_write(cs," unknown command %s\n\n",tokens[0]); return CON_CMD_ERROR; }
static void emit_property(struct ureg_program *ureg, unsigned name, unsigned data) { union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2); out[0].value = 0; out[0].prop.Type = TGSI_TOKEN_TYPE_PROPERTY; out[0].prop.NrTokens = 2; out[0].prop.PropertyName = name; out[1].prop_data.Data = data; }
int p2p_addr_setstr(p2p_addr dst, const char* p2p_str) { char tokens[MAX_TOK][MAX_TOKLEN]; //MAX_TOK=3 et MAX_TOKEN=30 definies dans p2p_common.h if (get_tokens(p2p_str,tokens,test_delim) == 3) //get_tokens definie dans p2p_common.c, //pour decouper 127.0.0.1:10002:10003 -> ip, p_tcp, p_udp { return p2p_addr_set(dst,tokens[0],atoi(tokens[1]),atoi(tokens[2])); } else { return P2P_ERROR; } }
void ureg_emit_texture(struct ureg_program *ureg, unsigned extended_token, unsigned target ) { union tgsi_any_token *out, *insn; out = get_tokens( ureg, DOMAIN_INSN, 1 ); insn = retrieve_token( ureg, DOMAIN_INSN, extended_token ); insn->insn.Texture = 1; out[0].value = 0; out[0].insn_texture.Texture = target; }
void dry_run_script() { // save some stuff char *old_rover = rover; section_t *old_current_section = current_section; char *end = current_script->data + current_script->len; char *token_alloc; killscript = false; // allocate space for the tokens token_alloc = Z_Malloc(current_script->len + T_MAXTOKENS, PU_STATIC, 0); rover = current_script->data; while(rover < end && *rover) { tokens[0] = token_alloc; get_tokens(rover); if(killscript) break; if(!num_tokens) continue; if(current_section && tokentype[0] == function) { if(!strcmp(tokens[0], "if")) { current_section->type = st_if; continue; } else if(!strcmp(tokens[0], "while") || !strcmp(tokens[0], "for")) { current_section->type = st_loop; current_section->data.data_loop.loopstart = linestart; continue; } } } Z_Free(token_alloc); // restore stuff current_section = old_current_section; rover = old_rover; }
static void emit_immediate( struct ureg_program *ureg, const unsigned *v, unsigned type ) { union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 5 ); out[0].value = 0; out[0].imm.Type = TGSI_TOKEN_TYPE_IMMEDIATE; out[0].imm.NrTokens = 5; out[0].imm.DataType = type; out[0].imm.Padding = 0; out[1].imm_data.Uint = v[0]; out[2].imm_data.Uint = v[1]; out[3].imm_data.Uint = v[2]; out[4].imm_data.Uint = v[3]; }
static void emit_decl_range( struct ureg_program *ureg, unsigned file, unsigned first, unsigned count ) { union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 ); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 2; out[0].decl.File = file; out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[0].decl.Semantic = 0; out[1].value = 0; out[1].decl_range.First = first; out[1].decl_range.Last = first + count - 1; }
void ureg_emit_label(struct ureg_program *ureg, unsigned extended_token, unsigned *label_token ) { union tgsi_any_token *out, *insn; if(!label_token) return; out = get_tokens( ureg, DOMAIN_INSN, 1 ); out[0].value = 0; insn = retrieve_token( ureg, DOMAIN_INSN, extended_token ); insn->insn.Label = 1; *label_token = ureg->domain[DOMAIN_INSN].count - 1; }
void parse_data(char *data, char *end) { char *token_alloc; // allocated memory for tokens killscript = false; // dont kill the script straight away // allocate space for the tokens token_alloc = new char[current_script->len + T_MAXTOKENS]; prev_section = NULL; // clear it while(*rover) // go through the script executing each statement { // past end of script? if(rover > end) break; // reset the tokens before getting the next line tokens[0] = token_alloc; prev_section = current_section; // store from prev. statement // get the line and tokens get_tokens(rover); if(killscript) break; if(!num_tokens) { if(current_section) // no tokens but a brace { // possible } at end of loop: // refer to spec.c spec_brace(); } continue; // continue to next statement } if(script_debug) print_tokens(); // debug run_statement(); // run the statement } delete token_alloc; }
/** * Load an image in the file of the proprietary format. * The file name describes the image configuration as: * *-(width)x(height)x(num_channels)-(opencv_depth_code).bin * There is no header in the file. The file is a binary dump of an OpenCV cv::Mat data. * For the better portability, an existing format can be used to carry image data. */ cv::Mat cv_subtractor::read_binary_image_file(const std::string filename) { std::vector<int> tokens; { // Extract the information on the image from the file name const std::vector<char> delims = {'-', 'x','x','-','.'}; std::string dir; std::string basename; parse_path(filename, dir, basename); tokens = get_tokens(basename, delims); if (tokens.size() != delims.size()) { return cv::Mat(); } } std::ifstream file(filename, std::ios::binary); if (!file.good()) { return cv::Mat(); } file.unsetf(std::ios::skipws); { // Check file size const size_t image_byte_size = tokens[1] * tokens[2] * tokens[3] * CV_ELEM_SIZE(tokens[4]); file.seekg(0, std::ios::end); const size_t file_size = static_cast<size_t>(file.tellg()); if (image_byte_size != file_size) { return cv::Mat(); } } // Construct an image data structure cv::Mat image(tokens[1], tokens[2], CV_MAKETYPE(tokens[4], tokens[3])); // Reset the file pointer file.seekg(0, std::ios::beg); // Load the image from the file std::copy(std::istream_iterator<unsigned char>(file), std::istream_iterator<unsigned char>(), reinterpret_cast<unsigned char*>(image.data)); return image; }
void opc_content_types_context::start_element(xmlns_id_t ns, xml_token_t name, const::std::vector<xml_token_attr_t> &attrs) { xml_token_pair_t parent = push_stack(ns, name); switch (name) { case XML_Types: { xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN); print_attrs(get_tokens(), attrs); } break; case XML_Override: { xml_element_expected(parent, NS_opc_ct, XML_Types); part_ext_attr_parser func(&m_ct_cache, XML_PartName); func = for_each(attrs.begin(), attrs.end(), func); // We need to use allocated strings for part names here because // the part names need to survive after the [Content_Types].xml // stream is destroyed. pstring part_name = get_session_context().m_string_pool.intern(func.get_name()).first; m_parts.push_back( xml_part_t(part_name, func.get_content_type())); } break; case XML_Default: { xml_element_expected(parent, NS_opc_ct, XML_Types); part_ext_attr_parser func(&m_ct_cache, XML_Extension); func = for_each(attrs.begin(), attrs.end(), func); // Like the part names, we need to use allocated strings for // extension names. pstring ext_name = get_session_context().m_string_pool.intern(func.get_name()).first; m_ext_defaults.push_back( xml_part_t(ext_name, func.get_content_type())); } break; default: warn_unhandled(); } }
struct ureg_emit_insn_result ureg_emit_insn(struct ureg_program *ureg, unsigned opcode, boolean saturate, boolean predicate, boolean pred_negate, unsigned pred_swizzle_x, unsigned pred_swizzle_y, unsigned pred_swizzle_z, unsigned pred_swizzle_w, unsigned num_dst, unsigned num_src ) { union tgsi_any_token *out; uint count = predicate ? 2 : 1; struct ureg_emit_insn_result result; validate( opcode, num_dst, num_src ); out = get_tokens( ureg, DOMAIN_INSN, count ); out[0].insn = tgsi_default_instruction(); out[0].insn.Opcode = opcode; out[0].insn.Saturate = saturate; out[0].insn.NumDstRegs = num_dst; out[0].insn.NumSrcRegs = num_src; result.insn_token = ureg->domain[DOMAIN_INSN].count - count; result.extended_token = result.insn_token; if (predicate) { out[0].insn.Predicate = 1; out[1].insn_predicate = tgsi_default_instruction_predicate(); out[1].insn_predicate.Negate = pred_negate; out[1].insn_predicate.SwizzleX = pred_swizzle_x; out[1].insn_predicate.SwizzleY = pred_swizzle_y; out[1].insn_predicate.SwizzleZ = pred_swizzle_z; out[1].insn_predicate.SwizzleW = pred_swizzle_w; } ureg->nr_instructions++; return result; }
int main() { // Ввод текста из стандартного потока ввода // (при вводе текста из консоли в конце нужно нажать Ctrl-D). string text = string(istreambuf_iterator<char>(cin), istreambuf_iterator<char>()); // Итератор для вывода слов через пробел. ostream_iterator<string> owords(cout, " "); // Разбиение текста на слова. vector<string> tokens; TIMED(get_tokens(text, delimiters, tokens)); copy(tokens.begin(), tokens.end(), owords); cout << endl; // Составление частотного словаря. map<string, int> freqdi; TIMED(get_type_freq(tokens, freqdi);) for (auto p : freqdi) {
static pdfout_data * parser_parse (fz_context *ctx, pdfout_parser *parse) { parser *p = (parser *) parse; if (p->finished) pdfout_throw (ctx, "call to finished outline wysiwyg parser"); p->finished = true; pdfout_data *lines = get_lines (ctx, p); if (pdfout_data_array_len (ctx, lines) == 0) return lines; pdfout_data *tokens = get_tokens (ctx, lines); pdfout_data *outline = token_parse(ctx, tokens); pdfout_data_drop (ctx, tokens); pdfout_data_drop (ctx, lines); return outline; }
/* RPN calculator */ int main() { char buffer[CBMAX]; int tkclass; while (get_tokens(buffer, CBMAX, &tkclass)) { if (tkclass == TK_WORD || tkclass == TK_SYMBOL) { execop(buffer); } else if (tkclass == TK_NUM) { double num; char *end; errno = 0; num = strtod(buffer, &end); if (errno == ERANGE) { printf("num2big?\n"); } mypush(num); } else { puts("What is \"%s\" suppsed to mean?\n"); } } return EXIT_SUCCESS; }
static void emit_decl_range2D(struct ureg_program *ureg, unsigned file, unsigned first, unsigned last, unsigned index2D) { union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); out[0].value = 0; out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 3; out[0].decl.File = file; out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[0].decl.Dimension = 1; out[1].value = 0; out[1].decl_range.First = first; out[1].decl_range.Last = last; out[2].value = 0; out[2].decl_dim.Index2D = index2D; }
void ureg_emit_dst( struct ureg_program *ureg, struct ureg_dst dst ) { unsigned size = (1 + (dst.Indirect ? 1 : 0)); union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size ); unsigned n = 0; assert(dst.File != TGSI_FILE_NULL); assert(dst.File != TGSI_FILE_CONSTANT); assert(dst.File != TGSI_FILE_INPUT); assert(dst.File != TGSI_FILE_SAMPLER); assert(dst.File != TGSI_FILE_IMMEDIATE); assert(dst.File < TGSI_FILE_COUNT); out[n].value = 0; out[n].dst.File = dst.File; out[n].dst.WriteMask = dst.WriteMask; out[n].dst.Indirect = dst.Indirect; out[n].dst.Index = dst.Index; n++; if (dst.Indirect) { out[n].value = 0; out[n].src.File = TGSI_FILE_ADDRESS; out[n].src.SwizzleX = dst.IndirectSwizzle; out[n].src.SwizzleY = dst.IndirectSwizzle; out[n].src.SwizzleZ = dst.IndirectSwizzle; out[n].src.SwizzleW = dst.IndirectSwizzle; out[n].src.Index = dst.IndirectIndex; n++; } assert(n == size); }
int main(int ac, char **av, char **env) { t_token *root; t_parse_tree *tree; t_shell *sh; (void)av; (void)ac; if (!(sh = init_sh(env))) return (FAILURE); parse_config_file(sh); while (!sh->exe->exit && get_line_caps(sh->line) != FAILURE) { pre_parsing(sh); if (!(root = get_tokens(sh->line->line))) return (FAILURE); if ((tree = start_parsing(root, sh)) && (sh->exe->return_value = 2)) exec_cmd(tree, sh->exe); free_tokens(root); XFREE(sh->line->line); } add_in_history_file(sh->line); return (clean_all(sh)); }