Support VERSION_REVTYPE git builds on cleanup_checkout.sh
[freeciv.git] / tools / mpcmdline.c
blobd2e6699b516a3a20426ea14c35de92c7b58f22e4
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)
6 any later version.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "fc_cmdline.h"
20 #include "fciconv.h"
21 #include "fcintl.h"
22 #include "support.h"
24 /* common */
25 #include "fc_cmdhelp.h"
26 #include "version.h"
28 /* modinst */
29 #include "modinst.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
38 returned.
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[])
47 int i = 1;
48 bool ui_separator = FALSE;
49 int ui_options = 0;
50 char *option = NULL;
51 enum log_level loglevel = LOG_NORMAL;
53 while (i < argc) {
54 if (ui_separator) {
55 argv[1 + ui_options] = argv[i];
56 ui_options++;
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. */
64 _("List URL"),
65 _("Load modpack list from given URL"));
66 cmdhelp_add(help, "p",
67 /* TRANS: "prefix" is exactly what user must type, do not translate. */
68 _("prefix DIR"),
69 _("Install modpacks to given directory hierarchy"));
70 cmdhelp_add(help, "i",
71 /* TRANS: "install" is exactly what user must type, do not translate. */
72 _("install URL"),
73 _("Automatically install modpack from a given URL"));
74 #ifdef FREECIV_DEBUG
75 cmdhelp_add(help, "d",
76 /* TRANS: "debug" is exactly what user must type, do not translate. */
77 _("debug NUM"),
78 _("Set debug log level (%d to %d, or "
79 "%d:file1,min,max:...)"), LOG_FATAL, LOG_DEBUG,
80 LOG_DEBUG);
81 #else /* FREECIV_DEBUG */
82 cmdhelp_add(help, "d",
83 /* TRANS: "debug" is exactly what user must type, do not translate. */
84 _("debug NUM"),
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);
95 exit(EXIT_SUCCESS);
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)) {
104 fc_fprintf(stderr,
105 _("Invalid debug level \"%s\" specified with --debug "
106 "option.\n"), option);
107 fc_fprintf(stderr, _("Try using --help.\n"));
108 exit(EXIT_FAILURE);
110 free(option);
111 } else if (is_option("--version", argv[i])) {
112 fc_fprintf(stderr, "%s \n", freeciv_name_version());
114 exit(EXIT_SUCCESS);
115 } else if (is_option("--", argv[i])) {
116 ui_separator = TRUE;
117 } else {
118 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
119 exit(EXIT_FAILURE);
122 i++;
125 log_init(NULL, loglevel, NULL, NULL, -1);
127 if (fcmp.inst_prefix == NULL) {
128 const char *home = user_home_dir();
130 if (home == NULL) {
131 log_error("Cannot determine user home directory");
132 } else {
133 static char pfx_buf[500];
135 snprintf(pfx_buf, sizeof(pfx_buf), "%s" DIR_SEPARATOR ".freeciv", home);
136 fcmp.inst_prefix = pfx_buf;
140 return ui_options;