wmail: added new ChangeLog.
[dockapps.git] / wmget / list.c
blobbfa4dce0e648ce80610cb255aea4d701425565c1
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 list.c - Client code for retrieving the current job list
27 When invoked with the ``list'' argument, main() calls list(),
28 defined below. This code sends a LIST command to the server and
29 dumps the returned list to stdout.
32 #include <stdio.h>
33 #include <string.h>
34 #include <stdlib.h>
36 #include "wmget.h"
38 int list (int argc, char **argv)
40 char line[MAXCMDLEN + 1];
41 char *word_break;
42 FILE *fp;
44 /* No additional options or arguments.
46 if (argc > 2) {
47 error ("Extra arguments: list takes none");
48 return 1;
51 (void)argv;
53 if (!(fp = iq_client_connect ()))
54 return 1;
56 if (fprintf (fp, "LIST\r\n") == EOF) {
57 error_sys ("Could not submit command to server");
58 fclose (fp);
59 return 1;
62 if (!fgets (line, sizeof line - 1, fp)) {
63 error ("Server did not respond to command!");
64 fclose (fp);
65 return 1;
68 /* Extract the first word and compare. */
69 word_break = line + strcspn (line, " \t\r\n");
71 if (*word_break)
72 *word_break++ = 0;
74 if (strcasecmp (line, RESPONSE_LIST_COMING)) {
75 error ("Server responded with error: %s", word_break);
76 fclose (fp);
77 return 1;
80 while (fgets (line, sizeof line - 1, fp)) {
81 fputs (line, stdout);
84 fclose (fp);
86 return 0;