/****************************** Module Header ******************************* * * Module Name: dict.e * * Copyright (c) Netlabs EPM Distribution Project 2004 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ ; Select dictionaries compile if not defined( SMALL) -- If compiled separately EA_comment 'Select language for dictionaries.' define INCLUDING_FILE = 'DICT.E' tryinclude 'mycnf.e' const include 'stdconst.e' const compile if not defined( NLS_LANGUAGE) NLS_LANGUAGE = 'ENGLISH' compile endif include NLS_LANGUAGE'.e' compile endif ; --------------------------------------------------------------------------- ; Syntax: DictNum ; Sets the active dictionary. ; Accepts also 'delete' as arg to delete all entries. ; Accepts also 'switch' as arg to switch to next entry. ; When called without arg, the SelectDictLang command is called to ; select/add/configure/delete a language. defc DictNum universal nepmd_hini universal dictionary_filename universal addenda_filename parse arg args args = strip( args) opt = upcase( args) if args = '' then 'SelectDictLang' return endif KeyPath = '\NEPMD\User\Spellcheck\Language' ActiveNum = QueryConfigKey( KeyPath'\Selected') if ActiveNum = '' then ActiveNum = 1 endif Order = QueryConfigKey( KeyPath'\Order') SearchOption = 'C' NextNum = '' NumFound = 0 Select = '' do while NepmdGetNextConfigKey( nepmd_hini, KeyPath, SearchOption, NextNum) if not IsNum( NextNum) then iterate endif NumFound = NumFound + 1 if Opt = 'DELETE' then DeleteConfigKey( KeyPath'\'NextNum'\Dictionary') DeleteConfigKey( KeyPath'\'NextNum'\Addenda') Select = 'DELETE' else if NextNum = args then Select = NextNum leave endif endif enddo -- Handle RegDefault entries if Select = '' & IsNum( args) then Select = args endif if Opt = 'SWITCH' then if IsNum( ActiveNum) & Order <> '' then wpos = wordpos( ActiveNum, Order) if wpos = words( Order) then nextwpos = 1 else nextwpos = wpos + 1 endif Select = word( Order, nextwpos) endif endif if Opt = 'DELETE' then elseif Select = '' & NumFound = 0 then 'SayError No dictionary language defined.' elseif Select = '' then 'SayError Language number "'args'" not found.' else WriteConfigKey( KeyPath'\Selected', Select) dictionary_filename = QueryConfigKey( KeyPath'\'Select'\Dictionary') addenda_filename = QueryConfigKey( KeyPath'\'Select'\Addenda') SelectName = QueryConfigKey( KeyPath'\'Select'\Name') -- Toggle dynaspell off and on to activate the new dicts if .keyset = 'SPELL_KEYS' then 'dynaspell' 'dynaspell' endif 'SayError Switched to language "'SelectName'"' 'RefreshInfoLine DICT' endif return ; --------------------------------------------------------------------------- defproc DictNameToNum( SearchName) universal nepmd_hini -- Optinally return the number for the last found name fReverse = abbrev( upcase( arg( 2)), 'R') KeyPath = '\NEPMD\User\Spellcheck\Language' SearchOption = 'C' NextNum = '' FoundNum = '' do while NepmdGetNextConfigKey( nepmd_hini, KeyPath, SearchOption, NextNum) if not IsNum( NextNum) then iterate endif NextName = QueryConfigKey( KeyPath'\'NextNum'\Name') if upcase( SearchName) = upcase( NextName) then FoundNum = NextNum if not fReverse then leave endif endif enddo -- Handle RegDefault entries if FoundNum = '' then n = 0 do forever n = n + 1 NextName = QueryConfigKey( KeyPath'\'n'\Name') if NextName = '' then leave endif if upcase( SearchName) = upcase( NextName) then FoundNum = n leave endif enddo endif return FoundNum ; --------------------------------------------------------------------------- ; Syntax: SelectDictLang [lang_number] ; lang_number is the language number as used for the keys in NEPMD.INI. ; lang_number can be specified to define the pre-selected item. ; If lang_number is missing, the number fpr the active language is used. defc SelectDictLang universal nepmd_hini universal dictionary_filename universal addenda_filename KeyPath = '\NEPMD\User\Spellcheck\Language' ActiveNum = QueryConfigKey( KeyPath'\Selected') Order = QueryConfigKey( KeyPath'\Order') NoEntry = '-none-' Delim = \1 -- Find add. numbers that are present in ini, but not in Order IniNumbers = '' AddIniNumbers = '' NextNum = '' SearchOption = 'C' do while NepmdGetNextConfigKey( nepmd_hini, KeyPath, SearchOption, NextNum) if not IsNum( NextNum) then iterate endif IniNumbers = strip( IniNumbers NextNum) if not wordpos( NextNum, Order) then AddIniNumbers = strip( AddIniNumbers NextNum) endif enddo -- Handle RegDefault entries n = 0 do forever n = n + 1 NextName = QueryConfigKey( KeyPath'\'n'\Name') if NextName = '' then leave endif if not wordpos( n, IniNumbers) then IniNumbers = strip( IniNumbers n) if not wordpos( n, Order) then AddIniNumbers = strip( AddIniNumbers n) endif endif enddo -- Delete numbers that are present in Order, but not in ini CheckedOrder = Order do w = 1 to words( Order) NextNum = word( Order, w) if not wordpos( NextNum, IniNumbers) then wpos = wordpos( NextNum, CheckedOrder) CheckedOrder = SpaceStr( delword( CheckedOrder, wpos, 1)) endif enddo -- Append AddIniNumbers if AddIniNumbers <> '' then CheckedOrder = strip( CheckedOrder AddIniNumbers) endif -- Write to Order, if different from CheckedOrder if CheckedOrder <> Order then Order = CheckedOrder WriteConfigKey( KeyPath'\Order', Order) endif -- Build LangList and get data for active item LangList = '' ActiveSelectNum = '' ActiveLang = '' do w = 1 to words( Order) NextNum = word( Order, w) Name = QueryConfigKey( KeyPath'\'NextNum'\Name') LangList = LangList''Delim''Name if NextNum = ActiveNum then ActiveSelectNum = w ActiveLang = Name endif enddo if LangList = '' then LangList = Delim''NoEntry -- without an entry, listbox would return Button = 0 endif -- Determine pre-selected item PreSelectNum = arg( 1) if PreSelectNum = '' then if ActiveSelectNum = '' then PreSelectNum = 1 else PreSelectNum = ActiveSelectNum endif endif -- Open Listbox -- No Linebreak allowed in Text Title = 'Select a dictionary language' Text = 'Current language: 'ActiveLang if ActiveNum = '' then DefButton = 4 -- Edit else DefButton = 1 -- Set endif HelpId = 0 refresh ret = ListBox( Title, LangList, '/~Set/~Up.../~Down.../~Edit.../'CANCEL__MSG, -- buttons 6, 10, -- top, left, Min( count( Delim, LangList) + 1, 12), 80, -- height, width GethWndC( APP_HANDLE) || atoi( PreSelectNum) || atoi( DefButton) || atoi( HelpId) || Text\0) refresh -- Parse button number and selected list item string Button = asc( leftstr( ret, 1)) EOS = pos( \0, ret, 2) -- CHR(0) signifies End Of String Select = substr( ret, 2, EOS - 2) SelectNum = '' if Select = NoEntry then Select = '' if Button < 4 then Button = 3 -- switch to Edit endif else SelectNum = DictNameToNum( Select) endif if Button = 1 then -- Set 'DictNum' SelectNum return elseif Button = 2 then -- Up wpos = wordpos( SelectNum, Order) NewOrder = Order widx = 0 if wpos <> 0 then NewOrder = SpaceStr( delword( Order, wpos, 1)) widx = wordindex( NewOrder, Max( 1, wpos - 1)) endif NewOrder = SpaceStr( insertstr( SelectNum' ', NewOrder, Max( 0, widx - 1))) WriteConfigKey( KeyPath'\Order', NewOrder) NewSelectNum = wordpos( SelectNum, NewOrder) 'SelectDictLang' NewSelectNum return elseif Button = 3 then -- Down wpos = wordpos( SelectNum, Order) NewOrder = Order widx = 0 if wpos <> 0 then NewOrder = SpaceStr( delword( Order, wpos, 1)) widx = wordindex( NewOrder, Max( 1, Min( words( NewOrder), wpos))) endif NewOrder = SpaceStr( insertstr( ' 'SelectNum, NewOrder, Min( length( NewOrder), widx))) WriteConfigKey( KeyPath'\Order', NewOrder) NewSelectNum = wordpos( SelectNum, NewOrder) 'SelectDictLang' NewSelectNum return elseif Button = 4 then -- Edit 'EditDictLang' SelectNum return else -- Cancel or Esc key return endif return ; --------------------------------------------------------------------------- ; Find NextFreeNum for 'Add' defproc GetNextFreeDictNum universal nepmd_hini -- Search first free number in RegKeys and RegDefaults KeyPath = '\NEPMD\User\Spellcheck\Language' NextFreeNum = 1 n = 0 do forever n = n + 1 Next = QueryConfigKey( KeyPath'\'n'\Name') if Next <> '' then iterate endif Next = QueryConfigKey( KeyPath'\'n'\Dictionary') if Next <> '' then iterate endif Next = QueryConfigKey( KeyPath'\'n'\Addenda') if Next <> '' then iterate endif NextFreeNum = n leave enddo return NextFreeNum ; --------------------------------------------------------------------------- defc EditDictLang universal dictionary_filename universal addenda_filename KeyPath = '\NEPMD\User\Spellcheck\Language' ActiveNum = QueryConfigKey( KeyPath'\Selected') Order = QueryConfigKey( KeyPath'\Order') NoEntry = '-none-' Delim = \1 -- Build LangList and get data for active item LangList = '' ActiveSelectNum = '' ActiveLang = '' do w = 1 to words( Order) NextNum = word( Order, w) Name = QueryConfigKey( KeyPath'\'NextNum'\Name') LangList = LangList''Delim''Name if NextNum = ActiveNum then ActiveSelectNum = w ActiveLang = Name endif enddo if LangList = '' then LangList = Delim''NoEntry -- without an entry, listbox would return Button = 0 endif -- Determine pre-selected item PreSelectNum = arg( 1) if not IsNum( PreSelectNum) then PreSelectNum = '' endif if PreSelectNum = '' then if ActiveSelectNum = '' then PreSelectNum = 1 else PreSelectNum = ActiveSelectNum endif endif -- Open Listbox -- No Linebreak allowed in Text Title = 'Edit a dictionary language' Text = 'Current language: 'ActiveLang if ActiveNum = '' then DefButton = 1 -- Add else DefButton = 3 -- Configure endif HelpId = 0 refresh ret = ListBox( Title, LangList, '/~Add.../Down~load.../~Configure.../~Delete/Return', -- buttons 6, 10, -- top, left, Min( count( Delim, LangList) + 1, 12), 60, -- height, width GethWndC( APP_HANDLE) || atoi( PreSelectNum) || atoi( DefButton) || atoi( HelpId) || Text\0) refresh -- Parse button number and selected list item string Button = asc( leftstr( ret, 1)) EOS = pos( \0, ret, 2) -- CHR(0) signifies End Of String Select = substr( ret, 2, EOS - 2) SelectNum = '' if Select = NoEntry then Select = '' if Button = 3 | Button = 4 then Button = 1 -- switch to Add endif endif if Select = '' then SelectNum = PreSelectNum else SelectNum = DictNameToNum( Select, 'R') -- For multiple entries, take last one first endif if Button = 1 then -- Add Config = 'NEW' 'ConfigDictLang' Config SelectNum return elseif Button = 2 then -- Download 'SelectDownloadDict' return elseif Button = 3 then -- Configure Config = 'CONFIG' 'ConfigDictLang' Config SelectNum return elseif Button = 4 then -- Delete if Select <> '' then DeleteConfigKey( KeyPath'\'SelectNum'\Dictionary') DeleteConfigKey( KeyPath'\'SelectNum'\Addenda') DeleteConfigKey( KeyPath'\'SelectNum'\Name') if SelectNum = ActiveNum then NewNum = 1 NewDict = QueryConfigKey( KeyPath'\'NewNum'\Dictionary') NewAdd = QueryConfigKey( KeyPath'\'NewNum'\Addenda') WriteConfigKey( KeyPath'\Selected', NewNum) dictionary_filename = NewDict addenda_filename = NewAdd endif wpos = wordpos( SelectNum, Order) if wpos then NewOrder = SpaceStr( delword( Order, wpos, 1)) WriteConfigKey( KeyPath'\Order', NewOrder) endif endif 'EditDictLang' -- restart return else -- Cancel or Esc key 'SelectDictLang' SelectNum -- return return endif return ; --------------------------------------------------------------------------- defc ConfigDictLang RightArrow = \16 LeftArrow = \17 Empty = \255 -- This button text works to create an empty button i = 1 KeyPath = '\NEPMD\User\Spellcheck\Language' NoName = '-untitled-' UserDir = NepmdQueryInstValue( 'USERDIR') if UserDir = '' then 'SayError Error: UserDir not set.' return endif DefaultDir = UserDir'\spellchk' DefaultAdd = DefaultDir'\user.add' parse arg Config ConfigNum Config = upcase( Config) -- Config = DOWNLOAD: Instead of ConfigNum, also a filename may be specified if leftstr( ConfigNum, 1) = '"' then parse value ConfigNum with '"'ConfigNum'"' endif SavedConfigNum = ConfigNum Order = QueryConfigKey( KeyPath'\Order') ActiveNum = QueryConfigKey( KeyPath'\Selected') Dict = '' Add = '' Name = '' if Config = 'NEW' | ConfigNum = '' then Dict = QueryConfigKey( KeyPath'\'ActiveNum'\Dictionary') Add = DefaultAdd ConfigNum = GetNextFreeDictNum() elseif Config = 'DOWNLOAD' then Dict = ConfigNum Add = DefaultAdd ConfigNum = GetNextFreeDictNum() i = 2 else DefaultDict = QueryConfigKey( KeyPath'\'ConfigNum'\Dictionary') DefaultAdd = QueryConfigKey( KeyPath'\'ConfigNum'\Addenda') DefaultName = QueryConfigKey( KeyPath'\'ConfigNum'\Name') Dict = DefaultDict Add = DefaultAdd Name = DefaultName endif Again = 1 do while Again Again = 0 -- Open EntryBox -- No line break allowed in Text maxi = 3 if wordpos( Config, 'NEW DOWNLOAD') then Title = 'Add new language - page 'i'/'maxi else Title = 'Configure language "'Name'" - page 'i'/'maxi endif if i = 1 then Text = 'Enter a filename for a dictionary or a space-separated list:' Buttons = '/'Empty'/~Next 'RightArrow'/~File dialog/Return' Back = 0; Next = 2; FileDlg = 3; OK = 0; Cancel = 4 OldEntry = Dict DefaultButton = Next elseif i = 2 then Text = 'Enter a filename for an addendum or a space-separated list:' OldEntry = Add Buttons = '/'LeftArrow' ~Back/~Next 'RightArrow'/~File dialog/Return' Back = 1; Next = 2; FileDlg = 3; OK = 0; Cancel = 4 DefaultButton = Next else Text = 'Enter a name for the language:' Buttons = '/'LeftArrow' ~Back/'Empty'/'OK__MSG'/Return' Back = 1; Next = 0; FileDlg = 0; OK = 3; Cancel = 4 if Name = '' then -- get DictBasename if Dict <> '' then parse value Dict with first rest lp = lastpos( '\', first) DictName = substr( first, lp + 1) parse value DictName with DictBasename'.'ext if DictBasename <> '' then Name = GetDefaultDictLangName( DictBasename) endif endif endif OldEntry = Name DefaultButton = OK endif Title = leftstr( Title, 100)'.' -- Add spaces to fit the text in titlebar HelpId = 0 -- PosFlag = 1 (#9) would be useful, but makes the right edge cut. ret = EntryBox( Title, Buttons, OldEntry, '', 255, -- Length atoi( DefaultButton) || atoi( HelpId) || GethWndC( APP_HANDLE) || Text) -- Parse button number and selected list item string EntryButton = asc( leftstr( ret, 1)) EOS = pos( \0, ret, 2) -- CHR(0) signifies End Of String NewEntry = substr( ret, 2, EOS - 2) -- Check if empty button was pressed if (Entrybutton = 1 & Back = 0) | (Entrybutton = 2 & Next = 0) then -- Re-open this dialog Again = 1 -- Check if 0 for Esc key must come first elseif EntryButton = Cancel | EntryButton = 0 then 'EditDictLang' SavedConfigNum return elseif EntryButton = Next then if i = 1 then Dict = NewEntry elseif i = 2 then Add = NewEntry elseif i = 3 then Name = NewEntry endif -- Open this dialog with next page Again = 1 i = i + 1 elseif EntryButton = Back then if i = 1 then Dict = NewEntry elseif i = 2 then Add = NewEntry elseif i = 3 then Name = NewEntry endif -- Open this dialog with previous page Again = 1 i = i - 1 elseif EntryButton = OK then if i = 1 then Dict = NewEntry elseif i = 2 then Add = NewEntry elseif i = 3 then Name = NewEntry endif if Name = '' then Name = NoName endif if IsNum( ConfigNum) then if wordpos( Config, 'NEW DOWNLOAD') then -- Check if name already exists fNameExists = 0 do n = 1 to ConfigNum - 1 if Name = QueryConfigKey( KeyPath'\'n'\Name') then fNameExists = 1 leave endif enddo if fNameExists then Again = 1 Title = 'Add new language' Text = '' Text = Text || Name\n\n Text = Text || 'This name is already defined. Specify another one.' Style = MB_OK + MB_WARNING + MB_MOVEABLE ret = WinMessageBox( Title, Text, Style) iterate endif endif -- Write changed entries if Dict <> DefaultDict | wordpos( Config, 'NEW DOWNLOAD') then WriteConfigKey( KeyPath'\'ConfigNum'\Dictionary', Dict) endif if Add <> DefaultAdd | wordpos( Config, 'NEW DOWNLOAD') then WriteConfigKey( KeyPath'\'ConfigNum'\Addenda', Add) endif if Name <> DefaultName | wordpos( Config, 'NEW DOWNLOAD') then WriteConfigKey( KeyPath'\'ConfigNum'\Name', Name) endif -- Append to Order, if not already present if not wordpos( ConfigNum, Order) then WriteConfigKey( KeyPath'\Order', strip( Order ConfigNum)) endif else if wordpos( Config, 'NEW DOWNLOAD') then Title = 'Add new language' else Title = 'Configure language' endif Text = '' Text = Text || Name\n\n Text = Text || 'No entry written to NEPMD.INI, ConfigNum = "'ConfigNum'".' Style = MB_OK + MB_ERROR + MB_MOVEABLE ret = WinMessageBox( Title, Text, Style) endif -- Automatically make the new language the selected one, if named and if none selected before if wordpos( Config, 'NEW DOWNLOAD') & Name <> NoName then 'DictNum' ConfigNum endif 'EditDictLang' ConfigNum return elseif EntryButton = FileDlg then Again = 1 if i = 1 then FileDlgTitle = 'Select a dictionary (Netscape 4.6.1 or IBM Works type)' FileMask = '*.dic;*.dct' lp = lastpos( '\', Dict) if lp then DefaultDictDir = substr( Dict, 1, lp) else DefaultDictDir = DefaultDir endif FileMask = strip( DefaultDictDir, 't', '\')'\'FileMask else FileDlgTitle = 'Select an addendum (could be a new file)' FileMask = '*.add;*.adl' lp = lastpos( '\', Add) if lp then DefaultAddDir = substr( Add, 1, lp) else DefaultAddDir = DefaultDir endif FileMask = strip( DefaultAddDir, 't', '\')'\'FileMask endif if getpminfo( EPMINFO_EDITFRAME) then handle = EPMINFO_EDITFRAME else -- If frame handle is 0, use edit client instead handle = EPMINFO_EDITCLIENT endif size = 328 -- size of FILEDLG struct flags = 257 filename = '' FileDlgTitle = FileDlgTitle\0 fileDlg = atol( size) || atol( flags) || copies( \0, 12) || address( FileDlgTitle) || copies( \0, size - 24) fileDlg = overlay( FileMask, fileDlg, 53) -- Provide a starting path -- and a filetype filter. -- if owner should be Desktop: replace gethwndc(handle) with atol(1) result = dynalink32( 'PMCTLS', 'WINFILEDLG', atol( 1) || GethWndC( handle) /*atol( 1)*/ || -- Owner address( fileDlg)) if result then parse value substr( filedlg, 53) with filename \0 --dprintf( 'Button =' ltoa( substr( fileDlg, 13, 4), 10)'; file = "'filename'"') Button = ltoa( substr( fileDlg, 13, 4), 10) if Button = 1 & filename <> '' then if i = 1 then Dict = filename elseif i = 2 then Add = filename endif endif endif endif enddo return ; --------------------------------------------------------------------------- ; Available Netscape dictionaries ; http://service.boulder.ibm.com/asd-bin/doc/en_us/nsdicts/f-server.htm const compile if not defined( DICT_LIST) -- These dictionaries work: DICT_LIST = '/catala' || '/Catalan' || '/dansk' || '/Danish' || '/nedplus' || '/Dutch (Permissive spelling)' || '/nederlnd' || '/Dutch (Restrictive spelling)' || '/afrikaan' || '/Dutch (South Africa Afrikaan)' || '/aus' || '/English (Australian)' || '/uk' || '/English (United Kingdom)' || '/us' || '/English (United States)' || '/canadien' || '/French (Canadian)' || '/francais' || '/French (National)' || '/deutsch' || '/German (Before reform)' || '/deutsch2' || '/German (National reform)' || '/dschweiz' || '/German (Swiss)' || '/hellas' || '/Greek' || '/islensk' || '/Icelandic' || '/italiano' || '/Italian' || '/norbok' || '/Norwegian (Bokmal)' || '/nornyn' || '/Norwegian (Nynorsk)' || '/brasil' || '/Portuguese (Brazilian)' || '/portugal' || '/Portuguese (National)' || '/espana' || '/Spanish' || '/svensk' || '/Swedish' compile endif compile if not defined( OTHER_DICT_LIST) -- These dictionaries make EPM crash: (suomi.dic doesn't crash, but doesn't find a word) OTHER_DICT_LIST = '/czech' || '/Czech' || '/suomi' || '/Finnish' || '/magyar' || '/Hungarian' || '/polska' || '/Polish' || '/russian' || '/Russian' || '/turkiye' || '/Turkish' compile endif ; --------------------------------------------------------------------------- defproc GetDefaultDictLangName( DictBasename) List = DICT_LIST''OTHER_DICT_LIST -- String length = 645. Max length is 1599. Name = '' rest = List do while rest <> '' parse value rest with '/'next1'/'next2'/' -1 rest if next2 = '' then leave endif if upcase( DictBasename) = upcase( next1) then Name = next2 leave endif enddo if Name = '' then Name = DictBasename endif return Name ; --------------------------------------------------------------------------- defproc GetDictLangList LangList = '' rest = DICT_LIST do while rest <> '' parse value rest with '/'next1'/'next2'/' -1 rest if next2 = '' then leave endif Lang = next2 -- Append ' - downloaded' if .dic file found DictBasename = LangToDic( Lang) UserDir = NepmdQueryInstValue( 'USERDIR') DestDir = UserDir'\spellchk' DictFilename = DestDir'\'DictBasename'.dic' if Exist( DictFilename) then Lang = Lang' - downloaded' endif LangList = LangList'/'Lang enddo return LangList ; --------------------------------------------------------------------------- defproc LangToDic( DictLang) rest = DICT_LIST DictBasename = '' do while rest <> '' parse value rest with '/'next1'/'next2'/' -1 rest if next2 = '' then leave endif if upcase( DictLang) = upcase( next2) then DictBaseName = next1 leave endif enddo if DictBasename = '' then DictBasename = DictLang endif return DictBasename ; --------------------------------------------------------------------------- defproc GetDictLang KeyPath = '\NEPMD\User\Spellcheck\Language' ActiveNum = QueryConfigKey( KeyPath'\Selected') ActiveName = QueryConfigKey( KeyPath'\'ActiveNum'\Name') return ActiveName ; --------------------------------------------------------------------------- defproc GetDictBaseName DictBaseName = '' Dict = '' KeyPath = '\NEPMD\User\Spellcheck\Language' ActiveNum = QueryConfigKey( KeyPath'\Selected') DictList = QueryConfigKey( KeyPath'\'ActiveNum'\Dictionary') -- Get first filename if leftstr( DictList, 1) = '"' then parse value DictList with '"'Dict'"' . else parse value DictList with Dict . endif -- Strip path lp1 = lastpos( '\', Dict) if lp1 > 0 then DictBaseName = substr( Dict, lp1 + 1) -- Strip extension lp2 = lastpos( '.', DictBaseName) if lp2 > 0 then DictBaseName = leftstr( DictBaseName, lp2 - 1) DictBaseName = lowcase( DictBaseName) endif endif return DictBaseName ; --------------------------------------------------------------------------- defc SelectDownloadDict -- Open Listbox -- No Linebreak allowed in Text Title = 'Select a dictionary language for download' UserDir = NepmdQueryInstValue( 'USERDIR') DestDir = UserDir'\spellchk' Text = 'Destination: 'DestDir PreSelectNum = 1 DefButton = 1 -- OK HelpId = 0 LangList = GetDictLangList() Delim = leftstr( LangList, 1) refresh ret = ListBox( Title, LangList, '/'OK__MSG'/'CANCEL__MSG, -- buttons 6, 10, -- top, left, Min( count( Delim, LangList) + 1, 12), 70, -- height, width GethWndC( APP_HANDLE) || atoi( PreSelectNum) || atoi( DefButton) || atoi( HelpId) || Text\0) refresh -- Parse button number and selected list item string Button = asc( leftstr( ret, 1)) EOS = pos( \0, ret, 2) -- CHR( 0) signifies End Of String Select = substr( ret, 2, EOS - 2) if Button <> 1 then 'PostMe EditDictLang' return endif -- Strip appendix and convert to DictFilename parse value Select with Select' - downloaded' DictBasename = LangToDic( Select) DictFilename = DestDir'\'DictBasename'.dic' TmpFile = GetTmpPath()''DictBasename'.zip' KeyPath = '\NEPMD\User\Spellcheck\DictsPath' DictsPath = QueryConfigKey( KeyPath) Url = DictsPath''DictBasename'.zip' UrlFile = GetTmpDir()'\nepmd\tmp.url' EpmOpt = '' EpmCmd = 'ConfigDictLang DOWNLOAD' call WriteFile( UrlFile, Url) if Exist( TmpFile) then call DeleteFile( TmpFile) endif 'SayError Downloading 'Url -- Open a cmd window to execute wget, unzip and an EPM command. -- Must split the cmd in at least two parts, because otherwise it gets -- too long. Create a temporary cmd file. -- Another option would be to use multiple quietshell calls without -- a cmd window. But then a log file should be created to report details. CmdFile = GetTmpPath()'dldict.cmd' if Exist( CmdFile) then call DeleteFile( CmdFile) endif 'xcom e /c 'CmdFile .autosave = 0 KeyPath = '\NEPMD\User\Tools' WgetTemplate = QueryConfigKey( KeyPath'\wget\Template') UnzipTemplate = QueryConfigKey( KeyPath'\unzip\Template') EpmTemplate = QueryConfigKey( KeyPath'\epm\Template') -- EpmTemplate contains both single and double quotes. -- Single quotes in the template must be doubled additionally here, -- because the lines below are surrounded with single quotes themselves. WgetTemplate = DoubleCharInStr( "'", WgetTemplate) UnzipTemplate = DoubleCharInStr( "'", UnzipTemplate) EpmTemplate = DoubleCharInStr( "'", EpmTemplate) -- ERRORLEVEL is always 0 for wget. Therefore create a REXX cmd and check -- if downloaded TmpFile exists and if size is <> 0. insertline "/**/" insertline "ErrorTitle = 'SelectDownloadDict'" insertline "ErrorMessage = ''" insertline "do 1" insertline " '"ExpandTemplate( WgetTemplate, 'uf='UrlFile, 'of='TmpFile)"'" insertline " if stream( '"TmpFile"', 'c', 'query exist') = '' |," insertline " stream( '"TmpFile"', 'c', 'query size') = 0 then" insertline " do" insertline " ErrorMessage = 'Error: Download of "Url" failed.'" insertline " leave" insertline " end" insertline " '"ExpandTemplate( UnzipTemplate, 'if='TmpFile, 'od='DestDir)"'" insertline " if stream( '"DictFilename"', 'c', 'query exist') = '' |," insertline " stream( '"DictFilename"', 'c', 'query size') = 0 then" insertline " do" insertline " ErrorMessage = 'Error: Unzip of "TmpFile" failed.'" insertline " leave" insertline " end" insertline " '"ExpandTemplate( EpmTemplate, 'eo='EpmOpt, 'ec='EpmCmd, 'ef='DictFilename)"'" insertline " '@IF ERRORLEVEL 0 DEL %0'" insertline " '@EXIT'" insertline "end" insertline """@START epm /r 'ErrorMsgBox ""ErrorTitle"",""ErrorMessage""'""" insertline "'@PAUSE & EXIT'" 'xcom s' 'xcom q' -- Execute CmdFile in a cmd window 'os2 /k 'CmdFile return