/[gentoo-src]/ufed/ufed-curses-help.c
Gentoo

Contents of /ufed/ufed-curses-help.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Sun Nov 13 00:28:17 2005 UTC (9 years, 4 months ago) by truedfx
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-csrc
Fix use.defaults in CVS too (bug #111902)
Don't use A_NORMAL anymore

1 #include "ufed-curses-help.h"
2
3 #include "ufed-curses.h"
4
5 #include <ctype.h>
6 #include <errno.h>
7 #include <limits.h>
8 #include <locale.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <unistd.h>
13
14 static struct line {
15 struct item item;
16 char *text;
17 } *lines;
18 static int helpheight, helpwidth;
19
20 static void free_lines(void);
21 static void init_lines(void) {
22 static const char * const help[] = {
23 "ufed is a simple program designed to help you configure the systems USE "
24 "flags (see below) to your liking. Use the Up and Down arrow keys, the "
25 "Page Up and Page Down keys, the Home and End keys, or start typing the "
26 "name of a flag to select it. Then, use the space bar to toggle the "
27 "setting. After changing flags, press the Return or Enter key to make "
28 "this permanent, or press Escape to revert your changes.",
29 "",
30 "Note: Depending on your system, you may need to wait a second before "
31 "ufed detects this key; in some cases, you can use the ncurses "
32 "environment variable ESCDELAY to change this. See the ncurses(3x) "
33 "manpage for more info.",
34 "",
35 "ufed will present you with a list of descriptions for each USE flag. If "
36 "a description is too long to fit on your screen, you can use the Left "
37 "and Right arrow keys to scroll the descriptions.",
38 "",
39 "ufed attempts to show you where a particular use setting came from. "
40 "Each USE flag has a 3 character descriptor that represents the three "
41 "ways a use flag can be set.",
42 "",
43 "The 1st char is the setting from the /etc/make.profile/make.defaults "
44 "file. These are the defaults for Gentoo as a whole. These should not be "
45 "changed.",
46 "",
47 "The 2nd char is the setting from the /etc/make.profile/use.defaults "
48 "file. These will change as packages are added and removes from the "
49 "system.",
50 "",
51 "The 3rd char is the settings from the /etc/make.conf file. these are "
52 "the only ones that should be changed by the user and these are the ones "
53 "that ufed changes.",
54 "",
55 "If the character is a + then that USE flag was set in that file, if it "
56 "is a space then the flag was not mentioned in that file and if it is a "
57 "- then that flag was unset in that file.",
58 "",
59 "-- What Are USE Flags? --",
60 "",
61 "The USE settings system is a flexible way to enable or disable various "
62 "features at package build-time on a global level and for individual "
63 "packages. This allows an administrator control over how packages are "
64 "built in regards to the optional features which can be compiled into "
65 "those packages.",
66 "",
67 "For instance, packages with optional GNOME support can have this "
68 "support disabled at compile time by disabling the \"gnome\" USE setting. "
69 "Enabling the \"gnome\" USE setting would enable GNOME support in these "
70 "same packages.",
71 "",
72 "The effect of USE settings on packages is dependent on whether both the "
73 "software itself and the package ebuild supports the USE setting as an "
74 "optional feature. If the software does not have support for an optional "
75 "feature then the corresponding USE setting will obviously have no "
76 "effect.",
77 "",
78 "Also many package dependencies are not considered optional by the "
79 "software and thus USE settings will have no effect on those mandatory "
80 "dependencies.",
81 "",
82 "A list of USE keywords used by a particular package can be found by "
83 "checking the IUSE line in any ebuild file.",
84 "",
85 "See",
86 " http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=1",
87 "for more information on USE flags.",
88 "",
89 "Please also note that if ufed describes a flag as (Unknown) it "
90 "generally means that it is either a spelling error in one of the three "
91 "configuration files or it is not an offically sanctioned USE flag. "
92 "Sanctioned USE flags can be found in",
93 " /usr/portage/profiles/use.desc",
94 "and in",
95 " /usr/portage/profiles/use.local.desc",
96 "",
97 "***",
98 "",
99 "ufed was originally written by Maik Schreiber <blizzy@blizzy.de>.",
100 "ufed was previously maintained by Robin Johnson <robbat2@gentoo.org>, "
101 "Fred Van Andel <fava@gentoo.org>, and Arun Bhanu <codebear@gentoo.org>.",
102 "ufed is currently maintained by Harald van Dijk <truedfx@gentoo.org>.",
103 "",
104 "Copyright 1999-2005 Gentoo Foundation",
105 "Distributed under the terms of the GNU General Public License v2"
106 };
107 struct line *line;
108 const char * const *paragraph = &help[0], *word = &help[0][0];
109 int n, y=0;
110
111 helpheight = wHeight(List);
112 helpwidth = wWidth(List);
113
114 atexit(&free_lines);
115 for(;;) {
116 line = malloc(sizeof *line);
117 if(line==NULL)
118 exit(-1);
119 if(lines==NULL) {
120 line->item.prev = (struct item *) line;
121 line->item.next = (struct item *) line;
122 lines = line;
123 } else {
124 line->item.next = (struct item *) lines;
125 line->item.prev = lines->item.prev;
126 lines->item.prev->next = (struct item *) line;
127 lines->item.prev = (struct item *) line;
128 }
129 line->item.top = y++;
130 line->item.height = 1;
131 n = strlen(word);
132 if(n > helpwidth-1) {
133 for(n = helpwidth-1; word[n]!=' '; n--) {
134 if(n==0) {
135 n = helpwidth;
136 break;
137 }
138 }
139 }
140 line->text = malloc(n+1);
141 if(line->text==NULL)
142 exit(-1);
143 memcpy(line->text, word, n);
144 line->text[n] = '\0';
145 while(word[n]==' ')
146 n++;
147 word += n;
148 if(word[0]=='\0') {
149 paragraph++;
150 if(paragraph == &help[sizeof help / sizeof *help])
151 break;
152 word = &(*paragraph)[0];
153 }
154 }
155 }
156
157 static void free_lines(void) {
158 struct line *line = lines;
159 if(line!=NULL) {
160 line->item.prev->next = NULL;
161 do {
162 void *p = line;
163 free(line->text);
164 line = (struct line *) line->item.next;
165 free(p);
166 } while(line!=NULL);
167 lines = NULL;
168 }
169 }
170
171 static const struct key keys[] = {
172 #define key(x) x, sizeof(x)-1
173 { '\033', key("Back (Esc)") },
174 { '\0', key("") }
175 #undef key
176 };
177
178 static void drawline(struct item *item, bool highlight) {
179 struct line *line = (struct line *) item;
180 #if C99
181 char buf[wWidth(List)+1];
182 #else
183 char *buf = __builtin_alloca(wWidth(List)+1);
184 #endif
185 sprintf(buf, "%-*.*s", wWidth(List), wWidth(List), line->text);
186 if(!highlight)
187 wattrset(win(List), COLOR_PAIR(3));
188 else
189 wattrset(win(List), COLOR_PAIR(3) | A_BOLD | A_REVERSE);
190 mvwaddstr(win(List), line->item.top-topy, 0, buf);
191 if(highlight)
192 wmove(win(List), line->item.top-topy, 0);
193 wnoutrefresh(win(List));
194 }
195
196 static int callback(struct item **currentitem, int key) {
197 switch(key) {
198 case 'Q': case 'q':
199 case '\033':
200 return 0;
201 #ifdef KEY_RESIZE
202 case KEY_RESIZE:
203 free_lines();
204 init_lines();
205 *currentitem = (struct item *) lines;
206 return -2;
207 #endif
208 default:
209 return -1;
210 }
211 }
212
213 void help(void) {
214 if(helpheight!=wHeight(List) || helpwidth!=wWidth(List)) {
215 if(lines!=NULL)
216 free_lines();
217 init_lines();
218 }
219 maineventloop("", &callback, &drawline, (struct item *) lines, keys);
220 }

  ViewVC Help
Powered by ViewVC 1.1.20