Fossil SCM

More minor internal consistency cleanups.

stephan 2012-07-16 19:21 th1-query-api
Commit 495f26a00eb7e4a5c2722a7583c7251197c0b382
3 files changed +26 -18 +12 -7 +1 -1
+26 -18
--- src/th.c
+++ src/th.c
@@ -7,29 +7,19 @@
77
#include "th.h"
88
#include <string.h>
99
#include <assert.h>
1010
#include <stdio.h> /* FILE class */
1111
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
-
2212
typedef struct Th_Command Th_Command;
2313
typedef struct Th_Frame Th_Frame;
2414
typedef struct Th_Variable Th_Variable;
2515
2616
/*
2717
** Shared instance. See th.h for the docs.
2818
*/
2919
const Th_Vtab_OutputMethods Th_Vtab_OutputMethods_FILE = {
30
- Th_Output_f_FILE /* write() */,
20
+ Th_Output_f_FILE /* xWrite() */,
3121
Th_Output_dispose_FILE /* dispose() */,
3222
NULL /*pState*/,
3323
1/*enabled*/
3424
};
3525
@@ -1443,16 +1433,16 @@
14431433
return p;
14441434
}
14451435
14461436
14471437
int Th_Vtab_Output( Th_Vtab *vTab, char const * zData, int nData ){
1448
- if(!vTab->out.write){
1438
+ if(!vTab->out.xWrite){
14491439
return -1;
14501440
}else if(!vTab->out.enabled){
14511441
return 0;
14521442
}else{
1453
- return vTab->out.write( zData, nData, vTab->out.pState );
1443
+ return vTab->out.xWrite( zData, nData, vTab->out.pState );
14541444
}
14551445
}
14561446
14571447
14581448
int Th_Output( Th_Interp *pInterp, char const * zData, int nData ){
@@ -1748,12 +1738,12 @@
17481738
Th_HashDelete(interp, interp->paGc);
17491739
interp->paGc = NULL;
17501740
}
17511741
17521742
/* 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 );
17551745
}
17561746
17571747
/* Delete the contents of the global frame. */
17581748
thPopFrame(interp);
17591749
@@ -2806,10 +2796,20 @@
28062796
Th_Vtab_OutputMethods parts for purposes of stacking layers of
28072797
buffers. We could add access to it via the public interface,
28082798
but that didn't seem appropriate.
28092799
*/
28102800
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 );
28112811
28122812
/* Empty-initialized Th_Ob_Manager instance. */
28132813
#define Th_Ob_Man_empty_m { \
28142814
NULL/*aBuf*/, \
28152815
0/*nBuf*/, \
@@ -2864,11 +2864,11 @@
28642864
assert( b );
28652865
blob_append( b, zData, len );
28662866
return len;
28672867
}
28682868
2869
-static void Th_Output_dispose_ob( void * pState ){
2869
+void Th_Output_dispose_ob( void * pState ){
28702870
/* possible todo: move the cleanup logic from
28712871
Th_Ob_Pop() to here? */
28722872
#if 0
28732873
Th_Ob_Manager * pMan = (Th_Ob_Manager*)pState;
28742874
Blob * b = Th_Ob_GetCurrentBuffer( pMan );
@@ -2940,13 +2940,21 @@
29402940
Th_Vtab_OutputMethods * theOut;
29412941
assert( pMan->nBuf > pMan->cursor );
29422942
rc = pMan->aBuf[pMan->cursor];
29432943
pMan->aBuf[pMan->cursor] = NULL;
29442944
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 );
29472954
}
2955
+#endif
29482956
pMan->interp->pVtab->out = *theOut;
29492957
pMan->aOutput[pMan->cursor] = Th_Vtab_OutputMethods_empty;
29502958
if(-1 == --pMan->cursor){
29512959
Th_Interp * interp = pMan->interp;
29522960
Th_Free( pMan->interp, pMan->aBuf );
29532961
--- 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
+12 -7
--- src/th.h
+++ src/th.h
@@ -47,15 +47,15 @@
4747
** Th_Vtab. It is intended that a given Vtab be able to swap out
4848
** output back-ends during its lifetime, e.g. to form a stack of
4949
** buffers.
5050
*/
5151
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
5454
this output handler,passed this object's
5555
pState pointer.. */
56
- void * pState; /* final argument for write() and dispose()*/
56
+ void * pState; /* final argument for xWrite() and xDispose()*/
5757
char enabled; /* if 0, Th_Output() does nothing. */
5858
};
5959
typedef struct Th_Vtab_OutputMethods Th_Vtab_OutputMethods;
6060
6161
/*
@@ -97,11 +97,11 @@
9797
typedef struct Th_Interp Th_Interp;
9898
9999
100100
/*
101101
** 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
103103
** called when the interpreter is cleaned up. The optional "ob" API
104104
** swaps out Vtab::out instances, so pVtab->out might not be active
105105
** for the entire lifetime of the interpreter.
106106
**
107107
** Potential TODO: we "should probably" add a dispose() method to the
@@ -371,13 +371,13 @@
371371
** NULL).
372372
*/
373373
int Th_Output_f_FILE( char const * zData, int len, void * pState );
374374
375375
/*
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
377377
** one of the standard streams (stdin, stdout, stderr) then it is
378
-** fclose()d.
378
+** fclose()d by this call.
379379
*/
380380
void Th_Output_dispose_FILE( void * pState );
381381
382382
/*
383383
** A helper type for holding lists of function registration information.
@@ -444,11 +444,16 @@
444444
*/
445445
int Th_RegisterCommands( Th_Interp * interp, Th_Command_Reg const * pList );
446446
447447
#ifdef TH_ENABLE_OB
448448
/*
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.
450455
*/
451456
struct Th_Ob_Manager {
452457
Blob ** aBuf; /* Stack of Blobs */
453458
int nBuf; /* Number of blobs */
454459
int cursor; /* Current level (-1=not active) */
455460
--- 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 @@
20892089
{0, 0, 0}
20902090
};
20912091
if( g.interp==0 ){
20922092
int i;
20932093
if(g.cgiOutput){
2094
- vtab.out.write = Th_Output_f_cgi_content;
2094
+ vtab.out.xWrite = Th_Output_f_cgi_content;
20952095
}else{
20962096
vtab.out = Th_Vtab_OutputMethods_FILE;
20972097
vtab.out.pState = stdout;
20982098
}
20992099
vtab.out.enabled = enableOutput;
21002100
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button