############################################################################ # # File: adjuncts.icn # # Subject: Procedures for gettext and idxtext # # Author: Richard L. Goerwitz # # Date: June 21, 2000 # ############################################################################ # # This file is in the public domain. # ############################################################################ # # Version: 1.4 December 28, 1993 Phillip Lee Thomas # _delimiter added to global list. # OS conventions moved to Set_OS() from # idxtext.icn and gettext.icn. # Version: 1.5 August 5, 1995 Add MS-DOS/386 to features check. # ############################################################################ # # Pretty mundane stuff. Set_OS(), Basename(), Pathname(), Strip(), and # a utility for creating index filenames. # ############################################################################ # # See also: gettext.icn, idxtext,icn # ############################################################################ global _slash, _baselen, _delimiter, _OS_offset, firstline procedure Set_OS() #: set global OS features # delimiter for indexed values _delimiter := char(255) # Initialize filename and line termination conventions. # _baselen: number of characters in filename base. # _OS_offset: number of characters marking newline. if find("UNIX"|"Amiga", &features) then { _slash := "/" _baselen := 10 _OS_offset := 1 } else if find("MS-DOS"|"MS-DOS/386"|"OS/2"|"MS Windows NT", &features) then { _slash := "\\" _baselen := 8 _OS_offset := 2 } else if find("Macintosh", &features) then { _slash := ":" _baselen := 15 _OS_offset := 1 } else stop("gettext: OS not supported") return end procedure Basename(s) #: obtain base filename # global _slash s ? { while tab(find(_slash)+1) return tab(0) } end procedure Pathname(s) #: obtain path of filename local s2 # global _slash s2 := "" s ? { while s2 ||:= tab(find(_slash)+1) return s2 } end procedure getidxname(FNAME) #: obtain index from datafile name # # Discard path component. Cut basename down to a small enough # size that the OS will be able to handle addition of the ex- # tension ".IDX" # # global _slash, _baselen return right(Strip(Basename(FNAME,_slash),'.'), _baselen, "x") || ".IDX" end procedure Strip(s,c) #: remove chars from string local s2 s2 := "" s ? { while s2 ||:= tab(upto(c)) do tab(many(c)) s2 ||:= tab(0) } return s2 end