* standard formatting system

Writing and using plugins for Version 5 and above.
Post Reply
User avatar
Ron Melby
Superstar
Posts: 400
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

standard formatting system

Post by Ron Melby » 06 Sep 2019 17:39

I am trying to come up with a system for formatting output data on screen or print:
I derive actual length of field in global variables per run via these type of statements, as I am materializing those fields, if a function is not called, the cwfield should not exist.

GEDRCD[#GEDRCD].NAME = Name
cwnam = cwnam or 0
cwnam = math.max(cwnam, #Name)


COLUMN WIDTH (actual length of field)
cwnam
cwera
cwsex
cwptr

DISPLAY WIDTH (length for fhOutputResultColumn)
dwnam
dwera
dwsex
dwptr

PRINT WIDTH(the 'parent' fields need special handling, but also semi standard lengths and formats, as well as standard length fields occur)
pwnam
pwera
pwsex

for display width the y = mx + b is used, where:

y = final len
m = cw fld
x = 4 (this is the constant provided by documentation)
b = a variable number of padding char from 0 .. n (in 4s, but constant for each individual cwfield always)

let y be an input field fld, and an output field result
let m be the cwfield
let x be mult
let b be add

a function can be:

function matlen(fld, mult, add, ----perhaps posn to left right center and whether to pad)
fld = (fld * mult) + add
return field
end

cwnam = matlen(cwnam, 4, 4)
cwsex = matlen(move(cwsex), 4, 0) -- move takes a field trims it, and pads a blank on either side, i.e. 'F' becomes ' F '

I have the functions
triml --remove leading spaces
trimr --remove trailing spaces
trimi --remove extra internal spaces
trime --remove leading and trailing spaces
trim -- remove leading, extra internal, trailing spaces

move routines that move the characters in the fieldlen, left, right, or center, and same functions with padding characters so that this can be done:

'a' can result in:
'a '
' a '
' a'



right now, I have to personally remember to keep track of this, and make a statement:
cwnam = (cwnam * 4) + 4 and so on (the b space is needed because I trim the Name of leading, interior and trailing spaces to normalize it because of situations where I want Sr. to appear before Jr. in a sort and several others)

and i want to create a less than gobbletygook system where I can store and retrieve the field lenght setups for display or printing per run.

I can do a:

matPrtLen()

if cwnam then
tlbNAME = {}
dwnam = matlen(cwnam, mult, add)
...
end

or

if not cwnam then
else
tlbNAME = {}
dwnam = matlen(cwnam, mult, add)
...
end

(not sure which statement works, but one of them will)

matDspLen()
**miracle occurs here**



so I am looking for an on the fly built table that would be easy for this, of course if I could get a field name directly ie: [cwnam] and not ['cwnam'], I wouldnt have to go thru a lot of that rigamarole..., could store the mult adds as well in a LENRCD( {??= {mult=4, add= 0}}) or something on that order.

but in any case, the ancillary transformations and sizes for each field are somewhat fixed for each case depending on whether I am printing or running them thru fhOutputResultColumn

the major issues I have that seem nefarious are mostly the how do I translate the field cwnam into a standard index of variable or some other clever way, and whether I can then from that build a format.string or generalized functions so it is easy to flip back and forth (I know that is amorphous) but would like to avoid several if then else if then else or if then elseif elsif elsif forever kind of code).

for instance, sex is standard built ' F ' cwptr is always 0 len its a pointer.
Name however in my reports depending on what it cuts, runs from 31 to 44, and for printing functions needs to be proportionally spaced to the stuff that follows it, on the same line for that run.
I am sure I have not fully explained this, so ask away....

Mike you say I make all my stuff to complex, and always show me a way to do 250 lines of code in 3 lines. LOL any shortcuts in code chunks you got?
FH V.6.2.7 Win 7 64 bit

Post Reply