int main(int argc, char* argv[])
{
    struct nbd_handle* handle;
   
    if (argc < 9)
    {
        fprintf_light_red(stderr, USAGE, argv[0]);
        exit(EXIT_FAILURE);
    }

    fprintf_blue(stdout, "nbd-queuer-test program by: Wolfgang Richter "
                         "<*****@*****.**>\n");

    handle = nbd_init_redis(argv[1], argv[2], atoi(argv[3]), atoi(argv[4]),
                            atoll(argv[5]), argv[6], argv[7],
                            (strncmp(argv[8], "y", 1) == 0) ||
                            (strncmp(argv[8], "Y", 1) == 0));

    assert(handle != NULL);
    assert(handle->fd != 0);
    assert(strncmp(argv[1], handle->export_name, strlen(argv[1])) == 0);
    assert(handle->eb != NULL);
    assert(handle->conn != NULL);
    assert(handle->size >= 0);

    /* special case allow for example /dev/null to appear as a large file */
    if (handle->size == 0) handle->size = 1024*1024*1024*1024LL;
    
    nbd_run_loop(handle);
    nbd_shutdown(handle);

    fprintf_green(stdout, "-- Shutting down --\n");
    return EXIT_SUCCESS;
}
Exemple #2
0
int listTasks(){
	/*This function does the following:
	 -open up the .tigger file
	 -print out all of the tasks in the .tigger file
	 -close the .tigger file
	 */
	char line[255];
	int count = 0;
	if(!tiggerExists()){
		return 0;
	}
	FILE *file = fopen(".tigger", "rt");
	if (COLOR_FLAG)
                fprintf_white(stdout, "\nLoading tasks from tigger...\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
        else
                printf("\nLoading tasks from tigger...\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
	while(fgets(line, 255, file) != NULL){
		if(!protectedText(line)){
			count += 1;
                        if (COLOR_FLAG) {
                                fprintf_yellow(stdout, "Task ");
        		        fprintf(stdout, "%d", count);
                                fprintf_yellow(stdout, ": \n");
		                fprintf_green(stdout, trimwhitespace(line));
                        } else {
			        printf("Task %d: \n", count);
			        printf("%s", trimwhitespace(line));
                        }
			printf("\n");

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

	}else{
		if (COLOR_FLAG)
                        fprintf_blue(stdout, "Yay! You have no tasks remaining. Go have a beer.\n");
                else 
                        printf("Yay! You have no tasks remaining. Go have a beer.\n");
	}
	fclose(file);
	return 1;
}    
Exemple #3
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 #4
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;

}