]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - quota/init.c
xfsprogs: simplify internal includes
[thirdparty/xfsprogs-dev.git] / quota / init.c
CommitLineData
5aead01d 1/*
da23017d
NS
2 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5aead01d 4 *
da23017d
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
5aead01d
NS
7 * published by the Free Software Foundation.
8 *
da23017d
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
5aead01d 13 *
da23017d
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5aead01d
NS
17 */
18
6b803e5a
CH
19#include "path.h"
20#include "command.h"
21#include "input.h"
5aead01d
NS
22#include "init.h"
23
24char *progname;
25int exitcode;
26int expert;
27
28static char **projopts; /* table of project names (cmdline) */
29static int nprojopts; /* number of entries in name table. */
30
31static void
32add_project_opt(
33 char *optarg)
34{
35 nprojopts++;
36 projopts = realloc(projopts, sizeof(char*) * nprojopts);
37 if (!projopts) {
38 perror("realloc");
39 exit(1);
40 }
41 projopts[nprojopts - 1] = optarg;
42}
43
44static void
45usage(void)
46{
47 fprintf(stderr,
30626ef6 48 _("Usage: %s [-V] [-x] [-p prog] [-c cmd]... [-d project]... [path]\n"),
5aead01d
NS
49 progname);
50 exit(1);
51}
52
53void
54init_cvtnum(
cb7ba2b0
CH
55 unsigned int *blocksize,
56 unsigned int *sectsize)
5aead01d
NS
57{
58 *blocksize = 4096;
59 *sectsize = 512;
60}
61
62static void
63init_commands(void)
64{
65 edit_init();
66 free_init();
67 help_init();
68 path_init();
69 project_init();
70 quot_init();
71 quota_init();
72 quit_init();
73 report_init();
74 state_init();
75}
76
77static int
78init_args_command(
79 int index)
80{
81 if (index >= fs_count)
82 return 0;
83
84 do {
85 fs_path = &fs_table[index++];
86 } while ((fs_path->fs_flags & FS_PROJECT_PATH) && index < fs_count);
87
fa13a00f
NS
88 if (fs_path->fs_flags & FS_PROJECT_PATH)
89 return 0;
5aead01d
NS
90 if (index > fs_count)
91 return 0;
92 return index;
93}
94
95static void
96init(
97 int argc,
98 char **argv)
99{
100 int c;
101
102 progname = basename(argv[0]);
103 setlocale(LC_ALL, "");
104 bindtextdomain(PACKAGE, LOCALEDIR);
105 textdomain(PACKAGE);
106
107 while ((c = getopt(argc, argv, "c:d:D:P:p:t:xV")) != EOF) {
108 switch (c) {
109 case 'c': /* commands */
110 add_user_command(optarg);
111 break;
112 case 'd':
113 add_project_opt(optarg);
114 break;
115 case 't':
116 mtab_file = optarg;
117 break;
118 case 'D':
119 projects_file = optarg;
120 break;
121 case 'P':
122 projid_file = optarg;
123 break;
124 case 'p':
125 progname = optarg;
126 break;
127 case 'x':
128 expert++;
129 break;
130 case 'V':
131 printf(_("%s version %s\n"), progname, VERSION);
132 exit(0);
133 default:
134 usage();
135 }
136 }
137
0900efe4
AE
138 fs_table_initialise(argc - optind, &argv[optind], nprojopts, projopts);
139 free(projopts);
5aead01d
NS
140
141 init_commands();
142 add_args_command(init_args_command);
36298cce
DC
143
144 /*
145 * Ensure that global commands don't end up with an invalid path pointer
146 * by setting the default device at the first specified on the CLI
147 */
148 if (argc != optind)
149 fs_path = fs_table_lookup(argv[optind], FS_MOUNT_POINT);
150 else
151 fs_path = &fs_table[0];
5aead01d
NS
152}
153
154int
155main(
156 int argc,
157 char **argv)
158{
159 init(argc, argv);
160 command_loop();
161 return exitcode;
162}