Entry
TSE: Macro: Template: Parse: File: Template.dat: Abbreviation: Get: How to get the abbreviations?
Feb 28th, 2004 14:48
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 28 February 2004 - 05:38 am -------------------
TSE: Macro: Template: Parse: File: Template.dat: Abbreviation: Get:
How to get the abbreviations?
---
As your collection of abbreviations in template.dat will possibly grow
to possibly tens of thousands, extracting your abbreviations to a
database where you can e.g. search, edit and replace, getting
an overview of your existing abbreviations and remember what the
abbreviation is, might come very handy.
---
Steps: Overview:
1. -Make a backup of your original
template.dat file
2. -Run this macro
3. -It will ask for an input file
1. -Supply here your template.dat file
(or any file in the same format)
e.g.
c:\tse\template.dat
4. -It will ask for an output file
in which the generated records containing
the abbreviations will be stored
1. -Supply here any output filename
e.g.
c:\mytemporary.txt
5. -It will then start extracting the
abbreviations by reading that
template.dat input file.
And store the result in your
output file
6. -When finished, you will see a file containing
the abbreviation in a record structure like:
---
Q. Language: Computer: C: Template: Abbreviation: void ['void \c() {']
A.
02/28/2004
[.gf ...]
---
--- cut here -------------------------------------------------------
void \c() {
}
--- cut here -------------------------------------------------------
--------------------------------------------------------------------
Q. Language: Computer: C: Template: Abbreviation: switch ['switch ()']
A.
02/28/2004
[.gf ...]
---
--- cut here -------------------------------------------------------
switch (\c) {
default:
}
--- cut here -------------------------------------------------------
--------------------------------------------------------------------
---
7. -To see all your current abbreviations in one go
You can then e.g. use a regular expression search to see all your
current abbreviations (with the first line of the abbreviation
showing also)
1. -Goto that output file containing your records
e.g.
c:\mytemporary.txt
2. -select from TSE menu option 'File'
3. -select from list 'Search'
4. -select from list 'Find'
5. -To see all abbreviations in the file:
1. -Type the following text:
^Q\.
2. -and as the option use:
xv
3. You will then see in a glance all your abbreviations
like below:
---
Q. Computer: Language: C++: Abbreviation: w ['while']
Q. Computer: Language: C++: Abbreviation: f ['for']
Q. Computer: Language: C++: Abbreviation: fl ['float']
Q. Computer: Language: C++: Abbreviation: not ['!']
Q. Computer: Language: C++: Abbreviation: or ['||']
Q. Computer: Language: C++: Abbreviation: and ['&&']
Q. Computer: Language: C++: Abbreviation: == ['==']
Q. Computer: Language: C++: Abbreviation: = ['=']
Q. Computer: Language: C++: Abbreviation: <> ['!=']
Q. Computer: Language: C#: Abbreviation: not ['!']
Q. Computer: Language: C#: Abbreviation: or ['||']
Q. Computer: Language: C#: Abbreviation: and ['&&']
Q. Computer: Language: C#: Abbreviation: == ['==']
Q. Computer: Language: C#: Abbreviation: = ['=']
Q. Computer: Language: C#: Abbreviation: <> ['!=']
Q. Computer: Language: Delphi: Abbreviation: not ['not']
Q. Computer: Language: Delphi: Abbreviation: or ['or']
Q. Computer: Language: Delphi: Abbreviation: and ['and']
Q. Computer: Language: Delphi: Abbreviation: == ['=']
Q. Computer: Language: Delphi: Abbreviation: = [':=']
Q. Computer: Language: Delphi: Abbreviation: <> ['<>']
...
---
Note:
you see here clearly that you could use one central and same
abbreviation for all the computer languages.
e.g.
the equal sign '=' which expands differently depending on the current
file extension (e.g. to ':=' in Delphi, but to '=' in C++)).
So again an application of a basic programming language translator, for
quick and easy use, without having to think too much.
This principle you can use to generate quick and easy
translation between the different computer languages.
---
6. If you then want to see all abbreviations defined
e.g. only of the keyword 'for', you can search for:
1. -Type the following text:
^Q\..*: for
2. -and as the option use:
xv
this will show all 'for' abbreviations:
Like the following:
---
Q. BBCBASIC: for ['FOR loopindexI% = 1 TO 10']
Q. C: for ['int loopindexI = FNIntegerInitializeNewI();']
Q. C++: for ['int loopindexI = FNIntegerInitializeNewI();']
Q. Delphi: for ['var loopindexI : integer;']
Q. Java: for ['int loopindexI = FNIntegerInitializeNewI();']
Q. JavaScript: for ['var loopindexI = FNIntegerInitializeNewI();']
Q. Pascal: for ['for \c := to do begin']
Q. PERL: for ['for (my $i=1; $i<=$exponent; $i++) {']
Q. PHP: for ['$loopindexI=FNIntegerInitializeNewI();']
Q. Ruby: for ['for \c in do']
Q. TSE: for ['INTEGER loopindexI = FNIntegerInitializeNewI()']
Q. Visual Basic.NET: for ['Dim loopindexI As Integer']
...
---
-in general, type:
^Q\..*: <your keyword>
-to search for the keyword 'for' in a specific language,
like 'Delphi', use e.g.
^Q\..*Delphi.*: for
-in general, type:
^Q\..*<your language>.*: <your keyword>
---
8. Note:
If you want to replace an existing abbreviation or add a new
abbreviation, the best is extract once all your abbreviations in
this output file, and use that as the mother database once and
for all, in which all the editing from then on takes place.
You add then a record or replace the current information
in that output file, as usual by highlighting the
current information, and running the template macro
and then supplying the appropriate name.
---
Note: it might be that you have your own file extensions defined,
in that case add them at the appropriate positions
in the macro and recompile.
---
Note: all the lines below are each on one line.
---
--- cut here ---------------------------------------------------------
// library: file: get: template: data: extract
(filenamemacro=getfitda.s) [kn, ri, we, 25-02-2004 0:34:48]
PROC PROCFileGetTemplateDataExtract( STRING s, STRING keywordS, STRING
infoS, STRING filenameinputS, STRING filenameoutputS )
INTEGER I = 0
INTEGER abbreviationlinetotalI = 0
INTEGER showB = FALSE
STRING abbreviationfileextensionS[255] = ""
STRING abbreviationnameS[255] = ""
STRING lineS[255] = ""
EditFile( filenameinputS )
// 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
Message( "abbreviation total number of lines = " + Str(
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
Message( "abbreviation valid in all files" )
ELSE
// else in only the file with that extension
Message( "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
Message( "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
IF keywordS == ""
showB = TRUE
ELSEIF LTrim( RTrim( Lower( keywordS ) ) ) == LTrim( RTrim( Lower(
abbreviationnameS ) ) )
showB = TRUE
ELSE
showB = FALSE
ENDIF
IF LTrim( RTrim( Lower( abbreviationfileextensionS ) ) ) == LTrim(
RTrim( Lower( s ) ) ) AND showB
PushPosition()
EditFile( filenameoutputS )
EndFile()
AddLine( infoS + " " + "Template: Abbreviation: " +
abbreviationnameS )
//
PlaceMark( "Q" )
//
AddLine()
AddLine( "A." )
AddLine( GetDateStr() )
AddLine( "[.gf ...]" )
AddLine( "---" )
AddLine()
AddLine()
AddLine( "--- cut here ---------------------------------------------
------------" )
AddLine()
PopPosition()
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
lineS = GetText( 1, CurrLineLen() )
Message( "abbreviation body line" + Str( I ) + ": " + lineS )
PushPosition()
EditFile( filenameoutputS )
//
PushPosition()
IF I == 1
GotoMark( "Q" )
EndLine()
InsertText( " " + "['" + lineS + "']", _INSERT_ )
ENDIF
PopPosition()
//
AddLine( lineS )
PopPosition()
ENDWHILE
BegLine()
PushPosition()
EditFile( filenameoutputS )
AddLine()
AddLine( "--- cut here ---------------------------------------------
------------" )
AddLine( "----------------------------------------------------------
--------------------" )
Up()
PopPosition()
ENDIF
ENDWHILE
EditFile( filenameinputS )
AbandonFile()
EditFile( filenameoutputS )
END
PROC Main()
STRING keywordS[255] = ""
STRING filenameinputS[255]
= "c:\wordproc\tse32_v42003original\template.dat" // you will have to
change this to your template.dat
STRING filenameoutputS[255] = "c:\ddd.ddd"
// keywordS = "for"
keywordS = ""
REPEAT
IF NOT AskFilename( "Please browse to your 'template.dat'
abbreviation file on your computer", filenameinputS )
RETURN()
ENDIF
IF NOT FileExists( filenameinputS )
Warn( "This file does not exist. Please select an existing file with
the format of template.dat" )
ENDIF
UNTIL FileExists( filenameinputS )
IF NOT AskFilename( "Please supply a filename to store this
abbreviation database", filenameoutputS )
RETURN()
ENDIF
PROCFileGetTemplateDataExtract( ".asm", keywordS, "Q. Language:
Computer: Assembler:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".asp", keywordS, "Q. Language:
Computer: Server side include: Microsoft: ASP:", filenameinputS,
filenameoutputS )
PROCFileGetTemplateDataExtract( ".bas", keywordS, "Q. Language:
Computer: BASIC:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".bat", keywordS, "Q. Operation
system: DOS: Batch:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".bbc", keywordS, "Q. Language:
Computer: BASIC: BBCBASIC:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".c", keywordS, "Q. Language:
Computer: Compiler: C:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".cl", keywordS, "Q. Language:
Computer: LISP: Common:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".cob", keywordS, "Q. Language:
Computer: Cobol:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".cpp", keywordS, "Q. Language:
Computer: Compiler: C++:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".cs", keywordS, "Q. Language:
Computer: Compiler: C#:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".del", keywordS, "Q. Language:
Computer: Borland: Delphi:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".dok", keywordS, "Q. Dok:",
filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".dtd", keywordS, "Q. Language:
Computer: Document processing: XML: XSL: DTD:", filenameinputS,
filenameoutputS )
PROCFileGetTemplateDataExtract( ".f", keywordS, "Q. Language:
Computer: Fortran:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".htm", keywordS, "Q. Language:
Computer: HTML:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".idl", keywordS, "Q. Language:
Computer: Compiler: IDL:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".iss", keywordS, "Q. Installation:
Inno:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".jav", keywordS, "Q. Language:
Computer: Java:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".js", keywordS, "Q. Language:
Computer: Interpreter: JavaScript:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".jsp", keywordS, "Q. Language:
Computer: Server side include: JSP:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".lot", keywordS, "Q. Lotus Notes:
LotusScript:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".lsp", keywordS, "Q. Language:
Computer: LISP:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".map", keywordS, "Q. Math: Symbolic:
Maple:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".pas", keywordS, "Q. Language:
Computer: Pascal:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".pl", keywordS, "Q. Language:
Computer: Script language: PERL:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".php", keywordS, "Q. Language:
Computer: Script language: PHP:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".ps", keywordS, "Q. Language:
Computer: PostScript:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".prg", keywordS, "Q. Language:
Computer: Prg:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".py", keywordS, "Q. Language:
Computer: Script language: Python:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".rb", keywordS, "Q. Language:
Computer: Ruby:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".s", keywordS, "Q. Computer: Editor:
TSE:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".sql", keywordS, "Q. Language:
Computer: Database: SQL:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".tcl", keywordS, "Q. Language:
Computer: TCL:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".tex", keywordS, "Q. Wordprocessor:
Tex:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".uml", keywordS, "Q. Language:
Computer: UML:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".vb", keywordS, "Q. Language:
Computer: Microsoft: Visual Basic.NET:", filenameinputS,
filenameoutputS )
PROCFileGetTemplateDataExtract( ".vbs", keywordS, "Q. Language:
Computer: VBScript:", filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".wsh", keywordS, "Q. Language:
Computer: Script language: Windows Scripting Host: WSH:",
filenameinputS, filenameoutputS )
PROCFileGetTemplateDataExtract( ".xml", keywordS, "Q. Language:
Computer: Document processing: XML: XSL:", filenameinputS,
filenameoutputS )
PROCFileGetTemplateDataExtract( ".xsl", keywordS, "Q. Language:
Computer: Document processing: XML: XSL:", filenameinputS,
filenameoutputS )
PROCFileGetTemplateDataExtract( "", keywordS, "Q. File: All:",
filenameinputS, filenameoutputS )
END
<F12> Main()
--- cut here ---------------------------------------------------------
---
---
Internet: see also:
---
TSE: Macro: Template: Expand: Abbreviation: File: Parse: What is
format of template.dat file?
http://www.faqts.com/knowledge_base/view.phtml/aid/28897/fid/1657
---
Computer: Editor: TSE: Line: Wrap: Delete: Empty: How to wrap and
delete empty lines from 'cut here'
http://www.faqts.com/knowledge_base/view.phtml/aid/29224/fid/903
----------------------------------------------------------------------