Exemple #1
0
int addTask(char *args[], int optind){
	/*This function does the following:
	 -open up the .tigger file
	 -write the task to the .tigger file
	 -close the .tigger file
	 */
	if(!tiggerExists(args)){
		return 0;
	}
	if(args[optind]){
		if(strlen(args[optind]) < 255){
			FILE *file = fopen(".tigger", "a+");
			fprintf(file, "%s", args[optind]);
			fprintf(file, "\n");
			fclose(file);
                        if (COLOR_FLAG) {
			        fprintf_white(stdout, "Just added new task to tigger.\n");
			        fprintf_green(stdout, args[optind]);
			        printf("\n");
			        return 1;
                        } else {
                                printf("Just added new task to tigger.\n");
			        printf("%s", args[optind]);
			        printf("\n");
			        return 1;
                        }
		}else{
                        if (COLOR_FLAG) {
                                fprintf_red(stdout, "Sorry you must enter a description that is less than 255 characters long.\n");
			        return 0;
                        } else {
			        printf("Sorry you must enter a description that is less than 255 characters long.\n");
			        return 0;
                        }
		}

	}else{
		printUsage();
		return 0;
	}
}
Exemple #2
0
int main (int argc, char * argv[]) {
	loadCommands();

        /* option parsing */
        int c = 0;
        int option_index = 0;

        while ((c = getopt_long(argc, argv, "cf", long_options, &option_index)) != -1)
        {
                switch (c)
                {
                        case 0: /* longopt detected */
                                break;
                        case 'c': /* short option, color enabled */
                                COLOR_FLAG = 1;
                                break;
                        case 'f':
                                FORCE_FLAG = 1;
                                break;
                        default:
                                fprintf(stdout, "Unknown option code %d\n", c);
                                printUsage();
                                return EXIT_FAILURE;
                }
        }

        /* argument loop */
	if(optind < argc && argv[optind] && isCommand(argv[optind])){
		//then we want to process the command
		if (!processCommand(argv, optind)){
			if (COLOR_FLAG)
                                fprintf_red(stdout, "Your command was not processed.\n");
                        else
                                printf("Your command was not processed.\n");
		}
	}else{
		printUsage();
	}
    return 0;
}
Exemple #3
0
int completedTasks(){
	/*This function does the following:
	 -open up the .tigger_completed file
	 -print out all of the tasks in the .tigger_completed file
	 -close the .tigger_completed file
	 */
	char line[255];
	int count = 0; 
	char * delim = "<?TIG?>";
	char * found;   
	size_t index;  
	char *new_string;
	if(!tiggerExists()){
		return 0;
	}
	FILE *file = fopen(".tigger_completed", "rt");
	if (COLOR_FLAG)
                fprintf_white(stdout, "\nLoading completed tasks from tigger...\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
        else
                printf("\nLoading completed tasks from tigger...\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
	while(fgets(line, 255, file) != NULL){
		if(!protectedText(line)){
			count += 1;    
			found = strstr(line, delim);
			if(found != NULL){
				index = found - line;
			}  
			new_string = &line[index+7];
			if (COLOR_FLAG) {
                                fprintf_yellow(stdout, "Task ");
                                fprintf(stdout, "%d", count);
                                fprintf_yellow(stdout, ": \n");
			        fprintf_green(stdout, trimwhitespace(new_string));
			        printf("\n");
                        } else {
                                printf("Task %d: \n", count);
			        printf("%s",trimwhitespace(new_string));
			        printf("\n");
                        }

		}
	}
	if (count > 0){
                if (COLOR_FLAG) {
		        fprintf_blue(stdout, "You have completed ");
                        fprintf(stdout, "%d", count);
                        fprintf_blue(stdout, " tasks. Congrats!\n");
		        fprintf_white(stdout, "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
                } else {
		        printf("You have completed %d tasks. Congrats!\n", count);
		        printf("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
                }

	}else{
		if (COLOR_FLAG)
                        fprintf_red(stdout, "You haven't completed any tasks and are lazy. That is all.\n");
                else
                        printf("You haven't completed any tasks and are lazy. That is all.\n");
	}
	fclose(file);
	return 1;

}