Beispiel #1
0
int main(int argc, char *argv[])
{
    int     i;
    char    line[1024], *uri;

    /* copy defaults */
    init_config();
    uri = &config.start_uri[0];

    /* parse command line */
    for (i = 1; i < argc; i++) {
        if (argv[i][0] == '-') switch(argv[i][1]) {
            case 'H':
                usage();
                break;
            case 'v':
                banner(stderr);
                exit(EXIT_FAILURE);
            default:
                usage();
        } else {
            uri = argv[i];
        }
    }

    /* parse uri */
    banner(stdout);
    if (! parse_uri(uri)) {
        banner(stderr);
        fprintf(stderr, "invalid gopher URI: %s", argv[i]);
        exit(EXIT_FAILURE);
    }

    /* main loop */
    view_directory(parsed_host, parsed_port, parsed_selector, 0);
    for (;;) {
        printf("\033[%sm%s:%s%s\033[0m ", config.color_prompt,
                current_host, current_port, current_selector);
        fflush(stdout); /* to display the prompt */
        if (! read_line(0, line, sizeof(line))) {
            puts("QUIT");
            return EXIT_SUCCESS;
        }
        i = strlen(line);
        switch (line[0]) {
            case '?':
                puts(
                    "?          - help\n"
                    "*          - reload directory\n"
                    "<          - go back in history\n"
                    ".LINK      - download the given link\n"
                    "h          - show history\n"
                    "hLINK      - jump to the specified history item\n"
                    "gURI       - jump to the given gopher URI\n"
                    "b          - show bookmarks\n"
                    "bLINK      - jump to the specified bookmark item\n"
                    "C^d        - quit");
                break;
            case '<':
                pop_history();
                break;
            case '*':
                view_directory(current_host, current_port,
                        current_selector, 0);
                break;
            case '.':
                download_link(make_key(line[1], line[2]));
                break;
            case 'h':
                if (i == 1 || i == 3) view_history(make_key(line[1], line[2]));
                else follow_link(make_key(line[0], line[1]));
                break;
            case 'g':
                if (i != 2) {
                    if (parse_uri(&line[1])) view_directory(parsed_host, parsed_port, parsed_selector, 1);
                    else puts("invalid gopher URI");
                } else follow_link(make_key(line[0], line[1]));
                break;
            case 'b':
                if (i == 1 || i == 3) view_bookmarks(make_key(line[1], line[2]));
                else follow_link(make_key(line[0], line[1]));
                break;
            default:
                follow_link(make_key(line[0], line[1]));
                break;
        }
    }
    return EXIT_SUCCESS; /* never get's here but stops cc complaining */
}
Beispiel #2
0
int main (int argc, char* argv[])
{
	int optc, optindex;
	short filter, pact, ppri, pday, pmonth, pyear, pfin;
	char padded[T_S_ADDED], pdue[T_S_DUE], pfinished[T_S_FINISHED], pproject[T_S_PROJECT], pdescription[T_S_DESCRIPTION];
	bask_core tcore;
	bask_theme btheme;
	bask_priority* bprioritys = NULL;
	bask_filter bfilter;
	struct bask_task* first = NULL;
	
	struct option long_options[] = {
		 {"help", no_argument, 0, B_CMD_ARG_HELP},
		 {"about", no_argument, 0, B_CMD_ARG_ABOUT},
		 {"day", required_argument, 0, B_CMD_ARG_DAY},
		 {"month", required_argument, 0, B_CMD_ARG_MONTH},
		 {"year", required_argument, 0, B_CMD_ARG_YEAR},
		 {"due", required_argument, 0, B_CMD_ARG_DUE},
		 {"today", no_argument, 0, B_CMD_ARG_TODAY},
		 {0,0,0,0}
	};
	
	optindex = filter = tcore.priority_min = tcore.priority_max = 0;
	ppri = pact = pday = pmonth = pyear = pfin = -1;
	
	strcpy (padded, "");
	strcpy (pdue, "");
	strcpy (pfinished, "");
	strcpy (pproject, "");
	strcpy (pdescription, "");
	
	strcpy (tcore.path_baskpath, secure_getenv("HOME"));
	
	if (tcore.path_baskpath == NULL || *tcore.path_baskpath == '\0')
	{
		errors_homedirnotgot ();
		exit (EXIT_FAILURE);
	}

	strcat (tcore.path_baskpath, "/.local/share/bask/");
	
	bask_get_baskpath (&tcore, tcore.path_baskconf, BASKCONFFILE);
	bask_get_baskpath (&tcore, tcore.path_basktheme, BASKTHEMEFILE);
	bask_get_baskpath (&tcore, tcore.path_baskbin, BASKBINFILE);
	
	config_init (&tcore);
	
	/* NOTE: These are cmd's that don't need the tasks data, so it wont be loaded. */
	if (argc <= 1)
	{
		usage ();
		exit (EXIT_FAILURE);
	}
	else if (argc == 2)
	{
		if (utils_streq (argv[optind], B_CMD_HELP) == 0)
		{
			print_help ();
			exit (EXIT_SUCCESS);
		}
		else if (utils_streq (argv[optind], B_CMD_ABOUT) == 0)
		{
			print_about ();
			exit (EXIT_SUCCESS);
		}
		else if (utils_streq (argv[optind], B_CMD_INIT) == 0)
		{
			bask_init_local (&tcore);
			exit (EXIT_SUCCESS);
		}
	}
	else if (argc == 3)
	{
		if (utils_streq (argv[optind], B_CMD_INIT) == 0)
		{
			if (utils_streq (argv[optind+1], B_CMD_BASKCONF) == 0)
			{
				/* Saving the default values and exit. */
				config_save (&tcore);
				exit (EXIT_SUCCESS);
			}
			else if (utils_streq (argv[optind+1], B_CMD_BASKBIN) == 0)
			{
				bask_init_baskbin (&tcore);
				exit (EXIT_SUCCESS);
			}
			else if (utils_streq (argv[optind+1], B_CMD_BASKTHEME) == 0)
			{
				bask_init_basktheme (&tcore);
				exit (EXIT_SUCCESS);
			}
		}
	}
	
	config_load (&tcore);
	ui_theme_load (&tcore, &btheme);
	
	/* Default Prioritys */
	priority_create (&tcore, &bprioritys, 0, btheme.color_normal, "L", "Normal");
	priority_create (&tcore, &bprioritys, 1, btheme.color_important, "I", "Important");
	priority_create (&tcore, &bprioritys, 2, btheme.color_today, "T", "Today");
	priority_create (&tcore, &bprioritys, 3, btheme.color_critical, "C", "Critical");
	
	while ((optc = getopt_long (argc, argv, "p:P:a:D:F:A:s:fh", long_options, &optindex)) != -1)
	{
		switch (optc)
		{
			case 'p':
				ppri = priority_get_idfromstr (&bprioritys, optarg);
				break;
			case 'P':
				if (strlen (optarg) < sizeof (pproject))
				{
					strcpy (pproject, optarg);
				}
				break;
			case 'a':
				if (utils_atos (&pact, optarg) == -2 || ISBOOL (pact) != TRUE)
				{
					errors_outofrange_int ("-a", FALSE, TRUE);
				}
				break;
			case 'D':
				if (strlen (optarg) < sizeof (pdescription))
				{
					strcpy (pdescription, optarg);
				}
				break;
			case 'F':
				time_get_str_described (pfinished, sizeof (pfinished), optarg);
				break;
			case 'A':
				time_get_str_described (padded, sizeof (padded), optarg);
				break;
			case 's':
				if (utils_atos (&pfin, optarg) == -2 || ISBOOL (pfin) != TRUE)
				{
					errors_outofrange_int ("-s", FALSE, TRUE);
				}
				break;
			case 'f':
				filter = TRUE;
				break;
			case B_CMD_ARG_HELP:
				print_help ();
				exit (EXIT_SUCCESS);
				break;
			case B_CMD_ARG_ABOUT:
				print_about ();
				exit (EXIT_SUCCESS);
				break;
			case B_CMD_ARG_DAY:
				if (utils_atos (&pday, optarg) == -2 || pday < 1 || pday > 31)
				{
					errors_outofrange_int ("--day", 1, 31);
				}
				break;
			case B_CMD_ARG_MONTH:
				if (utils_atos (&pmonth, optarg) == -2 || pmonth < 1 || pmonth > 12)
				{
					errors_outofrange_int ("--month", 1, 12);
				}
				break;
			case B_CMD_ARG_YEAR:
				if (utils_atos (&pyear, optarg) == -2)
				{
					errors_outofrange_int ("--year", SHRT_MIN, SHRT_MAX);
				}
				break;
			case B_CMD_ARG_DUE:
				time_get_str_described (pdue, sizeof (pdue), optarg);
				break;
			case B_CMD_ARG_TODAY:
				/* TODO: Improve this. */
				if (time_get_str (padded, sizeof (padded)) == 0)
				{
					pday = (short) time_get_day (padded);
					pmonth = (short) time_get_month (padded);
					pyear = (short) time_get_year (padded);
				}
				break;
			default:
				break;
		}
	}
	
	if (filter == TRUE)
	{
		filter_init (&bfilter, pact, pfin, ppri, pday, pmonth, pyear);
	}
	else
	{
		filter_init (&bfilter, TRUE, -1, -1, -1, -1, -1);
	}
	
	bask_init (&tcore, &first);
	
	if (optind > 1)
	{
		if (argc-optind == 1)
		{
			if (utils_streq (argv[optind], B_CMD_LIST) == 0)
			{
				view_tasklist (&tcore, &btheme, &bprioritys, &first, &bfilter);
			}
			else if (utils_streq (argv[optind], B_CMD_SUMMARY) == 0)
			{
				view_summary (&tcore, &btheme, &first, &bfilter);
			}
			else if (utils_streq (argv[optind], B_CMD_HISTORY) == 0)
			{
				view_history (&tcore, &btheme, &first, &bfilter);
			}
			else
			{
				usage ();
			}
		}
		else if (argc-optind == 2)
		{
			if (utils_streq (argv[optind], B_CMD_MOD) == 0)
			{
				task_modificate_cmd (&tcore, &first, atoi (argv[optind+1]), pact, -1, ppri, padded, pdue, pfinished, pproject, pdescription);
			}
			else if (utils_streq (argv[optind], B_CMD_SEARCH) == 0)
			{
				search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+1], BVIEW_TASKLIST);
			}
			else
			{
				usage ();
			}
		}
		else if (argc-optind == 3)
		{
			if (utils_streq (argv[optind], B_CMD_SEARCH) == 0)
			{
				if (utils_streq (argv[optind+1], B_CMD_TASKLIST) == 0)
				{
					search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_TASKLIST);
				}
				else if (utils_streq (argv[optind+1], B_CMD_SUMMARY) == 0)
				{
					search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_SUMMARY);
				}
				else if (utils_streq (argv[optind+1], B_CMD_DETAILED) == 0)
				{
					search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_DETAILED);
				}
				else
				{
					usage ();
				}
			}
		}
		else
		{
			usage ();
		}
	}
	else if (argc == 2)
	{
		if (utils_streq (argv[optind], B_CMD_LIST) == 0)
		{
			view_tasklist (&tcore, &btheme, &bprioritys, &first, &bfilter);
		}
		else if (utils_streq (argv[optind], B_CMD_SUMMARY) == 0)
		{
			view_summary (&tcore, &btheme, &first, &bfilter);
		}
		else if (utils_streq (argv[optind], B_CMD_HISTORY) == 0)
		{
			/* This allows History to use all tasks including the hidden ones. */
			filter_init (&bfilter, -1, -1, -1, -1, -1, -1);
			view_history (&tcore, &btheme, &first, &bfilter);
		}
		else
		{
			usage ();
		}
	}
	else if (argc == 3)
	{
		if (utils_streq (argv[optind], B_CMD_FINISH) == 0)
		{
			task_finish_cmd (&tcore, &first, atoi (argv[optind+1]));
		}
		else if (utils_streq (argv[optind], B_CMD_REMOVE) == 0)
		{
			task_remove_cmd (&tcore, &first, atoi (argv[optind+1]));
		}
		else if (utils_streq (argv[optind], B_CMD_SEARCH) == 0)
		{
			search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+1], BVIEW_TASKLIST);
		}
		else if (utils_streq (argv[optind], B_CMD_STOP) == 0)
		{
			task_deactivate_cmd (&tcore, &first, atoi (argv[optind+1]));
		}
		else if (utils_streq (argv[optind], B_CMD_SHOW) == 0)
		{
			view_single (&tcore, &first, &bfilter, atoi (argv[optind+1]), FALSE);
		}
		else if (utils_streq (argv[optind], B_CMD_EXPORT) == 0)
		{
			export_baskbin_cmd (&tcore, &first, argv[optind+1]);
		}
		else if (utils_streq (argv[optind], B_CMD_IMPORT) == 0)
		{
			import_baskbin_cmd (&tcore, &first, argv[optind+1]);
		}
		else if (utils_streq (argv[optind], B_CMD_CONFIG) == 0)
		{
			config_set_str_cmd (&tcore, argv[optind+1]);
		}
		else
		{
			usage ();
		}
	}
	else if (argc == 4)
	{
		if (utils_streq (argv[optind], B_CMD_SEARCH) == 0)
		{
			if (utils_streq (argv[optind+1], B_CMD_TASKLIST) == 0)
			{
				search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_TASKLIST);
			}
			else if (utils_streq (argv[optind+1], B_CMD_SUMMARY) == 0)
			{
				search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_SUMMARY);
			}
			else if (utils_streq (argv[optind+1], B_CMD_DETAILED) == 0)
			{
				search_view (&tcore, &btheme, &bprioritys, &bfilter, &first, argv[optind+2], BVIEW_DETAILED);
			}
			else
			{
				usage ();
			}
		}
		else if (utils_streq (argv[optind], B_CMD_EXPORT) == 0)
		{
			if (utils_streq (argv[optind+1], B_CMD_BASKBIN) == 0)
			{
				export_baskbin_cmd (&tcore, &first, argv[optind+2]);
			}
			else if (utils_streq (argv[optind+1], B_CMD_CSV) == 0)
			{
				export_csv_cmd (&tcore, &first, argv[optind+2]);
			}
			else if (utils_streq (argv[optind+1], B_CMD_ICAL) == 0)
			{
				export_ical_cmd (&tcore, &first, argv[optind+2]);
			}
			else if (utils_streq (argv[optind+1], B_CMD_WEB) == 0)
			{
				export_web (&tcore, &first, argv[optind+2]);
			}
			else
			{
				usage ();
			}
		}
		else if (utils_streq (argv[optind], B_CMD_IMPORT) == 0)
		{
			if (utils_streq (argv[optind+1], B_CMD_BASKBIN) == 0)
			{
				import_baskbin_cmd (&tcore, &first, argv[optind+2]);
			}
			else if (utils_streq (argv[optind+1], B_CMD_CSV) == 0)
			{
				import_csv_cmd (&tcore, &first, argv[optind+2]);
			}
			else if (utils_streq (argv[optind+1], B_CMD_ICAL) == 0)
			{
				import_ical_cmd (&tcore, &first, argv[optind+2]);
			}
			else
			{
				usage ();
			}
		}
		else if (utils_streq (argv[optind], B_CMD_DUE) == 0)
		{
			time_get_str_described (pdue, sizeof (pdue), argv[optind+2]);
			task_due_cmd (&tcore, &first, atoi (argv[optind+1]), pdue);
		}
		else
		{
			usage ();
		}
	}
	else if (argc == 5)
	{	
		if (utils_streq (argv[optind], B_CMD_ADD) == 0)
		{
			task_create_cmd (&tcore, &first, priority_get_idfromstr (&bprioritys, argv[optind+1]), argv[optind+2], argv[optind+3]);
		}
		else
		{
			usage ();
		}
	}
	else
	{
		usage ();
	}
	
	config_save (&tcore);
	bask_unload (&bprioritys, &first);
	return 0;
}