static node_t *tag_decl(void) { int t = token->id; const char *id = NULL; node_t *sym = NULL; struct source src = source; int follow[] = {INT, CONST, STATIC, IF, 0}; expect(t); if (token->id == ID) { id = token->name; expect(ID); } if (token->id == '{') { expect('{'); sym = tag_type(t, id, src); if (t == ENUM) ids(sym); else fields(sym); match('}', follow); SYM_DEFINED(sym) = true; } else if (id) { sym = lookup(id, tags); if (sym) { if (is_current_scope(sym) && TYPE_OP(SYM_TYPE(sym)) != t) errorf(src, "use of '%s' with tag type that does not match " "previous declaration '%s' at %s:%u:%u", id2s(t), type2s(SYM_TYPE(sym)), AST_SRC(sym).file, AST_SRC(sym).line, AST_SRC(sym).column); } else { sym = tag_type(t, id, src); } } else { error("expected identifier or '{'"); sym = tag_type(t, NULL, src); } return SYM_TYPE(sym); }
static int subprocess(void *context) { struct context *con = (struct context *)context; const char *code = con->code; const char *type = con->type; const char *output = con->output; node_t *n = compile(code); node_t *n1 = DECL_EXTS(n)[0]; node_t *ty = SYM_TYPE(DECL_SYM(n1)); const char *ret; const char *p1, *p2; if (strcmp(TYPE_NAME(unqual(ty)), type)) fail("type not equal: %s != %s", TYPE_NAME(unqual(ty)), type); ret = type2s(ty); p1 = ret; p2 = output; for (;;) { while (isspace((unsigned char)*ret)) ret++; while (isspace((unsigned char)*output)) output++; if (*ret == '\0' || *output == '\0') break; if (*ret != *output) fail("'%s' != '%s' at '%c' != '%c'", p1, p2, *ret, *output); ret++; output++; } if (*ret != '\0' || *output != '\0') fail("'%s' != '%s'", p1, p2); return EXIT_SUCCESS; }
int nl2_send(int sock, struct sockaddr_in *addr, znl2msg *msg) { int i; int len; uint32_t* store; znl2msg *flipped; if (verbose >= 1) fprintf(stdout, "%s: sending %d bytes (message #%d %s) to %s:%d\n", progname, msg->n.znl2msg_len, msg->n.znl2msg_seq, type2s(msg->n.znl2msg_type), inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)); /* * Make a copy of msg before byte flipping it. We're preserving the * original so that we can compare the request & reply headers. */ len = msg->n.znl2msg_len; flipped = malloc(len); memcpy(flipped, msg, len); /* Endianess/byte ordering */ store = (uint32_t*) flipped; if (flipped->n.znl2msg_type == ZNL2_SYN || flipped->n.znl2msg_type == ZNL2_FIN) { for (i = 0; i < (sizeof(znl2msghdr)/4+2); i++) store[i] = psdb_pton(store[i]); } else { for (i = 0; i < (len/4); i++) store[i] = psdb_pton(store[i]); } if (verbose >= 3) dump_packet(flipped, len); return sendto(sock, flipped, len, 0, (struct sockaddr *)addr, sizeof(struct sockaddr_in)); }
static void parse_assign(node_t *atype) { node_t *assign = assign_expr(); TYPE_A_ASSIGN(atype) =assign; if (!assign) return; if (isint(AST_TYPE(assign))) { // try evaluate the length node_t *ret = eval(assign, longtype); if (ret) { cc_assert(isiliteral(ret)); TYPE_LEN(atype) = ILITERAL_VALUE(ret); if ((long)ILITERAL_VALUE(ret) < 0) error("array has negative size"); } else { error("expect constant expression"); } } else { error("size of array has non-integer type '%s'", type2s(AST_TYPE(assign))); } }