1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-23 03:21:12 +03:00

pgindent run over code.

This commit is contained in:
Bruce Momjian
1999-05-25 16:15:34 +00:00
parent 4b04b01aaa
commit 07842084fe
413 changed files with 11723 additions and 10769 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.42 1999/05/10 00:46:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.43 1999/05/25 16:15:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -28,7 +28,7 @@
#define DIGIT(c) ((c) - '0')
/*
* translate_escape()
* translate_escape()
*
* This function performs in-place translation of a single C-style
* escape sequence pointed by p. Curly braces { } and double-quote
@ -132,7 +132,7 @@ translate_escape(char *p, int isArray)
}
/*
* tcl_value()
* tcl_value()
*
* This function does in-line conversion of a value returned by libpq
* into a tcl string or into a tcl list if the value looks like the
@ -219,7 +219,7 @@ tcl_value(char *value)
return value;
}
#endif /* TCL_ARRAYS */
#endif /* TCL_ARRAYS */
/**********************************
@ -241,12 +241,13 @@ Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
{
PQconninfoOption *option;
Tcl_DString result;
char ibuf[32];
char ibuf[32];
Tcl_DStringInit(&result);
for (option = PQconndefaults(); option->keyword != NULL; option++)
{
char * val = option->val ? option->val : "";
char *val = option->val ? option->val : "";
sprintf(ibuf, "%d", option->dispsize);
Tcl_DStringStartSublist(&result);
Tcl_DStringAppendElement(&result, option->keyword);
@ -359,7 +360,7 @@ Pg_connect(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
}
if (PQstatus(conn) == CONNECTION_OK)
if (PQstatus(conn) == CONNECTION_OK)
{
PgSetConnectionId(interp, conn);
return TCL_OK;
@ -367,7 +368,7 @@ Pg_connect(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
else
{
Tcl_AppendResult(interp, "Connection to database failed\n",
PQerrorMessage(conn), 0);
PQerrorMessage(conn), 0);
PQfinish(conn);
return TCL_ERROR;
}
@ -452,6 +453,7 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
int rId = PgSetResultId(interp, argv[1], result);
ExecStatusType rStat = PQresultStatus(result);
if (rStat == PGRES_COPY_IN || rStat == PGRES_COPY_OUT)
{
connid->res_copyStatus = RES_COPY_INPROGRESS;
@ -473,11 +475,11 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
syntax:
pg_result result ?option?
pg_result result ?option?
the options are:
-status the status of the result
-status the status of the result
-error the error message, if the status indicates error; otherwise
an empty string
@ -491,11 +493,11 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
-numAttrs returns the number of attributes returned by the query
-assign arrayName
assign the results to an array, using subscripts of the form
(tupno,attributeName)
assign the results to an array, using subscripts of the form
(tupno,attributeName)
-assignbyidx arrayName ?appendstr?
assign the results to an array using the first field's value
assign the results to an array using the first field's value
as a key.
All but the first field of each tuple are stored, using
subscripts of the form (field0value,attributeNameappendstr)
@ -504,17 +506,17 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
returns the values of the tuple in a list
-tupleArray tupleNumber arrayName
stores the values of the tuple in array arrayName, indexed
stores the values of the tuple in array arrayName, indexed
by the attributes returned
-attributes
returns a list of the name/type pairs of the tuple attributes
returns a list of the name/type pairs of the tuple attributes
-lAttributes
returns a list of the {name type len} entries of the tuple
returns a list of the {name type len} entries of the tuple
attributes
-clear clear the result buffer. Do not reuse after this
-clear clear the result buffer. Do not reuse after this
**********************************/
int
@ -526,12 +528,12 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
int tupno;
char *arrVar;
char nameBuffer[256];
const char *appendstr;
const char *appendstr;
if (argc < 3 || argc > 5)
{
Tcl_AppendResult(interp, "Wrong # of arguments\n", 0);
goto Pg_result_errReturn; /* append help info */
goto Pg_result_errReturn; /* append help info */
}
result = PgGetResultId(interp, argv[1]);
@ -550,7 +552,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
else if (strcmp(opt, "-error") == 0)
{
Tcl_SetResult(interp, (char*) PQresultErrorMessage(result),
Tcl_SetResult(interp, (char *) PQresultErrorMessage(result),
TCL_STATIC);
return TCL_OK;
}
@ -588,11 +590,10 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* this assignment assigns the table of result tuples into a giant
* array with the name given in the argument.
* The indices of the array are of the form (tupno,attrName).
* Note we expect field names not to
* exceed a few dozen characters, so truncating to prevent buffer
* overflow shouldn't be a problem.
* array with the name given in the argument. The indices of the
* array are of the form (tupno,attrName). Note we expect field
* names not to exceed a few dozen characters, so truncating to
* prevent buffer overflow shouldn't be a problem.
*/
for (tupno = 0; tupno < PQntuples(result); tupno++)
{
@ -616,7 +617,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
{
if (argc != 4 && argc != 5)
{
Tcl_AppendResult(interp, "-assignbyidx option requires an array name and optionally an append string",0);
Tcl_AppendResult(interp, "-assignbyidx option requires an array name and optionally an append string", 0);
return TCL_ERROR;
}
arrVar = argv[3];
@ -624,25 +625,27 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* this assignment assigns the table of result tuples into a giant
* array with the name given in the argument. The indices of the array
* are of the form (field0Value,attrNameappendstr).
* Here, we still assume PQfname won't exceed 200 characters,
* but we dare not make the same assumption about the data in field 0
* nor the append string.
* array with the name given in the argument. The indices of the
* array are of the form (field0Value,attrNameappendstr). Here, we
* still assume PQfname won't exceed 200 characters, but we dare
* not make the same assumption about the data in field 0 nor the
* append string.
*/
for (tupno = 0; tupno < PQntuples(result); tupno++)
{
const char *field0 =
const char *field0 =
#ifdef TCL_ARRAYS
tcl_value(PQgetvalue(result, tupno, 0));
tcl_value(PQgetvalue(result, tupno, 0));
#else
PQgetvalue(result, tupno, 0);
PQgetvalue(result, tupno, 0);
#endif
char *workspace = malloc(strlen(field0) + strlen(appendstr) + 210);
char *workspace = malloc(strlen(field0) + strlen(appendstr) + 210);
for (i = 1; i < PQnfields(result); i++)
{
sprintf(workspace, "%s,%.200s%s", field0, PQfname(result,i),
sprintf(workspace, "%s,%.200s%s", field0, PQfname(result, i),
appendstr);
if (Tcl_SetVar2(interp, arrVar, workspace,
#ifdef TCL_ARRAYS
@ -676,9 +679,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
#ifdef TCL_ARRAYS
for (i = 0; i < PQnfields(result); i++)
{
Tcl_AppendElement(interp, tcl_value(PQgetvalue(result, tupno, i)));
}
#else
for (i = 0; i < PQnfields(result); i++)
Tcl_AppendElement(interp, PQgetvalue(result, tupno, i));
@ -739,7 +740,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
else
{
Tcl_AppendResult(interp, "Invalid option\n", 0);
goto Pg_result_errReturn; /* append help info */
goto Pg_result_errReturn; /* append help info */
}
@ -1298,7 +1299,7 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
if (PQresultStatus(result) != PGRES_TUPLES_OK)
{
/* query failed, or it wasn't SELECT */
Tcl_SetResult(interp, (char*) PQresultErrorMessage(result),
Tcl_SetResult(interp, (char *) PQresultErrorMessage(result),
TCL_VOLATILE);
PQclear(result);
return TCL_ERROR;
@ -1374,7 +1375,7 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
*/
static int
Pg_have_listener (Pg_ConnectionId *connid, const char * relname)
Pg_have_listener(Pg_ConnectionId * connid, const char *relname)
{
Pg_TclNotifies *notifies;
Tcl_HashEntry *entry;
@ -1388,7 +1389,7 @@ Pg_have_listener (Pg_ConnectionId *connid, const char * relname)
if (interp == NULL)
continue; /* ignore deleted interpreter */
entry = Tcl_FindHashEntry(&notifies->notify_hash, (char*) relname);
entry = Tcl_FindHashEntry(&notifies->notify_hash, (char *) relname);
if (entry == NULL)
continue; /* no pg_listen in this interpreter */
@ -1491,14 +1492,15 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
if (callback)
{
/*
* Create or update a callback for a relation
*/
int alreadyHadListener = Pg_have_listener(connid, caserelname);
int alreadyHadListener = Pg_have_listener(connid, caserelname);
entry = Tcl_CreateHashEntry(&notifies->notify_hash, caserelname, &new);
/* If update, free the old callback string */
if (! new)
if (!new)
ckfree((char *) Tcl_GetHashValue(entry));
/* Store the new callback string */
Tcl_SetHashValue(entry, callback);
@ -1509,10 +1511,11 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* Send a LISTEN command if this is the first listener.
*/
if (! alreadyHadListener)
if (!alreadyHadListener)
{
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 8));
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 8));
sprintf(cmd, "LISTEN %s", origrelname);
result = PQexec(conn, cmd);
ckfree(cmd);
@ -1533,6 +1536,7 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
else
{
/*
* Remove a callback for a relation
*/
@ -1545,15 +1549,17 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
ckfree((char *) Tcl_GetHashValue(entry));
Tcl_DeleteHashEntry(entry);
/*
* Send an UNLISTEN command if that was the last listener.
* Note: we don't attempt to turn off the notify mechanism
* if no LISTENs remain active; not worth the trouble.
* Send an UNLISTEN command if that was the last listener. Note:
* we don't attempt to turn off the notify mechanism if no LISTENs
* remain active; not worth the trouble.
*/
if (! Pg_have_listener(connid, caserelname))
if (!Pg_have_listener(connid, caserelname))
{
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 10));
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 10));
sprintf(cmd, "UNLISTEN %s", origrelname);
result = PQexec(conn, cmd);
ckfree(cmd);

View File

@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pgtclCmds.h,v 1.13 1999/02/13 23:22:38 momjian Exp $
* $Id: pgtclCmds.h,v 1.14 1999/05/25 16:15:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -54,7 +54,7 @@ typedef struct Pg_ConnectionId_s
Pg_TclNotifies *notify_list;/* head of list of notify info */
int notifier_running; /* notify event source is live */
int notifier_socket; /* PQsocket on which notifier is listening */
int notifier_socket;/* PQsocket on which notifier is listening */
} Pg_ConnectionId;
/* Values of res_copyStatus */

View File

@ -12,7 +12,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.18 1999/02/13 23:22:38 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.19 1999/05/25 16:15:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -34,7 +34,7 @@ PgEndCopy(Pg_ConnectionId * connid, int *errorCodePtr)
{
PQclear(connid->results[connid->res_copy]);
connid->results[connid->res_copy] =
PQmakeEmptyPGresult(connid->conn, PGRES_BAD_RESPONSE);
PQmakeEmptyPGresult(connid->conn, PGRES_BAD_RESPONSE);
connid->res_copy = -1;
*errorCodePtr = EIO;
return -1;
@ -43,51 +43,53 @@ PgEndCopy(Pg_ConnectionId * connid, int *errorCodePtr)
{
PQclear(connid->results[connid->res_copy]);
connid->results[connid->res_copy] =
PQmakeEmptyPGresult(connid->conn, PGRES_COMMAND_OK);
PQmakeEmptyPGresult(connid->conn, PGRES_COMMAND_OK);
connid->res_copy = -1;
return 0;
}
}
/*
* Called when reading data (via gets) for a copy <rel> to stdout.
* Called when reading data (via gets) for a copy <rel> to stdout.
*/
int PgInputProc(DRIVER_INPUT_PROTO)
int
PgInputProc(DRIVER_INPUT_PROTO)
{
Pg_ConnectionId *connid;
PGconn *conn;
int avail;
Pg_ConnectionId *connid;
PGconn *conn;
int avail;
connid = (Pg_ConnectionId *)cData;
conn = connid->conn;
connid = (Pg_ConnectionId *) cData;
conn = connid->conn;
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_OUT)
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_OUT)
{
*errorCodePtr = EBUSY;
return -1;
}
}
/* Read any newly arrived data into libpq's buffer,
* thereby clearing the socket's read-ready condition.
*/
if (! PQconsumeInput(conn))
/*
* Read any newly arrived data into libpq's buffer, thereby clearing
* the socket's read-ready condition.
*/
if (!PQconsumeInput(conn))
{
*errorCodePtr = EIO;
return -1;
}
}
/* Move data from libpq's buffer to Tcl's. */
/* Move data from libpq's buffer to Tcl's. */
avail = PQgetlineAsync(conn, buf, bufSize);
avail = PQgetlineAsync(conn, buf, bufSize);
if (avail < 0)
if (avail < 0)
{
/* Endmarker detected, change state and return 0 */
return PgEndCopy(connid, errorCodePtr);
}
/* Endmarker detected, change state and return 0 */
return PgEndCopy(connid, errorCodePtr);
}
return avail;
return avail;
}
/*
@ -103,13 +105,13 @@ PgOutputProc(DRIVER_OUTPUT_PROTO)
conn = connid->conn;
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_IN)
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_IN)
{
*errorCodePtr = EBUSY;
return -1;
}
if (PQputnbytes(conn, buf, bufSize))
if (PQputnbytes(conn, buf, bufSize))
{
*errorCodePtr = EIO;
return -1;
@ -358,7 +360,7 @@ getresid(Tcl_Interp * interp, char *id, Pg_ConnectionId ** connid_p)
connid = (Pg_ConnectionId *) Tcl_GetChannelInstanceData(conn_chan);
if (resid < 0 || resid >= connid->res_max || connid->results[resid] == NULL)
if (resid < 0 || resid >= connid->res_max || connid->results[resid] == NULL)
{
Tcl_SetResult(interp, "Invalid result handle", TCL_STATIC);
return -1;
@ -450,7 +452,7 @@ error_out:
the channel can outlive the interpreter it was created by!)
Upon closure of the channel, we immediately delete the file event handler
for it, which has the effect of disabling any file-ready events that might
be hanging about in the Tcl event queue. But for interpreter deletion,
be hanging about in the Tcl event queue. But for interpreter deletion,
we just set any matching interp pointers in the Pg_TclNotifies list to NULL.
The list item stays around until the connection is deleted. (This avoids
trouble with walking through a list whose members may get deleted under us.)
@ -459,10 +461,10 @@ error_out:
libpgtcl currently claims to work with Tcl 7.5, 7.6, and 8.0, and each of
'em is different. Worse, the Tcl_File type went away in 8.0, which means
there is no longer any platform-independent way of waiting for file ready.
So we now have to use a Unix-specific interface. Grumble.
So we now have to use a Unix-specific interface. Grumble.
In the current design, Pg_Notify_FileHandler is a file handler that
we establish by calling Tcl_CreateFileHandler(). It gets invoked from
we establish by calling Tcl_CreateFileHandler(). It gets invoked from
the Tcl event loop whenever the underlying PGconn's socket is read-ready.
We suck up any available data (to clear the OS-level read-ready condition)
and then transfer any available PGnotify events into the Tcl event queue.
@ -473,8 +475,8 @@ error_out:
typedef struct
{
Tcl_Event header; /* Standard Tcl event info */
PGnotify info; /* Notify name from SQL server */
Tcl_Event header; /* Standard Tcl event info */
PGnotify info; /* Notify name from SQL server */
Pg_ConnectionId *connid; /* Connection for server */
} NotifyEvent;
@ -620,7 +622,7 @@ PgNotifyInterpDelete(ClientData clientData, Tcl_Interp * interp)
* Therefore we daren't tell Tcl_DeleteEvents to actually delete anything!
* We simply use it as a way of scanning the event queue. Events matching
* the about-to-be-deleted connid are marked dead by setting their connid
* fields to NULL. Then Pg_Notify_EventProc will do nothing when those
* fields to NULL. Then Pg_Notify_EventProc will do nothing when those
* events are executed.
*/
static int
@ -631,6 +633,7 @@ NotifyEventDeleteProc(Tcl_Event * evPtr, ClientData clientData)
if (evPtr->proc == Pg_Notify_EventProc)
{
NotifyEvent *event = (NotifyEvent *) evPtr;
if (event->connid == connid)
event->connid = NULL;
}
@ -644,13 +647,14 @@ NotifyEventDeleteProc(Tcl_Event * evPtr, ClientData clientData)
*/
static void
Pg_Notify_FileHandler (ClientData clientData, int mask)
Pg_Notify_FileHandler(ClientData clientData, int mask)
{
Pg_ConnectionId *connid = (Pg_ConnectionId *) clientData;
/*
* Consume any data available from the SQL server (this just buffers
* it internally to libpq; but it will clear the read-ready condition).
* it internally to libpq; but it will clear the read-ready
* condition).
*/
PQconsumeInput(connid->conn);
@ -667,7 +671,7 @@ Pg_Notify_FileHandler (ClientData clientData, int mask)
* notifier is run until the connection is closed.
*
* FIXME: if PQreset is executed on the underlying PGconn, the active
* socket number could change. How and when should we test for this
* socket number could change. How and when should we test for this
* and update the Tcl file handler linkage? (For that matter, we'd
* also have to reissue LISTEN commands for active LISTENs, since the
* new backend won't know about 'em. I'm leaving this problem for
@ -680,18 +684,20 @@ PgStartNotifyEventSource(Pg_ConnectionId * connid)
/* Start the notify event source if it isn't already running */
if (!connid->notifier_running)
{
int pqsock = PQsocket(connid->conn);
int pqsock = PQsocket(connid->conn);
if (pqsock >= 0)
{
#if TCL_MAJOR_VERSION >= 8
/* In Tcl 8, Tcl_CreateFileHandler takes a socket directly. */
Tcl_CreateFileHandler(pqsock, TCL_READABLE,
Pg_Notify_FileHandler, (ClientData) connid);
Pg_Notify_FileHandler, (ClientData) connid);
#else
/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
Tcl_File tclfile = Tcl_GetFile((ClientData) pqsock, TCL_UNIX_FD);
Tcl_File tclfile = Tcl_GetFile((ClientData) pqsock, TCL_UNIX_FD);
Tcl_CreateFileHandler(tclfile, TCL_READABLE,
Pg_Notify_FileHandler, (ClientData) connid);
Pg_Notify_FileHandler, (ClientData) connid);
#endif
connid->notifier_running = 1;
connid->notifier_socket = pqsock;
@ -710,8 +716,9 @@ PgStopNotifyEventSource(Pg_ConnectionId * connid)
Tcl_DeleteFileHandler(connid->notifier_socket);
#else
/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
Tcl_File tclfile = Tcl_GetFile((ClientData) connid->notifier_socket,
TCL_UNIX_FD);
Tcl_File tclfile = Tcl_GetFile((ClientData) connid->notifier_socket,
TCL_UNIX_FD);
Tcl_DeleteFileHandler(tclfile);
#endif
connid->notifier_running = 0;

View File

@ -9,7 +9,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pgtclId.h,v 1.10 1999/02/13 23:22:39 momjian Exp $
* $Id: pgtclId.h,v 1.11 1999/05/25 16:15:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -34,7 +34,7 @@ extern void PgSetConnectionId(Tcl_Interp * interp, PGconn *conn);
#endif
extern PGconn *PgGetConnectionId(Tcl_Interp * interp, char *id,
Pg_ConnectionId **);
Pg_ConnectionId **);
extern PgDelConnectionId(DRIVER_DEL_PROTO);
extern int PgOutputProc(DRIVER_OUTPUT_PROTO);
extern PgInputProc(DRIVER_INPUT_PROTO);
@ -56,6 +56,7 @@ extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp * interp);
#if HAVE_TCL_GETFILEPROC
extern Tcl_File PgGetFileProc(ClientData cData, int direction);
#endif
extern Tcl_ChannelType Pg_ConnType;