int main(void) { char buf[1024]; int ret; do_config(); setup(); sleep(2); while (1) { cgc_memset(buf, 0, sizeof(buf)); ret = read_until(read_fd, buf, sizeof(buf), '\n'); if (ret == -1) cgc_exit(4); if (ret > 0) { if (buf[0] == 0) { cgc_exit(0); } ret = search(buf, cgc_strlen(buf)); if (ret != 1) { printf(write_fd, "%s\n", buf); } } } cgc_exit(1); }
int main(void) { unsigned size = 0; size_t cgc_read = 0; uint8_t buf[MAX_SIZE]; cgc_memset(buf, 0, sizeof(buf)); if (receive(STDIN, &size, sizeof(size), &cgc_read) != 0) cgc_exit(1); if (cgc_read != 4) cgc_exit(1); if (size > MAX_SIZE) { printf("too big\n"); cgc_exit(1); } if (read_exactly(STDIN, buf, size) != 0) cgc_exit(1); element *e = decode(buf, (unsigned) buf + size); if (e == NULL) cgc_exit(1); pprint(e); }
int main(int cgc_argc, char *cgc_argv[]) { char buf[8]; int i; cgc_fbuffered(cgc_stdin, 1); for (i = 0; i < 8; i += 2) cgc_printf("%02X", secret[i] & 0xFF); cgc_printf("\n"); while(1) { cgc_print_menu(); cgc_fflush(cgc_stdout); if (cgc_freaduntil(buf, sizeof(buf), '\n', cgc_stdin) < 0) return -1; switch(cgc_strtoul(buf, NULL, 10)) { case 1: cgc_handle_compress(); break; case 2: cgc_handle_decompress(); break; case 3: cgc_printf("Bye.\n"); cgc_fflush(cgc_stdout); cgc_exit(0); break; default: cgc_printf("Invalid menu.\n"); break; } } return 0; }
int dispatch(void) { int ret = SUCCESS; unsigned char op = rx_buf[0]; switch(op) { case '\x01': entanglement_razzmatazz(); break; case '\x07': causality_poppycock(); break; case '\x03': heisenberg_hooey(); break; case '\x04': relativistic_jabberwock(); break; case '\x00': cgc_exit(); break; default: #ifdef DEBUG fprintf(stderr, "[D] invalid operation: 0x%02x\n", op); #endif ret = ERRNO_INVALID_OPERATION; break; } return ret; }
packet_t* cgc_parse_packet(int fd) { cgc_size_t to_read = 0; char *body = NULL; packet_t *packet = NULL; packet = (packet_t *) cgc_malloc(sizeof(packet_t)); if (packet == NULL) goto fail; /* Read the packet header */ to_read = sizeof(packet_t) - sizeof(char *); if (cgc_read_n(fd, (char *)packet, to_read) != to_read) cgc_exit(0); //goto fail; if (packet->body_len > MAX_BODY_LEN) goto fail; body = cgc_malloc(packet->body_len); if (body == NULL) goto fail; /* Read the packet body */ to_read = packet->body_len; if (cgc_read_n(fd, body, to_read) != packet->body_len) goto fail; packet->body = body; if (packet->checksum != cgc_calc_checksum(packet)) goto fail; return packet; fail: if (body) cgc_free(body); if (packet) cgc_free(packet); return NULL; }
int main(int cgc_argc, char *cgc_argv[]) { cgc_printf("Welcome to the SLUR REPL. Type an expression to evaluate it.\n"); char *buf = cgc_malloc(MAX_EXPRESSION_LENGTH + 1); if (buf == NULL) cgc_exit(1); for (;;) { cgc_memset(buf, '\0', MAX_EXPRESSION_LENGTH + 1); cgc_printf("> "); if (cgc_read_balanced_expression(STDIN, buf, MAX_EXPRESSION_LENGTH) != 0) { cgc_printf("Expression too long or unbalanced, try again.\n"); continue; } // Maybe unbounded print here on hard to acheive error. if (cgc_repl(buf) != 0) cgc_printf("Error evaluating expression.\n"); return 0; } }
void cgc_handle_menu(const char *str) { int cmd = str[0]; /* either nothing comes after command or a space delimiter */ if (str[1] != 0 && str[1] != ' ') cmd = 0; switch (cmd) { case 'H': case 'h': case '?': cgc_bbs_help(); break; case 'L': case 'l': cgc_do_list(str); break; case 'P': case 'p': cgc_do_post(str); break; case 'R': case 'r': cgc_do_read(str); break; case 'Q': case 'q': cgc_exit(0); break; default: send_string("Bad input. Unknown command.\n"); break; } }
void cgc__terminate(int ec) { cgc_exit(ec); }
void quit() { printf("Bye!\n"); cgc_exit(0); }
int cgc_part_cmd(const char *s) { cgc_printf("BYE!\n"); cgc_exit(0); return 0; }