]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: color unit may now be longer than the corresponding format unit
authorOndrej Oprala <ooprala@redhat.com>
Fri, 21 Feb 2014 14:34:45 +0000 (15:34 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Mar 2014 11:48:59 +0000 (12:48 +0100)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
tests/expected/hexdump/highlighting-1b_octal-6
tests/expected/hexdump/highlighting-2b_dec-3
tests/ts/hexdump/highlighting
text-utils/hexdump-parse.c
text-utils/hexdump.1

index a5cc10bcf8d204756adaa158776b07f089caa057..8dca57ff2bab4e035418abb907e766de3ee22234 100644 (file)
@@ -1 +1,41 @@
-hexdump: bad byte count for conversion character _L
+0000000 000 040 001 040 002 040 003 040 004 040 005 040 006 040 007 040
+0000010 010 040 011 040 012 040 013 040 014 040 015 040 016 040 017 040
+0000020 020 040 021 040 022 040 023 040 024 040 025 040 026 040 027 040
+0000030 030 040 031 040 032 040 033 040 034 040 035 040 036 040 037 040
+0000040 040 040 041 040 042 040 043 040 044 040 045 040 046 040 047 040
+0000050 050 040 051 040 052 040 053 040 054 040 055 040 056 040 057 040
+0000060 060 040 061 040 062 040 063 040 064 040 065 040 066 040 067 040
+0000070 070 040 071 040 072 040 073 040 074 040 075 040 076 040 077 040
+0000080 100 040 101 040 102 040 103 040 104 040 105 040 106 040 107 040
+0000090 110 040 111 040 112 040 113 040 114 040 115 040 116 040 117 040
+00000a0 120 040 121 040 122 040 123 040 124 040 125 040 126 040 127 040
+00000b0 130 040 131 040 132 040 133 040 134 040 135 040 136 040 137 040
+00000c0 140 \e[31m040\e[0m \e[31m141\e[0m 040 142 040 143 040 144 040 145 040 146 040 147 040
+00000d0 150 040 151 040 152 040 153 040 154 040 155 040 156 040 157 040
+00000e0 160 040 161 040 162 040 163 040 164 040 165 040 166 040 167 040
+00000f0 170 040 171 040 172 040 173 040 174 040 175 040 176 040 177 040
+0000100 302 200 040 302 201 040 302 202 040 302 203 040 302 204 040 302
+0000110 205 040 302 206 040 302 207 040 302 210 040 302 211 040 302 212
+0000120 040 302 213 040 302 214 040 302 215 040 302 216 040 302 217 040
+0000130 302 220 040 302 221 040 302 222 040 302 223 040 302 224 040 302
+0000140 225 040 302 226 040 302 227 040 302 230 040 302 231 040 302 232
+0000150 040 302 233 040 302 234 040 302 235 040 302 236 040 302 237 040
+0000160 302 240 040 302 241 040 302 242 040 302 243 040 302 244 040 302
+0000170 245 040 302 246 040 302 247 040 302 250 040 302 251 040 302 252
+0000180 040 302 253 040 302 254 040 302 255 040 302 256 040 302 257 040
+0000190 302 260 040 302 261 040 302 262 040 302 263 040 302 264 040 302
+00001a0 265 040 302 266 040 302 267 040 302 270 040 302 271 040 302 272
+00001b0 040 302 273 040 302 274 040 302 275 040 302 276 040 302 277 040
+00001c0 303 200 040 303 201 040 303 202 040 303 203 040 303 204 040 303
+00001d0 205 040 303 206 040 303 207 040 303 210 040 303 211 040 303 212
+00001e0 040 303 213 040 303 214 040 303 215 040 303 216 040 303 217 040
+00001f0 303 220 040 303 221 040 303 222 040 303 223 040 303 224 040 303
+0000200 225 040 303 226 040 303 227 040 303 230 040 303 231 040 303 232
+0000210 040 303 233 040 303 234 040 303 235 040 303 236 040 303 237 040
+0000220 303 240 040 303 241 040 303 242 040 303 243 040 303 244 040 303
+0000230 245 040 303 246 040 303 247 040 303 250 040 303 251 040 303 252
+0000240 040 303 253 040 303 254 040 303 255 040 303 256 040 303 257 040
+0000250 303 260 040 303 261 040 303 262 040 303 263 040 303 264 040 303
+0000260 265 040 303 266 040 303 267 040 303 270 040 303 271 040 303 272
+0000270 040 303 273 040 303 274 040 303 275 040 303 276 040 303 277 040
+0000280
index a5cc10bcf8d204756adaa158776b07f089caa057..1872323b71a96f97876b3b0b6341306475b5b267 100644 (file)
@@ -1 +1,41 @@
-hexdump: bad byte count for conversion character _L
+0000000   08192   08193   08194   08195   08196   08197   08198   08199
+0000010   08200   08201   08202   08203   08204   08205   08206   08207
+0000020   08208   08209   08210   08211   08212   08213   08214   08215
+0000030   08216   08217   08218   08219   08220   08221   08222   08223
+0000040   08224   08225   08226   08227   08228   08229   08230   08231
+0000050   08232   08233   08234   08235   08236   08237   08238   08239
+0000060   08240 \e[31m  08241\e[0m   08242   08243   08244   08245   08246   08247
+0000070   08248   08249   08250   08251   08252   08253   08254   08255
+0000080   08256   08257   08258   08259   08260   08261   08262   08263
+0000090   08264   08265   08266   08267   08268   08269   08270   08271
+00000a0   08272   08273   08274   08275   08276   08277   08278   08279
+00000b0   08280   08281   08282   08283   08284   08285   08286   08287
+00000c0   08288   08289   08290   08291   08292   08293   08294   08295
+00000d0   08296   08297   08298   08299   08300   08301   08302   08303
+00000e0   08304   08305   08306   08307   08308   08309   08310   08311
+00000f0   08312   08313   08314   08315   08316   08317   08318   08319
+0000100   32962   49696   08321   33474   49696   08323   33986   49696
+0000110   08325   34498   49696   08327   35010   49696   08329   35522
+0000120   49696   08331   36034   49696   08333   36546   49696   08335
+0000130   37058   49696   08337   37570   49696   08339   38082   49696
+0000140   08341   38594   49696   08343   39106   49696   08345   39618
+0000150   49696   08347   40130   49696   08349   40642   49696   08351
+0000160   41154   49696   08353   41666   49696   08355   42178   49696
+0000170   08357   42690   49696   08359   43202   49696   08361   43714
+0000180   49696   08363   44226   49696   08365   44738   49696   08367
+0000190   45250   49696   08369   45762   49696   08371   46274   49696
+00001a0   08373   46786   49696   08375   47298   49696   08377   47810
+00001b0   49696   08379   48322   49696   08381   48834   49696   08383
+00001c0   32963   49952   08321   33475   49952   08323   33987   49952
+00001d0   08325   34499   49952   08327   35011   49952   08329   35523
+00001e0   49952   08331   36035   49952   08333   36547   49952   08335
+00001f0   37059   49952   08337   37571   49952   08339   38083   49952
+0000200   08341   38595   49952   08343   39107   49952   08345   39619
+0000210   49952   08347   40131   49952   08349   40643   49952   08351
+0000220   41155   49952   08353   41667   49952   08355   42179   49952
+0000230   08357   42691   49952   08359   43203   49952   08361   43715
+0000240   49952   08363   44227   49952   08365   44739   49952   08367
+0000250   45251   49952   08369   45763   49952   08371   46275   49952
+0000260   08373   46787   49952   08375   47299   49952   08377   47811
+0000270   49952   08379   48323   49952   08381   48835   49952   08383
+0000280
index f3b8c8172587e0edf5e5a8de17f53a3197e00e02..45d1a6c3f35f1c7d2937ec9cd1c8c92dd47cffa3 100755 (executable)
@@ -67,7 +67,7 @@ $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
        $FILES/ascii.in &> $TS_OUTPUT
 ts_finalize_subtest
 
-# highlight a range longer than the byte count of %o - error
+# highlight a range longer than the byte count of %o
 ts_init_subtest "1b_octal-6"
 $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
        -e '"%07.7_ax " 16/1 "%03o_L[red@193-194] " "\n"' \
@@ -150,7 +150,6 @@ $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
 ts_finalize_subtest
 
 # color the current print unit if some or all of the bytes it prints are at offsets 98 and 99
-# (false - range longer than format byte count)
 ts_init_subtest "2b_dec-3"
 $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
        -e '"%07.7_ax " 8/2 "  %05u_L[red@97-99] " "\n"' \
@@ -185,6 +184,13 @@ $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
        $FILES/ascii.in &> $TS_OUTPUT
 ts_finalize_subtest
 
+# color the current print unit if of the bytes it prints are at offsets 98-102 (multiple print units)
+ts_init_subtest "2b_dec-8"
+$TS_CMD_HEXDUMP $OPTS $ADDRFMT \
+       -e '"%07.7_ax " 8/2 "  %05u_L[red@98-102] " "\n"' \
+       $FILES/ascii.in &> $TS_OUTPUT
+ts_finalize_subtest
+
 # color the current print unit if some or all of the bytes it prints are at offsets 97 and 99 (true)
 ts_init_subtest "4b_dec-1"
 $TS_CMD_HEXDUMP $OPTS $ADDRFMT \
index 660dcce31cc3f1ac4c082ba31e0abb585e497539..22e397c918d06843a95253b95f3ead03d8e632e0 100644 (file)
@@ -565,8 +565,22 @@ static struct list_head *color_fmt(char *cfmt, int bcnt)
                                if (errno)
                                        badfmt(fmt);
                                /* offset range must be between 0 and format byte count */
-                               if (!(hcnext->range >= 0 && hcnext->range <= bcnt))
+                               if (hcnext->range < 0)
                                        badcnt("_L");
+                               /* the offset extends over several print units, clone
+                                * the condition, link it in and adjust the address/offset */
+                               while (hcnext->range > bcnt) {
+                                       hc = xcalloc(1, sizeof(struct hexdump_clr));
+                                       memcpy(hc, hcnext, sizeof(struct hexdump_clr));
+
+                                       hc->range = bcnt;
+
+                                       INIT_LIST_HEAD(&hc->colorlist);
+                                       list_add_tail(&hc->colorlist, ret_head);
+
+                                       hcnext->offt += bcnt;
+                                       hcnext->range -= bcnt;
+                               }
                        }
                /* no specific offset */
                } else
index edf5d6f9c6489cd370aaab958e50a6aeb2dc4528..89b0d9168a8fe80136fc31c4ab7e2b88a5a5e562 100644 (file)
@@ -264,8 +264,7 @@ interpreted by hexdump inside the color_units.
 .TP
 .B OFFSET
 An offset or an offset range at which to check for a match.  Please note
-that lone OFFSET_START uses the same value as END offset.  Also, the
-range may not be larger than the respective format byte count.
+that lone OFFSET_START uses the same value as END offset.
 .SS Counters
 The default and supported byte counts for the conversion characters
 are as follows: