VBScript PDF Conversion Tool. 6. Auxiliary Functions: Reading configuration files

Source: Internet
Author: User
Tags constant definition keyword list

Configuration file structure

The configuration file is stored in the Config Directory, which consists of a Main file Main. conf and several sub-configuration files. Main. Conf stores the ing between the extension and sub-configuration files.

When the script runs, it first reads Main. conf and obtains the path of the sub-configuration file based on the content of Main. conf.

Which sub-configuration file is used depends on the extension of the file to be processed.

If no configuration is available, use the default settings (refer to the "constant definition" chapter ).

The configuration file supports single-line comments, starting. Tail annotations are not supported.

 

Main. Conf content example

H = cpp. conf <br/> c = cpp. conf <br/> hpp = cpp. conf <br/> cpp = cpp. conf <br/> hxx = cpp. conf <br/> cxx = cpp. conf <br/> cs = cs. conf <br/> vbs = vbs. conf <br/> SQL = SQL. conf <br/> txt = <br/> doc = <br/> docx = <br/> rtf = <br/> xml = <br/> html = <br/> text =

 

For example, the configuration file of the cpp file is cpp. conf.

 

Sub-configuration file example

The following uses Cpp. Conf as an example. Definition includes description, Case sensitivity, keyword color, keyword list configuration file, extended keyword color, extended keyword list configuration file, backward words (because the word will separate the # and the following words), the start and end characters of the comment, the color of the comment, the name, size, and color of the document font.

Description = C/C ++ Source Code <br/> CaseSensitive = true <br/> KeyWordColor = 255, <br/> KeyWordConf = CppKeyWord. conf <br/> ExtKeyWordColor = 0,128,128 <br/> ExtKeyWordConf = CppExtKeyWord. conf <br/> BackwardWord = # <br/> CommentsMark =/*, */| //,/n <br/> CommentsColor = 0,128, 0 <br/> FontName = <br/> FontSize = 10

 

Keyword list configuration file example

Check the keyword list of the Cpp file.

; Directive <br/> # if <br/> # else <br/> # endif <br/> # ifdef <br/> # ifndef <br/> # define <br/> # undef <br/> # undefine <br/> # include <br/> # pragma <br/> once <br/>; class <br/> using <br/> namespace <br/> template <br/> ....

 

Configuration File Read code

'================================================ =============================< Br/> 'configuration aupoliciary <br/> '=================================================== =================================< br/> function getconfigcontent (PATH) <br/> If filesysobj. fileexists (PATH) Then <br/> dim fileobj <br/> dim line, ext, confpath, POS <br/> dim keylist (), vallist () <br/> dim count: Count = 0 <br/> dim incstep: incstep = 4 <br/> set fileobj = filesysobj. opentextfile (path, 1) <br/> redim keylist (incstep) <br/> redim vallist (incstep) <br/> do until fileobj. atendofstream <br/> line = fileobj. readline <br/> Pos = instr (1, line, keyvaluedelimiter) </P> <p> If POS> 0 then <br/> ext = trim (mid (line, 1, pos-1) <br/> confpath = trim (mid (line, POS + 1) <br/> If Len (EXT)> 0 then <br/> If count> ubound (keylist) Then <br/> redim preserve keylist (ubound (keylist) + incstep) <br/> redim preserve vallist (ubound (vallist) + incstep) <br/> incstep = incstep * 2 <br/> end if <br/> keylist (count) = ext <br/> vallist (count) = confpath <br/> COUNT = count + 1 <br/> end if <br/> loop <br/> fileobj. close <br/> set fileobj = nothing <br/> If count> 0 then <br/> dim reslist () <br/> redim reslist (count-1, 1) <br/> for I = 0 to count-1 <br/> reslist (I, 0) = lcase (keylist (I) <br/> reslist (I, 1) = vallist (I) <br/> next </P> <p> getconfigcontent = reslist </P> <p> 'debug <br/> 'for I = lbound (reslist, 1) to ubound (reslist, 1) <br/> 'Log ("res (" & I & "):" & reslist (I, 0) & keyvaluedelimiter & reslist (I, 1) <br/> 'Next <br/> end if <br/> end function <br/> function getmainconfig () <br/> dim path: Path = getmainconfigpath () <br/> If filesysobj. fileexists (PATH) Then <br/> getmainconfig = getconfigcontent (PATH) <br/> end if <br/> end function <br/> function getextlist () <br/> dim allconfig: allconfig = getmainconfig () <br/> dim keylist () </P> <p> redim keylist (ubound (allconfig, 1 )) <br/> for m = 0 to ubound (allconfig, 1) <br/> keylist (m) = allconfig (M, 0) <br/> next <br/> getextlist = keylist <br/> end function <br/> function getextconfigpath (EXT) <br/> dim allconfig: allconfig = getmainconfig () <br/> dim Tag: Tag = lcase (EXT) <br/> for m = 0 to ubound (allconfig, 1) <br/> If allconfig (M, 0) = tag then <br/> getextconfigpath = allconfig (M, 1) <br/> exit for <br/> end if <br/> next <br/> end function <br/> function extconfigexists (EXT) <br/> dim conf: conf = getmainconfig () <br/> dim Tag: Tag = lcase (EXT) <br/> extconfigexists = false <br/> for m = 0 to ubound (Conf, 1) <br/> If conf (M, 0) = tag and Len (CONF (M, 1)> 0 then <br/> extconfigexists = filesysobj. fileexists (getconfigdir () & conf (M, 1 )) <br/> exit for <br/> end if <br/> next <br/> end function <br/> function getextconfig (EXT) <br/> dim path: path = getconfigdir () & getextconfigpath (EXT) <br/> If filesysobj. fileexists (PATH) Then <br/> getextconfig = getconfigcontent (PATH) <br/> end if 'if file exists <br/> end function <br/> function getconfig (EXT, key) <br/> If extconfigexists (EXT) Then <br/> dim conf: conf = getextconfig (EXT) <br/> dim Tag: Tag = lcase (key) </P> <p> for I = 0 to ubound (Conf, 1) <br/> If tag = lcase (CONF (I, 0 )) then <br/> getconfig = conf (I, 1) <br/> exit for <br/> end if <br/> next <br/> else <br/> getconfig = "" <br/> end if <br/> end function <br/> '==================================== =================< br/> 'get config value <br/> '============== =====================================================< br/> function getconfigdesc (EXT) <br/> getconfigdesc = getconfig (EXT, configkey_description) <br/> end function <br/> function getconfigcasesensitive (EXT) <br/> dim conf: conf = getconfig (EXT, configkey_casesensitive) <br/> If lcase (CONF) = "true" then <br/> getconfigcasesensitive = true <br/> else <br/> getconfigcasesensitive = false <br/> end if <br/> end function <br/> function getconfigcolor (EXT, key, defcolor) <br/> dim conf: conf = getconfig (EXT, key) <br/> getconfigcolor = defcolor <br/> If conf <> "" Then <br/> dim color: color = Split (Conf, colordelimiter) <br/> dim R, g, B </P> <p> r = color (0) <br/> G = color (1) <br/> B = color (2) <br/> getconfigcolor = RGB (CINT (R), CINT (G), CINT (B )) </P> <p> end if <br/> end function <br/> function getconfigkeywordcolor (EXT) <br/> getconfigkeywordcolor = getconfigcolor (EXT, configkey_keywordcolor, defakeykeywordcolor) <br/> end function <br/> function getconfigkeywordconffilepath (EXT) <br/> dim conf: conf = getconfig (EXT, configkey_keywordconf) <br/> If conf <> "" Then <br/> getconfigkeywordconffilepath = getconfigdir () & conf <br/> end if <br/> end function <br/> function getconfigextkeywordcolor (EXT) <br/> getconfigextkeywordcolor = getconfigcolor (EXT, configkey_extkeywordcolor, defaultextkeywordcolor) <br/> end function <br/> function getconfigextkeywordconfigfilepath (EXT) <br/> dim conf: conf = getconfig (EXT, configkey_extkeywordconf) <br/> If conf <> "" Then <br/> getconfigextkeywordconfigfilepath = getconfigdir () & conf <br/> end if <br/> end function <br/> function getconfigbackwardword (EXT) <br/> getconfigbackwardword = getconfig (EXT, configkey_backwardword) <br/> end function <br/> function getconfigcommentsmark (EXT) <br/> dim conf: conf = getconfig (EXT, configkey_commentsmark) <br/> dim markgroup: markgroup = Split (Conf, markdelimiter) <br/> dim count: Count = 0 <br/> dim startmark, endmark <br/> dim startmarklist (), endmarklist () <br/> dim incstep: incstep = 4 <br/> redim startmarklist (incstep) <br/> redim endmarklist (incstep) <br/> for each group in markgroup <br/> marks = Split (group, commentmarkdelimiter) <br/> If ubound (marks)> = 1 then <br/> startmark = trim (marks (0) <br/> endmark = trim (marks (1) <br/> If Len (startmark)> 0 and Len (endmark)> 0 then <br/> If count> ubound (startmarklist) Then <br/> redim preserve startmarklist (ubound (startmarklist) + incstep) <br/> redim preserve endmarklist (ubound (endmarklist) + incstep) <br/> incstep = incstep * 2 <br/> end if <br/> startmarklist (count) = startmark <br/> If lcase (endmark) = configval_carriagereturn then <br/> endmarklist (count) = vbcrlf <br/> else <br/> endmarklist (count) = endmark <br/> end if <br/> COUNT = count + 1 <br/> end if <br/> next <br/> dim markpairs () <br/> redim markpairs (count-1, 1) <br/> for I = 0 to count-1 <br/> markpairs (I, 0) = startmarklist (I) <br/> markpairs (I, 1) = endmarklist (I) <br/> next <br/> getconfigcommentsmark = markpairs <br/> end function <br/> function getconfigcommentscolor (EXT) <br/> getconfigcommentscolor = getconfigcolor (EXT, configkey_commentscolor, defaultcommentscolor) <br/> end function <br/> function getconfigstringmark (EXT) <br/> dim conf: conf = getconfig (EXT, configkey_stringmark) <br/> dim markgroup: markgroup = Split (Conf, markdelimiter) <br/> dim count: Count = 0 <br/> dim startmark, escstrmark <br/> dim startmarklist (), escmarklist () <br/> dim incstep: incstep = 4 <br/> redim startmarklist (incstep) <br/> redim escmarklist (incstep) <br/> for each group in markgroup <br/> marks = Split (group, commentmarkdelimiter) <br/> If ubound (marks)> = 1 then <br/> startmark = trim (marks (0) <br/> escstrmark = trim (marks (1) <br/> If Len (startmark)> 0 and Len (escstrmark)> 0 then <br/> If count> ubound (startmarklist) Then <br/> redim preserve startmarklist (ubound (startmarklist) + incstep) <br/> redim preserve escmarklist (ubound (escmarklist) + incstep) <br/> incstep = incstep * 2 <br/> end if <br/> startmarklist (count) = startmark <br/> escmarklist (count) = escstrmark <br/> COUNT = count + 1 <br/> end if <br/> next <br/> dim markpairs () <br/> redim markpairs (count-1, 1) <br/> for I = 0 to count-1 <br/> markpairs (I, 0) = startmarklist (I) <br/> markpairs (I, 1) = escmarklist (I) <br/> next <br/> getconfigstringmark = markpairs <br/> end function <br/> function getconfigstringcolor (EXT) <br/> getconfigstringcolor = getconfigcolor (EXT, configkey_stringcolor, defaultstringcolor) <br/> end function <br/> function getconfigfontname (EXT) <br/> getconfigfontname = getconfig (EXT, configkey_fontname) <br/> end function <br/> function getconfigfontsize (EXT) <br/> getconfigfontsize = getconfig (EXT, configkey_fontsize) <br/> end function <br/> function getconfigfontcolor (EXT) <br/> getconfigfontcolor = getconfigcolor (EXT, configkey_stringcolor, defaultfontcolor) <br/> end function <br/> function getwordlist (path, casesensitive) <br/> dim fileobj <br/> dim content <br/> dim hash: hash = createhash () <br/> set fileobj = filesysobj. opentextfile (path, 1) <br/> do until fileobj. atendofstream <br/> content = trim (fileobj. readline) </P> <p> If Len (content) = 0 or instr (1, content, configcommentsmark) = 1 then <br/> 'dummy <br/> else <br/> if not casesensitive then <br/> content = lcase (content) <br/> end if <br/> hashadd hash, casesensitive, content <br/> end if <br/> loop <br/> getwordlist = hash <br/> end function <br/> function getconfigkeywordlist (EXT, casesensitive) <br/> dim path: Path = getconfigkeywordconffilepath (EXT) <br/> If filesysobj. fileexists (PATH) Then <br/> getconfigkeywordlist = getwordlist (path, casesensitive) <br/> end if <br/> end function <br/> function getconfigextkeywordlist (EXT, casesensitive) <br/> dim path: Path = getconfigextkeywordconfigfilepath (EXT) <br/> If filesysobj. fileexists (PATH) Then <br/> getconfigextkeywordlist = getwordlist (path, casesensitive) <br/> end if <br/> end Function



 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.