1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2001-2008, 2011, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18
19 #include <common/ac/stdio.h>
20 #include <common/ac/stdlib.h>
21
22 #include <common/progname.h>
23 #include <common/quit.h>
24 #include <common/sizeof.h>
25 #include <common/trace.h>
26 #include <libaegis/ael/project/aliases.h>
27 #include <libaegis/arglex/project.h>
28 #include <libaegis/arglex2.h>
29 #include <libaegis/change/identifier.h>
30 #include <libaegis/commit.h>
31 #include <libaegis/gonzo.h>
32 #include <libaegis/gonzo.h>
33 #include <libaegis/help.h>
34 #include <libaegis/lock.h>
35 #include <libaegis/project.h>
36 #include <libaegis/project/history.h>
37 #include <libaegis/sub.h>
38 #include <libaegis/user.h>
39
40 #include <aegis/aerpa.h>
41
42
43 static void
project_alias_remove_usage(void)44 project_alias_remove_usage(void)
45 {
46 const char *progname;
47
48 progname = progname_get();
49 fprintf
50 (
51 stderr,
52 "usage: %s -Remove_Project_Alias [ <option>... ]\n",
53 progname
54 );
55 fprintf
56 (
57 stderr,
58 " %s -Remove_Project_Alias -List [ <option>... ]\n",
59 progname
60 );
61 fprintf(stderr, " %s -Remove_Project_Alias -Help\n", progname);
62 quit(1);
63 }
64
65
66 static void
project_alias_remove_help(void)67 project_alias_remove_help(void)
68 {
69 help("aerpa", project_alias_remove_usage);
70 }
71
72
73 static void
project_alias_remove_list(void)74 project_alias_remove_list(void)
75 {
76 arglex();
77 change_identifier cid;
78 cid.command_line_parse_rest(project_alias_remove_usage);
79 list_project_aliases(cid, 0);
80 }
81
82
83 static void
project_alias_remove_main(void)84 project_alias_remove_main(void)
85 {
86 string_ty *project_name;
87 project *pp;
88 user_ty::pointer up;
89 sub_context_ty *scp;
90
91 trace(("project_alias_remove_main()\n{\n"));
92 arglex();
93 project_name = 0;
94 while (arglex_token != arglex_token_eoln)
95 {
96 switch (arglex_token)
97 {
98 default:
99 generic_argument(project_alias_remove_usage);
100 continue;
101
102 case arglex_token_keep:
103 case arglex_token_interactive:
104 case arglex_token_keep_not:
105 user_ty::delete_file_argument(project_alias_remove_usage);
106 break;
107
108 case arglex_token_project:
109 arglex();
110 // fall through...
111
112 case arglex_token_string:
113 arglex_parse_project(&project_name, project_alias_remove_usage);
114 continue;
115
116 case arglex_token_wait:
117 case arglex_token_wait_not:
118 user_ty::lock_wait_argument(project_alias_remove_usage);
119 break;
120 }
121 arglex();
122 }
123
124 //
125 // locate project data
126 //
127 if (!project_name)
128 {
129 error_intl(0, i18n("no project name"));
130 project_alias_remove_usage();
131 }
132 pp = project_alloc(project_name);
133 pp->bind_existing();
134
135 //
136 // locate user data
137 //
138 up = user_ty::create();
139
140 //
141 // make sure it's an alias
142 //
143 if (!gonzo_alias_to_actual(project_name))
144 {
145 scp = sub_context_new();
146 sub_var_set_string(scp, "Name", project_name);
147 project_fatal(pp, scp, i18n("project alias $name exists not"));
148 // NOTREACHED
149 }
150
151 //
152 // lock gstate
153 //
154 gonzo_gstate_lock_prepare_new();
155 lock_take();
156
157 //
158 // it is an error if the current user is not an administrator
159 //
160 if (!project_administrator_query(pp, up->name()))
161 project_fatal(pp, 0, i18n("not an administrator"));
162
163 //
164 // remove the project alias
165 //
166 gonzo_alias_delete(project_name);
167 gonzo_gstate_write();
168
169 //
170 // release the locks
171 //
172 commit();
173 lock_release();
174
175 //
176 // verbose success message
177 //
178 scp = sub_context_new();
179 sub_var_set_string(scp, "Name", project_name);
180 project_verbose(pp, scp, i18n("remove project alias $name complete"));
181 sub_context_delete(scp);
182
183 //
184 // clean up and go home
185 //
186 project_free(pp);
187 str_free(project_name);
188 trace(("}\n"));
189 }
190
191
192 void
project_alias_remove(void)193 project_alias_remove(void)
194 {
195 static arglex_dispatch_ty dispatch[] =
196 {
197 { arglex_token_help, project_alias_remove_help, 0 },
198 { arglex_token_list, project_alias_remove_list, 0 },
199 };
200
201 trace(("project_alias_remove()\n{\n"));
202 arglex_dispatch(dispatch, SIZEOF(dispatch), project_alias_remove_main);
203 trace(("}\n"));
204 }
205
206
207 // vim: set ts=8 sw=4 et :
208