summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <arch@njw.me.uk>2007-03-05 23:42:31 +0000
committerNick White <arch@njw.me.uk>2007-03-05 23:42:31 +0000
commit38d38ea919c6a2e3faeaee0b036607259f7a428c (patch)
tree7d7cef3d1f1c4768e4c4873d5fa31f143d4f4167
parent9548ce6885325c0772cf3d83ad40076844d4d846 (diff)
Add long option support
Added long option support using getopt_long Separated usage to separate function git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-5
-rw-r--r--TODO7
-rw-r--r--getht.c47
2 files changed, 39 insertions, 15 deletions
diff --git a/TODO b/TODO
index 34a1460..b8dffc3 100644
--- a/TODO
+++ b/TODO
@@ -8,7 +8,10 @@ post a screenshot?
-immediate term-
-add long options
+if download fails, remove attempted file
+if -uf is passed, download & parse media regardless (check that same isn't added multiple times)
+
+handle ctrl-c by removing half-downloaded file
save entered directories to config file
@@ -36,7 +39,7 @@ handle smil files successfully
if no required contents file exists, attempt to retrieve it, even if update is not passed
comment source - at least all functions
-use autotools
+#use autotools
integrate gettext
add options to allow decent listing of issues
diff --git a/getht.c b/getht.c
index 57d44c3..0087743 100644
--- a/getht.c
+++ b/getht.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <getopt.h>
#include <string.h>
#include <sys/stat.h>
#include <curl/curl.h>
@@ -36,6 +37,8 @@ void show_med_struct(med * issue);
void clearmed(med * cur_media);
void cleariss(iss * cur_issue);
+void showusage();
+
med * findnewestmed(iss ** issue, int no_of_issues);
proxytype proxy_type; char proxy_addr[STR_MAX]; long proxy_port;
@@ -93,7 +96,20 @@ int main(int argc, char *argv[])
/* Parse command line options */
char c;
- while((c = getopt(argc, argv, "adfhmnsuvxt:")) != -1) {
+ static struct option long_opts[] =
+ {
+ {"download-all", no_argument, 0, 'a'},
+ {"download-latest", no_argument, 0, 'd'},
+ {"download-all-media", no_argument, 0, 'm'},
+ {"download-latest-media", no_argument, 0, 'n'},
+ {"force", no_argument, 0, 'f'},
+ {"update", no_argument, 0, 'u'},
+ {"tocfile", required_argument, 0, 't'},
+ {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+ };
+ while((c = getopt_long(argc, argv, "adfhmnsuvxt:", long_opts, NULL)) != -1) {
switch(c) {
case 'a':
downall = 1;
@@ -124,18 +140,7 @@ int main(int argc, char *argv[])
strcpy(issue_xml, strdup(optarg));
break;
case 'h':
- printf("Usage: getht -am dn -f [-t tocfile] -u -hv\n");
- printf("-a Download all issues\n");
- printf("-d Download latest issue\n");
- printf("-m Download all media\n");
- printf("-n Download latest issue's media\n");
- printf("-f Force redownloading of existent issues\n");
- printf("-u Download new contents files\n");
- printf("-t file Use alternative contents xml file\n");
- printf("-h Print this help message\n");
- printf("-v Print version information\n");
- printf(" ---DEBUGGING--\n");
- printf("-s Print structure information\n");
+ showusage();
return 0;
break;
case 'v':
@@ -389,3 +394,19 @@ int findnewestiss(iss ** issue, int no_of_issues)
return new_iss;
}
+
+void showusage()
+{
+ printf("Usage: getht -u -a -d -m -n -f [-t tocfile] -h -v\n");
+ printf("-a | --download-all Download all issues\n");
+ printf("-d | --download-latest Download latest issue\n");
+ printf("-m | --download-all-media Download all media\n");
+ printf("-n | --download-latest-media Download latest issue's media\n");
+ printf("-f | --force Force redownloading of existent issues\n");
+ printf("-u | --update Update contents files\n");
+ printf("-t | --tocfile file Use alternative contents xml file\n");
+ printf("-h | --help Print this help message\n");
+ printf("-v | --version Print version information\n");
+ printf(" ---DEBUGGING--\n");
+ printf("-s Print structure information\n");
+}