home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Database / CBK-MT31.DMS / in.adf / arexx.lha / ARexx / sbd_to_twist.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-11-11  |  8.1 KB  |  218 lines

  1. /* This Arexx program builds a Twist files from a .SBD file of an existing
  2.    Superbase file. It only creates the field list in the Twist file, it
  3.    does NOT perform any record data import nor does it convert the record
  4.    form.
  5.  
  6.    Since Twist and Superbase does not have exactly the same field types or
  7.    field attributes such a conversion will always be an aproximation. The
  8.    generated twist files may need to be manually adjusted afterwards (in
  9.    the GUI open the Twist file and select "edit fields" from the .DB
  10.    windows File menu).
  11.  
  12.     At a minimum the validation and calculation formulars need to be
  13.    adjusted. Because Superbase uses a BASIC like syntax and Twist uses a
  14.    C-style syntax the formulars are converted to a string constant.
  15.  
  16.    Also you might want to delete some of the index files, since they are
  17.    not so strongly needed in Twist because Twist can search much faster in
  18.    non-indexed fields.
  19.  
  20.    You are not encouraged to create the Twist file with the same path
  21.    because this would overwrite the existing Superbase index files and
  22.    thus Superbase can't open the files again.
  23.  
  24.    Full sequence of steps to take to convert a database file named ADDRESS
  25.    from superbase to twist
  26.  
  27. 1. Export a "ASCII Delimited" file from ADDRESS.SBF
  28.    -  Start superbase
  29.    -  Open the database file ADDRESS.SBD
  30.    -  Select "Export" from the Process menu
  31.    -  Klick on OK in the "Define Filter" to accept the empty selection
  32.       (all records will be exported)
  33.    -  Choose "ASCII Delimited" as the export format and click OK
  34.    -  In the file requester enter "Twist:address.txt" Clik OK and
  35.       exporting will commence.
  36.  
  37. 2. Create a new Twist database file with the same field layout as
  38.    ADDRESS.SBF
  39.    -  Open a shell window
  40.    -  Start Twist either from the shell by typing: run twist:twist2 or by
  41.       double clicking the Twist icon on the WB
  42.    -  CD (change directory) to the path where ADDRESS.SBF is stored say
  43.       Superbasepro4:myadr
  44.    -  Start the arexx program by entering:
  45.  
  46.          RX twist:arexx/sbd_to_twist address twist:address
  47.  
  48. 3. Import the "ASCII Delimited file into the Twist database ADDRESS.DB
  49.    -  From the already started Twist program open the newly created file
  50.       Twist:address.db
  51.    -  Select "Import..." from the record menu of the address.db window
  52.    -  Click on the file requester symbol next to the "Name" label and
  53.       select the file "Twist:address.txt"
  54.    -  Select the radio button "Durch Komma getrennt" and the check box
  55.       "Mehrzeilige Felder"
  56.    -  Klick on "Start" to begin importing.
  57.  
  58. Hasse Wehner, Mermaid Group, 18th November 1994
  59. */
  60.  
  61. parse arg sbdfullfilename twistfullfilename
  62. if upper(right(sbdfullfilename, 4)) == ".SBD" then sbdfullfilename = left(sbdfullfilename, length(sbdfullfilename)-4)
  63. if upper(right(twistfullfilename, 3)) == ".DB" then twistfullfilename = left(twistfullfilename, length(twistfullfilename)-3)
  64. if sbdfullfilename = "" then
  65. do
  66.     say "Enter path to search for Superbase .SBD files"
  67.     pull sbdpath
  68.     say "Listing files in " sbdpath
  69.     address command 'list' sbdpath
  70.     say "Enter name of file .SBD file to use (without .SBD extention)"
  71.     pull sbdname
  72.     if sbdname == "" then exit
  73.     if right(sbdpath,1) ~= ":" & right(sbdpath,1) ~= '/' & sbdpath ~= "" then sbdpath = sbdpath || '/'
  74.     fullname = sbdpath || sbdname || ".SBD"
  75. end
  76. else
  77. do
  78.     fullname = sbdfullfilename || ".SBD"
  79. end
  80. if twistfullfilename = "" then
  81. do
  82.     say "Enter path in which to create Twist .DB files"
  83.     pull twpath
  84.     if right(twpath,1) ~= ":" & right(twpath,1) ~= '/' & twpath ~= "" then twpath = twpath || '/'
  85.     twistfullfilename = sbdpath || sbdname
  86. end
  87. sbdopenok = open("sbdfile",fullname,'R')
  88. if sbdopenok then
  89. do
  90.     address twist 'CREATEDB ' || twistfullfilename
  91.     if RC~=0 then exit
  92.     sbdline = readln("sbdfile")
  93.     do until sbdline=""
  94.         /* cut of trailing CR */
  95.         if (c2d(right(sbdline,1)) = 13) then sbdline = left(sbdline, length(sbdline)-1)
  96.  
  97.         /* read valline if both valid and calcul lines. Cut trailing CR */
  98.         if right(sbdline,2) = ">>" then valline = readln("sbdfile")
  99.         else valline = ""
  100.         if (c2d(right(valline,1)) = 13) then valline = left(valline, length(valline)-1)
  101.  
  102.         /* read last extra line. Cut trailing CR */
  103.         if right(sbdline,1) = ">" then calcline = readln("sbdfile")
  104.         else calcline = ""
  105.         if (c2d(right(calcline,1)) = 13) then calcline = left(calcline, length(calcline)-1)
  106.  
  107.         sbdv.name = translate(trim(substr(sbdline,1,15)), "_", " ")
  108.         sbdv.type = substr(sbdline,17,3)
  109.         sbdv.calc = substr(sbdline,21,3)
  110.         sbdv.rdo = substr(sbdline,25,3)
  111.         sbdv.idx = substr(sbdline,29,3)
  112.         sbdv.format= substr(sbdline,34,22)
  113.         sbdv.line = substr(sbdline,57,3)
  114.         sbdv.coloumn = substr(sbdline,61,3)
  115.  
  116.         cl = conv_calcstr(calcline)
  117.         vl = conv_calcstr(valline)
  118.         twtypestr = ""
  119.  
  120.         /* Try to get a somewhat sensible format string. */
  121.         /* The Twist and Superbase formats are a lot different. At least the length of the field should be wright */
  122.         formatstr = ""
  123.         dotpos = pos(".",sbdv.format)
  124.         select
  125.             when left(sbdv.format,1)="L" then formatstr = substr(subword(sbdv.format,1,1),2) || " CMPR "
  126.             when dotpos > 0 then
  127.             do
  128.                 zeropos = pos("0", sbdv.format)
  129.                 ninepos = pos("9", sbdv.format)
  130.                 if zeropos = 0 & ninepos = 0 then digits = 0
  131.                 if zeropos > 0 & ninepos > 0 then digits = dotpos - min(zeropos,ninepos)
  132.                 if zeropos > 0 & ninepos = 0 then digits = dotpos - zeropos
  133.                 if zeropos = 0 & ninepos > 0 then digits = dotpos - ninepos
  134.                 decimals = length(subword(substr(sbdv.format, dotpos+1, 20),1,1))
  135.                 formatstr = digits || "." || decimals || " "
  136.             end
  137.             otherwise formatstr = subword(sbdv.format,1,1)
  138.         end
  139.  
  140.         select
  141.             when sbdv.type = "TXT" then twtypestr = formatstr || " TXT "
  142.             when sbdv.type = "VTX" then twtypestr = formatstr || " TXT VIRT "
  143.             when sbdv.type = "TIM" then twtypestr = "8 TXT "    /* format string ignored */
  144.             when sbdv.type = "EXT" then twtypestr = formatstr || " TXT "
  145.             when sbdv.type = "LOG" then twtypestr = "01 INT "
  146.             when sbdv.type = "NML" then twtypestr = formatstr || " INT "
  147.             when sbdv.type = "NMI" then twtypestr = formatstr || " INT "
  148.             when sbdv.type = "NUM" then twtypestr = formatstr || " FLT "
  149.             when sbdv.type = "DAT" then twtypestr = "DATE "  /* format string ignored */
  150.             when sbdv.type = "VNU" then twtypestr = formatstr || " FLT VIRT "
  151.             when sbdv.type = "VNL" then twtypestr = formatstr || " INT VIRT "
  152.             when sbdv.type = "VNI" then twtypestr = formatstr || " INT VIRT "
  153.             when sbdv.type = "VDA" then twtypestr = "DATE VIRT " /* format string is ignored */
  154.             when sbdv.type = "VTI" then twtypestr = "8 TXT " /* format string is ignored */
  155.             otherwise leave
  156.         end
  157.  
  158.         select
  159.             when sbdv.rdo = "RDQ" then twtypestr = twtypestr || "REQ NOED "
  160.             when sbdv.rdo = "RDO" then twtypestr = twtypestr || "NOED "
  161.             when sbdv.rdo = "REQ" then twtypestr = twtypestr || "REQ "
  162.             otherwise ;
  163.         end
  164.  
  165.         select
  166.             when sbdv.idx = "IXD" then twtypestr = twtypestr || "IDX "
  167.             when sbdv.idx = "IXU" then twtypestr = twtypestr || "IDX UNIQ "
  168.             otherwise ;
  169.         end
  170.  
  171.         select
  172.             when sbdv.calc = "VAL" then twtypestr = twtypestr || "VALID " || cl
  173.             when sbdv.calc = "CON" then twtypestr = twtypestr || "FIX CALC " || cl
  174.             when sbdv.calc = "CLC" then twtypestr = twtypestr || "CALC " || cl
  175.             when sbdv.calc = "CLV" then twtypestr = twtypestr || "CALC " || cl || " VALID " || vl
  176.             when sbdv.calc = "COV" then twtypestr = twtypestr || "FIX CALC " || cl || " VALID " || vl
  177.             otherwise ;
  178.         end
  179.  
  180.         address twist 'CREATEFIELD ' sbdv.name || " " || twtypestr
  181.  
  182.         if eof("sbdfile") then leave
  183.         sbdline = ""
  184.         sbdline = readln("sbdfile")
  185.     end
  186.     address twist 'ENDCREATEDB'
  187. end
  188. exit
  189.  
  190. conv_calcstr: PROCEDURE
  191. /* This procedure does not really convert a Superbase calculation/validation formula into Twist format
  192.     (because that would be a ten-thousand-liner procedure).
  193.     But it does convert it into a string constant that can be saved with the field in the Twist file.
  194.     The user must change the formular into    Twist syntax
  195.     (and of course remove the outher quotations marks)
  196. */
  197.     trace OFF
  198.     parse arg calcstr
  199.     slen = length(calcstr)
  200.     if slen > 0 then
  201.     do
  202.         cl = '"\"'
  203.         do i=1 to slen
  204.             calcchr = substr(calcstr, i, 1);
  205.             if calcchr = '"' then cl = cl || '\\\"'
  206.             else    cl = cl || calcchr
  207.         end
  208.         cl = cl || '\""'
  209.     end
  210.     else
  211.     do
  212.         cl = ""
  213.     end
  214.     trace Normal
  215.     return cl
  216. /* end of conv_calcstr */
  217.  
  218.