FIP Data Formatting Hints



this version 4a8/19j0



1.Make the output section readable


- split long lines over several ones each with the same test :

eg


r=22 "<TR><TD>" f1 "</TD><TD>" f2 "</TD><TD>" f3 "</TD><TD>" f4 "</TD></TR>"


is exactly the same as


r=22 "<TR><TD>"

r=22 f1

r=22 "</TD><TD>"

r=22 f2

r=22 "</TD><TD>"

r=22 f3

r=22 "</TD><TD>"

r=22 f4

r=22 "</TD></TR>"


2.QuoteMarks inside a String


Ouch

normally we use double quote marks around a string - to embed spaces and to signify THIS IS A STRING. So to add a quote you have to \" or \072 !


3.Tests


- What to do if you are not sure that the data is going to be consistent...

why not strip spaces and case from the test fields :

eg f3 could be 'SuperSonic', 'SUPER SONIC', 'super      sonics'

r=4 ifeq "SUPERSONIC" caps zapspc f3 x33



- Always check that you areas actually exist and have something in them before using 'ifeq' etc

r=4 ifnnul f3 ifnnul s66 ifeq f3 s66


4.Saves


- do not try builtins when saving - they are ignored

r=\b save=33 zapspc f4


- add more data to a save field with 'savcat' (save concatenate)

r=4 save=33 "And the winner is:"

r=4 savcat=33 f3

r=4 savcat=33 ", while the loser is:"

r=4 savcat=33 f4


5.Variable number of fields


- use ifnnul/ifnul to check for the presence of extra fields


r=44 f1 ":" f2 "=" f3 "."

r=44 ifnnul f4 TAB BOLD f4 ROMAN

r=44 ifnnul f5 TAB BOLD f5 ROMAN

r=44 ifnnul f6 TAB BOLD f6 ROMAN

r=44 ifnnul f7 TAB BOLD f7 ROMAN


6.Partials...


- it is good practise to always have an 's:0' as a first field as the eye does not always see preceeding spaces.

eg

partial:pname s:0 a:0 s:0 a:0 s:0

will put the 2words into p2 and p4 correctly for :

"Aaron Goldfelt"

"  Jimmy     Armfield     "

"                     Hummungeous Diddley"


- note that partials SKIP fields NOT data when a type of field is NOT correct.


Say we have data in a field (assume it is field 5) in the form of

"D 76 Big Daddy"

and want 3 fields :

D

76

Big Daddy


So we can break this up with

;                        D      76      Big Daddy

partial: p3fields   s:0 a:1 s:0 n:0 s:0 b:0

(note the stripping of spaces beforehand as mentioned above)


Gives (ignore the quotes) :

p1 blank

p2 "D"

p3 " "

p4 "76"

p5 " "

p6 "Big Daddy"


So in the output section:

r=AB p3fields f5

r=AB p6 " has a waist of " p4 " and intelligence rating " p2 ".\n"


But What if the data can also be "TEAM RATING" ?


Then the above partial will put :

p1 blank

p2 "T"

p3 blank

p4 blank

p5 blank

p6 "EAM RATING"


Why not check there is data in the middle fields ?


Mark 2 - in the output section:

r=AB p3fields f5

r=AB ifnnul p4 p6 " has a waist of " p4 " and intelligence rating " p2 ".\n"

r=AB ifnul p4 f1


7. What comes out is NOT what goes in !


If you do NOT specify anything, nothing will be output.



8. Why am I outputting some data twice ?


It means you have specified that data zone twice - field, save area, whatever


Remember THE OUTPUT SECTION lines are in ORDER OF EXECUTION not ORDER of DATA INPUT.

The order of the lines in the Output Section from the top down are in the order YOU want the data to be OUTPUT and are not connected to the way the data is input.


Just because the record read in is the last record, does NOT mean that the lines in the Output section handling it have to be the last few lines !


In fact for large files - 1mb plus there are big time savings to putting all the lines concerning the most-common input record-type/key at the top of the output section and using 'continue' to stop processing each one of these records as soon as it is possible.



Remember the way dataformats works is that :

a. the file is broken into records - usually lines

b. each record is then taken..

b.1 does it have a record key or type ?

b.2 if any field separator has been specified, break into fields

b.3 the key is compared to EVERY line in the OUTPUT section in descending order unless a 'continue' or a 'stop!' is encounted.

So to find out the offending line, take a record from the input file and check it against each line of the Output Section to find where data is output.


9. Close your tables


Always always end your tables  with an </TABLE>.


If you forget -

NetScape will not show any data

Any subsequent text and heading will float out of position.


10. Mixing Matches and firstmatches


Sometimes you need to do matches AND firstmatches on the same bit of output.


Matches are recursive remember ! So what you just replaced can be replaced (unlike 'ipxchg' which blocks off access).


Let us look at an example: AP uses {}|[]\ as fractions which we need to map to <frac>1/8</frac> etc.

But they also put in <=> as quads.


So what happens when you have a field which looks like

       00|Race 4 - Purse $30,000 7{ furlongs <

Lets assume you have several matches for fractions and the quads like

match: frac18  !{!<frac>1/8</frac>!

match: eatLT   +<++

etc

NOTE THE ORDER YOU SPECIFY THE MATCHES IS IMPORTANT!

you want to put the 'eatLT' BEFORE all the fractions else the '<' of the tags will be zapped too.

ie     r=00  eatLT eatGT eatEqual frac18 frac14 frac38 frac12 frac58 frac34 frac78 f1


If any of these are 'firstmatch', do the 'match' first as the processing will stop on the first valid 'firstmatch'.