source: trunk/guitools/shared/nlv.vrs @ 990

Last change on this file since 990 was 990, checked in by Herwig Bauernfeind, 4 years ago

GUITools: All changes that have built over time.

File size: 7.8 KB
Line 
1/*:VRX         NLVSetup
2 */
3NLVSetup: PROCEDURE EXPOSE settings. options.
4    /* This subroutine is (c) by Alex Taylor, portions (c) Herwig Bauernfeind
5     * Sets all UI text from the message file.  Any string that can't be loaded
6     * will default to the built-in English.
7     */
8
9    /* settings.! variables used in NLV.VRS
10       settings.!messages: 0 = there are no message files, do not search them
11                           any other value = look for message files
12       settings.!helpfile: 0 = there are no helpfiles, do not search them
13                           any other value = look for message files
14       settings.!nlv8dot3: 0 = nlv files do not conform to 8.3 names
15                           any other value = nlv files are shortened to 8.3
16     */
17     
18    IF options.!debug == 1 THEN SAY time()' NLVSetup() started'
19    IF options.!debug == 1 THEN SAY '  NLVSetup() is (c) Alex Taylor, portions (c) Herwig Bauernfeind'
20
21    execPath = VRGet("Application", "Program")
22    if execPath = "" then parse source . . execPath
23    execDir  = translate(VRParseFileName( execPath, "DP"))
24    parse var execDir srchroot '\BIN'
25
26    say '  NLV execDir    = "'execDir'"'
27    say '  NLV srchroot   = "'srchRoot'"'
28
29    filestem = VRParseFileName( execPath, "N")
30    select
31        when settings.!nlv8dot3 = 0 then filestem = filestem||'_'
32        when translate(filestem) = "EVFSGUI" then filestem = "evfsi_"
33        otherwise filestem = strip(SUBSTR( filestem, 1, 5 ))||'_'
34    end
35    say '  NLV filestem   = "'filestem'"'
36
37    /* First, figure out what language/message file to use */
38    Syslang = TRANSLATE( VALUE('LANG',,'OS2ENVIRONMENT'))
39    SELECT
40        WHEN Syslang == 'ZH_TW' THEN nlv = 'TW'
41        WHEN Syslang == 'ZH_CN' THEN nlv = 'CX'
42        OTHERWISE PARSE VAR Syslang nlv '_' .
43    END
44
45    /* Find the messagefile and helpfile */
46    if settings.!messages <> 0 then settings.!messages = NLVsearch(nlv,'LANG','MSG','DPATH')
47    if settings.!helpfile <> 0 then settings.!helpfile = NLVsearch(nlv,'HELP','HLP','HELP')
48
49    IF options.!debug == 1 THEN SAY '  NLV MessageFile = "'settings.!messages'"'
50    IF options.!debug == 1 THEN SAY '  NLV HelpFile    = "'settings.!helpfile'"'
51
52    IF options.!debug == 1 THEN SAY time()' NLVSetup() done'
53RETURN
54
55/*:VRX         NLVSearch
56*/
57NLVSearch: procedure expose filestem execdir srchroot
58    nlv     = arg(1)
59    SubDir  = arg(2)
60    Suffix  = arg(3)
61    PathVar = arg(4)
62    NLVSrchDone = 0
63    NLVFile = ""
64    UnixRoot = value("UNIXROOT",,"OS2ENVIRONMENT")
65    do until NLVSrchDone = 1
66        say '  NLV 'Suffix' file   = "'filestem||nlv'.'Suffix'"'
67        select
68            when VRFileExists(execdir'\'filestem||nlv'.'Suffix) then do
69                say "  Attempt1: NLV "Suffix" file found directly!"
70                NLVFile = strip(execdir'\'filestem||nlv'.'Suffix,'L','\')
71                NLVSrchDone = 1
72            end
73            when VRFileExists(srchRoot'\'SubDir'\'filestem||nlv'.'Suffix) then do
74                say "  Attempt2: NLV "Suffix" file found directly!"
75                NLVFile = strip(srchRoot'\'SubDir'\'filestem||nlv'.'Suffix,'L','\')
76                NLVSrchDone = 1
77            end
78            when SysSearchPath(PathVar, filestem||nlv'.'Suffix) \= '' then do
79                execDir = VRParseFileName(SysSearchPath(PathVar, filestem||nlv'.'Suffix),"DP")
80                say "  Attempt3: NLV "Suffix" file found via "PathVar
81                NLVFile = strip(execdir'\'filestem||nlv'.'Suffix,'L','\')
82                NLVSrchDone = 1
83            end
84            when VRFileExists(UnixRoot||'\usr\share\os2') then do
85                ok = SysFileTree(UnixRoot||'\usr\share\os2\'filestem||nlv'.'Suffix,nlvmsg.,'FOS')
86                if nlvmsg.0 = 1 then do
87                    say "  Attempt4: Found  NLV "Suffix" file in rpm/yum subdirectory"
88                    NLVFile = VRParseFilename(nlvmsg.1,"DPN")'.'Suffix
89                    say "  Adding NLV "Suffix" path to "PathVar
90                    OldPathVar = value(PathVar,,"OS2ENVIRONMENT")
91                    ok = value(PathVar,VRParseFilename(nlvmsg.1,"DP")';'OldPathVar,"OS2ENVIRONMENT")
92                    NLVSrchDone = 1
93                end
94                else say "  NLV "Suffix" file NOT in rpm/yum "UnixRoot||'\usr\share\os2\'filestem||nlv'.'Suffix"subdirectory."
95            end
96           
97            otherwise do
98                say "  Searching subdirectories"
99                ok = SysFileTree(srchRoot'\'filestem||nlv'.'Suffix,nlvmsg.,'FOS')
100                if nlvmsg.0 = 1 then do
101                    say "  Found  NLV "Suffix" file in subdirectory"
102                    NLVFile = VRParseFilename(nlvmsg.1,"DPN")'.'Suffix
103                    say "  Adding NLV "Suffix" path to "PathVar
104                    OldPathVar = value(PathVar,,"OS2ENVIRONMENT")
105                    ok = value(PathVar,VRParseFilename(nlvmsg.1,"DP")';'OldPathVar,"OS2ENVIRONMENT")
106                    NLVSrchDone = 1
107                end
108                else say "  NLV "Suffix" file not found in subdirectories!"
109            end
110        end
111        if NLVSrchDone = 0 then do /* Fallback to English */
112            if nlv = "EN" then do
113                NLVSrchDone = 1 /* We give up and leave */
114                id = VRMessage( "", "Could not find a valid language file!", "NLV Setup Error", "E", )
115                /* We will leave without a valid NLV file here! */
116            end
117            else do
118                say "  NLV "Suffix" File not found, falling back to EN."
119                nlv = "EN"
120                /* Now we repeat the whole procedure to find the EN file */
121            end
122        end
123    end
124    say time()' NLVSearch() done, returning "'NLVFile'"'
125return NLVFile
126
127/*:VRX         NLVGetMessage
128*/
129NLVGetMessage: PROCEDURE EXPOSE settings. options. fs.
130
131    msgfile = settings.!messages
132    msgnum  = ARG( 1 )
133
134    IF msgfile == '' THEN RETURN ''
135    IF msgnum == '' THEN RETURN ''
136
137    SELECT
138        WHEN ARG() == 2 THEN
139            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2) )
140        WHEN ARG() == 3 THEN
141            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3) )
142        WHEN ARG() == 4 THEN
143            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4) )
144        WHEN ARG() == 5 THEN
145            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5) )
146        WHEN ARG() == 6 THEN
147            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5), ARG(6) )
148        WHEN ARG() == 7 THEN
149            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7) )
150        WHEN ARG() == 8 THEN
151            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8) )
152        WHEN ARG() == 9 THEN
153            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9) )
154        WHEN ARG() == 10 THEN
155            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10) )
156        OTHERWISE
157            msgtxt = SysGetMessage( msgnum, msgfile )
158    END
159
160    PARSE VAR msgtxt message '0D'x .
161
162    IF translate(SUBSTR( message, 1, 4 )) == 'SYS0' THEN message = '[Missing message 'msgnum'!]'
163
164RETURN message
165
166/*:VRX         NLVSetText
167*/
168/*
169 * Sets the specified property of the specified control to the specified
170 * message text.
171 */
172NLVSetText: PROCEDURE EXPOSE settings. options. fs.
173    PARSE ARG control, property, message, substitution
174
175    success = 1
176    IF substitution == '' THEN
177        text = NLVGetMessage( message )
178    ELSE
179        text = NLVGetMessage( message, substitution )
180
181    IF text == '' THEN success = 0
182    ELSE               CALL VRSet control, property, text
183
184RETURN success
Note: See TracBrowser for help on using the repository browser.