TYPERULES(5)

๐Ÿ“ฆ
version 6.0.7 ยท 2 versions
  • 6.0.7 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 6.0.7 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– TYPERULES(5) ๐Ÿ’–

okay so this is the TYPERULES(5) page, straight out of the File Formats Manual, and it's all about typerules โ€” HylaFAX's file type identification and conversion rules. bestie, this is the glow-up guide for your fax server's taste in files. let's get into it ๐Ÿฆ‹


๐ŸŒธ NAME ๐ŸŒธ

typerules โ€” HylaFAX file type identification and conversion rules


โœจ DESCRIPTION โœจ

okay so here's the vibe check first: the HylaFAX server is picky. it only accepts three types of files for transmission as facsimile:

  • POSTSCRIPTยฎ files
  • PDF files
  • TIFF Class F (bilevel Group 3-encoded) files

that's it. that's the whole list. every other type of file has to be converted</> into one of those three formats before it gets to go anywhere. no exceptions, bestie ๐Ÿ’…

so what happens is, the facsimile submission program runs a set of rules against the contents of each input file. it uses those rules to figure out what the file's type is, and then to figure out how to convert it into something that's actually suitable for transmission. icon behaviour, honestly.

these rules live in the file /etc/hylafax/typerules โ€” an ASCII file that's patterned after the /etc/magic file used by the System V file(1) program. but (and this is important) there are significant differences, and they're noted below. don't just assume it's the same thing, iykyk.


๐Ÿงš how type rules actually work

type rules work by matching data patterns in a file โ€” typically patterns that show up in the first few bytes of the file (i.e. magic numbers). there are two types of rules:

  • primary rules โ€” the main character rules
  • secondary rules โ€” they specify additional rules to apply after a primary rule has been matched

when secondary rules are used, rule scanning continues up to the next primary type rule in the file. periodt.


๐ŸŽ€ the anatomy of a rule

each rule consists of a set of whitespace-separated fields:

     offset    datatype    match    result   command

if a line is terminated with a backslash character, the entry is continued on the next line with any leading whitespace characters compressed to a single space. ๐Ÿ’ซ

comments are marked with the `#` character; everything from there to the end of the line is discarded. gone. bye. ๐Ÿ™ˆ

secondary rules have a `>` character in the first column of the line; primary rules do not.


๐Ÿ’œ the fields, one by one

  • offset โ€” the byte offset in the file at which data should be extracted and compared to a matching string or value.
  • datatype โ€” the type of data value to extract at the specified offset, for comparison purposes. it's one of:
    • `byte` (8 bit unsigned number)
    • `short` (16 bit unsigned number)
    • `long` (32 bit unsigned number)
    • `string` (an array of bytes)
    • `istring` (a case-insensitive array of bytes)
    • `ascii` (an array of ASCII-only bytes)
  • match โ€” the value and the operation to use in matching; the value used is based on the datatype field. if value is `x`, then it's interpreted to mean match anything. otherwise the following operators are supported (where data is the value extracted from the file and value is specified in the match field) โ€” except for the types `string`, `istring`, and `ascii`:
=     data == value              !=    data != value
>     data > value               <     data < value
<=    data <= value              >=    data >= value
&     (data & value) == value    !     (data & value) != value
^     (data ^ value) != 0

if no operation is specified then `=` is used. (the default is the default, bestie ๐Ÿ’…)

for `string`, `istring`, and `ascii` no operator is allowed; the implicit operation is always `=`. in these cases, the field is terminated by a tab or end of line, not by `#`. characters in the field have their literal value; there are no C-style character escapes. none. zero. nada.

  • result โ€” one of `ps`, `tiff`, or `error` (case insensitive). the first two results specify whether the rule generates a POSTSCRIPT file or a TIFF/F file (Group 3-encoded bilevel data), respectively. the `error` result indicates that a file is unsuitable for transmission and, if supplied for transmission, should cause the job to be aborted with the command field used in an error message. ๐Ÿ˜ญ
  • command โ€” a command description that is expanded and passed to the shell to convert the input file to the result format (suitable for sending as facsimile). before the string is passed to the shell, it's scanned and the following `%` escape codes are substituted for:
    • `%i` โ€” input file name
    • `%o` โ€” output file name
    • `%r` โ€” output horizontal resolution in pixels/mm
    • `%R` โ€” output horizontal resolution in pixels/inch
    • `%v` โ€” output vertical resolution in lines/mm
    • `%V` โ€” output vertical resolution in lines/inch
    • `%f` โ€” data format, `1` for 1-d encoding or `2` for 2-d encoding
    • `%w` โ€” page width in pixels
    • `%W` โ€” page width in mm
    • `%l` โ€” page length in pixels
    • `%L` โ€” page length in mm
    • `%s` โ€” page size by name
    • `%F` โ€” the directory where HylaFAX filter programs reside
    • `%<x>` โ€” the <x> character (e.g. `%%` results in `%`)

see below for example uses of these codes. ๐Ÿ‘€


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

the following rules are used to match the formats that are handled directly by the server:

#offset   datatype    match          result    command
0         string      %!             ps                       # POSTSCRIPT
0         string      %PDF           ps                       # POSTSCRIPT by Ghostscript
0         short       0x4d4d         tiff                     # big-endian TIFF
0         short       0x4949         tiff                     # little-endian TIFF

these rules are used to process the ASCII version of IRIS Inventor database files while blocking the transmission of the binary format variant:

#offset   datatype    match          result    command
0         string      #Inventor V    error     IRIS Inventor file
>15       string      binary         error     binary IRIS Inventor file
>15       string      ascii          ps        %F/textfmt -fCourier-Bold -p11bp\
                                                   -U -q >%o <%i

this rule is typically the last entry in the file and is used to convert all unmatched ASCII data files to POSTSCRIPT:

#offset   datatype    match          result    command
0         ascii       x              ps        %F/textfmt -fCourier-Bold -p11bp -U -q >%o <%i

๐Ÿซถ NOTES ๐Ÿซถ

it is much better to convert data that is to be transmitted to POSTSCRIPT, because this data format permits the facsimile server to do the final imaging according to the optimal transfer parameters (resolution, binary encoding, etc.). like, genuinely, do this. it's the move. ๐Ÿ‘‘

it might be better to allow secondary rules to augment a primary rule rather than just replace them. this would allow, for example, command line options to be selected based on file type. (it's a thought. a vibe. a maybe. ๐Ÿงš)


โญ SEE ALSO โญ

sendfax(1), hylafax-client(1)


okay that's the whole page bestie, you ate ๐Ÿ’… this one's dated May 12, 1993 and it belongs to TYPERULES(5) โ€” go forth and convert responsibly, no cap ๐Ÿฆ‹โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from