home *** CD-ROM | disk | FTP | other *** search
- /* This Arexx program builds a Twist files from a .SBD file of an existing
- Superbase file. It only creates the field list in the Twist file, it
- does NOT perform any record data import nor does it convert the record
- form.
-
- Since Twist and Superbase does not have exactly the same field types or
- field attributes such a conversion will always be an aproximation. The
- generated twist files may need to be manually adjusted afterwards (in
- the GUI open the Twist file and select "edit fields" from the .DB
- windows File menu).
-
- At a minimum the validation and calculation formulars need to be
- adjusted. Because Superbase uses a BASIC like syntax and Twist uses a
- C-style syntax the formulars are converted to a string constant.
-
- Also you might want to delete some of the index files, since they are
- not so strongly needed in Twist because Twist can search much faster in
- non-indexed fields.
-
- You are not encouraged to create the Twist file with the same path
- because this would overwrite the existing Superbase index files and
- thus Superbase can't open the files again.
-
- Full sequence of steps to take to convert a database file named ADDRESS
- from superbase to twist
-
- 1. Export a "ASCII Delimited" file from ADDRESS.SBF
- - Start superbase
- - Open the database file ADDRESS.SBD
- - Select "Export" from the Process menu
- - Klick on OK in the "Define Filter" to accept the empty selection
- (all records will be exported)
- - Choose "ASCII Delimited" as the export format and click OK
- - In the file requester enter "Twist:address.txt" Clik OK and
- exporting will commence.
-
- 2. Create a new Twist database file with the same field layout as
- ADDRESS.SBF
- - Open a shell window
- - Start Twist either from the shell by typing: run twist:twist2 or by
- double clicking the Twist icon on the WB
- - CD (change directory) to the path where ADDRESS.SBF is stored say
- Superbasepro4:myadr
- - Start the arexx program by entering:
-
- RX twist:arexx/sbd_to_twist address twist:address
-
- 3. Import the "ASCII Delimited file into the Twist database ADDRESS.DB
- - From the already started Twist program open the newly created file
- Twist:address.db
- - Select "Import..." from the record menu of the address.db window
- - Click on the file requester symbol next to the "Name" label and
- select the file "Twist:address.txt"
- - Select the radio button "Durch Komma getrennt" and the check box
- "Mehrzeilige Felder"
- - Klick on "Start" to begin importing.
-
- Hasse Wehner, Mermaid Group, 18th November 1994
- */
-
- parse arg sbdfullfilename twistfullfilename
- if upper(right(sbdfullfilename, 4)) == ".SBD" then sbdfullfilename = left(sbdfullfilename, length(sbdfullfilename)-4)
- if upper(right(twistfullfilename, 3)) == ".DB" then twistfullfilename = left(twistfullfilename, length(twistfullfilename)-3)
- if sbdfullfilename = "" then
- do
- say "Enter path to search for Superbase .SBD files"
- pull sbdpath
- say "Listing files in " sbdpath
- address command 'list' sbdpath
- say "Enter name of file .SBD file to use (without .SBD extention)"
- pull sbdname
- if sbdname == "" then exit
- if right(sbdpath,1) ~= ":" & right(sbdpath,1) ~= '/' & sbdpath ~= "" then sbdpath = sbdpath || '/'
- fullname = sbdpath || sbdname || ".SBD"
- end
- else
- do
- fullname = sbdfullfilename || ".SBD"
- end
- if twistfullfilename = "" then
- do
- say "Enter path in which to create Twist .DB files"
- pull twpath
- if right(twpath,1) ~= ":" & right(twpath,1) ~= '/' & twpath ~= "" then twpath = twpath || '/'
- twistfullfilename = sbdpath || sbdname
- end
- sbdopenok = open("sbdfile",fullname,'R')
- if sbdopenok then
- do
- address twist 'CREATEDB ' || twistfullfilename
- if RC~=0 then exit
- sbdline = readln("sbdfile")
- do until sbdline=""
- /* cut of trailing CR */
- if (c2d(right(sbdline,1)) = 13) then sbdline = left(sbdline, length(sbdline)-1)
-
- /* read valline if both valid and calcul lines. Cut trailing CR */
- if right(sbdline,2) = ">>" then valline = readln("sbdfile")
- else valline = ""
- if (c2d(right(valline,1)) = 13) then valline = left(valline, length(valline)-1)
-
- /* read last extra line. Cut trailing CR */
- if right(sbdline,1) = ">" then calcline = readln("sbdfile")
- else calcline = ""
- if (c2d(right(calcline,1)) = 13) then calcline = left(calcline, length(calcline)-1)
-
- sbdv.name = translate(trim(substr(sbdline,1,15)), "_", " ")
- sbdv.type = substr(sbdline,17,3)
- sbdv.calc = substr(sbdline,21,3)
- sbdv.rdo = substr(sbdline,25,3)
- sbdv.idx = substr(sbdline,29,3)
- sbdv.format= substr(sbdline,34,22)
- sbdv.line = substr(sbdline,57,3)
- sbdv.coloumn = substr(sbdline,61,3)
-
- cl = conv_calcstr(calcline)
- vl = conv_calcstr(valline)
- twtypestr = ""
-
- /* Try to get a somewhat sensible format string. */
- /* The Twist and Superbase formats are a lot different. At least the length of the field should be wright */
- formatstr = ""
- dotpos = pos(".",sbdv.format)
- select
- when left(sbdv.format,1)="L" then formatstr = substr(subword(sbdv.format,1,1),2) || " CMPR "
- when dotpos > 0 then
- do
- zeropos = pos("0", sbdv.format)
- ninepos = pos("9", sbdv.format)
- if zeropos = 0 & ninepos = 0 then digits = 0
- if zeropos > 0 & ninepos > 0 then digits = dotpos - min(zeropos,ninepos)
- if zeropos > 0 & ninepos = 0 then digits = dotpos - zeropos
- if zeropos = 0 & ninepos > 0 then digits = dotpos - ninepos
- decimals = length(subword(substr(sbdv.format, dotpos+1, 20),1,1))
- formatstr = digits || "." || decimals || " "
- end
- otherwise formatstr = subword(sbdv.format,1,1)
- end
-
- select
- when sbdv.type = "TXT" then twtypestr = formatstr || " TXT "
- when sbdv.type = "VTX" then twtypestr = formatstr || " TXT VIRT "
- when sbdv.type = "TIM" then twtypestr = "8 TXT " /* format string ignored */
- when sbdv.type = "EXT" then twtypestr = formatstr || " TXT "
- when sbdv.type = "LOG" then twtypestr = "01 INT "
- when sbdv.type = "NML" then twtypestr = formatstr || " INT "
- when sbdv.type = "NMI" then twtypestr = formatstr || " INT "
- when sbdv.type = "NUM" then twtypestr = formatstr || " FLT "
- when sbdv.type = "DAT" then twtypestr = "DATE " /* format string ignored */
- when sbdv.type = "VNU" then twtypestr = formatstr || " FLT VIRT "
- when sbdv.type = "VNL" then twtypestr = formatstr || " INT VIRT "
- when sbdv.type = "VNI" then twtypestr = formatstr || " INT VIRT "
- when sbdv.type = "VDA" then twtypestr = "DATE VIRT " /* format string is ignored */
- when sbdv.type = "VTI" then twtypestr = "8 TXT " /* format string is ignored */
- otherwise leave
- end
-
- select
- when sbdv.rdo = "RDQ" then twtypestr = twtypestr || "REQ NOED "
- when sbdv.rdo = "RDO" then twtypestr = twtypestr || "NOED "
- when sbdv.rdo = "REQ" then twtypestr = twtypestr || "REQ "
- otherwise ;
- end
-
- select
- when sbdv.idx = "IXD" then twtypestr = twtypestr || "IDX "
- when sbdv.idx = "IXU" then twtypestr = twtypestr || "IDX UNIQ "
- otherwise ;
- end
-
- select
- when sbdv.calc = "VAL" then twtypestr = twtypestr || "VALID " || cl
- when sbdv.calc = "CON" then twtypestr = twtypestr || "FIX CALC " || cl
- when sbdv.calc = "CLC" then twtypestr = twtypestr || "CALC " || cl
- when sbdv.calc = "CLV" then twtypestr = twtypestr || "CALC " || cl || " VALID " || vl
- when sbdv.calc = "COV" then twtypestr = twtypestr || "FIX CALC " || cl || " VALID " || vl
- otherwise ;
- end
-
- address twist 'CREATEFIELD ' sbdv.name || " " || twtypestr
-
- if eof("sbdfile") then leave
- sbdline = ""
- sbdline = readln("sbdfile")
- end
- address twist 'ENDCREATEDB'
- end
- exit
-
- conv_calcstr: PROCEDURE
- /* This procedure does not really convert a Superbase calculation/validation formula into Twist format
- (because that would be a ten-thousand-liner procedure).
- But it does convert it into a string constant that can be saved with the field in the Twist file.
- The user must change the formular into Twist syntax
- (and of course remove the outher quotations marks)
- */
- trace OFF
- parse arg calcstr
- slen = length(calcstr)
- if slen > 0 then
- do
- cl = '"\"'
- do i=1 to slen
- calcchr = substr(calcstr, i, 1);
- if calcchr = '"' then cl = cl || '\\\"'
- else cl = cl || calcchr
- end
- cl = cl || '\""'
- end
- else
- do
- cl = ""
- end
- trace Normal
- return cl
- /* end of conv_calcstr */
-
-