1 /* Command line parsing.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Wget. If not, see <http://www.gnu.org/licenses/>.
24 /* Final exit code possibilities. Exit codes 1 and 2 are reserved
25 * for situations that lead to direct exits from Wget, not using the
26 * value of final_exit_status. */
29 WGET_EXIT_SUCCESS = 0,
31 WGET_EXIT_MINIMUM = 3,
32 WGET_EXIT_IO_FAIL = WGET_EXIT_MINIMUM,
33 WGET_EXIT_NETWORK_FAIL = 4,
34 WGET_EXIT_SSL_AUTH_FAIL = 5,
35 WGET_EXIT_SERVER_AUTH_FAIL = 6,
36 WGET_EXIT_PROTOCOL_ERROR = 7,
37 WGET_EXIT_SERVER_ERROR = 8,
42 static int final_exit_status = WGET_EXIT_SUCCESS;
44 /* XXX: I don't like that newly-added uerr_t codes will doubtless fall
45 through the craccks, or the fact that we seem to have way more
46 codes than we know what to do with. Need to go through and sort
47 through the truly essential codes, and merge the rest with
48 those. Quite a few are never even used!
50 Quite a few of the codes below would have no business being
51 returned to retrieve_url's caller, but since it's very difficult to
52 determine which do and which don't, I grab virtually all of them to
55 get_status_for_err (uerr_t err)
60 return WGET_EXIT_SUCCESS;
61 case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
62 return WGET_EXIT_IO_FAIL;
63 case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR:
64 case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV:
65 case READERR: case TRYLIMEXC:
66 return WGET_EXIT_NETWORK_FAIL;
68 return WGET_EXIT_SSL_AUTH_FAIL;
69 case FTPLOGINC: case FTPLOGREFUSED: case AUTHFAILED:
70 return WGET_EXIT_SERVER_AUTH_FAIL;
72 return WGET_EXIT_PROTOCOL_ERROR;
73 case WRONGCODE: case FTPPORTERR: case FTPSYSERR:
74 case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR:
75 case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV:
76 case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN:
78 return WGET_EXIT_SERVER_ERROR;
79 case URLERROR: case QUOTEXC: case SSLINITFAILED:
81 return WGET_EXIT_UNKNOWN;
87 * Ensure that Wget's exit status will reflect the problem indicated
88 * by ERR, unless the exit status has already been set to reflect a more
89 * important problem. */
91 inform_exit_status (uerr_t err)
93 int new_status = get_status_for_err (err);
95 if (new_status != WGET_EXIT_SUCCESS
96 && (final_exit_status == WGET_EXIT_SUCCESS
97 || new_status < final_exit_status))
99 final_exit_status = new_status;
104 get_exit_status (void)
107 (final_exit_status == WGET_EXIT_UNKNOWN)