Fossil SCM
More minor internal consistency cleanups.
Commit
495f26a00eb7e4a5c2722a7583c7251197c0b382
Parent
c25a5d199b7dd52…
3 files changed
+26
-18
+12
-7
+1
-1
M
src/th.c
+26
-18
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -7,29 +7,19 @@ | ||
| 7 | 7 | #include "th.h" |
| 8 | 8 | #include <string.h> |
| 9 | 9 | #include <assert.h> |
| 10 | 10 | #include <stdio.h> /* FILE class */ |
| 11 | 11 | |
| 12 | -/* | |
| 13 | -** Th_Output_f() impl which redirects output to a Th_Ob_Manager. | |
| 14 | -*/ | |
| 15 | -static int Th_Output_f_ob( char const * zData, int len, void * pState ); | |
| 16 | - | |
| 17 | -/* | |
| 18 | -** Th_Output::dispose() impl which requires pState to be-a Th_Ob_Manager. | |
| 19 | -*/ | |
| 20 | -static void Th_Output_dispose_ob( void * pState ); | |
| 21 | - | |
| 22 | 12 | typedef struct Th_Command Th_Command; |
| 23 | 13 | typedef struct Th_Frame Th_Frame; |
| 24 | 14 | typedef struct Th_Variable Th_Variable; |
| 25 | 15 | |
| 26 | 16 | /* |
| 27 | 17 | ** Shared instance. See th.h for the docs. |
| 28 | 18 | */ |
| 29 | 19 | const Th_Vtab_OutputMethods Th_Vtab_OutputMethods_FILE = { |
| 30 | - Th_Output_f_FILE /* write() */, | |
| 20 | + Th_Output_f_FILE /* xWrite() */, | |
| 31 | 21 | Th_Output_dispose_FILE /* dispose() */, |
| 32 | 22 | NULL /*pState*/, |
| 33 | 23 | 1/*enabled*/ |
| 34 | 24 | }; |
| 35 | 25 | |
| @@ -1443,16 +1433,16 @@ | ||
| 1443 | 1433 | return p; |
| 1444 | 1434 | } |
| 1445 | 1435 | |
| 1446 | 1436 | |
| 1447 | 1437 | int Th_Vtab_Output( Th_Vtab *vTab, char const * zData, int nData ){ |
| 1448 | - if(!vTab->out.write){ | |
| 1438 | + if(!vTab->out.xWrite){ | |
| 1449 | 1439 | return -1; |
| 1450 | 1440 | }else if(!vTab->out.enabled){ |
| 1451 | 1441 | return 0; |
| 1452 | 1442 | }else{ |
| 1453 | - return vTab->out.write( zData, nData, vTab->out.pState ); | |
| 1443 | + return vTab->out.xWrite( zData, nData, vTab->out.pState ); | |
| 1454 | 1444 | } |
| 1455 | 1445 | } |
| 1456 | 1446 | |
| 1457 | 1447 | |
| 1458 | 1448 | int Th_Output( Th_Interp *pInterp, char const * zData, int nData ){ |
| @@ -1748,12 +1738,12 @@ | ||
| 1748 | 1738 | Th_HashDelete(interp, interp->paGc); |
| 1749 | 1739 | interp->paGc = NULL; |
| 1750 | 1740 | } |
| 1751 | 1741 | |
| 1752 | 1742 | /* Clean up the output abstraction. */ |
| 1753 | - if( interp->pVtab && interp->pVtab->out.dispose ){ | |
| 1754 | - interp->pVtab->out.dispose( interp->pVtab->out.pState ); | |
| 1743 | + if( interp->pVtab && interp->pVtab->out.xDispose ){ | |
| 1744 | + interp->pVtab->out.xDispose( interp->pVtab->out.pState ); | |
| 1755 | 1745 | } |
| 1756 | 1746 | |
| 1757 | 1747 | /* Delete the contents of the global frame. */ |
| 1758 | 1748 | thPopFrame(interp); |
| 1759 | 1749 | |
| @@ -2806,10 +2796,20 @@ | ||
| 2806 | 2796 | Th_Vtab_OutputMethods parts for purposes of stacking layers of |
| 2807 | 2797 | buffers. We could add access to it via the public interface, |
| 2808 | 2798 | but that didn't seem appropriate. |
| 2809 | 2799 | */ |
| 2810 | 2800 | |
| 2801 | +/* | |
| 2802 | +** Th_Output_f() impl which redirects output to a Th_Ob_Manager. | |
| 2803 | +** Requires that pState be a (Th_Ob_Man*). | |
| 2804 | +*/ | |
| 2805 | +static int Th_Output_f_ob( char const * zData, int len, void * pState ); | |
| 2806 | + | |
| 2807 | +/* | |
| 2808 | +** Th_Output::dispose() impl which requires pState to be-a Th_Ob_Manager. | |
| 2809 | +*/ | |
| 2810 | +static void Th_Output_dispose_ob( void * pState ); | |
| 2811 | 2811 | |
| 2812 | 2812 | /* Empty-initialized Th_Ob_Manager instance. */ |
| 2813 | 2813 | #define Th_Ob_Man_empty_m { \ |
| 2814 | 2814 | NULL/*aBuf*/, \ |
| 2815 | 2815 | 0/*nBuf*/, \ |
| @@ -2864,11 +2864,11 @@ | ||
| 2864 | 2864 | assert( b ); |
| 2865 | 2865 | blob_append( b, zData, len ); |
| 2866 | 2866 | return len; |
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | -static void Th_Output_dispose_ob( void * pState ){ | |
| 2869 | +void Th_Output_dispose_ob( void * pState ){ | |
| 2870 | 2870 | /* possible todo: move the cleanup logic from |
| 2871 | 2871 | Th_Ob_Pop() to here? */ |
| 2872 | 2872 | #if 0 |
| 2873 | 2873 | Th_Ob_Manager * pMan = (Th_Ob_Manager*)pState; |
| 2874 | 2874 | Blob * b = Th_Ob_GetCurrentBuffer( pMan ); |
| @@ -2940,13 +2940,21 @@ | ||
| 2940 | 2940 | Th_Vtab_OutputMethods * theOut; |
| 2941 | 2941 | assert( pMan->nBuf > pMan->cursor ); |
| 2942 | 2942 | rc = pMan->aBuf[pMan->cursor]; |
| 2943 | 2943 | pMan->aBuf[pMan->cursor] = NULL; |
| 2944 | 2944 | theOut = &pMan->aOutput[pMan->cursor]; |
| 2945 | - if( theOut->dispose ){ | |
| 2946 | - theOut->dispose( theOut->pState ); | |
| 2945 | +#if 0 | |
| 2946 | + /* We need something like this (but not this!) if we extend the | |
| 2947 | + support to use other (non-Blob) proxies. We will likely need | |
| 2948 | + another callback function or two for that case, e.g. xStart() | |
| 2949 | + and xEnd(), which would be called when they are pushed/popped | |
| 2950 | + to/from the stack. | |
| 2951 | + */ | |
| 2952 | + if( theOut->xDispose ){ | |
| 2953 | + theOut->xDispose( theOut->pState ); | |
| 2947 | 2954 | } |
| 2955 | +#endif | |
| 2948 | 2956 | pMan->interp->pVtab->out = *theOut; |
| 2949 | 2957 | pMan->aOutput[pMan->cursor] = Th_Vtab_OutputMethods_empty; |
| 2950 | 2958 | if(-1 == --pMan->cursor){ |
| 2951 | 2959 | Th_Interp * interp = pMan->interp; |
| 2952 | 2960 | Th_Free( pMan->interp, pMan->aBuf ); |
| 2953 | 2961 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -7,29 +7,19 @@ | |
| 7 | #include "th.h" |
| 8 | #include <string.h> |
| 9 | #include <assert.h> |
| 10 | #include <stdio.h> /* FILE class */ |
| 11 | |
| 12 | /* |
| 13 | ** Th_Output_f() impl which redirects output to a Th_Ob_Manager. |
| 14 | */ |
| 15 | static int Th_Output_f_ob( char const * zData, int len, void * pState ); |
| 16 | |
| 17 | /* |
| 18 | ** Th_Output::dispose() impl which requires pState to be-a Th_Ob_Manager. |
| 19 | */ |
| 20 | static void Th_Output_dispose_ob( void * pState ); |
| 21 | |
| 22 | typedef struct Th_Command Th_Command; |
| 23 | typedef struct Th_Frame Th_Frame; |
| 24 | typedef struct Th_Variable Th_Variable; |
| 25 | |
| 26 | /* |
| 27 | ** Shared instance. See th.h for the docs. |
| 28 | */ |
| 29 | const Th_Vtab_OutputMethods Th_Vtab_OutputMethods_FILE = { |
| 30 | Th_Output_f_FILE /* write() */, |
| 31 | Th_Output_dispose_FILE /* dispose() */, |
| 32 | NULL /*pState*/, |
| 33 | 1/*enabled*/ |
| 34 | }; |
| 35 | |
| @@ -1443,16 +1433,16 @@ | |
| 1443 | return p; |
| 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | int Th_Vtab_Output( Th_Vtab *vTab, char const * zData, int nData ){ |
| 1448 | if(!vTab->out.write){ |
| 1449 | return -1; |
| 1450 | }else if(!vTab->out.enabled){ |
| 1451 | return 0; |
| 1452 | }else{ |
| 1453 | return vTab->out.write( zData, nData, vTab->out.pState ); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | |
| 1458 | int Th_Output( Th_Interp *pInterp, char const * zData, int nData ){ |
| @@ -1748,12 +1738,12 @@ | |
| 1748 | Th_HashDelete(interp, interp->paGc); |
| 1749 | interp->paGc = NULL; |
| 1750 | } |
| 1751 | |
| 1752 | /* Clean up the output abstraction. */ |
| 1753 | if( interp->pVtab && interp->pVtab->out.dispose ){ |
| 1754 | interp->pVtab->out.dispose( interp->pVtab->out.pState ); |
| 1755 | } |
| 1756 | |
| 1757 | /* Delete the contents of the global frame. */ |
| 1758 | thPopFrame(interp); |
| 1759 | |
| @@ -2806,10 +2796,20 @@ | |
| 2806 | Th_Vtab_OutputMethods parts for purposes of stacking layers of |
| 2807 | buffers. We could add access to it via the public interface, |
| 2808 | but that didn't seem appropriate. |
| 2809 | */ |
| 2810 | |
| 2811 | |
| 2812 | /* Empty-initialized Th_Ob_Manager instance. */ |
| 2813 | #define Th_Ob_Man_empty_m { \ |
| 2814 | NULL/*aBuf*/, \ |
| 2815 | 0/*nBuf*/, \ |
| @@ -2864,11 +2864,11 @@ | |
| 2864 | assert( b ); |
| 2865 | blob_append( b, zData, len ); |
| 2866 | return len; |
| 2867 | } |
| 2868 | |
| 2869 | static void Th_Output_dispose_ob( void * pState ){ |
| 2870 | /* possible todo: move the cleanup logic from |
| 2871 | Th_Ob_Pop() to here? */ |
| 2872 | #if 0 |
| 2873 | Th_Ob_Manager * pMan = (Th_Ob_Manager*)pState; |
| 2874 | Blob * b = Th_Ob_GetCurrentBuffer( pMan ); |
| @@ -2940,13 +2940,21 @@ | |
| 2940 | Th_Vtab_OutputMethods * theOut; |
| 2941 | assert( pMan->nBuf > pMan->cursor ); |
| 2942 | rc = pMan->aBuf[pMan->cursor]; |
| 2943 | pMan->aBuf[pMan->cursor] = NULL; |
| 2944 | theOut = &pMan->aOutput[pMan->cursor]; |
| 2945 | if( theOut->dispose ){ |
| 2946 | theOut->dispose( theOut->pState ); |
| 2947 | } |
| 2948 | pMan->interp->pVtab->out = *theOut; |
| 2949 | pMan->aOutput[pMan->cursor] = Th_Vtab_OutputMethods_empty; |
| 2950 | if(-1 == --pMan->cursor){ |
| 2951 | Th_Interp * interp = pMan->interp; |
| 2952 | Th_Free( pMan->interp, pMan->aBuf ); |
| 2953 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -7,29 +7,19 @@ | |
| 7 | #include "th.h" |
| 8 | #include <string.h> |
| 9 | #include <assert.h> |
| 10 | #include <stdio.h> /* FILE class */ |
| 11 | |
| 12 | typedef struct Th_Command Th_Command; |
| 13 | typedef struct Th_Frame Th_Frame; |
| 14 | typedef struct Th_Variable Th_Variable; |
| 15 | |
| 16 | /* |
| 17 | ** Shared instance. See th.h for the docs. |
| 18 | */ |
| 19 | const Th_Vtab_OutputMethods Th_Vtab_OutputMethods_FILE = { |
| 20 | Th_Output_f_FILE /* xWrite() */, |
| 21 | Th_Output_dispose_FILE /* dispose() */, |
| 22 | NULL /*pState*/, |
| 23 | 1/*enabled*/ |
| 24 | }; |
| 25 | |
| @@ -1443,16 +1433,16 @@ | |
| 1433 | return p; |
| 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | int Th_Vtab_Output( Th_Vtab *vTab, char const * zData, int nData ){ |
| 1438 | if(!vTab->out.xWrite){ |
| 1439 | return -1; |
| 1440 | }else if(!vTab->out.enabled){ |
| 1441 | return 0; |
| 1442 | }else{ |
| 1443 | return vTab->out.xWrite( zData, nData, vTab->out.pState ); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | int Th_Output( Th_Interp *pInterp, char const * zData, int nData ){ |
| @@ -1748,12 +1738,12 @@ | |
| 1738 | Th_HashDelete(interp, interp->paGc); |
| 1739 | interp->paGc = NULL; |
| 1740 | } |
| 1741 | |
| 1742 | /* Clean up the output abstraction. */ |
| 1743 | if( interp->pVtab && interp->pVtab->out.xDispose ){ |
| 1744 | interp->pVtab->out.xDispose( interp->pVtab->out.pState ); |
| 1745 | } |
| 1746 | |
| 1747 | /* Delete the contents of the global frame. */ |
| 1748 | thPopFrame(interp); |
| 1749 | |
| @@ -2806,10 +2796,20 @@ | |
| 2796 | Th_Vtab_OutputMethods parts for purposes of stacking layers of |
| 2797 | buffers. We could add access to it via the public interface, |
| 2798 | but that didn't seem appropriate. |
| 2799 | */ |
| 2800 | |
| 2801 | /* |
| 2802 | ** Th_Output_f() impl which redirects output to a Th_Ob_Manager. |
| 2803 | ** Requires that pState be a (Th_Ob_Man*). |
| 2804 | */ |
| 2805 | static int Th_Output_f_ob( char const * zData, int len, void * pState ); |
| 2806 | |
| 2807 | /* |
| 2808 | ** Th_Output::dispose() impl which requires pState to be-a Th_Ob_Manager. |
| 2809 | */ |
| 2810 | static void Th_Output_dispose_ob( void * pState ); |
| 2811 | |
| 2812 | /* Empty-initialized Th_Ob_Manager instance. */ |
| 2813 | #define Th_Ob_Man_empty_m { \ |
| 2814 | NULL/*aBuf*/, \ |
| 2815 | 0/*nBuf*/, \ |
| @@ -2864,11 +2864,11 @@ | |
| 2864 | assert( b ); |
| 2865 | blob_append( b, zData, len ); |
| 2866 | return len; |
| 2867 | } |
| 2868 | |
| 2869 | void Th_Output_dispose_ob( void * pState ){ |
| 2870 | /* possible todo: move the cleanup logic from |
| 2871 | Th_Ob_Pop() to here? */ |
| 2872 | #if 0 |
| 2873 | Th_Ob_Manager * pMan = (Th_Ob_Manager*)pState; |
| 2874 | Blob * b = Th_Ob_GetCurrentBuffer( pMan ); |
| @@ -2940,13 +2940,21 @@ | |
| 2940 | Th_Vtab_OutputMethods * theOut; |
| 2941 | assert( pMan->nBuf > pMan->cursor ); |
| 2942 | rc = pMan->aBuf[pMan->cursor]; |
| 2943 | pMan->aBuf[pMan->cursor] = NULL; |
| 2944 | theOut = &pMan->aOutput[pMan->cursor]; |
| 2945 | #if 0 |
| 2946 | /* We need something like this (but not this!) if we extend the |
| 2947 | support to use other (non-Blob) proxies. We will likely need |
| 2948 | another callback function or two for that case, e.g. xStart() |
| 2949 | and xEnd(), which would be called when they are pushed/popped |
| 2950 | to/from the stack. |
| 2951 | */ |
| 2952 | if( theOut->xDispose ){ |
| 2953 | theOut->xDispose( theOut->pState ); |
| 2954 | } |
| 2955 | #endif |
| 2956 | pMan->interp->pVtab->out = *theOut; |
| 2957 | pMan->aOutput[pMan->cursor] = Th_Vtab_OutputMethods_empty; |
| 2958 | if(-1 == --pMan->cursor){ |
| 2959 | Th_Interp * interp = pMan->interp; |
| 2960 | Th_Free( pMan->interp, pMan->aBuf ); |
| 2961 |
M
src/th.h
+12
-7
| --- src/th.h | ||
| +++ src/th.h | ||
| @@ -47,15 +47,15 @@ | ||
| 47 | 47 | ** Th_Vtab. It is intended that a given Vtab be able to swap out |
| 48 | 48 | ** output back-ends during its lifetime, e.g. to form a stack of |
| 49 | 49 | ** buffers. |
| 50 | 50 | */ |
| 51 | 51 | struct Th_Vtab_OutputMethods { |
| 52 | - Th_Output_f write; /* output handler */ | |
| 53 | - void (*dispose)( void * pState ); /* Called when the framework is done with | |
| 52 | + Th_Output_f xWrite; /* output handler */ | |
| 53 | + void (*xDispose)( void * pState ); /* Called when the framework is done with | |
| 54 | 54 | this output handler,passed this object's |
| 55 | 55 | pState pointer.. */ |
| 56 | - void * pState; /* final argument for write() and dispose()*/ | |
| 56 | + void * pState; /* final argument for xWrite() and xDispose()*/ | |
| 57 | 57 | char enabled; /* if 0, Th_Output() does nothing. */ |
| 58 | 58 | }; |
| 59 | 59 | typedef struct Th_Vtab_OutputMethods Th_Vtab_OutputMethods; |
| 60 | 60 | |
| 61 | 61 | /* |
| @@ -97,11 +97,11 @@ | ||
| 97 | 97 | typedef struct Th_Interp Th_Interp; |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /* |
| 101 | 101 | ** Creates a new interpreter instance using the given v-table. pVtab |
| 102 | -** must outlive the returned object, and pVtab->out.dispose() will be | |
| 102 | +** must outlive the returned object, and pVtab->out.xDispose() will be | |
| 103 | 103 | ** called when the interpreter is cleaned up. The optional "ob" API |
| 104 | 104 | ** swaps out Vtab::out instances, so pVtab->out might not be active |
| 105 | 105 | ** for the entire lifetime of the interpreter. |
| 106 | 106 | ** |
| 107 | 107 | ** Potential TODO: we "should probably" add a dispose() method to the |
| @@ -371,13 +371,13 @@ | ||
| 371 | 371 | ** NULL). |
| 372 | 372 | */ |
| 373 | 373 | int Th_Output_f_FILE( char const * zData, int len, void * pState ); |
| 374 | 374 | |
| 375 | 375 | /* |
| 376 | -** A Th_Vtab_OutputMethods::dispose() impl for FILE handles. If pState is not | |
| 376 | +** A Th_Vtab_OutputMethods::xDispose() impl for FILE handles. If pState is not | |
| 377 | 377 | ** one of the standard streams (stdin, stdout, stderr) then it is |
| 378 | -** fclose()d. | |
| 378 | +** fclose()d by this call. | |
| 379 | 379 | */ |
| 380 | 380 | void Th_Output_dispose_FILE( void * pState ); |
| 381 | 381 | |
| 382 | 382 | /* |
| 383 | 383 | ** A helper type for holding lists of function registration information. |
| @@ -444,11 +444,16 @@ | ||
| 444 | 444 | */ |
| 445 | 445 | int Th_RegisterCommands( Th_Interp * interp, Th_Command_Reg const * pList ); |
| 446 | 446 | |
| 447 | 447 | #ifdef TH_ENABLE_OB |
| 448 | 448 | /* |
| 449 | -** Output buffer stack manager for TH. Used/managed by the Th_ob_xxx() functions. | |
| 449 | +** Output buffer stack manager for TH. Used/managed by the Th_ob_xxx() | |
| 450 | +** functions. This class manages Th_Interp::pVtab->out for a specific | |
| 451 | +** interpreter, swapping it in and out in order to redirect output | |
| 452 | +** generated via Th_Output() to internal buffers. The buffers can be | |
| 453 | +** pushed and popped from the stack, allowing clients to selectively | |
| 454 | +** capture output for a given block of TH1 code. | |
| 450 | 455 | */ |
| 451 | 456 | struct Th_Ob_Manager { |
| 452 | 457 | Blob ** aBuf; /* Stack of Blobs */ |
| 453 | 458 | int nBuf; /* Number of blobs */ |
| 454 | 459 | int cursor; /* Current level (-1=not active) */ |
| 455 | 460 |
| --- src/th.h | |
| +++ src/th.h | |
| @@ -47,15 +47,15 @@ | |
| 47 | ** Th_Vtab. It is intended that a given Vtab be able to swap out |
| 48 | ** output back-ends during its lifetime, e.g. to form a stack of |
| 49 | ** buffers. |
| 50 | */ |
| 51 | struct Th_Vtab_OutputMethods { |
| 52 | Th_Output_f write; /* output handler */ |
| 53 | void (*dispose)( void * pState ); /* Called when the framework is done with |
| 54 | this output handler,passed this object's |
| 55 | pState pointer.. */ |
| 56 | void * pState; /* final argument for write() and dispose()*/ |
| 57 | char enabled; /* if 0, Th_Output() does nothing. */ |
| 58 | }; |
| 59 | typedef struct Th_Vtab_OutputMethods Th_Vtab_OutputMethods; |
| 60 | |
| 61 | /* |
| @@ -97,11 +97,11 @@ | |
| 97 | typedef struct Th_Interp Th_Interp; |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | ** Creates a new interpreter instance using the given v-table. pVtab |
| 102 | ** must outlive the returned object, and pVtab->out.dispose() will be |
| 103 | ** called when the interpreter is cleaned up. The optional "ob" API |
| 104 | ** swaps out Vtab::out instances, so pVtab->out might not be active |
| 105 | ** for the entire lifetime of the interpreter. |
| 106 | ** |
| 107 | ** Potential TODO: we "should probably" add a dispose() method to the |
| @@ -371,13 +371,13 @@ | |
| 371 | ** NULL). |
| 372 | */ |
| 373 | int Th_Output_f_FILE( char const * zData, int len, void * pState ); |
| 374 | |
| 375 | /* |
| 376 | ** A Th_Vtab_OutputMethods::dispose() impl for FILE handles. If pState is not |
| 377 | ** one of the standard streams (stdin, stdout, stderr) then it is |
| 378 | ** fclose()d. |
| 379 | */ |
| 380 | void Th_Output_dispose_FILE( void * pState ); |
| 381 | |
| 382 | /* |
| 383 | ** A helper type for holding lists of function registration information. |
| @@ -444,11 +444,16 @@ | |
| 444 | */ |
| 445 | int Th_RegisterCommands( Th_Interp * interp, Th_Command_Reg const * pList ); |
| 446 | |
| 447 | #ifdef TH_ENABLE_OB |
| 448 | /* |
| 449 | ** Output buffer stack manager for TH. Used/managed by the Th_ob_xxx() functions. |
| 450 | */ |
| 451 | struct Th_Ob_Manager { |
| 452 | Blob ** aBuf; /* Stack of Blobs */ |
| 453 | int nBuf; /* Number of blobs */ |
| 454 | int cursor; /* Current level (-1=not active) */ |
| 455 |
| --- src/th.h | |
| +++ src/th.h | |
| @@ -47,15 +47,15 @@ | |
| 47 | ** Th_Vtab. It is intended that a given Vtab be able to swap out |
| 48 | ** output back-ends during its lifetime, e.g. to form a stack of |
| 49 | ** buffers. |
| 50 | */ |
| 51 | struct Th_Vtab_OutputMethods { |
| 52 | Th_Output_f xWrite; /* output handler */ |
| 53 | void (*xDispose)( void * pState ); /* Called when the framework is done with |
| 54 | this output handler,passed this object's |
| 55 | pState pointer.. */ |
| 56 | void * pState; /* final argument for xWrite() and xDispose()*/ |
| 57 | char enabled; /* if 0, Th_Output() does nothing. */ |
| 58 | }; |
| 59 | typedef struct Th_Vtab_OutputMethods Th_Vtab_OutputMethods; |
| 60 | |
| 61 | /* |
| @@ -97,11 +97,11 @@ | |
| 97 | typedef struct Th_Interp Th_Interp; |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | ** Creates a new interpreter instance using the given v-table. pVtab |
| 102 | ** must outlive the returned object, and pVtab->out.xDispose() will be |
| 103 | ** called when the interpreter is cleaned up. The optional "ob" API |
| 104 | ** swaps out Vtab::out instances, so pVtab->out might not be active |
| 105 | ** for the entire lifetime of the interpreter. |
| 106 | ** |
| 107 | ** Potential TODO: we "should probably" add a dispose() method to the |
| @@ -371,13 +371,13 @@ | |
| 371 | ** NULL). |
| 372 | */ |
| 373 | int Th_Output_f_FILE( char const * zData, int len, void * pState ); |
| 374 | |
| 375 | /* |
| 376 | ** A Th_Vtab_OutputMethods::xDispose() impl for FILE handles. If pState is not |
| 377 | ** one of the standard streams (stdin, stdout, stderr) then it is |
| 378 | ** fclose()d by this call. |
| 379 | */ |
| 380 | void Th_Output_dispose_FILE( void * pState ); |
| 381 | |
| 382 | /* |
| 383 | ** A helper type for holding lists of function registration information. |
| @@ -444,11 +444,16 @@ | |
| 444 | */ |
| 445 | int Th_RegisterCommands( Th_Interp * interp, Th_Command_Reg const * pList ); |
| 446 | |
| 447 | #ifdef TH_ENABLE_OB |
| 448 | /* |
| 449 | ** Output buffer stack manager for TH. Used/managed by the Th_ob_xxx() |
| 450 | ** functions. This class manages Th_Interp::pVtab->out for a specific |
| 451 | ** interpreter, swapping it in and out in order to redirect output |
| 452 | ** generated via Th_Output() to internal buffers. The buffers can be |
| 453 | ** pushed and popped from the stack, allowing clients to selectively |
| 454 | ** capture output for a given block of TH1 code. |
| 455 | */ |
| 456 | struct Th_Ob_Manager { |
| 457 | Blob ** aBuf; /* Stack of Blobs */ |
| 458 | int nBuf; /* Number of blobs */ |
| 459 | int cursor; /* Current level (-1=not active) */ |
| 460 |
+1
-1
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2089,11 +2089,11 @@ | ||
| 2089 | 2089 | {0, 0, 0} |
| 2090 | 2090 | }; |
| 2091 | 2091 | if( g.interp==0 ){ |
| 2092 | 2092 | int i; |
| 2093 | 2093 | if(g.cgiOutput){ |
| 2094 | - vtab.out.write = Th_Output_f_cgi_content; | |
| 2094 | + vtab.out.xWrite = Th_Output_f_cgi_content; | |
| 2095 | 2095 | }else{ |
| 2096 | 2096 | vtab.out = Th_Vtab_OutputMethods_FILE; |
| 2097 | 2097 | vtab.out.pState = stdout; |
| 2098 | 2098 | } |
| 2099 | 2099 | vtab.out.enabled = enableOutput; |
| 2100 | 2100 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2089,11 +2089,11 @@ | |
| 2089 | {0, 0, 0} |
| 2090 | }; |
| 2091 | if( g.interp==0 ){ |
| 2092 | int i; |
| 2093 | if(g.cgiOutput){ |
| 2094 | vtab.out.write = Th_Output_f_cgi_content; |
| 2095 | }else{ |
| 2096 | vtab.out = Th_Vtab_OutputMethods_FILE; |
| 2097 | vtab.out.pState = stdout; |
| 2098 | } |
| 2099 | vtab.out.enabled = enableOutput; |
| 2100 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2089,11 +2089,11 @@ | |
| 2089 | {0, 0, 0} |
| 2090 | }; |
| 2091 | if( g.interp==0 ){ |
| 2092 | int i; |
| 2093 | if(g.cgiOutput){ |
| 2094 | vtab.out.xWrite = Th_Output_f_cgi_content; |
| 2095 | }else{ |
| 2096 | vtab.out = Th_Vtab_OutputMethods_FILE; |
| 2097 | vtab.out.pState = stdout; |
| 2098 | } |
| 2099 | vtab.out.enabled = enableOutput; |
| 2100 |