1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
15 #include <fc_config.h>
19 #include "fc_cmdline.h"
25 #include "fc_cmdhelp.h"
31 #include "mpcmdline.h"
33 extern struct fcmp_params fcmp
;
35 /**************************************************************************
36 Parse commandline parameters. Modified argv[] so it contains only
37 ui-specific options afterwards. Number of those ui-specific options is
39 Currently this is implemented in a way that it never fails. Either it
40 returns with success or exit()s. Implementation can be changed so that
41 this returns with value -1 in case program should be shut down instead
42 of exiting itself. Callers are prepared for such implementation.
43 This call initialises the log system.
44 **************************************************************************/
45 int fcmp_parse_cmdline(int argc
, char *argv
[])
48 bool ui_separator
= FALSE
;
51 enum log_level loglevel
= LOG_NORMAL
;
55 argv
[1 + ui_options
] = argv
[i
];
57 } else if (is_option("--help", argv
[i
])) {
58 struct cmdhelp
*help
= cmdhelp_new(argv
[0]);
60 cmdhelp_add(help
, "h", "help",
61 _("Print a summary of the options"));
62 cmdhelp_add(help
, "L",
63 /* TRANS: "List" is exactly what user must type, do not translate. */
65 _("Load modpack list from given URL"));
66 cmdhelp_add(help
, "p",
67 /* TRANS: "prefix" is exactly what user must type, do not translate. */
69 _("Install modpacks to given directory hierarchy"));
70 cmdhelp_add(help
, "i",
71 /* TRANS: "install" is exactly what user must type, do not translate. */
73 _("Automatically install modpack from a given URL"));
75 cmdhelp_add(help
, "d",
76 /* TRANS: "debug" is exactly what user must type, do not translate. */
78 _("Set debug log level (%d to %d, or "
79 "%d:file1,min,max:...)"), LOG_FATAL
, LOG_DEBUG
,
81 #else /* FREECIV_DEBUG */
82 cmdhelp_add(help
, "d",
83 /* TRANS: "debug" is exactly what user must type, do not translate. */
85 _("Set debug log level (%d to %d)"),
86 LOG_FATAL
, LOG_VERBOSE
);
87 #endif /* FREECIV_DEBUG */
88 cmdhelp_add(help
, "v", "version",
89 _("Print the version number"));
90 /* The function below prints a header and footer for the options.
91 * Furthermore, the options are sorted. */
92 cmdhelp_display(help
, TRUE
, TRUE
, TRUE
);
93 cmdhelp_destroy(help
);
96 } else if ((option
= get_option_malloc("--List", argv
, &i
, argc
, TRUE
))) {
97 fcmp
.list_url
= option
;
98 } else if ((option
= get_option_malloc("--prefix", argv
, &i
, argc
, TRUE
))) {
99 fcmp
.inst_prefix
= option
;
100 } else if ((option
= get_option_malloc("--install", argv
, &i
, argc
, TRUE
))) {
101 fcmp
.autoinstall
= option
;
102 } else if ((option
= get_option_malloc("--debug", argv
, &i
, argc
, FALSE
))) {
103 if (!log_parse_level_str(option
, &loglevel
)) {
105 _("Invalid debug level \"%s\" specified with --debug "
106 "option.\n"), option
);
107 fc_fprintf(stderr
, _("Try using --help.\n"));
111 } else if (is_option("--version", argv
[i
])) {
112 fc_fprintf(stderr
, "%s \n", freeciv_name_version());
115 } else if (is_option("--", argv
[i
])) {
118 fc_fprintf(stderr
, _("Unrecognized option: \"%s\"\n"), argv
[i
]);
125 log_init(NULL
, loglevel
, NULL
, NULL
, -1);
127 if (fcmp
.inst_prefix
== NULL
) {
128 const char *home
= user_home_dir();
131 log_error("Cannot determine user home directory");
133 static char pfx_buf
[500];
135 snprintf(pfx_buf
, sizeof(pfx_buf
), "%s" DIR_SEPARATOR
".freeciv", home
);
136 fcmp
.inst_prefix
= pfx_buf
;