Major cleanup of comments
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@128 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8a914e8bce
commit
fc2fb1ff98
25 changed files with 769 additions and 853 deletions
|
|
@ -1,21 +1,17 @@
|
|||
/******************************************************************************
|
||||
* DOH
|
||||
/* -----------------------------------------------------------------------------
|
||||
* base.c
|
||||
*
|
||||
* This file contains the function entry points for dispatching methods on
|
||||
* DOH objects. A number of small utility functions are also included.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
******************************************************************************/
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/*******************************************************************************
|
||||
* base.c
|
||||
*
|
||||
* This file contains the function entry points for dispatching methods on DOH
|
||||
* objects.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
static DohObjInfo DohBaseType = {
|
||||
|
|
@ -1096,6 +1092,54 @@ DohInit(DOH *b) {
|
|||
bs->flags = 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_setfile()
|
||||
*
|
||||
* Set file location (default method).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
DohXBase_setfile(DOH *ho, DOH *file) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
if (!DohCheck(file)) file = NewString(file);
|
||||
h->file = file;
|
||||
Incref(h->file);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_getfile()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohXBase_getfile(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->file;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_setline()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
DohXBase_setline(DOH *ho, int l) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
h->line = l;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_getline()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
DohXBase_getline(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->line;
|
||||
}
|
||||
|
||||
static DohPositionalMethods XBasePositionalMethods = {
|
||||
DohXBase_setfile,
|
||||
DohXBase_getfile,
|
||||
DohXBase_setline,
|
||||
DohXBase_getline
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXInit()
|
||||
*
|
||||
|
|
@ -1106,47 +1150,9 @@ DohXInit(DOH *b) {
|
|||
DohXBase *bs = (DohXBase *) b;
|
||||
bs->file = 0;
|
||||
bs->line = 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* XBase_setfile()
|
||||
*
|
||||
* Set file location (default method).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
XBase_setfile(DOH *ho, DOH *file) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
if (!DohCheck(file)) file = NewString(file);
|
||||
h->file = file;
|
||||
Incref(h->file);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* XBase_getfile()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
XBase_getfile(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->file;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* XBase_setline()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
XBase_setline(DOH *ho, int l) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
h->line = l;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* XBase_getline()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
XBase_getline(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->line;
|
||||
bs->objinfo->doh_position = &XBasePositionalMethods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
/******************************************************************************
|
||||
* DOH
|
||||
/* -----------------------------------------------------------------------------
|
||||
* callable.c
|
||||
*
|
||||
* This file implements a simple callable object supporting a function call
|
||||
* operation.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
******************************************************************************/
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* callable.c
|
||||
*
|
||||
* Implements a callable function-like object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
/******************************************************************************
|
||||
* DOH
|
||||
/* -----------------------------------------------------------------------------
|
||||
* file.c
|
||||
*
|
||||
* This file implements a file-like object that can be built around an
|
||||
* ordinary FILE * or integer file descriptor.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
******************************************************************************/
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* file.c
|
||||
*
|
||||
* This file implements a DOH file-like object.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
||||
#include "dohint.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -26,7 +23,9 @@ typedef struct {
|
|||
} DohFile;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DelFile(DOH *s) - Delete a file
|
||||
* DelFile()
|
||||
*
|
||||
* Delete a file. Closes the file if the closeondel flag is set.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
|
|
@ -39,9 +38,9 @@ DelFile(DOH *so) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_read(DOH *so, void *buffer, int len)
|
||||
* File_read()
|
||||
*
|
||||
* Read data from the File
|
||||
* Reads data from a file into a buffer.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
|
|
@ -54,10 +53,11 @@ File_read(DOH *so, void *buffer, int len) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_write(DOH *so, void *buffer, int len)
|
||||
* File_write()
|
||||
*
|
||||
* Write data to the File
|
||||
* Write data from a buffer to a file.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
File_write(DOH *so, void *buffer, int len) {
|
||||
DohFile *s = (DohFile *) so;
|
||||
|
|
@ -68,10 +68,11 @@ File_write(DOH *so, void *buffer, int len) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_seek(DOH *so, long offset, int whence)
|
||||
* File_seek()
|
||||
*
|
||||
* Seek to a new position
|
||||
* Seek to a new file position.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
File_seek(DOH *so, long offset, int whence) {
|
||||
DohFile *s = (DohFile *) so;
|
||||
|
|
@ -82,10 +83,11 @@ File_seek(DOH *so, long offset, int whence) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* long File_tell(DOH *so)
|
||||
* File_tell()
|
||||
*
|
||||
* Return current position
|
||||
* Return current file pointer.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static long
|
||||
File_tell(DOH *so) {
|
||||
DohFile *s = (DohFile *) so;
|
||||
|
|
@ -96,7 +98,7 @@ File_tell(DOH *so) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_putc(DOH *obj, int ch)
|
||||
* File_putc()
|
||||
*
|
||||
* Put a character on the output
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -110,7 +112,7 @@ File_putc(DOH *obj, int ch) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_getc(DOH *obj)
|
||||
* File_getc()
|
||||
*
|
||||
* Get a character
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -124,7 +126,7 @@ File_getc(DOH *obj) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_ungetc(DOH *obj, int ch)
|
||||
* File_ungetc()
|
||||
*
|
||||
* Put a character back onto the input
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -171,8 +173,11 @@ static DohObjInfo DohFileType = {
|
|||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewFile(DOH *filename, char *mode)
|
||||
* NewFile()
|
||||
*
|
||||
* Create a new file from a given filename and mode.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewFile(DOH *fn, char *mode)
|
||||
{
|
||||
|
|
@ -197,7 +202,9 @@ NewFile(DOH *fn, char *mode)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewFileFromFile(FILE *f)
|
||||
* NewFileFromFile()
|
||||
*
|
||||
* Create a file object from an already open FILE *.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
|
|
@ -214,7 +221,9 @@ NewFileFromFile(FILE *file)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewFileFromFd(int fd)
|
||||
* NewFileFromFd()
|
||||
*
|
||||
* Create a file object from an already existing integer file descriptor.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
|
|
@ -232,7 +241,9 @@ NewFileFromFd(int fd)
|
|||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int File_check(DOH *f) - Check if f is a file
|
||||
* File_check()
|
||||
*
|
||||
* Check if an object is a file.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
File_check(DOH *f)
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
static char cvsroot[] = "$Header:";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* fio.c
|
||||
*
|
||||
* This file provides support for formatted I/O via fprint style
|
||||
* functions.
|
||||
* This file implements a number of standard I/O operations included
|
||||
* formatted output, readline, and splitting.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header:";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
#define OBUFLEN 512
|
||||
|
||||
static DOH *encodings = 0; /* Encoding hash */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Writen()
|
||||
*
|
||||
* Write's N characters of output and retries until all characters are
|
||||
* written. This is useful should a write operation encounter a spurious signal.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int Writen(DOH *out, void *buffer, int len) {
|
||||
int nw = len, ret;
|
||||
char *cb = (char *) buffer;
|
||||
|
|
@ -39,18 +38,19 @@ static int Writen(DOH *out, void *buffer, int len) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void DohEncoding(char *name, DOH *(*fn)(DOH *s))
|
||||
* DohEncoding()
|
||||
*
|
||||
* Register a printf named encoding method.
|
||||
* Registers a new printf encoding method. An encoder function should accept
|
||||
* two file-like objects and operate as a filter.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *encodings = 0;
|
||||
void DohEncoding(char *name, DOH *(*fn)(DOH *s))
|
||||
{
|
||||
void
|
||||
DohEncoding(char *name, DOH *(*fn)(DOH *s)) {
|
||||
if (!encodings) encodings = NewHash();
|
||||
Setattr(encodings,(void *) name, NewVoid((void *)fn,0));
|
||||
}
|
||||
|
||||
/* internal function for processing an encoding */
|
||||
static DOH *encode(char *name, DOH *s) {
|
||||
DOH *handle, *ns;
|
||||
DOH *(*fn)(DOH *);
|
||||
|
|
@ -67,9 +67,21 @@ static DOH *encode(char *name, DOH *s) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohvPrintf(DOH *so, char *format, va_list ap)
|
||||
* DohvPrintf()
|
||||
*
|
||||
* printf
|
||||
* DOH implementation of printf. Output can be directed to any file-like object
|
||||
* including bare FILE * objects. The same formatting codes as printf are
|
||||
* recognized with two extensions:
|
||||
*
|
||||
* %s - Prints a "char *" or the string representation of any
|
||||
* DOH object. This will implicitly result in a call to
|
||||
* Str(obj).
|
||||
*
|
||||
* %(encoder)* - Filters the output through an encoding function registered
|
||||
* with DohEncoder().
|
||||
*
|
||||
* Note: This function is not particularly memory efficient with large strings.
|
||||
* It's better to use Dump() or some other method instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
|
|
@ -357,8 +369,14 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
return nbytes;
|
||||
}
|
||||
|
||||
/* Printf */
|
||||
int DohPrintf(DOH *obj, char *format, ...) {
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohPrintf()
|
||||
*
|
||||
* Variable length argument entry point to Printf
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
DohPrintf(DOH *obj, char *format, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_start(ap,format);
|
||||
|
|
@ -367,9 +385,15 @@ int DohPrintf(DOH *obj, char *format, ...) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* DohCopyto(DOH *in, DOH *out) */
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohCopyto()
|
||||
*
|
||||
* Copies all of the input from an input stream to an output stream. Returns the
|
||||
* number of bytes copied.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int DohCopyto(DOH *in, DOH *out) {
|
||||
int
|
||||
DohCopyto(DOH *in, DOH *out) {
|
||||
int nbytes = 0, ret;
|
||||
int nwrite = 0, wret;
|
||||
char *cw;
|
||||
|
|
@ -394,9 +418,16 @@ int DohCopyto(DOH *in, DOH *out) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Split by a character */
|
||||
|
||||
DOH *DohSplit(DOH *in, char *chs, int nsplits) {
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohSplit()
|
||||
*
|
||||
* Split an input stream into a list of strings delimeted by characters in a
|
||||
* string. Optionally accepts a maximum number of splits to perform.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohSplit(DOH *in, char *chs, int nsplits) {
|
||||
DOH *list;
|
||||
DOH *str;
|
||||
int c;
|
||||
|
|
@ -425,9 +456,14 @@ DOH *DohSplit(DOH *in, char *chs, int nsplits) {
|
|||
return list;
|
||||
}
|
||||
|
||||
/* Read a single line of text */
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohReadline()
|
||||
*
|
||||
* Read a single input line and return it as a string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *DohReadline(DOH *in) {
|
||||
DOH *
|
||||
DohReadline(DOH *in) {
|
||||
char c;
|
||||
int n = 0;
|
||||
DOH *s = NewString("");
|
||||
|
|
|
|||
|
|
@ -1,25 +1,15 @@
|
|||
/****************************************************************************
|
||||
* DOH
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/***********************************************************************
|
||||
/* -----------------------------------------------------------------------------
|
||||
* hash.c
|
||||
*
|
||||
* Hash table implementation.
|
||||
***********************************************************************/
|
||||
* Implements a simple hash table object.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -40,12 +30,7 @@ typedef struct Hash {
|
|||
HashNode *current;
|
||||
} Hash;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
Key interning. This is used for getattr,setattr functions.
|
||||
|
||||
The following structure maps raw char * entries to string objects.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
/* Key interning structure */
|
||||
typedef struct KeyValue {
|
||||
char *cstr;
|
||||
DOH *sstr;
|
||||
|
|
@ -55,6 +40,7 @@ typedef struct KeyValue {
|
|||
|
||||
static KeyValue *root = 0;
|
||||
|
||||
/* Find or create a key in the interned key table */
|
||||
static DOH *find_key(char *c) {
|
||||
KeyValue *r, *s;
|
||||
int d = 0;
|
||||
|
|
@ -85,8 +71,8 @@ static DOH *find_key(char *c) {
|
|||
|
||||
#define HASH_INIT_SIZE 7
|
||||
|
||||
static HashNode *NewNode(DOH *k, void *obj)
|
||||
{
|
||||
/* Create a new hash node */
|
||||
static HashNode *NewNode(DOH *k, void *obj) {
|
||||
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
|
||||
hn->key = k;
|
||||
Incref(hn->key);
|
||||
|
|
@ -96,22 +82,21 @@ static HashNode *NewNode(DOH *k, void *obj)
|
|||
return hn;
|
||||
}
|
||||
|
||||
static void DelNode(HashNode *hn)
|
||||
{
|
||||
/* Delete a hash node */
|
||||
static void DelNode(HashNode *hn) {
|
||||
Delete(hn->key);
|
||||
Delete(hn->object);
|
||||
DohFree(hn);
|
||||
}
|
||||
|
||||
int Hash_check(DOH *);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DelHash() - Delete a hash table
|
||||
* DelHash()
|
||||
*
|
||||
* Delete a hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
DelHash(DOH *ho)
|
||||
{
|
||||
DelHash(DOH *ho) {
|
||||
Hash *h;
|
||||
HashNode *n,*next;
|
||||
int i;
|
||||
|
|
@ -134,12 +119,13 @@ DelHash(DOH *ho)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_clear(DOH *ho) - Clear all entries in a hash table
|
||||
* Hash_clear()
|
||||
*
|
||||
* Clear all of the entries in the hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Hash_clear(DOH *ho)
|
||||
{
|
||||
Hash_clear(DOH *ho) {
|
||||
Hash *h;
|
||||
HashNode *n,*next;
|
||||
int i;
|
||||
|
|
@ -159,12 +145,13 @@ Hash_clear(DOH *ho)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_scope(DOH *ho, int s) - Clear all entries in a hash table
|
||||
* Hash_scope()
|
||||
*
|
||||
* Change the scope of the hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Hash_scope(DOH *ho, int s)
|
||||
{
|
||||
Hash_scope(DOH *ho, int s) {
|
||||
Hash *h;
|
||||
HashNode *n;
|
||||
int i;
|
||||
|
|
@ -184,10 +171,7 @@ Hash_scope(DOH *ho, int s)
|
|||
h->flags = h->flags & ~DOH_FLAG_SETSCOPE;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* static resize(Hash *h) - Resizes the hash table
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* resize the hash table */
|
||||
static void resize(Hash *h) {
|
||||
HashNode *n, *next, **table;
|
||||
int oldsize, newsize;
|
||||
|
|
@ -233,7 +217,10 @@ static void resize(Hash *h) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int Hash_setattr(DOH *h, DOH *k, DOH *obj) - Adds an object to a hash
|
||||
* Hash_setattr()
|
||||
*
|
||||
* Set an attribute in the hash table. Deletes the existing entry if it already
|
||||
* exists.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
|
|
@ -280,7 +267,9 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Hash_getattr(DOH *ho, DOH *k) - Get an item from the hash table
|
||||
* Hash_getattr()
|
||||
*
|
||||
* Get an attribute from the hash table. Returns 0 if it doesn't exist.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
|
|
@ -301,12 +290,13 @@ Hash_getattr(DOH *ho, DOH *k) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Hash_delattr(DOH *ho, DOH *k) - Delete an element from the table
|
||||
* Hash_delattr()
|
||||
*
|
||||
* Delete an object from the hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
Hash_delattr(DOH *ho, DOH *k)
|
||||
{
|
||||
Hash_delattr(DOH *ho, DOH *k) {
|
||||
HashNode *n, *prev;
|
||||
int hv;
|
||||
Hash *h;
|
||||
|
|
@ -334,10 +324,7 @@ Hash_delattr(DOH *ho, DOH *k)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Iterators
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* General purpose iterators */
|
||||
static HashNode *
|
||||
hash_first(DOH *ho) {
|
||||
Hash *h = (Hash *) ho;
|
||||
|
|
@ -367,41 +354,39 @@ hash_next(DOH *ho) {
|
|||
h->current = h->hashtable[h->currentindex];
|
||||
return h->current;
|
||||
}
|
||||
|
||||
static DOH *
|
||||
Hash_first(DOH *ho) {
|
||||
HashNode *hn = hash_first(ho);
|
||||
if (hn) return hn->object;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_firstkey()
|
||||
*
|
||||
* Return first hash-table key.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Hash_next(DOH *ho)
|
||||
{
|
||||
HashNode *hn = hash_next(ho);
|
||||
if (hn) return hn->object;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DOH *
|
||||
Hash_firstkey(DOH *ho)
|
||||
{
|
||||
Hash_firstkey(DOH *ho) {
|
||||
HashNode *hn = hash_first(ho);
|
||||
if (hn) return hn->key;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_nextkey()
|
||||
*
|
||||
* Return next hash table key.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Hash_nextkey(DOH *ho)
|
||||
{
|
||||
Hash_nextkey(DOH *ho) {
|
||||
HashNode *hn = hash_next(ho);
|
||||
if (hn) return hn->key;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* String *Hash_str(DOH *ho) - Create a string representation of a hash
|
||||
* Hash_str()
|
||||
*
|
||||
* Create a string representation of a hash table (mainly for debugging).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Hash_str(DOH *ho) {
|
||||
int i;
|
||||
|
|
@ -430,7 +415,9 @@ Hash_str(DOH *ho) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_len(DOH *)
|
||||
* Hash_len()
|
||||
*
|
||||
* Return number of entries in the hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
|
|
@ -444,7 +431,6 @@ Hash_len(DOH *ho) {
|
|||
*
|
||||
* Return a list of keys
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Hash_keys(DOH *so) {
|
||||
DOH *keys;
|
||||
|
|
@ -461,7 +447,9 @@ Hash_keys(DOH *so) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *CopyHash(DOH *ho) - Copy a hash table
|
||||
* CopyHash()
|
||||
*
|
||||
* Make a copy of a hash table. Note: this is a shallow copy.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
|
|
@ -471,6 +459,7 @@ CopyHash(DOH *ho) {
|
|||
int i;
|
||||
h = (Hash *) ho;
|
||||
nh = (Hash *) DohObjMalloc(sizeof(Hash));
|
||||
nh->objinfo = h->objinfo;
|
||||
DohXInit(h);
|
||||
nh->hashsize = h->hashsize;
|
||||
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
|
||||
|
|
@ -480,7 +469,6 @@ CopyHash(DOH *ho) {
|
|||
nh->currentindex = -1;
|
||||
nh->current = 0;
|
||||
nh->nitems = 0;
|
||||
nh->objinfo = h->objinfo;
|
||||
nh->line = h->line;
|
||||
nh->file = h->file;
|
||||
if (nh->file) Incref(nh->file);
|
||||
|
|
@ -508,13 +496,6 @@ static DohMappingMethods HashMappingMethods = {
|
|||
Hash_nextkey,
|
||||
};
|
||||
|
||||
static DohPositionalMethods HashPositionalMethods = {
|
||||
XBase_setfile,
|
||||
XBase_getfile,
|
||||
XBase_setline,
|
||||
XBase_getline
|
||||
};
|
||||
|
||||
static DohObjInfo HashType = {
|
||||
"Hash", /* objname */
|
||||
sizeof(Hash), /* size */
|
||||
|
|
@ -534,10 +515,17 @@ static DohObjInfo HashType = {
|
|||
0, /* doh_file */
|
||||
0, /* doh_string */
|
||||
0, /* doh_callable */
|
||||
&HashPositionalMethods, /* doh_positional */
|
||||
0, /* doh_positional */
|
||||
};
|
||||
|
||||
int Hash_check(DOH *so) {
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_check()
|
||||
*
|
||||
* Return 1 if an object is a hash table object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Hash_check(DOH *so) {
|
||||
Hash *h = (Hash *) so;
|
||||
if (!h) return 0;
|
||||
if (!DohCheck(so)) return 0;
|
||||
|
|
@ -546,13 +534,17 @@ int Hash_check(DOH *so) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewHash() - Create a new hash table
|
||||
* NewHash()
|
||||
*
|
||||
* Create a new hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *NewHash() {
|
||||
DOH *
|
||||
NewHash() {
|
||||
Hash *h;
|
||||
int i;
|
||||
h = (Hash *) DohObjMalloc(sizeof(Hash));
|
||||
h->objinfo = &HashType;
|
||||
DohXInit(h);
|
||||
h->hashsize = HASH_INIT_SIZE;
|
||||
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
|
||||
|
|
@ -562,8 +554,9 @@ DOH *NewHash() {
|
|||
h->currentindex = -1;
|
||||
h->current = 0;
|
||||
h->nitems = 0;
|
||||
h->objinfo = &HashType;
|
||||
return (DOH *) h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,16 @@
|
|||
/****************************************************************************
|
||||
* DOH
|
||||
/* -----------------------------------------------------------------------------
|
||||
* list.c
|
||||
*
|
||||
* Implements a simple list object.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/*******************************************************************************
|
||||
* File : list.c
|
||||
*
|
||||
* General purpose structure for keeping a list of reference counted Swig objects.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
typedef struct List {
|
||||
|
|
@ -31,9 +21,7 @@ typedef struct List {
|
|||
DOH **items;
|
||||
} List;
|
||||
|
||||
int List_check(DOH *);
|
||||
|
||||
/* Internal function. Doubles amount of memory in a list */
|
||||
/* Doubles amount of memory in a list */
|
||||
static
|
||||
void more(List *l) {
|
||||
int i;
|
||||
|
|
@ -52,7 +40,9 @@ void more(List *l) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *CopyList(DOH *l) - Copy a list
|
||||
* CopyList()
|
||||
*
|
||||
* Make a shallow copy of a list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
|
|
@ -61,8 +51,8 @@ CopyList(DOH *lo) {
|
|||
int i;
|
||||
l = (List *) lo;
|
||||
nl = (List *) DohObjMalloc(sizeof(List));
|
||||
DohXInit(nl);
|
||||
nl->objinfo = l->objinfo;
|
||||
DohXInit(nl);
|
||||
nl->nitems = l->nitems;
|
||||
nl->maxitems = l->maxitems;
|
||||
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||
|
|
@ -80,7 +70,9 @@ CopyList(DOH *lo) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void DelList(DOH *l) - Delete a list
|
||||
* DelList()
|
||||
*
|
||||
* Delete a list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
|
|
@ -99,7 +91,9 @@ DelList(DOH *lo) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void List_clear(DOH *l) - Clear all elements in the list
|
||||
* List_clear()
|
||||
*
|
||||
* Remove all of the list entries, but keep the list object intact.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
|
|
@ -115,8 +109,11 @@ List_clear(DOH *lo) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void List_scope(DOH *lo, int s)
|
||||
* List_scope()
|
||||
*
|
||||
* Change the scope setting of the list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
List_scope(DOH *lo, int s) {
|
||||
List *l;
|
||||
|
|
@ -132,18 +129,19 @@ List_scope(DOH *lo, int s) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void List_insert(DOH *lo, int pos, DOH *item) - Insert an element
|
||||
* List_insert()
|
||||
*
|
||||
* Insert an item into the list. If the item is not a DOH object, it is assumed
|
||||
* to be a 'char *' and is used to construct an equivalent string object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
List_insert(DOH *lo, int pos, DOH *item)
|
||||
{
|
||||
List_insert(DOH *lo, int pos, DOH *item) {
|
||||
List *l;
|
||||
DohBase *b;
|
||||
int i, no = 0;
|
||||
|
||||
if (!item) return -1;
|
||||
|
||||
l = (List *) lo;
|
||||
|
||||
if (!DohCheck(item)) {
|
||||
|
|
@ -168,12 +166,13 @@ List_insert(DOH *lo, int pos, DOH *item)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void List_remove(DOH *lo, int pos) - Remove an element
|
||||
* List_remove()
|
||||
*
|
||||
* Remove an item from a list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
List_remove(DOH *lo, int pos)
|
||||
{
|
||||
List_remove(DOH *lo, int pos) {
|
||||
List *l;
|
||||
DOH *item;
|
||||
int i;
|
||||
|
|
@ -192,22 +191,24 @@ List_remove(DOH *lo, int pos)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int List_len(DOH *l) - List length
|
||||
* List_len()
|
||||
*
|
||||
* Return the number of elements in the list
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
List_len(DOH *lo)
|
||||
{
|
||||
List_len(DOH *lo) {
|
||||
return ((List *) lo)->nitems;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *List_get(DOH *lo, int n) - Get an item
|
||||
* List_get()
|
||||
*
|
||||
* Get the nth item from the list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
List_get(DOH *lo, int n)
|
||||
{
|
||||
List_get(DOH *lo, int n) {
|
||||
List *l;
|
||||
l = (List *) lo;
|
||||
if (n == DOH_END) n = l->nitems-1;
|
||||
|
|
@ -219,12 +220,13 @@ List_get(DOH *lo, int n)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int List_set(DOH *lo, int n, DOH *val) - Set an item
|
||||
* List_set()
|
||||
*
|
||||
* Set the nth item in the list replacing any previous item.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
List_set(DOH *lo, int n, DOH *val)
|
||||
{
|
||||
List_set(DOH *lo, int n, DOH *val) {
|
||||
List *l;
|
||||
int no = 0;
|
||||
l = (List *) lo;
|
||||
|
|
@ -246,12 +248,13 @@ List_set(DOH *lo, int n, DOH *val)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Iterators
|
||||
* List_first()
|
||||
*
|
||||
* Return the first item in the list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
List_first(DOH *lo)
|
||||
{
|
||||
List_first(DOH *lo) {
|
||||
List *l;
|
||||
l = (List *) lo;
|
||||
l->iter = 0;
|
||||
|
|
@ -259,9 +262,14 @@ List_first(DOH *lo)
|
|||
return l->items[l->iter];
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List_next()
|
||||
*
|
||||
* Return the next item in the list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
List_next(DOH *lo)
|
||||
{
|
||||
List_next(DOH *lo) {
|
||||
List *l;
|
||||
l = (List *) lo;
|
||||
l->iter++;
|
||||
|
|
@ -270,12 +278,12 @@ List_next(DOH *lo)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* String *List_str() - Create a string representation
|
||||
* List_str()
|
||||
*
|
||||
* Create a string representation of the list
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
List_str(DOH *lo)
|
||||
{
|
||||
List_str(DOH *lo) {
|
||||
DOH *s;
|
||||
int i;
|
||||
|
||||
|
|
@ -297,6 +305,12 @@ List_str(DOH *lo)
|
|||
return s;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List_dump()
|
||||
*
|
||||
* Dump the items to an output stream.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
List_dump(DOH *lo, DOH *out) {
|
||||
int nsent = 0;
|
||||
|
|
@ -310,26 +324,6 @@ List_dump(DOH *lo, DOH *out) {
|
|||
return nsent;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void List_sort(DOH *DOH)
|
||||
*
|
||||
* Sorts a list
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int objcmp(const void *s1, const void *s2) {
|
||||
DOH **so1, **so2;
|
||||
so1 = (DOH **) s1;
|
||||
so2 = (DOH **) s2;
|
||||
return Cmp(*so1,*so2);
|
||||
}
|
||||
|
||||
void List_sort(DOH *so) {
|
||||
List *l;
|
||||
if (!List_check(so)) return;
|
||||
l = (List *) so;
|
||||
qsort(l->items,l->nitems,sizeof(DOH *), objcmp);
|
||||
}
|
||||
|
||||
#define MAXLISTITEMS 8
|
||||
|
||||
static DohSequenceMethods ListSeqMethods = {
|
||||
|
|
@ -341,13 +335,6 @@ static DohSequenceMethods ListSeqMethods = {
|
|||
List_next,
|
||||
};
|
||||
|
||||
static DohPositionalMethods ListPositionalMethods = {
|
||||
XBase_setfile,
|
||||
XBase_getfile,
|
||||
XBase_setline,
|
||||
XBase_getline
|
||||
};
|
||||
|
||||
static DohObjInfo ListType = {
|
||||
"List", /* objname */
|
||||
sizeof(List), /* List size */
|
||||
|
|
@ -367,13 +354,14 @@ static DohObjInfo ListType = {
|
|||
0, /* doh_file */
|
||||
0, /* doh_string */
|
||||
0, /* doh_callable */
|
||||
&ListPositionalMethods, /* doh_position */
|
||||
0, /* doh_position */
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List_check(DOH *lo) - Check to see if an object is a list
|
||||
* List_check()
|
||||
*
|
||||
* Return 1 if an object is a List object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
List_check(DOH *lo) {
|
||||
List *l = (List *) lo;
|
||||
|
|
@ -384,7 +372,9 @@ List_check(DOH *lo) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewList() - Create a new list
|
||||
* NewList()
|
||||
*
|
||||
* Create a new list.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
|
|
@ -392,8 +382,8 @@ NewList() {
|
|||
List *l;
|
||||
int i;
|
||||
l = (List *) DohObjMalloc(sizeof(List));
|
||||
DohXInit(l);
|
||||
l->objinfo = &ListType;
|
||||
DohXInit(l);
|
||||
l->nitems = 0;
|
||||
l->maxitems = MAXLISTITEMS;
|
||||
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||
|
|
@ -403,3 +393,24 @@ NewList() {
|
|||
l->iter = 0;
|
||||
return (DOH *) l;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List_sort()
|
||||
*
|
||||
* Sorts a list
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int objcmp(const void *s1, const void *s2) {
|
||||
DOH **so1, **so2;
|
||||
so1 = (DOH **) s1;
|
||||
so2 = (DOH **) s2;
|
||||
return Cmp(*so1,*so2);
|
||||
}
|
||||
|
||||
void
|
||||
List_sort(DOH *so) {
|
||||
List *l;
|
||||
if (!List_check(so)) return;
|
||||
l = (List *) so;
|
||||
qsort(l->items,l->nitems,sizeof(DOH *), objcmp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* memory.c
|
||||
*
|
||||
* This file implements all of DOH's memory management including allocation
|
||||
* of objects, checking of objects, and garbage collection.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
|
|
@ -33,14 +30,7 @@ static int _DohMemoryCurrent = 0;
|
|||
static int _DohMemoryHigh = 0;
|
||||
static int _PoolSize = DOH_POOL_SIZE;
|
||||
|
||||
DOH *DohNone = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* memory.c
|
||||
*
|
||||
* Doh memory manager. Keeps pools of memory around for allocating objects.
|
||||
* Pools are used to determine if an object is really a Doh object or not.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
DOH *DohNone = 0; /* The DOH None object */
|
||||
|
||||
typedef struct fragment {
|
||||
char *ptr; /* Pointer to fragment */
|
||||
|
|
@ -64,13 +54,13 @@ static int nscopes = 0;
|
|||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Pool *CreatePool(int size)
|
||||
* CreatePool()
|
||||
*
|
||||
* Create a new pool
|
||||
* Create a new memory pool
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
Pool *CreatePool(int size)
|
||||
{
|
||||
static Pool *
|
||||
CreatePool(int size) {
|
||||
Pool *p = 0;
|
||||
char *c;
|
||||
c = (char *) DohMalloc(size);
|
||||
|
|
@ -85,12 +75,13 @@ Pool *CreatePool(int size)
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void InitPools()
|
||||
* InitPools()
|
||||
*
|
||||
* Initialize the memory allocator
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
static void InitPools() {
|
||||
static void
|
||||
InitPools() {
|
||||
int i;
|
||||
if (pools_initialized) return;
|
||||
for (i = 0; i < DOH_MAX_FRAG; i++) {
|
||||
|
|
@ -107,12 +98,14 @@ static void InitPools() {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* int DohCheck(DOH *ptr)
|
||||
* DohCheck()
|
||||
*
|
||||
* Check if ptr is an object we created.
|
||||
* Returns 1 if an arbitrary pointer is a DOH object. This determination
|
||||
* is made according to the pointer value only.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
int DohCheck(DOH *ptr) {
|
||||
int
|
||||
DohCheck(DOH *ptr) {
|
||||
Pool *p = Pools;
|
||||
char *cptr = (char *) ptr;
|
||||
while (p) {
|
||||
|
|
@ -123,12 +116,14 @@ int DohCheck(DOH *ptr) {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* int DohObjFreeCheck(DOH *ptr)
|
||||
* DohObjFreeCheck()
|
||||
*
|
||||
* Check if ptr is an object that has been deleted.
|
||||
* Checks to see if an object was already deleted. Useful when tracking
|
||||
* down nasty double-free problems.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
int DohObjFreeCheck(DOH *ptr) {
|
||||
int
|
||||
DohObjFreeCheck(DOH *ptr) {
|
||||
int i;
|
||||
Fragment *f;
|
||||
char *cptr = (char *) ptr;
|
||||
|
|
@ -143,12 +138,13 @@ int DohObjFreeCheck(DOH *ptr) {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* int DohNewScope()
|
||||
* DohNewScope()
|
||||
*
|
||||
* Create a new scope in which objects will be placed
|
||||
* Create a new scope in which objects will be placed. Returns a scope
|
||||
* identifier.
|
||||
* ---------------------------------------------------------------------- */
|
||||
int DohNewScope()
|
||||
{
|
||||
int
|
||||
DohNewScope() {
|
||||
assert(nscopes < DOH_MAX_SCOPES);
|
||||
if (!pools_initialized) InitPools();
|
||||
scopes[nscopes] = 0;
|
||||
|
|
@ -157,11 +153,13 @@ int DohNewScope()
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void DohDelScope(int s) - Delete scope s
|
||||
* DohDelScope()
|
||||
*
|
||||
* Deletes a scope.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
void DohDelScope(int s)
|
||||
{
|
||||
void
|
||||
DohDelScope(int s) {
|
||||
int ns;
|
||||
DohBase *b, *b1;
|
||||
ns = s;
|
||||
|
|
@ -193,9 +191,14 @@ void DohDelScope(int s)
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void real_objfree(DOH *ptr) - Free a DOH object for real.
|
||||
* real_objfree()
|
||||
*
|
||||
* This is the function that actually frees an object. Invoked by the
|
||||
* garbage collector.
|
||||
* ---------------------------------------------------------------------- */
|
||||
static void real_objfree(DOH *ptr) {
|
||||
|
||||
static void
|
||||
real_objfree(DOH *ptr) {
|
||||
DohBase *b;
|
||||
Fragment *f;
|
||||
b = (DohBase *) ptr;
|
||||
|
|
@ -213,7 +216,7 @@ static void real_objfree(DOH *ptr) {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void DohGarbageCollect()
|
||||
* DohGarbageCollect()
|
||||
*
|
||||
* This walks through all of the scopes and does garbage collection.
|
||||
*
|
||||
|
|
@ -259,12 +262,13 @@ DohGarbageCollect() {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void *DohObjMalloc(size_t size)
|
||||
* DohObjMalloc()
|
||||
*
|
||||
* Allocate an object
|
||||
* Allocate memory for a new object.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
void *DohObjMalloc(size_t size) {
|
||||
void *
|
||||
DohObjMalloc(size_t size) {
|
||||
Pool *p;
|
||||
Fragment *f;
|
||||
void *ptr = 0;
|
||||
|
|
@ -329,14 +333,14 @@ void *DohObjMalloc(size_t size) {
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* void DohObjFree(DOH *ptr)
|
||||
* DohObjFree()
|
||||
*
|
||||
* Free a DOH object. This function doesn't do much of anything with GC.
|
||||
* Frees a DOH object. Doesn't do much with GC.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
void DohObjFree(DOH *ptr) {
|
||||
void
|
||||
DohObjFree(DOH *ptr) {
|
||||
DohBase *b;
|
||||
|
||||
if (!DohCheck(ptr)) {
|
||||
DohTrace(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr);
|
||||
return; /* Oh well. Guess we're leaky */
|
||||
|
|
@ -349,71 +353,46 @@ void DohObjFree(DOH *ptr) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void *DohMalloc(size_t nbytes)
|
||||
* DohMalloc()
|
||||
*
|
||||
* Wrapper around malloc() function. Records memory usage.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void *DohMalloc(size_t nbytes) {
|
||||
char *ptr;
|
||||
ptr = (char *) malloc(nbytes+8);
|
||||
if (!ptr) return 0;
|
||||
_DohMemoryCurrent += (nbytes+8);
|
||||
if (_DohMemoryCurrent > _DohMemoryHigh) _DohMemoryHigh = _DohMemoryCurrent;
|
||||
*((int *) ptr) = nbytes;
|
||||
return (void *) (ptr+8);
|
||||
void *
|
||||
DohMalloc(size_t nbytes) {
|
||||
return (void *) malloc(nbytes);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void *DohRealloc(void *ptr, size_t newsize)
|
||||
* DohRealloc()
|
||||
*
|
||||
* Wrapper around realloc() function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void *DohRealloc(void *ptr, size_t newsize) {
|
||||
char *cptr = (char *) ptr;
|
||||
char *nptr;
|
||||
int size;
|
||||
|
||||
size = *((int *) (cptr - 8));
|
||||
nptr = (char *) realloc(cptr-8,newsize+8);
|
||||
if (!nptr) return 0;
|
||||
*((int *) nptr) = newsize;
|
||||
_DohMemoryCurrent += (newsize - size);
|
||||
if (_DohMemoryCurrent > _DohMemoryHigh) _DohMemoryHigh = _DohMemoryCurrent;
|
||||
return (void *) (nptr+8);
|
||||
void *
|
||||
DohRealloc(void *ptr, size_t newsize) {
|
||||
return (void *) realloc(ptr,newsize);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void DohFree(void *ptr)
|
||||
* DohFree()
|
||||
*
|
||||
* Wrapper around free() function. Records memory usage.
|
||||
* Wrapper around free() function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void DohFree(void *ptr) {
|
||||
char *cptr = (char *) ptr;
|
||||
int size;
|
||||
if (!ptr) return;
|
||||
size = *((int *) (cptr - 8));
|
||||
free(cptr-8);
|
||||
_DohMemoryCurrent = _DohMemoryCurrent - (size+8);
|
||||
void
|
||||
DohFree(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int DohMemoryUse()
|
||||
* DohPoolSize()
|
||||
*
|
||||
* Return bytes currently in use by Doh
|
||||
* Change the size of the memory pools used by DOH
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int DohMemoryUse() {
|
||||
return _DohMemoryCurrent;
|
||||
}
|
||||
|
||||
int DohMemoryHigh() {
|
||||
return _DohMemoryHigh;
|
||||
}
|
||||
|
||||
int DohPoolSize(int poolsize) {
|
||||
int
|
||||
DohPoolSize(int poolsize) {
|
||||
int ps;
|
||||
ps = _PoolSize;
|
||||
if (poolsize > 0) {
|
||||
|
|
|
|||
|
|
@ -1,25 +1,16 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* string.c
|
||||
*
|
||||
* String object.
|
||||
* --------------------------------------------------------------------------- */
|
||||
* Implements a string object that supports both sequence operations and
|
||||
* file semantics.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -69,13 +60,6 @@ static DohSequenceMethods StringSeqMethods = {
|
|||
0, /* doh_next */
|
||||
};
|
||||
|
||||
static DohPositionalMethods StringPositionalMethods = {
|
||||
XBase_setfile,
|
||||
XBase_getfile,
|
||||
XBase_setline,
|
||||
XBase_getline
|
||||
};
|
||||
|
||||
static DohFileMethods StringFileMethods = {
|
||||
String_read,
|
||||
String_write,
|
||||
|
|
@ -111,7 +95,7 @@ static DohObjInfo StringType = {
|
|||
&StringFileMethods,/* doh_file */
|
||||
&StringStringMethods, /* doh_string */
|
||||
0, /* doh_callable */
|
||||
&StringPositionalMethods, /* doh_position */
|
||||
0, /* doh_position */
|
||||
};
|
||||
|
||||
#define INIT_MAXSIZE 16
|
||||
|
|
@ -160,6 +144,7 @@ NewString(char *s)
|
|||
String *str;
|
||||
str = (String *) DohObjMalloc(sizeof(String));
|
||||
str->objinfo = &StringType;
|
||||
DohXInit(str);
|
||||
str->hashkey = -1;
|
||||
str->sp = 0;
|
||||
str->lsp = 0;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,17 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void.c
|
||||
*
|
||||
* Void Object
|
||||
* Implements a "void" object that is really just a DOH container around
|
||||
* an arbitrary C/C++ object represented as a void *.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -30,9 +20,46 @@ typedef struct {
|
|||
void (*del)(void *);
|
||||
} VoidObj;
|
||||
|
||||
void Void_delete(DOH *);
|
||||
DOH *Void_copy(DOH *);
|
||||
void *Void_data(DOH *);
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void_delete()
|
||||
*
|
||||
* Delete a void object. Invokes the destructor supplied at the time of creation.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Void_delete(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
if (v->del) {
|
||||
(*v->del)(v->ptr);
|
||||
}
|
||||
v->del = 0;
|
||||
DohObjFree(v);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void_copy()
|
||||
*
|
||||
* Copies a void object. This is only a shallow copy. The object destruction
|
||||
* function is not copied in order to avoid potential double-free problems.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Void_copy(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return NewVoid(v->ptr,0);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void_data()
|
||||
*
|
||||
* Returns the void * stored in the object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
Void_data(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return v->ptr;
|
||||
}
|
||||
|
||||
static DohObjInfo DohVoidType = {
|
||||
"VoidObj", /* objname */
|
||||
|
|
@ -63,7 +90,15 @@ static DohObjInfo DohVoidType = {
|
|||
};
|
||||
|
||||
|
||||
DOH *NewVoid(void *obj, void (*del)(void *)) {
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewVoid()
|
||||
*
|
||||
* Creates a new Void object given a void * and a pointer to an optional
|
||||
* destruction function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewVoid(void *obj, void (*del)(void *)) {
|
||||
VoidObj *v;
|
||||
v = (VoidObj *) DohObjMalloc(sizeof(VoidObj));
|
||||
v->objinfo = &DohVoidType;
|
||||
|
|
@ -71,23 +106,3 @@ DOH *NewVoid(void *obj, void (*del)(void *)) {
|
|||
v->del = del;
|
||||
return (DOH *) v;
|
||||
}
|
||||
|
||||
void Void_delete(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
if (v->del) {
|
||||
(*v->del)(v->ptr);
|
||||
}
|
||||
v->del = 0;
|
||||
DohObjFree(v);
|
||||
}
|
||||
|
||||
DOH *Void_copy(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return NewVoid(v->ptr,0);
|
||||
}
|
||||
|
||||
void *Void_data(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return v->ptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,15 @@
|
|||
/*******************************************************************************
|
||||
* DOH (Dave's Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which DOH
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* $Header$
|
||||
*
|
||||
/* -----------------------------------------------------------------------------
|
||||
* doh.h
|
||||
*
|
||||
* DOH is really not much more than an interface. This file describes
|
||||
* the interface.
|
||||
***********************************************************************/
|
||||
* This file describes of the externally visible functions in DOH.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _DOH_H
|
||||
#define _DOH_H
|
||||
|
|
@ -151,8 +140,6 @@ typedef struct DohObjInfo {
|
|||
extern void DohInit(DOH *obj); /* Initialize an object */
|
||||
extern void DohXInit(DOH *obj); /* Initialize extended object */
|
||||
extern int DohCheck(DOH *ptr); /* Check if a DOH object */
|
||||
extern int DohMemoryUse(); /* Return current memory */
|
||||
extern int DohMemoryHigh(); /* High memory use */
|
||||
extern int DohPoolSize(int); /* Set memory alloc size */
|
||||
extern int DohNewScope(); /* Create a new scope */
|
||||
extern void DohDelScope(int); /* Delete a scope */
|
||||
|
|
|
|||
|
|
@ -6,8 +6,3 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
#include "doh.h"
|
||||
|
||||
extern void XBase_setfile(DOH *, DOH *);
|
||||
extern DOH *XBase_getfile(DOH *);
|
||||
extern void XBase_setline(DOH *, int);
|
||||
extern int XBase_getline(DOH *);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,16 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* cscanner.c
|
||||
*
|
||||
* C Scanner that is roughly compatible with the SWIG1.1 scanner.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* $Header$
|
||||
*
|
||||
* scanner.c
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "lparse.h"
|
||||
|
||||
#define yylval lparse_yylval
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* lparse.h
|
||||
*
|
||||
* Lame tag-based parsed based on the SWIG1.1 parser.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _LPARSE_H
|
||||
#define _LPARSE_H
|
||||
|
|
@ -22,7 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
extern void LParse_push(DOH *);
|
||||
extern DOH *LParse_skip_balanced(int, int);
|
||||
extern void LParse_skip_semi();
|
||||
|
|
|
|||
|
|
@ -1,25 +1,14 @@
|
|||
%{
|
||||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
/***********************************************************************
|
||||
* $Header$
|
||||
*
|
||||
/* -----------------------------------------------------------------------------
|
||||
* parser.y
|
||||
*
|
||||
* YACC parser for parsing function declarations.
|
||||
***********************************************************************/
|
||||
* YACC grammar for Dave's lame parser.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define yylex lparse_yylex
|
||||
#define yyerror lparse_yyerror
|
||||
|
|
@ -597,7 +586,7 @@ tm_parm : type tm_name {
|
|||
$$ = NewHash();
|
||||
if ($2.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($2.array));
|
||||
$1->arraystr = Swig_copy_string(Char($2.array));
|
||||
}
|
||||
Setattr($$,"type",$1);
|
||||
if ($2.name)
|
||||
|
|
@ -610,7 +599,7 @@ tm_parm : type tm_name {
|
|||
$1->is_pointer += $2.ivalue;
|
||||
if ($3.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($3.array));
|
||||
$1->arraystr = Swig_copy_string(Char($3.array));
|
||||
}
|
||||
Setattr($$,"type",$1);
|
||||
if ($3.name)
|
||||
|
|
@ -624,7 +613,7 @@ tm_parm : type tm_name {
|
|||
$1->is_pointer++;
|
||||
if ($3.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($3.array));
|
||||
$1->arraystr = Swig_copy_string(Char($3.array));
|
||||
}
|
||||
Setattr($$,"type",$1);
|
||||
if ($3.name)
|
||||
|
|
@ -750,7 +739,7 @@ variable_decl : extern_spec type declaration array2 def_args {
|
|||
$2->is_pointer += $3.is_pointer;
|
||||
if ($4.text) {
|
||||
$2->is_pointer++;
|
||||
$2->arraystr = copy_string(Char($4.text));
|
||||
$2->arraystr = Swig_copy_string(Char($4.text));
|
||||
}
|
||||
$2->is_reference = $3.is_reference;
|
||||
o = new_node("Variable", Getfile($3.id),Getline($3.id));
|
||||
|
|
@ -860,7 +849,7 @@ stail : SEMI { }
|
|||
t->is_pointer += $2.is_pointer;
|
||||
if ($3.text) {
|
||||
t->is_pointer++;
|
||||
t->arraystr = copy_string(Char($3.text));
|
||||
t->arraystr = Swig_copy_string(Char($3.text));
|
||||
}
|
||||
t->is_reference = $2.is_reference;
|
||||
o = new_node("Variable", Getfile($2.id),Getline($2.id));
|
||||
|
|
@ -1021,7 +1010,7 @@ typedef_decl : TYPEDEF type declaration {
|
|||
Active_typedef = (LParseType *) Copy($2);
|
||||
$2->is_pointer += $3.is_pointer;
|
||||
$2->is_pointer++;
|
||||
$2->arraystr = copy_string(Char($4.text));
|
||||
$2->arraystr = Swig_copy_string(Char($4.text));
|
||||
LParse_typedef_add($2,$3.id);
|
||||
o = new_node("Typedef", $1.filename, $1.line);
|
||||
Setattr(o,"name", $3.id);
|
||||
|
|
@ -1046,7 +1035,7 @@ typedeflist : COMMA declaration typedeflist {
|
|||
LParseType *t;
|
||||
t = (LParseType *) Copy(Active_typedef);
|
||||
t->is_pointer += $2.is_pointer + 1;
|
||||
t->arraystr = copy_string(Char($3.text));
|
||||
t->arraystr = Swig_copy_string(Char($3.text));
|
||||
LParse_typedef_add(t,$2.id);
|
||||
o = new_node("Typedef", Getfile($2.id), Getline($2.id));
|
||||
Setattr(o,"name", $2.id);
|
||||
|
|
@ -1322,7 +1311,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
|
|||
$1->is_pointer += $2.is_pointer;
|
||||
$1->is_reference = $2.is_reference;
|
||||
if ($3.text) {
|
||||
$1->arraystr = copy_string(Char($3.text));
|
||||
$1->arraystr = Swig_copy_string(Char($3.text));
|
||||
$1->is_pointer++;
|
||||
}
|
||||
Setattr(o,"name",$2.id);
|
||||
|
|
@ -1498,7 +1487,7 @@ cpp_tail : SEMI { }
|
|||
t->is_pointer += $2.is_pointer;
|
||||
t->is_reference = $2.is_reference;
|
||||
if ($3.text) {
|
||||
t->arraystr = copy_string(Char($3.text));
|
||||
t->arraystr = Swig_copy_string(Char($3.text));
|
||||
t->is_pointer++;
|
||||
}
|
||||
Setattr(o,"name",$2.id);
|
||||
|
|
@ -1595,7 +1584,7 @@ parm : type pname {
|
|||
Setattr($$,"name",$2.name);
|
||||
if ($2.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($2.array));
|
||||
$1->arraystr = Swig_copy_string(Char($2.array));
|
||||
}
|
||||
if ($2.value)
|
||||
Setattr($$,"value",$2.value);
|
||||
|
|
@ -1607,7 +1596,7 @@ parm : type pname {
|
|||
$1->is_pointer += $2.ivalue;
|
||||
if ($3.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($3.array));
|
||||
$1->arraystr = Swig_copy_string(Char($3.array));
|
||||
}
|
||||
if ($3.value) {
|
||||
Setattr($$,"value",$3.value);
|
||||
|
|
@ -1621,7 +1610,7 @@ parm : type pname {
|
|||
Setattr($$,"name",$3.name);
|
||||
if ($3.array) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(Char($3.array));
|
||||
$1->arraystr = Swig_copy_string(Char($3.array));
|
||||
}
|
||||
if ($3.value) {
|
||||
Setattr($$,"value",$3.value);
|
||||
|
|
@ -1766,7 +1755,7 @@ realtype : TYPE_INT { $$ = NewLParseType(LPARSE_T_INT); }
|
|||
}
|
||||
| CONST type {
|
||||
$$ = $2;
|
||||
$$->qualifier = copy_string("const");
|
||||
$$->qualifier = Swig_copy_string("const");
|
||||
}
|
||||
| cpptype idtype {
|
||||
$$ = NewLParseType(LPARSE_T_USER);
|
||||
|
|
|
|||
|
|
@ -1,28 +1,18 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* type.c
|
||||
*
|
||||
* Lame SWIG1.1 type implementation.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "lparse.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* $Header$
|
||||
*
|
||||
* type.c
|
||||
*
|
||||
* Lame type structure for old SWIG parser
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOH *LParseTypeStr(DOH *to);
|
||||
|
||||
static DohObjInfo LParseTypeType = {
|
||||
|
|
|
|||
|
|
@ -1,39 +1,25 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* cpp.c
|
||||
*
|
||||
* An implementation of a C preprocessor plus some support for additional
|
||||
* SWIG directives.
|
||||
*
|
||||
* - SWIG directives such as %include, %extern, and %import are handled
|
||||
* - A new macro %define ... %enddef can be used for multiline macros
|
||||
* - No preprocessing is performed in %{ ... %} blocks
|
||||
* - Lines beginning with %# are stripped down to #... and passed through.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "preprocessor.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* $Header$
|
||||
*
|
||||
* File : cpp.c
|
||||
*
|
||||
* The SWIG Preprocessor. This works almost exactly like the C preprocessor except
|
||||
* for a number of extensions:
|
||||
*
|
||||
* - SWIG directives such as %include, %extern, and %import are recognized
|
||||
* - A new macro %define ... %enddef is provided to make it easier to
|
||||
* write multi-line macros.
|
||||
* - No preprocessing is performed inside %{ ... %} blocks.
|
||||
* - Lines beginning with %#... are stripped to #... and passed through
|
||||
* unmodified.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *cpp = 0; /* C preprocessor data */
|
||||
static int include_all = 1; /* Follow all includes */
|
||||
static int single_include = 1; /* Only include each file once */
|
||||
|
|
|
|||
|
|
@ -1,31 +1,19 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
#include "preprocessor.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* expr.c
|
||||
*
|
||||
* This is your basic ol' integer arithmetic expression evaluator. Could have
|
||||
* used yacc for this, but it generates something like 1000 lines of code
|
||||
* (whereas this implementation is much smaller).
|
||||
* Integer arithmetic expression evaluator used to handle expressions
|
||||
* encountered during preprocessing.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* This module is primarily for use by the preprocessor and any other parts of
|
||||
* the compiler that need to perform compile-time expression evaluation.
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "preprocessor.h"
|
||||
|
||||
static SwigScanner *scan = 0;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -172,23 +160,25 @@ static void reduce_op() {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Preprocessor_expr_init()
|
||||
* Preprocessor_expr_init()
|
||||
*
|
||||
* Initialize the expression evaluator
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Preprocessor_expr_init() {
|
||||
void
|
||||
Preprocessor_expr_init() {
|
||||
if (!expr_init) init_precedence();
|
||||
if (!scan) scan = NewSwigScanner();
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int Preprocessor_expr(DOH *s, int *error)
|
||||
* Preprocessor_expr()
|
||||
*
|
||||
* Evaluates an arithmetic expression in s.
|
||||
* Evaluates an arithmetic expression. Returns the result and sets an error code.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int Preprocessor_expr(DOH *s, int *error) {
|
||||
int
|
||||
Preprocessor_expr(DOH *s, int *error) {
|
||||
int token = 0;
|
||||
int op = 0;
|
||||
|
||||
|
|
@ -328,8 +318,14 @@ int Preprocessor_expr(DOH *s, int *error) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Return the expression error message */
|
||||
char *Preprocessor_expr_error() {
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Preprocessor_expr_error()
|
||||
*
|
||||
* Return error message set by the evaluator (if any)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
Preprocessor_expr_error() {
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* preprocessor.h
|
||||
*
|
||||
* SWIG preprocessor module.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _PREPROCESSOR_H
|
||||
#define _PREPROCESSOR_H
|
||||
|
|
|
|||
|
|
@ -279,7 +279,11 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
|
|||
|
||||
Swig_check_options();
|
||||
|
||||
Swig_set_library(LibDir);
|
||||
{
|
||||
DOH *rl = NewString("");
|
||||
Printf(rl,"%s/%s", SwigLib,LibDir);
|
||||
Swig_add_directory(rl);
|
||||
}
|
||||
|
||||
// If we made it this far, looks good. go for it....
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* getopt.c
|
||||
*
|
||||
* Handles the parsing of command line options. This is particularly nasty
|
||||
* compared to other utilities given that command line options can potentially
|
||||
* be read by many different modules within SWIG. Thus, in order to make sure
|
||||
* there are no unrecognized options, each module is required to "mark"
|
||||
* the options that it uses. Afterwards, we can make a quick scan to make
|
||||
* sure there are no unmarked options.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
* To do:
|
||||
* - This module needs to be modified so that it doesn't call exit().
|
||||
* Should have cleaner error handling in general.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* $Header$
|
||||
*
|
||||
* File : getopt.c
|
||||
*
|
||||
* Functions for handling command line arguments. This is a little funky because
|
||||
* the arguments are checked in multiple places.
|
||||
*******************************************************************************/
|
||||
|
||||
static char **args;
|
||||
static int numargs;
|
||||
static int *marked;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_init_args(int argc, char **argv)
|
||||
* Swig_init_args()
|
||||
*
|
||||
* Initializes the argument list.
|
||||
* Initialize the argument list handler.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_init_args(int argc, char **argv)
|
||||
{
|
||||
Swig_init_args(int argc, char **argv) {
|
||||
int i;
|
||||
assert(argc > 0);
|
||||
assert(argv);
|
||||
|
|
@ -53,10 +48,9 @@ Swig_init_args(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_mark_arg(int n)
|
||||
* Swig_mark_arg()
|
||||
*
|
||||
* Marks an argument as being parsed. All modules should do this whenever they
|
||||
* parse a command line option.
|
||||
* Marks an argument as being parsed.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
|
|
@ -67,16 +61,16 @@ Swig_mark_arg(int n) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_check_options()
|
||||
* Swig_check_options()
|
||||
*
|
||||
* Checks for unparsed command line options. If so, issues an error and exits.
|
||||
* Checkers for unprocessed command line options and errors.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_check_options() {
|
||||
void
|
||||
Swig_check_options() {
|
||||
int error = 0;
|
||||
int i;
|
||||
assert(marked);
|
||||
|
||||
for (i = 1; i < numargs-1; i++) {
|
||||
if (!marked[i]) {
|
||||
Printf(stderr,"swig error : Unrecognized option %s\n", args[i]);
|
||||
|
|
@ -94,12 +88,13 @@ void Swig_check_options() {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_arg_error()
|
||||
* Swig_arg_error()
|
||||
*
|
||||
* Generates a generic error message and exits.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_arg_error() {
|
||||
void
|
||||
Swig_arg_error() {
|
||||
Printf(stderr,"SWIG : Unable to parse command line options.\n");
|
||||
Printf(stderr,"Use 'swig -help' for available options.\n");
|
||||
exit(1);
|
||||
|
|
|
|||
|
|
@ -1,46 +1,34 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* include.c
|
||||
*
|
||||
* The functions in this file are used to manage files in the SWIG library.
|
||||
* General purpose functions for opening, including, and retrieving pathnames
|
||||
* are provided.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* $Header$
|
||||
*
|
||||
* File : include.c
|
||||
*
|
||||
* Various file manipulation functions.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Delimeter used in accessing files and directories */
|
||||
|
||||
static DOH *directories = 0; /* List of include directories */
|
||||
static DOH *libdir = 0; /* SWIG library directory */
|
||||
static DOH *lastpath = 0; /* Last file that was included */
|
||||
static int bytes_read = 0; /* Bytes read */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_add_directory( DOH *dirname)
|
||||
* Swig_add_directory()
|
||||
*
|
||||
* Adds a directory to the SWIG search path.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_add_directory(DOH *dirname)
|
||||
{
|
||||
Swig_add_directory(DOH *dirname) {
|
||||
if (!directories) directories = NewList();
|
||||
assert(directories);
|
||||
if (!String_check(dirname)) {
|
||||
|
|
@ -51,35 +39,7 @@ Swig_add_directory(DOH *dirname)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_set_library(DOH *libname)
|
||||
*
|
||||
* Sets the language specific library name like 'tcl', 'perl5', 'python', etc...
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_set_library(DOH *libname)
|
||||
{
|
||||
Delete(libdir);
|
||||
if (!String_check(libname)) {
|
||||
libname = NewString((char *) libname);
|
||||
assert(libname);
|
||||
}
|
||||
libdir = libname;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Swig_get_library()
|
||||
*
|
||||
* Gets the language specific name like 'tcl', 'perl5', etc...
|
||||
* ----------------------------------------------------------------------------- */
|
||||
DOH *
|
||||
Swig_get_library() {
|
||||
assert(libdir);
|
||||
return libdir;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Swig_last_file()
|
||||
* Swig_last_file()
|
||||
*
|
||||
* Returns the full pathname of the last file opened.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -91,13 +51,13 @@ Swig_last_file() {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Swig_search_path()
|
||||
* Swig_search_path()
|
||||
*
|
||||
* Returns a list of the current search paths.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *Swig_search_path()
|
||||
{
|
||||
DOH *
|
||||
Swig_search_path() {
|
||||
DOH *filename;
|
||||
DOH *dirname;
|
||||
DOH *slist;
|
||||
|
|
@ -111,12 +71,6 @@ DOH *Swig_search_path()
|
|||
Append(slist,filename);
|
||||
for (i = 0; i < Len(directories); i++) {
|
||||
dirname = Getitem(directories,i);
|
||||
if (libdir) {
|
||||
filename = NewString("");
|
||||
assert(filename);
|
||||
Printf(filename,"%s%s%s%s", dirname, SWIG_FILE_DELIMETER, libdir, SWIG_FILE_DELIMETER);
|
||||
Append(slist,filename);
|
||||
}
|
||||
filename = NewString("");
|
||||
assert(filename);
|
||||
Printf(filename, "%s%s", dirname, SWIG_FILE_DELIMETER);
|
||||
|
|
@ -126,14 +80,13 @@ DOH *Swig_search_path()
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* FILE *Swig_open( DOH *name)
|
||||
* Swig_open()
|
||||
*
|
||||
* Looks for a file and open it.
|
||||
* Looks for a file and open it. Returns an open FILE * on success.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
FILE *
|
||||
Swig_open(DOH *name)
|
||||
{
|
||||
Swig_open(DOH *name) {
|
||||
FILE *f;
|
||||
DOH *filename;
|
||||
DOH *spath = 0;
|
||||
|
|
@ -166,12 +119,13 @@ Swig_open(DOH *name)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Swig_read_file(FILE *f)
|
||||
* Swig_read_file()
|
||||
*
|
||||
* Reads data from f and returns as a new string
|
||||
* Reads data from an open FILE * and returns it as a string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *Swig_read_file(FILE *f) {
|
||||
DOH *
|
||||
Swig_read_file(FILE *f) {
|
||||
char buffer[4096];
|
||||
DOH *str = NewString("");
|
||||
assert(str);
|
||||
|
|
@ -183,14 +137,13 @@ DOH *Swig_read_file(FILE *f) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Swig_include(DOH *name)
|
||||
* Swig_include()
|
||||
*
|
||||
* Open a file and return it as a string.
|
||||
* Opens a file and returns it as a string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Swig_include(DOH *name)
|
||||
{
|
||||
Swig_include(DOH *name) {
|
||||
FILE *f;
|
||||
DOH *str;
|
||||
f = Swig_open(name);
|
||||
|
|
@ -201,7 +154,12 @@ Swig_include(DOH *name)
|
|||
Seek(str,0,SEEK_SET);
|
||||
Setfile(str,lastpath);
|
||||
Setline(str,1);
|
||||
/* fprintf(stderr,"%d bytes read\n", bytes_read); */
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,27 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* misc.c
|
||||
*
|
||||
* Miscellaneous functions that don't really fit anywhere else.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* $Header$
|
||||
* Swig_copy_string()
|
||||
*
|
||||
* misc.c
|
||||
* Duplicate a NULL-terminate string given as a char *.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *copy_string(const char *s) {
|
||||
char *
|
||||
Swig_copy_string(const char *s) {
|
||||
char *c = 0;
|
||||
if (s) {
|
||||
c = (char *) malloc(strlen(s)+1);
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* scanner.c
|
||||
*
|
||||
* This file implements a general purpose C/C++ compatible lexical scanner.
|
||||
* This scanner isn't intended to be plugged directly into a parser built
|
||||
* with yacc. Rather, it contains a lot of generic code that could be used
|
||||
* to easily construct yacc-compatible scanners.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include <ctype.h>
|
||||
|
||||
struct SwigScanner {
|
||||
DOH *text; /* Current token value */
|
||||
|
|
@ -30,21 +30,14 @@ struct SwigScanner {
|
|||
DOH *file;
|
||||
};
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* $Header$
|
||||
* NewSwigScanner()
|
||||
*
|
||||
* scanner.c
|
||||
*
|
||||
* A generic C-based lexical scanner.
|
||||
* Create a new scanner object
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner *NewSwigScanner() - Create a new scanner object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
SwigScanner *NewSwigScanner()
|
||||
{
|
||||
SwigScanner *
|
||||
NewSwigScanner() {
|
||||
SwigScanner *s;
|
||||
s = (SwigScanner *) malloc(sizeof(SwigScanner));
|
||||
s->line = 1;
|
||||
|
|
@ -61,10 +54,13 @@ SwigScanner *NewSwigScanner()
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DelSwigScanner(SwigScanner *s) - Delete a SwigScanner object
|
||||
* DelSwigScanner()
|
||||
*
|
||||
* Delete a scanner object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void DelSwigScanner(SwigScanner *s)
|
||||
{
|
||||
|
||||
void
|
||||
DelSwigScanner(SwigScanner *s) {
|
||||
assert(s);
|
||||
Delete(s->scanobjs);
|
||||
Delete(s->text);
|
||||
|
|
@ -73,9 +69,13 @@ void DelSwigScanner(SwigScanner *s)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_clear(SwigScanner *s) - Clear a scanner object
|
||||
* SwigScanner_clear()
|
||||
*
|
||||
* Clear the contents of a scanner object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void SwigScanner_clear(SwigScanner *s) {
|
||||
|
||||
void
|
||||
SwigScanner_clear(SwigScanner *s) {
|
||||
assert(s);
|
||||
Delete(s->str);
|
||||
Clear(s->text);
|
||||
|
|
@ -88,11 +88,14 @@ void SwigScanner_clear(SwigScanner *s) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_push(SwigScanner *s, DOH *txt) - Push text into the scanner
|
||||
* SwigScanner_push()
|
||||
*
|
||||
* Push some new text into the scanner. The scanner will start parsing this text
|
||||
* immediately before returning to the old text.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void SwigScanner_push(SwigScanner *s, DOH *txt)
|
||||
{
|
||||
void
|
||||
SwigScanner_push(SwigScanner *s, DOH *txt) {
|
||||
assert(s && txt);
|
||||
Push(s->scanobjs,txt);
|
||||
if (s->str) Delete(s->str);
|
||||
|
|
@ -100,30 +103,37 @@ void SwigScanner_push(SwigScanner *s, DOH *txt)
|
|||
Incref(s->str);
|
||||
s->line = Getline(txt);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_pushtoken(SwigScanner *s, int nt)
|
||||
* SwigScanner_pushtoken()
|
||||
*
|
||||
* Set the next processing token.
|
||||
* Push a token into the scanner. This token will be returned on the next
|
||||
* call to SwigScanner_token().
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void SwigScanner_pushtoken(SwigScanner *s, int nt) {
|
||||
void
|
||||
SwigScanner_pushtoken(SwigScanner *s, int nt) {
|
||||
assert(s);
|
||||
assert((nt >= 0) && (nt < SWIG_MAXTOKENS));
|
||||
s->nexttoken = nt;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_set_location(SwigScanner *s, DOH *file, int line)
|
||||
* SwigScanner_set_location()
|
||||
*
|
||||
* Set the file and line number location of the scanner.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
SwigScanner_set_location(SwigScanner *s, DOH *file, int line)
|
||||
{
|
||||
SwigScanner_set_location(SwigScanner *s, DOH *file, int line) {
|
||||
Setline(s->str,line);
|
||||
Setfile(s->str,file);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_get_file(SwigScanner *s) - Get current file
|
||||
* SwigScanner_get_file()
|
||||
*
|
||||
* Get the current file.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
|
|
@ -131,24 +141,29 @@ SwigScanner_get_file(SwigScanner *s) {
|
|||
return Getfile(s->str);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigScanner_get_line()
|
||||
*
|
||||
* Get the current line number
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
SwigScanner_get_line(SwigScanner *s) {
|
||||
return Getline(s->str);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void SwigScanner_idstart(SwigScanner *s, char *id)
|
||||
* SwigScanner_idstart()
|
||||
*
|
||||
* Set the characters that can be used to start an identifier
|
||||
* Change the set of additional characters that can be used to start an identifier.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
SwigScanner_idstart(SwigScanner *s, char *id) {
|
||||
s->idstart = copy_string(id);
|
||||
s->idstart = Swig_copy_string(id);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* char nextchar(SwigScanner *s)
|
||||
* nextchar()
|
||||
*
|
||||
* Returns the next character from the scanner or 0 if end of the string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -176,7 +191,7 @@ nextchar(SwigScanner *s)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void retract(SwigScanner *s, int n)
|
||||
* retract()
|
||||
*
|
||||
* Retract n characters
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -199,14 +214,13 @@ retract(SwigScanner *s, int n) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int look(SwigScanner *s)
|
||||
* look()
|
||||
*
|
||||
* Get the next token.
|
||||
* Return the raw value of the next token.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
look(SwigScanner *s)
|
||||
{
|
||||
look(SwigScanner *s) {
|
||||
int state;
|
||||
char c = 0;
|
||||
|
||||
|
|
@ -632,14 +646,13 @@ look(SwigScanner *s)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int SwigScanner_token(SwigScanner *s)
|
||||
* SwigScanner_token()
|
||||
*
|
||||
* Return the next token or 0 if at the end of the string
|
||||
* Real entry point to return the next token. Returns 0 if at end of input.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
SwigScanner_token(SwigScanner *s)
|
||||
{
|
||||
SwigScanner_token(SwigScanner *s) {
|
||||
int t;
|
||||
Clear(s->text);
|
||||
if (s->nexttoken >= 0) {
|
||||
|
|
@ -652,25 +665,24 @@ SwigScanner_token(SwigScanner *s)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *SwigScanner_text(SwigScanner *s)
|
||||
* SwigScanner_text()
|
||||
*
|
||||
* Return the text associated with the last token returned.
|
||||
* Return the lexene associated with the last returned token.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
SwigScanner_text(SwigScanner *s)
|
||||
{
|
||||
SwigScanner_text(SwigScanner *s) {
|
||||
return s->text;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void SwigScanner_skip_line(SwigScanner *s)
|
||||
* SwigScanner_skip_line()
|
||||
*
|
||||
* Skips to the end of a line
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
SwigScanner_skip_line(SwigScanner *s)
|
||||
{
|
||||
SwigScanner_skip_line(SwigScanner *s) {
|
||||
char c;
|
||||
int done = 0;
|
||||
Clear(s->text);
|
||||
|
|
@ -685,15 +697,14 @@ SwigScanner_skip_line(SwigScanner *s)
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void SwigScanner_skip_balanced(SwigScanner *s, int start, int end)
|
||||
* SwigScanner_skip_balanced()
|
||||
*
|
||||
* Skips a piece of code enclosed in begin/end symbols such as '{...}' or
|
||||
* (...). Ignores symbols inside comments or strings.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
SwigScanner_skip_balanced(SwigScanner *s, int startchar, int endchar)
|
||||
{
|
||||
SwigScanner_skip_balanced(SwigScanner *s, int startchar, int endchar) {
|
||||
char c;
|
||||
int num_levels = 1;
|
||||
int l;
|
||||
|
|
|
|||
|
|
@ -1,30 +1,21 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* super.c
|
||||
*
|
||||
* SuperStrings are just like strings, except that they maintain
|
||||
* information as to the origininal file/line of each character they
|
||||
* contain.
|
||||
*
|
||||
* Authors : David Beazley
|
||||
* Dustin Mitchell
|
||||
* Author(s) : Dustin Mitchell (djmitche@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
---------------------------------------------------------------------- */
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "doh.h"
|
||||
#include "swig.h"
|
||||
|
||||
static char cvstag[] = "$Header$";
|
||||
|
||||
/*
|
||||
* SuperStrings are just like strings, except that they maintain
|
||||
* information as to the origininal file/line of each character they
|
||||
* contain.
|
||||
*/
|
||||
|
||||
typedef struct SSTag
|
||||
{
|
||||
int length; /* distance to the next tag */
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig.h
|
||||
*
|
||||
* Header file for the SWIG core.
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
* Dustin Mitchell (djmitche@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which Swig
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _SWIGCORE_H
|
||||
#define _SWIGCORE_H
|
||||
|
|
@ -20,6 +19,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "doh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -29,8 +29,6 @@ extern "C" {
|
|||
/* --- File interface --- */
|
||||
|
||||
extern void Swig_add_directory(DOH *dirname);
|
||||
extern void Swig_set_library(DOH *libname);
|
||||
extern DOH *Swig_get_library();
|
||||
extern DOH *Swig_last_file();
|
||||
extern DOH *Swig_search_path();
|
||||
extern FILE *Swig_open(DOH *name);
|
||||
|
|
@ -51,7 +49,6 @@ extern void Swig_mark_arg(int n);
|
|||
extern void Swig_check_options();
|
||||
extern void Swig_arg_error();
|
||||
|
||||
|
||||
/* --- Scanner Interface --- */
|
||||
|
||||
typedef struct SwigScanner SwigScanner;
|
||||
|
|
@ -122,8 +119,7 @@ extern void SwigScanner_idstart(SwigScanner *, char *idchar);
|
|||
#define SWIG_TOKEN_LAST 99
|
||||
|
||||
/* --- Misc --- */
|
||||
|
||||
extern char *copy_string(const char *c);
|
||||
extern char *Swig_copy_string(const char *c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue