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

  1. /* This arexx programm is intended to help you getting your database data
  2.    from DATAMAT to Twist. The programm will convert a .DIF file produced
  3.    by DATAMAT to a standard komma file importable in Twist. This conversion
  4.    is needed if any field contains kommas, quotation marks or linefeeds.
  5.  
  6.    The first step is to create the .DIF file in DATAMAT or DATAMAT
  7.    Profesional:
  8.    -  Select the menu:
  9.       Optionen -> Arbeitsumgebungen ändern... -> Ein-Ausgabe
  10.    -  In the opening requester change the "Feldtrenner" value to: A4 and
  11.       change the "Satztrenner" value to: A5
  12.    -  Close the requester by clicking on "OK"
  13.    To ensure that all fields are exported and that they are exported in the
  14.    right sequence make a new field selection.
  15.    -  Select the menu option: Optionen -> Feldauswahl treffen (Amiga T).
  16.    -  Enter an ascending number (ie 1 in the first field, 2 in the next
  17.       field, and so on..) in all the fields you wish to export.
  18.    -  When all fields have been numbered select the menu item again (now
  19.       labeled "Feldauswahl beenden")
  20.    -  confirm that you wish to save the new field selection.
  21.  
  22.    -  Open your DATAMAT database file window and select the menu:
  23.       Ein-Ausgabe -> Textdatei -> Ausgeben
  24.    -  In the opening file name requester enter a filename. DATAMAT will by
  25.       it self add the extension .DIF
  26.  
  27.    -  Open a shell window and start this arexx program with the filename
  28.       as its argument. E.g.
  29.  
  30.          RX twist:arexx/datamatdif_to_txt.rexx myaddressbook
  31.  
  32.    The argument should include a fully qualifying path but not the .DIF
  33.    extension. The arexx program will create a new file with the same name
  34.    and path but with the extension .TXT
  35.  
  36.    IF SUCH A FILE ALREADY EXISTS TWIST WILL OVERWRITE IT.
  37.  
  38.    The conversion is rather slow. On an A3000 about 10 KB per minute. The
  39.    converted file has each field enclosed in quotiation marks and separated
  40.    by kommas. Every record ends with a line feed. If the fields contain
  41.    doublequotation marks these will be converted to singe quotes ( " -> ' )
  42.  
  43.    -  Start Twist and create a new file with the same fields as the
  44.       DATAMAT file. Make sure that text fields have a length large enough
  45.       to the maximum size of the DATAMAT form layout. Fields larger than
  46.       50 characters should problably be set to file type "Compressed".
  47.  
  48.    -  Use a text field for time fields with length 8 and a calc formular
  49.  
  50.          "TimeStr(TimeVal(<fieldname>))"
  51.  
  52.    (You need to first define the field before you can enter the calculation
  53.    string. Of course <fieldname> should be replaced by the actual field
  54.    name)
  55.  
  56.    When all the fields have been added close the "Edit fields" window and
  57.    from the opening database window select the menu: "Datensatz -> Impor-
  58.    tiere..."
  59.  
  60.    In the import window make sure that "Durch Komma getrennt" and "Mehr-
  61.    zeilige Felder" is selected. Select the File requester symbol at the
  62.    "Name" gadget and pick the file just created by the arexx programm.
  63.  
  64.    After that the "Start" gadget can be be activated and Twist will start
  65.    to import the data. When finished look at the records imported in "list
  66.    modus" (table mode) make sure that the records have been imported with
  67.    the right sequence of fields (ie that the "strasse" field does in fact
  68.    contain values for that field and not for "Vorname").
  69.  
  70.    If the sequence of fields was wrong delete all imported records (Daten-
  71.    satz -> Alle markieren + "Lösche") and change the sequence of the fields
  72.    in the import window before you retry.
  73.  
  74. Mermaid Group 24/10/94
  75. */
  76.  
  77. PARSE ARG dif_filename
  78. Say "This program converts an exported .DEF file from DATAMAT (Profesional)"
  79. say "to a .TXT file that can be imported into Twist2"
  80. say "For full instructions load this file into an editor an read the comments"
  81. say ""
  82. if dif_filename = "" then
  83. do
  84.     say "Enter name of .DIF file to convert (don't enter .DIF extension)"
  85.     pull dif_filename
  86.     if dif_filename = "" then exit
  87. end
  88.  
  89. difopenok =  open('input',dif_filename || ".DIF" ,'R')
  90. if ~difopenok then
  91. do
  92.     say "Unable to open " || dif_filename || ".DIF"
  93.     exit
  94. end
  95. txtopenok = open('output', dif_filename || ".TXT", 'W')
  96. if ~txtopenok then
  97. do
  98.     say "Unable to create " || dif_filename || "TXT"
  99.     exit
  100. end
  101.  
  102. field_delimchr = x2c(a4)
  103. record_delimchr = x2c(a5)
  104.  
  105. fsiz = seek('input',0,'E')
  106. seek('input',0,'B')
  107.  
  108. rlen = 0
  109. rpos = 1
  110. outstr = '"'
  111. do FOREVER
  112.     if (rpos > rlen) then /* Read the next block from the file */
  113.     do
  114.         rlen = min(fsiz,1024)
  115.         if rlen <= 0 then leave
  116.         fsiz = fsiz - rlen
  117.         readbuf = readch('input', rlen)
  118.         rpos = 1
  119.     end
  120.  
  121.     chr = substr(readbuf, rpos, 1) /* Get next chr from read buffer */
  122.     rpos = rpos + 1
  123.  
  124.     select /* examine chr for field and record delimiters perform conversion */
  125.         when chr = field_delimchr then outstr = outstr || '","'
  126.         when chr = record_delimchr then
  127.         do
  128.             writech('output', outstr || '"' || x2c(a)) /* Write the whole converted record string to the output file */
  129.             outstr = '"'
  130.         end
  131.         when chr = '"' then outstr = outstr || "'"
  132.         otherwise outstr = outstr || chr
  133.     end
  134. end
  135. close('output')
  136. close('input')
  137.  
  138.