/** * Fills the given order with the data of the next buffered order. * * parser_has_new_order() _has_ to return true before calling this. * * @param[out] order The order structure which should be filled. */ void parser_get_new_order(order_t* order) { // Function fills the parameter with the next order in the ringbuffer // but will do a check on it first. if the Order isn't flagged valid // the caller must discard it. parser_check_order(&parser_order_buffer[first_buffer_position]); if (DEBUG_ENABLE) { debug_write_integer(PSTR("parse.c : parser_get_new_order() : status = "), parser_order_buffer[first_buffer_position].status); } // Copy the order to the caller order_copy(&parser_order_buffer[first_buffer_position], order); // Clean the local structure order_init(&parser_order_buffer[first_buffer_position]); first_buffer_position++; // manual modulo operation, because normal modulo operation takes to much time first_buffer_position -= (first_buffer_position / PARSER_ORDER_BUFFER_SIZE) * PARSER_ORDER_BUFFER_SIZE; // if buffer is full, set position to illegal value if (first_buffer_position == current_buffer_position) { first_buffer_position = -1; } }
/** * Initializes the Parser Module. * * Mainly needed to init the ring buffer of orders. */ void parser_init(void) { // Initialize the Ringbuffer for (uint8_t i = 0; i < PARSER_ORDER_BUFFER_SIZE; i++) { order_init(&parser_order_buffer[i]); } }
int main(int argc, char **argv) { int ch; const char *conffile; conffile = CONFFILE; while ((ch = getopt(argc, argv, "f:v")) != -1) { switch (ch) { case 'f': conffile = optarg; break; case 'v': verbose++; break; default: usage(); /* NOTREACHED */ } } bzero(&config, sizeof(config)); config.print.feedlines = -1; config.print.cchide_customer = 1; config.print.ccsig_customer = 1; bzero(&header, sizeof(header)); if (parse_config(conffile)) exit(1); /* set database files */ if (config.database.custdb == NULL) if ((config.database.custdb = strdup(config.database.alldb ? config.database.alldb : CUSTDBFILE)) == NULL) err(1, "cannot set customer database file"); if (config.database.menudb == NULL) if ((config.database.menudb = strdup(config.database.alldb ? config.database.alldb : MENUDBFILE)) == NULL) err(1, "cannot set menu database file"); if (config.database.orderdb == NULL) if ((config.database.orderdb = strdup(config.database.alldb ? config.database.alldb : ORDERDBFILE)) == NULL) err(1, "cannot set order database file"); if (config.print.feedlines < 0) config.print.feedlines = PRINT_FEED_LINES; if (licence_init() == -1) errx(1, "cannot proceed without licence"); event_init(); module_init(); rule_init(); input_init(); print_init(); form_init(); display_init(); status_init(); menu_init(); customer_init(); special_init(); payment_init(); window_init(); order_init(); display_refresh(); signal(SIGPIPE, SIG_IGN); if (event_dispatch() == -1) err(1, "terminated abnormally"); if (exitcode != 0 && exitmsg == NULL) exitmsg = strdup(status.status); order_exit(); window_exit(); payment_exit(); special_exit(); customer_exit(); menu_exit(); status_exit(); display_exit(); form_exit(); print_exit(); input_exit(); rule_exit(); module_exit(); if (exitcode && exitmsg != NULL) errx(exitcode, "%s", exitmsg); else fprintf(stdout, "exiting normally\n"); exit(0); }