changeset 2433:2fcd8d712b1e

More improvements to the grep mode.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 19 Feb 2020 18:25:50 +0200
parents 758223ba6551
children 0d86e7ff49e1
files tools/fanalyze.c
diffstat 1 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tools/fanalyze.c	Wed Feb 19 18:00:49 2020 +0200
+++ b/tools/fanalyze.c	Wed Feb 19 18:25:50 2020 +0200
@@ -107,6 +107,7 @@
 typedef struct
 {
     char *name;
+    char *desc;
     Uint32 nmax;
     unsigned int bsize;
 } DMGrepType;
@@ -114,11 +115,11 @@
 
 static const DMGrepType dmGrepTypes[DMGV_last] =
 {
-    { "8bit (byte)"      , (1ULL <<  8) - 1, 1 },
-    { "16bit (word) LE"  , (1ULL << 16) - 1, 2 },
-    { "16bit (word) BE"  , (1ULL << 16) - 1, 2 },
-    { "32bit (word) LE"  , (1ULL << 32) - 1, 4 },
-    { "32bit (word) BE"  , (1ULL << 32) - 1, 4 },
+    { "8"    , "8bit (byte)"      , (1ULL <<  8) - 1, 1 },
+    { "le16" , "16bit (word) LE"  , (1ULL << 16) - 1, 2 },
+    { "be16" , "16bit (word) BE"  , (1ULL << 16) - 1, 2 },
+    { "le32" , "32bit (word) LE"  , (1ULL << 32) - 1, 4 },
+    { "be32" , "32bit (word) BE"  , (1ULL << 32) - 1, 4 },
 };
 
 
@@ -155,6 +156,7 @@
 int            nsetGrepValues = 0;
 DMGrepValue    setGrepValues[SET_MAX_GREP_VALUES];
 size_t         optMinMatchLen = 8;
+BOOL           optOffsetMode = FALSE;
 
 DMMatchSeq dmSequences[SET_MAX_SEQUENCES];
 int ndmSequences = 0;
@@ -172,6 +174,8 @@
     { 12, 'o', "offset"          , "Show data in offset <offs>[,<offs2>...][:<le|be>[8|16|32][d|x]]", OPT_ARGREQ },
     { 14, 'm', "match"           , "Find matching sequences minimum of <n> bytes long", OPT_NONE },
     { 16, 'n', "minmatch"        , "Minimum match sequence length", OPT_ARGREQ },
+
+    { 18, 'O', "offset-mode"     , "Output -o offset list when in grep mode (-g)", OPT_NONE },
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -445,7 +449,7 @@
             ret = dmError(DMERR_INVALID_ARGS,
                 "Integer value %d <= %d <= %d out of range for type %s.\n",
                 val.values[n], 0, dmGrepTypes[val.type].nmax,
-                dmGrepTypes[val.type].name);
+                dmGrepTypes[val.type].desc);
 
             goto out;
         }
@@ -465,7 +469,7 @@
         if (mode == FA_GREP)
         {
             printf("Grep %s: ",
-                dmGrepTypes[val.type].name);
+                dmGrepTypes[val.type].desc);
 
             dmPrintGrepValueList(stdout, node, FALSE, NULL, 0);
             printf("\n");
@@ -523,6 +527,10 @@
             }
             return TRUE;
 
+        case 18:
+            optOffsetMode = TRUE;
+            break;
+
         default:
             dmErrorMsg("Unknown argument '%s'.\n", currArg);
             return FALSE;
@@ -719,6 +727,10 @@
             {
                 DMGrepValue *node = &setGrepValues[n];
                 const DMGrepType *def = &dmGrepTypes[node->type];
+                BOOL sep = FALSE;
+
+                if (optOffsetMode)
+                    printf("-o ");
 
                 for (size_t offs = 0; offs + (def->bsize * node->nvalues) < file->size; offs++)
                 {
@@ -738,15 +750,28 @@
 
                     if (match)
                     {
-                        printf("%08" DM_PRIx_SIZE_T, offs);
-                        if (dmVerbosity >= 1)
+                        if (optOffsetMode)
                         {
-                            printf(" : ");
-                            dmPrintGrepValueList(stdout, node, TRUE, file, offs);
+                            printf("%s0x%" DM_PRIx_SIZE_T, sep ? "," : "", offs);
+                            sep = TRUE;
                         }
-                        printf("\n");
+                        else
+                            printf("%08" DM_PRIx_SIZE_T, offs);
+
+                        if (!optOffsetMode)
+                        {
+                            if (dmVerbosity >= 1)
+                            {
+                                printf(" : ");
+                                dmPrintGrepValueList(stdout, node, TRUE, file, offs);
+                            }
+                            printf("\n");
+                        }
                     }
                 }
+
+                if (optOffsetMode)
+                    printf(":%s\n", def->name);
             }
         }
     }