diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2012-05-02 08:06:32 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2012-05-02 08:06:32 -0700 |
commit | 588f3d7f11c87965d3d19a9c8a587b329d7d20be (patch) | |
tree | 390a6a6d145d2ef4c08b95c23741a9797b4338e1 | |
parent | 66b1c9fff6c37fbadaa201bb96e24ba6f47b077d (diff) |
302.07302.07
-rw-r--r-- | Makefile | 65 | ||||
-rw-r--r-- | backup.c | 15 | ||||
-rw-r--r-- | common-utils/common-utils.c | 338 | ||||
-rw-r--r-- | common-utils/common-utils.h | 78 | ||||
-rw-r--r-- | common-utils/gen-manpage-opts-helper.c | 181 | ||||
-rw-r--r-- | common-utils/gen-manpage-opts-helper.h | 24 | ||||
-rw-r--r-- | common-utils/nvgetopt.c | 125 | ||||
-rw-r--r-- | common-utils/nvgetopt.h | 24 | ||||
-rw-r--r-- | common-utils/src.mk | 6 | ||||
-rw-r--r-- | crc.c | 1 | ||||
-rw-r--r-- | dist-files.mk | 4 | ||||
-rw-r--r-- | format.c | 323 | ||||
-rw-r--r-- | format.h | 41 | ||||
-rw-r--r-- | gen-manpage-opts.c | 114 | ||||
-rw-r--r-- | help-args.c | 123 | ||||
-rw-r--r-- | help-args.h | 28 | ||||
-rw-r--r-- | install-from-cwd.c | 2 | ||||
-rw-r--r-- | log.c | 1 | ||||
-rw-r--r-- | makeself-help-script.c | 35 | ||||
-rw-r--r-- | misc.c | 21 | ||||
-rw-r--r-- | misc.h | 37 | ||||
-rw-r--r-- | mkprecompiled.c | 32 | ||||
-rw-r--r-- | nvidia-installer.c | 47 | ||||
-rw-r--r-- | nvidia-installer.h | 10 | ||||
-rw-r--r-- | option_table.h | 17 | ||||
-rw-r--r-- | stream-ui.c | 18 | ||||
-rw-r--r-- | user-interface.c | 3 | ||||
-rw-r--r-- | utils.mk | 30 | ||||
-rw-r--r-- | version.mk | 2 |
29 files changed, 961 insertions, 784 deletions
@@ -122,15 +122,15 @@ CFLAGS += -I. -imacros $(CONFIG_H) -I $(OUTPUTDIR) | |||
122 | CFLAGS += -I $(COMMON_UTILS_DIR) | 122 | CFLAGS += -I $(COMMON_UTILS_DIR) |
123 | 123 | ||
124 | HOST_CFLAGS += -I. -imacros $(CONFIG_H) -I $(OUTPUTDIR) | 124 | HOST_CFLAGS += -I. -imacros $(CONFIG_H) -I $(OUTPUTDIR) |
125 | LDFLAGS += -L. -ldl | 125 | LDFLAGS += -L. |
126 | LIBS += -ldl | ||
126 | 127 | ||
127 | MKPRECOMPILED_SRC = crc.c mkprecompiled.c | 128 | MKPRECOMPILED_SRC = crc.c mkprecompiled.c |
128 | MKPRECOMPILED_OBJS = $(call BUILD_OBJECT_LIST,$(MKPRECOMPILED_SRC)) | 129 | MKPRECOMPILED_OBJS = $(call BUILD_OBJECT_LIST,$(MKPRECOMPILED_SRC)) |
129 | 130 | ||
130 | MAKESELF_HELP_SCRIPT_SRC = makeself-help-script.c | 131 | MAKESELF_HELP_SCRIPT_SRC = makeself-help-script.c |
131 | MAKESELF_HELP_SCRIPT_SRC += help-args.c | ||
132 | MAKESELF_HELP_SCRIPT_SRC += format.c | ||
133 | MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/common-utils.c | 132 | MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/common-utils.c |
133 | MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/nvgetopt.c | ||
134 | 134 | ||
135 | BUILD_MAKESELF_OBJECT_LIST = \ | 135 | BUILD_MAKESELF_OBJECT_LIST = \ |
136 | $(patsubst %.o,%.makeself.o,$(call BUILD_OBJECT_LIST,$(1))) | 136 | $(patsubst %.o,%.makeself.o,$(call BUILD_OBJECT_LIST,$(1))) |
@@ -157,45 +157,44 @@ install: NVIDIA_INSTALLER_install MKPRECOMPILED_install MANPAGE_install \ | |||
157 | MAKESELF_HELP_SCRIPT_install | 157 | MAKESELF_HELP_SCRIPT_install |
158 | 158 | ||
159 | NVIDIA_INSTALLER_install: $(NVIDIA_INSTALLER) | 159 | NVIDIA_INSTALLER_install: $(NVIDIA_INSTALLER) |
160 | $(MKDIR) $(bindir) | 160 | $(MKDIR) $(BINDIR) |
161 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(bindir)/$(notdir $<) | 161 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<) |
162 | 162 | ||
163 | MKPRECOMPILED_install: $(MKPRECOMPILED) | 163 | MKPRECOMPILED_install: $(MKPRECOMPILED) |
164 | $(MKDIR) $(bindir) | 164 | $(MKDIR) $(BINDIR) |
165 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(bindir)/$(notdir $<) | 165 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<) |
166 | 166 | ||
167 | MAKESELF_HELP_SCRIPT_install: $(MAKESELF_HELP_SCRIPT) | 167 | MAKESELF_HELP_SCRIPT_install: $(MAKESELF_HELP_SCRIPT) |
168 | $(MKDIR) $(bindir) | 168 | $(MKDIR) $(BINDIR) |
169 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(bindir)/$(notdir $<) | 169 | $(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<) |
170 | 170 | ||
171 | MANPAGE_install: $(MANPAGE) | 171 | MANPAGE_install: $(MANPAGE) |
172 | $(MKDIR) $(mandir) | 172 | $(MKDIR) $(MANDIR) |
173 | $(INSTALL) $(INSTALL_DOC_ARGS) $< $(mandir)/$(notdir $<) | 173 | $(INSTALL) $(INSTALL_DOC_ARGS) $< $(MANDIR)/$(notdir $<) |
174 | 174 | ||
175 | $(MKPRECOMPILED): $(MKPRECOMPILED_OBJS) | 175 | $(MKPRECOMPILED): $(MKPRECOMPILED_OBJS) |
176 | $(call quiet_cmd,LINK) -o $@ \ | 176 | $(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) \ |
177 | $(MKPRECOMPILED_OBJS) $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) | 177 | $(MKPRECOMPILED_OBJS) -o $@ $(LIBS) |
178 | $(call quiet_cmd,STRIP_CMD) $@ | 178 | $(call quiet_cmd,STRIP_CMD) $@ |
179 | 179 | ||
180 | $(MAKESELF_HELP_SCRIPT): $(MAKESELF_HELP_SCRIPT_OBJS) | 180 | $(MAKESELF_HELP_SCRIPT): $(MAKESELF_HELP_SCRIPT_OBJS) |
181 | $(call quiet_cmd,HOST_LINK) -o $@ \ | 181 | $(call quiet_cmd,HOST_LINK) $(HOST_CFLAGS) $(HOST_LDFLAGS) \ |
182 | $(MAKESELF_HELP_SCRIPT_OBJS) $(HOST_CFLAGS) $(HOST_LDFLAGS) \ | 182 | $(HOST_BIN_LDFLAGS) $(MAKESELF_HELP_SCRIPT_OBJS) -o $@ |
183 | $(HOST_BIN_LDFLAGS) | ||
184 | $(call quiet_cmd,STRIP_CMD) $@ | 183 | $(call quiet_cmd,STRIP_CMD) $@ |
185 | 184 | ||
186 | $(NVIDIA_INSTALLER): $(INSTALLER_OBJS) | 185 | $(NVIDIA_INSTALLER): $(INSTALLER_OBJS) |
187 | $(call quiet_cmd,LINK) -o $@ $(INSTALLER_OBJS) $(CFLAGS) $(LDFLAGS) \ | 186 | $(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(PCI_LDFLAGS) \ |
188 | -Bstatic $(PCI_LDFLAGS) -lpci -Bdynamic $(BIN_LDFLAGS) | 187 | $(BIN_LDFLAGS) $(INSTALLER_OBJS) -o $@ \ |
188 | $(LIBS) -Bstatic -lpci -Bdynamic | ||
189 | $(call quiet_cmd,STRIP_CMD) $@ | 189 | $(call quiet_cmd,STRIP_CMD) $@ |
190 | 190 | ||
191 | $(GEN_UI_ARRAY): gen-ui-array.c $(CONFIG_H) | 191 | $(GEN_UI_ARRAY): gen-ui-array.c $(CONFIG_H) |
192 | $(call quiet_cmd,HOST_CC) -o $@ $< $(HOST_CFLAGS) $(HOST_LDFLAGS) \ | 192 | $(call quiet_cmd,HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) \ |
193 | $(HOST_BIN_LDFLAGS) | 193 | $(HOST_BIN_LDFLAGS) $< -o $@ |
194 | 194 | ||
195 | $(NCURSES_UI_SO): $(call BUILD_OBJECT_LIST,ncurses-ui.c) | 195 | $(NCURSES_UI_SO): $(call BUILD_OBJECT_LIST,ncurses-ui.c) |
196 | $(call quiet_cmd,LINK) -o $@ -shared $< \ | 196 | $(call quiet_cmd,LINK) -shared $(NCURSES_LDFLAGS) \ |
197 | $(NCURSES_LDFLAGS) -lncurses \ | 197 | $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) $< -o $@ -lncurses $(LIBS) |
198 | $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) | ||
199 | 198 | ||
200 | $(NCURSES_UI_SO_C): $(GEN_UI_ARRAY) $(NCURSES_UI_SO) | 199 | $(NCURSES_UI_SO_C): $(GEN_UI_ARRAY) $(NCURSES_UI_SO) |
201 | $(call quiet_cmd,GEN_UI_ARRAY) $(NCURSES_UI_SO) ncurses_ui_array > $@ | 200 | $(call quiet_cmd,GEN_UI_ARRAY) $(NCURSES_UI_SO) ncurses_ui_array > $@ |
@@ -237,7 +236,7 @@ $(foreach src,$(MAKESELF_HELP_SCRIPT_SRC),\ | |||
237 | # define the rule to generate $(STAMP_C) | 236 | # define the rule to generate $(STAMP_C) |
238 | $(eval $(call DEFINE_STAMP_C_RULE, $(INSTALLER_OBJS),$(NVIDIA_INSTALLER_PROGRAM_NAME))) | 237 | $(eval $(call DEFINE_STAMP_C_RULE, $(INSTALLER_OBJS),$(NVIDIA_INSTALLER_PROGRAM_NAME))) |
239 | 238 | ||
240 | $(CONFIG_H): | 239 | $(CONFIG_H): $(VERSION_MK) |
241 | @ $(RM) -f $@ | 240 | @ $(RM) -f $@ |
242 | @ $(MKDIR) $(OUTPUTDIR) | 241 | @ $(MKDIR) $(OUTPUTDIR) |
243 | @ $(ECHO) "#define INSTALLER_OS \"$(TARGET_OS)\"" >> $@ | 242 | @ $(ECHO) "#define INSTALLER_OS \"$(TARGET_OS)\"" >> $@ |
@@ -298,18 +297,24 @@ AUTO_TEXT = ".\\\" WARNING: THIS FILE IS AUTO-GENERATED! Edit $< instead." | |||
298 | 297 | ||
299 | doc: $(MANPAGE) | 298 | doc: $(MANPAGE) |
300 | 299 | ||
301 | $(eval $(call DEFINE_OBJECT_RULE,HOST_CC,gen-manpage-opts.c)) | 300 | GEN_MANPAGE_OPTS_SRC = gen-manpage-opts.c |
301 | GEN_MANPAGE_OPTS_SRC += $(COMMON_UTILS_DIR)/gen-manpage-opts-helper.c | ||
302 | 302 | ||
303 | $(call BUILD_OBJECT_LIST,gen-manpage-opts.c): $(CONFIG_H) | 303 | GEN_MANPAGE_OPTS_OBJS = $(call BUILD_OBJECT_LIST,$(GEN_MANPAGE_OPTS_SRC)) |
304 | 304 | ||
305 | $(GEN_MANPAGE_OPTS): $(call BUILD_OBJECT_LIST,gen-manpage-opts.c) | 305 | $(foreach src, $(GEN_MANPAGE_OPTS_SRC), \ |
306 | $(call quiet_cmd,HOST_LINK) $< -o $@ \ | 306 | $(eval $(call DEFINE_OBJECT_RULE,HOST_CC,$(src)))) |
307 | $(HOST_CFLAGS) $(HOST_LDFLAGS) $(HOST_BIN_LDFLAGS) | 307 | |
308 | $(GEN_MANPAGE_OPTS_OBJS): $(CONFIG_H) | ||
309 | |||
310 | $(GEN_MANPAGE_OPTS): $(GEN_MANPAGE_OPTS_OBJS) | ||
311 | $(call quiet_cmd,HOST_LINK) \ | ||
312 | $(HOST_CFLAGS) $(HOST_LDFLAGS) $(HOST_BIN_LDFLAGS) $^ -o $@ | ||
308 | 313 | ||
309 | $(OPTIONS_1_INC): $(GEN_MANPAGE_OPTS) | 314 | $(OPTIONS_1_INC): $(GEN_MANPAGE_OPTS) |
310 | @./$< > $@ | 315 | @./$< > $@ |
311 | 316 | ||
312 | $(MANPAGE): nvidia-installer.1.m4 $(OPTIONS_1_INC) | 317 | $(MANPAGE): nvidia-installer.1.m4 $(OPTIONS_1_INC) $(VERSION_MK) |
313 | $(call quiet_cmd,M4) \ | 318 | $(call quiet_cmd,M4) \ |
314 | -D__HEADER__=$(AUTO_TEXT) \ | 319 | -D__HEADER__=$(AUTO_TEXT) \ |
315 | -D__VERSION__=$(NVIDIA_INSTALLER_VERSION) \ | 320 | -D__VERSION__=$(NVIDIA_INSTALLER_VERSION) \ |
@@ -1194,6 +1194,21 @@ int uninstall_existing_driver(Options *op, const int interactive) | |||
1194 | return TRUE; | 1194 | return TRUE; |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | if (interactive && op->uninstall) { | ||
1198 | ret = ui_yes_no(op, FALSE, | ||
1199 | "If you plan to no longer use the NVIDIA driver, you " | ||
1200 | "should make sure that no X screens are configured to " | ||
1201 | "use the NVIDIA X driver in your X configuration file. " | ||
1202 | "If you used nvidia-xconfig to configure X, it may have " | ||
1203 | "created a backup of your original configuration. Would " | ||
1204 | "you like to run `nvidia-xconfig --restore-original-" | ||
1205 | "backup` to attempt restoration of the original X " | ||
1206 | "configuration file?"); | ||
1207 | if (ret) { | ||
1208 | run_nvidia_xconfig(op, TRUE); | ||
1209 | } | ||
1210 | } | ||
1211 | |||
1197 | ret = do_uninstall(op); | 1212 | ret = do_uninstall(op); |
1198 | 1213 | ||
1199 | if (ret) { | 1214 | if (ret) { |
diff --git a/common-utils/common-utils.c b/common-utils/common-utils.c index 701bb07..98b92fe 100644 --- a/common-utils/common-utils.c +++ b/common-utils/common-utils.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2010 NVIDIA Corporation | 2 | * Copyright (C) 2010-2012 NVIDIA Corporation |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms and conditions of the GNU General Public License, | 5 | * under the terms and conditions of the GNU General Public License, |
@@ -150,6 +150,35 @@ char *nvstrdup(const char *s) | |||
150 | 150 | ||
151 | 151 | ||
152 | /* | 152 | /* |
153 | * nvstrndup() - implementation of strndup() that checks return values; if | ||
154 | * an error occurs, an error is printed to stderr and exit is called | ||
155 | * -- this function will only return on success. | ||
156 | */ | ||
157 | |||
158 | char *nvstrndup(const char *s, size_t n) | ||
159 | { | ||
160 | char *m; | ||
161 | |||
162 | if (!s) return NULL; | ||
163 | |||
164 | m = malloc(n + 1); | ||
165 | |||
166 | if (!m) { | ||
167 | fprintf(stderr, "%s: memory allocation failure during malloc (%s)! \n", | ||
168 | PROGRAM_NAME, strerror(errno)); | ||
169 | exit(1); | ||
170 | } | ||
171 | |||
172 | strncpy (m, s, n); | ||
173 | m[n] = '\0'; | ||
174 | |||
175 | return m; | ||
176 | |||
177 | } /* nvstrndup() */ | ||
178 | |||
179 | |||
180 | |||
181 | /* | ||
153 | * nvstrtolower() - convert the given string to lowercase. | 182 | * nvstrtolower() - convert the given string to lowercase. |
154 | */ | 183 | */ |
155 | 184 | ||
@@ -250,3 +279,310 @@ char *tilde_expansion(const char *str) | |||
250 | return ret; | 279 | return ret; |
251 | 280 | ||
252 | } /* tilde_expansion() */ | 281 | } /* tilde_expansion() */ |
282 | |||
283 | |||
284 | /****************************************************************************/ | ||
285 | /* TextRows helper functions */ | ||
286 | /****************************************************************************/ | ||
287 | |||
288 | /* | ||
289 | * nv_format_text_rows() - this function breaks the given string str | ||
290 | * into some number of rows, where each row is not longer than the | ||
291 | * specified width. | ||
292 | * | ||
293 | * If prefix is non-NULL, the first line is prepended with the prefix, | ||
294 | * and subsequent lines are indented to line up with the prefix. | ||
295 | * | ||
296 | * If word_boundary is TRUE, then attempt to only break lines on | ||
297 | * boundaries between words. | ||
298 | */ | ||
299 | |||
300 | TextRows *nv_format_text_rows(const char *prefix, | ||
301 | const char *str, | ||
302 | int width, int word_boundary) | ||
303 | { | ||
304 | int len, prefix_len, z, w, i; | ||
305 | char *line, *buf, *local_prefix, *a, *b, *c; | ||
306 | TextRows *t; | ||
307 | |||
308 | /* initialize the TextRows structure */ | ||
309 | |||
310 | t = (TextRows *) malloc(sizeof(TextRows)); | ||
311 | |||
312 | if (!t) return NULL; | ||
313 | |||
314 | t->t = NULL; | ||
315 | t->n = 0; | ||
316 | t->m = 0; | ||
317 | |||
318 | if (!str) return t; | ||
319 | |||
320 | buf = strdup(str); | ||
321 | |||
322 | if (!buf) return t; | ||
323 | |||
324 | z = strlen(buf); /* length of entire string */ | ||
325 | a = buf; /* pointer to the start of the string */ | ||
326 | |||
327 | /* initialize the prefix fields */ | ||
328 | |||
329 | if (prefix) { | ||
330 | prefix_len = strlen(prefix); | ||
331 | local_prefix = strdup(prefix); | ||
332 | } else { | ||
333 | prefix_len = 0; | ||
334 | local_prefix = NULL; | ||
335 | } | ||
336 | |||
337 | /* adjust the max width for any prefix */ | ||
338 | |||
339 | w = width - prefix_len; | ||
340 | |||
341 | do { | ||
342 | /* | ||
343 | * if the string will fit on one line, point b to the end of the | ||
344 | * string | ||
345 | */ | ||
346 | |||
347 | if (z < w) b = a + z; | ||
348 | |||
349 | /* | ||
350 | * if the string won't fit on one line, move b to where the | ||
351 | * end of the line should be, and then move b back until we | ||
352 | * find a space; if we don't find a space before we back b all | ||
353 | * the way up to a, just assign b to where the line should end. | ||
354 | */ | ||
355 | |||
356 | else { | ||
357 | b = a + w; | ||
358 | |||
359 | if (word_boundary) { | ||
360 | while ((b >= a) && (!isspace(*b))) b--; | ||
361 | if (b <= a) b = a + w; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /* look for any newline inbetween a and b, and move b to it */ | ||
366 | |||
367 | for (c = a; c < b; c++) if (*c == '\n') { b = c; break; } | ||
368 | |||
369 | /* | ||
370 | * copy the string that starts at a and ends at b, prepending | ||
371 | * with a prefix, if present | ||
372 | */ | ||
373 | |||
374 | len = b-a; | ||
375 | len += prefix_len; | ||
376 | line = (char *) malloc(len+1); | ||
377 | if (local_prefix) strncpy(line, local_prefix, prefix_len); | ||
378 | strncpy(line + prefix_len, a, len - prefix_len); | ||
379 | line[len] = '\0'; | ||
380 | |||
381 | /* append the new line to the array of text rows */ | ||
382 | |||
383 | t->t = (char **) realloc(t->t, sizeof(char *) * (t->n + 1)); | ||
384 | t->t[t->n] = line; | ||
385 | t->n++; | ||
386 | |||
387 | if (t->m < len) t->m = len; | ||
388 | |||
389 | /* | ||
390 | * adjust the length of the string and move the pointer to the | ||
391 | * beginning of the new line | ||
392 | */ | ||
393 | |||
394 | z -= (b - a + 1); | ||
395 | a = b + 1; | ||
396 | |||
397 | /* move to the first non whitespace character (excluding newlines) */ | ||
398 | |||
399 | if (word_boundary && isspace(*b)) { | ||
400 | while ((z) && (isspace(*a)) && (*a != '\n')) a++, z--; | ||
401 | } else { | ||
402 | if (!isspace(*b)) z++, a--; | ||
403 | } | ||
404 | |||
405 | if (local_prefix) { | ||
406 | for (i = 0; i < prefix_len; i++) local_prefix[i] = ' '; | ||
407 | } | ||
408 | |||
409 | } while (z > 0); | ||
410 | |||
411 | if (local_prefix) free(local_prefix); | ||
412 | free(buf); | ||
413 | |||
414 | return t; | ||
415 | } | ||
416 | |||
417 | |||
418 | /* | ||
419 | * nv_text_rows_append() - append the given msg to the existing TextRows | ||
420 | */ | ||
421 | |||
422 | void nv_text_rows_append(TextRows *t, const char *msg) | ||
423 | { | ||
424 | int len; | ||
425 | |||
426 | t->t = realloc(t->t, sizeof(char *) * (t->n + 1)); | ||
427 | |||
428 | if (msg) { | ||
429 | t->t[t->n] = strdup(msg); | ||
430 | len = strlen(msg); | ||
431 | if (t->m < len) t->m = len; | ||
432 | } else { | ||
433 | t->t[t->n] = NULL; | ||
434 | } | ||
435 | |||
436 | t->n++; | ||
437 | } | ||
438 | |||
439 | /* | ||
440 | * nv_concat_text_rows() - concatenate two text rows, storing the | ||
441 | * result in t0 | ||
442 | */ | ||
443 | |||
444 | #define NV_MAX(x,y) ((x) > (y) ? (x) : (y)) | ||
445 | |||
446 | void nv_concat_text_rows(TextRows *t0, TextRows *t1) | ||
447 | { | ||
448 | int n, i; | ||
449 | |||
450 | n = t0->n + t1->n; | ||
451 | |||
452 | t0->t = realloc(t0->t, sizeof(char *) * n); | ||
453 | |||
454 | for (i = 0; i < t1->n; i++) { | ||
455 | t0->t[i + t0->n] = strdup(t1->t[i]); | ||
456 | } | ||
457 | |||
458 | t0->m = NV_MAX(t0->m, t1->m); | ||
459 | t0->n = n; | ||
460 | |||
461 | } /* nv_concat_text_rows() */ | ||
462 | |||
463 | |||
464 | /* | ||
465 | * nv_free_text_rows() - free the TextRows data structure allocated by | ||
466 | * nv_format_text_rows() | ||
467 | */ | ||
468 | |||
469 | void nv_free_text_rows(TextRows *t) | ||
470 | { | ||
471 | int i; | ||
472 | |||
473 | if (!t) return; | ||
474 | for (i = 0; i < t->n; i++) free(t->t[i]); | ||
475 | if (t->t) free(t->t); | ||
476 | free(t); | ||
477 | |||
478 | } /* nv_free_text_rows() */ | ||
479 | |||
480 | |||
481 | /****************************************************************************/ | ||
482 | /* printing helper functions */ | ||
483 | /****************************************************************************/ | ||
484 | |||
485 | #define DEFAULT_WIDTH 75 | ||
486 | |||
487 | static unsigned short __terminal_width = 0; | ||
488 | |||
489 | /* | ||
490 | * reset_current_terminal_width() - if new_val is zero, then use the | ||
491 | * TIOCGWINSZ ioctl to get the current width of the terminal, and | ||
492 | * assign it the value to __terminal_width. If the ioctl fails, use a | ||
493 | * hardcoded constant. If new_val is non-zero, then use new_val. | ||
494 | */ | ||
495 | |||
496 | void reset_current_terminal_width(unsigned short new_val) | ||
497 | { | ||
498 | struct winsize ws; | ||
499 | |||
500 | if (new_val) { | ||
501 | __terminal_width = new_val; | ||
502 | return; | ||
503 | } | ||
504 | |||
505 | if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) { | ||
506 | __terminal_width = DEFAULT_WIDTH; | ||
507 | } else { | ||
508 | __terminal_width = ws.ws_col - 1; | ||
509 | } | ||
510 | } | ||
511 | |||
512 | /* | ||
513 | * Call silence_fmt(1) to turn fmtout(), fmtoutp() and format() into noops. | ||
514 | */ | ||
515 | static int __silent = 0; | ||
516 | |||
517 | void silence_fmt(int val) | ||
518 | { | ||
519 | __silent = val; | ||
520 | } | ||
521 | |||
522 | |||
523 | static void vformat(FILE *stream, const int wb, | ||
524 | const char *prefix, const char *buf) | ||
525 | { | ||
526 | int i; | ||
527 | TextRows *t; | ||
528 | |||
529 | if (!__terminal_width) reset_current_terminal_width(0); | ||
530 | |||
531 | t = nv_format_text_rows(prefix, buf, __terminal_width, wb); | ||
532 | |||
533 | for (i = 0; i < t->n; i++) fprintf(stream, "%s\n", t->t[i]); | ||
534 | |||
535 | nv_free_text_rows(t); | ||
536 | } | ||
537 | |||
538 | |||
539 | #define NV_VFORMAT(stream, wb, prefix, fmt) \ | ||
540 | do { \ | ||
541 | char *buf; \ | ||
542 | NV_VSNPRINTF(buf, fmt); \ | ||
543 | vformat(stream, wb, prefix, buf); \ | ||
544 | free (buf); \ | ||
545 | } while(0) | ||
546 | |||
547 | |||
548 | void fmtout(const char *fmt, ...) | ||
549 | { | ||
550 | if (__silent > 0) { | ||
551 | return; | ||
552 | } | ||
553 | NV_VFORMAT(stdout, TRUE, NULL, fmt); | ||
554 | } | ||
555 | |||
556 | |||
557 | void fmtoutp(const char *prefix, const char *fmt, ...) | ||
558 | { | ||
559 | if (__silent > 0) { | ||
560 | return; | ||
561 | } | ||
562 | NV_VFORMAT(stdout, TRUE, prefix, fmt); | ||
563 | } | ||
564 | |||
565 | |||
566 | void fmterr(const char *fmt, ...) | ||
567 | { | ||
568 | vformat(stderr, 0, NULL, ""); | ||
569 | NV_VFORMAT(stderr, TRUE, "ERROR: ", fmt); | ||
570 | vformat(stderr, 0, NULL, ""); | ||
571 | } | ||
572 | |||
573 | |||
574 | void fmtwarn(const char *fmt, ...) | ||
575 | { | ||
576 | vformat(stderr, 0, NULL, ""); | ||
577 | NV_VFORMAT(stderr, TRUE, "WARNING: ", fmt); | ||
578 | vformat(stderr, 0, NULL, ""); | ||
579 | } | ||
580 | |||
581 | |||
582 | void fmt(FILE *stream, const char *prefix, const char *fmt, ...) | ||
583 | { | ||
584 | if (__silent > 0) { | ||
585 | return; | ||
586 | } | ||
587 | NV_VFORMAT(stream, TRUE, prefix, fmt); | ||
588 | } | ||
diff --git a/common-utils/common-utils.h b/common-utils/common-utils.h index 04d5f3b..e0d9314 100644 --- a/common-utils/common-utils.h +++ b/common-utils/common-utils.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2010 NVIDIA Corporation | 2 | * Copyright (C) 2010-2012 NVIDIA Corporation |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms and conditions of the GNU General Public License, | 5 | * under the terms and conditions of the GNU General Public License, |
@@ -17,6 +17,9 @@ | |||
17 | #ifndef __COMMON_UTILS_H__ | 17 | #ifndef __COMMON_UTILS_H__ |
18 | #define __COMMON_UTILS_H__ | 18 | #define __COMMON_UTILS_H__ |
19 | 19 | ||
20 | #include <stdio.h> | ||
21 | #include <stdarg.h> | ||
22 | |||
20 | #if !defined(TRUE) | 23 | #if !defined(TRUE) |
21 | #define TRUE 1 | 24 | #define TRUE 1 |
22 | #endif | 25 | #endif |
@@ -25,13 +28,86 @@ | |||
25 | #define FALSE 0 | 28 | #define FALSE 0 |
26 | #endif | 29 | #endif |
27 | 30 | ||
31 | #define ARRAY_LEN(_arr) (sizeof(_arr) / sizeof(_arr[0])) | ||
32 | |||
33 | #define TAB " " | ||
34 | #define BIGTAB " " | ||
35 | |||
36 | typedef struct { | ||
37 | char **t; /* the text rows */ | ||
38 | int n; /* number of rows */ | ||
39 | int m; /* maximum row length */ | ||
40 | } TextRows; | ||
41 | |||
28 | void *nvalloc(size_t size); | 42 | void *nvalloc(size_t size); |
29 | char *nvstrcat(const char *str, ...); | 43 | char *nvstrcat(const char *str, ...); |
30 | void *nvrealloc(void *ptr, size_t size); | 44 | void *nvrealloc(void *ptr, size_t size); |
31 | char *nvstrdup(const char *s); | 45 | char *nvstrdup(const char *s); |
46 | char *nvstrndup(const char *s, size_t n); | ||
32 | char *nvstrtolower(char *s); | 47 | char *nvstrtolower(char *s); |
33 | void nvfree(void *s); | 48 | void nvfree(void *s); |
34 | 49 | ||
35 | char *tilde_expansion(const char *str); | 50 | char *tilde_expansion(const char *str); |
36 | 51 | ||
52 | TextRows *nv_format_text_rows(const char *prefix, | ||
53 | const char *str, | ||
54 | int width, int word_boundary); | ||
55 | void nv_text_rows_append(TextRows *t, const char *msg); | ||
56 | void nv_concat_text_rows(TextRows *t0, TextRows *t1); | ||
57 | void nv_free_text_rows(TextRows *t); | ||
58 | |||
59 | void reset_current_terminal_width(unsigned short new_val); | ||
60 | |||
61 | void silence_fmt(int val); | ||
62 | void fmtout(const char *fmt, ...); | ||
63 | void fmtoutp(const char *prefix, const char *fmt, ...); | ||
64 | void fmterr(const char *fmt, ...); | ||
65 | void fmtwarn(const char *fmt, ...); | ||
66 | void fmt(FILE *stream, const char *prefix, const char *fmt, ...); | ||
67 | |||
68 | /* | ||
69 | * NV_VSNPRINTF(): macro that assigns buf using vsnprintf(). This is | ||
70 | * correct for differing semantics of the vsnprintf() return value: | ||
71 | * | ||
72 | * -1 when the buffer is not long enough (glibc < 2.1) | ||
73 | * | ||
74 | * or | ||
75 | * | ||
76 | * the length the string would have been if the buffer had been large | ||
77 | * enough (glibc >= 2.1) | ||
78 | * | ||
79 | * This macro allocates memory for buf; the caller should free it when | ||
80 | * done. | ||
81 | */ | ||
82 | |||
83 | #define NV_FMT_BUF_LEN 256 | ||
84 | |||
85 | #define NV_VSNPRINTF(buf, fmt) \ | ||
86 | do { \ | ||
87 | if (!fmt) { \ | ||
88 | (buf) = NULL; \ | ||
89 | } else { \ | ||
90 | va_list ap; \ | ||
91 | int len, current_len = NV_FMT_BUF_LEN; \ | ||
92 | \ | ||
93 | (buf) = malloc(current_len); \ | ||
94 | \ | ||
95 | while (1) { \ | ||
96 | va_start(ap, fmt); \ | ||
97 | len = vsnprintf((buf), current_len, (fmt), ap); \ | ||
98 | va_end(ap); \ | ||
99 | \ | ||
100 | if ((len > -1) && (len < current_len)) { \ | ||
101 | break; \ | ||
102 | } else if (len > -1) { \ | ||
103 | current_len = len + 1; \ | ||
104 | } else { \ | ||
105 | current_len += NV_FMT_BUF_LEN; \ | ||
106 | } \ | ||
107 | free(buf); \ | ||
108 | (buf) = malloc(current_len); \ | ||
109 | } \ | ||
110 | } \ | ||
111 | } while (0) | ||
112 | |||
37 | #endif /* __COMMON_UTILS_H__ */ | 113 | #endif /* __COMMON_UTILS_H__ */ |
diff --git a/common-utils/gen-manpage-opts-helper.c b/common-utils/gen-manpage-opts-helper.c new file mode 100644 index 0000000..d2abb1c --- /dev/null +++ b/common-utils/gen-manpage-opts-helper.c | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <ctype.h> | ||
19 | #include <string.h> | ||
20 | |||
21 | #include "nvgetopt.h" | ||
22 | #include "gen-manpage-opts-helper.h" | ||
23 | |||
24 | static void print_option(const NVGetoptOption *o) | ||
25 | { | ||
26 | char scratch[64], *s; | ||
27 | int j, len; | ||
28 | |||
29 | int italics, bold, omitWhiteSpace; | ||
30 | |||
31 | /* if we are going to need the argument, process it now */ | ||
32 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
33 | if (o->arg_name) { | ||
34 | strcpy(scratch, o->arg_name); | ||
35 | } else { | ||
36 | len = strlen(o->name); | ||
37 | for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]); | ||
38 | scratch[len] = '\0'; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | printf(".TP\n.BI \""); | ||
43 | /* Print the name of the option */ | ||
44 | /* XXX We should backslashify the '-' characters in o->name. */ | ||
45 | |||
46 | if (isalpha(o->val)) { | ||
47 | /* '\-c' */ | ||
48 | printf("\\-%c", o->val); | ||
49 | |||
50 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
51 | /* ' " "ARG" "' */ | ||
52 | printf(" \" \"%s\" \"", scratch); | ||
53 | } | ||
54 | /* ', ' */ | ||
55 | printf(", "); | ||
56 | } | ||
57 | |||
58 | /* '\-\-name' */ | ||
59 | printf("\\-\\-%s", o->name); | ||
60 | |||
61 | /* '=" "ARG' */ | ||
62 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
63 | printf("=\" \"%s", scratch); | ||
64 | |||
65 | /* '" "' */ | ||
66 | if ((o->flags & NVGETOPT_IS_BOOLEAN) || | ||
67 | (o->flags & NVGETOPT_ALLOW_DISABLE)) { | ||
68 | printf("\" \""); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /* ', \-\-no\-name' */ | ||
73 | if (((o->flags & NVGETOPT_IS_BOOLEAN) && | ||
74 | !(o->flags & NVGETOPT_HAS_ARGUMENT)) || | ||
75 | (o->flags & NVGETOPT_ALLOW_DISABLE)) { | ||
76 | printf(", \\-\\-no\\-%s", o->name); | ||
77 | } | ||
78 | |||
79 | printf("\"\n"); | ||
80 | |||
81 | /* Print the option description */ | ||
82 | /* XXX Each sentence should be on its own line! */ | ||
83 | |||
84 | /* | ||
85 | * Print the option description: write each character one at a | ||
86 | * time (ugh) so that we can special-case a few characters: | ||
87 | * | ||
88 | * '&' : toggles italics on and off | ||
89 | * '^' : toggles bold on and off | ||
90 | * '-' : is backslashified: "\-" | ||
91 | * | ||
92 | * Whitespace is omited when italics or bold is on | ||
93 | */ | ||
94 | |||
95 | italics = 0; | ||
96 | bold = 0; | ||
97 | omitWhiteSpace = 0; | ||
98 | |||
99 | for (s = o->description; s && *s; s++) { | ||
100 | |||
101 | switch (*s) { | ||
102 | case '&': | ||
103 | if (italics) { | ||
104 | printf("\n"); | ||
105 | } else { | ||
106 | printf("\n.I "); | ||
107 | } | ||
108 | omitWhiteSpace = italics; | ||
109 | italics = !italics; | ||
110 | break; | ||
111 | case '^': | ||
112 | if (bold) { | ||
113 | printf("\n"); | ||
114 | } else { | ||
115 | printf("\n.B "); | ||
116 | } | ||
117 | omitWhiteSpace = bold; | ||
118 | bold = !bold; | ||
119 | break; | ||
120 | case '-': | ||
121 | printf("\\-"); | ||
122 | omitWhiteSpace = 0; | ||
123 | break; | ||
124 | case ' ': | ||
125 | if (!omitWhiteSpace) { | ||
126 | printf(" "); | ||
127 | } | ||
128 | break; | ||
129 | default: | ||
130 | printf("%c", *s); | ||
131 | omitWhiteSpace = 0; | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | printf("\n"); | ||
137 | } | ||
138 | |||
139 | void gen_manpage_opts_helper(const NVGetoptOption *options) | ||
140 | { | ||
141 | int i; | ||
142 | int has_advanced_options = 0; | ||
143 | |||
144 | /* Print the "simple" options; i.e. the ones you get with --help. */ | ||
145 | printf(".SH OPTIONS\n"); | ||
146 | for (i = 0; options[i].name; i++) { | ||
147 | const NVGetoptOption *o = &options[i]; | ||
148 | |||
149 | if (!o->description) { | ||
150 | continue; | ||
151 | } | ||
152 | |||
153 | if (!(o->flags & NVGETOPT_HELP_ALWAYS)) { | ||
154 | has_advanced_options = 1; | ||
155 | continue; | ||
156 | } | ||
157 | |||
158 | print_option(o); | ||
159 | } | ||
160 | |||
161 | if (has_advanced_options) { | ||
162 | /* | ||
163 | * If any exist, print the advanced options; i.e., the ones | ||
164 | * you get with --advanced-help | ||
165 | */ | ||
166 | printf(".SH \"ADVANCED OPTIONS\"\n"); | ||
167 | for (i = 0; options[i].name; i++) { | ||
168 | const NVGetoptOption *o = &options[i]; | ||
169 | |||
170 | if (!o->description) { | ||
171 | continue; | ||
172 | } | ||
173 | |||
174 | if (o->flags & NVGETOPT_HELP_ALWAYS) { | ||
175 | continue; | ||
176 | } | ||
177 | |||
178 | print_option(o); | ||
179 | } | ||
180 | } | ||
181 | } | ||
diff --git a/common-utils/gen-manpage-opts-helper.h b/common-utils/gen-manpage-opts-helper.h new file mode 100644 index 0000000..b09852e --- /dev/null +++ b/common-utils/gen-manpage-opts-helper.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #if !defined(__GEN_MANPAGE_OPTS_HELPER_H__) | ||
18 | #define __GEN_MANPAGE_OPTS_HELPER_H__ | ||
19 | |||
20 | #include "nvgetopt.h" | ||
21 | |||
22 | void gen_manpage_opts_helper(const NVGetoptOption *options); | ||
23 | |||
24 | #endif /* __GEN_MANPAGE_OPTS_HELPER_H__ */ | ||
diff --git a/common-utils/nvgetopt.c b/common-utils/nvgetopt.c index a89dcac..f04cef3 100644 --- a/common-utils/nvgetopt.c +++ b/common-utils/nvgetopt.c | |||
@@ -21,8 +21,10 @@ | |||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <ctype.h> | ||
24 | 25 | ||
25 | #include "nvgetopt.h" | 26 | #include "nvgetopt.h" |
27 | #include "common-utils.h" | ||
26 | 28 | ||
27 | 29 | ||
28 | int nvgetopt(int argc, | 30 | int nvgetopt(int argc, |
@@ -309,3 +311,126 @@ int nvgetopt(int argc, | |||
309 | return ret; | 311 | return ret; |
310 | 312 | ||
311 | } /* nvgetopt() */ | 313 | } /* nvgetopt() */ |
314 | |||
315 | |||
316 | /* | ||
317 | * cook_description() - the description string may contain text within | ||
318 | * special characters which are interpreted by the manpage generator. | ||
319 | * We want to omit those characters here. | ||
320 | */ | ||
321 | |||
322 | static char *cook_description(const char *description) | ||
323 | { | ||
324 | const char *src; | ||
325 | char *s, *dst; | ||
326 | |||
327 | if (!description) { | ||
328 | return NULL; | ||
329 | } | ||
330 | |||
331 | s = strdup(description); | ||
332 | |||
333 | if (!s) { | ||
334 | return NULL; | ||
335 | } | ||
336 | |||
337 | for (src = description, dst = s; *src; src++) { | ||
338 | if ((*src == '&') || (*src == '^')) { | ||
339 | continue; | ||
340 | } | ||
341 | *dst = *src; | ||
342 | dst++; | ||
343 | } | ||
344 | |||
345 | *dst = '\0'; | ||
346 | |||
347 | return s; | ||
348 | } | ||
349 | |||
350 | |||
351 | void nvgetopt_print_help(const NVGetoptOption *options, | ||
352 | unsigned int include_mask, | ||
353 | nvgetopt_print_help_callback_ptr callback) | ||
354 | { | ||
355 | const NVGetoptOption *o; | ||
356 | int i; | ||
357 | |||
358 | for (i = 0; options[i].name; i++) { | ||
359 | |||
360 | char *msg = NULL, *arg = NULL, *description = NULL; | ||
361 | |||
362 | o = &options[i]; | ||
363 | |||
364 | /* Skip options with no help text */ | ||
365 | if (!o->description) { | ||
366 | continue; | ||
367 | } | ||
368 | |||
369 | /* skip options who don't have all the bits of include_mask */ | ||
370 | if ((o->flags & include_mask) != include_mask) { | ||
371 | continue; | ||
372 | } | ||
373 | |||
374 | /* if we are going to need the argument, process it now */ | ||
375 | arg = NULL; | ||
376 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
377 | if (o->arg_name) { | ||
378 | arg = strdup(o->arg_name); | ||
379 | } else { | ||
380 | char *tmp; | ||
381 | arg = strdup(o->name); | ||
382 | for (tmp = arg; tmp && *tmp; tmp++) { | ||
383 | *tmp = toupper(*tmp); | ||
384 | } | ||
385 | } | ||
386 | } | ||
387 | |||
388 | msg = NULL; | ||
389 | |||
390 | /* | ||
391 | * create the long version of the option, possibly with an | ||
392 | * argument; e.g., "--foo" or "--foo=BAR" | ||
393 | */ | ||
394 | if (arg) { | ||
395 | msg = nvstrcat("--", o->name, "=", arg, NULL); | ||
396 | } else { | ||
397 | msg = nvstrcat("--", o->name, NULL); | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * prepend the single character version of the option, | ||
402 | * possibly with an argument; e.g., "-f" or "-f BAR" | ||
403 | */ | ||
404 | if (isalpha(o->val)) { | ||
405 | char scratch[16]; | ||
406 | char *tmp; | ||
407 | snprintf(scratch, sizeof(scratch), "%c", o->val); | ||
408 | if (arg) { | ||
409 | tmp = nvstrcat("-", scratch, " ", arg, ", ", msg, NULL); | ||
410 | } else { | ||
411 | tmp = nvstrcat("-", scratch, ", ", msg, NULL); | ||
412 | } | ||
413 | free(msg); | ||
414 | msg = tmp; | ||
415 | } | ||
416 | |||
417 | /* append the boolean version of the option; e.g., "--no-foo" */ | ||
418 | if (((o->flags & NVGETOPT_IS_BOOLEAN) && | ||
419 | !(o->flags & NVGETOPT_HAS_ARGUMENT)) || | ||
420 | (o->flags & NVGETOPT_ALLOW_DISABLE)) { | ||
421 | char *tmp = nvstrcat(msg, ", --no-", o->name, NULL); | ||
422 | free(msg); | ||
423 | msg = tmp; | ||
424 | } | ||
425 | |||
426 | /* process the description text */ | ||
427 | description = cook_description(o->description); | ||
428 | |||
429 | /* give the strings to the caller to format and print */ | ||
430 | callback(msg, description); | ||
431 | |||
432 | free(msg); | ||
433 | free(arg); | ||
434 | free(description); | ||
435 | } | ||
436 | } | ||
diff --git a/common-utils/nvgetopt.h b/common-utils/nvgetopt.h index 127f40b..5847546 100644 --- a/common-utils/nvgetopt.h +++ b/common-utils/nvgetopt.h | |||
@@ -155,5 +155,29 @@ int nvgetopt(int argc, | |||
155 | double *doubleval, | 155 | double *doubleval, |
156 | int *disable_val); | 156 | int *disable_val); |
157 | 157 | ||
158 | /* | ||
159 | * nvgetopt_print_help() - print a help message for each option in the | ||
160 | * provided NVGetoptOption array. This is useful for a utility's | ||
161 | * "--help" output. | ||
162 | * | ||
163 | * Options will only be printed if they have every bit set that | ||
164 | * include_mask includes. | ||
165 | * | ||
166 | * For each option, the provided callback function wil be called with | ||
167 | * two strings: a name string that lists the option's name, and a | ||
168 | * description string for the option. The callback function is | ||
169 | * responsible for actually printing these strings. Examples: | ||
170 | * | ||
171 | * name = "-v, --version"; | ||
172 | * description = "Print usage information for the common commandline " | ||
173 | * "options and exit."; | ||
174 | */ | ||
175 | |||
176 | typedef void nvgetopt_print_help_callback_ptr(const char *name, | ||
177 | const char *description); | ||
178 | |||
179 | void nvgetopt_print_help(const NVGetoptOption *options, | ||
180 | unsigned int include_mask, | ||
181 | nvgetopt_print_help_callback_ptr callback); | ||
158 | 182 | ||
159 | #endif /* __NVGETOPT_H__ */ | 183 | #endif /* __NVGETOPT_H__ */ |
diff --git a/common-utils/src.mk b/common-utils/src.mk index 14e4131..12ba143 100644 --- a/common-utils/src.mk +++ b/common-utils/src.mk | |||
@@ -7,3 +7,9 @@ COMMON_UTILS_EXTRA_DIST += nvgetopt.h | |||
7 | COMMON_UTILS_EXTRA_DIST += common-utils.h | 7 | COMMON_UTILS_EXTRA_DIST += common-utils.h |
8 | COMMON_UTILS_EXTRA_DIST += src.mk | 8 | COMMON_UTILS_EXTRA_DIST += src.mk |
9 | 9 | ||
10 | # gen-manpage-opts-helper.c is listed in EXTRA_DIST, rather than SRC, | ||
11 | # because it is not compiled into the utilities themselves, but used | ||
12 | # when building the utility's gen-manpage-opts | ||
13 | COMMON_UTILS_EXTRA_DIST += gen-manpage-opts-helper.c | ||
14 | COMMON_UTILS_EXTRA_DIST += gen-manpage-opts-helper.h | ||
15 | |||
@@ -43,6 +43,7 @@ | |||
43 | #include "nvidia-installer.h" | 43 | #include "nvidia-installer.h" |
44 | #include "user-interface.h" | 44 | #include "user-interface.h" |
45 | #include "misc.h" | 45 | #include "misc.h" |
46 | #include "crc.h" | ||
46 | 47 | ||
47 | #define BIT(x) (1 << (x)) | 48 | #define BIT(x) (1 << (x)) |
48 | #define CRC_GEN_MASK (BIT(26) | BIT(23) | BIT(22) | BIT(16) | BIT(12) | \ | 49 | #define CRC_GEN_MASK (BIT(26) | BIT(23) | BIT(22) | BIT(16) | BIT(12) | \ |
diff --git a/dist-files.mk b/dist-files.mk index d650543..289bf07 100644 --- a/dist-files.mk +++ b/dist-files.mk | |||
@@ -30,7 +30,6 @@ SRC := backup.c | |||
30 | SRC += command-list.c | 30 | SRC += command-list.c |
31 | SRC += crc.c | 31 | SRC += crc.c |
32 | SRC += files.c | 32 | SRC += files.c |
33 | SRC += format.c | ||
34 | SRC += install-from-cwd.c | 33 | SRC += install-from-cwd.c |
35 | SRC += kernel.c | 34 | SRC += kernel.c |
36 | SRC += log.c | 35 | SRC += log.c |
@@ -44,7 +43,6 @@ SRC += stream-ui.c | |||
44 | SRC += update.c | 43 | SRC += update.c |
45 | SRC += user-interface.c | 44 | SRC += user-interface.c |
46 | SRC += sanity.c | 45 | SRC += sanity.c |
47 | SRC += help-args.c | ||
48 | 46 | ||
49 | DIST_FILES := $(SRC) | 47 | DIST_FILES := $(SRC) |
50 | 48 | ||
@@ -52,7 +50,6 @@ DIST_FILES += backup.h | |||
52 | DIST_FILES += command-list.h | 50 | DIST_FILES += command-list.h |
53 | DIST_FILES += crc.h | 51 | DIST_FILES += crc.h |
54 | DIST_FILES += files.h | 52 | DIST_FILES += files.h |
55 | DIST_FILES += format.h | ||
56 | DIST_FILES += kernel.h | 53 | DIST_FILES += kernel.h |
57 | DIST_FILES += misc.h | 54 | DIST_FILES += misc.h |
58 | DIST_FILES += nvidia-installer-ui.h | 55 | DIST_FILES += nvidia-installer-ui.h |
@@ -64,7 +61,6 @@ DIST_FILES += snarf-internal.h | |||
64 | DIST_FILES += snarf.h | 61 | DIST_FILES += snarf.h |
65 | DIST_FILES += update.h | 62 | DIST_FILES += update.h |
66 | DIST_FILES += user-interface.h | 63 | DIST_FILES += user-interface.h |
67 | DIST_FILES += help-args.h | ||
68 | 64 | ||
69 | DIST_FILES += COPYING | 65 | DIST_FILES += COPYING |
70 | DIST_FILES += README | 66 | DIST_FILES += README |
diff --git a/format.c b/format.c deleted file mode 100644 index c67773e..0000000 --- a/format.c +++ /dev/null | |||
@@ -1,323 +0,0 @@ | |||
1 | /* | ||
2 | * nvidia-installer: A tool for installing NVIDIA software packages on | ||
3 | * Unix and Linux systems. | ||
4 | * | ||
5 | * Copyright (C) 2003 NVIDIA Corporation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, see <http://www.gnu.org/licenses>. | ||
18 | * | ||
19 | * | ||
20 | * format.c - this source file contains routines for formatting string | ||
21 | * output. | ||
22 | */ | ||
23 | |||
24 | |||
25 | #include <ctype.h> | ||
26 | #include <stdio.h> | ||
27 | #include <unistd.h> | ||
28 | #include <sys/ioctl.h> | ||
29 | #include <stdlib.h> | ||
30 | #include <string.h> | ||
31 | |||
32 | #include "nvidia-installer.h" | ||
33 | #include "format.h" | ||
34 | #include "misc.h" | ||
35 | |||
36 | static unsigned short __terminal_width = 0; | ||
37 | |||
38 | |||
39 | |||
40 | #define DEFAULT_WIDTH 75 | ||
41 | |||
42 | /* | ||
43 | * Format and display a printf style string such that it fits within | ||
44 | * the terminal width | ||
45 | */ | ||
46 | |||
47 | #define NV_VFORMAT(stream, wb, prefix, fmt) \ | ||
48 | do { \ | ||
49 | char *buf; \ | ||
50 | NV_VSNPRINTF(buf, fmt); \ | ||
51 | vformat(stream, wb, prefix, buf); \ | ||
52 | free (buf); \ | ||
53 | } while(0) | ||
54 | |||
55 | |||
56 | static void vformat(FILE *stream, const int wb, | ||
57 | const char *prefix, const char *buf); | ||
58 | |||
59 | |||
60 | /* | ||
61 | * reset_current_terminal_width() - if new_val is zero, then use the | ||
62 | * TIOCGWINSZ ioctl to get the current width of the terminal, and | ||
63 | * assign it the value to __terminal_width. If the ioctl fails, use a | ||
64 | * hardcoded constant. If new_val is non-zero, then use new_val. | ||
65 | */ | ||
66 | |||
67 | void reset_current_terminal_width(unsigned short new_val) | ||
68 | { | ||
69 | struct winsize ws; | ||
70 | |||
71 | if (new_val) { | ||
72 | __terminal_width = new_val; | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) { | ||
77 | __terminal_width = DEFAULT_WIDTH; | ||
78 | } else { | ||
79 | __terminal_width = ws.ws_col - 1; | ||
80 | } | ||
81 | } /* get_current_terminal_width() */ | ||
82 | |||
83 | |||
84 | |||
85 | /* | ||
86 | * fmtout() - stdout format function: prints the given string to | ||
87 | * stdout with no prefix. | ||
88 | */ | ||
89 | |||
90 | void fmtout(const char *fmt, ...) | ||
91 | { | ||
92 | NV_VFORMAT(stdout, TRUE, NULL, fmt); | ||
93 | |||
94 | } /* fmtout() */ | ||
95 | |||
96 | |||
97 | |||
98 | /* | ||
99 | * fmtoutp() - stdout format function with prefix: prints the given | ||
100 | * string to stdout with the given prefix. | ||
101 | */ | ||
102 | |||
103 | void fmtoutp(const char *prefix, const char *fmt, ...) | ||
104 | { | ||
105 | NV_VFORMAT(stdout, TRUE, prefix, fmt); | ||
106 | |||
107 | } /* fmtoutp() */ | ||
108 | |||
109 | |||
110 | |||
111 | /* | ||
112 | * fmterr() - stderr format function: prints the given string to | ||
113 | * stderr with no prefix. | ||
114 | */ | ||
115 | |||
116 | void fmterr(const char *fmt, ...) | ||
117 | { | ||
118 | NV_VFORMAT(stderr, TRUE, NULL, fmt); | ||
119 | |||
120 | } /* fmterr() */ | ||
121 | |||
122 | |||
123 | |||
124 | /* | ||
125 | * fmterrp() - stderr format function: prints the given string to | ||
126 | * stderr with the given prefix. | ||
127 | */ | ||
128 | |||
129 | void fmterrp(const char *prefix, const char *fmt, ...) | ||
130 | { | ||
131 | NV_VFORMAT(stderr, TRUE, prefix, fmt); | ||
132 | |||
133 | } /* fmterrp() */ | ||
134 | |||
135 | |||
136 | |||
137 | /* | ||
138 | * format() & vformat() - these takes a printf-style format string and | ||
139 | * a variable list of args. We use NV_VSNPRINTF to generate the | ||
140 | * desired string, and then call nv_format_text_rows() to format the | ||
141 | * string so that not more than __terminal_width characters are | ||
142 | * printed across. | ||
143 | * | ||
144 | * The resulting formatted output is written to the specified stream. | ||
145 | * The output may also include an optional prefix (to be prepended on | ||
146 | * the first line, and filled with spaces on subsequent lines. | ||
147 | * | ||
148 | * The wb argument indicates whether the line wrapping should only | ||
149 | * break on word boundaries. | ||
150 | */ | ||
151 | |||
152 | void format(FILE *stream, const char *prefix, const char *fmt, ...) | ||
153 | { | ||
154 | NV_VFORMAT(stream, TRUE, prefix, fmt); | ||
155 | |||
156 | } /* format() */ | ||
157 | |||
158 | |||
159 | |||
160 | static void vformat(FILE *stream, const int wb, | ||
161 | const char *prefix, const char *buf) | ||
162 | { | ||
163 | int i; | ||
164 | TextRows *t; | ||
165 | |||
166 | if (!__terminal_width) reset_current_terminal_width(0); | ||
167 | |||
168 | t = nv_format_text_rows(prefix, buf, __terminal_width, wb); | ||
169 | |||
170 | for (i = 0; i < t->n; i++) fprintf(stream, "%s\n", t->t[i]); | ||
171 | |||
172 | nv_free_text_rows(t); | ||
173 | |||
174 | } /* vformat() */ | ||
175 | |||
176 | |||
177 | |||
178 | /* | ||
179 | * nv_format_text_rows() - this function breaks the given string str | ||
180 | * into some number of rows, where each row is not longer than the | ||
181 | * specified width. | ||
182 | * | ||
183 | * If prefix is non-NULL, the first line is prepended with the prefix, | ||
184 | * and subsequent lines are indented to line up with the prefix. | ||
185 | * | ||
186 | * If word_boundary is TRUE, then attempt to only break lines on | ||
187 | * boundaries between words. | ||
188 | * | ||
189 | * XXX Note that we don't use nvalloc() or any of the other wrapper | ||
190 | * functions from here, so that this function doesn't require any | ||
191 | * non-c library symbols (so that it can be called from dlopen()'ed | ||
192 | * user interfaces. | ||
193 | */ | ||
194 | |||
195 | TextRows *nv_format_text_rows(const char *prefix, const char *str, | ||
196 | int width, int word_boundary) | ||
197 | { | ||
198 | int len, prefix_len, z, w, i; | ||
199 | char *line, *buf, *local_prefix, *a, *b, *c; | ||
200 | TextRows *t; | ||
201 | |||
202 | /* initialize the TextRows structure */ | ||
203 | |||
204 | t = (TextRows *) malloc(sizeof(TextRows)); | ||
205 | t->t = NULL; | ||
206 | t->n = 0; | ||
207 | t->m = 0; | ||
208 | |||
209 | if (!str) return t; | ||
210 | |||
211 | buf = strdup(str); | ||
212 | |||
213 | z = strlen(buf); /* length of entire string */ | ||
214 | a = buf; /* pointer to the start of the string */ | ||
215 | |||
216 | /* initialize the prefix fields */ | ||
217 | |||
218 | if (prefix) { | ||
219 | prefix_len = strlen(prefix); | ||
220 | local_prefix = nvstrdup(prefix); | ||
221 | } else { | ||
222 | prefix_len = 0; | ||
223 | local_prefix = NULL; | ||
224 | } | ||
225 | |||
226 | /* adjust the max width for any prefix */ | ||
227 | |||
228 | w = width - prefix_len; | ||
229 | |||
230 | do { | ||
231 | /* | ||
232 | * if the string will fit on one line, point b to the end of the | ||
233 | * string | ||
234 | */ | ||
235 | |||
236 | if (z < w) b = a + z; | ||
237 | |||
238 | /* | ||
239 | * if the string won't fit on one line, move b to where the | ||
240 | * end of the line should be, and then move b back until we | ||
241 | * find a space; if we don't find a space before we back b all | ||
242 | * the way up to a, just assign b to where the line should end. | ||
243 | */ | ||
244 | |||
245 | else { | ||
246 | b = a + w; | ||
247 | |||
248 | if (word_boundary) { | ||
249 | while ((b >= a) && (!isspace(*b))) b--; | ||
250 | if (b <= a) b = a + w; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /* look for any newline inbetween a and b, and move b to it */ | ||
255 | |||
256 | for (c = a; c < b; c++) if (*c == '\n') { b = c; break; } | ||
257 | |||
258 | /* | ||
259 | * copy the string that starts at a and ends at b, prepending | ||
260 | * with a prefix, if present | ||
261 | */ | ||
262 | |||
263 | len = b-a; | ||
264 | len += prefix_len; | ||
265 | line = (char *) malloc(len+1); | ||
266 | if (local_prefix) strncpy(line, local_prefix, prefix_len); | ||
267 | strncpy(line + prefix_len, a, len - prefix_len); | ||
268 | line[len] = '\0'; | ||
269 | |||
270 | /* append the new line to the array of text rows */ | ||
271 | |||
272 | t->t = (char **) realloc(t->t, sizeof(char *) * (t->n + 1)); | ||
273 | t->t[t->n] = line; | ||
274 | t->n++; | ||
275 | |||
276 | if (t->m < len) t->m = len; | ||
277 | |||
278 | /* | ||
279 | * adjust the length of the string and move the pointer to the | ||
280 | * beginning of the new line | ||
281 | */ | ||
282 | |||
283 | z -= (b - a + 1); | ||
284 | a = b + 1; | ||
285 | |||
286 | /* move to the first non whitespace character (excluding newlines) */ | ||
287 | |||
288 | if (word_boundary && isspace(*b)) { | ||
289 | while ((z) && (isspace(*a)) && (*a != '\n')) a++, z--; | ||
290 | } else { | ||
291 | if (!isspace(*b)) z++, a--; | ||
292 | } | ||
293 | |||
294 | if (local_prefix) { | ||
295 | for (i = 0; i < prefix_len; i++) local_prefix[i] = ' '; | ||
296 | } | ||
297 | |||
298 | } while (z > 0); | ||
299 | |||
300 | if (local_prefix) free(local_prefix); | ||
301 | free(buf); | ||
302 | |||
303 | return t; | ||
304 | |||
305 | } /* nv_format_text_rows() */ | ||
306 | |||
307 | |||
308 | |||
309 | /* | ||
310 | * nv_free_text_rows() - free the TextRows data structure allocated by | ||
311 | * nv_format_text_rows() | ||
312 | */ | ||
313 | |||
314 | void nv_free_text_rows(TextRows *t) | ||
315 | { | ||
316 | int i; | ||
317 | |||
318 | if (!t) return; | ||
319 | for (i = 0; i < t->n; i++) free(t->t[i]); | ||
320 | if (t->t) free(t->t); | ||
321 | free(t); | ||
322 | |||
323 | } /* nv_free_text_rows() */ | ||
diff --git a/format.h b/format.h deleted file mode 100644 index b9e1423..0000000 --- a/format.h +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | /* | ||
2 | * nvidia-installer: A tool for installing NVIDIA software packages on | ||
3 | * Unix and Linux systems. | ||
4 | * | ||
5 | * Copyright (C) 2003 NVIDIA Corporation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, see <http://www.gnu.org/licenses>. | ||
18 | * | ||
19 | * | ||
20 | * format.h | ||
21 | */ | ||
22 | |||
23 | #ifndef __NVIDIA_INSTALLER_FORMAT_H__ | ||
24 | #define __NVIDIA_INSTALLER_FORMAT_H__ | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <stdarg.h> | ||
28 | |||
29 | void reset_current_terminal_width(unsigned short new_val); | ||
30 | |||
31 | void fmtout(const char *fmt, ...); | ||
32 | void fmtoutp(const char *prefix, const char *fmt, ...); | ||
33 | void fmterr(const char *fmt, ...); | ||
34 | void fmterrp(const char *prefix, const char *fmt, ...); | ||
35 | void format(FILE *stream, const char *prefix, const char *fmt, ...); | ||
36 | |||
37 | TextRows *nv_format_text_rows(const char *prefix, const char *buf, | ||
38 | int width, int word_boundary); | ||
39 | void nv_free_text_rows(TextRows *t); | ||
40 | |||
41 | #endif /* __NVIDIA_INSTALLER_FORMAT_H__ */ | ||
diff --git a/gen-manpage-opts.c b/gen-manpage-opts.c index c821a31..0875828 100644 --- a/gen-manpage-opts.c +++ b/gen-manpage-opts.c | |||
@@ -5,119 +5,11 @@ | |||
5 | #include <ctype.h> | 5 | #include <ctype.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
8 | #include "nvidia-installer.h" | ||
9 | #include "option_table.h" | 8 | #include "option_table.h" |
9 | #include "gen-manpage-opts-helper.h" | ||
10 | 10 | ||
11 | static void print_option(const NVGetoptOption *o) | 11 | int main(void) |
12 | { | 12 | { |
13 | char scratch[64], *s; | 13 | gen_manpage_opts_helper(__options); |
14 | int j, len; | ||
15 | |||
16 | int omitWhiteSpace; | ||
17 | |||
18 | printf(".TP\n.BI "); | ||
19 | /* Print the name of the option */ | ||
20 | /* XXX We should backslashify the '-' characters in o->name. */ | ||
21 | if (o->flags & NVGETOPT_IS_BOOLEAN) { | ||
22 | /* "\-\-name, \-\-no\-name */ | ||
23 | printf("\"\\-\\-%s, \\-\\-no\\-%s", o->name, o->name); | ||
24 | } else if (isalnum(o->val)) { | ||
25 | /* "\-c, \-\-name */ | ||
26 | printf("\"\\-%c, \\-\\-%s", o->val, o->name); | ||
27 | } else { | ||
28 | /* "\-\-name */ | ||
29 | printf("\"\\-\\-%s", o->name); | ||
30 | } | ||
31 | |||
32 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
33 | len = strlen(o->name); | ||
34 | for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]); | ||
35 | scratch[len] = '\0'; | ||
36 | printf("=\" \"%s", scratch); | ||
37 | } | ||
38 | |||
39 | printf("\"\n"); | ||
40 | |||
41 | /* | ||
42 | * Print the option description: write each character one at a | ||
43 | * time (ugh) so that we can special-case a few characters: | ||
44 | * | ||
45 | * "[" --> "\n.I " | ||
46 | * "]" --> "\n" | ||
47 | * "-" --> "\-" | ||
48 | * | ||
49 | * Brackets are used to mark the text inbetween as italics. | ||
50 | * '-' is special cased so that we can backslashify it. | ||
51 | * | ||
52 | * XXX Each sentence should be on its own line! | ||
53 | */ | ||
54 | |||
55 | omitWhiteSpace = 0; | ||
56 | |||
57 | for (s = o->description; s && *s; s++) { | ||
58 | |||
59 | switch (*s) { | ||
60 | case '[': | ||
61 | printf("\n.I "); | ||
62 | omitWhiteSpace = 0; | ||
63 | break; | ||
64 | case ']': | ||
65 | printf("\n"); | ||
66 | omitWhiteSpace = 1; | ||
67 | break; | ||
68 | case '-': | ||
69 | printf("\\-"); | ||
70 | omitWhiteSpace = 0; | ||
71 | break; | ||
72 | case ' ': | ||
73 | if (!omitWhiteSpace) { | ||
74 | printf("%c", *s); | ||
75 | } | ||
76 | break; | ||
77 | default: | ||
78 | printf("%c", *s); | ||
79 | omitWhiteSpace = 0; | ||
80 | break; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | printf("\n"); | ||
85 | } | ||
86 | |||
87 | int main(int argc, char* argv[]) | ||
88 | { | ||
89 | int i; | ||
90 | const NVGetoptOption *o; | ||
91 | |||
92 | /* Print the "simple" options, i.e. the ones you get by running | ||
93 | * nvidia-installer --help. | ||
94 | */ | ||
95 | printf(".SH OPTIONS\n"); | ||
96 | for (i = 0; __options[i].name; i++) { | ||
97 | o = &__options[i]; | ||
98 | |||
99 | if (!(o->flags & NVGETOPT_HELP_ALWAYS)) | ||
100 | continue; | ||
101 | |||
102 | if (!o->description) | ||
103 | continue; | ||
104 | |||
105 | print_option(o); | ||
106 | } | ||
107 | |||
108 | /* Print the advanced options. */ | ||
109 | printf(".SH \"ADVANCED OPTIONS\"\n"); | ||
110 | for (i = 0; __options[i].name; i++) { | ||
111 | o = &__options[i]; | ||
112 | |||
113 | if (o->flags & NVGETOPT_HELP_ALWAYS) | ||
114 | continue; | ||
115 | |||
116 | if (!o->description) | ||
117 | continue; | ||
118 | |||
119 | print_option(o); | ||
120 | } | ||
121 | |||
122 | return 0; | 14 | return 0; |
123 | } | 15 | } |
diff --git a/help-args.c b/help-args.c deleted file mode 100644 index 824eda2..0000000 --- a/help-args.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* | ||
2 | * nvidia-installer: A tool for installing NVIDIA software packages on | ||
3 | * Unix and Linux systems. | ||
4 | * | ||
5 | * Copyright (C) 2003-2009 NVIDIA Corporation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, see <http://www.gnu.org/licenses>. | ||
18 | * | ||
19 | * | ||
20 | * help-args.c: this file contains a utility function that outputs the | ||
21 | * option table in a human readable format. | ||
22 | */ | ||
23 | |||
24 | #include <ctype.h> | ||
25 | #include <string.h> | ||
26 | #include <stdio.h> | ||
27 | |||
28 | #include "nvidia-installer.h" | ||
29 | #include "format.h" | ||
30 | |||
31 | #include "option_table.h" | ||
32 | |||
33 | /* | ||
34 | * cook_description() - the description string may contain text | ||
35 | * within brackets, which is used by the manpage generator | ||
36 | * to denote text to be italicized. We want to omit the bracket | ||
37 | * characters here. | ||
38 | */ | ||
39 | |||
40 | static char *cook_description(const char *description) | ||
41 | { | ||
42 | int len; | ||
43 | char *s, *dst; | ||
44 | const char *src; | ||
45 | |||
46 | len = strlen(description); | ||
47 | s = nvalloc(len + 1); | ||
48 | |||
49 | for (src = description, dst = s; *src; src++) { | ||
50 | if (*src != '[' && (*src != ']')) { | ||
51 | *dst = *src; | ||
52 | dst++; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | *dst = '\0'; | ||
57 | |||
58 | return s; | ||
59 | |||
60 | } /* cook_description() */ | ||
61 | |||
62 | |||
63 | |||
64 | void print_help_args_only(int is_uninstall, int args_only, int advanced) | ||
65 | { | ||
66 | int i, j, len; | ||
67 | char *msg, *tmp, scratch[64]; | ||
68 | const NVGetoptOption *o; | ||
69 | |||
70 | /* | ||
71 | * the args_only parameter is used by makeself.sh to get our | ||
72 | * argument list and description; in this case we don't | ||
73 | * want to format to the width of the terminal, so hardcode | ||
74 | * the width to 65. | ||
75 | */ | ||
76 | if (args_only) reset_current_terminal_width(65); | ||
77 | |||
78 | for (i = 0; __options[i].name; i++) { | ||
79 | o = &__options[i]; | ||
80 | |||
81 | /* | ||
82 | * if non-advanced help is requested, and the ALWAYS flag is | ||
83 | * not set, then skip this option | ||
84 | */ | ||
85 | |||
86 | if (!advanced && !(o->flags & NVGETOPT_HELP_ALWAYS)) continue; | ||
87 | |||
88 | /* Skip options with no help text */ | ||
89 | if (!o->description) continue; | ||
90 | |||
91 | /* Skip options that do not apply to nvidia-uninstall if we're | ||
92 | * invoked as nvidia-uninstall. */ | ||
93 | if (is_uninstall | ||
94 | && !(o->flags & NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL)) { | ||
95 | continue; | ||
96 | } | ||
97 | |||
98 | if (o->flags & NVGETOPT_IS_BOOLEAN) { | ||
99 | msg = nvstrcat("--", o->name, "/--no-", o->name, NULL); | ||
100 | } else if (isalnum(o->val)) { | ||
101 | sprintf(scratch, "%c", o->val); | ||
102 | msg = nvstrcat("-", scratch, ", --", o->name, NULL); | ||
103 | } else { | ||
104 | msg = nvstrcat("--", o->name, NULL); | ||
105 | } | ||
106 | if (o->flags & NVGETOPT_HAS_ARGUMENT) { | ||
107 | len = strlen(o->name); | ||
108 | for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]); | ||
109 | scratch[len] = '\0'; | ||
110 | tmp = nvstrcat(msg, "=", scratch, NULL); | ||
111 | nvfree(msg); | ||
112 | msg = tmp; | ||
113 | } | ||
114 | fmtoutp(TAB, msg); | ||
115 | if (o->description) { | ||
116 | tmp = cook_description(o->description); | ||
117 | fmtoutp(BIGTAB, tmp); | ||
118 | nvfree(tmp); | ||
119 | } | ||
120 | fmtout(""); | ||
121 | nvfree(msg); | ||
122 | } | ||
123 | } | ||
diff --git a/help-args.h b/help-args.h deleted file mode 100644 index 60a6d48..0000000 --- a/help-args.h +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* | ||
2 | * nvidia-installer: A tool for installing NVIDIA software packages on | ||
3 | * Unix and Linux systems. | ||
4 | * | ||
5 | * Copyright (C) 2003-2009 NVIDIA Corporation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, see <http://www.gnu.org/licenses>. | ||
18 | * | ||
19 | * | ||
20 | * nvidia-installer.h | ||
21 | */ | ||
22 | |||
23 | #ifndef __HELP_ARGS_H__ | ||
24 | #define __HELP_ARGS_H__ | ||
25 | |||
26 | void print_help_args_only(int is_uninstall, int args_only, int advanced); | ||
27 | |||
28 | #endif /* __HELP_ARGS_H__ */ | ||
diff --git a/install-from-cwd.c b/install-from-cwd.c index 671a5da..5fd8159 100644 --- a/install-from-cwd.c +++ b/install-from-cwd.c | |||
@@ -276,7 +276,7 @@ int install_from_cwd(Options *op) | |||
276 | "file will be backed up."); | 276 | "file will be backed up."); |
277 | 277 | ||
278 | if (ret) { | 278 | if (ret) { |
279 | ret = run_nvidia_xconfig(op); | 279 | ret = run_nvidia_xconfig(op, FALSE); |
280 | } | 280 | } |
281 | 281 | ||
282 | if (ret) { | 282 | if (ret) { |
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | #include "nvidia-installer.h" | 29 | #include "nvidia-installer.h" |
30 | #include "misc.h" | 30 | #include "misc.h" |
31 | #include "format.h" | ||
32 | 31 | ||
33 | /* global stream for log output */ | 32 | /* global stream for log output */ |
34 | 33 | ||
diff --git a/makeself-help-script.c b/makeself-help-script.c index de28611..47f8a9a 100644 --- a/makeself-help-script.c +++ b/makeself-help-script.c | |||
@@ -9,29 +9,50 @@ | |||
9 | #include <string.h> | 9 | #include <string.h> |
10 | 10 | ||
11 | #include "nvidia-installer.h" | 11 | #include "nvidia-installer.h" |
12 | #include "help-args.h" | 12 | #include "nvgetopt.h" |
13 | #include "option_table.h" | ||
13 | 14 | ||
14 | void print_usage(char **argv) | 15 | static void print_usage(char **argv) |
15 | { | 16 | { |
16 | fprintf(stderr, "usage: %s --help-args-only|" | 17 | fprintf(stderr, "usage: %s --help-args-only|" |
17 | "--advanced-options-args-only\n", argv[0]); | 18 | "--advanced-options-args-only\n", argv[0]); |
18 | } | 19 | } |
19 | 20 | ||
21 | static void print_help_helper(const char *name, const char *description) | ||
22 | { | ||
23 | fmtoutp(TAB, name); | ||
24 | fmtoutp(BIGTAB, description); | ||
25 | fmtout(""); | ||
26 | } | ||
27 | |||
20 | int main(int argc, char **argv) | 28 | int main(int argc, char **argv) |
21 | { | 29 | { |
30 | unsigned int include_mask = 0; | ||
31 | |||
22 | if (argc != 2) { | 32 | if (argc != 2) { |
23 | print_usage(argv); | 33 | print_usage(argv); |
24 | exit(1); | 34 | exit(1); |
25 | } | 35 | } |
26 | 36 | ||
27 | if (strcmp(argv[1], "--help-args-only") == 0) | 37 | /* |
28 | print_help_args_only(FALSE, TRUE, FALSE); | 38 | * We are printing help text for use by makeself.sh; we do not |
29 | else if (strcmp(argv[1], "--advanced-options-args-only") == 0) | 39 | * want this formatted to the width of the current terminal, so |
30 | print_help_args_only(FALSE, TRUE, TRUE); | 40 | * hardcode the width used by fmtout() to 65. |
31 | else { | 41 | */ |
42 | reset_current_terminal_width(65); | ||
43 | |||
44 | if (strcmp(argv[1], "--help-args-only") == 0) { | ||
45 | /* only print options with the ALWAYS flag */ | ||
46 | include_mask = NVGETOPT_HELP_ALWAYS; | ||
47 | } else if (strcmp(argv[1], "--advanced-options-args-only") == 0) { | ||
48 | /* print all options */ | ||
49 | include_mask = 0; | ||
50 | } else { | ||
32 | print_usage(argv); | 51 | print_usage(argv); |
33 | exit(1); | 52 | exit(1); |
34 | } | 53 | } |
35 | 54 | ||
55 | nvgetopt_print_help(__options, include_mask, print_help_helper); | ||
56 | |||
36 | return 0; | 57 | return 0; |
37 | } | 58 | } |
@@ -1723,8 +1723,7 @@ static int rtld_test_internal(Options *op, Package *p, | |||
1723 | if (!name) continue; | 1723 | if (!name) continue; |
1724 | 1724 | ||
1725 | s = strstr(name, ".so.1"); | 1725 | s = strstr(name, ".so.1"); |
1726 | if (!s) goto next; | 1726 | if (!s || s[strlen(".so.1")] != '\0') goto next; |
1727 | *(s + strlen(".so.1")) = '\0'; | ||
1728 | 1727 | ||
1729 | cmd = nvstrcat(op->utils[LDD], " ", tmpfile, " > ", tmpfile1, NULL); | 1728 | cmd = nvstrcat(op->utils[LDD], " ", tmpfile, " > ", tmpfile1, NULL); |
1730 | 1729 | ||
@@ -2332,24 +2331,28 @@ int check_selinux(Options *op) | |||
2332 | /* | 2331 | /* |
2333 | * run_nvidia_xconfig() - run the `nvidia-xconfig` utility. Without | 2332 | * run_nvidia_xconfig() - run the `nvidia-xconfig` utility. Without |
2334 | * any options, this will just make sure the X config file uses the | 2333 | * any options, this will just make sure the X config file uses the |
2335 | * NVIDIA driver by default. | 2334 | * NVIDIA driver by default. The restore parameter controls whether |
2335 | * the --restore-original-backup option is added, which attempts to | ||
2336 | * restore the original backed up X config file. | ||
2336 | */ | 2337 | */ |
2337 | 2338 | ||
2338 | int run_nvidia_xconfig(Options *op) | 2339 | int run_nvidia_xconfig(Options *op, int restore) |
2339 | { | 2340 | { |
2340 | int ret, bRet = TRUE; | 2341 | int ret, bRet = TRUE; |
2341 | char *data = NULL, *cmd; | 2342 | char *data = NULL, *cmd, *args; |
2343 | |||
2344 | args = restore ? " --restore-original-backup" : ""; | ||
2342 | 2345 | ||
2343 | cmd = find_system_util("nvidia-xconfig"); | 2346 | cmd = nvstrcat(find_system_util("nvidia-xconfig"), args, NULL); |
2344 | 2347 | ||
2345 | ret = run_command(op, cmd, &data, FALSE, FALSE, TRUE); | 2348 | ret = run_command(op, cmd, &data, FALSE, 0, TRUE); |
2346 | nvfree(cmd); | ||
2347 | 2349 | ||
2348 | if (ret != 0) { | 2350 | if (ret != 0) { |
2349 | ui_error(op, "Failed to run nvidia-xconfig:\n%s", data); | 2351 | ui_error(op, "Failed to run `%s`:\n%s", cmd, data); |
2350 | bRet = FALSE; | 2352 | bRet = FALSE; |
2351 | } | 2353 | } |
2352 | 2354 | ||
2355 | nvfree(cmd); | ||
2353 | nvfree(data); | 2356 | nvfree(data); |
2354 | 2357 | ||
2355 | return bRet; | 2358 | return bRet; |
@@ -30,41 +30,6 @@ | |||
30 | #include "nvidia-installer.h" | 30 | #include "nvidia-installer.h" |
31 | #include "command-list.h" | 31 | #include "command-list.h" |
32 | 32 | ||
33 | #define ARRAY_LEN(_arr) (sizeof(_arr) / sizeof(_arr[0])) | ||
34 | |||
35 | /* | ||
36 | * NV_VSNPRINTF() - takes a fmt string, and uses vsnprintf to build | ||
37 | * the resulting string whic it assigns to buf. The caller of this | ||
38 | * function is responsible for freeing the returned string. | ||
39 | */ | ||
40 | #define NV_VSNPRINTF(buf, fmt) \ | ||
41 | do { \ | ||
42 | if (!fmt) { \ | ||
43 | (buf) = NULL; \ | ||
44 | } else { \ | ||
45 | va_list ap; \ | ||
46 | int len, current_len = NV_LINE_LEN; \ | ||
47 | \ | ||
48 | (buf) = malloc(current_len); \ | ||
49 | \ | ||
50 | while (1) { \ | ||
51 | va_start(ap, fmt); \ | ||
52 | len = vsnprintf((buf), current_len, (fmt), ap); \ | ||
53 | va_end(ap); \ | ||
54 | \ | ||
55 | if ((len > -1) && (len < current_len)) { \ | ||
56 | break; \ | ||
57 | } else if (len > -1) { \ | ||
58 | current_len = len + 1; \ | ||
59 | } else { \ | ||
60 | current_len += NV_LINE_LEN; \ | ||
61 | } \ | ||
62 | \ | ||
63 | (buf) = realloc(buf, current_len); \ | ||
64 | } \ | ||
65 | } \ | ||
66 | } while (0) | ||
67 | |||
68 | char *read_next_word (char *buf, char **e); | 33 | char *read_next_word (char *buf, char **e); |
69 | 34 | ||
70 | int check_euid(Options *op); | 35 | int check_euid(Options *op); |
@@ -96,7 +61,7 @@ Distribution get_distribution(Options *op); | |||
96 | int check_for_running_x(Options *op); | 61 | int check_for_running_x(Options *op); |
97 | int check_for_modular_xorg(Options *op); | 62 | int check_for_modular_xorg(Options *op); |
98 | int check_for_nvidia_graphics_devices(Options *op, Package *p); | 63 | int check_for_nvidia_graphics_devices(Options *op, Package *p); |
99 | int run_nvidia_xconfig(Options *op); | 64 | int run_nvidia_xconfig(Options *op, int restore); |
100 | int run_distro_hook(Options *op, const char *hook); | 65 | int run_distro_hook(Options *op, const char *hook); |
101 | int check_for_nouveau(Options *op); | 66 | int check_for_nouveau(Options *op); |
102 | 67 | ||
diff --git a/mkprecompiled.c b/mkprecompiled.c index e1f23d5..0c75a9f 100644 --- a/mkprecompiled.c +++ b/mkprecompiled.c | |||
@@ -85,14 +85,13 @@ typedef struct { | |||
85 | 85 | ||
86 | #include "crc.h" | 86 | #include "crc.h" |
87 | 87 | ||
88 | |||
89 | /* | 88 | /* |
90 | * nv_alloc() - malloc wrapper that checks for errors, and zeros out | 89 | * nv_alloc() - malloc wrapper that checks for errors, and zeros out |
91 | * the memory; if an error occurs, an error is printed to stderr and | 90 | * the memory; if an error occurs, an error is printed to stderr and |
92 | * exit() is called -- this function will only return on success. | 91 | * exit() is called -- this function will only return on success. |
93 | */ | 92 | */ |
94 | 93 | ||
95 | void *nv_alloc (size_t size) | 94 | static void *nv_alloc (size_t size) |
96 | { | 95 | { |
97 | void *m = malloc (size); | 96 | void *m = malloc (size); |
98 | 97 | ||
@@ -110,11 +109,15 @@ void *nv_alloc (size_t size) | |||
110 | * XXX hack to resolve symbols used by crc.c | 109 | * XXX hack to resolve symbols used by crc.c |
111 | */ | 110 | */ |
112 | 111 | ||
112 | void *nvalloc(size_t size); | ||
113 | |||
113 | void *nvalloc(size_t size) | 114 | void *nvalloc(size_t size) |
114 | { | 115 | { |
115 | return nv_alloc(size); | 116 | return nv_alloc(size); |
116 | } | 117 | } |
117 | 118 | ||
119 | void ui_warn(Options *op, const char *fmt, ...); | ||
120 | |||
118 | void ui_warn(Options *op, const char *fmt, ...) | 121 | void ui_warn(Options *op, const char *fmt, ...) |
119 | { | 122 | { |
120 | va_list ap; | 123 | va_list ap; |
@@ -131,7 +134,7 @@ void ui_warn(Options *op, const char *fmt, ...) | |||
131 | * fails and calls exit(). This function only returns on success. | 134 | * fails and calls exit(). This function only returns on success. |
132 | */ | 135 | */ |
133 | 136 | ||
134 | int nv_open(const char *pathname, int flags, mode_t mode) | 137 | static int nv_open(const char *pathname, int flags, mode_t mode) |
135 | { | 138 | { |
136 | int fd; | 139 | int fd; |
137 | fd = open(pathname, flags, mode); | 140 | fd = open(pathname, flags, mode); |
@@ -152,7 +155,7 @@ int nv_open(const char *pathname, int flags, mode_t mode) | |||
152 | * on success. | 155 | * on success. |
153 | */ | 156 | */ |
154 | 157 | ||
155 | int nv_get_file_length(const char *filename) | 158 | static int nv_get_file_length(const char *filename) |
156 | { | 159 | { |
157 | struct stat stat_buf; | 160 | struct stat stat_buf; |
158 | int ret; | 161 | int ret; |
@@ -175,7 +178,7 @@ int nv_get_file_length(const char *filename) | |||
175 | * function only returns on success. | 178 | * function only returns on success. |
176 | */ | 179 | */ |
177 | 180 | ||
178 | void nv_set_file_length(const char *filename, int fd, int len) | 181 | static void nv_set_file_length(const char *filename, int fd, int len) |
179 | { | 182 | { |
180 | if ((lseek(fd, len - 1, SEEK_SET) == -1) || | 183 | if ((lseek(fd, len - 1, SEEK_SET) == -1) || |
181 | (write(fd, "", 1) == -1)) { | 184 | (write(fd, "", 1) == -1)) { |
@@ -192,7 +195,8 @@ void nv_set_file_length(const char *filename, int fd, int len) | |||
192 | * fails and calls exit(). This function only returns on success. | 195 | * fails and calls exit(). This function only returns on success. |
193 | */ | 196 | */ |
194 | 197 | ||
195 | void *nv_mmap(const char *filename, size_t len, int prot, int flags, int fd) | 198 | static void *nv_mmap(const char *filename, size_t len, int prot, |
199 | int flags, int fd) | ||
196 | { | 200 | { |
197 | void *ret; | 201 | void *ret; |
198 | 202 | ||
@@ -212,7 +216,7 @@ void *nv_mmap(const char *filename, size_t len, int prot, int flags, int fd) | |||
212 | * print_help() | 216 | * print_help() |
213 | */ | 217 | */ |
214 | 218 | ||
215 | void print_help(void) | 219 | static void print_help(void) |
216 | { | 220 | { |
217 | printf("\n%s [options] \n\n", BINNAME); | 221 | printf("\n%s [options] \n\n", BINNAME); |
218 | 222 | ||
@@ -254,7 +258,7 @@ void print_help(void) | |||
254 | * structure. | 258 | * structure. |
255 | */ | 259 | */ |
256 | 260 | ||
257 | Options *parse_commandline(int argc, char *argv[]) | 261 | static Options *parse_commandline(int argc, char *argv[]) |
258 | { | 262 | { |
259 | Options *op; | 263 | Options *op; |
260 | int c, option_index = 0; | 264 | int c, option_index = 0; |
@@ -336,7 +340,7 @@ Options *parse_commandline(int argc, char *argv[]) | |||
336 | 340 | ||
337 | 341 | ||
338 | 342 | ||
339 | char *read_proc_version(void) | 343 | static char *read_proc_version(void) |
340 | { | 344 | { |
341 | int fd, ret, len, version_len; | 345 | int fd, ret, len, version_len; |
342 | char *version, *c = NULL; | 346 | char *version, *c = NULL; |
@@ -390,7 +394,7 @@ char *read_proc_version(void) | |||
390 | * Returns 1 if the strings match, 0 if they don't match. | 394 | * Returns 1 if the strings match, 0 if they don't match. |
391 | */ | 395 | */ |
392 | 396 | ||
393 | int check_match(char *str) | 397 | static int check_match(char *str) |
394 | { | 398 | { |
395 | int ret = 0; | 399 | int ret = 0; |
396 | char *version = read_proc_version(); | 400 | char *version = read_proc_version(); |
@@ -416,7 +420,7 @@ int check_match(char *str) | |||
416 | * the integer to the data buffer. | 420 | * the integer to the data buffer. |
417 | */ | 421 | */ |
418 | 422 | ||
419 | void encode_uint32(uint32 val, uint8 data[4]) | 423 | static void encode_uint32(uint32 val, uint8 data[4]) |
420 | { | 424 | { |
421 | data[0] = ((val >> 0) & 0xff); | 425 | data[0] = ((val >> 0) & 0xff); |
422 | data[1] = ((val >> 8) & 0xff); | 426 | data[1] = ((val >> 8) & 0xff); |
@@ -432,7 +436,7 @@ void encode_uint32(uint32 val, uint8 data[4]) | |||
432 | * bytes, and build a uint32. | 436 | * bytes, and build a uint32. |
433 | */ | 437 | */ |
434 | 438 | ||
435 | uint32 decode_uint32(char *buf) | 439 | static uint32 decode_uint32(char *buf) |
436 | { | 440 | { |
437 | uint32 ret = 0; | 441 | uint32 ret = 0; |
438 | 442 | ||
@@ -460,7 +464,7 @@ uint32 decode_uint32(char *buf) | |||
460 | * string, and the proc version string. | 464 | * string, and the proc version string. |
461 | */ | 465 | */ |
462 | 466 | ||
463 | int pack(Options *op) | 467 | static int pack(Options *op) |
464 | { | 468 | { |
465 | int fd, offset, src_fd; | 469 | int fd, offset, src_fd; |
466 | uint8 *out, *src, data[4]; | 470 | uint8 *out, *src, data[4]; |
@@ -571,7 +575,7 @@ int pack(Options *op) | |||
571 | * unpack() - unpack the specified package | 575 | * unpack() - unpack the specified package |
572 | */ | 576 | */ |
573 | 577 | ||
574 | int unpack(Options *op) | 578 | static int unpack(Options *op) |
575 | { | 579 | { |
576 | int dst_fd, fd, ret, offset, len = 0; | 580 | int dst_fd, fd, ret, offset, len = 0; |
577 | char *buf, *dst; | 581 | char *buf, *dst; |
diff --git a/nvidia-installer.c b/nvidia-installer.c index 173e058..2f3d038 100644 --- a/nvidia-installer.c +++ b/nvidia-installer.c | |||
@@ -42,10 +42,8 @@ | |||
42 | #include "user-interface.h" | 42 | #include "user-interface.h" |
43 | #include "backup.h" | 43 | #include "backup.h" |
44 | #include "files.h" | 44 | #include "files.h" |
45 | #include "help-args.h" | ||
46 | #include "misc.h" | 45 | #include "misc.h" |
47 | #include "update.h" | 46 | #include "update.h" |
48 | #include "format.h" | ||
49 | #include "sanity.h" | 47 | #include "sanity.h" |
50 | #include "option_table.h" | 48 | #include "option_table.h" |
51 | 49 | ||
@@ -79,17 +77,40 @@ static void print_version(void) | |||
79 | * print_help() - print usage information | 77 | * print_help() - print usage information |
80 | */ | 78 | */ |
81 | 79 | ||
80 | static void print_help_helper(const char *name, const char *description) | ||
81 | { | ||
82 | fmtoutp(TAB, name); | ||
83 | fmtoutp(BIGTAB, description); | ||
84 | fmtout(""); | ||
85 | } | ||
86 | |||
87 | static void print_options(int is_uninstall, int advanced) | ||
88 | { | ||
89 | unsigned int include_mask = 0; | ||
90 | |||
91 | if (is_uninstall) { | ||
92 | /* only print options with the UNINSTALL flag */ | ||
93 | include_mask |= NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL; | ||
94 | } | ||
95 | |||
96 | if (!advanced) { | ||
97 | /* only print options with the ALWAYS flag */ | ||
98 | include_mask |= NVGETOPT_HELP_ALWAYS; | ||
99 | } | ||
100 | |||
101 | nvgetopt_print_help(__options, include_mask, print_help_helper); | ||
102 | } | ||
103 | |||
82 | static void print_help(const char* name, int is_uninstall, int advanced) | 104 | static void print_help(const char* name, int is_uninstall, int advanced) |
83 | { | 105 | { |
84 | print_version(); | 106 | print_version(); |
85 | 107 | ||
86 | fmtout(""); | 108 | fmtout(""); |
87 | fmtout("%s [options]", name); | 109 | fmtout("%s [options]", name); |
88 | fmtout(""); | 110 | fmtout(""); |
89 | |||
90 | print_help_args_only(is_uninstall, FALSE, advanced); | ||
91 | 111 | ||
92 | } /* print_help() */ | 112 | print_options(is_uninstall, advanced); |
113 | } | ||
93 | 114 | ||
94 | 115 | ||
95 | /* | 116 | /* |
@@ -264,7 +285,6 @@ static void parse_commandline(int argc, char *argv[], Options *op) | |||
264 | else if (strcasecmp(strval, "classic") == 0) | 285 | else if (strcasecmp(strval, "classic") == 0) |
265 | op->which_tls = FORCE_CLASSIC_TLS; | 286 | op->which_tls = FORCE_CLASSIC_TLS; |
266 | else { | 287 | else { |
267 | fmterr("\n"); | ||
268 | fmterr("Invalid parameter for '--force-tls'"); | 288 | fmterr("Invalid parameter for '--force-tls'"); |
269 | goto fail; | 289 | goto fail; |
270 | } | 290 | } |
@@ -276,7 +296,6 @@ static void parse_commandline(int argc, char *argv[], Options *op) | |||
276 | else if (strcasecmp(strval, "classic") == 0) | 296 | else if (strcasecmp(strval, "classic") == 0) |
277 | op->which_tls_compat32 = FORCE_CLASSIC_TLS; | 297 | op->which_tls_compat32 = FORCE_CLASSIC_TLS; |
278 | else { | 298 | else { |
279 | fmterr("\n"); | ||
280 | fmterr("Invalid parameter for '--force-tls-compat32'"); | 299 | fmterr("Invalid parameter for '--force-tls-compat32'"); |
281 | goto fail; | 300 | goto fail; |
282 | } | 301 | } |
@@ -322,7 +341,6 @@ static void parse_commandline(int argc, char *argv[], Options *op) | |||
322 | else if (strcasecmp(strval, "no") == 0) | 341 | else if (strcasecmp(strval, "no") == 0) |
323 | op->selinux_option = SELINUX_FORCE_NO; | 342 | op->selinux_option = SELINUX_FORCE_NO; |
324 | else if (strcasecmp(strval, "default")) { | 343 | else if (strcasecmp(strval, "default")) { |
325 | fmterr("\n"); | ||
326 | fmterr("Invalid parameter for '--force-selinux'"); | 344 | fmterr("Invalid parameter for '--force-selinux'"); |
327 | goto fail; | 345 | goto fail; |
328 | } | 346 | } |
@@ -375,7 +393,14 @@ static void parse_commandline(int argc, char *argv[], Options *op) | |||
375 | } | 393 | } |
376 | 394 | ||
377 | if (print_help_args_only_after) { | 395 | if (print_help_args_only_after) { |
378 | print_help_args_only(op->uninstall, TRUE, print_advanced_help); | 396 | /* |
397 | * We are printing help text for use by makeself.sh; we do not | ||
398 | * want this formatted to the width of the current terminal, | ||
399 | * so hardcode the width used by fmtout() to 65. | ||
400 | */ | ||
401 | reset_current_terminal_width(65); | ||
402 | |||
403 | print_options(op->uninstall, print_advanced_help); | ||
379 | exit(0); | 404 | exit(0); |
380 | } | 405 | } |
381 | 406 | ||
@@ -393,10 +418,8 @@ static void parse_commandline(int argc, char *argv[], Options *op) | |||
393 | return; | 418 | return; |
394 | 419 | ||
395 | fail: | 420 | fail: |
396 | fmterr("\n"); | ||
397 | fmterr("Invalid commandline, please run `%s --help` " | 421 | fmterr("Invalid commandline, please run `%s --help` " |
398 | "for usage information.", argv[0]); | 422 | "for usage information.", argv[0]); |
399 | fmterr("\n"); | ||
400 | nvfree((void*)op); | 423 | nvfree((void*)op); |
401 | exit(1); | 424 | exit(1); |
402 | } /* parse_commandline() */ | 425 | } /* parse_commandline() */ |
diff --git a/nvidia-installer.h b/nvidia-installer.h index 0361375..816a074 100644 --- a/nvidia-installer.h +++ b/nvidia-installer.h | |||
@@ -260,16 +260,6 @@ typedef struct __package { | |||
260 | } Package; | 260 | } Package; |
261 | 261 | ||
262 | 262 | ||
263 | |||
264 | typedef struct { | ||
265 | char **t; /* the text rows */ | ||
266 | int n; /* number of rows */ | ||
267 | int m; /* maximum row length */ | ||
268 | } TextRows; | ||
269 | |||
270 | |||
271 | |||
272 | |||
273 | /* flags for passing into install_from_cwd() */ | 263 | /* flags for passing into install_from_cwd() */ |
274 | 264 | ||
275 | #define ADJUST_CWD 0x01 | 265 | #define ADJUST_CWD 0x01 |
diff --git a/option_table.h b/option_table.h index 998fbd8..7f755ee 100644 --- a/option_table.h +++ b/option_table.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define __OPT_TABLE_H__ | 24 | #define __OPT_TABLE_H__ |
25 | 25 | ||
26 | #include "nvgetopt.h" | 26 | #include "nvgetopt.h" |
27 | #include "nvidia-installer.h" | ||
27 | 28 | ||
28 | #define NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL 0x00010000 | 29 | #define NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL 0x00010000 |
29 | 30 | ||
@@ -316,7 +317,7 @@ static const NVGetoptOption __options[] = { | |||
316 | { "ui", USER_INTERFACE_OPTION, | 317 | { "ui", USER_INTERFACE_OPTION, |
317 | NVGETOPT_STRING_ARGUMENT | NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL, | 318 | NVGETOPT_STRING_ARGUMENT | NVGETOPT_OPTION_APPLIES_TO_NVIDIA_UNINSTALL, |
318 | NULL, "Specify what user interface to use, if available. " | 319 | NULL, "Specify what user interface to use, if available. " |
319 | "Valid values for [UI] are 'ncurses' (the default) or 'none'. " | 320 | "Valid values for &UI& are 'ncurses' (the default) or 'none'. " |
320 | "If the ncurses interface fails to initialize, or 'none' " | 321 | "If the ncurses interface fails to initialize, or 'none' " |
321 | "is specified, then a simple printf/scanf interface will " | 322 | "is specified, then a simple printf/scanf interface will " |
322 | "be used." }, | 323 | "be used." }, |
@@ -341,7 +342,7 @@ static const NVGetoptOption __options[] = { | |||
341 | "nvidia-installer will select the OpenGL libraries appropriate " | 342 | "nvidia-installer will select the OpenGL libraries appropriate " |
342 | "for your system; however, you may use this option to force the " | 343 | "for your system; however, you may use this option to force the " |
343 | "installer to install one library type or another. Valid values " | 344 | "installer to install one library type or another. Valid values " |
344 | "for [FORCE-TLS] are 'new' and 'classic'." }, | 345 | "for &FORCE-TLS& are 'new' and 'classic'." }, |
345 | 346 | ||
346 | #if defined(NV_X86_64) | 347 | #if defined(NV_X86_64) |
347 | { "force-tls-compat32", FORCE_TLS_COMPAT32_OPTION, | 348 | { "force-tls-compat32", FORCE_TLS_COMPAT32_OPTION, |
@@ -353,14 +354,14 @@ static const NVGetoptOption __options[] = { | |||
353 | 354 | ||
354 | { "kernel-name", 'k', NVGETOPT_STRING_ARGUMENT, NULL, | 355 | { "kernel-name", 'k', NVGETOPT_STRING_ARGUMENT, NULL, |
355 | "Build and install the NVIDIA kernel module for the " | 356 | "Build and install the NVIDIA kernel module for the " |
356 | "non-running kernel specified by [KERNEL-NAME] ([KERNEL-NAME] " | 357 | "non-running kernel specified by &KERNEL-NAME& (&KERNEL-NAME& " |
357 | "should be the output of `uname -r` when the target kernel is " | 358 | "should be the output of `uname -r` when the target kernel is " |
358 | "actually running). This option implies " | 359 | "actually running). This option implies " |
359 | "'--no-precompiled-interface'. If the options " | 360 | "'--no-precompiled-interface'. If the options " |
360 | "'--kernel-install-path' and '--kernel-source-path' are not " | 361 | "'--kernel-install-path' and '--kernel-source-path' are not " |
361 | "given, then they will be inferred from [KERNEL-NAME]; eg: " | 362 | "given, then they will be inferred from &KERNEL-NAME&; eg: " |
362 | "'/lib/modules/[KERNEL-NAME]/kernel/drivers/video/' and " | 363 | "'/lib/modules/&KERNEL-NAME&/kernel/drivers/video/' and " |
363 | "'/lib/modules/[KERNEL-NAME]/build/', respectively." }, | 364 | "'/lib/modules/&KERNEL-NAME&/build/', respectively." }, |
364 | 365 | ||
365 | { "no-precompiled-interface", 'n', 0, NULL, | 366 | { "no-precompiled-interface", 'n', 0, NULL, |
366 | "Disable use of precompiled kernel interfaces." }, | 367 | "Disable use of precompiled kernel interfaces." }, |
@@ -464,7 +465,7 @@ static const NVGetoptOption __options[] = { | |||
464 | "use it to also clear the executable stack flag of the libraries. " | 465 | "use it to also clear the executable stack flag of the libraries. " |
465 | "Use this option to override nvidia-installer's detection of when " | 466 | "Use this option to override nvidia-installer's detection of when " |
466 | "to set the security type. " | 467 | "to set the security type. " |
467 | "Valid values for [FORCE-SELINUX] are 'yes' (force setting of the " | 468 | "Valid values for &FORCE-SELINUX& are 'yes' (force setting of the " |
468 | "security type), " | 469 | "security type), " |
469 | "'no' (prevent setting of the security type), and 'default' " | 470 | "'no' (prevent setting of the security type), and 'default' " |
470 | "(let nvidia-installer decide when to set the security type)." }, | 471 | "(let nvidia-installer decide when to set the security type)." }, |
@@ -514,7 +515,7 @@ static const NVGetoptOption __options[] = { | |||
514 | { "advanced-options-args-only", ADVANCED_OPTIONS_ARGS_ONLY_OPTION, 0, | 515 | { "advanced-options-args-only", ADVANCED_OPTIONS_ARGS_ONLY_OPTION, 0, |
515 | NULL, NULL }, | 516 | NULL, NULL }, |
516 | 517 | ||
517 | { NULL, 0, 0, NULL }, | 518 | { NULL, 0, 0, NULL, NULL }, |
518 | }; | 519 | }; |
519 | 520 | ||
520 | #endif /* __OPT_TABLE_H__ */ | 521 | #endif /* __OPT_TABLE_H__ */ |
diff --git a/stream-ui.c b/stream-ui.c index 2ca729f..be0326c 100644 --- a/stream-ui.c +++ b/stream-ui.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "nvidia-installer-ui.h" | 32 | #include "nvidia-installer-ui.h" |
33 | #include "misc.h" | 33 | #include "misc.h" |
34 | #include "files.h" | 34 | #include "files.h" |
35 | #include "format.h" | 35 | #include "common-utils.h" |
36 | 36 | ||
37 | /* prototypes of each of the stream ui functions */ | 37 | /* prototypes of each of the stream ui functions */ |
38 | 38 | ||
@@ -182,8 +182,8 @@ char *stream_get_input(Options *op, const char *def, const char *msg) | |||
182 | { | 182 | { |
183 | char *buf; | 183 | char *buf; |
184 | 184 | ||
185 | format(stdout, NULL, ""); | 185 | fmt(stdout, NULL, ""); |
186 | format(stdout, NULL, msg); | 186 | fmt(stdout, NULL, msg); |
187 | fprintf(stdout, " [default: '%s']: ", def); | 187 | fprintf(stdout, " [default: '%s']: ", def); |
188 | fflush(stdout); | 188 | fflush(stdout); |
189 | 189 | ||
@@ -271,9 +271,9 @@ void stream_message(Options *op, const int level, const char *msg) | |||
271 | 271 | ||
272 | if ((level == NV_MSG_LEVEL_LOG) && (d->status_active)) return; | 272 | if ((level == NV_MSG_LEVEL_LOG) && (d->status_active)) return; |
273 | 273 | ||
274 | if (msg_attrs[level].newline) format(msg_attrs[level].stream, NULL, ""); | 274 | if (msg_attrs[level].newline) fmt(msg_attrs[level].stream, NULL, ""); |
275 | format(msg_attrs[level].stream, msg_attrs[level].prefix, msg); | 275 | fmt(msg_attrs[level].stream, msg_attrs[level].prefix, msg); |
276 | if (msg_attrs[level].newline) format(msg_attrs[level].stream, NULL, ""); | 276 | if (msg_attrs[level].newline) fmt(msg_attrs[level].stream, NULL, ""); |
277 | 277 | ||
278 | } /* stream_message() */ | 278 | } /* stream_message() */ |
279 | 279 | ||
@@ -350,7 +350,7 @@ int stream_approve_command_list(Options *op, CommandList *cl, | |||
350 | 350 | ||
351 | default: | 351 | default: |
352 | 352 | ||
353 | fmterrp("ERROR: ", "Error in CommandList! (cmd: %d; s0: '%s';" | 353 | fmterr("Error in CommandList! (cmd: %d; s0: '%s';" |
354 | "s1: '%s'; s2: '%s'; mode: %04o)", | 354 | "s1: '%s'; s2: '%s'; mode: %04o)", |
355 | c->cmd, c->s0, c->s1, c->s2, c->mode); | 355 | c->cmd, c->s0, c->s1, c->s2, c->mode); |
356 | fmterr("Aborting installation."); | 356 | fmterr("Aborting installation."); |
@@ -383,8 +383,8 @@ int stream_yes_no(Options *op, const int def, const char *msg) | |||
383 | char *buf; | 383 | char *buf; |
384 | int eof, ret = def; | 384 | int eof, ret = def; |
385 | 385 | ||
386 | format(stdout, NULL, ""); | 386 | fmt(stdout, NULL, ""); |
387 | format(stdout, NULL, msg); | 387 | fmt(stdout, NULL, msg); |
388 | if (def) fprintf(stdout, " [default: (Y)es]: "); | 388 | if (def) fprintf(stdout, " [default: (Y)es]: "); |
389 | else fprintf(stdout, " [default: (N)o]: "); | 389 | else fprintf(stdout, " [default: (N)o]: "); |
390 | fflush(stdout); | 390 | fflush(stdout); |
diff --git a/user-interface.c b/user-interface.c index fe7001c..aff75a0 100644 --- a/user-interface.c +++ b/user-interface.c | |||
@@ -36,9 +36,8 @@ | |||
36 | #include "nvidia-installer.h" | 36 | #include "nvidia-installer.h" |
37 | #include "nvidia-installer-ui.h" | 37 | #include "nvidia-installer-ui.h" |
38 | #include "misc.h" | 38 | #include "misc.h" |
39 | #include "format.h" | ||
40 | #include "files.h" | 39 | #include "files.h" |
41 | 40 | #include "user-interface.h" | |
42 | 41 | ||
43 | /* | 42 | /* |
44 | * global user interface pointer | 43 | * global user interface pointer |
@@ -28,9 +28,10 @@ | |||
28 | 28 | ||
29 | CC ?= gcc | 29 | CC ?= gcc |
30 | LD ?= ld | 30 | LD ?= ld |
31 | CFLAGS ?= | 31 | # only set these warnings and optimizations if CFLAGS is unset |
32 | CFLAGS += -Wall -fno-strict-aliasing -Wno-unused-parameter | 32 | CFLAGS ?= -Wall -Wno-unused-parameter -O2 |
33 | CFLAGS += -O2 -fno-omit-frame-pointer | 33 | # always set these -f CFLAGS |
34 | CFLAGS += -fno-strict-aliasing -fno-omit-frame-pointer | ||
34 | CC_ONLY_CFLAGS ?= | 35 | CC_ONLY_CFLAGS ?= |
35 | LDFLAGS ?= | 36 | LDFLAGS ?= |
36 | BIN_LDFLAGS ?= | 37 | BIN_LDFLAGS ?= |
@@ -93,9 +94,9 @@ ifndef TARGET_ARCH | |||
93 | endif | 94 | endif |
94 | 95 | ||
95 | ifeq ($(TARGET_OS),Linux) | 96 | ifeq ($(TARGET_OS),Linux) |
96 | LIBDL_LDFLAGS = -ldl | 97 | LIBDL_LIBS = -ldl |
97 | else | 98 | else |
98 | LIBDL_LDFLAGS = | 99 | LIBDL_LIBS = |
99 | endif | 100 | endif |
100 | 101 | ||
101 | OUTPUTDIR ?= _out/$(TARGET_OS)_$(TARGET_ARCH) | 102 | OUTPUTDIR ?= _out/$(TARGET_OS)_$(TARGET_ARCH) |
@@ -124,11 +125,10 @@ endif | |||
124 | # the source tarball | 125 | # the source tarball |
125 | ############################################################################## | 126 | ############################################################################## |
126 | 127 | ||
127 | prefix = /usr/local | 128 | PREFIX ?= /usr/local |
128 | 129 | ||
129 | exec_prefix = $(prefix) | 130 | BINDIR = $(DESTDIR)$(PREFIX)/bin |
130 | bindir = $(exec_prefix)/bin | 131 | MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1 |
131 | mandir = $(exec_prefix)/share/man/man1 | ||
132 | 132 | ||
133 | 133 | ||
134 | ############################################################################## | 134 | ############################################################################## |
@@ -145,10 +145,16 @@ default build: all | |||
145 | # version.mk may be in one of two places: either in $(OUTPUTDIR) when | 145 | # version.mk may be in one of two places: either in $(OUTPUTDIR) when |
146 | # building as part of the NVIDIA driver build, or directly in the | 146 | # building as part of the NVIDIA driver build, or directly in the |
147 | # source directory when building from the source tarball | 147 | # source directory when building from the source tarball |
148 | # | ||
149 | # Throw an error if one of these two places did not define NVIDIA_VERSION. | ||
148 | ############################################################################## | 150 | ############################################################################## |
149 | 151 | ||
150 | include $(wildcard $(OUTPUTDIR)/version.mk version.mk) | 152 | VERSION_MK := $(wildcard $(OUTPUTDIR)/version.mk version.mk) |
153 | include $(VERSION_MK) | ||
151 | 154 | ||
155 | ifndef NVIDIA_VERSION | ||
156 | $(error NVIDIA_VERSION undefined) | ||
157 | endif | ||
152 | 158 | ||
153 | ############################################################################## | 159 | ############################################################################## |
154 | # to generate the dependency files, use the compiler's "-MM" option to | 160 | # to generate the dependency files, use the compiler's "-MM" option to |
@@ -260,7 +266,7 @@ BUILD_DEPENDENCY_LIST = \ | |||
260 | define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME | 266 | define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME |
261 | $(3): $(2) | 267 | $(3): $(2) |
262 | @$(MKDIR) $(OUTPUTDIR) | 268 | @$(MKDIR) $(OUTPUTDIR) |
263 | $$(call quiet_cmd,$(1)) -c $$< -o $$@ $$(CFLAGS) \ | 269 | $$(call quiet_cmd,$(1)) $$(CFLAGS) -c $$< -o $$@ \ |
264 | $(call AUTO_DEP_CMD,$(1),$(2),$(3)) | 270 | $(call AUTO_DEP_CMD,$(1),$(2),$(3)) |
265 | 271 | ||
266 | -include $$(call BUILD_DEPENDENCY_LIST,$(3)) | 272 | -include $$(call BUILD_DEPENDENCY_LIST,$(3)) |
@@ -298,7 +304,7 @@ define DEFINE_STAMP_C_RULE | |||
298 | 304 | ||
299 | $$(STAMP_C): $$(filter-out \ | 305 | $$(STAMP_C): $$(filter-out \ |
300 | $$(call BUILD_OBJECT_LIST,$$(STAMP_C)),$(1)) \ | 306 | $$(call BUILD_OBJECT_LIST,$$(STAMP_C)),$(1)) \ |
301 | $$(wildcard version.mk $$(OUTPUTDIR)/version.mk) | 307 | $$(VERSION_MK) |
302 | @ $$(RM) $$@ | 308 | @ $$(RM) $$@ |
303 | @ $$(PRINTF) "const char NV_ID[] = \"nvidia id: " >> $$@ | 309 | @ $$(PRINTF) "const char NV_ID[] = \"nvidia id: " >> $$@ |
304 | @ $$(PRINTF) "$(2): " >> $$@ | 310 | @ $$(PRINTF) "$(2): " >> $$@ |
@@ -1 +1 @@ | |||
NVIDIA_VERSION = 295.40 | NVIDIA_VERSION = 302.07 | ||