From 76f3489353251bfe04221414ecdae3fba6cb86fe Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Wed, 18 Aug 1999 04:12:59 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@18 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/DOH/Doh/Makefile | 4 +- SWIG/Source/DOH/Doh/base.c | 10 +-- SWIG/Source/DOH/Doh/file.c | 8 +-- SWIG/Source/DOH/Doh/fio.c | 12 ++-- SWIG/Source/DOH/Doh/hash.c | 20 +++--- SWIG/Source/DOH/Doh/list.c | 16 ++--- SWIG/Source/DOH/Doh/memory.c | 94 ++++++++++++++++++++++----- SWIG/Source/DOH/Doh/string.c | 28 ++++---- SWIG/Source/DOH/Doh/void.c | 4 +- SWIG/Source/DOH/Include/doh.h | 14 +++- SWIG/Source/DOH/install-sh | 119 ++++++++++++++++++++++++++++++++++ 11 files changed, 261 insertions(+), 68 deletions(-) create mode 100755 SWIG/Source/DOH/install-sh diff --git a/SWIG/Source/DOH/Doh/Makefile b/SWIG/Source/DOH/Doh/Makefile index 562dc91cc..751ce0257 100644 --- a/SWIG/Source/DOH/Doh/Makefile +++ b/SWIG/Source/DOH/Doh/Makefile @@ -9,8 +9,8 @@ # Set your C++ compiler here. g++ works on most machines, # but you might have to change it depending on your installation. # -CC = cc -g -prefix = /usr/local +CC = gcc +prefix = /home/beazley/Projects # Comment out the following line if you're on an SGI or don't have ranlib! RANLIB = ranlib diff --git a/SWIG/Source/DOH/Doh/base.c b/SWIG/Source/DOH/Doh/base.c index 8d6e8cff0..c5192c64e 100644 --- a/SWIG/Source/DOH/Doh/base.c +++ b/SWIG/Source/DOH/Doh/base.c @@ -99,8 +99,8 @@ static DOH *find_internal(DOH *co) { if (d < 0) r = r->left; else r = r->right; } - r = (StringNode *) malloc(sizeof(StringNode)); - r->cstr = (char *) malloc(strlen(c)+1); + r = (StringNode *) DohMalloc(sizeof(StringNode)); + r->cstr = (char *) DohMalloc(strlen(c)+1); strcpy(r->cstr,c); r->sstr = NewString(c); Incref(r->sstr); @@ -122,8 +122,8 @@ void DohDestroy(DOH *obj) { b->refcount--; if (b->refcount <= 0) { if (doh_debug_level >= DOH_MEMORY) { - if (DohFreeCheck(obj)) { - DohError(DOH_MEMORY,"DohFree. %x was already released! (ignoring for now)\n", obj); + if (DohObjFreeCheck(obj)) { + DohError(DOH_MEMORY,"DohDestroy. %x was already released! (ignoring for now)\n", obj); return; } } @@ -131,7 +131,7 @@ void DohDestroy(DOH *obj) { (b->objinfo->doh_del)(obj); return; } else { - free(b); + /* free(b); */ } } } diff --git a/SWIG/Source/DOH/Doh/file.c b/SWIG/Source/DOH/Doh/file.c index 7b142e778..4094063e6 100644 --- a/SWIG/Source/DOH/Doh/file.c +++ b/SWIG/Source/DOH/Doh/file.c @@ -88,7 +88,7 @@ NewFile(char *filename, char *mode) file = fopen(filename,mode); if (!file) return 0; - f = (File *) DohMalloc(sizeof(File)); + f = (File *) DohObjMalloc(sizeof(File)); if (!f) { fclose(file); return 0; @@ -109,7 +109,7 @@ DOH * NewFileFromFile(FILE *file) { File *f; - f = (File *) DohMalloc(sizeof(File)); + f = (File *) DohObjMalloc(sizeof(File)); if (!f) return 0; DohInit(f); f->objinfo = &FileType; @@ -127,7 +127,7 @@ DOH * NewFileFromFd(int fd) { File *f; - f = (File *) DohMalloc(sizeof(File)); + f = (File *) DohObjMalloc(sizeof(File)); if (!f) return 0; DohInit(f); f->objinfo = &FileType; @@ -146,7 +146,7 @@ DelFile(DOH *so) { assert(f->refcount <= 0); if (f->closeondel) fclose(f->filep); - DohFree(f); + DohObjFree(f); } /* ----------------------------------------------------------------------------- diff --git a/SWIG/Source/DOH/Doh/fio.c b/SWIG/Source/DOH/Doh/fio.c index 18d60be07..0d4133799 100644 --- a/SWIG/Source/DOH/Doh/fio.c +++ b/SWIG/Source/DOH/Doh/fio.c @@ -214,7 +214,7 @@ DohvPrintf(DOH *so, char *format, va_list ap) if ((maxwidth + 1) < OBUFLEN) { stemp = obuffer; } else { - stemp = (char *) malloc(maxwidth+1); + stemp = (char *) DohMalloc(maxwidth+1); } nbytes+=sprintf(stemp,newformat,Data(Sval)); if (Writen(so,stemp,strlen(stemp)) < 0) return -1; @@ -225,7 +225,7 @@ DohvPrintf(DOH *so, char *format, va_list ap) Delete(doh); } if (stemp != obuffer) { - free(stemp); + DohFree(stemp); } } else { maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh); @@ -234,12 +234,12 @@ DohvPrintf(DOH *so, char *format, va_list ap) if ((maxwidth+1) < OBUFLEN) { stemp = obuffer; } else { - stemp = (char *) malloc(maxwidth + 1); + stemp = (char *) DohMalloc(maxwidth + 1); } nbytes+=sprintf(stemp,newformat,doh); if (Writen(so,stemp,strlen(stemp)) < 0) return -1; if (stemp != obuffer) { - free(stemp); + DohFree(stemp); } } } else { @@ -253,7 +253,7 @@ DohvPrintf(DOH *so, char *format, va_list ap) if (maxwidth < OBUFLEN) stemp = obuffer; else - stemp = (char *) malloc(maxwidth+1); + stemp = (char *) DohMalloc(maxwidth+1); switch(*p) { case 'd': case 'i': @@ -281,7 +281,7 @@ DohvPrintf(DOH *so, char *format, va_list ap) break; } if (Writen(so,stemp,strlen(stemp)) < 0) return -1; - if (stemp != obuffer) free(stemp); + if (stemp != obuffer) DohFree(stemp); } state = 0; break; diff --git a/SWIG/Source/DOH/Doh/hash.c b/SWIG/Source/DOH/Doh/hash.c index 1d74532b0..3eb5fd21c 100644 --- a/SWIG/Source/DOH/Doh/hash.c +++ b/SWIG/Source/DOH/Doh/hash.c @@ -56,7 +56,7 @@ int Hash_len(DOH *h); static HashNode *NewNode(DOH *k, void *obj) { - HashNode *hn = (HashNode *) malloc(sizeof(HashNode)); + HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode)); hn->key = k; Incref(hn->key); hn->object = obj; @@ -69,7 +69,7 @@ static void DelNode(HashNode *hn) { Delete(hn->key); Delete(hn->object); - free(hn); + DohFree(hn); } @@ -121,10 +121,10 @@ int Hash_check(DOH *so) { DOH *NewHash() { Hash *h; int i; - h = (Hash *) DohMalloc(sizeof(Hash)); + h = (Hash *) DohObjMalloc(sizeof(Hash)); DohInit(h); h->hashsize = HASH_INIT_SIZE; - h->hashtable = (HashNode **) malloc(h->hashsize*sizeof(HashNode *)); + h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *)); for (i = 0; i < h->hashsize; i++) { h->hashtable[i] = 0; } @@ -146,11 +146,11 @@ DOH *CopyHash(DOH *ho) { DOH *key; h = (Hash *) ho; - nh = (Hash *) DohMalloc(sizeof(Hash)); + nh = (Hash *) DohObjMalloc(sizeof(Hash)); DohInit(nh); nh->hashsize = h->hashsize; - nh->hashtable = (HashNode **) malloc(nh->hashsize*sizeof(HashNode *)); + nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *)); for (i = 0; i < nh->hashsize; i++) { nh->hashtable[i] = 0; } @@ -190,8 +190,8 @@ void DelHash(DOH *ho) } } } - free(h->hashtable); - DohFree(h); + DohFree(h->hashtable); + DohObjFree(h); } /* ----------------------------------------------------------------------------- @@ -244,7 +244,7 @@ static void resize(Hash *h) { p = p + 2; } - table = (HashNode **) malloc(newsize*sizeof(HashNode *)); + table = (HashNode **) DohMalloc(newsize*sizeof(HashNode *)); for (i = 0; i < newsize; i++ ) { table[i] = 0; } @@ -262,7 +262,7 @@ static void resize(Hash *h) { n = next; } } - free(h->hashtable); + DohFree(h->hashtable); h->hashtable = table; } diff --git a/SWIG/Source/DOH/Doh/list.c b/SWIG/Source/DOH/Doh/list.c index e23b39faf..0a9256646 100644 --- a/SWIG/Source/DOH/Doh/list.c +++ b/SWIG/Source/DOH/Doh/list.c @@ -88,7 +88,7 @@ void more(List *l) { int i; void **newitems; - newitems = (void **) malloc(l->maxitems*2*sizeof(void *)); + newitems = (void **) DohMalloc(l->maxitems*2*sizeof(void *)); for (i = 0; i < l->maxitems; i++) { newitems[i] = l->items[i]; } @@ -96,7 +96,7 @@ void more(List *l) { newitems[i] = (void *) 0; } l->maxitems *= 2; - free(l->items); + DohFree(l->items); l->items = newitems; } @@ -121,12 +121,12 @@ DOH * NewList() { List *l; int i; - l = (List *) DohMalloc(sizeof(List)); + l = (List *) DohObjMalloc(sizeof(List)); DohInit(l); l->objinfo = &ListType; l->nitems = 0; l->maxitems = MAXLISTITEMS; - l->items = (void **) malloc(l->maxitems*sizeof(void *)); + l->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); for (i = 0; i < MAXLISTITEMS; i++) { l->items[i] = 0; } @@ -143,12 +143,12 @@ CopyList(DOH *lo) { List *l,*nl; int i; l = (List *) lo; - nl = (List *) DohMalloc(sizeof(List)); + nl = (List *) DohObjMalloc(sizeof(List)); DohInit(nl); nl->objinfo = l->objinfo; nl->nitems = l->nitems; nl->maxitems = l->maxitems; - nl->items = (void **) malloc(l->maxitems*sizeof(void *)); + nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); nl->iter = 0; for (i = 0; i < l->maxitems; i++) { nl->items[i] = l->items[i]; @@ -172,8 +172,8 @@ DelList(DOH *lo) { for (i = 0; i < l->nitems; i++) { Delete(l->items[i]); } - free(l->items); - DohFree(l); + DohFree(l->items); + DohObjFree(l); } /* ----------------------------------------------------------------------------- diff --git a/SWIG/Source/DOH/Doh/memory.c b/SWIG/Source/DOH/Doh/memory.c index ca14a1044..b6354d1af 100644 --- a/SWIG/Source/DOH/Doh/memory.c +++ b/SWIG/Source/DOH/Doh/memory.c @@ -23,6 +23,9 @@ #define DOH_MAX_FRAG 1024 #endif +int _DohMemoryCurrent = 0; +int _DohMemoryHigh = 0; + /* ----------------------------------------------------------------------------- * memory.c * @@ -58,10 +61,10 @@ Pool *CreatePool(int size) { Pool *p = 0; char *c; - c = (char *) malloc(size); + c = (char *) DohMalloc(size); if (!c) return 0; - p = (Pool *) malloc(sizeof(Pool)); + p = (Pool *) DohMalloc(sizeof(Pool)); p->ptr = c; p->len = size; p->current = 0; @@ -102,12 +105,12 @@ int DohCheck(DOH *ptr) { } /* ---------------------------------------------------------------------- - * int DohFreeCheck(DOH *ptr) + * int DohObjFreeCheck(DOH *ptr) * * Check if ptr is an object that has been deleted. * ---------------------------------------------------------------------- */ -int DohFreeCheck(DOH *ptr) { +int DohObjFreeCheck(DOH *ptr) { int i; Fragment *f; char *cptr = (char *) ptr; @@ -122,12 +125,12 @@ int DohFreeCheck(DOH *ptr) { } /* ---------------------------------------------------------------------- - * void *DohMalloc(int size) + * void *DohObjMalloc(size_t size) * * Allocate an object * ---------------------------------------------------------------------- */ -void *DohMalloc(int size) { +void *DohObjMalloc(size_t size) { Pool *p; Fragment *f; void *ptr; @@ -140,7 +143,7 @@ void *DohMalloc(int size) { if (f) { ptr = (void *) f->ptr; FreeFragments[size] = f->next; - free(f); + DohFree(f); return ptr; } @@ -154,7 +157,7 @@ void *DohMalloc(int size) { /* Pool is not large enough. Create a new pool */ if (p->len - p->current > 0) { - f = (Fragment *) malloc(sizeof(Fragment)); + f = (Fragment *) DohMalloc(sizeof(Fragment)); f->ptr = (p->ptr + p->current); f->len = (p->len - p->current); f->next = FreeFragments[f->len]; @@ -163,36 +166,97 @@ void *DohMalloc(int size) { p = CreatePool(DOH_POOL_SIZE); p->next = Pools; Pools = p; - return DohMalloc(size); + return DohObjMalloc(size); } /* ---------------------------------------------------------------------- - * void DohFree(DOH *ptr) + * void DohObjFree(DOH *ptr) * * Free a DOH object. Important! It must be a properly allocated * DOH object. Not something else. * ---------------------------------------------------------------------- */ -void DohFree(DOH *ptr) { +void DohObjFree(DOH *ptr) { DohBase *b; Fragment *f; extern int doh_debug_level; if (!DohCheck(ptr)) { - DohError(DOH_MEMORY,"DohFree. %x not a DOH object!\n", ptr); + DohError(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr); return; /* Oh well. Guess we're leaky */ } b = (DohBase *) ptr; if (!b->objinfo) { - DohError(DOH_MEMORY,"DohFree. %x not properly defined. No objinfo structure.\n", ptr); + DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); return; /* Improperly initialized object. leak some more */ } - f = (Fragment *) malloc(sizeof(Fragment)); + f = (Fragment *) DohMalloc(sizeof(Fragment)); f->ptr = (char *) ptr; f->len = b->objinfo->objsize; f->next = FreeFragments[f->len]; FreeFragments[f->len] = f; } +/* ----------------------------------------------------------------------------- + * void *DohMalloc(size_t nbytes) + * + * 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 *DohRealloc(void *ptr, size_t newsize) + * + * 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 DohFree(void *ptr) + * + * Wrapper around free() function. Records memory usage. + * ----------------------------------------------------------------------------- */ + +void DohFree(void *ptr) { + char *cptr = (char *) ptr; + int size; + size = *((int *) (cptr - 8)); + free(cptr-8); + _DohMemoryCurrent -= (size+8); +} + +/* ----------------------------------------------------------------------------- + * int DohMemoryUse() + * + * Return bytes currently in use by Doh + * ----------------------------------------------------------------------------- */ + +int DohMemoryUse() { + return _DohMemoryCurrent; +} - +int DohMemoryHigh() { + return _DohMemoryHigh; +} diff --git a/SWIG/Source/DOH/Doh/string.c b/SWIG/Source/DOH/Doh/string.c index 396f56a64..c104af31d 100644 --- a/SWIG/Source/DOH/Doh/string.c +++ b/SWIG/Source/DOH/Doh/string.c @@ -142,7 +142,7 @@ NewString(char *s) { int l, max; String *str; - str = (String *) DohMalloc(sizeof(String)); + str = (String *) DohObjMalloc(sizeof(String)); DohInit(str); str->objinfo = &StringType; str->hashkey = -1; @@ -155,7 +155,7 @@ NewString(char *s) l = (int) strlen(s); if ((l+1) > max) max = l+1; } - str->str = (char *) malloc(max); + str->str = (char *) DohMalloc(max); str->maxsize = max; if (s) { strcpy(str->str,s); @@ -176,7 +176,7 @@ CopyString(DOH *so) { int l, max; String *str; s = (String *) so; - str = (String *) DohMalloc(sizeof(String)); + str = (String *) DohObjMalloc(sizeof(String)); DohInit(str); str->objinfo = &StringType; str->hashkey = -1; @@ -185,7 +185,7 @@ CopyString(DOH *so) { str->line = 1; str->pbi = 0; max = s->maxsize; - str->str = (char *) malloc(max); + str->str = (char *) DohMalloc(max); memmove(str->str, s->str, max); str->maxsize= max; str->len = s->len; @@ -201,8 +201,8 @@ DelString(DOH *so) { String *s; s = (String *) so; assert(s->refcount <= 0); - free(s->str); - DohFree(s); + DohFree(s->str); + DohObjFree(s); } /* ----------------------------------------------------------------------------- @@ -293,7 +293,7 @@ add(String *s, const char *newstr) { if (newlen >= s->maxsize-1) { newmaxsize = 2*s->maxsize; if (newlen >= newmaxsize -1) newmaxsize = newlen + 1; - assert(s->str = (char *) realloc(s->str,newmaxsize)); + assert(s->str = (char *) DohRealloc(s->str,newmaxsize)); s->maxsize = newmaxsize; } strcpy(s->str+s->len,newstr); @@ -311,7 +311,7 @@ addstr(String *s, String *s1) { if (newlen >= s->maxsize-1) { newmaxsize = 2*s->maxsize; if (newlen >= newmaxsize -1) newmaxsize = newlen + 1; - assert(s->str = (char *) realloc(s->str,newmaxsize)); + assert(s->str = (char *) DohRealloc(s->str,newmaxsize)); s->maxsize = newmaxsize; } memmove(s->str+s->len,s1->str,s1->len); @@ -327,7 +327,7 @@ String_addchar(DOH *so, char c) { String *s = (String *) so; s->hashkey = -1; if ((s->len+1) > (s->maxsize-1)) { - assert(s->str = (char *) realloc(s->str,2*s->maxsize)); + assert(s->str = (char *) DohRealloc(s->str,2*s->maxsize)); s->maxsize *= 2; } s->str[s->len] = c; @@ -342,7 +342,7 @@ String_addchar(DOH *so, char c) { void String_expand(String *s, int width) { if ((s->len + width) > (s->maxsize-1)) { - assert(s->str = (char *) realloc(s->str,(s->len + width)+1)); + assert(s->str = (char *) DohRealloc(s->str,(s->len + width)+1)); s->maxsize = s->len + width + 1; } } @@ -381,7 +381,7 @@ raw_insert(String *s, int pos, char *data, int len) /* See if there is room to insert the new data */ while (s->maxsize <= s->len+len) { - assert(s->str = (char *) realloc(s->str,2*s->maxsize)); + assert(s->str = (char *) DohRealloc(s->str,2*s->maxsize)); s->maxsize *= 2; } memmove(s->str+pos+len, s->str+pos, (s->len - pos)); @@ -482,7 +482,7 @@ String_write(DOH *so, void *buffer, int len) { s->hashkey = -1; newlen = s->sp + len+1; if (newlen > s->maxsize) { - assert(s->str = (char *) realloc(s->str,newlen)); + assert(s->str = (char *) DohRealloc(s->str,newlen)); s->maxsize = newlen; s->len = s->sp + len; } @@ -622,7 +622,7 @@ void replace_internal(String *str, char *token, char *rep, int flags, char *star t = strstr(c,token); if (t) { str->len = 0; - str->str = (char *) malloc(str->maxsize); + str->str = (char *) DohMalloc(str->maxsize); if (start) { char temp = *start; *start = 0; @@ -697,7 +697,7 @@ void replace_internal(String *str, char *token, char *rep, int flags, char *star } else { add(str,t); } - free(s); + DohFree(s); } } diff --git a/SWIG/Source/DOH/Doh/void.c b/SWIG/Source/DOH/Doh/void.c index 00aecedad..14c324f29 100644 --- a/SWIG/Source/DOH/Doh/void.c +++ b/SWIG/Source/DOH/Doh/void.c @@ -60,7 +60,7 @@ static DohObjInfo DohVoidType = { DOH *NewVoid(void *obj, void (*del)(void *)) { VoidObj *v; - v = (VoidObj *) DohMalloc(sizeof(VoidObj)); + v = (VoidObj *) DohObjMalloc(sizeof(VoidObj)); DohInit(v); v->objinfo = &DohVoidType; v->ptr = obj; @@ -73,7 +73,7 @@ void Void_delete(DOH *vo) { if (v->del) { (*v->del)(v->ptr); } - free(v); + DohObjFree(v); } DOH *Void_copy(DOH *vo) { diff --git a/SWIG/Source/DOH/Include/doh.h b/SWIG/Source/DOH/Include/doh.h index c51c539ce..1901ca58f 100644 --- a/SWIG/Source/DOH/Include/doh.h +++ b/SWIG/Source/DOH/Include/doh.h @@ -26,6 +26,12 @@ #include #include +#define DOH_MAJOR_VERSION 0 +#define DOH_MINOR_VERSION 1 + +extern int _DohMemoryCurrent; +extern int _DohMemoryHigh; + typedef void DOH; #define DOH_BEGIN -1 @@ -109,11 +115,15 @@ typedef struct DohObjInfo { } DohObjInfo; /* Memory management */ -extern void *DohMalloc(int size); +extern void *DohMalloc(size_t size); +extern void *DohObjMalloc(size_t size); extern void DohFree(DOH *ptr); -extern int DohFreeCheck(DOH *ptr); +extern void DohObjFree(DOH *ptr); +extern int DohObjFreeCheck(DOH *ptr); extern int DohCheck(DOH *ptr); extern int DohFreeCheck(DOH *ptr); +extern int DohMemoryUse(); +extern int DohMemoryHigh(); /* Low-level doh methods. Do not call directly (well, unless you want to). */ extern void DohError(int level, char *fmt,...); diff --git a/SWIG/Source/DOH/install-sh b/SWIG/Source/DOH/install-sh new file mode 100755 index 000000000..0ff4b6a08 --- /dev/null +++ b/SWIG/Source/DOH/install-sh @@ -0,0 +1,119 @@ +#!/bin/sh + +# +# install - install a program, script, or datafile +# This comes from X11R5; it is not part of GNU. +# +# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ +# +# This script is compatible with the BSD install script, but was written +# from scratch. +# + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" + +instcmd="$mvprog" +chmodcmd="" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +fi + +if [ x"$dst" = x ] +then + echo "install: no destination specified" + exit 1 +fi + + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + +if [ -d $dst ] +then + dst="$dst"/`basename $src` +fi + +# Make a temp file name in the proper directory. + +dstdir=`dirname $dst` +dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + +$doit $instcmd $src $dsttmp + +# and set any options; do chmod last to preserve setuid bits + +if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi +if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi +if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi +if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi + +# Now rename the file to the real destination. + +$doit $rmcmd $dst +$doit $mvcmd $dsttmp $dst + + +exit 0