#include #include #include #include /* Written by Wyatt Carss on July 5th, 2010 around 12:50 PM * * Updated rather substantially on September 1st at 1:45 AM! * * Just a timer program; planning to use it to break my time into 25 minute * chunks, with 5 minute breaks. Every 4 of these (2 hours), take a longer * break and return to work. New use: this wakes me up every morning. :) * * no longer uses usleep; uses windows "Sleep" instead. Because windows doesn't * have a working implementation of usleep. :/ * * after running, it gives you the opportunity to start the program over. * * Supports 4 methods of calling: * * C:\Users\wcarss\timer.exe * C:\Users\wcarss\timer.exe h m s * C:\Users\wcarss\timer.exe h m s filename * C:\Users\wcarss\timer.exe filename * * In each case, the program will ask you for whatever information you didn't * provide. Units will break things - it takes space separated integer values * for hours, minutes, and seconds. * * Additionally, (unfortunately) the command-line filename input seems to be * broken :/ * * Something is weird about the way Windows uses quotes in command lines - or * perhaps it's just VLC. It'll take some more testing and tinkering. For now, * just input your filepath at the program prompt and only specify times as * arguments. * * * Typical usage: * * C:\Uses\wcarss\timer.exe * Timer! * * Enter how many hours you'd like the timer to run for. * 0 * Enter how many minutes you'd like the timer to run for. * 0 * Enter how many seconds you'd like the timer to run for. * 1 * What song would you like to play? * C:\Users\wcarss\Desktop\01 The Suburbs.mp3 * All done! Total time elapsed: 0 hours, 0 minutes, 1 seconds. * Run again? * y * Use last settings? * y * All done! Total time elapsed: 0 hours, 0 minutes, 1 seconds. * Run again? * y * Use last settings? * n * Timer! * * Enter how many hours you'd like the timer to run for. * 0 * Enter how many minutes you'd like the timer to run for. * 0 * Enter how many seconds you'd like the timer to run for. * 2 * What song would you like to play? * C:\Users\wcarss\Desktop\01 The Suburbs.mp3 * All done! Total time elapsed: 0 hours, 0 minutes, 2 seconds. * */ int main(int argc, char *argv[]) { int hours = 0, minutes = 0, seconds = 0; char run[10], buf[10], command[1024], filename[1024]; strcpy(run, "f"); /* Order of 'run' values: * * f f f f f - start * n y y y y - go again * n y n y - use last settings * n n y y - go again * . . * . . * . . * * During the first run of the program, run is "f". * On a second run of through program, run will be set * to "y", then for 'use last settings' to "y" or "n". * At termination of the program, it will be "n". */ printf("Timer!\n\n"); do { if(strcmp(run, "y") == 0) { printf("Use last settings?\n"); fgets(run, 9, stdin); run[strlen(run) - 1] = '\0'; if((strcmp(run, "yes") && strcmp(run, "Yes") && strcmp(run, "Y")) == 0) { strcpy(run, "y"); } } /* if run is not "y" here, this is the first time the program was run or the user chose not to use the settings from last time */ if(strcmp(run, "y") != 0) { strcpy(command, "\"\"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe\" \""); if((strcmp(run, "f") == 0) && (argc == 4 || argc == 5)) { sscanf(argv[1], "%d", &hours); sscanf(argv[2], "%d", &minutes); sscanf(argv[3], "%d", &seconds); } else { printf("Enter how many hours you'd like the timer to run for.\n"); fgets(buf, 10, stdin); sscanf(buf, "%d", &hours); printf("Enter how many minutes you'd like the timer to run for.\n"); fgets(buf, 10, stdin); sscanf(buf, "%d", &minutes); printf("Enter how many seconds you'd like the timer to run for.\n"); fgets(buf, 10, stdin); sscanf(buf, "%d", &seconds); } if(argc == 2 || argc == 5) { /* argc - 1 is 1 or 4, being the second or fifth arguments */ sscanf(argv[argc - 1], "%s", filename); } else { printf("What song would you like to play?\n"); fgets(filename, 1024, stdin); filename[strlen(filename)-1] = '\0'; } strcat(command, filename); strcat(command, "\"\""); } if(seconds + hours + minutes != 0) { Sleep(((hours * 60 * 60) + (minutes * 60) + seconds) * 1000); printf("All done! Total time elapsed: %d hours, %d minutes, %d seconds.\n", hours, minutes, seconds); system(command); } printf("Run again?\n"); fgets(run, 9, stdin); run[strlen(run) - 1] = '\0'; if((strcmp(run, "yes") && strcmp(run, "Yes") && strcmp(run, "Y")) == 0) { strcpy(run, "y"); } }while(strcmp(run, "y") == 0); return 0; }