aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-04-27 23:34:46 +0000
committerRob Landley <rob@landley.net>2006-04-27 23:34:46 +0000
commit7e21d5f6b1bdac9c20139e8bef82b17559e548a0 (patch)
tree08c1b12a37d2ef74b4471e154fe4227d3b6ae917 /applets
parentd5b9428bb6e9d7524f6ef24868ce6394ade08255 (diff)
downloadbusybox-w32-7e21d5f6b1bdac9c20139e8bef82b17559e548a0.tar.gz
busybox-w32-7e21d5f6b1bdac9c20139e8bef82b17559e548a0.tar.bz2
busybox-w32-7e21d5f6b1bdac9c20139e8bef82b17559e548a0.zip
Patch from Dennis Vlasenko to add the option to compress help text.
Diffstat (limited to 'applets')
-rw-r--r--applets/applets.c84
1 files changed, 61 insertions, 23 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 77e4fdbfe..387ddce84 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -32,24 +32,20 @@
32#include <assert.h> 32#include <assert.h>
33#include "busybox.h" 33#include "busybox.h"
34 34
35#if ENABLE_SHOW_USAGE 35#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
36const char usage_messages[] = 36static const char usage_messages[] =
37
38#define MAKE_USAGE 37#define MAKE_USAGE
39#include "usage.h" 38#include "usage.h"
40
41#include "applets.h" 39#include "applets.h"
42
43; 40;
44
45#undef MAKE_USAGE 41#undef MAKE_USAGE
46#endif /* ENABLE_SHOW_USAGE */ 42#endif /* ENABLE_SHOW_USAGE */
43
47#undef APPLET 44#undef APPLET
48#undef APPLET_NOUSAGE 45#undef APPLET_NOUSAGE
49#undef PROTOTYPES 46#undef PROTOTYPES
50#include "applets.h" 47#include "applets.h"
51 48
52
53static struct BB_applet *applet_using; 49static struct BB_applet *applet_using;
54 50
55/* The -1 arises because of the {0,NULL,0,-1} entry above. */ 51/* The -1 arises because of the {0,NULL,0,-1} entry above. */
@@ -405,27 +401,69 @@ static void check_suid (struct BB_applet *applet)
405 401
406 402
407 403
404#if ENABLE_FEATURE_COMPRESS_USAGE
408 405
406#include "usage_compressed.h"
407#include "unarchive.h"
409 408
410void bb_show_usage (void) 409static const char *unpack_usage_messages(void)
411{ 410{
412#if ENABLE_SHOW_USAGE 411 int input[2], output[2], pid;
413 const char *format_string; 412 char *buf;
414 const char *usage_string = usage_messages; 413
415 int i; 414 if(pipe(input) < 0 || pipe(output) < 0)
416 415 exit(1);
417 for (i = applet_using - applets; i > 0;) { 416
418 if (!*usage_string++) { 417 pid = fork();
419 --i; 418 switch (pid) {
419 case -1: /* error */
420 exit(1);
421 case 0: /* child */
422 close(input[1]);
423 close(output[0]);
424 uncompressStream(input[0], output[1]);
425 exit(0);
420 } 426 }
421 } 427 /* parent */
428
429 close(input[0]);
430 close(output[1]);
431 pid = fork();
432 switch (pid) {
433 case -1: /* error */
434 exit(1);
435 case 0: /* child */
436 bb_full_write(input[1], packed_usage, sizeof(packed_usage));
437 exit(0);
438 }
439 /* parent */
440 close(input[1]);
422 441
423 format_string = "%s\n\nUsage: %s %s\n\n"; 442 buf = xmalloc(SIZEOF_usage_messages);
424 if (*usage_string == '\b') 443 bb_full_read(output[0], buf, SIZEOF_usage_messages);
425 format_string = "%s\n\nNo help available.\n\n"; 444 return buf;
426 fprintf (stderr, format_string, bb_msg_full_version, applet_using->name, 445}
427 usage_string); 446
428#endif /* ENABLE_SHOW_USAGE */ 447#else
448#define unpack_usage_messages() usage_messages;
449#endif /* ENABLE_FEATURE_COMPRESS_USAGE */
450
451void bb_show_usage (void)
452{
453 if (ENABLE_SHOW_USAGE) {
454 const char *format_string;
455 const char *usage_string = unpack_usage_messages();
456 int i;
457
458 for (i = applet_using - applets; i > 0;)
459 if (!*usage_string++) --i;
460
461 format_string = "%s\n\nUsage: %s %s\n\n";
462 if (*usage_string == '\b')
463 format_string = "%s\n\nNo help available.\n\n";
464 fprintf (stderr, format_string, bb_msg_full_version,
465 applet_using->name, usage_string);
466 }
429 467
430 exit (bb_default_error_retval); 468 exit (bb_default_error_retval);
431} 469}