TSE: Extracting all defined templates from your template.dat file

3 views
Skip to first unread message

knud van eeden

unread,
Jan 10, 2023, 4:04:27 PM1/10/23
to SemWare TSE Pro Text Editor
Hello,

Use case: You have many templates (for example I about 7000 templates) for different programming languages and you want to extract only those templates for a particular computer language (e.g. only those for .jav, only those for .tex, ...)

Usage: Always backup your original template.dat file. Then run the program, 
supply the full path to your template.dat file,
supply the file extension (e.g. .jav) 
and accept the '1' for and keyword and also the corresponding template.
(choosing 0 should give only the keywords for that particular file extension and sort these).


// library: file: get: template: file: extension: keyword: all: to: buffer <description></description> 
// <version control></version control> <version>1.0.0.0.27</version> <version control></version control> 
// (filenamemacro=getfitbu.s) [<Program>] [<Research>] [kn, ri, mo, 09-01-2023 22:33:34]
INTEGER PROC FNFileGetTemplateFileExtensionKeywordAllToBufferB( STRING fileNameTemplateS, STRING fileExtensionS, INTEGER allB, INTEGER bufferI )
 INTEGER B = FALSE
 STRING s[255] = ""
 INTEGER I = 0
 Set( Break, ON )
 PushPosition()
 PushBlock()
 // erase / refresh / clean up
 PushPosition()
 PushBlock()
 IF EditFile( fileNameTemplateS )
  AbandonFile()
 ENDIF
 PopPosition()
 PopBlock()
 EditFile( fileNameTemplateS )
 IF NOT Find( "SemWare Template file... Do not edit", "gix" )
  Warn( "SemWare Template file... Do not edit", ":", " ", "not found. Please check." )
  PopBlock()
  PopPosition()
  B = FALSE
  RETURN( B )
 ENDIF
 Down()
 WHILE LFind( "^{[0-9]+}[ ]", "cgx" ) OR LFind( "^{[0-9][0-9][0-9][0-9]}[.]", "cgx" )
  // get the total amount of template text lines (e.g. 10 lines)
  s = GetFoundText( 1 )
  I = Val( s )
  s = GetText( 5, 4 ) // get the file extension (e.g. .jav)
  IF EquiStr( Trim( s ), Trim( fileExtensionS ) )
   AddLine( Trim( GetText( 9, 200 ) ), bufferI )
   IF ( allB )
    PushPosition()
    PushBlock()
    Down()
    BegLine()
    UnMarkBlock()
    MarkStream()
    Down( I - 1 )
    EndLine()
    MarkStream()
    Copy()
    GotoBufferId( bufferI )
    EndFile()
    AddLine()
    BegLine()
    Paste()
    EndFile()
    BegLine()
    InsertText( "──────────────────────────────────────────────────────────────────────────────" )
    PopBlock()
    PopPosition()
   ENDIF
  ENDIF
  Down( I + 1 )
 ENDWHILE
 // only sort if keywords only
 IF ( NOT allB )
  PushPosition()
  PushBlock()
  GotoBufferId( bufferI )
  MarkLine( 1, NumLines() )
  Sort()
  PopBlock()
  PopPosition()
 ENDIF
 IF EditFile( fileNameTemplateS )
  AbandonFile()
 ENDIF
 B = TRUE
 PopBlock()
 PopPosition()
 RETURN( B )
END

PROC Main()
 STRING s1[255] = "f:\bbc\taal\template.dat" // change this
 STRING s2[255] = ".jav" // change this
 STRING s3[255] = "1" // 0 means extract only the keywords for a given file extension / 1 means extract keyword and template text for a given file extension /change this
 INTEGER bufferI = 0
 PushPosition()
 bufferI = CreateTempBuffer()
 PopPosition()
 IF ( NOT ( Ask( "file: get: template: file: extension: keyword: all: to: buffer: fileNameTemplateS = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "file: get: template: file: extension: keyword: all: to: buffer: fileExtensionS = ", s2, _EDIT_HISTORY_ ) ) AND ( Length( s2 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "file: get: template: file: extension: keyword: all: to: buffer: allB = ", s3, _EDIT_HISTORY_ ) ) AND ( Length( s3 ) > 0 ) ) RETURN() ENDIF
 Message( FNFileGetTemplateFileExtensionKeywordAllToBufferB( s1, s2, Val( s3 ), bufferI ) ) // gives e.g. TRUE
 GotoBufferId( bufferI )
END

with friendly greetings
Knud van Eeden          

Reply all
Reply to author
Forward
0 new messages