"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18-x64/src/tcl/tclansifilter.c" (30 Jan 2021, 2638 Bytes) of package /windows/misc/ansifilter-2.18-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  * tclansifilter.c -- a minimal Tcl wrapper for ansifilter
    3  */
    4 #include <tcl.h>
    5 #include <memory>
    6 #include "../codegenerator.h"
    7 
    8 // Tcl namespace
    9 #define NS "ansifilter"
   10 
   11 // ansifilter requires C++ compiler
   12 extern "C" {
   13 
   14 
   15 static int
   16 Execute_Escape_Cmd(ansifilter::OutputType type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   17 {
   18     int i;
   19     // XXX this creates and destroys new instances for every call!
   20     auto_ptr<ansifilter::CodeGenerator> generator(ansifilter::CodeGenerator::getInstance(type));
   21     generator->setFragmentCode(1);     // -f
   22     generator->setPlainOutput(0);
   23     for (i = 1; i < objc; i++) {
   24         Tcl_AppendResult(interp, generator->generateString(Tcl_GetString(objv[i])).c_str(), NULL);
   25     }
   26     return TCL_OK;
   27 }
   28 
   29 static int
   30 LaTeXEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   31 {
   32     return Execute_Escape_Cmd(ansifilter::LATEX, interp, objc, objv);
   33 }
   34 
   35 static int
   36 TeXEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   37 {
   38     return Execute_Escape_Cmd(ansifilter::TEX, interp, objc, objv);
   39 }
   40 
   41 static int
   42 HtmlEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   43 {
   44     return Execute_Escape_Cmd(ansifilter::HTML, interp, objc, objv);
   45 }
   46 
   47 static int
   48 TextEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   49 {
   50     return Execute_Escape_Cmd(ansifilter::TEXT, interp, objc, objv);
   51 }
   52 
   53 static int
   54 BBCodeEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   55 {
   56     return Execute_Escape_Cmd(ansifilter::BBCODE, interp, objc, objv);
   57 }
   58 
   59 static int
   60 PangoEscape_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
   61 {
   62     return Execute_Escape_Cmd(ansifilter::PANGO, interp, objc, objv);
   63 }
   64 /*
   65  * Tclansifilter_Init -- Called when Tcl loads your extension.
   66  */
   67 int DLLEXPORT
   68 Tclansifilter_Init(Tcl_Interp *interp)
   69 {
   70     if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
   71         return TCL_ERROR;
   72     }
   73     // provide package
   74     if (Tcl_PkgProvide(interp, "ansifilter", "0.2") == TCL_ERROR) {
   75         return TCL_ERROR;
   76     }
   77     // create command
   78     Tcl_CreateObjCommand(interp, NS "::tex", TeXEscape_Cmd, NULL, NULL);
   79     Tcl_CreateObjCommand(interp, NS "::latex", LaTeXEscape_Cmd, NULL, NULL);
   80     Tcl_CreateObjCommand(interp, NS "::html", HtmlEscape_Cmd, NULL, NULL);
   81     Tcl_CreateObjCommand(interp, NS "::text", TextEscape_Cmd, NULL, NULL);
   82     Tcl_CreateObjCommand(interp, NS "::bbcode", BBCodeEscape_Cmd, NULL, NULL);
   83     Tcl_CreateObjCommand(interp, NS "::pango", PangoEscape_Cmd, NULL, NULL);
   84 
   85     return TCL_OK;
   86 }
   87 
   88 } // extern "C"