beautify/format source code with gnu indent

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9505 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-11-01 23:54:54 +00:00
commit aa04c4c057
72 changed files with 27038 additions and 28016 deletions

View file

@ -21,20 +21,21 @@ char cvsroot_tree_c[] = "$Header$";
* Dump the tag structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */
void
Swig_print_tags(DOH *obj, DOH *root) {
void Swig_print_tags(DOH *obj, DOH *root) {
DOH *croot, *newroot;
DOH *cobj;
if (!root) croot = NewStringEmpty();
else croot = root;
if (!root)
croot = NewStringEmpty();
else
croot = root;
while (obj) {
Printf(stdout,"%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
Printf(stdout, "%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
cobj = firstChild(obj);
if (cobj) {
newroot = NewStringf("%s . %s",croot,nodeType(obj));
Swig_print_tags(cobj,newroot);
newroot = NewStringf("%s . %s", croot, nodeType(obj));
Swig_print_tags(cobj, newroot);
Delete(newroot);
}
obj = nextSibling(obj);
@ -61,36 +62,34 @@ static void print_indent(int l) {
* Swig_print_node(Node *n)
* ----------------------------------------------------------------------------- */
void
Swig_print_node(Node *obj) {
void Swig_print_node(Node *obj) {
Iterator ki;
Node *cobj;
Node *cobj;
print_indent(0);
Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj));
Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj));
ki = First(obj);
while (ki.key) {
String *k = ki.key;
if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
(Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) ||
(Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
(Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k,"parms") == 0) {
} else if (Cmp(k, "parms") == 0) {
print_indent(2);
Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k)));
Printf(stdout, "%-12s - %s\n", k, ParmList_protostr(Getattr(obj, k)));
} else {
DOH *o;
char *trunc = "";
print_indent(2);
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 40) {
trunc = "...";
}
Printf(stdout,"%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc);
Printf(stdout, "%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc);
Delete(o);
} else {
Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k));
Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k));
}
}
ki = Next(ki);
@ -98,12 +97,12 @@ Swig_print_node(Node *obj) {
cobj = firstChild(obj);
if (cobj) {
indent_level += 6;
Printf(stdout,"\n");
Printf(stdout, "\n");
Swig_print_tree(cobj);
indent_level -= 6;
} else {
print_indent(1);
Printf(stdout,"\n");
Printf(stdout, "\n");
}
}
@ -113,8 +112,7 @@ Swig_print_node(Node *obj) {
* Dump the tree structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */
void
Swig_print_tree(DOH *obj) {
void Swig_print_tree(DOH *obj) {
while (obj) {
Swig_print_node(obj);
obj = nextSibling(obj);
@ -127,25 +125,25 @@ Swig_print_tree(DOH *obj) {
* Appends a new child to a node
* ----------------------------------------------------------------------------- */
void
appendChild(Node *node, Node *chd) {
void appendChild(Node *node, Node *chd) {
Node *lc;
if (!chd) return;
if (!chd)
return;
lc = lastChild(node);
if (!lc) {
set_firstChild(node,chd);
set_firstChild(node, chd);
} else {
set_nextSibling(lc,chd);
set_previousSibling(chd,lc);
set_nextSibling(lc, chd);
set_previousSibling(chd, lc);
}
while (chd) {
lc = chd;
set_parentNode(chd,node);
set_parentNode(chd, node);
chd = nextSibling(chd);
}
set_lastChild(node,lc);
set_lastChild(node, lc);
}
/* -----------------------------------------------------------------------------
@ -154,20 +152,20 @@ appendChild(Node *node, Node *chd) {
* Preppends a new child to a node
* ----------------------------------------------------------------------------- */
void
preppendChild(Node *node, Node *chd) {
void preppendChild(Node *node, Node *chd) {
Node *fc;
if (!chd) return;
if (!chd)
return;
fc = firstChild(node);
if (fc) {
set_nextSibling(chd,fc);
set_previousSibling(fc,chd);
set_nextSibling(chd, fc);
set_previousSibling(fc, chd);
}
set_firstChild(node,chd);
set_firstChild(node, chd);
while (chd) {
set_parentNode(chd,node);
set_parentNode(chd, node);
chd = nextSibling(chd);
}
}
@ -178,8 +176,7 @@ preppendChild(Node *node, Node *chd) {
* Deletes a node.
* ----------------------------------------------------------------------------- */
void
deleteNode(Node *n) {
void deleteNode(Node *n) {
Node *parent;
Node *prev;
Node *next;
@ -188,17 +185,17 @@ deleteNode(Node *n) {
prev = previousSibling(n);
next = nextSibling(n);
if (prev) {
set_nextSibling(prev,next);
set_nextSibling(prev, next);
} else {
if (parent) {
set_firstChild(parent,next);
set_firstChild(parent, next);
}
}
if (next) {
set_previousSibling(next,prev);
set_previousSibling(next, prev);
} else {
if (parent) {
set_lastChild(parent,prev);
set_lastChild(parent, prev);
}
}
}
@ -209,17 +206,16 @@ deleteNode(Node *n) {
* Copies a node, but only copies simple attributes (no lists, hashes).
* ----------------------------------------------------------------------------- */
Node *
copyNode(Node *n) {
Node *copyNode(Node *n) {
Iterator ki;
Node *c = NewHash();
for (ki = First(n); ki.key; ki = Next(ki)) {
if (DohIsString(ki.item)) {
Setattr(c,ki.key,Copy(ki.item));
Setattr(c, ki.key, Copy(ki.item));
}
}
Setfile(c,Getfile(n));
Setline(c,Getline(n));
Setfile(c, Getfile(n));
Setline(c, Getline(n));
return c;
}
@ -230,11 +226,10 @@ copyNode(Node *n) {
* subtypes with extra information.
* ----------------------------------------------------------------------------- */
void
Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
void Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
while (n) {
Setattr(n,attrname,value);
Swig_tag_nodes(firstChild(n),attrname, value);
Setattr(n, attrname, value);
Swig_tag_nodes(firstChild(n), attrname, value);
n = nextSibling(n);
}
}
@ -243,10 +238,9 @@ Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
* checkAttribute()
* ----------------------------------------------------------------------------- */
int
checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
String *v = Getattr(n,name);
return v ? Equal(v,value) : 0;
int checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
String *v = Getattr(n, name);
return v ? Equal(v, value) : 0;
}
/* -----------------------------------------------------------------------------
@ -263,8 +257,7 @@ checkAttribute(Node *n, const String_or_char *name, const String_or_char *value)
* This function can be called more than once with different namespaces.
* ----------------------------------------------------------------------------- */
int
Swig_require(const char *ns, Node *n, ...) {
int Swig_require(const char *ns, Node *n, ...) {
va_list ap;
char *name;
DOH *obj;
@ -282,13 +275,13 @@ Swig_require(const char *ns, Node *n, ...) {
opt = 1;
name++;
}
obj = Getattr(n,name);
obj = Getattr(n, name);
if (!opt && !obj) {
Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n",
Getfile(n), Getline(n), name, nodeType(n));
Printf(stderr, "%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", Getfile(n), Getline(n), name, nodeType(n));
assert(obj);
}
if (!obj) obj = DohNone;
if (!obj)
obj = DohNone;
if (newref) {
/* Save a copy of the attribute */
Setattr(n, NewStringf("%s:%s", ns, name), obj);
@ -299,14 +292,14 @@ Swig_require(const char *ns, Node *n, ...) {
/* Save the view */
{
String *view = Getattr(n,k_view);
String *view = Getattr(n, k_view);
if (view) {
if (Strcmp(view,ns) != 0) {
if (Strcmp(view, ns) != 0) {
Setattr(n, NewStringf("%s:view", ns), view);
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
} else {
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
}
@ -320,8 +313,7 @@ Swig_require(const char *ns, Node *n, ...) {
* are saved, ie behaves as if all the attribute names were prefixed by ?.
* ----------------------------------------------------------------------------- */
int
Swig_save(const char *ns, Node *n, ...) {
int Swig_save(const char *ns, Node *n, ...) {
va_list ap;
char *name;
DOH *obj;
@ -334,12 +326,13 @@ Swig_save(const char *ns, Node *n, ...) {
} else if (*name == '?') {
name++;
}
obj = Getattr(n,name);
if (!obj) obj = DohNone;
obj = Getattr(n, name);
if (!obj)
obj = DohNone;
/* Save a copy of the attribute */
if (Setattr(n, NewStringf("%s:%s", ns, name), obj)) {
Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name);
Printf(stderr, "Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name);
}
name = va_arg(ap, char *);
}
@ -347,14 +340,14 @@ Swig_save(const char *ns, Node *n, ...) {
/* Save the view */
{
String *view = Getattr(n,k_view);
String *view = Getattr(n, k_view);
if (view) {
if (Strcmp(view,ns) != 0) {
if (Strcmp(view, ns) != 0) {
Setattr(n, NewStringf("%s:view", ns), view);
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
} else {
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
}
@ -366,15 +359,14 @@ Swig_save(const char *ns, Node *n, ...) {
* Restores attributes saved by a previous call to Swig_require() or Swig_save().
* ----------------------------------------------------------------------------- */
void
Swig_restore(Node *n) {
void Swig_restore(Node *n) {
String *temp;
int len;
List *l;
int len;
List *l;
String *ns;
Iterator ki;
ns = Getattr(n,k_view);
ns = Getattr(n, k_view);
assert(ns);
l = NewList();
@ -384,16 +376,14 @@ Swig_restore(Node *n) {
for (ki = First(n); ki.key; ki = Next(ki)) {
if (Strncmp(temp, ki.key, len) == 0) {
Append(l,ki.key);
Append(l, ki.key);
}
}
for (ki = First(l); ki.item; ki = Next(ki)) {
DOH *obj = Getattr(n,ki.item);
Setattr(n,Char(ki.item)+len,obj);
Delattr(n,ki.item);
DOH *obj = Getattr(n, ki.item);
Setattr(n, Char(ki.item) + len, obj);
Delattr(n, ki.item);
}
Delete(l);
Delete(temp);
}