home *** CD-ROM | disk | FTP | other *** search
- /* ImportColumn.frx
- * Import an ascii file that is structured with columns
- * (seperated by spaces)
- * You have to create the fields in the database before using this
- * script!
- * Copyright © 1997 Nils Bandener
- * $VER: ImportColumn.frx 6.3 (6.10.97)
- */
-
- scriptname = "ImportColumn"
-
- Parse Arg File
- Options Results
-
- /*
- * If not called from Fiasco, try to address the active
- * Fiasco project
- */
-
- if ~abbrev(address(), "FIASCO.") then
- do
- ports = show("Ports")
-
- do i = 1 to words(ports)
-
- if abbrev(word(ports, i), "FIASCO.") then
- do
- P = word(ports, i)
-
- Address Value P
-
- GetAttr Project Name Active ARexx
-
- Address Value Result
-
- break
- end
- end
- end
-
- fiasco_port = address()
-
- Signal on Syntax
- Signal on Halt
- Signal on Break_C
- Signal on Failure
-
- LockGUI
-
- if File = "" then
- do
- RequestFile 'Var FILE'
-
- if rc ~= 0 then call bail_out
- end
-
- if Open("g", File, "read") then
- do
- SetStatus '"Scanning file..."'
-
- fieldcnt = 0
-
- do while ~eof("g")
-
- ln = readln("g")
-
- if ln ~= "" then
- do
- /* Ignore empty lines */
-
- if fieldcnt = 0 then
- do
- /* The first line is completely parsed */
-
- i = 1
- done = 0
-
- do while i <= length(ln) & ~done
-
- /* Search for a non-space character */
-
- txpos = verify(ln, " ", ,i)
-
- if txpos ~= 0 then
- do
- /* Search for a space */
-
- sppos = verify(ln, " ", "Match", txpos)
-
- if sppos = 0 then
- do
- endpos = length(ln)
-
- done = 1
- end
- else
- do
- endpos = verify(ln, " ", ,sppos) - 1
-
- if endpos = 0 then
- do
- endpos = length(ln)
-
- done = 1
- end
- end
-
- fieldcnt = fieldcnt + 1
-
- fields.fieldcnt.f_start = txpos
- fields.fieldcnt.f_end = endpos
- fields.fieldcnt.f_id = trim(substr(ln, txpos, endpos - txpos + 1))
-
- i = endpos + 1
- end
- else done = 1
- end
- end
- else
- do
- /* The following lines are used to verify the
- * structure data created using the first line
- */
-
- i = 1
-
- do while i <= fieldcnt
-
- ni = i + 1
-
- sppos = fields.i.f_start - 1
-
- if sppos > 0 then
- do
- if substr(ln, sppos, 1) ~= " " then
- do
- /* No space at this place,
- * this place is not a field
- * border
- */
-
- if i = 1 then
- do
- /* Special case for first field
- */
-
- fields.i.f_start = 1
- end
- else
- do
- /* Make one field
- * out of two fields
- */
-
- pi = i -1
-
- fields.pi.f_end = fields.i.f_end
- fields.pi.f_id = fields.pi.f_id || " " || fields.i.f_id
-
- /* Delete field at i
- */
-
- do k = i + 1 to fieldcnt
-
- pk = k - 1
-
- fields.pk.f_start = fields.k.f_start
- fields.pk.f_end = fields.k.f_end
- fields.pk.f_id = fields.k.f_id
- end
-
- fieldcnt = fieldcnt - 1
-
- ni = i
-
- end /* if i ~= 1 */
-
- end /* if substr ~= " " */
-
- end /* if sppos > 0 */
-
- i = ni
-
- end /* while i <= fieldcnt */
-
- end /* if fieldcnt ~= 0 */
-
- end /* if ln ~= "" */
-
- end /* do while ~eof() */
-
- goon = 1
-
- do while goon
-
- infostr = "Results from the file scan:*n"
-
- do i = 1 to fieldcnt
-
- infostr = infostr || "Field " || i || ": " || fields.i.f_id || ", Start: " || fields.i.f_start || ", End: " || fields.i.f_end || "*n"
-
- end
-
- infostr = infostr || "*nMake sure that you have created all required fields*nbefore you start importing"
-
- RequestChoice 'Body "' || infostr || '" Gadgets "Start Import|Change Field ID|Cancel" Title "ImportColumn"'
-
- if result = 2 then
- do
- RequestNumber 'Text "Please specify the number of the field:"' Var num
- if rc = 0 then
- do
- if num > 0 & num <= fieldcnt then
- do
- RequestString '"' || fields.num.f_id || '" Text "New ID:"'
-
- if rc = 0 then
- do
- fields.num.f_id = result
- end
- end
- end
- end
- else goon = 0
- end
-
- if result = 1 then
- do
-
- SetStatus '"Reading..."'
-
- call seek("g", 0, "Begin")
-
- ln = readln("g") /* Ignore first line */
-
- do while ~eof("g")
-
- ln = readln("g")
-
- if ln ~= "" then do
-
- AddRecord
-
- do i = 1 to fieldcnt
-
- data = trim(substr(ln, fields.i.f_start, fields.i.f_end - fields.i.f_start + 1))
-
- SetField '"' || fields.i.f_id || '" "' || data '"'
- end
- end
- end
- end
-
- call close("g")
- end
- else
- do
- RequestChoice '"Could not open ' || File || '" "Cancel" Title "ImportColumn.rexx"'
- end
-
-
-
- bail_out:
-
- Address Value fiasco_port
-
- UnlockGUI
- ResetStatus
-
- exit
-
- syntax:
- failure:
-
- if show("Ports", fiasco_port) then
- do
- Address Value fiasco_port
-
- RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
- end
- else
- do
- say "Error" rc "in line" sigl ":" errortext(rc)
- say "Enter to continue"
- pull dummy
- end
-
- call bail_out
-
- halt:
- break_c:
-
- if show("Ports", fiasco_port) then
- do
- Address Value fiasco_port
-
- RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
-
- if result = 0 then return
- end
- else
- do
- say "*** Break"
- say "Enter to continue"
- pull dummy
- end
-
- call bail_out
-
-
-