* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.41 2007/08/01 22:45:07 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.42 2007/11/15 23:23:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
sz += MAXALIGN(nslots * sizeof(LWLockId)); /* buffer_locks[] */
if (nlsns > 0)
- sz += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr)); /* group_lsn[] */
+ sz += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr)); /* group_lsn[] */
return BUFFERALIGN(sz) + BLCKSZ * nslots;
}
/* indeed, the I/O must have failed */
if (shared->page_status[slotno] == SLRU_PAGE_READ_IN_PROGRESS)
shared->page_status[slotno] = SLRU_PAGE_EMPTY;
- else /* write_in_progress */
+ else /* write_in_progress */
{
shared->page_status[slotno] = SLRU_PAGE_VALID;
shared->page_dirty[slotno] = true;
int fd = -1;
/*
- * Honor the write-WAL-before-data rule, if appropriate, so that we do
- * not write out data before associated WAL records. This is the same
- * action performed during FlushBuffer() in the main buffer manager.
+ * Honor the write-WAL-before-data rule, if appropriate, so that we do not
+ * write out data before associated WAL records. This is the same action
+ * performed during FlushBuffer() in the main buffer manager.
*/
if (shared->group_lsn != NULL)
{
/*
- * We must determine the largest async-commit LSN for the page.
- * This is a bit tedious, but since this entire function is a slow
- * path anyway, it seems better to do this here than to maintain
- * a per-page LSN variable (which'd need an extra comparison in the
+ * We must determine the largest async-commit LSN for the page. This
+ * is a bit tedious, but since this entire function is a slow path
+ * anyway, it seems better to do this here than to maintain a per-page
+ * LSN variable (which'd need an extra comparison in the
* transaction-commit path).
*/
XLogRecPtr max_lsn;
- int lsnindex, lsnoff;
+ int lsnindex,
+ lsnoff;
lsnindex = slotno * shared->lsn_groups_per_page;
max_lsn = shared->group_lsn[lsnindex++];
{
/*
* As noted above, elog(ERROR) is not acceptable here, so if
- * XLogFlush were to fail, we must PANIC. This isn't much of
- * a restriction because XLogFlush is just about all critical
+ * XLogFlush were to fail, we must PANIC. This isn't much of a
+ * restriction because XLogFlush is just about all critical
* section anyway, but let's make sure.
*/
START_CRIT_SECTION();
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.222 2007/11/05 19:00:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.223 2007/11/15 23:23:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* GUC variables */
-int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
+int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
/* Local function prototypes */
*
* constraintOid, if nonzero, says that this trigger is being created
* internally to implement that constraint. A suitable pg_depend entry will
- * be made to link the trigger to that constraint. constraintOid is zero when
+ * be made to link the trigger to that constraint. constraintOid is zero when
* executing a user-entered CREATE TRIGGER command.
*
* Note: can return InvalidOid if we decided to not create a trigger at all,
}
/*
- * If the command is a user-entered CREATE CONSTRAINT TRIGGER command
- * that references one of the built-in RI_FKey trigger functions, assume
- * it is from a dump of a pre-7.3 foreign key constraint, and take steps
- * to convert this legacy representation into a regular foreign key
- * constraint. Ugly, but necessary for loading old dump files.
+ * If the command is a user-entered CREATE CONSTRAINT TRIGGER command that
+ * references one of the built-in RI_FKey trigger functions, assume it is
+ * from a dump of a pre-7.3 foreign key constraint, and take steps to
+ * convert this legacy representation into a regular foreign key
+ * constraint. Ugly, but necessary for loading old dump files.
*/
if (stmt->isconstraint && !OidIsValid(constraintOid) &&
list_length(stmt->args) >= 6 &&
{
/*
* It's for a constraint, so make it an internal dependency of the
- * constraint. We can skip depending on the relations, as there'll
- * be an indirect dependency via the constraint.
+ * constraint. We can skip depending on the relations, as there'll be
+ * an indirect dependency via the constraint.
*/
referenced.classId = ConstraintRelationId;
referenced.objectId = constraintOid;
* full-fledged foreign key constraints.
*
* The conversion is complex because a pre-7.3 foreign key involved three
- * separate triggers, which were reported separately in dumps. While the
+ * separate triggers, which were reported separately in dumps. While the
* single trigger on the referencing table adds no new information, we need
* to know the trigger functions of both of the triggers on the referenced
* table to build the constraint declaration. Also, due to lack of proper
* an incomplete set of triggers resulting in an only partially enforced
* FK constraint. (This would happen if one of the tables had been dropped
* and re-created, but only if the DB had been affected by a 7.0 pg_dump bug
- * that caused loss of tgconstrrelid information.) We choose to translate to
+ * that caused loss of tgconstrrelid information.) We choose to translate to
* an FK constraint only when we've seen all three triggers of a set. This is
* implemented by storing unmatched items in a list in TopMemoryContext.
* We match triggers together by comparing the trigger arguments (which
* include constraint name, table and column names, so should be good enough).
*/
-typedef struct {
+typedef struct
+{
List *args; /* list of (T_String) Values or NIL */
Oid funcoids[3]; /* OIDs of trigger functions */
/* The three function OIDs are stored in the order update, delete, child */
{
static List *info_list = NIL;
- static const char * const funcdescr[3] = {
+ static const char *const funcdescr[3] = {
gettext_noop("Found referenced table's UPDATE trigger."),
gettext_noop("Found referenced table's DELETE trigger."),
gettext_noop("Found referencing table's trigger.")
i = 0;
foreach(l, stmt->args)
{
- Value *arg = (Value *) lfirst(l);
+ Value *arg = (Value *) lfirst(l);
i++;
if (i < 4) /* skip constraint and table names */
i = 0;
foreach(l, fk_attrs)
{
- Value *arg = (Value *) lfirst(l);
+ Value *arg = (Value *) lfirst(l);
if (i++ > 0)
appendStringInfoChar(&buf, ',');
i = 0;
foreach(l, pk_attrs)
{
- Value *arg = (Value *) lfirst(l);
+ Value *arg = (Value *) lfirst(l);
if (i++ > 0)
appendStringInfoChar(&buf, ',');
MemoryContext oldContext;
ereport(NOTICE,
- (errmsg("ignoring incomplete trigger group for constraint \"%s\" %s",
- constr_name, buf.data),
- errdetail(funcdescr[funcnum])));
+ (errmsg("ignoring incomplete trigger group for constraint \"%s\" %s",
+ constr_name, buf.data),
+ errdetail(funcdescr[funcnum])));
oldContext = MemoryContextSwitchTo(TopMemoryContext);
info = (OldTriggerInfo *) palloc0(sizeof(OldTriggerInfo));
info->args = copyObject(stmt->args);
{
/* Second trigger of set */
ereport(NOTICE,
- (errmsg("ignoring incomplete trigger group for constraint \"%s\" %s",
- constr_name, buf.data),
- errdetail(funcdescr[funcnum])));
+ (errmsg("ignoring incomplete trigger group for constraint \"%s\" %s",
+ constr_name, buf.data),
+ errdetail(funcdescr[funcnum])));
}
else
{
int i;
val = DatumGetByteaP(fastgetattr(htup,
- Anum_pg_trigger_tgargs,
- tgrel->rd_att, &isnull));
+ Anum_pg_trigger_tgargs,
+ tgrel->rd_att, &isnull));
if (isnull)
elog(ERROR, "tgargs is null in trigger for relation \"%s\"",
RelationGetRelationName(relation));
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
trigdesc = rInfo->ri_TrigDesc;
finfo = rInfo->ri_TrigFunctions;
instr = rInfo->ri_TrigInstrument;
- if (trigdesc == NULL) /* should not happen */
+ if (trigdesc == NULL) /* should not happen */
elog(ERROR, "relation %u has no triggers",
event->ate_relid);
}
if (local_estate)
{
- ListCell *l;
+ ListCell *l;
foreach(l, estate->es_trig_target_relations)
{
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
/*
- * Run all the remaining triggers. Loop until they are all gone, in
- * case some trigger queues more for us to do.
+ * Run all the remaining triggers. Loop until they are all gone, in case
+ * some trigger queues more for us to do.
*/
while (afterTriggerMarkEvents(events, NULL, false))
{
*
* Since all the info is in TopTransactionContext or children thereof, we
* don't really need to do anything to reclaim memory. However, the
- * pending-events list could be large, and so it's useful to discard
- * it as soon as possible --- especially if we are aborting because we
- * ran out of memory for the list!
+ * pending-events list could be large, and so it's useful to discard it as
+ * soon as possible --- especially if we are aborting because we ran out
+ * of memory for the list!
*
- * (Note: any event_cxts of child subtransactions could also be
- * deleted here, but we have no convenient way to find them, so we
- * leave it to TopTransactionContext reset to clean them up.)
+ * (Note: any event_cxts of child subtransactions could also be deleted
+ * here, but we have no convenient way to find them, so we leave it to
+ * TopTransactionContext reset to clean them up.)
*/
if (afterTriggers && afterTriggers->event_cxt)
MemoryContextDelete(afterTriggers->event_cxt);
/*
* Allocate more space in the stacks if needed. (Note: because the
- * minimum nest level of a subtransaction is 2, we waste the first
- * couple entries of each array; not worth the notational effort to
- * avoid it.)
+ * minimum nest level of a subtransaction is 2, we waste the first couple
+ * entries of each array; not worth the notational effort to avoid it.)
*/
while (my_level >= afterTriggers->maxtransdepth)
{
afterTriggers->state_stack[my_level] = NULL;
Assert(afterTriggers->query_depth ==
afterTriggers->depth_stack[my_level]);
+
/*
* It's entirely possible that the subxact created an event_cxt but
* there is not anything left in it (because all the triggers were
- * fired at end-of-statement). If so, we should release the context
- * to prevent memory leakage in a long sequence of subtransactions.
- * We can detect whether there's anything of use in the context by
- * seeing if anything was added to the global events list since
- * subxact start. (This test doesn't catch every case where the
- * context is deletable; for instance maybe the only additions were
- * from a sub-sub-xact. But it handles the common case.)
+ * fired at end-of-statement). If so, we should release the context
+ * to prevent memory leakage in a long sequence of subtransactions. We
+ * can detect whether there's anything of use in the context by seeing
+ * if anything was added to the global events list since subxact
+ * start. (This test doesn't catch every case where the context is
+ * deletable; for instance maybe the only additions were from a
+ * sub-sub-xact. But it handles the common case.)
*/
if (afterTriggers->cxt_stack[my_level] &&
afterTriggers->events.tail == afterTriggers->events_stack[my_level].tail)
trigger->tgenabled == TRIGGER_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL role */
+ else /* ORIGIN or LOCAL role */
{
if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
trigger->tgenabled == TRIGGER_DISABLED)
/*
* If we don't yet have an event context for the current (sub)xact,
- * create one. Make it a child of CurTransactionContext to ensure it
+ * create one. Make it a child of CurTransactionContext to ensure it
* will go away if the subtransaction aborts.
*/
- if (my_level > 1) /* subtransaction? */
+ if (my_level > 1) /* subtransaction? */
{
Assert(my_level < afterTriggers->maxtransdepth);
cxtptr = &afterTriggers->cxt_stack[my_level];
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.174 2007/09/06 17:31:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.175 2007/11/15 23:23:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static void rewriteValuesRTE(RangeTblEntry *rte, Relation target_relation,
List *attrnos);
static void markQueryForLocking(Query *qry, Node *jtnode,
- bool forUpdate, bool noWait);
+ bool forUpdate, bool noWait);
static List *matchLocks(CmdType event, RuleLock *rulelocks,
int varno, Query *parsetree);
static Query *fireRIRrules(Query *parsetree, List *activeRIRs);
RewriteRule *oneLock = rulelocks->rules[i];
/*
- * Suppress ON INSERT/UPDATE/DELETE rules that are disabled
- * or configured to not fire during the current sessions
- * replication role. ON SELECT rules will always be applied
- * in order to keep views working even in LOCAL or REPLICA
- * role.
+ * Suppress ON INSERT/UPDATE/DELETE rules that are disabled or
+ * configured to not fire during the current sessions replication
+ * role. ON SELECT rules will always be applied in order to keep views
+ * working even in LOCAL or REPLICA role.
*/
if (oneLock->event != CMD_SELECT)
{
oneLock->enabled == RULE_DISABLED)
continue;
}
- else /* ORIGIN or LOCAL ROLE */
+ else /* ORIGIN or LOCAL ROLE */
{
if (oneLock->enabled == RULE_FIRES_ON_REPLICA ||
oneLock->enabled == RULE_DISABLED)
case CMD_INSERT:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot perform INSERT RETURNING on relation \"%s\"",
- RelationGetRelationName(rt_entry_relation)),
+ errmsg("cannot perform INSERT RETURNING on relation \"%s\"",
+ RelationGetRelationName(rt_entry_relation)),
errhint("You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
break;
case CMD_UPDATE:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot perform UPDATE RETURNING on relation \"%s\"",
- RelationGetRelationName(rt_entry_relation)),
+ errmsg("cannot perform UPDATE RETURNING on relation \"%s\"",
+ RelationGetRelationName(rt_entry_relation)),
errhint("You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
break;
case CMD_DELETE:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot perform DELETE RETURNING on relation \"%s\"",
- RelationGetRelationName(rt_entry_relation)),
+ errmsg("cannot perform DELETE RETURNING on relation \"%s\"",
+ RelationGetRelationName(rt_entry_relation)),
errhint("You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
break;
default:
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.7 2007/10/24 03:30:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.8 2007/11/15 23:23:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
static int
-compareEntry(char *ptra, WordEntry * a, char *ptrb, WordEntry * b)
+compareEntry(char *ptra, WordEntry *a, char *ptrb, WordEntry *b)
{
if (a->len == b->len)
{
* Return the number added (might be less than expected due to overflow)
*/
static int4
-add_pos(TSVector src, WordEntry * srcptr,
- TSVector dest, WordEntry * destptr,
+add_pos(TSVector src, WordEntry *srcptr,
+ TSVector dest, WordEntry *destptr,
int4 maxpos)
{
uint16 *clen = &_POSVECPTR(dest, destptr)->npos;
startlen = *clen;
for (i = 0;
i < slen && *clen < MAXNUMPOS &&
- (*clen == 0 || WEP_GETPOS(dpos[*clen - 1]) != MAXENTRYPOS - 1);
+ (*clen == 0 || WEP_GETPOS(dpos[*clen - 1]) != MAXENTRYPOS - 1);
i++)
{
WEP_SETWEIGHT(dpos[*clen], WEP_GETWEIGHT(spos[i]));
memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
}
-
+
ptr++;
ptr1++;
i1--;
if (ptr2->haspos)
dataoff += add_pos(in2, ptr2, out, ptr, maxpos) * sizeof(WordEntryPos);
}
- else /* must have ptr2->haspos */
+ else /* must have ptr2->haspos */
{
int addlen = add_pos(in2, ptr2, out, ptr, maxpos);
}
/*
- * Instead of checking each offset individually, we check for overflow
- * of pos fields once at the end.
+ * Instead of checking each offset individually, we check for overflow of
+ * pos fields once at the end.
*/
if (dataoff > MAXSTRPOS)
ereport(ERROR,
* compare 2 string values
*/
static int4
-ValCompare(CHKVAL * chkval, WordEntry * ptr, QueryOperand * item)
+ValCompare(CHKVAL *chkval, WordEntry *ptr, QueryOperand *item)
{
if (ptr->len == item->length)
return strncmp(
WordEntryPos *ptr;
uint16 len;
- posvec = (WordEntryPosVector *)
+ posvec = (WordEntryPosVector *)
(chkval->values + SHORTALIGN(val->pos + val->len));
len = posvec->npos;
* is there value 'val' in array or not ?
*/
static bool
-checkcondition_str(void *checkval, QueryOperand * val)
+checkcondition_str(void *checkval, QueryOperand *val)
{
- CHKVAL *chkval = (CHKVAL *) checkval;
+ CHKVAL *chkval = (CHKVAL *) checkval;
WordEntry *StopLow = chkval->arrb;
WordEntry *StopHigh = chkval->arre;
WordEntry *StopMiddle;
*
*/
bool
-TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
- bool (*chkcond) (void *checkval, QueryOperand * val))
+TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
+ bool (*chkcond) (void *checkval, QueryOperand *val))
{
/* since this function recurses, it could be driven to stack overflow */
check_stack_depth();
if (curitem->type == QI_VAL)
return chkcond(checkval, (QueryOperand *) curitem);
- switch(curitem->operator.oper)
+ switch (curitem->operator.oper)
{
case OP_NOT:
if (calcnot)
* that have a weight equal to one of the weights in 'weight' bitmask.
*/
static int
-check_weight(TSVector txt, WordEntry * wptr, int8 weight)
+check_weight(TSVector txt, WordEntry *wptr, int8 weight)
{
int len = POSDATALEN(txt, wptr);
int num = 0;
}
static WordEntry **
-SEI_realloc(WordEntry ** in, uint32 *len)
+SEI_realloc(WordEntry **in, uint32 *len)
{
if (*len == 0 || in == NULL)
{
}
static int
-compareStatWord(StatEntry * a, WordEntry * b, tsstat * stat, TSVector txt)
+compareStatWord(StatEntry *a, WordEntry *b, tsstat *stat, TSVector txt)
{
if (a->len == b->len)
return strncmp(
}
static tsstat *
-formstat(tsstat * stat, TSVector txt, WordEntry ** entry, uint32 len)
+formstat(tsstat *stat, TSVector txt, WordEntry **entry, uint32 len)
{
tsstat *newstat;
uint32 totallen,
* This is written like a custom aggregate function, because the
* original plan was to do just that. Unfortunately, an aggregate function
* can't return a set, so that plan was abandoned. If that limitation is
- * lifted in the future, ts_stat could be a real aggregate function so that
+ * lifted in the future, ts_stat could be a real aggregate function so that
* you could use it like this:
*
- * SELECT ts_stat(vector_column) FROM vector_table;
+ * SELECT ts_stat(vector_column) FROM vector_table;
*
- * where vector_column is a tsvector-type column in vector_table.
+ * where vector_column is a tsvector-type column in vector_table.
*/
static tsstat *
-ts_accum(tsstat * stat, Datum data)
+ts_accum(tsstat *stat, Datum data)
{
tsstat *newstat;
TSVector txt = DatumGetTSVector(data);
static void
ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
- tsstat * stat)
+ tsstat *stat)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
istexttype(Oid typid)
{
/* varchar(n) and char(n) are binary-compatible with text */
- if (typid==TEXTOID || typid==VARCHAROID || typid==BPCHAROID)
+ if (typid == TEXTOID || typid == VARCHAROID || typid == BPCHAROID)
return true;
/* Allow domains over these types, too */
typid = getBaseType(typid);
- if (typid==TEXTOID || typid==VARCHAROID || typid==BPCHAROID)
+ if (typid == TEXTOID || typid == VARCHAROID || typid == BPCHAROID)
return true;
return false;
}
Oid cfgId;
/* Check call context */
- if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
+ if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
elog(ERROR, "tsvector_update_trigger: not fired by trigger manager");
trigdata = (TriggerData *) fcinfo->context;
/* Find the configuration to use */
if (config_column)
{
- int config_attr_num;
+ int config_attr_num;
config_attr_num = SPI_fnumber(rel->rd_att, trigger->tgargs[1]);
if (config_attr_num == SPI_ERROR_NOATTRIBUTE)
}
else
{
- List *names;
+ List *names;
names = stringToQualifiedNameList(trigger->tgargs[1]);
/* require a schema so that results are not search path dependent */
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.63 2007/03/25 11:56:02 ishii Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.64 2007/11/15 23:23:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static int
compare1(const void *p1, const void *p2)
{
- uint32 v1,
+ uint32 v1,
v2;
v1 = *(uint32 *) p1;
static int
compare2(const void *p1, const void *p2)
{
- uint32 v1,
+ uint32 v1,
v2;
v1 = *(uint32 *) p1;
static int
compare3(const void *p1, const void *p2)
{
- uint32 s1, s2, d1, d2;
+ uint32 s1,
+ s2,
+ d1,
+ d2;
- s1 = *(uint32 *)p1;
- s2 = *((uint32 *)p1 + 1);
+ s1 = *(uint32 *) p1;
+ s2 = *((uint32 *) p1 + 1);
d1 = ((pg_utf_to_local_combined *) p2)->utf1;
d2 = ((pg_utf_to_local_combined *) p2)->utf2;
return (s1 > d1 || (s1 == d1 && s2 > d2)) ? 1 : ((s1 == d1 && s2 == d2) ? 0 : -1);
static int
compare4(const void *p1, const void *p2)
{
- uint32 v1,
+ uint32 v1,
v2;
v1 = *(uint32 *) p1;
/*
* convert 32bit wide character to mutibye stream pointed to by iso
*/
-static unsigned char *set_iso_code(unsigned char *iso, uint32 code)
+static unsigned char *
+set_iso_code(unsigned char *iso, uint32 code)
{
if (code & 0xff000000)
*iso++ = code >> 24;
*/
void
UtfToLocal(const unsigned char *utf, unsigned char *iso,
- const pg_utf_to_local *map, const pg_utf_to_local_combined *cmap,
+ const pg_utf_to_local *map, const pg_utf_to_local_combined *cmap,
int size1, int size2, int encoding, int len)
{
- uint32 iutf;
- uint32 cutf[2];
- uint32 code;
+ uint32 iutf;
+ uint32 cutf[2];
+ uint32 code;
pg_utf_to_local *p;
pg_utf_to_local_combined *cp;
int l;
*/
if (cmap && len > l)
{
- const unsigned char *utf_save = utf;
- int len_save = len;
- int l_save = l;
-
+ const unsigned char *utf_save = utf;
+ int len_save = len;
+ int l_save = l;
+
len -= l;
l = pg_utf_mblen(utf);
sizeof(pg_utf_to_local), compare1);
if (p == NULL)
report_untranslatable_char(PG_UTF8, encoding,
- (const char *) (utf_save - l_save), len_save);
+ (const char *) (utf_save - l_save), len_save);
iso = set_iso_code(iso, p->code);
}
sizeof(pg_utf_to_local), compare1);
if (p == NULL)
report_untranslatable_char(PG_UTF8, encoding,
- (const char *) (utf_save - l_save), len_save);
+ (const char *) (utf_save - l_save), len_save);
iso = set_iso_code(iso, p->code);
p = bsearch(&cutf[1], map, size1,
code = p->code;
}
}
- else /* no cmap or no remaining data */
+ else /* no cmap or no remaining data */
{
p = bsearch(&iutf, map, size1,
sizeof(pg_utf_to_local), compare1);
if (p == NULL)
report_untranslatable_char(PG_UTF8, encoding,
- (const char *) (utf - l), len);
+ (const char *) (utf - l), len);
code = p->code;
}
iso = set_iso_code(iso, code);
*/
void
LocalToUtf(const unsigned char *iso, unsigned char *utf,
- const pg_local_to_utf *map, const pg_local_to_utf_combined *cmap,
+ const pg_local_to_utf *map, const pg_local_to_utf_combined *cmap,
int size1, int size2, int encoding, int len)
{
unsigned int iiso;
if (p == NULL)
{
/*
- * not found in the ordinary map. if there's a combined
- * character map, try with it
+ * not found in the ordinary map. if there's a combined character
+ * map, try with it
*/
if (cmap)
{
cp = bsearch(&iiso, cmap, size2,
- sizeof(pg_local_to_utf_combined), compare4);
+ sizeof(pg_local_to_utf_combined), compare4);
if (cp)
{
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.26 2007/10/13 20:18:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.27 2007/11/15 23:23:44 momjian Exp $
*
* XXX this file does not really belong in psql/. Perhaps move to libpq?
* It also seems that the mbvalidate function is redundant with existing
* To avoid version-skew problems, this file must not use declarations
* from pg_wchar.h: the encoding IDs we are dealing with are determined
* by the libpq.so we are linked with, and that might not match the
- * numbers we see at compile time. (If this file were inside libpq,
+ * numbers we see at compile time. (If this file were inside libpq,
* the problem would go away...)
*
* Hence, we have our own definition of pg_wchar, and we get the values
linewidth += 4;
format_size += 4;
}
- else /* Output it as-is */
+ else /* Output it as-is */
{
linewidth += w;
format_size += 1;
linewidth += 6; /* \u0000 */
format_size += 6;
}
- else /* All other chars */
+ else /* All other chars */
{
linewidth += w;
format_size += chlen;
linewidth += 4;
ptr += 4;
}
- else /* Output it as-is */
+ else /* Output it as-is */
{
linewidth += w;
*ptr++ = *pwcs;
ptr += 6;
linewidth += 6;
}
- else /* All other chars */
+ else /* All other chars */
{
int i;
#!/bin/sh
-# $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.93 2007/11/15 22:12:09 momjian Exp $
+# $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.94 2007/11/15 23:23:44 momjian Exp $
# Known bugs:
#
for FILE
do
cat "$FILE" |
-# convert // comments to /* */
+
+# Convert // comments to /* */
sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' |
+
# Avoid bug that converts 'x =- 1' to 'x = -1'
sed 's;=- ;-= ;g' |
-# mark some comments for special treatment later
+
+# Mark some comments for special treatment later
sed 's;/\* *---;/*---X_X;g' |
-# workaround for indent bug with 'else' handling
-# trim trailing space after single-line after-'else' comment
-# so next test can be done easily
- sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' |
-# indent multi-line after-'else' comment so BSD indent will move it properly
- sed 's;\([} ]\)else[ ]*\(/\*.*[^\*][^/]\)$;\1else\
+
+# 'else' followed by a single-line comment, followed by
+# a brace on the next line confuses BSD indent, so we push
+# the comment down to the next line, then later pull it
+# back up again.
+ sed 's;\([} ]\)else[ ]*\(/\*\)\(.*\*/\)[ ]*$;\1else\
+ \2PGINDENT_MOVED\3;g' |
+
+# Indent multi-line after-'else' comment so BSD indent will move it properly.
+# We already moved down single-line comments above. Check for '*' to make
+# sure we are not in a single-line comment that has other text on the line.
+ sed 's;\([} ]\)else[ ]*\(/\*[^\*]*\)[ ]*$;\1else\
\2;g' |
detab -t4 -qc |
-# work around bug where function that defines no local variables misindents
+# Work around bug where function that defines no local variables misindents
# switch() case lines and line after #else. Do not do for struct/enum.
awk ' BEGIN {line1 = ""; line2 = ""}
{
print line1;
}' |
-# prevent indenting of code in 'extern "C"' blocks
+# Prevent indenting of code in 'extern "C"' blocks.
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
{
line2 = $0;
print line1;
}' |
-# protect backslashes in DATA()
+# Protect backslashes in DATA().
sed 's;^DATA(.*$;/*&*/;' |
-# protect wrapping in CATALOG()
+# Protect wrapping in CATALOG().
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
# We get the list of typedef's from /src/tools/find_typedef
fi
cat /tmp/$$a |
-# restore DATA/CATALOG lines
+# Restore DATA/CATALOG lines.
sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
-# remove tabs and retab with four spaces
+# Remove tabs and retab with four spaces.
detab -t8 -qc |
entab -t4 -qc |
sed 's;^/\* Open extern \"C\" \*/$;{;' |
sed 's;^/\* Close extern \"C\" \*/$;};' |
sed 's;/\*---X_X;/* ---;g' |
-# workaround indent bug for 'static'
+# Workaround indent bug for 'static'.
sed 's;^static[ ][ ]*;static ;g' |
-# remove too much indenting after closing brace
+# Remove too much indenting after closing brace.
sed 's;^} [ ]*;} ;' |
-# indent single-line after-'else' comment by only one tab
+# Indent single-line after-'else' comment by only one tab.
sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' |
-# pull in #endif comments
+# Pull in #endif comments.
sed 's;^#endif[ ][ ]*/\*;#endif /*;' |
-# work around misindenting of function with no variables defined
+# Work around misindenting of function with no variables defined.
awk '
{
if ($0 ~ /^[ ]*int[ ]*pgindent_func_no_var_fix;/)
else print $0;
}' |
-# add space after comments that start on tab stops
+# Add space after comments that start on tab stops.
sed 's;\([^ ]\)\(/\*.*\*/\)$;\1 \2;' |
-# move trailing * in function return type
+# Move trailing * in function return type.
sed 's;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' |
-# remove un-needed braces around single statements
+# Remove un-needed braces around single statements.
# Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably
# isn't needed for general use.
# awk '
# print line2;
# }' |
-# remove blank line between opening brace and block comment
+# Remove blank line between opening brace and block comment.
awk '
{
line3 = $0;
print line2;
}' |
-# remove trailing blank lines, helps with adding blank before trailing #endif
+# Pull up single-line comment after 'else' that was pulled down above
+ awk '
+ {
+ if (NR != 1)
+ {
+ if ($0 ~ "/\*PGINDENT_MOVED")
+ {
+ # remove tag
+ sub("PGINDENT_MOVED", "", $0);
+ # remove leading whitespace
+ sub("^[ ]*", "", $0);
+ # add comment with single tab prefix
+ print prev_line" "$0;
+ # throw away current line
+ getline;
+ }
+ else
+ print prev_line;
+ }
+ prev_line = $0;
+ }
+ END {
+ if (NR >= 1)
+ print prev_line;
+ }' |
+
+# Remove trailing blank lines, helps with adding blank before trailing #endif.
awk ' BEGIN {blank_lines = 0;}
{
line1 = $0;
}
}' |
-# remove blank line before #else, #elif, and #endif
+# Remove blank line before #else, #elif, and #endif.
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
{
line2 = $0;
print line1;
}' |
-# add blank line before #endif if it is the last line in the file
+# Add blank line before #endif if it is the last line in the file.
awk ' BEGIN {line1 = ""; line2 = ""}
{
line2 = $0;
else print $0;
}' |
-# fix indenting of typedef caused by __cplusplus in libpq-fe.h
+# Fix indenting of typedef caused by __cplusplus in libpq-fe.h.
(
if echo "$FILE" | grep -q 'libpq-fe.h$'
then sed 's/^[ ]*typedef enum/typedef enum/'