configuration – ‘file’ command: specifying search depth for ‘search’ option in /etc/magic file?

How can I specify how far/deep the ‘file‘ command should search in a file to locate a match on a “search” definition ?

I am trying to create a universal specification in “/etc/magic” for multi-flavoured Prolog, so that I could do mass-transformation of imported predicate libraries for re-targeting to my personal environment for a project.

Having reviewed a number of the “target” files, I believe I would need to search within the first 3K characters of a file for this to be deemed reasonably successful as an approach.

So far I’ve tried these 2 flavours/definition, with no success:

(1) 0   search/3072 (Pp)(Rr)(Oo)(Ll)(Oo)(Gg)    Prolog Predicate File (ISO-Compliant Prolog), ASCII text 

and

(2) 0   search  (Pp)(Rr)(Oo)(Ll)(Oo)(Gg)    Prolog Predicate File (ISO-Compliant Prolog), ASCII text 

This second one is successful but only if the pattern is found in the first line of the file.

Also, I tried the following definitions:

(3) 0       search  :-      Prolog Predicate File (Non-Specific :-)

and

(4) 0      string  %       Prolog Predicate File (Non-Specific %), ASCII text

However, when I enter either of (3) or (4), below the entry for line (2), these seem to override the effectiveness of (2). Also, for some reason, regardless of order of precedence in the file, (3) seems to “overcome” any instance that, in my view should match up with (4).

This leads me to the question: How to tell the “file” command to exit on the first match encountered in my magic file and report that?

I have also defined this initial set of other specifications to normalize the files which will be massaged to conform:

0   string  %%Prolog    Prolog Predicate File (Non-Specific)
0   string  %%gprolog   Prolog Predicate File (GNU Prolog)
0   string  %%swipl     Prolog Predicate File (SWI-Prolog)
0   string  %%yap       Prolog Predicate File (YAP Prolog)
0   string  %%eclipse   Prolog Predicate File (ECLiPSe)
0   string  %%bprolog   Prolog Predicate File (B-Prolog)
0   string  %%poplog    Prolog Predicate File (Poplog)
0   string  %%lpaprolog Prolog Predicate File (LPA Prolog)
0   string  %%isoprolog Prolog Predicate File (ISO-Compliant Prolog)

I have created this last definition so that I may specifically tag those predicate files which I have confirmed as compliant with ISO Prolog specifications.

I do NOT want to use the “shebang” (i.e. #!/bin/gprolog) notation for first line auto-detection for execution.

(Additional) I just discovered a gotcha. How can I configure the installation to ensure any standard/builtin “shebang” notation is evaluated before my customized /etc/magic entries, but at the same time have my /etc/magic definitions be evaluated before any other magic sequences?

Guidance on search depth specification would be greatly appreciated.