faqts : Computers : Programming : Languages : Tse : File : Initalization / Configuration (.ini)

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

0 of 1 people (0%) answered Yes
Recently 0 of 1 people (0%) answered Yes

Entry

TSE: Variable: Global: Value: Get: How to possibly get from central initialization files?

Apr 30th, 2006 10:12
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden - 3 July 2003 - 10:24 pm --------------------------
TSE: Variable: Global: Value: Get: How to possibly get from central 
initialization files?
---
TSE: Initialization / Configuration: General: How to possibly handle
the question of the creation of general central initialization files
to get the value of your global variables in any of your TSE macros?
Steps: Overview:
 1. Create an initialization file
 2. In your macros get the
    variable value (given the
    variablename and the filename
    of the initialization file)
---
Steps: Worked out:
 1. -Create an initialization file
      The general format of this .ini files is:
      [some information1]
      variable11 = value11
      variable12 = value12
      variable13 = value13
      variable14 = value14
      ...
      variable1last = value1last
      [some information2]
      variable21 = value21
      variable22 = value22
      variable23 = value23
      variable24 = value24
      ...
      variable2last = value2last
      ...
      [some informationlast]
      variablelast1 = valuelast1
      variablelast2 = valuelast2
      variablelast3 = valuelast3
      variablelast4 = valuelast4
      ...
      variablelastlast = valuelastlast
      ---
      See e.g.:
       http://www.filext.com/detaillist.php?extdetail=ini
 2. -In your TSE macro to extract the value information from the given
     initialization file use a function like the following:
      yourvariablevalueS = FNStringGetVariableValueFileIniS
( "yourvariablename", yourinitializationfilenameS )
     ---
     The main advantages of using such a system are for example:
     1. Less memory needed to store your global variables:
        Because of you have all variables stored in external files, you
        avoid e.g. memory problems in your macros when having to
        initialize and or configure hundreds and or even thousands of
        global variables.
     2. Access from all your macros to one and only central
        initialization file:
        You only have to edit your variables in one place.
        All your macros can access it easily.
     3. External editing, independent of existing macros is
        possible:
        You can also quickly with an text editor change the files
        yourself from outside your macros (independent of them,
        so you do not need to recompile that macros for example)
     4. Uniform structure of the initialization file
        The structure of this .ini file is very uniform,
        that is by default:
        [ followed by some text ]
        <variablename> = <variable value>
        which makes it relatively easy to extract the wanted
        information.
        ---
        Note:
        In a lot of programs (e.g. Total Commander,
        http://www.ghisler.com), then in the menu choose
        'Configuration'->'Change settings file directly') they have
        used the same approach to initialize variables.
        ---
        Note:
        More general configuration files could be build using
        for example XML.
---
---
An example of the use of such a central initialization file
in your macros:
Here first an example of a possible initialization file, and then a
function (to be used in any of your macros), which extracts the
requested (global) variable value, given the variablename and the
initialization
filename.
---
Step 1. save this text below as 'yourfilename.ini',
        (this is just an example of a possible initialization
        file, edit it to adapt it to your own global
        initialization variables)
--- cut here: begin --------------------------------------------------
[COMMAND PROCESSOR: 4DOS]
path4dos = c:\4dos
[PROGRAM FILES: MICROSOFT WINDOWS]
pathprogramfiles = c:\program files
[WORDPROCESSOR: DEFAULT]
pathwordprocessordefault = c:\wordproc\tse32_v4\g32.exe
pathwordprocessordefaultdirectorystart = c:\wordproc\tse32_v4\
[WORDPROCESSOR: TSE]
pathtse = c:\wordproc
--- cut here: end ----------------------------------------------------
Step 2. save and run this macro to extract your global variablevalues
        (given the variablename, and the filename)
        from the above central initialization file,
        in any of your macros.
        E.g. to find the value of the 'path4dos' variable, to be used
             in any of your macros, you could use:
             path4dosS = FNStringGetVariableValueFileIniS
( 'path4dos', 'yourfilename.ini' )
--- cut here: begin --------------------------------------------------
// library: string: get: variable: value: file: ini
(filenamemacro=getstfin.s) [kn, ni, fr, 04-07-2003 11:04:17]
STRING PROC FNStringGetVariableValueFileIniS( STRING searchS, STRING
filenameS )
 STRING lineS[255] = ""
 STRING s[255] = ""
 INTEGER T = 0
 IF NOT EditFile( filenameS ) // open the given initialization file
  Warn( "file ", filenameS, " not found. Possibly create one (by e.g.
copying and pasting the .ini text above in this example in a file with
the name 'yourfilename.ini')" )
 ENDIF
 IF NOT LFind( searchS, "gi" ) // search for the given name
  RETURN( searchS + ": not found" )
 ENDIF
 lineS = GetText( 1, 255 ) // get current line
 IF NOT( GetToken( lineS, " ", 2 ) == "=" )
 // check if the format is <name> = <value,
 // by checking if the second token is the equal sign
  Warn( "no '=' found" )
  RETURN( searchS + ":not found" )
 ENDIF
 FOR T = 3 TO NumTokens( lineS, " " )
 // take out everything after the second token '='
  s = s + GetToken( lineS, " ", T ) + " "
  // by taking out all words separated by spaces
  // and building it up again, word after word,
  // and putting one space after it
 ENDFOR
 s = RTrim( s ) // remove the just added last space here
 QuitFile() // close the current file: given initialization file
 RETURN( s )
END
 PROC Main()
// get a global variable
Warn( FNStringGetVariableValueFileIniS
( "path4dos", "c:\dddpath.ini" ) )
// get another global variable
Warn( FNStringGetVariableValueFileIniS
( "pathprogramfiles", "c:\dddpath.ini" ) )
// get another global variable
Warn( FNStringGetVariableValueFileIniS
( "pathwordprocessordefault", "c:\dddpath.ini" ) )
END
<F12> Main()
--- cut here: end ----------------------------------------------------
---
---
See also the built in TSE commands:
GetProfileInt()
GetProfileStr()
WriteProfileInt()
WriteProfileStr()
in TSE v4.0
(check the TSE help)
---
---
Internet: see also:
---
Michael Graham ini files (e.g. Prof134.zip)
http://www.occamstoothbrush.com/tsemac
---
Language: Computer: Initialization: Link: Can you give an overview of 
links?
http://www.faqts.com/knowledge_base/view.phtml/aid/40799/fid/138
----------------------------------------------------------------------