"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/extras/tcl/tclhighlight.c" (12 May 2020, 3510 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * tclhighlight.c -- a minimal Tcl wrapper for highlight
    3  * based on the ansifilter extension of Martin Heinrich
    4  *
    5  * See README_TCL for compilation and usage
    6  *
    7  * Edit theme and syntax below
    8  */
    9 
   10 #include <tcl.h>
   11 #include <memory>
   12 #include "../../src/include/codegenerator.h"
   13 
   14 // Tcl namespace
   15 #define NS "highlight"
   16 
   17 // highlight requires C++ compiler
   18 extern "C" {
   19 
   20 static int
   21 Execute_Escape_Cmd(highlight::OutputType type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   22 {
   23     int i;
   24     // XXX this creates and destroys new instances for every call!
   25     unique_ptr<highlight::CodeGenerator> generator(highlight::CodeGenerator::getInstance(type));
   26 
   27     generator->initTheme ( "/usr/share/highlight/themes/edit-kwrite.theme" ); //EDIT theme
   28     generator->loadLanguage ( "/usr/share/highlight/langDefs/c.lang" );       //EDIT language definition
   29     generator->setFragmentCode(1);  // -f
   30     generator->disableTrailingNL(1);
   31 
   32     for (i = 1; i < objc; i++) {
   33         Tcl_AppendResult(interp, generator->generateString(Tcl_GetString(objv[i])).c_str(), NULL);
   34     }
   35     return TCL_OK;
   36 }
   37 
   38 static int
   39 LaTeXEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   40 {
   41     return Execute_Escape_Cmd(highlight::LATEX, interp, objc, objv);
   42 }
   43 
   44 static int
   45 TeXEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   46 {
   47     return Execute_Escape_Cmd(highlight::TEX, interp, objc, objv);
   48 }
   49 
   50 static int
   51 HtmlEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   52 {
   53     return Execute_Escape_Cmd(highlight::HTML, interp, objc, objv);
   54 }
   55 
   56 static int
   57 BBCodeEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   58 {
   59     return Execute_Escape_Cmd(highlight::BBCODE, interp, objc, objv);
   60 }
   61 
   62 static int
   63 PangoEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   64 {
   65     return Execute_Escape_Cmd(highlight::PANGO, interp, objc, objv);
   66 }
   67 
   68 static int
   69 AnsiEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   70 {
   71     return Execute_Escape_Cmd(highlight::ESC_ANSI, interp, objc, objv);
   72 }
   73 
   74 static int
   75 Xterm256Escape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   76 {
   77     return Execute_Escape_Cmd(highlight::ESC_XTERM256, interp, objc, objv);
   78 }
   79 static int
   80 TrueColorEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   81 {
   82     return Execute_Escape_Cmd(highlight::ESC_TRUECOLOR, interp, objc, objv);
   83 }
   84 /*
   85  * Tclhighlight_Init -- Called when Tcl loads your extension.
   86  */
   87 int DLLEXPORT
   88 Tclhighlight_Init(Tcl_Interp *interp)
   89 {
   90     if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
   91         return TCL_ERROR;
   92     }
   93     // provide package
   94     if (Tcl_PkgProvide(interp, "highlight", "0.1") == TCL_ERROR) {
   95         return TCL_ERROR;
   96     }
   97     // create command
   98     Tcl_CreateObjCommand(interp, NS "::tex", TeXEscape_Cmd, NULL, NULL);
   99     Tcl_CreateObjCommand(interp, NS "::latex", LaTeXEscape_Cmd, NULL, NULL);
  100     Tcl_CreateObjCommand(interp, NS "::html", HtmlEscape_Cmd, NULL, NULL);
  101     Tcl_CreateObjCommand(interp, NS "::bbcode", BBCodeEscape_Cmd, NULL, NULL);
  102     Tcl_CreateObjCommand(interp, NS "::pango", PangoEscape_Cmd, NULL, NULL);
  103     Tcl_CreateObjCommand(interp, NS "::ansi", AnsiEscape_Cmd, NULL, NULL);
  104     Tcl_CreateObjCommand(interp, NS "::xterm256", Xterm256Escape_Cmd, NULL, NULL);
  105     Tcl_CreateObjCommand(interp, NS "::truecolor", TrueColorEscape_Cmd, NULL, NULL);
  106     return TCL_OK;
  107 }
  108 
  109 } // extern "C"