static void body_out(void *context, int rec_type, const char *buf, ssize_t len, off_t offset) { HBC_TEST_CONTEXT *dp = (HBC_TEST_CONTEXT *) context; char *out; if (dp->body_checks == 0 || (out = hbc_body_checks(context, dp->body_checks, buf, len, offset)) == buf) { vstring_sprintf(dp->buf, "%d BODY %c %ld\t|%s", dp->recno, rec_type, (long) offset, buf); out_cb(dp, rec_type, STR(dp->buf), LEN(dp->buf), offset); } else if (out != 0) { vstring_sprintf(dp->buf, "%d BODY %c %ld\t|%s", dp->recno, rec_type, (long) offset, out); out_cb(dp, rec_type, STR(dp->buf), LEN(dp->buf), offset); myfree(out); } dp->recno += 1; }
static void combobox_panel(struct gui_panel_layout *panel, struct show_window *demo) { gui_int i = 0; static const char *options[] = {"easy", "normal", "hard", "hell", "doom", "godlike"}; gui_panel_row(panel, 30, 3); for (i = 0; i < (gui_int)LEN(options); i++) { if (gui_panel_option(panel, options[i], demo->combo_selection == i)) demo->combo_selection = i; } }
static const char *xml_parse_meta_text(ACL_XML *xml, const char *data) { int ch; if (LEN(xml->curr_node->text) == 0) { SKIP_SPACE(data); } while ((ch = *data) != 0) { if (xml->curr_node->quote) { if (ch == xml->curr_node->quote) { xml->curr_node->quote = 0; } ADDCH(xml->curr_node->text, ch); } else if (IS_QUOTE(ch)) { if (xml->curr_node->quote == 0) { xml->curr_node->quote = ch; } ADDCH(xml->curr_node->text, ch); } else if (ch == '<') { xml->curr_node->nlt++; ADDCH(xml->curr_node->text, ch); } else if (ch == '>') { if (xml->curr_node->nlt == 0) { char *last; size_t off; data++; xml->curr_node->status = ACL_XML_S_MEND; if ((xml->curr_node->flag & ACL_XML_F_META_QM) == 0) break; last = acl_vstring_end(xml->curr_node->text) - 1; if (last < STR(xml->curr_node->text) || *last != '?') break; off = ACL_VSTRING_LEN(xml->curr_node->text) - 1; if (off == 0) break; ACL_VSTRING_AT_OFFSET(xml->curr_node->text, off); ACL_VSTRING_TERMINATE(xml->curr_node->text); xml_meta_attr(xml->curr_node); break; } xml->curr_node->nlt--; ADDCH(xml->curr_node->text, ch); } else { ADDCH(xml->curr_node->text, ch); } data++; } ACL_VSTRING_TERMINATE(xml->curr_node->text); return (data); }
/* $e <- x-y$ */ static void gf3m_sub(element_t e, element_t a, element_t b) { unsigned long *e1 = DATA1(e), *e2 = DATA2(e), *a1 = DATA1(a), *a2 = DATA2(a), *b1 = DATA2(b), *b2 = DATA1(b); unsigned i; for (i = 0; i < LEN(e); i++, e1++, e2++, a1++, a2++, b1++, b2++) { unsigned long t = (*a1 | *a2) & (*b1 | *b2), c1 = t ^ (*a1 | *b1), c2 = t ^ (*a2 | *b2); *e1 = c1; *e2 = c2; } }
static void postmap_header(void *ptr, int unused_header_class, const HEADER_OPTS *unused_header_info, VSTRING *header_buf, off_t offset) { /* * Don't re-invent an already working wheel. */ postmap_body(ptr, 0, STR(header_buf), LEN(header_buf), offset); }
main(int unused_argc, char **unused_argv) { VSTRING *raw = vstring_alloc(BUFLEN); VSTRING *hex = vstring_alloc(100); int len; while ((len = read_buf(VSTREAM_IN, raw)) > 0) { hex_quote(hex, STR(raw)); if (hex_unquote(raw, STR(hex)) == 0) msg_fatal("bad input: %.100s", STR(hex)); if (LEN(raw) != len) msg_fatal("len %d != raw len %d", len, LEN(raw)); if (vstream_fwrite(VSTREAM_OUT, STR(raw), LEN(raw)) != LEN(raw)) msg_fatal("write error: %m"); } vstream_fflush(VSTREAM_OUT); vstring_free(raw); vstring_free(hex); return (0); }
int gf3m_to_bytes(unsigned char *d, element_ptr e) { unsigned long *a = DATA1(e), *b = DATA2(e); unsigned long i, j; for (i = 0; i < LEN(e); i++, a++, b++) { for (j = 0; j < sizeof(unsigned long) * 8; j += 8) { *(d++) = (unsigned char) ((*a) >> j); *(d++) = (unsigned char) ((*b) >> j); } } return SIZE(e); }
int rbug_send_texture_read_reply(struct rbug_connection *__con, uint32_t serial, uint32_t format, uint32_t blockw, uint32_t blockh, uint32_t blocksize, uint8_t *data, uint32_t data_len, uint32_t stride, uint32_t *__serial) { uint32_t __len = 0; uint32_t __pos = 0; uint8_t *__data = NULL; int __ret = 0; LEN(8); /* header */ LEN(4); /* serial */ LEN(4); /* format */ LEN(4); /* blockw */ LEN(4); /* blockh */ LEN(4); /* blocksize */ LEN_ARRAY(1, data); /* data */ LEN(4); /* stride */ /* align */ PAD(__len, 8); __data = (uint8_t*)MALLOC(__len); if (!__data) return -ENOMEM; WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY)); WRITE(4, uint32_t, ((uint32_t)(__len / 4))); WRITE(4, uint32_t, serial); /* serial */ WRITE(4, uint32_t, format); /* format */ WRITE(4, uint32_t, blockw); /* blockw */ WRITE(4, uint32_t, blockh); /* blockh */ WRITE(4, uint32_t, blocksize); /* blocksize */ WRITE_ARRAY(1, uint8_t, data); /* data */ WRITE(4, uint32_t, stride); /* stride */ /* final pad */ PAD(__pos, 8); if (__pos != __len) { __ret = -EINVAL; } else { rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len); rbug_connection_write(__con, __data, __len); __ret = rbug_connection_send_finish(__con, __serial); } FREE(__data); return __ret; }
/* rotate pieces in blocks by either 90^ or -90^ around (0, 0) pivot */ static int rotate_block(struct blocks *block, enum blocks_input_cmd cmd) { int new_x, new_y; int bounds_x, bounds_y; int dir = 1; size_t i; if (!block) return -1; /* Don't rotate O block */ if (block->type == O_BLOCK) return 1; if (cmd == ROT_LEFT) dir = -1; /* Check each piece for a collision before we write any changes */ for (i = 0; i < LEN(block->p); i++) { bounds_x = block->p[i].y * (-dir) + block->col_off; bounds_y = block->p[i].x * (dir) + block->row_off; /* Check for out of bounds on each piece */ if (bounds_x < 0 || bounds_x >= BLOCKS_MAX_COLUMNS || bounds_y < 0 || bounds_y >= BLOCKS_MAX_ROWS || /* Also check if a piece already exists here */ blocks_at_yx(bounds_y, bounds_x)) return 0; } /* No collisions, so update the block position. */ for (i = 0; i < LEN(block->p); i++) { new_x = block->p[i].y * (-dir); new_y = block->p[i].x * (dir); block->p[i].x = new_x; block->p[i].y = new_y; } return 1; }
int rbug_send_shader_list_reply(struct rbug_connection *__con, uint32_t serial, rbug_shader_t *shaders, uint32_t shaders_len, uint32_t *__serial) { uint32_t __len = 0; uint32_t __pos = 0; uint8_t *__data = NULL; int __ret = 0; LEN(8); /* header */ LEN(4); /* serial */ LEN_ARRAY(8, shaders); /* shaders */ /* align */ PAD(__len, 8); __data = (uint8_t*)MALLOC(__len); if (!__data) return -ENOMEM; WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY)); WRITE(4, uint32_t, ((uint32_t)(__len / 4))); WRITE(4, uint32_t, serial); /* serial */ WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */ /* final pad */ PAD(__pos, 8); if (__pos != __len) { __ret = -EINVAL; } else { rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len); rbug_connection_write(__con, __data, __len); __ret = rbug_connection_send_finish(__con, __serial); } FREE(__data); return __ret; }
int name2sig(const char *name) { size_t i; for (i = 0; i < LEN(sigs); i++) if (!strcasecmp(sigs[i].name, name)) return sigs[i].sig; eprintf("%s: bad signal name\n", name); return -1; /* not reached */ }
/* $y <- (-x)$ */ static void gf3m_neg(element_t y, element_t x) { unsigned long *a1 = DATA1(x), *a2 = DATA2(x), *c1 = DATA1(y), *c2 = DATA2(y); if (a1 == c1) { unsigned i; for (i = 0; i < LEN(y); i++, a1++, a2++) swap(a1, a2); } else { memcpy(c1, a2, SIZE(y) / 2); memcpy(c2, a1, SIZE(y) / 2); } }
void test_get_flow_info_one_flow( void** state ) { char* links[] = { "alink", "onemore", NULL }; datalink_id_t link_ids[ LEN( links ) - 1 ] = { 13, 15 }; char* ips[] = { "1.2.3.4", "4.3.2.1" }; dladm_flow_attr_t attrs[] = { { .fa_linkid = link_ids[ 0 ], .fa_flowname = "aflow", .fa_flow_desc = { .fd_mask = FLOW_IP_LOCAL | FLOW_IP_PROTOCOL | FLOW_ULP_PORT_LOCAL, .fd_protocol = IPPROTO_TCP, .fd_local_port = 12 } }, { .fa_linkid = link_ids[ 1 ],
MidiEvent midi_pop() { if (!midi_count()) err(1, "midi queue underflow"); locker(1); MidiEvent me = *head++; if (head == &events[LEN(events)]) head = events; nevent--; locker(0); return me; }
static void attr_print64_long_num(ACL_VSTREAM *fp, unsigned long long_num) { static __thread ACL_VSTRING *plain; if (plain == 0) { plain = acl_vstring_alloc(10); acl_pthread_atexit_add(plain, free_vstring); } acl_vstring_sprintf(plain, "%lu", long_num); attr_print64_str(fp, STR(plain), (int) LEN(plain)); }
/*! \brief frees the sem[] array \param owner if owner is nonzero, further deinitialization (sem_unlink) is performed \details Every element of sem[] will be SEM_FAILED after this function is called. If owner is nonzero, the semaphores will be unlinked */ static void free_semaphores(int owner) { int i; for(i = 0; i < LEN(sem); i++) { if(sem[i] != SEM_FAILED) { (void)sem_close(sem[i]); sem[i] = SEM_FAILED; } if(owner != 0) (void)sem_unlink(SEM_NAME[i]); } }
static void print_resolved_types(TYPERUN *pp) { fprintf(stderr, " Types: "); while(pp) { BidiStrIndex i; for(i = 0; i < LEN (pp); i++) fprintf(stderr, "%c", bidi_type_name(pp->type)); pp = pp->next; } fprintf(stderr, "\n"); }
const std::list<rfc822_addr*>& rfc822::parse_addrs(const char* in) { reset(); if (in == NULL || *in == 0) { logger_error("input invalid"); return (addrs_); } TOK822 *tree = tok822_parse(in); if (tree == NULL) { logger_error("tok822_parse(%s) error", in); return (addrs_); } const ACL_VSTRING* comment_prev = NULL; string buf; for (TOK822 *tp = tree; tp; tp = tp->next) { if (tp->type == TOK822_ATOM || tp->type == TOK822_COMMENT || tp->type == TOK822_QSTRING || tp->vstr != NULL) { comment_prev = tp->vstr; } if (tp->type != TOK822_ADDR || tp->head == NULL) continue; ACL_VSTRING* addrp = acl_vstring_alloc(32); (void) tok822_internalize(addrp, tp->head, TOK822_STR_DEFL); rfc822_addr* addr = (rfc822_addr*) acl_mymalloc(sizeof(rfc822_addr)); addr->addr = acl_vstring_export(addrp); if (comment_prev) { buf.clear(); rfc2047::decode(STR(comment_prev), LEN(comment_prev), &buf, "gb18030"); addr->comment = acl_mystrdup(buf.c_str()); comment_prev = NULL; } else addr->comment = NULL; addrs_.push_back(addr); } tok822_free_tree(tree); return (addrs_); }
int main(int unused_argc, char **unused_argv) { VSTRING *unquoted = vstring_alloc(BUFLEN); VSTRING *quoted = vstring_alloc(100); ssize_t len; while ((len = read_buf(VSTREAM_IN, unquoted)) > 0) { xtext_quote(quoted, STR(unquoted), "+="); if (xtext_unquote(unquoted, STR(quoted)) == 0) msg_fatal("bad input: %.100s", STR(quoted)); if (LEN(unquoted) != len) msg_fatal("len %ld != unquoted len %ld", (long) len, (long) LEN(unquoted)); if (vstream_fwrite(VSTREAM_OUT, STR(unquoted), LEN(unquoted)) != LEN(unquoted)) msg_fatal("write error: %m"); } vstream_fflush(VSTREAM_OUT); vstring_free(unquoted); vstring_free(quoted); return (0); }
static void parse_json(const char *data) { ACL_JSON *json = acl_json_alloc(); ACL_VSTRING *buf1 = acl_vstring_alloc(128); ACL_VSTRING *buf2 = acl_vstring_alloc(128); ACL_ARRAY *nodes; const char *tag = "header"; printf("buf src: %s\r\n", data); printf("------------------------------------------------\r\n"); acl_json_update(json, data); acl_json_build(json, buf1); printf("result src: %s\r\n", STR(buf1)); printf("------------------------------------------------\r\n"); nodes = acl_json_getElementsByTagName(json, tag); if (nodes == NULL) { printf("not found tag: %s\r\n", tag); acl_vstring_free(buf1); acl_vstring_free(buf2); acl_json_free(json); return; } printf(">>>tag: %s, len: %d\r\n", tag, acl_array_size(nodes)); ACL_ITER iter; #define STR acl_vstring_str #define LEN ACL_VSTRING_LEN acl_foreach(iter, nodes) { ACL_JSON_NODE *node = (ACL_JSON_NODE*) iter.data; ACL_JSON_NODE *tag_node = node->tag_node; if (tag_node == NULL) continue; printf(">>>tag: %s\r\n", STR(node->ltag)); ACL_ITER iter2; acl_foreach(iter2, tag_node) { ACL_JSON_NODE *node1 = (ACL_JSON_NODE*) iter2.data; if (node1->ltag == NULL || LEN(node1->ltag) == 0) continue; printf(">>>child tag: %s, txt: %s\r\n", STR(node1->ltag), node1->text ? STR(node1->text) : "null"); }
static void node_editor_link(struct node_editor *editor, int in_id, int in_slot, int out_id, int out_slot) { struct node_link *link; assert((zr_size)editor->link_count < LEN(editor->links)); link = &editor->links[editor->link_count++]; link->input_id = in_id; link->input_slot = in_slot; link->output_id = out_id; link->output_slot = out_slot; }
int main(void) { pc.baud(115200); pc.printf("ADC test:\r\n"); while (1) { for (int i = 0; i < LEN(s_ch); i++) pc.printf("%d: %4X ", i, s_ch[i].read_u16()); pc.printf("\r\n"); wait(1); } return 0; }
static inline void shift_chars(struct part *p, int y, int s) { chr *a; int l = LEN(y); if ((unsigned)l > MAXINT / sizeof(chr)) overalloc(); a = mem_alloc(l * sizeof(chr)); memcpy(a, &POS(0, y), l * sizeof(chr)); set_hchars(p, 0, y, s, (p->data->data[y].c << 11) | ' '); copy_chars(p, s, y, l, a); mem_free(a); move_links(p, 0, y, s, y); }
const char * sig2name(const int sig) { size_t i; for (i = 0; i < LEN(sigs); i++) if (sigs[i].sig == sig) return sigs[i].name; eprintf("%d: bad signal number\n", sig); return NULL; /* not reached */ }
static const char *xml_parse_text(ACL_XML *xml, const char *data) { int ch; if (LEN(xml->curr_node->text) == 0) { SKIP_SPACE(data); if (*data == 0) return (NULL); } while ((ch = *data) != 0) { if (ch == '<') { xml->curr_node->status = ACL_XML_S_RLT; data++; break; } ACL_VSTRING_ADDCH(xml->curr_node->text, ch); data++; } ACL_VSTRING_TERMINATE(xml->curr_node->text); if (xml->curr_node->status != ACL_XML_S_RLT) return (data); if ((xml->curr_node->flag & ACL_XML_F_SELF_CL)) { /* 如果该标签是自关闭类型,则应使父结点直接跳至右边 '/' 处理位置, * 同时使本结点跳至右边 '>' 处理位置 */ ACL_XML_NODE *parent = acl_xml_node_parent(xml->curr_node); if (parent != xml->root) parent->status = ACL_XML_S_RLT; xml->curr_node->status = ACL_XML_S_RGT; } if (LEN(xml->curr_node->text) == 0) return (data); return (data); }
int rbug_send_shader_info(struct rbug_connection *__con, rbug_context_t context, rbug_shader_t shader, uint32_t *__serial) { uint32_t __len = 0; uint32_t __pos = 0; uint8_t *__data = NULL; int __ret = 0; LEN(8); /* header */ LEN(8); /* context */ LEN(8); /* shader */ /* align */ PAD(__len, 8); __data = (uint8_t*)MALLOC(__len); if (!__data) return -ENOMEM; WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO)); WRITE(4, uint32_t, ((uint32_t)(__len / 4))); WRITE(8, rbug_context_t, context); /* context */ WRITE(8, rbug_shader_t, shader); /* shader */ /* final pad */ PAD(__pos, 8); if (__pos != __len) { __ret = -EINVAL; } else { rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len); rbug_connection_write(__con, __data, __len); __ret = rbug_connection_send_finish(__con, __serial); } FREE(__data); return __ret; }
/* * Search for exact match in given @head. * Assume host bits are cleared in @v_arg if @m_arg is not NULL * Note that prefixes with /32 or /128 masks are treated differently * from host routes. */ struct radix_node * rn_lookup(void *v_arg, void *m_arg, struct radix_node_head *head) { struct radix_node *x; caddr_t netmask; if (m_arg != NULL) { /* * Most common case: search exact prefix/mask */ x = rn_addmask(m_arg, head->rnh_masks, 1, head->rnh_treetop->rn_offset); if (x == NULL) return (NULL); netmask = x->rn_key; x = rn_match(v_arg, head); while (x != NULL && x->rn_mask != netmask) x = x->rn_dupedkey; return (x); } /* * Search for host address. */ if ((x = rn_match(v_arg, head)) == NULL) return (NULL); /* Check if found key is the same */ if (LEN(x->rn_key) != LEN(v_arg) || bcmp(x->rn_key, v_arg, LEN(v_arg))) return (NULL); /* Check if this is not host route */ if (x->rn_mask != NULL) return (NULL); return (x); }
CORD CORD_cat(CORD x, CORD y) { size_t result_len; int depth; size_t lenx; if (x == CORD_EMPTY) return(y); if (y == CORD_EMPTY) return(x); if (CORD_IS_STRING(y)) { return(CORD_cat_char_star(x, y, strlen(y))); } else if (CORD_IS_STRING(x)) { lenx = strlen(x); depth = DEPTH(y) + 1; } else { int depthy = DEPTH(y); lenx = LEN(x); depth = DEPTH(x) + 1; if (depthy >= depth) depth = depthy + 1; } result_len = lenx + LEN(y); { struct Concatenation * result = GC_NEW(struct Concatenation); if (NULL == result) OUT_OF_MEMORY; result->header = CONCAT_HDR; result->depth = (char)depth; if (lenx <= MAX_LEFT_LEN) result->left_len = (unsigned char)lenx; result->len = (word)result_len; result->left = x; GC_PTR_STORE_AND_DIRTY((void *)&result->right, y); GC_reachable_here(x); if (depth >= MAX_DEPTH) { return(CORD_balance((CORD)result)); } else { return((CORD) result); } } }
int rbug_send_context_draw_blocked(struct rbug_connection *__con, rbug_context_t context, rbug_block_t block, uint32_t *__serial) { uint32_t __len = 0; uint32_t __pos = 0; uint8_t *__data = NULL; int __ret = 0; LEN(8); /* header */ LEN(8); /* context */ LEN(4); /* block */ /* align */ PAD(__len, 8); __data = (uint8_t*)MALLOC(__len); if (!__data) return -ENOMEM; WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED)); WRITE(4, uint32_t, ((uint32_t)(__len / 4))); WRITE(8, rbug_context_t, context); /* context */ WRITE(4, rbug_block_t, block); /* block */ /* final pad */ PAD(__pos, 8); if (__pos != __len) { __ret = -EINVAL; } else { rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCKED, __len); rbug_connection_write(__con, __data, __len); __ret = rbug_connection_send_finish(__con, __serial); } FREE(__data); return __ret; }
/* DSR:CL_BUG: (See comment for join method in Misc.h): */ TCHAR* Misc::join (const TCHAR* a, const TCHAR* b, const TCHAR* c, const TCHAR* d, const TCHAR* e, const TCHAR* f) { #define LEN(x) (x == NULL ? 0 : _tcslen(x)) const size_t totalLen = LEN(a) + LEN(b) + LEN(c) + LEN(d) + LEN(e) + LEN(f) + sizeof(TCHAR); /* Space for terminator. */ TCHAR* buf = _CL_NEWARRAY(TCHAR, totalLen); buf[0] = 0; if (a != NULL) _tcscat(buf, a); if (b != NULL) _tcscat(buf, b); if (c != NULL) _tcscat(buf, c); if (d != NULL) _tcscat(buf, d); if (e != NULL) _tcscat(buf, e); if (f != NULL) _tcscat(buf, f); return buf; }