faqts : Computers : Programming : Languages : Tse : Template

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

4 of 8 people (50%) answered Yes
Recently 4 of 8 people (50%) answered Yes

Entry

TSE: Macro: Template: Expand: Abbreviation: File: Parse: What is format of template.dat file?

Feb 27th, 2004 21:30
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 22 February 2004 - 05:15 pm -------------------

TSE: Macro: Template: Expand: Abbreviation: File: Parse: What is 
format of template.dat file?

---

One very handy macro for any typist using TSE is the

 template.s

macro, which you can find in your TSE

 ..\mac

directory

---

You can use this macro to dramatically shorten your typing time and
reduce possible typing errors all the time in your programming
languages, like

batch,
C#,
C++,
Delphi,
HTML,
Java,
JavaScript,
PHP,
Perl,
Python,
TSE,
Visual Basic,
XML,
...

by expanding your text after only typing a few characters, to say any
control structure like for, while, repeat, switch, ...

Or in general any situation where you as a typist have to repeatedly
type the same block of text.

So it could be one of your most used and most useful macros in your 
repertoire.

---
---

To use this macro:

Steps: Overview:

 1. -run the macro 'template.mac'

     1. run it as usual

        1. -select from menu option 'Macro'

        2. -select from list 'Execute'

        3. -type the name of your macro

             e.g.

              template.mac

             (you might have to type the full path)

     -- or --

     2. e.g. put the macro 'template.mac' in your autoload list so that
             it is automatically run at startup of your TSE.

        1. -select from menu option 'Macro'

        2. -select from list 'Autoload List'

        3. -type the name of your macro

            e.g.

             template.mac

             (you might have to type the full path)

        4. -Press <ENTER> when finished

 2. -then in your text, first highlight any text

 3. -press <CTRL><TAB>

 4. -select from list 'Add Marked Text as Template'

     1. -choose a (short) abbreviation name for your highlighted text

         e.g.

           test

         or even shorter

           t

     2. -choose a file extension for which this abbreviation
         should be active

         e.g.

          .bat if it should only be active in batch files

          .cpp if it should only be active in C++ files

          .cs if it should only be active in C# files

          .jav if it should only be active in Java files

          .js if it should only be active in JavaScript files

          .pas if it should only be active in Delphi files

          .pl if it should only be active in Perl files

          .php if it should only be active in PHP files

          .py if it should only be active in Python files

          .s if it should only be active in TSE files

          .txt if it should only be active in text files

          .vb if it should only be active in Visual Basic files

          .xml if it should only be active in XML files

          ...

            The advantage of this is for example that you can define
            one central abbreviation, and have it expanded depending on
            the current file extension.

            So note that you so basically have created in this way an
            efficient translator for each (computer) language, which
            generates say the correct 'for' code depending on your
            current file extension. It saves you a lot of thinking,
            possible lookup and if you have a correct template it will
            also be correct and without typing errors to start with.
            So you gain a lot of time.
            And your programs will contain uniform, standardized and
            similar structures, if you use this method consequently.

            So you could e.g. use the same abbreviation

             'for'

            to have it expanded to that specific

             'for..next'

            control structures in the computer language you are
            currently editing.

         ---

         or press <ENTER> if it should be active in any
         file

         ---

 5. - Any time you type that abbreviation name, and run the template
      macro (usually by putting the cursor behind it, and pressing
      <TAB>) it will then expand it to the original highlighted text.

      e.g. type a 't', put the cursor after it, then press <TAB>

---

You find some more information in this file 'template.s' itself,
about how it should be used.

---
---

Now your abbreviation information is stored in a text file, called:

 template.dat

---

It might come handy if you are able to extract this abbreviation
information out of this text file yourself

E.g. for purposes like:

 -sorting

 -searching

 -comparing

 -statistic

  ...

in case you would like to write your own macros for doing
this.

---

Here follows some information which might be of aid in this extraction.

---
---

Your new latest abbreviations are stored in the beginning of the file,
thus at the top.

---
---

If you open this template file, called 'template.dat'
(make a backup first), you might notice that it stores your
abbreviations almost as is.

But there is a clear structure.

After looking at a few lines, you can induct that:

---

The template file is a collection of one or more records.

Where each record starts
from the begin of the line
with an integer number,
then possibly some spaces,
then a file extension of
 a dot followed by up to 3 characters
  or
 only spaces (which indicates 'abbrevation active for all files')
then an abbreviation name made up of any characters
until the end of that line.
then follows the body of your abbreviation
consisting of as many lines down as indicated
by the earlier number.

---
---

Or thus as informal Backus Naur Form:

---

file = record*

---

record = [begin of line]
          [integer number indicating total amount of lines down]
          [spaces]*
          [file extension of a dot followed by up to 3 characters or 
only spaces]
          [abbreviation name of up to 16 characters]
          [spaces]*
         [end of line]
         [as much lines down as indicated by that integer number]

---
---

Or thus as a possible program (using regular expressions
to extract this information):

You can stop this (kept simple) program in between by pressing
<CTRL><break>

---
---

--- cut here ---------------------------------------------------------

PROC Main()

 INTEGER I = 0

 INTEGER abbreviationlinetotalI = 0

 STRING abbreviationfileextensionS[255] = ""

 STRING abbreviationnameS[255] = ""

 // change this to the path of your template.dat file

 EditFile( "c:\wordproc\tse32_v42003\template.dat" )

 // start at the begin of the file

 BegFile()

 // while you find lines starting with a number

 // followed by zero or more spaces

 // followed by a dot or space

 // followed by 1 lower or upper case character or digit or underscore 
or space

 // followed by 2 lower or upper case character or digit or underscore 
or space

 // followed by zero or more spaces

 // followed by a name made up by any characters, until the end of 
that line

 WHILE( LFind( "^{[0-9][0-9]?[0-9]?[0-9]?}\c[ ]*{[. ][A-Za-z0-9_ ][A-
Za-z0-9_ ]?[A-Za-z0-9_ ]?}[ ]*{.*}$", "x" ) )

  // get that first number, in a string

  // and convert that string to an integer

  abbreviationlinetotalI = Val( GetFoundText( 1 ) )

  // show that number, which is the total amount of lines you have to 
go down

  // and containing the text for that abbreviation

  Warn( "abbreviation total number of lines = ", 
abbreviationlinetotalI )

  // there might be zero or more spaces after this number

  // and skip them

  LFind( "{[ ]@}", "x" )

  // then you should find the file extension,

  // which is a dot followed by up to 3 characters or spaces

  LFind( "{[. ][A-Za-z0-9_ ][A-Za-z0-9_ ][A-Za-z0-9_ ]}\c", "x" )

  // get that file extension

  abbreviationfileextensionS = GetFoundText( 1 )

  // and show that file extension

  IF ( abbreviationfileextensionS[ 1 ] == " " )

   // if the file extension starts with a space it is valid in all 
files

   Warn( "abbreviation valid in all files" )

  ELSE

   // else in only the file with that extension

   Warn( "abbreviation file extension = ", abbreviationfileextensionS )

  ENDIF

  // there might be zero or more spaces after this number

  // and skip them

  LFind( "{[ ]@\c}", "x" )

  // then find that abbreviation name

  // which runs until the end of that line

  LFind( "{.@}$\c", "x" )

  // then get that abbreviation name

  abbreviationnameS = GetFoundText( 1 )

  // and show that abbreviation name

  Warn( "abbreviation short name = ", abbreviationnameS )

  // start the line counter

  I = 1 - 1

  // now get the body of that abbreviation

  // by going down as many lines as indicated by the

  // earlier first number

  WHILE Down() AND ( I < abbreviationlinetotalI )

   // increase the line counter with one line

   I = I + 1

   // and show then each of that lines while going down

   Warn( "abbreviation body line", I, ": ", GetText( 1, CurrLineLen
() ) )

  ENDWHILE

 ENDWHILE

END

<F12> Main()

--- cut here ---------------------------------------------------------

---
---

Internet: see also:

---

TSE: Macro: Template: Parse: File: Template.dat: Abbreviation: Get: 
How to get the abbreviations?
http://www.faqts.com/knowledge_base/view.phtml/aid/29203/fid/1657

----------------------------------------------------------------------