#include #include #include #include "pickfile.h" char *defaultPrompt[] = { "Choose a file:", "Select files:", "File name and place to save:" }; int fd_parse_options(int argc, char *argv[]) { int ch; char *pdir = 0; optind = 0; while((ch = getopt(argc, argv, "vhd:s:p:")) != -1) { switch(ch) { case 'v': version(stdout); exit(-1); case 'h': usage(stdout, argv[0]); exit(-1); case 'p': pickerPrompt = optarg; break; case 'd': pdir = optarg; pickerMode = pickerChooseOneMode; break; case 's': pickerName = optarg; pickerMode = pickerSaveMode; break; case '?': default: usage(stderr, argv[0]); exit(-1); } } if(!pdir) pdir = getenv("HOME"); if(!pdir) pdir = "/"; pickerDir = malloc(strlen(pdir) + 1); strcpy(pickerDir, pdir); if(!pickerFile) { pickerFile = malloc(strlen(pickerDir) + 2); strcpy(pickerFile, pickerDir); strcat(pickerFile, "."); } if(!pickerPrompt) pickerPrompt = defaultPrompt[pickerMode]; if(!pickerName) pickerName = "untitled"; } version(FILE *f) { fprintf(f, "yzPickFile version %s.\nCopyright Woodley Packard, 2003\n", VERSION_STRING); } usage(FILE *f, char *prog) { fprintf(f, "usage: %s [-v | -h] | [-d default_path] " "[-s default_save_name] [-p prompt]\n", prog); }