|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.9 1997/09/08 02:40:08 momjian Exp $ |
| 12 | + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.10 1998/03/15 08:02:57 scrappy Exp $ |
13 | 13 | *
|
14 | 14 | *-------------------------------------------------------------------------
|
15 | 15 | */
|
|
23 | 23 | #include "pgtclId.h"
|
24 | 24 |
|
25 | 25 | /*
|
26 |
| - * Pgtcl_Init |
27 |
| - * initialization package for the PGLITE Tcl package |
| 26 | + * Pgtcl_Init |
| 27 | + * initialization package for the PGLITE Tcl package |
28 | 28 | *
|
29 | 29 | */
|
30 | 30 |
|
31 |
| -/* |
32 |
| - * Tidy up forgotten postgres connection at Tcl_Exit |
33 |
| - */ |
34 |
| -static void |
35 |
| -Pgtcl_AtExit(ClientData cData) |
36 |
| -{ |
37 |
| - Pg_clientData *cd = (Pg_clientData *) cData; |
38 |
| - Tcl_HashEntry *hent; |
39 |
| - Tcl_HashSearch hsearch; |
40 |
| - Pg_ConnectionId *connid; |
41 |
| - PGconn *conn; |
42 |
| - |
43 |
| - while ((hent = Tcl_FirstHashEntry(&(cd->dbh_hash), &hsearch)) != NULL) |
44 |
| - { |
45 |
| - connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent); |
46 |
| - conn = connid->conn; |
47 |
| - PgDelConnectionId(cd, connid->id); |
48 |
| - PQfinish(conn); |
49 |
| - } |
50 |
| - |
51 |
| - Tcl_DeleteHashTable(&(cd->dbh_hash)); |
52 |
| - Tcl_DeleteHashTable(&(cd->res_hash)); |
53 |
| - Tcl_DeleteHashTable(&(cd->notify_hash)); |
54 |
| - |
55 |
| - Tcl_DeleteExitHandler(Pgtcl_AtExit, cData); |
56 |
| -} |
57 |
| - |
58 |
| -/* |
59 |
| - * Tidy up forgotten postgres connections on Interpreter deletion |
60 |
| - */ |
61 |
| -static void |
62 |
| -Pgtcl_Shutdown(ClientData cData, Tcl_Interp * interp) |
63 |
| -{ |
64 |
| - Pgtcl_AtExit(cData); |
65 |
| -} |
66 |
| - |
67 | 31 | int
|
68 |
| -Pgtcl_Init(Tcl_Interp * interp) |
| 32 | +Pgtcl_Init (Tcl_Interp *interp) |
69 | 33 | {
|
70 |
| - Pg_clientData *cd; |
71 |
| - |
72 |
| - /* Create and initialize the client data area */ |
73 |
| - cd = (Pg_clientData *) ckalloc(sizeof(Pg_clientData)); |
74 |
| - Tcl_InitHashTable(&(cd->dbh_hash), TCL_STRING_KEYS); |
75 |
| - Tcl_InitHashTable(&(cd->res_hash), TCL_STRING_KEYS); |
76 |
| - Tcl_InitHashTable(&(cd->notify_hash), TCL_STRING_KEYS); |
77 |
| - cd->dbh_count = 0L; |
78 |
| - cd->res_count = 0L; |
79 |
| - |
80 |
| - /* Arrange for tidy up when interpreter is deleted or Tcl exits */ |
81 |
| - Tcl_CallWhenDeleted(interp, Pgtcl_Shutdown, (ClientData) cd); |
82 |
| - Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData) cd); |
83 |
| - |
84 |
| - /* register all pgtcl commands */ |
85 |
| - Tcl_CreateCommand(interp, |
86 |
| - "pg_conndefaults", |
87 |
| - Pg_conndefaults, |
88 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
89 |
| - |
90 |
| - Tcl_CreateCommand(interp, |
91 |
| - "pg_connect", |
92 |
| - Pg_connect, |
93 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
94 |
| - |
95 |
| - Tcl_CreateCommand(interp, |
96 |
| - "pg_disconnect", |
97 |
| - Pg_disconnect, |
98 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
99 |
| - |
100 |
| - Tcl_CreateCommand(interp, |
101 |
| - "pg_exec", |
102 |
| - Pg_exec, |
103 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
104 |
| - |
105 |
| - Tcl_CreateCommand(interp, |
106 |
| - "pg_select", |
107 |
| - Pg_select, |
108 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
109 |
| - |
110 |
| - Tcl_CreateCommand(interp, |
111 |
| - "pg_result", |
112 |
| - Pg_result, |
113 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
114 |
| - |
115 |
| - Tcl_CreateCommand(interp, |
116 |
| - "pg_lo_open", |
117 |
| - Pg_lo_open, |
118 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
119 |
| - |
120 |
| - Tcl_CreateCommand(interp, |
121 |
| - "pg_lo_close", |
122 |
| - Pg_lo_close, |
123 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
124 |
| - |
125 |
| - Tcl_CreateCommand(interp, |
126 |
| - "pg_lo_read", |
127 |
| - Pg_lo_read, |
128 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
129 |
| - |
130 |
| - Tcl_CreateCommand(interp, |
131 |
| - "pg_lo_write", |
132 |
| - Pg_lo_write, |
133 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
134 |
| - |
135 |
| - Tcl_CreateCommand(interp, |
136 |
| - "pg_lo_lseek", |
137 |
| - Pg_lo_lseek, |
138 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
139 |
| - |
140 |
| - Tcl_CreateCommand(interp, |
141 |
| - "pg_lo_creat", |
142 |
| - Pg_lo_creat, |
143 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
144 |
| - |
145 |
| - Tcl_CreateCommand(interp, |
146 |
| - "pg_lo_tell", |
147 |
| - Pg_lo_tell, |
148 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
149 |
| - |
150 |
| - Tcl_CreateCommand(interp, |
151 |
| - "pg_lo_unlink", |
152 |
| - Pg_lo_unlink, |
153 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
154 |
| - |
155 |
| - Tcl_CreateCommand(interp, |
156 |
| - "pg_lo_import", |
157 |
| - Pg_lo_import, |
158 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
159 |
| - |
160 |
| - Tcl_CreateCommand(interp, |
161 |
| - "pg_lo_export", |
162 |
| - Pg_lo_export, |
163 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
164 |
| - |
165 |
| - Tcl_CreateCommand(interp, |
166 |
| - "pg_listen", |
167 |
| - Pg_listen, |
168 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
169 |
| - |
170 |
| - Tcl_CreateCommand(interp, |
171 |
| - "pg_notifies", |
172 |
| - Pg_notifies, |
173 |
| - (ClientData) cd, (Tcl_CmdDeleteProc *) NULL); |
174 |
| - |
175 |
| - Tcl_PkgProvide(interp, "Pgtcl", "1.0"); |
176 |
| - |
177 |
| - return TCL_OK; |
| 34 | + |
| 35 | + /* finish off the ChannelType struct. Much easier to do it here then |
| 36 | + * to guess where it might be by position in the struct. This is needed |
| 37 | + * for Tcl7.6 and beyond, which have the getfileproc. |
| 38 | + */ |
| 39 | +#if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION == 6) |
| 40 | + Pg_ConnType.getFileProc = PgGetFileProc; |
| 41 | +#endif |
| 42 | + |
| 43 | + /* register all pgtcl commands */ |
| 44 | + Tcl_CreateCommand(interp, |
| 45 | + "pg_conndefaults", |
| 46 | + Pg_conndefaults, |
| 47 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 48 | + |
| 49 | + Tcl_CreateCommand(interp, |
| 50 | + "pg_connect", |
| 51 | + Pg_connect, |
| 52 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 53 | + |
| 54 | + Tcl_CreateCommand(interp, |
| 55 | + "pg_disconnect", |
| 56 | + Pg_disconnect, |
| 57 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 58 | + |
| 59 | + Tcl_CreateCommand(interp, |
| 60 | + "pg_exec", |
| 61 | + Pg_exec, |
| 62 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 63 | + |
| 64 | + Tcl_CreateCommand(interp, |
| 65 | + "pg_select", |
| 66 | + Pg_select, |
| 67 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 68 | + |
| 69 | + Tcl_CreateCommand(interp, |
| 70 | + "pg_result", |
| 71 | + Pg_result, |
| 72 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 73 | + |
| 74 | + Tcl_CreateCommand(interp, |
| 75 | + "pg_lo_open", |
| 76 | + Pg_lo_open, |
| 77 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 78 | + |
| 79 | + Tcl_CreateCommand(interp, |
| 80 | + "pg_lo_close", |
| 81 | + Pg_lo_close, |
| 82 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 83 | + |
| 84 | + Tcl_CreateCommand(interp, |
| 85 | + "pg_lo_read", |
| 86 | + Pg_lo_read, |
| 87 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 88 | + |
| 89 | + Tcl_CreateCommand(interp, |
| 90 | + "pg_lo_write", |
| 91 | + Pg_lo_write, |
| 92 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 93 | + |
| 94 | + Tcl_CreateCommand(interp, |
| 95 | + "pg_lo_lseek", |
| 96 | + Pg_lo_lseek, |
| 97 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 98 | + |
| 99 | + Tcl_CreateCommand(interp, |
| 100 | + "pg_lo_creat", |
| 101 | + Pg_lo_creat, |
| 102 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 103 | + |
| 104 | + Tcl_CreateCommand(interp, |
| 105 | + "pg_lo_tell", |
| 106 | + Pg_lo_tell, |
| 107 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 108 | + |
| 109 | + Tcl_CreateCommand(interp, |
| 110 | + "pg_lo_unlink", |
| 111 | + Pg_lo_unlink, |
| 112 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 113 | + |
| 114 | + Tcl_CreateCommand(interp, |
| 115 | + "pg_lo_import", |
| 116 | + Pg_lo_import, |
| 117 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 118 | + |
| 119 | + Tcl_CreateCommand(interp, |
| 120 | + "pg_lo_export", |
| 121 | + Pg_lo_export, |
| 122 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 123 | + |
| 124 | + Tcl_CreateCommand(interp, |
| 125 | + "pg_listen", |
| 126 | + Pg_listen, |
| 127 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 128 | + |
| 129 | + Tcl_CreateCommand(interp, |
| 130 | + "pg_notifies", |
| 131 | + Pg_notifies, |
| 132 | + (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
| 133 | + |
| 134 | + Tcl_PkgProvide(interp, "Pgtcl", "1.1"); |
| 135 | + |
| 136 | + return TCL_OK; |
178 | 137 | }
|
179 | 138 |
|
180 | 139 |
|
181 | 140 | int
|
182 |
| -Pgtcl_SafeInit(Tcl_Interp * interp) |
| 141 | +Pgtcl_SafeInit (Tcl_Interp *interp) |
183 | 142 | {
|
184 |
| - return Pgtcl_Init(interp); |
| 143 | + return Pgtcl_Init(interp); |
185 | 144 | }
|
0 commit comments