* where is the error?

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

where is the error?

Post by Ron Melby » 30 Sep 2019 01:41

if gadr ~= prvgadr then
print(prvgadr)
print(gadr)
print(recno)
if recno == 114 then
debug = debug
end
cinter = CEMRCD[gadr].cinter --** attempt to index field '?' (a nil value)
.....

this code does quite a bit of the same piece of work until this record (173 lines) and that line is executed say 30 times in that time outputting:

[75] => " "
[76] => "* AUS.NSW.Cumberland Interments: 5 "
[77] => "* Rookwood General Cemeteries Reserve Trust, Hawthorne Avenue Rookwood Necropolis, Rookwood, NSW, 2141, AUS Interments: 2"
[78] => " DUNK, Henry Robert........................... M (1862 - 1937) www.findagrave.com/memorial/188632877 "
[79] => " DUNK, (JENKINS) Lyla......................... F (1860 - 1916) www.findagrave.com/memorial/188662166 "
[80] => "* Rookwood, Sydney, Cumberland, NSW, AUS Interments: 3"
[81] => " HUDSON, (DUNK) Nellie Edna................... F (1906 - 1988) "
[82] => " DUNK, David.................................. M (1838 - 1919) "
[83] => " JAENICKE, Regina Louise...................... F (1905 - 1996) "
[84] => " "
[85] => "* AUS.QLD.Ward Interments: 1 "
[86] => "* Beaudesert Cemetery, , Beaudesert, QLD, , AUS Interments: 1"
[87] => " SIBLEY, Levi B............................... M (1913 - 1993) www.findagrave.com/memorial/61069400 "
[88] => " "
[89] => "* AUS.VIC. Interments: 2 "
[90] => "* Williamstown Cemetery, Champion Road, Williamstown, VIC, 3016, AUS Interments: 2"
[91] => " HOOK, Sion................................... M (1849 - 1888) www.findagrave.com/memorial/153566015 "
[92] => " HOOK, Sion Richard........................... M (1879 - 1953) www.findagrave.com/memorial/153566018 "
[93] => " "

this is the record it fails on
GEDRCD[114] => (table .20)
sERA => "111846"
NAME => "DUNK, Fanny Watson"
SEX => "F"
LONG => "-1.06798"
RMN => "ð"e
GADR => "St. James Church, Butcher Row, Ratcliffe, Middlesex, , GBR"
WEB => ""
AGE => 1
iID => 4787
GPLC => "Ratcliffe, , Leicestershire, EN, GBR"
AREA => "GBR.EN.Leicestershire"
pGADR (item) => Address: St. James Church, Butcher Row, Ratcliffe, Middlesex, , GBR
iPTR (item) => Individual: Fanny Watson DUNK
ERA => "(1846 - 1847)"
pFaG (item) => Buried in Ratcliffe, , Leicestershire, EN, GBR
DRM => "ff"
PLOT => ""
MML => ""
LAT => "52.725108"
pGPLC (item) => Link to Place record (Ratcliffe, , Leicestershire, EN, GBR)

gadr:= St. James Church, Butcher Row, Ratcliffe, Middlesex, , GBR

CEMRCD[gadr]:=
St. James Church, Butcher Row, Ratcliffe, Middlesex, , GBR => (table .3)
addr => "St. James Church, Butcher Row, Ratcliffe, Middlesex, , GBR"
cinter => 2
area => "GBR.EN.Leicestershire"

the gadr comes from the GEDRCD
there is a cemrcd[gadr] that seems to match the gadr and has a cinter. however, the error says one of the two is not there, what is wrong must be right here where I am looking, but cannot find it, it seems everything is correct. Does anyone see the DUH?
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 30 Sep 2019 09:43

What I suggest is you temporarily use:

Code: Select all

if not CEMRCD[gadr] or not CEMRCD[gadr].cinter then
  local zz = 0
end
cinter = CEMRCD[gadr].cinter
Put a break point on local zz = 0 and debug CEMRCD[gadr] table values to see what is missing.
If table CENRCD is a global then you must tick Debug > Options > Display Global Types > Table to see it in the bottom right debug pane.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 30 Sep 2019 15:11

the problem is intervening spaces, something that is near indistiguishable on the debug screen. I am breaking and displaying gadr inside the if and going into editpadlite and fixing them.

I trim in my mat modules but not when I make the tables. I do not want the intervening spaces, since I see them as subtle errors so I am fixing them now. very easy to see in editpadlite, because I have a monospaced font.

I would like to have all FH in monospace, but some displays are not able to be customized.

I question why the error has ? instead of gadr which it obviously knows is what is in error.

ah, well.
FH V.6.2.7 Win 7 64 bit

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 30 Sep 2019 23:51

I have corrected every error I can, I am well satisfied with it excepting one thing, which may not be my problem.

whether or not I use fhSetStringEncoding('UTF-8')

cinter = CEMRCD[gadr].cinter
cinter = string.format('%3d', cinter)
prvgadr = gadr
pad = cwgadr - string.len(gadr)
gadr = gadr .. string.rep(' ', pad)

HDR2 = hlin .. gadr .. hburi .. cinter
pad = linlen - string.len(HDR2)
HDR2 = HDR2 .. string.rep( ' ', pad)
table.insert(PRTF, HDR2)

hlin, linlen, hburi (and because I pad the cinter) are for all intents and purposes constants.

whenever gadr contains non-English characters that is extra french, or norwegian letters the line length is shortened by the number of non-English characters and it does not pad out correctly (display or text). Is this an error in FH, or is this expected behavior by experts here? I can live with it, but not happily.

a paint of the file display even zipped is too large.
FH V.6.2.7 Win 7 64 bit

User avatar
ColeValleyGirl
Megastar
Posts: 1379
Joined: 28 Dec 2005 22:02
Family Historian: V6.2
Location: Cirencester, Gloucestershire
Contact:

Re: where is the error?

Post by ColeValleyGirl » 01 Oct 2019 05:28

The Lua 5.1 string library does NOT take UF8 into account, and you need to handle UF8 encoded strings with care. See Knowledge Base > Unicode UTF-8 Encoding -- accented characters are a particular problem.

You may wish to look at Knowledge Base > Unicode String Functions (code snippet) for code snippets that might help.

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 01 Oct 2019 08:00

It is not an error in FH, it is the way Lua works, which treats text strings as a sequence of bytes regardless of encoding.
So multi-byte UTF-8 characters are 2 or more bytes long, despite printing as a single character.

I cannot remember if string.format deals with that problem, so try:
gadr = string.format( '%-'..cwgadr..'s', gadr )

Otherwise, as Helen suggests, see the Knowledge Base > Unicode String Functions (code snippet) and use the second function length(strTxt) to supply character length of UTF-8 text.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 10:15

I cant have it both ways as yet.

i used encoder.StrUTF8_ANSI it lines up everything prints blocks for those letters on screen but renders them correctly in print files. I am on windows 7 64 bit.

fhOutputResultSetColumn('', 'text', PRTF, #PRTF, linlen, 'align_left')

you know where when you save results to file fh says do you wish to see the newly-created file? (no idea what the hypen is for, not a compound) but anyway does anyone have a code chunk that does that directly from lua? i could dispense with the fh output altogether. or how can I render the characters to the screen and the printfile correctly simultaneously? In my world, its not too bad a thing at present (dont have a huge number of non-English letters in my gedcom yet) but an annoyance none the less.
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 02 Oct 2019 10:40

It is definitely possible to render all UTF-8 characters correctly in whatever output medium you choose to use.
I do it in my Plugins all the time to files, screen, etc, but does require the appropriate UTF-8 options.

The Plugin script must use File > Encoding > UTF-8 or execute fhSetStringEncoding("UTF-8")
To get the IUP GUI Library to utilise UTF-8 encoding then execute iup.SetGlobal("UTF8MODE","YES")

As usual with your postings I have no idea what commands you are talking about that produce file or screen output.
Please post short examples of script you use and we might be able to advise.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 12:36

dsp = os.execute('start EditPadLite7.exe C:\\Users\\user\\Desktop\\CemArea.txt')


trying to get this command to block until epl7 is closed.

it continues on as if that is a separate thread (which it probably is.)

and what can I do about the nasty fluttery fh and cmd windows until the file comes up on screen?
Last edited by Ron Melby on 02 Oct 2019 12:50, edited 1 time in total.
FH V.6.2.7 Win 7 64 bit

User avatar
Jane
Site Admin
Posts: 7754
Joined: 01 Nov 2002 15:00
Family Historian: V6.2
Location: Somerset, England
Contact:

Re: where is the error?

Post by Jane » 02 Oct 2019 12:49

Remove the "Start" then.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 12:54

it doesnt execute then just continues on.
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 02 Oct 2019 13:28

How does that have anything to do with sending UTF-8 chars to file or screen ? :?

BTW: Have you bothered to read the Microsoft documentation for the start command?
https://docs.microsoft.com/en-us/window ... ands/start
Try using start /wait

I suspect it also needs /b

i.e. start /wait /b EditPadLite7.exe C:\\Users\\user\\Desktop\\CemArea.txt
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 7754
Joined: 01 Nov 2002 15:00
Family Historian: V6.2
Location: Somerset, England
Contact:

Re: where is the error?

Post by Jane » 02 Oct 2019 14:02

Doing the following waits for notepad to shut

Code: Select all

os.execute("notepad.exe")
fhmessagebox("I am here")
If your editor is not waiting it's possible it's doing some sort of release.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 02 Oct 2019 14:17

Where is EditPadLite7.exe installed?
It may be necessary to include the full path.

Perhaps try substituting notepad.exe for EditPadLite7.exe and see if that works as required.
If so, then you need to investigate why EditPadLite7.exe is different.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 16:10

the iup statement fixed the problem. now it displays correctly on screen and in file (but I had to use the length command from the snippet to justify it correctly). leads to an involved question, is there a way to easily test if there are characters that are non-ascii or whatever in the string for any TAG? then I could run thru the tags that contain them, and fix in all plugins. I know, NAME, PLAC, ADDR have it, I would expect that some of my NOTE[xxx] tags would have them too. I would guess it wouldn't hurt to do the utf8 len thing for all fields, but for example I transform Male and Female into M and F respectively, dates are going to not need it.... just textual type fields. I guess I can add them as I find them as well.

regarding what does this have to do with displaying utf8? its a simplification.
what happens, is I write a formatted file as txt. if I show the file in the plugin, then I simply have one chunk of code...
matDOC
if Opt == 'Print'
savestingtofile .....whatever
end
if Opt =='Display'
os.execute(texteditor 'whatever') ...in this case I would have to figure out where PRTF is....(I would imagine /tmp/
right now I would have to do something like...
os.execute(dlt 'whatever')
end

that would simplify what I am doing, in quite a few of my plugins. And be better output than the fhOutput in many cases.

However, I do have many plugins that use the good old fhOutput and will continue to do so, I want them displayed correctly.
FH V.6.2.7 Win 7 64 bit

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 16:16

and mike, no I did not see that blurb on the start command, the one I saw was much simpler, I will study that and see if I can use it.
FH V.6.2.7 Win 7 64 bit

User avatar
ColeValleyGirl
Megastar
Posts: 1379
Joined: 28 Dec 2005 22:02
Family Historian: V6.2
Location: Cirencester, Gloucestershire
Contact:

Re: where is the error?

Post by ColeValleyGirl » 02 Oct 2019 16:27

There is nowhere when an fH user can enter text that they can't enter UTF8 so you should assume all fields are potentially UTF8. Things selected from a predefined list like Gender are safe.

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 02 Oct 2019 20:35

Yes, all fields that can hold user entered text may have UTF-8 characters, even Date fields as they can contain a Date Phrase of free text.

The only way I can think of to test if a string has UTF-8 multi-byte characters is to compare length(strTxt) versus #strTxt and if equal then it does not, or if the former is less than the latter then it does, because length(strTxt) counts characters whereas #strTxt counts bytes.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 02 Oct 2019 21:16

the wait /b seems to have cleared up everything but the flash of the cmd window.

I cannot take measure of where PRTF (the table I use to print to) is in temp, but thats ok, I will just make a file in tmp and show that when it is display. still only use one formatter chunk for both.

I had thought the lenght(str) and #str would be it, and it looks like that is the only option at present, rather than sweat those things, I will find the fields I have in my file as the need arises, as I say, right now, I know of NAME, PLAC, ADDR.. I havent wrote out NOTE type fields yet, and will cross that bridge when I come to it.

Thanks all.
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 03 Oct 2019 09:48

I have realised there is a more efficient way of testing for UTF-8 characters in a string:
isUTF8 = strTxt:match("[%z\1-\127\194-\244][\128-\191]") ~= nil
That returns true or false depending on whether a UTF-8 character exists in strTxt.

FYI:
That pattern match is looking for character codes zero and 1 thru 127 and 194 thru 244 (i.e. [%z\1-\127\194-\244]) followed by codes 128 thru 191 (i.e. [\128-\191]) where those pairs of codes represent all the UTF-8 two byte characters.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 03 Oct 2019 13:08

when I am on the fhoutputresultcolumn display and select the save icon, and say for instance save as text, it names the file the plugin name I am running .. '.txt' how can I get my plugin name? if I use debug.getinfo the path has a temporary file and not the plugin name. is there a way to retrieve my plugin name?
CemArea.fh _lua
FH V.6.2.7 Win 7 64 bit

User avatar
ColeValleyGirl
Megastar
Posts: 1379
Joined: 28 Dec 2005 22:02
Family Historian: V6.2
Location: Cirencester, Gloucestershire
Contact:

Re: where is the error?

Post by ColeValleyGirl » 03 Oct 2019 13:27

Look at the documentation in the Family Historian Plugin help.

You want to use fhGetContextInfo to get the plugin name from within the plugin,

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 03 Oct 2019 13:50

I just found it myself. wasnt immediately apparent that it would be named that. I was using the more universal debug.getinfo(1, 'S'), and that was getting nowhere fast.

thank you.
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16654
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: where is the error?

Post by tatewise » 03 Oct 2019 13:59

Keep in mind the distinction between Lua features and FH features.
According to the Lua reference manual debug.getinfo(...) provides info about functions in the script.
So that won't help with Plugin filenames, which are a feature of FH so need an FH API function.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 440
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: where is the error?

Post by Ron Melby » 03 Oct 2019 17:15

str = debug.getinfo(1, 'S')
not in a function
will give the path, and the function must be the program, it appears that fh transforms it to something like fh47D.tmp which is what it shows on a debug error as well.

but not a problem, the other way works. I can now generalize the file paths and file names to print.

interestingly however to get a C:\akdfkasdkljsadf\sdafsdfakjlsdfklj\dasfkjsdafkjlsdf\fh47d.tmp
how would I find the LAST '\' in the string and strip out to the end? or alternatively, gsub up to and including that last '\'?
FH V.6.2.7 Win 7 64 bit

Post Reply