/* --- begin code --- */ /* Erik Ferguson CMPS 104 Assignment Three */ /* === INCLUDES ===================================================== */ #include #include /* === INCLUDES ===================================================== */ /* === FUNCTION DECLARATIONS ======================================== */ unsigned short flipon (unsigned short, int, int); unsigned short flipoff (unsigned short, int, int); void status (unsigned short); /* === FUNCTION DECLARATIONS ======================================== */ /* === MAIN ========================================================= */ int main(void) { char aurora_musis_amica, *bibamus_moriendum_est; unsigned short ars_longa_vita_brevis = 0 << 15; /* Redisplay and prompt user until they enter nine */ while(aurora_musis_amica != 9) { /* print out status of lights */ status(ars_longa_vita_brevis); /* display menu */ printf("\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n", "1. turn on all lights", "2. turn on center stage lights (05-10)", "3. turn on left stage lights (11-15)", "4. turn on right stage lights (00-04)", "5. turn off all lights", "6. turn off center stage lights (05-10)", "7. turn off left stage lights (11-15)", "8. turn off right stage lights (00-04)", "9. quit the menu"); gets(aurora_musis_amica); aurora_musis_amica = strtok(aurora_musis_amica, "\040\t"); aurora_musis_amica = (int)strtol(aurora_musis_amica, &bibamus_moriendum_est, 10); /* handle menuchoice appropriately */ switch(aurora_musis_amica) { case 1: ars_longa_vita_brevis = flipon(ars_longa_vita_brevis, 0, 15); break; case 2: ars_longa_vita_brevis = flipon(ars_longa_vita_brevis, 5, 10); break; case 3: ars_longa_vita_brevis = flipon(ars_longa_vita_brevis, 11, 15); break; case 4: ars_longa_vita_brevis = flipon(ars_longa_vita_brevis, 0, 4); break; case 5: ars_longa_vita_brevis = flipoff(ars_longa_vita_brevis, 0, 15); break; case 6: ars_longa_vita_brevis = flipoff(ars_longa_vita_brevis, 5, 10); break; case 7: ars_longa_vita_brevis = flipoff(ars_longa_vita_brevis, 11, 15); break; case 8: ars_longa_vita_brevis = flipoff(ars_longa_vita_brevis, 0, 4); break; case 9: printf("\nExiting program...\n"); break; default: printf("\nAlas, thine entry is 'bunk'...\n"); break; } /* END SWITCH!! */ } /* END WHILE!! */ return 0; } /* END MAIN!! */ /* === MAIN ========================================================= */ /* === FUNCTION DEFINITIONS ========================================= */ unsigned short flipon(unsigned short dies_irae, int foo, int bar) { return dies_irae | (~((unsigned short) ~0 << ((bar-foo)+1)) << foo); } unsigned short flipoff(unsigned short lux_aeterna, int foo, int bar) { return lux_aeterna & ~(~((unsigned short) ~0 << ((bar-foo)+1)) << foo); } void status(unsigned short lacrimosa) { int cui_peccare_licet_peccat_minus; unsigned short tub_mirum; for( cui_peccare_licet_peccat_minus = 15; cui_peccare_licet_peccat_minus >= 0; cui_peccare_licet_peccat_minus--) { tub_mirum = lacrimosa >> cui_peccare_licet_peccat_minus; tub_mirum &= 1; printf("%1d", tub_mirum); } /* END FOR */ } /* === FUNCTION DEFINITIONS ========================================= */ /* --- end code --- */