File: list.c

package info (click to toggle)
wmget 0.6.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 280 kB
  • ctags: 325
  • sloc: ansic: 2,344; xml: 450; makefile: 135; perl: 31; sh: 24
file content (89 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
    wmget - A background download manager as a Window Maker dock app
    Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>

    Permission is hereby granted, free of charge, to any person
    obtaining a copy of this software and associated documentation files
    (the "Software"), to deal in the Software without restriction,
    including without limitation the rights to use, copy, modify, merge,
    publish, distribute, sublicense, and/or sell copies of the Software,
    and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    ********************************************************************
    list.c - Client code for retrieving the current job list

    When invoked with the ``list'' argument, main() calls list(),
    defined below.  This code sends a LIST command to the server and
    dumps the returned list to stdout.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "wmget.h"

int list (int argc, char **argv)
{
    char line[MAXCMDLEN + 1];
    char *word_break;
    FILE *fp;

    /* No additional options or arguments.
     */
    if (argc > 2) {
        error ("Extra arguments: list takes none");
        return 1;
    }

    (void)argv;

    if (!(fp = iq_client_connect ()))
        return 1;

    if (fprintf (fp, "LIST\r\n") == EOF) {
        error_sys ("Could not submit command to server");
        fclose (fp);
        return 1;
    }

    if (!fgets (line, sizeof line - 1, fp)) {
        error ("Server did not respond to command!");
        fclose (fp);
        return 1;
    }

    /* Extract the first word and compare. */
    word_break = line + strcspn (line, " \t\r\n");

    if (*word_break)
        *word_break++ = 0;

    if (strcasecmp (line, RESPONSE_LIST_COMING)) {
        error ("Server responded with error: %s", word_break);
        fclose (fp);
        return 1;
    }

    while (fgets (line, sizeof line - 1, fp)) {
        fputs (line, stdout);
    }

    fclose (fp);

    return 0;
}