wmail: renamed configure.in to configure.ac.
[dockapps.git] / wmget / wmget.c
blob16d3fc37a9bb150fb11e26a14b2510599659137e
1 /*
2 wmget - A background download manager as a Window Maker dock app
3 Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>
5 Permission is hereby granted, free of charge, to any person
6 obtaining a copy of this software and associated documentation files
7 (the "Software"), to deal in the Software without restriction,
8 including without limitation the rights to use, copy, modify, merge,
9 publish, distribute, sublicense, and/or sell copies of the Software,
10 and to permit persons to whom the Software is furnished to do so,
11 subject to the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ********************************************************************
25 wmget.c - main() and a few common functions
27 This file contains the main() for wmget; it simply checks for the
28 presence of ``dock'' as the first argument and invokes server(),
29 request(), cancel(), or list() as appropriate. Also found here are
30 a few global utilities.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <pwd.h>
37 #include <string.h>
38 #include <stdarg.h>
39 #include <errno.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
43 #include "wmget.h"
45 void debug_dump_job (Job *job)
47 if (output_level () < OL_DEBUG)
48 return;
50 debug ("id = %lu\n"
51 "status = %d\n"
52 "progress=%d/%d\n"
53 "stop_request=%d\n"
54 "display=[%s]\n"
55 "source_url=[%s]\n"
56 "save_to=[%s]\n"
57 "continue_from=%d\n\n",
58 job->job_id,
59 job->status, job->progress, job->stop_request,
60 job->prog_max, job->options.display, job->source_url,
61 job->options.save_to, job->options.continue_from);
65 const char *home_directory (void)
67 static char *home_directory = 0;
68 struct passwd *pwent;
70 if (home_directory)
71 return home_directory;
73 home_directory = getenv ("HOME");
75 if (!home_directory) {
76 pwent = getpwuid (geteuid ());
77 home_directory = strdup (pwent->pw_dir);
80 return home_directory;
84 int main (int argc, char **argv)
86 char **arg;
87 int (*function) (int, char **) = &request;
89 if (argc < 2) {
90 usage ();
91 return 0;
94 /* Cheat, because we don't invoke getopt until we know what mode
95 * we're in...
97 for (arg = argv; *arg; ++arg) {
98 if (strcmp (*arg, "dock") == 0) {
99 function = &server;
101 } else if (strcmp (*arg, "cancel") == 0) {
102 function = &cancel;
104 } else if (strcmp (*arg, "list") == 0) {
105 function = &list;
107 } else if (strcmp (*arg, "-v") == 0
108 || strcmp (*arg, "--version") == 0) {
109 puts (WMGET_VERSION_BANNER);
110 puts (WMGET_COPYRIGHT);
111 return 0;
113 } else if (strcmp (*arg, "-h") == 0
114 || strcmp (*arg, "--help") == 0) {
115 usage ();
116 return 0;
120 return function (argc, argv);