void capture_scanner::validate_reply (void) const { if (byte (0x80) == rep_) return; if (byte (0x40) == rep_) BOOST_THROW_EXCEPTION (device_busy ()); if (NAK == rep_) BOOST_THROW_EXCEPTION (invalid_command ()); BOOST_THROW_EXCEPTION (unknown_reply ()); }
int receiveProgramSize(socket) { char buf[1024] ={0}; int bytes_read; int arg_pos; int size; bytes_read = recvline(socket, buf, sizeof(buf)-1); if (bytes_read <= 0) _terminate(4); arg_pos = parseCmd(PRGM_SIZE_CMD, buf); if (!arg_pos) { invalid_command(); _terminate(5); } size = strn2int(buf+arg_pos, MAX_ARG_SIZE); return size; }
/** * This is the will be the entry point to your text editor. */ int main(int argc, char *argv[]) { // Checking to see if the editor is being used correctly. if (argc != 2) { print_usage_error(); return 1; } // Setting up a docment based on the file named 'filename'. char *filename = get_filename(argc, argv); Document *document = Document_create_from_file(filename); // Buffer for the command and length of said buffer char *command = NULL; size_t len = 0; // This while loop will keep reading from stdin one line at a time // until the user enters 'q' (the quit command). int done = 0; while (!done) { getline(&command, &len, stdin); int command_type; // remove newline from the command char *nl = strchr(command, '\n'); if (nl) *nl = 0; int stringlen = strlen(command); // if 'q' or 's' is first character only 'q' or 's' is allowed as valid // command if ((command[0] == 'q' || command[0] == 's') && stringlen != 1) { command_type = -1; } else { command_type = command[0]; } switch (command_type) { case 'p': handle_display_command(document, command); break; case 'w': handle_write_command(document, command); break; case 'a': handle_append_command(document, command); break; case 'd': handle_delete_command(document, command); break; case '/': handle_search_command(document, command); break; case 's': if (strlen(command) == 1) { handle_save_command(document, filename); } else { invalid_command(command); } break; case 'q': done = 1; Document_destroy(document); break; default: invalid_command(command); break; } } // Need to free the buffer that we created. if (command) { free(command); } }