/* * expect() gets a token and dies most horribly if it's not the token we want */ static void expect(tokid_t desired) { if (token() != desired) plonk(sc_tokid); /* and we die here... */ }
static void plus(struct tm *tm) { int delay; int expectplur; expect(NUMBER); delay = atoi(sc_token); expectplur = (delay != 1) ? 1 : 0; switch (token()) { case YEARS: tm->tm_year += delay; break; case MONTHS: tm->tm_mon += delay; break; case WEEKS: delay *= 7; case DAYS: tm->tm_mday += delay; break; case HOURS: tm->tm_hour += delay; break; case MINUTES: tm->tm_min += delay; break; default: plonk(sc_tokid); break; } if (expectplur != sc_tokplur) warnx("pluralization is wrong"); tm->tm_isdst = -1; if (mktime(tm) < 0) plonk(sc_tokid); } /* plus */
int main(int argc, const char *argv[]) { ALLEGRO_EVENT event; ALLEGRO_KEYBOARD_STATE kst; bool blend; if (!al_init()) { abort_example("Could not init Allegro.\n"); return 1; } al_init_primitives_addon(); al_install_keyboard(); al_install_mouse(); display = al_create_display(W, H); if (!display) { abort_example("Error creating display\n"); return 1; } black = al_map_rgb_f(0.0, 0.0, 0.0); white = al_map_rgb_f(1.0, 1.0, 1.0); background = al_map_rgb_f(0.5, 0.5, 0.6); if (argc > 1 && 0 == strcmp(argv[1], "--memory-bitmap")) { al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); } dbuf = al_create_bitmap(W, H); if (!dbuf) { abort_example("Error creating double buffer\n"); return 1; } al_set_target_bitmap(dbuf); al_clear_to_color(background); draw_clip_rect(); flip(); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); while (true) { al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { al_get_keyboard_state(&kst); blend = al_key_down(&kst, ALLEGRO_KEY_LSHIFT) || al_key_down(&kst, ALLEGRO_KEY_RSHIFT); if (event.mouse.button == 1) { plonk(event.mouse.x, event.mouse.y, blend); } else { splat(event.mouse.x, event.mouse.y, blend); } } else if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { last_x = last_y = -1; } else if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } } al_destroy_event_queue(queue); al_destroy_bitmap(dbuf); return 0; }