add better support for encoder, command including

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8149 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-12-31 10:38:29 +00:00
commit a32d40e0f1

View file

@ -55,14 +55,24 @@ static DOH *encode(char *name, DOH *s) {
DOH *handle, *ns; DOH *handle, *ns;
DOH *(*fn)(DOH *); DOH *(*fn)(DOH *);
long pos; long pos;
char *cfmt = strstr(name,":");
DOH *tmp = 0;
if (cfmt) {
tmp = NewStringf(cfmt + 1, s);
Setfile(tmp,Getfile((DOH *)s));
Setline(tmp,Getline((DOH *)s));
*cfmt = '\0';
}
if (!encodings || !(handle = Getattr(encodings,name))) { if (!encodings || !(handle = Getattr(encodings,name))) {
return Copy(s); return Copy(s);
} }
if (tmp) s = tmp;
pos = Tell(s); pos = Tell(s);
Seek(s,0,SEEK_SET); Seek(s,0,SEEK_SET);
fn = (DOH *(*)(DOH *)) Data(handle); fn = (DOH *(*)(DOH *)) Data(handle);
ns = (*fn)(s); ns = (*fn)(s);
Seek(s,pos,SEEK_SET); Seek(s,pos,SEEK_SET);
if (tmp) Delete(tmp);
return ns; return ns;
} }
@ -104,6 +114,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
char *stemp; char *stemp;
int nbytes = 0; int nbytes = 0;
char encoder[128], *ec = 0; char encoder[128], *ec = 0;
int plevel = 0;
memset (newformat, 0, sizeof (newformat)); memset (newformat, 0, sizeof (newformat));
@ -146,6 +157,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
nbytes++; nbytes++;
state = 0; state = 0;
} else if (*p == '(') { } else if (*p == '(') {
++plevel;
ec = encoder; ec = encoder;
state = 60; state = 60;
} else { } else {
@ -246,13 +258,23 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
/* Got an encoding header */ /* Got an encoding header */
case 60: case 60:
if (*p == ')') { if (*p == '(') {
++plevel;
*ec = *p;
ec++;
} else if (*p == ')') {
--plevel;
if (plevel <= 0) {
*ec = 0; *ec = 0;
state = 10; state = 10;
} else { } else {
*ec = *p; *ec = *p;
ec++; ec++;
} }
} else {
*ec = *p;
ec++;
}
break; break;
case 100: case 100:
/* Got a formatting code */ /* Got a formatting code */