home *** CD-ROM | disk | FTP | other *** search
- on createDatabase
- global gDHIndex, indexFileName, hardPath, term, def, titles, links, txtFile
- DBInitPlatform()
- DBOpenSession()
- if value(DBDatabaseExists(hardPath & indexFileName)) > 0 then
- put "Dynamic Human II index file already exists."
- put "Please delete existing index file."
- return -1
- end if
- set fields to EMPTY
- put "TERM,C,255" & RETURN after fields
- put "DEF,M" & RETURN after fields
- put "TITLES,C,255" & RETURN after fields
- put "LINKS,C,255" & RETURN after fields
- put fields
- set gDHIndex to DBCreate(hardPath & indexFileName, 4, fields, 0)
- put gDHIndex
- set term to EMPTY
- set def to EMPTY
- set titles to EMPTY
- set links to EMPTY
- set txtFile to fileio(mnew, "read", hardPath & "cindex.txt")
- repeat while txtFile(mGetPosition) < txtFile(mGetLength)
- set tempLine to txtFile(mReadLine)
- delete char 1 of tempLine
- delete char length(tempLine) of tempLine
- if tempLine = EMPTY then
- put "writing record:" && DBCount() + 1
- DBWriteRec("G", DBCount() + 1)
- DBWriteMemo("DEF", def)
- put term
- put def
- put titles
- put "**********"
- set term to EMPTY
- set def to EMPTY
- set titles to EMPTY
- set links to EMPTY
- next repeat
- end if
- if length(term) = 0 then
- set term to tempLine
- next repeat
- end if
- if length(def) = 0 then
- set def to tempLine
- next repeat
- end if
- if length(titles) = 0 then
- set titles to tempLine
- end if
- end repeat
- txtFile(mdispose)
- end
-
- on openDatabase
- global gDHIndex, indexFileName, hardPath
- set indexFileName to "dhindex"
- if the platform contains "Mac" then
- else
- end if
- DBInitPlatform()
- DBOpenSession()
- if DBDatabaseExists(hardPath & indexFileName) = 0 then
- set gDHIndex to DbUse(hardPath & indexFileName)
- DBSelect(gDHIndex)
- else
- put "could not find index database file."
- return -1
- end if
- end
-
- on closeDatabase
- global gDHIndex
- DBClose(gDHIndex)
- DBCloseSession()
- if the platform contains "Mac" then
- else
- end if
- updateStage()
- end
-
- on readNthTerm whichTerm
- if whichTerm <= DBCount() then
- DBGo(whichTerm)
- put DBGetFieldByName("TERM") into field "currentTerm"
- put DBGetMemo("DEF") into field "currentDefinition"
- end if
- end
-
- on toUpper inString
- set outString to EMPTY
- repeat with i = 1 to length(inString)
- if (charToNum(char i of inString) <= 122) and (charToNum(char i of inString) >= 97) then
- put numToChar(charToNum(char i of inString) - 32) after outString
- next repeat
- end if
- put char i of inString after outString
- end repeat
- return outString
- end
-
- on buildTermList outputField
- DBTop()
- set termList to []
- repeat with i = 1 to DBCount()
- DBGo(i)
- set currentTerm to DBGetFieldByName("term")
- if length(currentTerm) >= 1 then
- append(termList, currentTerm)
- end if
- end repeat
- sort(termList)
- set fullText to EMPTY
- set currentTerm to EMPTY
- set lastTerm to EMPTY
- repeat with k = 1 to count(termList)
- set currentTerm to getAt(termList, k)
- if length(lastTerm) >= 1 then
- if char 1 of lastTerm <> char 1 of currentTerm then
- put RETURN after fullText
- end if
- end if
- put currentTerm & RETURN after fullText
- set lastTerm to currentTerm
- end repeat
- set the text of field outputField to fullText
- end
-