void parcours_instr_si(n_instr *n) { parcours_exp(n->u.si_.test); int iRegistre = 0; char tmp[250]; char registre[250]; char faux[256]; char suite[256]; new_tag(faux); new_tag(suite); sprintf(registre,"$t%d",iRegistre); depile(registre); sprintf(tmp,"beq %s $zero %s", registre,faux); printMips(tmp); parcours_instr(n->u.si_.alors); sprintf(tmp,"j %s",suite); printMips(tmp); sprintf(tmp,"%s:",faux); printMips(tmp); if(n->u.si_.sinon) { parcours_instr(n->u.si_.sinon); } sprintf(tmp,"%s:",suite); printMips(tmp); }
void parcours_instr_pour(n_instr *n) { parcours_instr(n->u.pour_.init); char tmp[250]; char etiquette[256]; char fin[256]; char registre[250]; new_tag(etiquette); new_tag(fin); sprintf(tmp,"%s:",etiquette); printMips(tmp); parcours_exp(n->u.pour_.test); int iRegistre = 0; sprintf(registre,"$t%d",iRegistre); depile(registre); sprintf(tmp,"beq %s $zero %s", registre, fin); printMips(tmp); parcours_instr(n->u.pour_.faire); parcours_instr(n->u.pour_.incr); sprintf(tmp,"j %s",etiquette); printMips(tmp); sprintf(tmp,"%s:",fin); printMips(tmp); }
// Parse a tag (starting from a current token of '+' or '-') and return it. // Return NULL on error. golem_tag *parse_tag(golem_tokenizer *tokenizer) { log("> parse tag [%d]\n", tokenizer->token); bool sign = tokenizer->token == '+'; int token = get_token(tokenizer); if (token != token_name) { die("parse tag: expected name"); } #ifdef DEBUG golem_tag *tag = new_tag(sign, get_token_string(tokenizer)); log("< parsed tag %c%s [%d]\n", tag->sign ? '+' : '-', tag->name, tokenizer->token); return tag; #else return new_tag(sign, get_token_string(tokenizer)); #endif }
ID3v2_tag* load_tag(const char* file_name) { // Declaration FILE* file; ID3v2_tag* tag; ID3v2_frame_list* frame_list; ID3v2_header* tag_header; // Initialization tag = new_tag(); tag_header = get_tag_header(file_name); if(tag_header == NULL || get_tag_version(tag_header) == NO_COMPATIBLE_TAG) { // No compatible ID3 tag in the file, or we got some problem opening the file free_tag(tag); return NULL; } // Associations tag->tag_header = tag_header; file = fopen(file_name, "rb"); if(file == NULL) { perror("Error opening file"); free_tag(tag); return NULL; } tag->raw = (char*) malloc(tag->tag_header->tag_size * sizeof(char)); fseek(file, 10, SEEK_SET); fread(tag->raw, tag->tag_header->tag_size, 1, file); fclose(file); int offset = 0; while(offset < tag->tag_header->tag_size) { ID3v2_frame* frame; frame = parse_frame(tag->raw, offset, get_tag_version(tag_header)); if(frame != NULL) { offset += frame->size + 10; add_to_list(tag->frames, frame); } else { break; } } return tag; }
static int mpoa_cache_imposition_request( uint8_t * buff ){ int pos = 0; struct k_message msg; struct nhrp_fixed_h * fixed = (struct nhrp_fixed_h *)buff; struct nhrp_common_h * common; struct nhrp_cie_short * cie_short; struct extension_values values; pos += sizeof( struct nhrp_fixed_h ); memset(&values, 0, sizeof(struct extension_values)); memset(&msg,0,sizeof(struct k_message)); common = (struct nhrp_common_h *)(buff + pos); memcpy(msg.content.eg_info.in_MPC_data_ATM_addr, common->src_nbma_address ,ATM_ESA_LEN); pos += sizeof(struct nhrp_common_h); cie_short = (struct nhrp_cie_short *)(buff + pos); msg.content.eg_info.holding_time = ntohs(cie_short->holding_time); msg.ip_mask = calculate_ip_mask(cie_short->prefix_length); if(ntohs(fixed->ar_extoff)){ pos += parse_extensions(buff + ntohs(fixed->ar_extoff), &values); } if(ntohs(cie_short->holding_time)) { if (values.dll_header_present == 0) { printf("mpcd: p_recogn.c: warning: "); printf("holding time non-zero but MPOA DLL Header Extension missing\n"); return 0; } keep_alive_sm_running = 1; } msg.content.eg_info.cache_id = values.dll_ext.cache_id; msg.content.eg_info.DH_length = values.dll_ext.dh_length; memcpy(msg.content.eg_info.DLL_header, values.dll_ext.dll_header, msg.content.eg_info.DH_length); if(common->src_proto_len) msg.content.eg_info.mps_ip = common->src_protocol_address; if(common->dst_proto_len) msg.content.eg_info.eg_dst_ip = common->dst_protocol_address; msg.content.eg_info.tag = new_tag(msg.content.eg_info.cache_id); memcpy(msg.MPS_ctrl, mpc_control.MPS_CTRL_ATM_ADDR, ATM_ESA_LEN); msg.type = CACHE_IMPOS_RCVD; send_to_kernel(&msg); return send_cache_imposition_reply( buff, msg.content.eg_info.tag, 0x00, 0, MTU_DEFAULT, common->src_nbma_address ); }
/*-------------------------------------------------------------------------*/ void parcours_opExp(n_exp *n) { char tmp[256]; int iRegistre = 0; int iRegistre2 = 1; int iRegistre3 = 2; if(n->u.opExp_.op == plus) { parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"add $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3); printMips(tmp); } else if(n->u.opExp_.op == moins){ parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"sub $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3); printMips(tmp); } else if(n->u.opExp_.op == fois) { parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"mult $t%d, $t%d", iRegistre2, iRegistre3); printMips(tmp); sprintf(tmp,"mflo $t%d",iRegistre); printMips(tmp); } else if(n->u.opExp_.op == divise) { parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"div $t%d, $t%d", iRegistre2, iRegistre3); printMips(tmp); sprintf(tmp,"mflo $t%d",iRegistre); printMips(tmp); } else if(n->u.opExp_.op == egal){ parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); char etiquette[256]; new_tag(etiquette); sprintf(tmp,"li $t%d, 1",iRegistre); printMips(tmp); sprintf(tmp,"beq $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette); printMips(tmp); sprintf(tmp,"li $t%d, 0",iRegistre); printMips(tmp); sprintf(tmp,"%s:", etiquette); printMips(tmp); } else if(n->u.opExp_.op == diff) { parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); char etiquette[256]; new_tag(etiquette); sprintf(tmp,"li $t%d, 0",iRegistre); printMips(tmp); sprintf(tmp,"beq $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette); printMips(tmp); sprintf(tmp,"li $t%d, 1",iRegistre); printMips(tmp); sprintf(tmp,"%s:", etiquette); printMips(tmp); }else if(n->u.opExp_.op == inf){ parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); char etiquette[256]; new_tag(etiquette); sprintf(tmp,"li $t%d, 1",iRegistre); printMips(tmp); sprintf(tmp,"blt $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette); printMips(tmp); sprintf(tmp,"li $t%d, 0",iRegistre); printMips(tmp); sprintf(tmp,"%s:", etiquette); printMips(tmp); }else if(n->u.opExp_.op == infeg){ parcours_exp(n->u.opExp_.op1); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); char etiquette[256]; new_tag(etiquette); sprintf(tmp,"li $t%d, 1",iRegistre); printMips(tmp); sprintf(tmp,"ble $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette); printMips(tmp); sprintf(tmp,"li $t%d, 0",iRegistre); printMips(tmp); sprintf(tmp,"%s:", etiquette); printMips(tmp); }else if(n->u.opExp_.op == ou){ char faux1[256]; char faux2[256]; char vrai[256]; char empile[256]; new_tag(faux1); new_tag(faux2); new_tag(vrai); new_tag(empile); parcours_exp(n->u.opExp_.op1); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"beq $zero, $t%d, %s",iRegistre2, faux1); printMips(tmp); sprintf(tmp,"j %s",vrai); printMips(tmp); sprintf(tmp,"%s :",faux1); printMips(tmp); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp,"or $t%d, $zero, $t%d",iRegistre, iRegistre3); printMips(tmp); sprintf(tmp,"j %s",empile); printMips(tmp); sprintf(tmp, "%s :", vrai); printMips(tmp); sprintf(tmp,"move $t%d $t%d",iRegistre, iRegistre2); printMips(tmp); sprintf(tmp,"%s : ", empile); printMips(tmp); } else if(n->u.opExp_.op == et) { char fin[256]; char faux[256]; new_tag(fin); new_tag(faux); parcours_exp(n->u.opExp_.op1); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"beq $zero, $t%d, %s",iRegistre2,faux); printMips(tmp); sprintf(tmp, "$t%d", iRegistre2); empile(tmp); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"beq $zero, $t%d, %s", iRegistre3, faux); printMips(tmp); sprintf(tmp,"and $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3); printMips(tmp); sprintf(tmp,"j %s", fin); printMips(tmp); sprintf(tmp," %s :",faux); printMips(tmp); sprintf(tmp,"li $t%d 0",iRegistre); printMips(tmp); sprintf(tmp ," %s :",fin); printMips(tmp); } else if(n->u.opExp_.op == non) { parcours_exp(n->u.opExp_.op1); sprintf(tmp, "$t%d", iRegistre3); depile(tmp); sprintf(tmp,"not $t%d $t%d",iRegistre,iRegistre3); printMips(tmp); } else if(n->u.opExp_.op == cond) { char tmp[256]; char faux[256]; char empile[256]; new_tag(faux); new_tag(empile); parcours_exp(n->u.opExp_.op1); sprintf(tmp, "$t%d", iRegistre2); depile(tmp); sprintf(tmp,"beq $t%d, $zero %s",iRegistre2, faux); printMips(tmp); parcours_exp(n->u.opExp_.op2); sprintf(tmp, "$t%d", iRegistre); depile(tmp); sprintf(tmp,"j %s", empile); printMips(tmp); sprintf(tmp, "%s :", faux); printMips(tmp); parcours_exp(n->u.opExp_.op3); sprintf(tmp, "$t%d", iRegistre); depile(tmp); sprintf(tmp, "%s :", empile); printMips(tmp); } sprintf(tmp, "$t%d", iRegistre); empile(tmp); }
void MetricsRecordBuilder::addTag(const std::string& name, const std::string& desc, const std::string& value) { MetricTagPtr new_tag(new MetricTag(name, desc, value)); this->addTag(new_tag); }
static HeaderLine *sam_header_line_parse(const char *headerLine) { int itype; HeaderLine *hline; HeaderTag *tag; const char *from, *to; from = headerLine; if (*from != '@') { debug("[sam_header_line_parse] expected '@', got [%s]\n", headerLine); return 0; } to = ++from; while (*to && (*to != '\t')) to++; if ((to - from) != 2) { debug("[sam_header_line_parse] expected '@XY', got [%s]\nHint: The header tags must be tab-separated.\n", headerLine); return 0; } hline = (HeaderLine*)malloc(sizeof(HeaderLine)); hline->type[0] = from[0]; hline->type[1] = from[1]; hline->tags = NULL; itype = tag_exists(hline->type, types); from = to; while (*to && (*to == '\t')) to++; if ((to - from) != 1) { debug("[sam_header_line_parse] multiple tabs on line [%s] (%d)\n", headerLine, (int)(to - from)); return 0; } from = to; while (*from) { while (*to && (*to != '\t')) to++; if (!required_tags[itype] && !optional_tags[itype]) { // CO is a special case, it can contain anything, including tabs if (*to) { to++; continue; } tag = new_tag(" ", from, to - 1); } else tag = new_tag(from, from + 3, to - 1); if (header_line_has_tag(hline, tag->key)) debug("The tag '%c%c' present (at least) twice on line [%s]\n", tag->key[0], tag->key[1], headerLine); hline->tags = list_append(hline->tags, tag); from = to; while (*to && (*to == '\t')) to++; if (*to && (to-from != 1)) { debug("[sam_header_line_parse] multiple tabs on line [%s] (%d)\n", headerLine,(int)(to-from)); return 0; } from = to; } return hline; }
static void newhandlers_callback(const void *closure, upb_handlers *h) { UPB_UNUSED(closure); upb_handlers_setstartmsg(h, startmsg, NULL); upb_handlers_setendmsg(h, endmsg, NULL); const upb_msgdef *m = upb_handlers_msgdef(h); upb_msg_field_iter i; for(upb_msg_field_begin(&i, m); !upb_msg_field_done(&i); upb_msg_field_next(&i)) { const upb_fielddef *f = upb_msg_iter_field(&i); bool packed = upb_fielddef_isseq(f) && upb_fielddef_isprimitive(f) && upb_fielddef_packed(f); upb_handlerattr attr; upb_wiretype_t wt = packed ? UPB_WIRE_TYPE_DELIMITED : upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; // Pre-encode the tag for this field. new_tag(h, f, wt, &attr); if (packed) { upb_handlers_setstartseq(h, f, encode_startdelimfield, &attr); upb_handlers_setendseq(h, f, encode_enddelimfield, &attr); } #define T(upper, lower, upbtype) \ case UPB_DESCRIPTOR_TYPE_##upper: \ if (packed) { \ upb_handlers_set##upbtype(h, f, encode_packed_##lower, &attr); \ } else { \ upb_handlers_set##upbtype(h, f, encode_scalar_##lower, &attr); \ } \ break; switch (upb_fielddef_descriptortype(f)) { T(DOUBLE, double, double); T(FLOAT, float, float); T(INT64, int64, int64); T(INT32, int32, int32); T(FIXED64, fixed64, uint64); T(FIXED32, fixed32, uint32); T(BOOL, bool, bool); T(UINT32, uint32, uint32); T(UINT64, uint64, uint64); T(ENUM, enum, int32); T(SFIXED32, sfixed32, int32); T(SFIXED64, sfixed64, int64); T(SINT32, sint32, int32); T(SINT64, sint64, int64); case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: upb_handlers_setstartstr(h, f, encode_startstr, &attr); upb_handlers_setendstr(h, f, encode_enddelimfield, &attr); upb_handlers_setstring(h, f, encode_strbuf, &attr); break; case UPB_DESCRIPTOR_TYPE_MESSAGE: upb_handlers_setstartsubmsg(h, f, encode_startdelimfield, &attr); upb_handlers_setendsubmsg(h, f, encode_enddelimfield, &attr); break; case UPB_DESCRIPTOR_TYPE_GROUP: { // Endgroup takes a different tag (wire_type = END_GROUP). upb_handlerattr attr2; new_tag(h, f, UPB_WIRE_TYPE_END_GROUP, &attr2); upb_handlers_setstartsubmsg(h, f, encode_startgroup, &attr); upb_handlers_setendsubmsg(h, f, encode_endgroup, &attr2); upb_handlerattr_uninit(&attr2); break; } } #undef T upb_handlerattr_uninit(&attr); } }
free(tag->data); free(tag); } /** * Creates a new tagged graph node with the given coordinate * * @param degree The number of edges that can be connected to the node. * @param coord The coordinate to tag the node with * * @return A new node at the given location with no data or neighbors */ graph_t new_g_node(dir_t degree, point_t coord) { graph_t new = new_node(degree); geotag_t tag = new_tag(coord); if (new && tag) { node_set_data(new, tag); } else { delete_empty_nodes(new); free(tag); new = NULL; } return new; } /** * If a node is not already tagged, tag the node with the given coordinate *