In the middle of testing

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@108 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dustin Mitchell 2000-01-19 00:10:27 +00:00
commit da2211f160
3 changed files with 104 additions and 53 deletions

View file

@ -1,5 +1,3 @@
# Generated automatically from Makefile.in by configure.
CC = @CC@ CC = @CC@
AR = @AR@ AR = @AR@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
@ -11,14 +9,20 @@ CCSHARED = @CCSHARED@
LDSHARED = @LDSHARED@ LDSHARED = @LDSHARED@
INCLUDE = -I. -I../DOH/Include INCLUDE = -I. -I../DOH/Include
SRCS = scanner.c include.c getopt.c misc.c SRCS = scanner.c include.c getopt.c misc.c super.c
OBJS = scanner.o include.o getopt.o misc.o OBJS = scanner.o include.o getopt.o misc.o super.o
.c.o: .c.o:
$(CC) $(CCSHARED) $(INCLUDE) $(CFLAGS) -c -o $*.o $< $(CC) $(CCSHARED) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(OBJS) all: $(OBJS)
supertest: super.c
$(CC) $(CCSHARED) $(INCLUDE) $(CFLAGS) -g -DSUPER_TEST -c \
-o supertest.o super.c
$(CC) supertest.o -ldoh -o supertest
clean: clean:
rm -f *.o *~ core *.so *.a rm -f *.o *~ core *.so *.a

View file

@ -15,7 +15,7 @@
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
#include "doh.h" #include "doh.h"
#include "swigcore.h" #include "swig.h"
static char cvstag[] = "$Header$"; static char cvstag[] = "$Header$";
@ -46,6 +46,10 @@ typedef struct Super
char pb[4]; /* Pushback data */ char pb[4]; /* Pushback data */
int pbi; int pbi;
/* -- that silly line and file -- */
int line;
DOH *file;
/* -- specific to the SuperString implementation */ /* -- specific to the SuperString implementation */
SSTag *tags; /* array of tags */ SSTag *tags; /* array of tags */
int maxtags; /* max size allocated for tags */ int maxtags; /* max size allocated for tags */
@ -76,8 +80,10 @@ static int Super_putc(DOH *s, int ch);
static int Super_getc(DOH *s); static int Super_getc(DOH *s);
static int Super_ungetc(DOH *s, int ch); static int Super_ungetc(DOH *s, int ch);
static int Super_replace(DOH *str, DOH *token, DOH *rep, int flags); static int Super_replace(DOH *str, DOH *token, DOH *rep, int flags);
static int Super_setfile(DOH *s, DOH *f); static void Super_setfile(DOH *s, DOH *f);
static int Super_setline(DOH *s, int); static void Super_setline(DOH *s, int);
static DOH * Super_getfile(DOH *s);
static int Super_getline(DOH *s);
static void Super_chop(DOH *str); static void Super_chop(DOH *str);
/* internal functions */ /* internal functions */
@ -88,7 +94,7 @@ static void Super_add_space(Super *s, int more_bytes);
static void Super_insert_tag(Super *s, int index, int length, static void Super_insert_tag(Super *s, int index, int length,
int line, DOH *filename); int line, DOH *filename);
static void Super_delete_tag(Super *s, int index); static void Super_delete_tag(Super *s, int index);
static void Super_count_newlines(char *s, int len); static int Super_count_newlines(char *s, int len);
static void Super_string_insert(Super *s, int pos, char *str, static void Super_string_insert(Super *s, int pos, char *str,
int len, DOH *filename, int line); int len, DOH *filename, int line);
static void Super_super_insert2(Super *s, int pos, char *str, static void Super_super_insert2(Super *s, int pos, char *str,
@ -102,7 +108,8 @@ static int Super_raw_replace(Super *str, char *token, int flags,
/* method tables */ /* method tables */
static DohSequenceMethods SuperSeqMethods = { static DohSequenceMethods SuperSeqMethods =
{
0, /* doh_getitem */ 0, /* doh_getitem */
0, /* doh_setitem */ 0, /* doh_setitem */
Super_delitem, /* doh_delitem */ Super_delitem, /* doh_delitem */
@ -111,7 +118,16 @@ static DohSequenceMethods SuperSeqMethods = {
0, /* doh_next */ 0, /* doh_next */
}; };
static DohFileMethods SuperFileMethods = { static DohPositionalMethods SuperPositionalMethods =
{
Super_setfile,
Super_getfile,
Super_setline,
Super_getline
};
static DohFileMethods SuperFileMethods =
{
Super_read, Super_read,
Super_write, Super_write,
Super_putc, Super_putc,
@ -120,18 +136,16 @@ static DohFileMethods SuperFileMethods = {
Super_seek, Super_seek,
Super_tell, Super_tell,
0, 0,
0,
Super_setfile,
0,
Super_setline
}; };
static DohSuperMethods SuperSuperMethods = { static DohStringMethods SuperStringMethods =
{
Super_replace, Super_replace,
Super_chop Super_chop
}; };
static DohObjInfo SuperType = { static DohObjInfo SuperType =
{
"SuperString", /* objname */ "SuperString", /* objname */
sizeof(Super), /* objsize */ sizeof(Super), /* objsize */
DelSuper, /* doh_del */ DelSuper, /* doh_del */
@ -150,6 +164,7 @@ static DohObjInfo SuperType = {
&SuperFileMethods, /* doh_file */ &SuperFileMethods, /* doh_file */
&SuperStringMethods, /* doh_string */ &SuperStringMethods, /* doh_string */
0, /* doh_callable */ 0, /* doh_callable */
&SuperPositionalMethods, /* doh_position */
}; };
#define INIT_MAXSIZE 16 #define INIT_MAXSIZE 16
@ -184,7 +199,7 @@ NewSuper(char *s, DOH *filename, int firstline)
str->str = (char *) DohMalloc(max); str->str = (char *) DohMalloc(max);
assert(str); assert(str);
if (s) if (s)
copy_string(str->str,s); strcpy(str->str,s);
else else
str->str[0] = 0; str->str[0] = 0;
@ -199,8 +214,8 @@ NewSuper(char *s, DOH *filename, int firstline)
str->tags = (SSTag *) DohMalloc(max * sizeof(SSTag)); str->tags = (SSTag *) DohMalloc(max * sizeof(SSTag));
assert(str->tags); assert(str->tags);
str->tags[0].position = 0; str->tags[0].length = 0;
str->tags[0].line = 1; str->tags[0].line = firstline;
if (!String_check(filename) && !SuperString_check(filename)) if (!String_check(filename) && !SuperString_check(filename))
filename = NewString(filename); filename = NewString(filename);
else else
@ -212,12 +227,12 @@ NewSuper(char *s, DOH *filename, int firstline)
} }
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* int Super_check(DOH *s) - Check if s is a Super * int SuperString_check(DOH *s) - Check if s is a Super
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
int int
SuperString_check(DOH *s) SuperString_check(DOH *s)
{ {
return (s && DohCheck(s) && ((Super *) c)->objinfo == &SuperType); return (s && DohCheck(s) && ((Super *) s)->objinfo == &SuperType);
} }
/* ---- "Member" Functions ---- */ /* ---- "Member" Functions ---- */
@ -428,14 +443,14 @@ Super_insert(DOH *so, int pos, DOH *str)
Super *s; Super *s;
s = (Super *) so; s = (Super *) so;
if (Super_check(str)) if (SuperString_check(str))
Super_super_insert(s, pos, (Super *)str); Super_super_insert(s, pos, (Super *)str);
else if (DohCheck(str)) else if (DohCheck(str))
Super_string_insert(s, pos, Char(str), Len(str), Super_string_insert(s, pos, Char(str), Len(str),
Getfile(str), Getline(str)); Getfile(str), Getline(str));
else else
/* hmph. Nothin. */ /* hmph. Nothin. */
Super_string_insert(s, pos, char *str, 0, 0); Super_string_insert(s, pos, str, 0, 0, 0);
return 0; return 0;
} }
@ -449,7 +464,7 @@ Super_insert(DOH *so, int pos, DOH *str)
static int Super_delitem(DOH *so, int pos) static int Super_delitem(DOH *so, int pos)
{ {
Super *s = (Super *) so; Super *s = (Super *) so;
int thistag, nexttag; int tag;
s->hashkey = -1; s->hashkey = -1;
if (pos == DOH_END) pos = s->len-1; if (pos == DOH_END) pos = s->len-1;
@ -477,7 +492,7 @@ static int Super_delitem(DOH *so, int pos)
/* and move the tags */ /* and move the tags */
if (! --s->tags[tag].length) if (! --s->tags[tag].length)
Super_delete_tag(tag); Super_delete_tag(s, tag);
return 0; return 0;
} }
@ -557,7 +572,7 @@ Super_write(DOH *so, void *buffer, int len)
s->len = s->sp + len; s->len = s->sp + len;
/* update tag */ /* update tag */
s->tag[s->curtag].length += len; s->tags[s->curtag].length += len;
/* and copy the data */ /* and copy the data */
memmove(s->str + s->sp, buffer, len); memmove(s->str + s->sp, buffer, len);
@ -626,15 +641,15 @@ Super_putc(DOH *so, int ch)
assert(s->str); assert(s->str);
s->maxsize *= 2; s->maxsize *= 2;
} }
s->str[s->len++] = c; s->str[s->len++] = ch;
s->str[s->len] = 0; s->str[s->len] = 0;
} }
else else
s->str[s->sp] = (char) ch; s->str[s->sp] = (char) ch;
/* and move ahead over the new character */ /* and move ahead over the new character */
Super_move(s, 1) Super_move(s, 1);
return ch; return ch;
} }
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
@ -713,6 +728,26 @@ Super_setline(DOH *obj, int l)
assert(0); /* illegal operation */ assert(0); /* illegal operation */
} }
/* -------------------------------------------------------------------------
* void Super_getfile(DOH *obj, DOH *f)
* ------------------------------------------------------------------------- */
static DOH *
Super_getfile(DOH *obj)
{
assert(0); /* illegal operation */
}
/* -------------------------------------------------------------------------
* void Super_getline(DOH *obj, int l)
* ------------------------------------------------------------------------- */
static int
Super_getline(DOH *obj)
{
assert(0); /* illegal operation */
}
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* void Super_chop(DOH *str) * void Super_chop(DOH *str)
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -732,11 +767,11 @@ Super_chop(DOH *so) {
c = s->str + s->len - 1; c = s->str + s->len - 1;
while ((s->len >= 0) && (isspace(*c))) while ((s->len >= 0) && (isspace(*c)))
c--; c--;
len = c - str->str + 1; len = c - s->str + 1;
/* Move the point back if necessary */ /* Move the point back if necessary */
if (s->sp > len) if (s->sp > len)
Super_move(len - s->sp); Super_move(s, len - s->sp);
tag = Super_get_tag(s, len, &offset); tag = Super_get_tag(s, len, &offset);
@ -762,8 +797,8 @@ Super_move(Super *s, int delta)
int curtag_offset = s->curtag_offset; int curtag_offset = s->curtag_offset;
int line_offset; int line_offset;
if (delta > len - s->sp) if (delta > s->len - s->sp)
delta = len - s->sp; delta = s->len - s->sp;
while (1) while (1)
{ {
@ -825,12 +860,12 @@ Super_insert_tag(Super *s, int index, int length,
{ {
s->maxtags *= 2; s->maxtags *= 2;
s->tags = (SSTag *)DohRealloc(s->tags, s->tags = (SSTag *)DohRealloc(s->tags,
s->maxtags * sizeof(SStag)); s->maxtags * sizeof(SSTag));
assert(s->tags); assert(s->tags);
} }
memmove(s->tags + index + 1, s->tags + index, memmove(s->tags + index + 1, s->tags + index,
(s->numtags - index) * sizeof(SStag)); (s->numtags - index) * sizeof(SSTag));
s->tags[index].length = length; s->tags[index].length = length;
s->tags[index].line = line; s->tags[index].line = line;
s->tags[index].filename = filename; s->tags[index].filename = filename;
@ -844,11 +879,11 @@ Super_insert_tag(Super *s, int index, int length,
static void static void
Super_delete_tag(Super *s, int index) Super_delete_tag(Super *s, int index)
{ {
if (!tag) return; /* don't delete first tag */ if (!index) return; /* don't delete first tag */
Delete(s->tags[index].filename); Delete(s->tags[index].filename);
memmove(s->tags + index, s->tags + index + 1, memmove(s->tags + index, s->tags + index + 1,
(s->numtags - index - 1) * sizeof(SStag)); (s->numtags - index - 1) * sizeof(SSTag));
s->numtags--; s->numtags--;
} }
@ -856,7 +891,7 @@ Super_delete_tag(Super *s, int index)
* static int Super_add_space(Super *s, int more_bytes) -- room to grow * static int Super_add_space(Super *s, int more_bytes) -- room to grow
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
static void static int
Super_count_newlines(char *s, int len) Super_count_newlines(char *s, int len)
{ {
register int retval = 0; register int retval = 0;
@ -875,7 +910,7 @@ Super_add_space(Super *s, int more_bytes)
{ {
if (s->len + more_bytes >= s->maxsize) if (s->len + more_bytes >= s->maxsize)
{ {
newsize = (s->len + more_bytes) * 2; int newsize = (s->len + more_bytes) * 2;
s->str = (char *)DohRealloc(s->str, newsize); s->str = (char *)DohRealloc(s->str, newsize);
assert(s->str); assert(s->str);
s->maxsize = newsize; s->maxsize = newsize;
@ -911,7 +946,7 @@ Super_string_insert(Super *s, int pos, char *str, int len,
/* insert new tags for this string if necessary */ /* insert new tags for this string if necessary */
tag = Super_get_tag(s, pos, &offset); tag = Super_get_tag(s, pos, &offset);
if (file) if (filename)
{ {
int left_len = offset; int left_len = offset;
int mid_len = len; int mid_len = len;
@ -1043,7 +1078,7 @@ Super_super_insert(Super *s, int pos, Super *str)
if (left_len) if (left_len)
s->tags[tag++].length = left_len; s->tags[tag++].length = left_len;
memmove(s->tags + tag, str->tags, str->numtags * sizeof(SSTag)); memmove(s->tags + tag, str->tags, str->numtags * sizeof(SSTag));
tags += str->numtags; tag += str->numtags;
if (right_len) if (right_len)
{ {
s->tags[tag].length = right_len; s->tags[tag].length = right_len;
@ -1106,7 +1141,7 @@ Super_rr_append_chunk(int start, int len)
initial = rr_original->tags[initial_tag]; initial = rr_original->tags[initial_tag];
new_initial.line = rr_original->line; new_initial.line = rr_original->line;
new_initial.filename = rr_original->filename; new_initial.filename = rr_original->file;
new_initial.length = initial.length - rr_original->curtag_offset; new_initial.length = initial.length - rr_original->curtag_offset;
Super_move(rr_original, len); Super_move(rr_original, len);
@ -1116,7 +1151,7 @@ Super_rr_append_chunk(int start, int len)
{ {
final = rr_original->tags[final_tag]; final = rr_original->tags[final_tag];
new_final.line = rr_original->line; new_final.line = rr_original->line;
new_final.filename = rr_original->filename; new_final.filename = rr_original->file;
new_final.length = rr_original->curtag_offset; new_final.length = rr_original->curtag_offset;
} }
else /* avoid zero-length final tag */ else /* avoid zero-length final tag */
@ -1157,11 +1192,6 @@ Super_raw_replace(Super *str, char *token, int flags,
char *match, *lastmatch_end; char *match, *lastmatch_end;
int tokenlen, state, i; int tokenlen, state, i;
int repcount = 0; int repcount = 0;
Super fake; /* HACK! :) */
SSTag *old_tags;
int old_numtags;
char *old_str;
int old_len;
str->hashkey = -1; str->hashkey = -1;
tokenlen = strlen(token); tokenlen = strlen(token);
@ -1270,8 +1300,8 @@ Super_raw_replace(Super *str, char *token, int flags,
if (flags & DOH_REPLACE_NOQUOTE) if (flags & DOH_REPLACE_NOQUOTE)
{ {
if (*match == '\"') state = RR_INSIDE_DOUBLE_QUOTES; if (*match == '\"') state = RR_INSIDE_DOUBLE_QUOTE;
else if (*match == '\'') state = RR_INSIDE_SINGLE_QUOTES; else if (*match == '\'') state = RR_INSIDE_SINGLE_QUOTE;
else if (*match == '\\' && else if (*match == '\\' &&
(*(match+1) == '\'' || *(match+1) == '\"')) (*(match+1) == '\'' || *(match+1) == '\"'))
match++; match++;
@ -1279,17 +1309,17 @@ Super_raw_replace(Super *str, char *token, int flags,
break; break;
case RR_IN_IDENTIFIER: case RR_INSIDE_IDENTIFIER:
if (!(isalnum(*match) || (*match == '_') || (*match == '$'))) if (!(isalnum(*match) || (*match == '_') || (*match == '$')))
state = RR_BEGIN_MATCH; state = RR_BEGIN_MATCH;
break; break;
case RR_IN_DOUBLE_QUOTES: case RR_INSIDE_DOUBLE_QUOTE:
if (*match == '\"') state = RR_BEGIN_MATCH; if (*match == '\"') state = RR_BEGIN_MATCH;
else if (*match == '\\') match++; else if (*match == '\\') match++;
break; break;
case RR_IN_SINGLE_QUOTES: case RR_INSIDE_SINGLE_QUOTE:
if (*match == '\'') state = RR_BEGIN_MATCH; if (*match == '\'') state = RR_BEGIN_MATCH;
else if (*match == '\\') match++; else if (*match == '\\') match++;
break; break;
@ -1307,3 +1337,15 @@ Super_raw_replace(Super *str, char *token, int flags,
Delete(rr_original); Delete(rr_original);
return repcount; return repcount;
} }
#ifdef SUPER_TEST
#include <stdio.h>
int main(int argc, char **argv)
{
DOH *g = NewSuper("Hello, cruel world", "greeting", 100);
DOH *b = NewSuper("Goodbye!!!", "bye", 20);
Printf(stdout, "%s\n%s\n", g, b);
}
#endif

View file

@ -39,6 +39,11 @@ extern DOH *Swig_include(DOH *name);
#define SWIG_FILE_DELIMETER "/" #define SWIG_FILE_DELIMETER "/"
/* --- Super Strings --- */
extern DOH *NewSuper(char *s, DOH *filename, int firstline);
extern int SuperString_check(DOH *s);
/* --- Command line parsing --- */ /* --- Command line parsing --- */
extern void Swig_init_args(int argc, char **argv); extern void Swig_init_args(int argc, char **argv);