Table of Contents * Previous Chapter
For most use, configuration through the rc file will be sufficient. But you may decide that
you need to recognize additional information in the MIF file, or need new formatting
capabilities. Miftran has been designed to make it relatively easy to do this. This chapter
describes briefly how this is done.
Note that since the rc file is parsed by the same routines as the data file, the directions for
recognizing additional MIF constructs apply also to adding a new rc file command.
You can easily customize the C source for any of the following:
Miftran uses a table-driver parse to recognize specific constructs in its input stream. The
tables describe a tree structure which represents the nesting of the commands in the
input file. When the parser gets to a leaf of the tree, it executes a function associated
with that leaf to do the processing for that command. The function could do whatever
you want, but most functions so little more than invoking a translation command, whose
definition is specified in the rc file. In this way, miftran essentially takes the hierarchical
structure in a MIF file and presents it as a flat structure which is handled by the rc commands.
Flattening the structure of the input file in this way works quite well for the large majority of processing, and makes the user's job of specifying translations much simpler than
if he had to deal with the full hierarchy. If you want to recognize additional constructs in
a similar vein, and turn them into flattened commands, it should be pretty easy to do. If
you need to deal with the full hierarchy of the input structure, that's a lot more work, and
you're on your own.
To recognize another MIF construct, you must first know what the hierarchical specification for that construct it. To do this, you may have to slog through a couple of example
MIF files to see what they look like. Fortunately, MIF is a text format, so it's pretty easy
to browse through it with your favorite text editor.
Once you know the hierarchical structure of the command in MIF, you need to determine how much of that command (if any) is represented in the existing tables in miftran.
These tables are in the file
mtproc.c. For example, if you were trying to add the command
you would discover that
is already represented in the tables, so all you have to do is add a table entry for
<FUnderline> (to
FontTranTab in
mtproc.c). If, however, you wanted to recognize
you would discover that none of these are represented in the existing tables, so you
would have to add them all, starting with ConditionCatalog (in
TopTranTab in
mtproc.c).
Once you have determined which trantab (translation table, of type
MtSidTran[]) to
add your new keywords to, you need to add one table for each level of the command
hierarchy which does not already exist. Each line in the table specifies a command, and
refers to either another table, or (for the last command) a function to execute. Look the
existing trantabs in
mtproc.c to see how it's done.
After getting your tables set up, you are ready to write the action function which is
called from the final entry in your table. The function you will most likely want to call
from your action routine is
MtSubSid. For example, this is the function that is called
by
MtProcString to do the standard processing for text in the input file. Take a look
at that function (in mtproc.c) and the others for examples of how to process the data. In
most cases, your action routine should not have to be more than a few lines long. You
may have to add an additional MT_O_* definition, which goes at the beginning of
mtproc.c.
The RC commands are described in the file
mtrc.c. The
RcTranTab table lists the
commands and their action functions. To add another command, just add a line to that
table and write the associated action routine. Look at the existing action routines in
mtrc.c for examples.
Note that, since RC files are parsed with the same parser as MIF files, adding an RC
command is just a special case of recognizing an additional MIF construct, as described
in the previous section. This means that, if you really wanted to, you could add a hierarchical RC command using the same techniques as described for MIF files.
The format control characters are defined in the function
MtSubFmt in the file
mtfmt.c. There is a switch statement with a case for each valid character. Take a look
at that switch statement for examples.
Extended commands are defined in the table
MtXCmdTab in the file
mtfmt.c. You
can add a new extended command by adding a line to that table and writing the associated action function.
Register operations are defined in the file
mtop.c. The table
MtOpIntTab lists all of
the integer operations, and the table
MtOpStrTab lists all of the string operations. To
add a new operations, edit the appropriate table and add a new line with the operation
name and function. See the existing functions in that file for examples of how to implement new operation functions.
You can increase the number of registers available for use in % formatting commands.
The number of registers is controlled by the constant
NUMREGISTERS defined in
mtfmt.c. You can edit that file and change that definition, or define that number in the
makefile for miftran to be higher. You must recompile miftran with the higher value in
order to change the number of registers.
Table of Contents
* Previous Chapter
4 Advanced Customization
4.1 Recognizing an Additional MIF Construct
<TextFlow <Para <ParaLine <Font <FUnderline>>>>>
<TextFlow <Para <ParaLine <Font>>>>
<ConditionCatalog <Condition <CTag>>>
4.2 Adding an RC File Command
4.3 Adding Another Format Control Character
4.4 Changing the Number of Registers