Syntax error... in the wrong place
Brian K. White
brian at aljex.com
Fri Mar 1 10:09:44 PST 2013
On 3/1/2013 12:04 PM, Jay Ashworth wrote:
> The table below is giving me a syntax error. the error is
>
> """
> Syntax error in line 21:
>
> ::new(to) = old(fr):
> ^
> """
>
> If you count, though, you'll find that line 21 is actually:
>
> ::import ascii old=(fn) r=^J f=|:
>
> inside the block labeled 'header', and indeed, that's the line dcabe
> leaves me on when I ack the error message.
>
> Any thoughts on what it doesn't like here? Import accepts an indirected
> variable for a filename these days right? fr isn't a reserved word?
>
> 'old' used to be called 'web', and I thought maybe *that* was reserved,
> so I changed it.
>
> Confused now.
>
> dcabe is 4.8.3K2D4. Yes, it's ancient. No, I can't change it.
>
> On a side note, is my plan for skipping the label line actually going
> to work? The semantics of IMPORT ASCII are "open if necessary, and
> then read a line every time you're called", correct?
>
> Cheers,
> -- jra
>
>
> ================8<=========================
> ::debug on:
> ::' webget/importreg - import the student reg file we're given with -r:
> ::':
> ::' jra at baylink.com - 17 Feb 2013:
> ::':
> data:::
> ::fn(80,*) ' name of the file (today's date):
> ::':
> start:::
> ::' this code is a "sit on record 1 and lookup free" table:
> ::' I don't much like those, but there's no other obvious way to import:
> ::' a variable length CSV file with IMPORT:
I use
rclerk fpfile -z table -sscreen -xa -u -r importfile
That puts you on a new record, even works the first time when the key is
0 bytes to start with. Then in processing near the beginning if there is
no actual data to import I delete the record I'm standing on. This
leaves a physical record created, empty, on the disk, but it's marked
deleted and fp will use it instead of creating a new physical record the
next time. Empty records will not pile up if you run it a zillion times
with no input data.
Then my table looks like this it imports 0 or more CSV records:
:' 20120223 brian at aljex.com - import pushfile transaction logs:' see
/u/aljex/bin/pushfile::
:' csv record format:'job#,user,desc,action,from,dest_good,dest_bad,opts:
:'TODO^A header/detail lists of related items as single task::
::import word web = (@pm):
:not web:delete ; exit:
:' TODO^A unique transaction number, needs central control field:1 = "0"
' like pro#, check# etc.:
::2 = web(1):
::3 = web(2):
::4 = web(3):
::5 = web(4):
::6 = web(5):
::7 = web(6):
::8 = web(7):
::9 = web(8):
::x =
writeline(ah,"Received^A"<getenv("HOSTNAME")<getenv("COMPANY")<@fi<@rn):
::end:
@once:'**************************************************************:video
off:
::af(128,*,g) = @pm{".ackout":
::system noredraw "umask 0;>"{af:
::ah(4,.0,g) = open(af,"wc0t"):
:ah lt "1":exit "3":
::end:
This is part of a simple cgi script that I use for flexible generic
open-ended system-to-system EDI.
The cgi script verifies authentication and collects a company name
(think pfdata+pfdir+pfqual), a fpfilename, a process table name from the
query string. It collects the payload data from post by catting stdin to
a temp file. The payload data may have any format since you write the
process table to read it. Then just runs the rclerk command above,
dropping the temp file name in -r and deleting it after rclerk runs.
The table above writes an output file as it goes and the cgi cats that
back to the http client but you can drop that of course. You can drop
the entire @once section and the writeline line.
The table above reads CSV with unix newlines.
If the input file doesn't exist or isn't readable, or is zero bytes of
has only blank likes, no problem. One new record is created, but if
there is no input for any of those reasons, then that new record is
marked deleted and rclerk exits. A hundred such bad starts would just
reuse that same empty record over and over again and the next good input
will use it for data. This actually always happens, including at the end
of importing one or more good records so the file will always have one
extra physical on disk record but marked deleted so it doesn't show up
anywhere else in filepro like in browses.
If the input file has a single record, or any number of records, it
works. There are no explicit commands that show it here, but when the
end statement is reached, processing jumps back to the top and a new
empty filepro file record is created, and the next time the import
statement is reached it reads the next line of the input file.
--
bkw
> ::':
> ::' REMEMBER - if there *is* no record 1, the code won't run:
> ::':
> ::' even first-er, get the filename from the command line:
> ::fn=@PM ' the -r argument must be a full path name, possibly quoted:
> ::':
> header:::
> ::' first skip the headers:
> ::import ascii old=(fn) r=^J f=|:
> ::':
> rloop:::
> ::' ok, now, lets get a record:
> ::import ascii old=(fn) r=^J f=|:
> :not web:end ' if import fails, we're done:
> ::' everything's ok, so get a free record:
> ::lookup new=webimport r=free -nx:
> :not new:show "@Couldn't get free record - disk full?"; exit:
> ::':
> rcopy:::
> ::' and copy the fields:
> ::' don't forget to flag which file the data's coming from:
> ::':
> :fn co "bricks":new(1) = "B":
> :fn co "online":new(1) = "O":
> ::ii(3,.0)="1":
> rloop:::
> ::' loop - actually pull in the records:
> ::' no parsing or edits here; that happens on post, kicking out failures:
> ::':
> ::' for (i=1; i<=29; i++):
> ::fr(3,.0) = ii; to(3,.0) = ii+"1" ' 1 field offset in webimport due to B/O flag:
> ::new(to) = old(fr):
> ::gosub special:
> ::show "@"<ii<|"{new(to){"| == |"{old(fr){"|":
> ::ii=ii+"1":
> :ii gt 29:goto rend:
> ::goto rloop:
> ::':
> rend:::
> ::' never know if we'll need wrap-up processing later:
> ::end:
> ::':
> special:::
> ::' process special fields:
> :fr eq "24" and web(fr) eq "Cash":new(to)="CA":
> :fr eq "24" and web(fr) eq "Check":new(to)="CK":
> :fr eq "24" and web(fr) eq "Money Order":new(to)="MO":
> ::':
> ::return:
> ::':
>
> ================8<=========================
>
More information about the Filepro-list
mailing list