busybox-1.14.2-ls.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. diff -urpN busybox-1.14.2/coreutils/ls.c busybox-1.14.2-ls/coreutils/ls.c
  2. --- busybox-1.14.2/coreutils/ls.c 2009-06-22 00:40:29.000000000 +0200
  3. +++ busybox-1.14.2-ls/coreutils/ls.c 2009-07-03 12:46:16.000000000 +0200
  4. @@ -144,8 +144,7 @@ static const char ls_options[] ALIGN1 =
  5. USE_FEATURE_LS_FOLLOWLINKS("L") /* 1, 24 */
  6. USE_FEATURE_LS_RECURSIVE("R") /* 1, 25 */
  7. USE_FEATURE_HUMAN_READABLE("h") /* 1, 26 */
  8. - USE_SELINUX("K") /* 1, 27 */
  9. - USE_SELINUX("Z") /* 1, 28 */
  10. + USE_SELINUX("KZ") /* 2, 28 */
  11. USE_FEATURE_AUTOWIDTH("T:w:") /* 2, 30 */
  12. ;
  13. enum {
  14. @@ -162,6 +161,16 @@ enum {
  15. OPT_Q = (1 << 10),
  16. //OPT_A = (1 << 11),
  17. //OPT_k = (1 << 12),
  18. + OPTBIT_color = 13
  19. + + 4 * ENABLE_FEATURE_LS_TIMESTAMPS
  20. + + 4 * ENABLE_FEATURE_LS_SORTFILES
  21. + + 2 * ENABLE_FEATURE_LS_FILETYPES
  22. + + 1 * ENABLE_FEATURE_LS_FOLLOWLINKS
  23. + + 1 * ENABLE_FEATURE_LS_RECURSIVE
  24. + + 1 * ENABLE_FEATURE_HUMAN_READABLE
  25. + + 2 * ENABLE_SELINUX
  26. + + 2 * ENABLE_FEATURE_AUTOWIDTH,
  27. + OPT_color = 1 << OPTBIT_color,
  28. };
  29. enum {
  30. @@ -889,16 +898,6 @@ static int list_single(const struct dnod
  31. }
  32. -/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
  33. -#if ENABLE_FEATURE_LS_COLOR
  34. -/* long option entry used only for --color, which has no short option
  35. - * equivalent */
  36. -static const char ls_color_opt[] ALIGN1 =
  37. - "color\0" Optional_argument "\xff" /* no short equivalent */
  38. - ;
  39. -#endif
  40. -
  41. -
  42. int ls_main(int argc UNUSED_PARAM, char **argv)
  43. {
  44. struct dnode **dnd;
  45. @@ -911,8 +910,25 @@ int ls_main(int argc UNUSED_PARAM, char
  46. int dnfiles;
  47. int dndirs;
  48. int i;
  49. +#if ENABLE_FEATURE_LS_COLOR
  50. + /* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
  51. + /* coreutils 6.10:
  52. + * # ls --color=BOGUS
  53. + * ls: invalid argument 'BOGUS' for '--color'
  54. + * Valid arguments are:
  55. + * 'always', 'yes', 'force'
  56. + * 'never', 'no', 'none'
  57. + * 'auto', 'tty', 'if-tty'
  58. + * (and substrings: "--color=alwa" work too)
  59. + */
  60. + static const char ls_longopts[] ALIGN1 =
  61. + "color\0" Optional_argument "\xff"; /* no short equivalent */
  62. + static const char color_str[] ALIGN1 =
  63. + "always\0""yes\0""force\0"
  64. + "auto\0""tty\0""if-tty\0";
  65. /* need to initialize since --color has _an optional_ argument */
  66. - USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
  67. + const char *color_opt = color_str; /* "always" */
  68. +#endif
  69. INIT_G();
  70. @@ -927,7 +943,7 @@ int ls_main(int argc UNUSED_PARAM, char
  71. #endif
  72. /* process options */
  73. - USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
  74. + USE_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
  75. #if ENABLE_FEATURE_AUTOWIDTH
  76. opt_complementary = "T+:w+"; /* -T N, -w N */
  77. opt = getopt32(argv, ls_options, &tabstops, &terminal_width
  78. @@ -966,13 +982,20 @@ int ls_main(int argc UNUSED_PARAM, char
  79. if (!p || (p[0] && strcmp(p, "none") != 0))
  80. show_color = 1;
  81. }
  82. - if (opt & (1 << i)) { /* next flag after short options */
  83. - if (strcmp("always", color_opt) == 0)
  84. - show_color = 1;
  85. - else if (strcmp("never", color_opt) == 0)
  86. + if (opt & OPT_color) {
  87. + if (color_opt[0] == 'n')
  88. show_color = 0;
  89. - else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
  90. - show_color = 1;
  91. + else switch (index_in_substrings(color_str, color_opt)) {
  92. + case 3:
  93. + case 4:
  94. + case 5:
  95. + if (isatty(STDOUT_FILENO)) {
  96. + case 0:
  97. + case 1:
  98. + case 2:
  99. + show_color = 1;
  100. + }
  101. + }
  102. }
  103. #endif
  104. diff -urpN busybox-1.14.2/testsuite/ls/ls-1-works busybox-1.14.2-ls/testsuite/ls/ls-1-works
  105. --- busybox-1.14.2/testsuite/ls/ls-1-works 2009-06-22 00:32:00.000000000 +0200
  106. +++ busybox-1.14.2-ls/testsuite/ls/ls-1-works 2009-07-02 14:28:45.000000000 +0200
  107. @@ -1,4 +1,4 @@
  108. [ -n "$d" ] || d=..
  109. -ls -1 "$d" > logfile.gnu
  110. -busybox ls -1 "$d" > logfile.bb
  111. -cmp logfile.gnu logfile.bb
  112. +LC_ALL=C ls -1 "$d" > logfile.gnu
  113. +LC_ALL=C busybox ls -1 "$d" > logfile.bb
  114. +diff -ubw logfile.gnu logfile.bb
  115. diff -urpN busybox-1.14.2/testsuite/ls/ls-h-works busybox-1.14.2-ls/testsuite/ls/ls-h-works
  116. --- busybox-1.14.2/testsuite/ls/ls-h-works 2009-06-22 00:32:00.000000000 +0200
  117. +++ busybox-1.14.2-ls/testsuite/ls/ls-h-works 2009-07-02 14:28:45.000000000 +0200
  118. @@ -1,4 +1,4 @@
  119. [ -n "$d" ] || d=..
  120. -ls -h "$d" > logfile.gnu
  121. -busybox ls -h "$d" > logfile.bb
  122. -cmp logfile.gnu logfile.bb
  123. +LC_ALL=C ls -h "$d" > logfile.gnu
  124. +LC_ALL=C busybox ls -h "$d" > logfile.bb
  125. +diff -ubw logfile.gnu logfile.bb
  126. diff -urpN busybox-1.14.2/testsuite/ls/ls-l-works busybox-1.14.2-ls/testsuite/ls/ls-l-works
  127. --- busybox-1.14.2/testsuite/ls/ls-l-works 2009-06-22 00:32:00.000000000 +0200
  128. +++ busybox-1.14.2-ls/testsuite/ls/ls-l-works 2009-07-02 14:28:45.000000000 +0200
  129. @@ -1,4 +1,4 @@
  130. [ -n "$d" ] || d=..
  131. LC_ALL=C ls -l "$d" > logfile.gnu
  132. -busybox ls -l "$d" > logfile.bb
  133. -diff -w logfile.gnu logfile.bb
  134. +LC_ALL=C busybox ls -l "$d" > logfile.bb
  135. +diff -ubw logfile.gnu logfile.bb
  136. diff -urpN busybox-1.14.2/testsuite/ls/ls-s-works busybox-1.14.2-ls/testsuite/ls/ls-s-works
  137. --- busybox-1.14.2/testsuite/ls/ls-s-works 2009-06-22 00:32:00.000000000 +0200
  138. +++ busybox-1.14.2-ls/testsuite/ls/ls-s-works 2009-07-02 14:28:45.000000000 +0200
  139. @@ -1,4 +1,4 @@
  140. [ -n "$d" ] || d=..
  141. LC_ALL=C ls -1s "$d" > logfile.gnu
  142. -busybox ls -1s "$d" > logfile.bb
  143. -cmp logfile.gnu logfile.bb
  144. +LC_ALL=C busybox ls -1s "$d" > logfile.bb
  145. +diff -ubw logfile.gnu logfile.bb