Add -compact option.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4281 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
883b1dfa1a
commit
2c2bb2522f
2 changed files with 172 additions and 2 deletions
|
|
@ -354,7 +354,9 @@ typedef struct {
|
|||
|
||||
extern Wrapper *NewWrapper();
|
||||
extern void DelWrapper(Wrapper *w);
|
||||
extern void Wrapper_compact_print_mode_set(int flag);
|
||||
extern void Wrapper_pretty_print(String *str, File *f);
|
||||
extern void Wrapper_compact_print(String *str, File *f);
|
||||
extern void Wrapper_print(Wrapper *w, File *f);
|
||||
extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl);
|
||||
extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ char cvsroot_wrapfunc_c[] = "$Header$";
|
|||
#include "swig.h"
|
||||
#include <ctype.h>
|
||||
|
||||
static int Compact_mode = 0; /* set to 0 on commit */
|
||||
static int Max_line_size = 128;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewWrapper()
|
||||
*
|
||||
|
|
@ -51,6 +54,17 @@ DelWrapper(Wrapper *w) {
|
|||
free(w);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_compact_print_mode_set()
|
||||
*
|
||||
* Set compact_mode.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Wrapper_compact_print_mode_set(int flag) {
|
||||
Compact_mode = flag;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_pretty_print()
|
||||
*
|
||||
|
|
@ -160,11 +174,162 @@ Wrapper_pretty_print(String *str, File *f) {
|
|||
Printf(f,"\n");
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_compact_print()
|
||||
*
|
||||
* Formats a wrapper function and fixes up the indentation.
|
||||
* Print out in compact format, with Compact enabled.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Wrapper_compact_print(String *str, File *f) {
|
||||
String *ts, *tf; //temp string & temp file
|
||||
int level = 0;
|
||||
int c, i;
|
||||
int empty = 1;
|
||||
|
||||
ts = NewString("");
|
||||
tf = NewString("");
|
||||
Seek(str,0, SEEK_SET);
|
||||
Clear(ts);
|
||||
Clear(tf);
|
||||
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (c == '\"') {
|
||||
Putc(c,ts);
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (c == '\\') {
|
||||
Putc(c,ts);
|
||||
c = Getc(str);
|
||||
}
|
||||
Putc(c,ts);
|
||||
if (c == '\"') break;
|
||||
}
|
||||
} else if (c == '\'') {
|
||||
Putc(c,ts);
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (c == '\\') {
|
||||
Putc(c,ts);
|
||||
c = Getc(str);
|
||||
}
|
||||
Putc(c,ts);
|
||||
if (c == '\'') break;
|
||||
}
|
||||
} else if (c == '{') {
|
||||
Putc(c,ts);
|
||||
if (Len(tf) == 0) {
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
Printf(tf, "");
|
||||
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
|
||||
Putc(' ',tf);
|
||||
} else {
|
||||
Putc('\n',tf);
|
||||
Printf(f,"%s", tf);
|
||||
Clear(tf);
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
Printf(tf, "");
|
||||
}
|
||||
Printf(tf,"%s",ts);
|
||||
Clear(ts);
|
||||
level+=4;
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (!isspace(c)) {
|
||||
Ungetc(c,str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (c == '}') {
|
||||
if (Len(tf) == 0) {
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
|
||||
Putc(' ',tf);
|
||||
} else {
|
||||
Putc('\n',tf);
|
||||
Printf(f,"%s", tf);
|
||||
Clear(tf);
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
Printf(tf, "");
|
||||
}
|
||||
Printf(tf, "%s", ts);
|
||||
Putc(c, tf);
|
||||
Clear(ts);
|
||||
level-=4;
|
||||
} else if (c == '\n') {
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (!isspace(c))
|
||||
break;
|
||||
}
|
||||
if (c == '}') {
|
||||
Putc(' ',ts);
|
||||
} else if ( (c != EOF) || (Len(ts)!=0) ){
|
||||
if (Len(tf) == 0) {
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
Printf(tf, "");
|
||||
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
|
||||
Putc(' ',tf);
|
||||
} else {
|
||||
Putc('\n',tf);
|
||||
Printf(f,"%s", tf);
|
||||
Clear(tf);
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',tf);
|
||||
Printf(tf, "");
|
||||
}
|
||||
Printf(tf,"%s",ts);
|
||||
Clear(ts);
|
||||
}
|
||||
Ungetc(c,str);
|
||||
|
||||
empty = 1;
|
||||
} else if (c == '/') {
|
||||
c = Getc(str);
|
||||
if (c != EOF) {
|
||||
if (c == '/') { /* C++ comment */
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (c == '\n') {
|
||||
Ungetc(c,str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (c == '*') { /* C comment */
|
||||
int endstar = 0;
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (endstar && c == '/') { /* end of C comment */
|
||||
break;
|
||||
}
|
||||
endstar = (c == '*');
|
||||
}
|
||||
} else {
|
||||
Putc('/',ts);
|
||||
Putc(c,ts);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!empty || !isspace(c)) {
|
||||
Putc(c,ts);
|
||||
empty = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty) {
|
||||
Printf(tf,"%s",ts);
|
||||
}
|
||||
if (Len(tf) != 0)
|
||||
Printf(f,"%s",tf);
|
||||
Delete(ts);
|
||||
Delete(tf);
|
||||
Printf(f,"\n");
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_print()
|
||||
*
|
||||
* Print out a wrapper function. Does pretty printing as well.
|
||||
* Print out a wrapper function. Does pretty or compact printing as well.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
|
|
@ -175,7 +340,10 @@ Wrapper_print(Wrapper *w, File *f) {
|
|||
Printf(str,"%s\n", w->def);
|
||||
Printf(str,"%s\n", w->locals);
|
||||
Printf(str,"%s\n", w->code);
|
||||
Wrapper_pretty_print(str,f);
|
||||
if (Compact_mode == 1)
|
||||
Wrapper_compact_print(str,f);
|
||||
else
|
||||
Wrapper_pretty_print(str,f);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue