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

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

GUITools: EVFSGUI: Start implementinig client side Samba configuration settings

File size: 7.5 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 = 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    say time()" NLVSearch() started"
63    NLVSrchDone = 0
64    NLVFile = ""
65    UnixRoot = value("UNIXROOT",,"OS2ENVIRONMENT")
66    do until NLVSrchDone = 1
67        say '  NLV 'Suffix' file   = "'filestem||nlv'.'Suffix'"'
68        select
69            when VRFileExists(srchRoot'\'SubDir'\'filestem||nlv'.'Suffix) then do
70                say "  NLV "Suffix" file found directly!"
71                NLVFile = strip(srchRoot'\'SubDir'\'filestem||nlv'.'Suffix,'L','\')
72                NLVSrchDone = 1
73            end
74            when VRFileExists(UnixRoot||'\usr\share\os2') then do
75                ok = SysFileTree(UnixRoot||'\usr\share\os2\'filestem||nlv'.'Suffix,nlvmsg.,'FOS')
76                if nlvmsg.0 = 1 then do
77                    say "  Found  NLV "Suffix" file in rpm/yum subdirectory"
78                    NLVFile = VRParseFilename(nlvmsg.1,"DPN")'.'Suffix
79                    say "  Adding NLV "Suffix" path to "PathVar
80                    OldPathVar = value(PathVar,,"OS2ENVIRONMENT")
81                    ok = value(PathVar,VRParseFilename(nlvmsg.1,"DP")';'OldPathVar,"OS2ENVIRONMENT")
82                    NLVSrchDone = 1
83                end
84                else say "  NLV "Suffix" file NOT in rpm/yum subdirectory."
85            end
86            when SysSearchPath(PathVar, filestem||nlv'.'Suffix) \= '' then do
87                execDir = VRParseFileName(SysSearchPath(PathVar, filestem||nlv'.'Suffix),"DP")
88                say "  NLV "Suffix" file found via "PathVar
89                NLVFile = strip(execdir'\'filestem||nlv'.'Suffix,'L','\')
90                NLVSrchDone = 1
91            end
92            otherwise do
93                say "  Searching subdirectories"
94                ok = SysFileTree(srchRoot'\'filestem||nlv'.'Suffix,nlvmsg.,'FOS')
95                if nlvmsg.0 = 1 then do
96                    say "  Found  NLV "Suffix" file in subdirectory"
97                    NLVFile = VRParseFilename(nlvmsg.1,"DPN")'.'Suffix
98                    say "  Adding NLV "Suffix" path to "PathVar
99                    OldPathVar = value(PathVar,,"OS2ENVIRONMENT")
100                    ok = value(PathVar,VRParseFilename(nlvmsg.1,"DP")';'OldPathVar,"OS2ENVIRONMENT")
101                    NLVSrchDone = 1
102                end
103                else say "  NLV "Suffix" file not found in subdirectories!"
104            end
105        end
106        if NLVSrchDone = 0 then do /* Fallback to English */
107            if nlv = "EN" then do
108                NLVSrchDone = 1 /* We give up and leave */
109                id = VRMessage( "", "Could not find a valid language file!", "NLV Setup Error", "E", )
110                /* We will leave without a valid NLV file here! */
111            end
112            else do
113                say "  NLV "Suffix" File not found, falling back to EN."
114                nlv = "EN"
115                /* Now we repeat the whole procedure to find the EN file */
116            end
117        end
118    end
119    say time()' NLVSearch() done, returning "'NLVFile'"'
120return NLVFile
121
122/*:VRX         NLVGetMessage
123*/
124NLVGetMessage: PROCEDURE EXPOSE settings. options. fs.
125
126    msgfile = settings.!messages
127    msgnum  = ARG( 1 )
128
129    IF msgfile == '' THEN RETURN ''
130    IF msgnum == '' THEN RETURN ''
131
132    SELECT
133        WHEN ARG() == 2 THEN
134            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2) )
135        WHEN ARG() == 3 THEN
136            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3) )
137        WHEN ARG() == 4 THEN
138            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4) )
139        WHEN ARG() == 5 THEN
140            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5) )
141        WHEN ARG() == 6 THEN
142            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5), ARG(6) )
143        WHEN ARG() == 7 THEN
144            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7) )
145        WHEN ARG() == 8 THEN
146            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8) )
147        WHEN ARG() == 9 THEN
148            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9) )
149        WHEN ARG() == 10 THEN
150            msgtxt = SysGetMessage( msgnum, msgfile, ARG(2), ARG(2), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10) )
151        OTHERWISE
152            msgtxt = SysGetMessage( msgnum, msgfile )
153    END
154
155    PARSE VAR msgtxt message '0D'x .
156
157    IF translate(SUBSTR( message, 1, 4 )) == 'SYS0' THEN message = '[Missing message 'msgnum'!]'
158
159RETURN message
160
161/*:VRX         NLVSetText
162*/
163/*
164 * Sets the specified property of the specified control to the specified
165 * message text.
166 */
167NLVSetText: PROCEDURE EXPOSE settings. options. fs.
168    PARSE ARG control, property, message, substitution
169
170    success = 1
171    IF substitution == '' THEN
172        text = NLVGetMessage( message )
173    ELSE
174        text = NLVGetMessage( message, substitution )
175
176    IF text == '' THEN success = 0
177    ELSE               CALL VRSet control, property, text
178
179RETURN success
Note: See TracBrowser for help on using the repository browser.