(NewString): Declare arg const.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@261 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Thien-Thi Nguyen 2000-02-25 00:04:55 +00:00
commit b0cc2a423f
2 changed files with 42 additions and 42 deletions

View file

@ -1,9 +1,9 @@
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* string.c * string.c
* *
* Implements a string object that supports both sequence operations and * Implements a string object that supports both sequence operations and
* file semantics. * file semantics.
* *
* Author(s) : David Beazley (beazley@cs.uchicago.edu) * Author(s) : David Beazley (beazley@cs.uchicago.edu)
* *
* Copyright (C) 1999-2000. The University of Chicago * Copyright (C) 1999-2000. The University of Chicago
@ -52,7 +52,7 @@ int String_putc(DOH *s, int ch);
int String_ungetc(DOH *s, int ch); int String_ungetc(DOH *s, int ch);
int String_seek(DOH *s, long offset, int whence); int String_seek(DOH *s, long offset, int whence);
long String_tell(DOH *s); long String_tell(DOH *s);
int String_replace(DOH *str, DOH *token, DOH *rep, int flags); int String_replace(DOH *str, DOH *token, DOH *rep, int flags);
void String_chop(DOH *str); void String_chop(DOH *str);
static DohSequenceMethods StringSeqMethods = { static DohSequenceMethods StringSeqMethods = {
@ -97,7 +97,7 @@ static DohObjInfo StringType = {
0, /* doh_mapping */ 0, /* doh_mapping */
&StringSeqMethods, /* doh_sequence */ &StringSeqMethods, /* doh_sequence */
&StringFileMethods,/* doh_file */ &StringFileMethods,/* doh_file */
&StringStringMethods, /* doh_string */ &StringStringMethods, /* doh_string */
0, /* doh_callable */ 0, /* doh_callable */
0, /* doh_position */ 0, /* doh_position */
}; };
@ -118,7 +118,7 @@ void *String_data(DOH *so) {
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* int String_dump(DOH *so, DOH *out) * int String_dump(DOH *so, DOH *out)
* *
* Serialize a string onto out * Serialize a string onto out
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -127,7 +127,7 @@ int String_dump(DOH *so, DOH *out) {
int nsent; int nsent;
int ret; int ret;
String *s; String *s;
s = (String *) so; s = (String *) so;
nsent = 0; nsent = 0;
while (nsent < s->len) { while (nsent < s->len) {
@ -142,7 +142,7 @@ int String_dump(DOH *so, DOH *out) {
* NewString(const char *c) - Create a new string * NewString(const char *c) - Create a new string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
DOH * DOH *
NewString(DOH *so) NewString(const DOH *so)
{ {
int l = 0, max; int l = 0, max;
String *str; String *str;
@ -219,7 +219,7 @@ CopyString(DOH *so) {
str->str[str->len] = 0; str->str[str->len] = 0;
return (DOH *) str; return (DOH *) str;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DelString(DOH *s) - Delete a string * DelString(DOH *s) - Delete a string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -228,7 +228,7 @@ DelString(DOH *so) {
String *s; String *s;
s = (String *) so; s = (String *) so;
assert(s->refcount <= 0); assert(s->refcount <= 0);
if (s->str) if (s->str)
DohFree(s->str); DohFree(s->str);
s->str = 0; s->str = 0;
Delete(s->file); Delete(s->file);
@ -239,7 +239,7 @@ DelString(DOH *so) {
* int String_check(DOH *s) - Check if s is a string * int String_check(DOH *s) - Check if s is a string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
String_check(DOH *s) String_check(DOH *s)
{ {
char *c = (char *) s; char *c = (char *) s;
if (!s) return 0; if (!s) return 0;
@ -255,7 +255,7 @@ String_check(DOH *s)
* int String_len(DOH *s) - Length of a string * int String_len(DOH *s) - Length of a string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
String_len(DOH *so) { String_len(DOH *so) {
String *s = (String *)so; String *s = (String *)so;
return s->len; return s->len;
@ -302,7 +302,7 @@ int String_hash(DOH *so) {
c = s->str; c = s->str;
len = s->len > 50 ? 50 : s->len; len = s->len > 50 ? 50 : s->len;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
h = (((h << 5) + *(c++))); h = (((h << 5) + *(c++)));
} }
h = h & 0x7fffffff; h = h & 0x7fffffff;
s->hashkey = h; s->hashkey = h;
@ -337,7 +337,7 @@ add(String *s, const char *newstr) {
s->sp = s->len+l; s->sp = s->len+l;
} }
s->len += l; s->len += l;
} }
/* Add a single character to s */ /* Add a single character to s */
void void
@ -387,7 +387,7 @@ String_clear(DOH *so)
s->line = 1; s->line = 1;
s->pbi = 0; s->pbi = 0;
} }
void void
raw_insert(String *s, int pos, char *data, int len) raw_insert(String *s, int pos, char *data, int len)
{ {
@ -421,7 +421,7 @@ raw_insert(String *s, int pos, char *data, int len)
s->sp+=len; s->sp+=len;
} }
s->len += len; s->len += len;
s->str[s->len] = 0; s->str[s->len] = 0;
} }
@ -450,7 +450,7 @@ String_insert(DOH *so, int pos, DOH *str)
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* int String_delitem(DOH *so, int pos) * int String_delitem(DOH *so, int pos)
* *
* Delete an individual item * Delete an individual item
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -473,7 +473,7 @@ int String_delitem(DOH *so, int pos)
s->str[s->len] = 0; s->str[s->len] = 0;
return 0; return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DOH *String_str(DOH *so) - Returns a string (used by printing commands) * DOH *String_str(DOH *so) - Returns a string (used by printing commands)
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -488,7 +488,7 @@ String_str(DOH *so) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* int String_read(DOH *so, void *buffer, int len) * int String_read(DOH *so, void *buffer, int len)
* *
* Read data from the string * Read data from the string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
@ -517,7 +517,7 @@ String_read(DOH *so, void *buffer, int len) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* int String_write(DOH *so, void *buffer, int len) * int String_write(DOH *so, void *buffer, int len)
* *
* Write data to the string * Write data to the string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
@ -541,7 +541,7 @@ String_write(DOH *so, void *buffer, int len) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* int String_seek(DOH *so, long offset, int whence) * int String_seek(DOH *so, long offset, int whence)
* *
* Seek to a new position * Seek to a new position
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
@ -562,7 +562,7 @@ String_seek(DOH *so, long offset, int whence) {
if (nsp > s->sp) inc = 1; if (nsp > s->sp) inc = 1;
else inc = -1; else inc = -1;
#ifdef DOH_STRING_UPDATE_LINES #ifdef DOH_STRING_UPDATE_LINES
while (s->sp != nsp) { while (s->sp != nsp) {
if (s->str[s->sp-1] == '\n') s->line += inc; if (s->str[s->sp-1] == '\n') s->line += inc;
s->sp += inc; s->sp += inc;
} }
@ -574,7 +574,7 @@ String_seek(DOH *so, long offset, int whence) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* long String_tell(DOH *so) * long String_tell(DOH *so)
* *
* Return current position * Return current position
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
long long
@ -658,7 +658,7 @@ int String_ungetc(DOH *so, int ch) {
* DOH_REPLACE_NOQUOTE - Don't replace in quotes * DOH_REPLACE_NOQUOTE - Don't replace in quotes
* DOH_REPLACE_ID - Only replace valid identifiers * DOH_REPLACE_ID - Only replace valid identifiers
* DOH_REPLACE_FIRST - Only replace first occurrence * DOH_REPLACE_FIRST - Only replace first occurrence
* *
* start is a starting position. count is a count. * start is a starting position. count is a count.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -678,7 +678,7 @@ int replace_internal(String *str, char *token, char *rep, int flags, char *start
tokenlen = strlen(token); tokenlen = strlen(token);
/* If a starting position was given, dump those characters first */ /* If a starting position was given, dump those characters first */
if (start) { if (start) {
c = start; c = start;
} else { } else {
@ -778,7 +778,7 @@ int replace_internal(String *str, char *token, char *rep, int flags, char *start
* int String_replace(DOH *str, DOH *token, DOH *rep, int flags) * int String_replace(DOH *str, DOH *token, DOH *rep, int flags)
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
String_replace(DOH *stro, DOH *token, DOH *rep, int flags) String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
{ {
int count = -1; int count = -1;
@ -801,7 +801,7 @@ String_chop(DOH *s) {
String *str = (String *) s; String *str = (String *) s;
if (!String_check(s)) return; if (!String_check(s)) return;
/* assert(!str->refcount); */ /* assert(!str->refcount); */
/* Replace trailing whitespace */ /* Replace trailing whitespace */
c = str->str + str->len - 1; c = str->str + str->len - 1;
while ((str->len >= 0) && (isspace(*c))) { while ((str->len >= 0) && (isspace(*c))) {
@ -817,4 +817,4 @@ String_chop(DOH *s) {
str->hashkey = -1; str->hashkey = -1;
str->pbi = 0; str->pbi = 0;
} }

View file

@ -1,12 +1,12 @@
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* doh.h * doh.h
* *
* This file describes of the externally visible functions in DOH. * This file describes of the externally visible functions in DOH.
* *
* Author(s) : David Beazley (beazley@cs.uchicago.edu) * Author(s) : David Beazley (beazley@cs.uchicago.edu)
* *
* Copyright (C) 1999-2000. The University of Chicago * Copyright (C) 1999-2000. The University of Chicago
* See the file LICENSE for information on usage and redistribution. * See the file LICENSE for information on usage and redistribution.
* *
* $Header$ * $Header$
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -24,7 +24,7 @@ extern "C" {
#define DOH_MAJOR_VERSION 0 #define DOH_MAJOR_VERSION 0
#define DOH_MINOR_VERSION 1 #define DOH_MINOR_VERSION 1
typedef void DOH; typedef void DOH;
#define DOH_BEGIN -1 #define DOH_BEGIN -1
#define DOH_END -2 #define DOH_END -2
@ -50,7 +50,7 @@ typedef struct {
int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */ int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */
int (*doh_delitem)(DOH *obj, int index); /* Delete item */ int (*doh_delitem)(DOH *obj, int index); /* Delete item */
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */ int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
DOH *(*doh_firstitem)(DOH *obj); /* Iterators */ DOH *(*doh_firstitem)(DOH *obj); /* Iterators */
DOH *(*doh_nextitem)(DOH *obj); DOH *(*doh_nextitem)(DOH *obj);
} DohSequenceMethods; } DohSequenceMethods;
@ -87,7 +87,7 @@ typedef struct {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DohObjInfo * DohObjInfo
* *
* A pointer to this structure is included in all DOH types and is used to * A pointer to this structure is included in all DOH types and is used to
* describe the properties of various objects. * describe the properties of various objects.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -109,17 +109,17 @@ typedef struct DohObjInfo {
DOH *(*doh_load)(DOH *in); /* Unserialize from in */ DOH *(*doh_load)(DOH *in); /* Unserialize from in */
/* Length and hash values */ /* Length and hash values */
int (*doh_len)(DOH *obj); int (*doh_len)(DOH *obj);
int (*doh_hash)(DOH *obj); int (*doh_hash)(DOH *obj);
/* Compare */ /* Compare */
int (*doh_cmp)(DOH *obj1, DOH *obj2); int (*doh_cmp)(DOH *obj1, DOH *obj2);
DohMappingMethods *doh_mapping; /* Mapping methods */ DohMappingMethods *doh_mapping; /* Mapping methods */
DohSequenceMethods *doh_sequence; /* Sequence methods */ DohSequenceMethods *doh_sequence; /* Sequence methods */
DohFileMethods *doh_file; /* File methods */ DohFileMethods *doh_file; /* File methods */
DohStringMethods *doh_string; /* String methods */ DohStringMethods *doh_string; /* String methods */
DohCallableMethods *doh_callable; /* Callable methods */ DohCallableMethods *doh_callable; /* Callable methods */
DohPositionalMethods *doh_position; /* Positional methods */ DohPositionalMethods *doh_position; /* Positional methods */
void *reserved4; void *reserved4;
void *reserved5; void *reserved5;
@ -161,7 +161,7 @@ typedef struct DohObjInfo {
extern int DohCmp(DOH *obj1, DOH *obj2); extern int DohCmp(DOH *obj1, DOH *obj2);
/* Mapping methods */ /* Mapping methods */
extern DOH *DohGetattr(DOH *obj, DOH *name); extern DOH *DohGetattr(DOH *obj, DOH *name);
extern int DohSetattr(DOH *obj, DOH *name, DOH *value); extern int DohSetattr(DOH *obj, DOH *name, DOH *value);
extern void DohDelattr(DOH *obj, DOH *name); extern void DohDelattr(DOH *obj, DOH *name);
@ -321,12 +321,12 @@ typedef struct {
#define DOH_FLAG_DELSCOPE 0x04 #define DOH_FLAG_DELSCOPE 0x04
#define DOH_FLAG_GC 0x08 #define DOH_FLAG_GC 0x08
#define DOH_FLAG_INTERN 0x10 #define DOH_FLAG_INTERN 0x10
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Strings. * Strings.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
extern DOH *NewString(DOH *c); extern DOH *NewString(const DOH *c);
extern DOH *NewStringf(DOH *fmt, ...); extern DOH *NewStringf(DOH *fmt, ...);
extern int String_check(DOH *s); extern int String_check(DOH *s);
@ -376,7 +376,7 @@ extern DOH *DohSplit(DOH *input, char *chs, int nsplits);
extern DOH *DohNone; extern DOH *DohNone;
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Callable * Callable
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */