1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2001, 2003-2008, 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
7 // by the Free Software Foundation; either version 3 of the License, or
8 // (at 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/assert.h>
20
21 #include <common/str_list.h>
22 #include <common/trace.h>
23 #include <libaegis/ael/change/inappropriat.h>
24 #include <libaegis/ael/column_width.h>
25 #include <libaegis/ael/project/aliases.h>
26 #include <libaegis/change/identifier.h>
27 #include <libaegis/col.h>
28 #include <libaegis/gonzo.h>
29 #include <libaegis/option.h>
30 #include <libaegis/output.h>
31 #include <libaegis/project.h>
32
33
34 void
list_project_aliases(change_identifier & cid,string_list_ty *)35 list_project_aliases(change_identifier &cid, string_list_ty *)
36 {
37 string_list_ty name;
38 output::pointer name_col;
39 output::pointer desc_col;
40 col::pointer colp;
41 int nprinted = 0;
42
43 trace(("list_project_aliases()\n{\n"));
44 if (cid.set())
45 list_change_inappropriate();
46
47 //
48 // list the projects
49 //
50 gonzo_alias_list(&name);
51 name.sort();
52
53 //
54 // Find the longest name, and round it up so that the column is
55 // always one less than a multiple of eight (it makes for nice numbers
56 // of tabs).
57 //
58 size_t longest = PROJECT_WIDTH;
59 for (size_t k = 0; k < name.nstrings; ++k)
60 {
61 size_t x = name.string[k]->str_length;
62 if (longest < x)
63 longest = x;
64 }
65 longest |= 7;
66
67 //
68 // create the columns
69 //
70 colp = col::open((string_ty *)0);
71 colp->title("List of Project Aliases", (char *)0);
72
73 int left = 0;
74 name_col = colp->create(0, longest, "Alias\n---------");
75 left += longest + 1;
76
77 if (!option_terse_get())
78 {
79 desc_col =
80 colp->create(left, 0, "Project\n-----------");
81 }
82
83 //
84 // list each alias
85 //
86 nprinted = 0;
87 for (size_t j = 0; j < name.nstrings; ++j)
88 {
89 if (cid.project_set())
90 {
91 string_ty *other;
92
93 other = gonzo_alias_to_actual(name.string[j]);
94 assert(other);
95 if
96 (
97 other
98 &&
99 (
100 str_equal(other, cid.get_pp()->name_get())
101 ||
102 str_equal(name.string[j], cid.get_pp()->name_get())
103 )
104 )
105 {
106 name_col->fputs(name.string[j]);
107 if (desc_col)
108 desc_col->fputs(other);
109 colp->eoln();
110 ++nprinted;
111 }
112 }
113 else
114 {
115 name_col->fputs(name.string[j]);
116
117 if (desc_col)
118 {
119 string_ty *other;
120
121 other = gonzo_alias_to_actual(name.string[j]);
122 assert(other);
123 if (other)
124 desc_col->fputs(other);
125 }
126 colp->eoln();
127 ++nprinted;
128 }
129 }
130 if (option_verbose_get() && !nprinted)
131 {
132 output::pointer fp = colp->create(0, 0, (const char *)0);
133 fp->fputs("No project aliases.\n");
134 colp->eoln();
135 }
136 trace(("}\n"));
137 }
138
139
140 // vim: set ts=8 sw=4 et :
141