Make your own free website on Tripod.com


 Conversion Tool Specification
 

   * Take the name of the "datafile" and "fieldsfile" as command line arguments
     Optionally allow the user to enter the name of the outputDBFile. By default
     it will be set to the name of the "dataFile" suffixed with "DB".
   * make sure that the 2 files exist and are readable

   * for each line from the "fieldsfile"
      - if the line is not of the form "fieldName=value" pair then
           exit with message "Wrong format of fieldsfile".
        end if
      - get the "fieldName" and "fieldLength". store the "fieldName" and
        "fieldLength" into fieldNamesVector() and fieldsLengthVectors().

   * Open the outputDataFile for writing the header and the data records

   * create the heaader as follows:
     - writeInt(headerlen), where "headerLen" is = 0
     - writeInt(noOfFields), where "noOfFields" is set to
                 "fieldNamesVector.size()"
     - writeInt(recordCount), where ;recordCount" is = 0
     - for each element in "fieldNamesVector"
         --writeUTF(fieldName) where fieldName is set to
                               "fieldNamesVector.elementAt(loopcount)"
         --writeInt(fieldLength) where fieldLength is set to
                               "fieldLengthVector.elementAt(loopcount)"
    - writeInt(magic) where magic is set to "OXCOCOBABE"
    - set "headerLen" as the current value of the "filePointer"
 
   * Write the data Records as follows:

     - let "b" be a byte
     - let int i=0,cols=0,offset=0;
     - let recordCount=0
     - create an array of byes "buffer" of size "recordLen" (need to calculate)
     - let "db" be the name of the DataFile
     - let "outDb" be the name of the outputDBFile
     - while not the end of file do {
        -- set buffer[0] = LIVE_RECORD
        -- while((b=db.readByte())!= '\n') {
              if ( b != '^') {
                 val[i++] = b;
              } else
                 {
                   size = (i < fieldLengthVector.elementAt(cols)) ? i :
                               fieldLengthVector.elementAt(cols);

                   write to buffer size number of bytes from val, starting at
                   "offset"

                   flush contents of val
                   offset += fieldLengthVector.elementAt(cols);
                   cols++;
                   i=0;
                 }
            }//while

          if ( i != 0) {
                   size = (i < fieldLengthVector.elementAt(cols)) ? i :
                               fieldLengthVector.elementAt(cols);

                   write to buffer size number of bytes from val, starting at
                   "offset"

                   flush contents of val
                   offset += fieldLengthVector.elementAt(cols);
                   cols++;
                   i=0;
            }

 
          if (cols != fieldsNamesVector.size()) {
               exit with message "not correct number
                                  of values specified in record '?'"
          }
 
          if (cols == fieldsNamesVector.size()){
             recordCount++;
             write buffer to outDb
           }

          flush contents of buffer
          set offset = 0

       } //end of while not end of file

* seek() to the "recordCount" field of the "header" and set the record
  count.