Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
XCOMM $XConsortium: Imakefile /main/14 1996/08/21 15:54:08 drk $
XCOMM ** WARNING **
XCOMM
XCOMM The files named here may appear in many different Imakefiles.
XCOMM If you add or remove a file, be sure to update all locations.
XCOMM It's unfortunate, but all this redundancy serves a purpose.
XCOMM
XCOMM Other possible locations are:
XCOMM .../lib/DtMmdb/Imakefile
XCOMM .../lib/DtMmdb/<subdir>/Imakefile
XCOMM .../programs/dtinfo/mmdb/Imakefile
XCOMM .../programs/dtinfo/mmdb/<subdir>/Imakefile
#define DoNormalLib NormalLibDtMmdb
#define DoSharedLib SharedLibDtMmdb
#define DoDebugLib DebugLibDtMmdb
#define DoProfileLib ProfileLibDtMmdb
#define LibName DtMmdb
#define SoRev SODTMMDBREV
#define LibHeaders NO
#define LibCreate NO
#define LargePICTable YES
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
XCOMM In DtMmdb we compile as C_API sources.
DEFINES = -DC_API -DPORTABLE_DB
INCLUDES = -I.. $(EXCEPTIONS_INCLUDES) -I../misc
BASE_SRCS = \
funcs.C ostring.C pm_random.C atoi_pearson.C \
xtime.C buffer.C atoi_larson.C atomic_lock.C \
rw_lock.C atoi_fast.C filter.C mmdb_exception.C \
randomize.C
C_API_SRCS = \
streambuf.C charbuf.C filebuf.C strstream.C \
iostream.C fstream.C stream.C ios.C
SRCS = $(BASE_SRCS) $(C_API_SRCS)
OBJS = $(BASE_SRCS:.C=.o) $(C_API_SRCS:.C=.o)
#include <Library.tmpl>
SubdirLibraryRule($(OBJS))
DependTarget()

View File

@@ -0,0 +1,171 @@
/*
* $XConsortium: atoi_fast.cc /main/3 1996/06/11 17:35:24 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/atoi_fast.h"
#define MASK 0xff
atoi_fast::atoi_fast(int r, int l)
{
pm_random rdm_generator;
init(r, l, rdm_generator);
}
atoi_fast::atoi_fast(int r, int l, pm_random& rdm_generator)
{
init(r, l, rdm_generator);
}
void atoi_fast::init(int r, int, pm_random& rdm_generator)
{
v_entries = 256;
v_range = r;
v_mask = 0;
v_tbl = new char[v_entries];
for ( int i = 0; i < v_entries; i++ )
v_tbl[i] = i;
for ( i = 0; i < v_entries - 1; i++ ) {
char_swap(v_tbl[rdm_generator.rand() % ( v_entries - i ) + i],
v_tbl[i]
);
}
v_no_bytes = 4;
}
atoi_fast::~atoi_fast()
{
delete v_tbl;
}
struct reg_t {
unsigned b4: 8;
unsigned b3: 8;
unsigned b2: 8;
unsigned b1: 8;
};
union u_tag {
struct reg_t chars_val;
unsigned int hash_val;
};
int atoi_fast::atoi(const key_type& k, int offset) const
{
char* string = k.get();
int l = k.size();
return atoi((const char*)string, l, offset, 0);
}
int atoi_fast::atoi(const char* string, int l, int , int rang ) const
{
u_tag reg ;
reg.hash_val = 0;
switch (l) {
case 0:
break;
case 1:
reg.chars_val.b1 = v_tbl[string[0]] ;
break;
case 2:
reg.chars_val.b1 = v_tbl[string[0]] ;
reg.chars_val.b2 = v_tbl[string[1]] ;
break;
case 3:
reg.chars_val.b1 = v_tbl[string[0]] ;
reg.chars_val.b2 = v_tbl[string[1]] ;
reg.chars_val.b3 = v_tbl[string[2]] ;
break;
default:
reg.chars_val.b1 = v_tbl[string[0]] ;
reg.chars_val.b2 = v_tbl[string[1]] ;
reg.chars_val.b3 = v_tbl[string[2]] ;
reg.chars_val.b4 = v_tbl[string[3]] ;
}
int x = 0;
for ( int j=1; j<l; j++ ) {
x ^= string[j];
}
reg.chars_val.b1 |= x;
reg.chars_val.b2 |= x;
reg.chars_val.b3 |= x;
reg.chars_val.b4 |= x;
/*
if ( ( rang == 0 && v_range > 65535 ) ||
( rang > 65535 )
)
{
reg.chars_val.b3 |= x;
reg.chars_val.b4 |= x;
}
*/
/*
int x = string[0]+offset;
reg.chars_val.b1 = x ;
reg.chars_val.b2 = x + 1;
if ( v_range > 65535 ) {
reg.chars_val.b3 = x+2;
reg.chars_val.b4 = x+3;
}
for ( int j=1; j<l; j++ ) {
reg.chars_val.b1 += string[j];
reg.chars_val.b2 += string[j];
if ( v_range > 65535 ) {
reg.chars_val.b3 += string[j];
reg.chars_val.b4 += string[j];
}
}
*/
return (rang == 0 ) ?
( reg.hash_val % v_range )
:
( reg.hash_val % rang );
}
int atoi_fast::atoi(const char* str, int offset, int rang ) const
{
return atoi(str, strlen(str), offset, rang);
}
ostream& operator<<(ostream& s, atoi_fast& p)
{
for ( int i = 0; i < p.v_entries ; i++ )
s << int(p.v_tbl[i]) << " ";
return s;
}

View File

@@ -0,0 +1,58 @@
/*
* $XConsortium: atoi_fast.h /main/3 1996/06/11 17:35:30 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _atoi_fast_h
#define _atoi_fast_h 1
#include "utility/funcs.h"
#include "utility/pm_random.h"
#include "utility/key.h"
class atoi_fast
{
public:
atoi_fast(int _range, int _entries) ;
atoi_fast(int _range, int _entries, pm_random&) ;
virtual ~atoi_fast() ;
virtual int atoi(const key_type& k, int offset = 0) const ;
int atoi(const char* str, int _offset = 0, int range = 0) const ;
int atoi(const char* str, int sz, int _offset = 0, int range = 0) const ;
int size() { return v_entries; } ;
friend ostream& operator<<(ostream&, atoi_fast&);
private:
void init(int _range, int _entries, pm_random&);
protected:
char *v_tbl;
unsigned v_mask;
unsigned int v_entries;
unsigned int v_range;
unsigned int v_no_bytes;
};
#endif

View File

@@ -0,0 +1,65 @@
/*
* $XConsortium: atoi_larson.cc /main/3 1996/06/11 17:35:35 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/atoi_larson.h"
atoi_larson::atoi_larson(int _range) : v_range(_range)
{
}
atoi_larson::~atoi_larson()
{
}
int
atoi_larson::atoi(const char* str, int offset, int rang) const
{
return atoi(str, strlen(str), offset, rang);
}
int
atoi_larson::atoi(const char* str, int sz, int, int rang) const
{
unsigned int sum = 0;
for ( int i=0; i<sz; i++ ) {
sum *= 37;
sum += str[i];
}
return sum % ((rang == 0) ? v_range : rang);
}
int
atoi_larson::atoi(const key_type& k, int) const
{
char* string = k.get();
int l = k.size();
unsigned int sum = 0;
for ( int i=0; i<l; i++ ) {
//sum *= 37;
sum <<= 7;
sum |= string[i];
}
return sum % v_range;
}

View File

@@ -0,0 +1,50 @@
/*
* $XConsortium: atoi_larson.h /main/3 1996/06/11 17:35:41 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _atoi_larson_h
#define _atoi_larson_h 1
#include <values.h>
#include "key.h"
// Based on Larson's algorithm presented in CACM ???.
class atoi_larson
{
public:
atoi_larson(int _range = MAXINT) ;
virtual ~atoi_larson() ;
// argument offset has no effect.
int atoi(const key_type& k, int _offset = 0) const ;
int atoi(const char* str, int _offset = 0, int range = 0) const ;
int atoi(const char* str, int sz, int _offset = 0, int range = 0) const ;
protected:
int v_range;
};
#endif

View File

@@ -0,0 +1,177 @@
/*
* $XConsortium: atoi_pearson.cc /main/6 1996/06/11 17:35:45 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/config.h"
#include "utility/atoi_pearson.h"
#define MASK 0xff
atoi_pearson::atoi_pearson(int r, int l): v_shared(false)
{
pm_random rdm_generator;
init(r, l, rdm_generator);
}
atoi_pearson::atoi_pearson(int r, int l, pm_random& rdm_generator) :
v_shared(false)
{
init(r, l, rdm_generator);
}
atoi_pearson::atoi_pearson(int r, int, char* shared_tbl) :
v_entries(256), v_range(r), v_mask(0xff),
v_no_bytes(4), v_tbl(shared_tbl), v_shared(true)
{
}
void atoi_pearson::init(int r, int, pm_random& rdm_generator)
{
v_entries = 256;
v_range = r;
v_mask = 0xff;
v_no_bytes = 4;
v_tbl = new char[v_entries];
for ( int i = 0; i < v_entries; i++ )
v_tbl[i] = i;
/*
MESSAGE(cerr, "atoi_pearson::init()");
for ( i = 0; i < v_entries; i++ )
cerr << int(v_tbl[i]) << " ";
cerr << "\n";
*/
int l;
for ( i = 0; i < v_entries - 1; i++ ) {
l = rdm_generator.rand() % ( v_entries - i ) + i;
char_swap(v_tbl[l], v_tbl[i]);
}
/*
MESSAGE(cerr, "atoi_pearson::init()");
for ( i = 0; i < v_entries; i++ )
cerr << int(v_tbl[i]) << " ";
cerr << "\n";
*/
}
atoi_pearson::~atoi_pearson()
{
if ( v_shared == false )
delete v_tbl;
}
struct reg_t {
#ifdef MMDB_BIG_ENDIAN
unsigned b4: 8;
unsigned b3: 8;
unsigned b2: 8;
unsigned b1: 8;
#endif
#ifdef MMDB_LITTLE_ENDIAN
unsigned b1: 8;
unsigned b2: 8;
unsigned b3: 8;
unsigned b4: 8;
#endif
};
union u_tag {
struct reg_t chars_val;
unsigned int hash_val;
} ;
int atoi_pearson::atoi(const key_type& k, int offset) const
{
char* string = k.get();
int l = k.size();
return atoi((const char*)string, l, offset, 0);
}
int atoi_pearson::atoi(const char* string, int l, int offset, int rang ) const
{
u_tag reg ;
reg.hash_val = 0;
int x = string[0] + offset;
reg.chars_val.b1 = v_tbl[x & MASK];
reg.chars_val.b2 = v_tbl[(x+1) & MASK];
if ( v_range > 65535 ) {
reg.chars_val.b3 = v_tbl[(x + 2) & MASK];
reg.chars_val.b4 = v_tbl[(x + 3) & MASK];
}
for ( int j= 1; j<l; j++ ) {
reg.chars_val.b1 = v_tbl[ reg.chars_val.b1 ^ string[j] ];
reg.chars_val.b2 = v_tbl[ reg.chars_val.b2 ^ string[j] ];
if ( v_range > 65535 ) {
reg.chars_val.b3 = v_tbl[( reg.chars_val.b3 ^ string[j] ) ];
reg.chars_val.b4 = v_tbl[( reg.chars_val.b4 ^ string[j] ) ];
}
}
return (rang == 0 ) ?
( reg.hash_val % v_range )
:
( reg.hash_val % rang );
}
int atoi_pearson::atoi(const char* str, int offset, int rang ) const
{
return atoi(str, strlen(str), offset, rang);
}
ostream& operator<<(ostream& s, atoi_pearson& p)
{
for ( int i = 0; i < p.v_entries ; i++ )
s << int(p.v_tbl[i]) << " ";
return s;
}
/* ########################################### */
/* */
/* ########################################### */
/*
int atoi_sum::atoi(const char* string, int l)
{
}
atoi_sum::size()
{
}
ostream& operator<<(ostream& s, atoi_sum& t)
{
return s;
}
*/

View File

@@ -0,0 +1,66 @@
/*
* $XConsortium: atoi_pearson.h /main/3 1996/06/11 17:35:50 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _atoi_pearson_h
#define _atoi_pearson_h 1
#include "utility/funcs.h"
#include "utility/pm_random.h"
#include "utility/key.h"
// Based on Pearson's algorithm presented in CACM 90/6.
// rewritten to speed up atoi()
class atoi_pearson
{
public:
atoi_pearson(int _range, int _entries) ;
atoi_pearson(int _range, int _entries, pm_random&) ;
atoi_pearson(int _range, int _entries, char* v_tbl) ;
virtual ~atoi_pearson() ;
virtual int atoi(const key_type& k, int offset = 0) const ;
int atoi(const char* str, int _offset = 0, int range = 0) const ;
int atoi(const char* str, int sz, int _offset = 0, int range = 0) const ;
int size() { return v_entries; } ;
char* tblPtr() { return v_tbl; } ;
friend ostream& operator<<(ostream&, atoi_pearson&);
private:
void init(int _range, int _entries, pm_random&);
protected:
char *v_tbl;
Boolean v_shared;
unsigned v_mask;
unsigned int v_entries;
unsigned int v_range;
unsigned int v_no_bytes;
};
#endif

View File

@@ -0,0 +1,76 @@
/*
* $XConsortium: atomic_lock.C /main/4 1996/11/01 10:19:09 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "atomic_lock.h"
#include <X11/Xosdefs.h>
#include <errno.h>
#ifdef X_NOT_STDC_ENV
extern int errno;
#endif
atomic_lock::atomic_lock(const char* p)
{
strcpy(v_path, p);
}
atomic_lock::~atomic_lock()
{
}
/////////////////////////////////////////
// from Rochkind's Adv. UNIX programming
/////////////////////////////////////////
Boolean atomic_lock::lock()
{
int fd, tries;
tries = 0;
while ( (fd = creat(v_path, 0)) == -1 && errno == EACCES ) {
if ( ++tries >= MAXTRIES )
break;
sleep (NAPTIME);
}
if ( fd == -1 || close(fd) == -1 ) {
perror("lock");
return false;
} else
return true;
}
Boolean atomic_lock::unlock()
{
if ( unlink(v_path) == -1 ) {
MESSAGE(cerr, "unlock(): unlink() failed");
throw(systemException(errno));
}
return true;
}

View File

@@ -0,0 +1,55 @@
/*
* $XConsortium: atomic_lock.h /main/3 1996/06/11 17:36:00 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _atomic_lock_h
#define _atomic_lock_h 1
#include <fcntl.h>
#include <errno.h>
#include "utility/funcs.h"
#define NAPTIME 5
#define MAXTRIES 3
class atomic_lock
{
public:
atomic_lock(const char* path);
~atomic_lock();
Boolean lock();
Boolean unlock();
protected:
char v_path[PATHSIZ];
};
#endif

View File

@@ -0,0 +1,474 @@
/*
* $TOG: buffer.C /main/9 1998/04/17 11:50:56 mgreess $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/buffer.h"
/***********************************************************/
// Constructor
/***********************************************************/
/*
buffer::buffer(const int sz)
{
_alloc(sz);
}
*/
buffer::buffer(buffer& original): v_swap_order(original.v_swap_order)
{
_alloc(original.v_bufsz);
memcpy(v_aptr, original.v_aptr, original.v_bufsz);
}
void buffer::_alloc(const int sz)
{
int void_ptr_size = sizeof(voidPtr);
v_bufsz = sz;
if ( sz > 0 ) {
v_base = ::new char[void_ptr_size+sz];
memset(v_base, (char)0, void_ptr_size+sz);
v_align_offset = int(void_ptr_size - long(v_base) % void_ptr_size);
if (v_align_offset != void_ptr_size)
v_base += v_align_offset;
else
v_align_offset = 0;
v_allocated = 1;
} else {
v_base = 0;
v_allocated = 0;
}
v_aptr = v_eptr = v_base;
}
/***********************************************************/
// Destructor
/***********************************************************/
buffer::~buffer()
{
if ( v_allocated == 1 ) {
free((char*)(v_base-v_align_offset));
}
}
void buffer::reset()
{
v_eptr = v_base;
v_aptr = v_base;
memset(v_base, (char)0, v_bufsz);
}
/*
void buffer::set_chunk(char* ptr, const int sz)
{
bufsz = sz;
eptr = aptr = base = ptr;
allocated = 0;
}
void buffer::set_content_sz(const int sz)
{
eptr = base + sz;
}
*/
/***********************************************************/
// Expand buffer chunk to newsz.
/***********************************************************/
int buffer::expand_chunk(const int newsz)
{
if ( v_allocated == 0 )
throw(stringException("expand a buffer with reference memory"));
int cursz = buf_sz();
if ( newsz <= cursz ) {
v_bufsz = newsz;
return 0;
}
int void_ptr_size = sizeof(voidPtr);
//MESSAGE(cerr, "real expand");
//char* x = (char*)malloc(void_ptr_size+newsz);
char* x = ::new char [void_ptr_size+newsz];
int delta = int(void_ptr_size - long(x) % void_ptr_size);
x += delta ;
memcpy(x, v_base, cursz);
memset(x+cursz, char(0), newsz - cursz);
v_aptr -= long(v_base);
v_eptr -= long(v_base);
//free((char*)(v_base-v_align_offset));
delete (char*)(v_base-v_align_offset);
v_align_offset = delta;
v_base = x;
v_aptr += long(v_base);
v_eptr += long(v_base);
v_bufsz = newsz;
return 0;
}
#if defined(linux)
#define CASTBNDEXCEPT (boundaryException*)
#else
#define CASTBNDEXCEPT
#endif
/***********************************************************/
// Get sz chars to the array x. x is supposed allocated
/***********************************************************/
buffer& buffer::get(char *x, int sz)
{
if ( sz + v_aptr > v_eptr ) {
MESSAGE(cerr, "buffer::get(): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(sz + v_aptr) ));
}
memcpy(x, v_aptr, sz);
v_aptr += sz;
return *this;
}
/***********************************************************/
// skip i chars.
/***********************************************************/
buffer& buffer::skip(int i)
{
if ( i + v_aptr > v_eptr )
MESSAGE(cerr, "buffer::skip(): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(i + v_aptr) ));
v_aptr += i;
return *this;
}
/***********************************************************/
// Get a char to y.
/***********************************************************/
buffer& buffer::get(char& y)
{
if ( v_aptr > v_eptr) {
MESSAGE(cerr, "buffer::get(char&): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(1+v_aptr)));
}
y = *v_aptr;
v_aptr++;
return *this;
}
buffer& buffer::getusc(int& y)
{
y = *(unsigned char*)v_aptr;
v_aptr++;
return *this;
}
/***********************************************************/
// Get an integer to y. option can be ASCII or BINARY.
/***********************************************************/
buffer& buffer::get(int& y)
{
unsigned int x;
get(x);
y = (int)x;
return *this;
}
buffer& buffer::get(unsigned int& y)
{
if ( v_aptr + sizeof(y) > v_eptr ) {
MESSAGE(cerr, "buffer::get(int&): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(sizeof(unsigned)+v_aptr)));
}
get((char*)&y, sizeof(y));
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_UINT(y);
#endif
return *this;
}
/***********************************************************/
// Get a long to y. option can be ASCII or BINARY.
/***********************************************************/
buffer& buffer::get(long& y)
{
//MESSAGE(cerr, "WARNING: buffer::get(long& y) +++++++++++++++++++++++");
if ( v_aptr + sizeof(y) > v_eptr ) {
MESSAGE(cerr, "buffer::get(long&): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(sizeof(long)+v_aptr)));
}
get((char*)&y, sizeof(y));
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_LONG(y);
#endif
return *this;
}
/***********************************************************/
// Get a float to y.
/***********************************************************/
buffer& buffer::get(float& y)
{
if ( v_aptr + sizeof(y) > v_eptr ) {
MESSAGE(cerr, "buffer::get(float &): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(sizeof(float)+v_aptr)));
}
get((char*)&y, sizeof(y));
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_FLOAT(y);
#endif
return *this;
}
buffer& buffer::get(unsigned short& y)
{
if ( v_aptr + sizeof(y) > v_eptr ) {
MESSAGE(cerr, "buffer::get(float &): underflow");
throw ( CASTBNDEXCEPT boundaryException( long(v_aptr), long(v_eptr), long(sizeof(float)+v_aptr)));
}
get((char*)&y, sizeof(y));
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_USHORT(y);
#endif
return *this;
}
/***********************************************************/
// Put a char to buffer.
/***********************************************************/
buffer& buffer::put(const char content, Boolean exp_buf)
{
//return put((char*)&content, sizeof(content));
if ( v_bufsz == content_sz() )
{
if ( exp_buf == true )
expand_chunk(v_bufsz + 10);
else {
MESSAGE( cerr, "buffer::put(const char): overflow");
throw ( CASTBNDEXCEPT boundaryException(content_sz(), v_bufsz, 1) );
}
}
*v_eptr = content;
v_eptr++;
return *this;
}
buffer& buffer::put(const unsigned char content, Boolean exp_buf)
{
return put((char*)&content, sizeof(content), exp_buf);
}
/***********************************************************/
// Put a unsigned int to buffer.
/***********************************************************/
buffer& buffer::put(const int content, Boolean exp_buf)
{
return put((unsigned int)content, exp_buf);
}
buffer& buffer::put(const unsigned int content, Boolean exp_buf)
{
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_UINT(content);
#endif
return put((char*)&content, sizeof(content), exp_buf);
}
/***********************************************************/
// Put a long to buffer.
/***********************************************************/
buffer& buffer::put(const long content, Boolean exp_buf)
{
//MESSAGE(cerr, "WARNING: buffer::put(long& y) =====================");
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_LONG(content);
#endif
return put((char*)&content, sizeof(content), exp_buf);
}
/***********************************************************/
// Put a unsigned short to buffer.
/***********************************************************/
buffer& buffer::put(const unsigned short content, Boolean exp_buf)
{
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_USHORT(content);
#endif
return put((char*)&content, sizeof(content), exp_buf);
}
/***********************************************************/
// Put a float to buffer.
/***********************************************************/
buffer& buffer::put(const float content, Boolean exp_buf)
{
#ifdef PORTABLE_DB
if ( v_swap_order == true )
ORDER_SWAP_FLOAT(content);
#endif
return put((char*)&content, sizeof(content), exp_buf);
}
/***********************************************************/
// Put sz chars to buffer.
/***********************************************************/
buffer& buffer::put(const char* content, int sz, Boolean exp_buf)
{
if ( sz > v_bufsz - content_sz() ) {
if ( exp_buf == true )
expand_chunk(v_bufsz + sz);
else {
MESSAGE( cerr, "buffer::put(char*, int): overflow");
throw ( CASTBNDEXCEPT boundaryException(content_sz(), v_bufsz, sz) );
}
}
//memcpy(v_eptr, content, sz);
//debug(cerr, int(v_base));
//debug(cerr, int(v_eptr));
for ( int i=0; i<sz; i++ ) {
v_eptr[i] = content[i];
//debug(cerr, int(v_eptr[i]));
}
v_eptr += sz;
return *this;
}
Boolean operator ==(buffer&x, buffer& y)
{
if ( x.content_sz() != y.content_sz() ) {
debug(cerr, x.content_sz());
debug(cerr, y.content_sz());
}
unsigned char* x_buf = (unsigned char*)x.get_base();
unsigned char* y_buf = (unsigned char*)y.get_base();
for ( int i=0; i<x.content_sz(); i++ ) {
if ( x_buf[i] != y_buf[i] ) {
debug(cerr, i);
debug(cerr, x_buf[i]);
debug(cerr, y_buf[i]);
#ifndef __osf__
debug(cerr, hex(x_buf[i]));
debug(cerr, hex(y_buf[i]));
#endif
//return false;
}
}
return true;
}
/***********************************************************/
// show content
/***********************************************************/
ostream& operator<<(ostream& s, buffer& b)
{
//debug(s, b.bufsz);
//debug(s, b.content_sz());
//debug(s, b.base);
//debug(s, b.eptr);
//debug(s, b.aptr);
int x = b.v_eptr - b.v_base ;
for ( int i = 0; i < x; i++ ) {
s << b.v_base[i];
/*
if ( isprint(b.v_base[i]) )
cout << b.v_base[i];
else
cout << int(b.v_base[i]);
*/
}
MESSAGE(cerr, "buffer=");
for ( i = 0; i < x; i++ ) {
cout << int(b.v_base[i]) << " ";
}
cout << endl;
return s;
}
/*
void buffer::cdrIn(buffer& buf)
{
buf.get(v_bufsz);
buf.get(v_base, v_bufsz);
}
void buffer::cdrOut(buffer& buf)
{
buf.put(v_bufsz);
buf.put(v_base, v_bufsz);
}
*/

View File

@@ -0,0 +1,114 @@
/*
* $XConsortium: buffer.h /main/6 1996/08/15 14:21:05 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _buffer_h
#define _buffer_h 1
#include <ctype.h>
#include "utility/funcs.h"
class buffer
{
public:
buffer(const int sz = 1024) : v_swap_order(false) { _alloc(sz); };
buffer(buffer&);
virtual ~buffer();
// buffer management functions
virtual void reset(); // clean the buffer
int expand_chunk(const int); // expand buffer chunk
void set_chunk(char* ptr, const int sz) {
v_bufsz = sz;
v_eptr = v_aptr = v_base = ptr;
v_allocated = 0;
}; // set buffer chunk
void set_content_sz(const int sz) {v_eptr = v_base + sz;} ;
// buffer status functions
int buf_sz() const { return v_bufsz; }; // chunk length
int content_sz() const { return v_eptr - v_aptr; }; // content length
int remaining_sz() const { return v_bufsz - int(v_eptr - v_aptr); }; // remaining space
char* get_base() const { return v_base; }; // get 'base'
// get items
buffer& get(char& y); // get current char
buffer& get(unsigned short& y); // get a short
buffer& get(unsigned int& y); // get a unsigned int
buffer& get(int& y); // get an int
buffer& get(long& y); // get a long
buffer& get(float & y); // get a float
buffer& get(char*, int) ; // get a string
buffer& getusc(int& y); // get unsigned char to intr.
// no boundary checking
// put items
buffer& put(const char content, Boolean exp_buf = false) ; // append char
buffer& put(const unsigned char, Boolean exp_buf = false) ; //append unsigned char
buffer& put(const int, Boolean exp_buf = false) ; // append an int
buffer& put(const unsigned int, Boolean exp_buf = false) ; // append a unsigned int
buffer& put(const long, Boolean exp_buf = false) ; // append a long
buffer& put(const unsigned short, Boolean exp_buf = false) ; //append a short
buffer& put(const float y, Boolean exp_buf = false); // put a float
buffer& put(const char*, int, Boolean exp_buf = false) ; // append a string
buffer& skip(int i) ; // skip i chars
// set and get byte order
void set_swap_order(Boolean x) { v_swap_order = x; };
Boolean get_swap_order() { return v_swap_order; };
friend Boolean operator ==(buffer&, buffer&);
// show the buffer
friend ostream& operator <<(ostream&, buffer&);
friend class abs_storage;
friend class unixf_storage;
friend class page_storage;
friend class mem_storage;
friend class page_cache_global_part;
protected:
char v_allocated;
unsigned int v_bufsz ; // allocated chunk size
char *v_base ; // base address of the chunk
char *v_eptr ; // end address of the buf content
char *v_aptr ; // beginning address of the buf content
int v_align_offset; // memory align offset
Boolean v_swap_order;
protected:
void _alloc(const int sz);
};
typedef buffer* bufferPtr;
#endif

View File

@@ -0,0 +1,20 @@
/* $XConsortium: c_charbuf.h /main/4 1996/08/21 15:54:16 drk $ */
#ifndef _charbuf_h
#define _charbuf_h
#include "utility/c_streambuf.h"
class charbuf : public streambuf
{
protected:
protected:
public:
charbuf(char* p, int l, int pHasContent = 0);
~charbuf();
};
#endif

View File

@@ -0,0 +1,49 @@
/* $XConsortium: c_filebuf.h /main/4 1996/08/21 15:54:26 drk $ */
#ifndef _x_filebuf_h
#define _x_filebuf_h
#include "utility/c_streambuf.h"
#include "utility/c_ios.h"
class filebuf : public streambuf
{
protected:
int _fd;
int _mode;
int _prev_action;
char* _name;
streampos current_pos;
streampos new_pos;
streampos default_new_pos;
protected:
void notify(int action_t);
void _notify(int action_t);
int overflow();
int underflow() ;
int _seek();
int _seek(streampos pos, int whence);
int _write(char* ptr, int size);
public:
filebuf(int fd);
filebuf(const char* name, int mode, int protect = 0644);
~filebuf();
int fd() { return _fd; };
int is_open();
int open(const char* name, int mode, int protect = 0644);
int close();
int flush() ;
int seekg(streampos delta) ;
};
#endif

View File

@@ -0,0 +1,31 @@
/* $XConsortium: c_fstream.h /main/5 1996/08/21 15:54:38 drk $ */
#ifndef _x_fstream_h
#define _x_fstream_h
#include "utility/c_filebuf.h"
#include "utility/c_iostream.h"
class fstream : public iostream
{
public:
fstream ();
fstream (int fd);
fstream (const char* name, int mode, int protect = 0644);
~fstream();
void open(const char* name, int mode, int protect = 0644);
void close();
filebuf* rdbuf();
};
extern fstream xcout;
extern fstream xcerr;
extern fstream xcin;
#endif

View File

@@ -0,0 +1,42 @@
/* $XConsortium: c_ios.h /main/4 1996/08/21 15:54:50 drk $ */
#ifndef _ios_h
#define _ios_h
#include "utility/macro.h"
#include "utility/c_streambuf.h"
class ios
{
protected:
int f_state;
streambuf* sbuf; // buffer that provides char sequence read/write
public:
enum open_mode { in=1, out=2, app=4, trunc=8 };
enum seek_dir { beg=0, cur=1, end=2 } ;
enum states { OK=0, BAD=1, FAIL=2 } ;
ios(streambuf* sb = 0);
virtual ~ios();
int rdstate() { return f_state; };
int fail() ;
int bad() ;
int good() {
return !(fail() || bad()) ;
};
void set_bad() { f_state |= BAD;};
void set_fail() { f_state |= FAIL;};
void clear() { f_state = OK; };
int operator!() { return fail(); };
operator void*() { return (void*)good(); };
};
#endif

View File

@@ -0,0 +1,82 @@
/* $XConsortium: c_iostream.h /main/4 1996/08/21 15:54:57 drk $ */
#ifndef _xostream_h
#define _xostream_h
#include "utility/c_ios.h"
class istream : public virtual ios
{
protected:
istream& _getline(char* b, int lim, int delim, int fill_zero);
int eatw(); // return EOF if no char available.
// Otherwise, return the first no white char.
// The char is still in the buffer.
public:
istream(streambuf* sb);
virtual ~istream() {};
istream& seekg(streampos delta, ios::seek_dir d) ;
int get();
istream& get(char& c);
istream& putback(char c);
istream& getline(char* b, int lim, char delim='\n');
istream& read(char* s,int n);
int gcount() ;
istream& operator>>(unsigned short& c);
istream& operator>>(unsigned int& c);
istream& operator>>(int& c);
istream& operator>>(long& c);
istream& operator>>(char* s);
istream& operator>>(char& c);
};
class ostream : virtual public ios
{
public:
ostream(streambuf* sb);
virtual ~ostream() {};
ostream& operator<<(void*);
ostream& operator<<(const char*);
ostream& operator<<(char c);
ostream& operator<<(int);
ostream& operator<<(unsigned int);
ostream& operator<<(long);
ostream& operator<< (ostream& (*f)(ostream&));
ostream& put(char);
ostream& flush() ;
ostream& write(const char* s,int n);
};
//class iostream : public istream, public ostream
class iostream : public istream, public ostream
{
public:
iostream(streambuf* sb);
virtual ~iostream() {};
};
ostream& endl(ostream& i) ;
#ifndef STREAM_DEBUG
#define cout (*cout_ptr)
#define cin (*cin_ptr)
#define cerr (*cerr_ptr)
extern ostream *cout_ptr;
extern istream *cin_ptr;
extern ostream *cerr_ptr;
#endif
#endif

View File

@@ -0,0 +1,10 @@
/* $XConsortium: c_stream.h /main/4 1996/08/21 15:55:10 drk $ */
#ifndef _x_stream_h
#define _x_stream_h
#include "utility/c_streambuf.h"
extern char* form(const char* ...);
#endif

View File

@@ -0,0 +1,95 @@
/* $XConsortium: streambuf.h /main/4 1996/06/11 17:39:15 cde-hal $ */
#ifndef _x_streambuf_h
#define _x_streambuf_h
#ifdef EOF
#if EOF!=-1
#define EOF (-1)
#endif
#else
#define EOF (-1)
#endif
typedef long streampos;
#ifdef STREAM_DEBUG
#define form x_form
#define streambuf x_streambuf
#define filebuf x_filebuf
#define ios x_ios
#define iostream x_iostream
#define istream x_istream
#define ostream x_ostream
#define fstream x_fstream
#define istrstream x_istrstream
#define ostrstream x_ostrstream
#endif
class streambuf
{
protected:
char* base;
char* end;
char* get_ptr;
char* put_ptr;
int _gcount;
int _pcount;
int _capacity;
int _size;
int _alloc;
protected:
enum notify_action_t { GET, PUT };
virtual void notify(int) {};
virtual int overflow() { return EOF;};
virtual int underflow() { return EOF; };
int full() { return ( _size == _capacity ) ? 1 : 0 ; };
int empty() { return ( _size == 0 ) ? 1 : 0 ; };
void empty_buffer() {
_size = 0;
put_ptr = get_ptr = base;
};
int move_get_ptr(int);
int move_put_ptr(int);
public:
streambuf();
streambuf(char* p, int l, int pHasContent = 0);
virtual ~streambuf();
virtual int examine() ; // EOF: no char available. Otherwise,
// return 0.The get_ptr pointer does
// not move.
virtual int get() ; // EOF: can't get a char. Otherwise,
// return 0. The get_ptr pointer does move.
virtual int putback(char c) ; // EOF: can't put back. Otherwise,
// putback operation is ok.
virtual int put(char c) ; // EOF: can't put. Otherwise,
// put operation is ok.
int gcount() { return _gcount; };
void clear_gcount() { _gcount = 0; };
int pcount() { return _pcount; };
void clear_pcount() { _pcount = 0; };
virtual int flush() { return EOF; };
virtual int seekg(streampos) { return EOF; };
char* get_buf() { return base; };
};
#endif

View File

@@ -0,0 +1,29 @@
/* $XConsortium: c_strstream.h /main/5 1996/08/21 15:55:22 drk $ */
#ifndef _strstream_h
#define _strstream_h
#include <string.h>
#include "utility/c_iostream.h"
class istrstream : public istream
{
public:
istrstream(char* str, int size) ;
istrstream(char* str);
~istrstream() ;
};
class ostrstream : public ostream
{
public:
ostrstream(char* str, int size, int=ios::out);
~ostrstream() ;
int pcount() ;
char* str();
};
#endif

View File

@@ -0,0 +1,14 @@
// $XConsortium: charbuf.C /main/4 1996/08/21 15:54:12 drk $
#include "utility/c_charbuf.h"
charbuf::charbuf(char* p, int l, int bufferFull) : streambuf(p, l, bufferFull)
{
}
charbuf::~charbuf()
{
}

View File

@@ -0,0 +1,24 @@
/* $XConsortium: config.h /main/4 1996/06/11 17:36:26 cde-hal $ */
#ifndef _config_h
#define _config_h 1
#ifdef OLIAS_LITTLE_ENDIAN
# define MMDB_LITTLE_ENDIAN // i386
#else
# ifdef OLIAS_BIG_ENDIAN
# define MMDB_BIG_ENDIAN // sun, rs/6000, hp, uxpds
# else
# ifdef OLIAS_DEFAULT_ENDIAN
# ifdef MMDB_BIG_ENDIAN
# undef MMDB_BIG_ENDIAN
# endif
# ifdef MMDB_LITTLE_ENDIAN
# undef MMDB_LITTLE_ENDIAN
# endif
# endif
# endif
#endif
#endif

View File

@@ -0,0 +1,61 @@
/*
* $XConsortium: const.h /main/4 1996/06/11 17:36:31 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _const_h
#define _const_h 1
#define KB 1024
#define PATHSIZ 256
#define NAMESIZ 50
#ifndef LBUFSIZ
#define LBUFSIZ (8*KB)
#endif
#define PAGSIZ LBUFSIZ
#ifndef CACHE_PAGES
#define CACHE_PAGES 500
#endif
#ifndef TOTAL_MEM_PAGES
#define TOTAL_MEM_PAGES 4000
#endif
#define LIST_MARK_CHAR '#' // LIST_MARK_CHAR encloses
// short_list elements. Used in
// short_list::asciiIn(), and
// dl_list::asciiIn().
#define CommentChar '#'
#endif

View File

@@ -0,0 +1,333 @@
// $XConsortium: core_fstream.C /main/4 1996/10/04 10:47:25 drk $
#include <stdlib.h>
#include <string.h>
void filebuf_exam_test1()
{
fprintf(stderr, "fstream test1 : read\n");
fstream fb("stream_test.read", ios::in|ios::out);
char buf[10];
for ( int i=0; i<2; i++ ) {
fb.read(buf, 4);
fprintf(stderr, "buf[0]=%c\n", buf[0]);
fprintf(stderr, "buf[1]=%c\n", buf[1]);
fprintf(stderr, "buf[2]=%c\n", buf[2]);
fprintf(stderr, "buf[3]=%c\n", buf[3]);
fprintf(stderr, "gcount=%d\n", fb.gcount());
}
}
void filebuf_exam_test2()
{
fprintf(stderr, "fstream test2 : write \n");
fstream fb("/tmp/stream_test.write", ios::in|ios::out|ios::trunc);
char* buf = "abcdefghijklmnopq";
for ( int i=0; i<2; i++ ) {
fb.write(buf+i*4, 4);
}
system("cmp stream_test.write /tmp/stream_test.write");
system("rm /tmp/stream_test.write");
}
void filebuf_exam_test3()
{
fprintf(stderr, "fstream test3 : getline\n");
fstream fb("stream_test.getline", ios::in|ios::out);
char buf[100];
while ( fb.getline(buf, 100) ) {
fprintf(stderr, "buf=%s\n", buf);
fprintf(stderr, "gcount=%d\n", fb.gcount());
}
}
void filebuf_exam_test4()
{
fprintf(stderr, "fstream test4 : word counting\n");
fstream fb("stream_test.mobydick", ios::in);
char buf[50];
char largest[50];
int curlen, max = -1, cnt = 0;
while ( fb >> buf ) {
curlen = strlen(buf);
++cnt;
if ( curlen > max ) {
max = curlen;
memcpy(largest, buf, strlen(buf));
}
}
fprintf(stderr, "# of words read is = %d\n", cnt);
fprintf(stderr, "the longest word has a length of = %d\n", max);
fprintf(stderr, "the longest word is = %s\n", largest);
}
void filebuf_exam_test5()
{
fprintf(stderr, "fstream test 5: (extraction)\n");
fstream fb("stream_test.extraction", ios::in|ios::out);
int x;
long y;
char c;
unsigned short u;
unsigned int v;
// read
// int long char (u)short (u)int
fb >> x; fprintf(stderr, "x=%d\n", x);
fprintf(stderr, "gcount=%d\n", fb.gcount());
fb >> y; fprintf(stderr, "y=%ld\n", y);
fprintf(stderr, "gcount=%d\n", fb.gcount());
fb >> c; fprintf(stderr, "c=%c\n", c);
fprintf(stderr, "gcount=%d\n", fb.gcount());
fb >> u; fprintf(stderr, "u=%d\n", u);
fprintf(stderr, "gcount=%d\n", fb.gcount());
fb >> v; fprintf(stderr, "v=%d\n", v);
fprintf(stderr, "gcount=%d\n", fb.gcount());
}
void filebuf_exam_test6()
{
fprintf(stderr, "fstream test 6: (mixed insertion and extraction [1]) \n");
system("cp stream_test.mixed_ins_extr /tmp/stream_test.mixed_ins_extr");
fstream fb("/tmp/stream_test.mixed_ins_extr", ios::in|ios::out);
int x;
long y;
char c;
unsigned short u;
unsigned int v;
// read
// int long char (u)short (u)int
fb >> x; fprintf(stderr, "x=%d\n", x);
fb >> y; fprintf(stderr, "y=%ld\n", y);
c = '0'; fb << c;
c = '1'; fb << c;
system("diff stream_test.mixed_ins_extr /tmp/stream_test.mixed_ins_extr");
}
void filebuf_exam_test7()
{
fprintf(stderr, "fstream test 7: (mixed insertion and extraction [2]) \n");
system("cp stream_test.mixed_ins_extr.2 /tmp/stream_test.mixed_ins_extr.2");
fstream fb("/tmp/stream_test.mixed_ins_extr.2", ios::in|ios::out|ios::trunc);
int x = 1;
long y = 2;
char c;
fb << x << y << "abcdefghijk";
fb.seekg(9, ios::beg);
fb >> c; fprintf(stderr, "c=%c\n", c);
fb >> c; fprintf(stderr, "c=%c\n", c);
system("diff /tmp/stream_test.mixed_ins_extr.2 stream_test.mixed_ins_extr.2");
system("rm /tmp/stream_test.mixed_ins_extr.2");
}
void filebuf_exam_test8()
{
fprintf(stderr, "fstream test 8: (seek and read) \n");
fstream fb("stream_test.seek_and_read", ios::in|ios::out);
fb.seekg(10, ios::beg);
char c;
fb >> c; fprintf(stderr, "c=%c\n", c);
fb >> c; fprintf(stderr, "c=%c\n", c);
fb.seekg(20, ios::beg);
fb >> c; fprintf(stderr, "c=%c\n", c);
fb >> c; fprintf(stderr, "c=%c\n", c);
}
void filebuf_exam_test9()
{
fprintf(stderr, "fstream test 9: (append) \n");
system("rm -f /tmp/stream_test.append");
fstream fb("/tmp/stream_test.append", ios::app);
fb << "lseek() sets the seek";
fb << " pointer associated with the open";
system("diff /tmp/stream_test.append stream_test.append");
system("rm /tmp/stream_test.append");
}
void filebuf_exam_test10()
{
fprintf(stderr, "fstream test 10: (cerr) \n");
fstream fb(2);
fb << "cerr: lseek() sets the seek\n";
fb << "cerr: pointer associated with the open\n";
fstream fb1(1);
fb1 << "cout::lseek() sets the seek\n";
fb1 << "cout:: pointer associated with the open\n";
}
void filebuf_exam_test11(char* nm)
{
fprintf(stderr, "fstream test11 : getline (2)\n");
fstream fb(nm, ios::in);
char buf[100];
while ( fb.getline(buf, 100) ) {
fprintf(stderr, "buf=%s\n", buf);
fprintf(stderr, "gcount=%d\n", fb.gcount());
}
}
void filebuf_exam_test12()
{
fprintf(stderr, "fstream test12 : write (2)\n");
fstream fb("/tmp/stream_test.write", ios::out);
char* buf = "abcdefghijklmnopq";
for ( int i=0; i<2; i++ ) {
fb.write(buf+i*4, 4);
}
system("diff stream_test.write /tmp/stream_test.write");
system("rm /tmp/stream_test.write");
}
void filebuf_exam_test13(char* nm, int pos)
{
fprintf(stderr, "fstream test13 : read (2)\n");
fstream fb(nm, ios::in);
char buf[8192];
fb.seekg(pos, ios::beg);
int len = 8192;
fb.read(buf, len);
fprintf(stderr, "len=%d\n", len);
fprintf(stderr, "gcount=%d\n", fb.gcount());
}
void filebuf_exam_test14(char* nm)
{
fprintf(stderr, "fstream test14 : write (3)\n");
fstream fb(nm, ios::out);
char* buf = "abcdefghijklmnopq";
for ( int i=0; i<2; i++ ) {
fb.write(buf+i*4, 4);
}
}
void usage(char** argv)
{
fprintf(stderr, "Usage: %s option\n", argv[0]);
fprintf(stderr, "option = 1: read\n");
fprintf(stderr, " 2: write\n");
fprintf(stderr, " 3: getline\n");
fprintf(stderr, " 4: word counting\n");
fprintf(stderr, " 5: extraction\n");
fprintf(stderr, " 6: mixed insertion/extraction [1]\n");
fprintf(stderr, " 7: mixed insertion/extraction [2]\n");
fprintf(stderr, " 8: seek and read\n");
fprintf(stderr, " 9: append\n");
fprintf(stderr, " 10: cerr\n");
fprintf(stderr, " 11: getline (2). arguments: 11 filename\n");
fprintf(stderr, " 12: write (2)\n");
fprintf(stderr, " 13: read (2). arg: 13 filename offset\n");
fprintf(stderr, " 14: write (3). arg: 14 filename\n");
}
int main(int argc, char** argv)
{
if ( argc <= 1 ) {
usage(argv);
return 1;
}
int i = atoi(argv[1]);
switch (i) {
case 1:
filebuf_exam_test1();
break;
case 2:
filebuf_exam_test2();
break;
case 3:
filebuf_exam_test3();
break;
case 4:
filebuf_exam_test4();
break;
case 5:
filebuf_exam_test5();
break;
case 6:
filebuf_exam_test6();
break;
case 7:
filebuf_exam_test7();
break;
case 8:
filebuf_exam_test8();
break;
case 9:
filebuf_exam_test9();
break;
case 10:
filebuf_exam_test10();
break;
case 11:
if ( argc == 3 )
filebuf_exam_test11(argv[2]);
else
usage(argv);
break;
case 12:
filebuf_exam_test12();
break;
case 13:
if ( argc == 4 )
filebuf_exam_test13(argv[2], atoi(argv[3]));
break;
case 14:
if ( argc == 3 )
filebuf_exam_test14(argv[2]);
break;
default:
filebuf_exam_test1();
filebuf_exam_test2();
filebuf_exam_test3();
filebuf_exam_test4();
filebuf_exam_test5();
filebuf_exam_test6();
filebuf_exam_test7();
filebuf_exam_test8();
filebuf_exam_test9();
filebuf_exam_test10();
filebuf_exam_test12();
}
return 0;
}

View File

@@ -0,0 +1,10 @@
/* $XConsortium: db_version.h /main/4 1996/06/11 17:36:43 cde-hal $ */
#ifndef _db_version_h
#define _db_version_h 1
#define MAJOR 2
#define MINOR 3
#endif

View File

@@ -0,0 +1,50 @@
/*
* $XConsortium: debug.h /main/5 1996/07/18 14:57:44 drk $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _debug_h
#define _debug_h 1
#ifdef DEBUG
#if !defined ( __STDC__) && !defined (hpux) && !defined(__osf__)
#define debug(s, x) s << "x" << " = " << (x) << "\n"
#else
#define debug(s, x) s << #x << " = " << (x) << "\n"
#endif
#define MESSAGE(s, x) s << x << "\n"
#else /* DEBUG */
#define debug(s,x)
#define MESSAGE(s,x)
#endif /* DEBUG */
#ifndef C_API
#define STDERR_MESSAGE(x) cerr << x << "\n";
#else
#define STDERR_MESSAGE(x) fprintf(stderr, "%s\n", x);
#endif
#endif

View File

@@ -0,0 +1,278 @@
/* $XConsortium: filebuf.C /main/9 1996/10/04 10:44:52 drk $ */
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#if !defined(hpux) && !defined(__osf__) && !defined(USL)
#include <sysent.h>
#endif
#include <fcntl.h>
#include <string.h>
#include "utility/c_filebuf.h"
#include <sys/stat.h>
filebuf::~filebuf()
{
close();
delete _name;
}
/////////////////////////////////////////////
// only current_pos is used.
/////////////////////////////////////////////
filebuf::filebuf(int __fd) :
new_pos(0), default_new_pos(0), _fd(__fd), current_pos(0),
_prev_action(-1), _name(0)
{
_mode = 0;
struct stat statbuf;
if ( fstat(_fd, &statbuf ) == 0 ) {
if ( BIT_TEST( statbuf.st_mode, S_IRUSR) )
_mode |= ios::in;
if ( BIT_TEST( statbuf.st_mode, S_IWUSR) )
_mode |= ios::out;
} else {
_mode = 0;
}
}
filebuf::filebuf(const char* name, int mode, int protect) :
new_pos(0), default_new_pos(0), current_pos(0),
_fd(-1), _prev_action(-1), _name(strdup(name))
{
open(name, mode, protect);
}
int filebuf::open(const char* name, int mode, int protect)
{
if ( _fd != -1 &&
_name && strcmp(name, _name) == 0 &&
mode == _mode
)
return 0;
close();
delete _name; _name = strdup(name);
_mode = mode;
int flag = 0;
if ( BIT_TEST(mode, ios::app) || BIT_TEST(mode, ios::out) ) {
if ( BIT_TEST(mode, ios::in) )
flag |= O_RDWR;
else
flag |= O_WRONLY;
} else {
if ( BIT_TEST(mode, ios::in) )
flag |= O_RDONLY;
}
if ( BIT_TEST(mode, ios::trunc) ||
(
BIT_TEST(mode, ios::trunc) &&
!(BIT_TEST(mode, ios::in)||BIT_TEST(mode, ios::app))
)
)
flag |= O_TRUNC;
//fprintf(stderr, "flag=%x\n", flag);
_fd = ::open(name, flag);
if ( _fd < 0 ) {
//fprintf(stderr, "use O_CREAT\n");
flag |= O_CREAT;
_fd = ::open(name, flag, protect);
}
if ( _fd >= 0 ) {
//fprintf(stderr, "filebuf::open OK, name = %s, fd = %d, this = %d\n", name, _fd, (void*)this);
return 0;
} else
return EOF;
}
int filebuf::close()
{
if ( _prev_action == streambuf::PUT )
flush();
::close(_fd);
_fd = -1;
return 0;
}
int filebuf::is_open()
{
return (_fd>=0) ? 1 : 0;
}
void filebuf::notify(int action_t)
{
if ( _prev_action == -1 ) {
_prev_action = action_t;
} else
if ( _prev_action != action_t )
_notify(action_t);
}
void filebuf::_notify(int action_t)
{
switch ( action_t ) {
case streambuf::GET:
//////////////////////////////////////////////////////////////
// previous action was PUT. Now calculate the number of chars
// that have been put and write them out.
//
// Note: put_ptr always starts at base. And at this time,
// get_ptr == base.
//
//////////////////////////////////////////////////////////////
overflow();
break;
case streambuf::PUT:
//////////////////////////////////////////////////////////////
// previous action was a GET.
//
// Note: get_ptr always starts at base.
//
//////////////////////////////////////////////////////////////
empty_buffer();
break;
default:
return;
}
_prev_action = action_t;
}
int filebuf::_write(char* ptr, int size)
{
//fprintf(stderr, "_write() size = %d, fd = %d\n", size, _fd);
int _written_size = ::write(_fd, ptr, size);
if ( _written_size != size ) {
//fprintf(stderr, "fwrite only writes %d bytes\n.", size - _written_size);
return EOF;
}
return _written_size;
}
int filebuf::overflow()
{
// write to the file if possible and clean the buffer
if ( !BIT_TEST(_mode, ios::out) && !BIT_TEST(_mode, ios::app) )
return EOF;
if ( _size == 0 ) return 0;
if ( BIT_TEST(_mode, ios::app) ) {
if ( _seek(0L, SEEK_END) != 0 ) return EOF;
} else
if ( _seek() != 0 ) return EOF;
int ok;
if ( get_ptr + _size <= end ) {
ok = _write(get_ptr, _size);
} else {
int l = end - get_ptr;
ok = _write(get_ptr, l);
if ( ok != EOF )
ok = _write(base, _size - l);
}
if ( ok == EOF ) return EOF;
current_pos += _size;
empty_buffer();
return ok;
}
int filebuf::underflow()
{
// get more from the file if possible
if ( !BIT_TEST(_mode, ios::in) )
return EOF;
if ( _seek() != 0 ) return EOF;
_size = ::read(_fd, base, _capacity);
//fprintf(stderr, "read in _underflow() this = %d, _size = %d, current_pos = %d, fd = %d\n", (void*)this, _size, current_pos, _fd);
if (_size <=0)
return EOF;
else {
get_ptr = base;
put_ptr = base + _size;
}
current_pos += _size;
return 0;
}
int filebuf::_seek()
{
//fprintf(stderr, "_seek() [1] current_pos= %d\n", current_pos);
if ( ::lseek(_fd, current_pos, SEEK_SET) == -1 ) {
fprintf(stderr, "lseek failed. current_pos= %ld\n", current_pos);
return EOF;
} else
return 0;
}
int filebuf::_seek(streampos pos, int whence)
{
//fprintf(stderr, "_seek() [2]: pos= %d, whence=%d\n", pos, whence);
current_pos = pos;
if ( ::lseek(_fd, pos, whence) == -1 ) {
fprintf(stderr, "lseek failed. pos= %ld, whence=%d\n", pos, whence);
return EOF;
} else
return 0;
}
int filebuf::seekg(long delta)
{
if ( _prev_action == streambuf::PUT )
overflow();
else
empty_buffer();
current_pos = delta;
return 0;
}
int filebuf::flush()
{
if ( overflow() == EOF )
return EOF;
if ( ::fsync(_fd) != 0 )
return EOF;
else
return 0;
}

View File

@@ -0,0 +1,14 @@
// $XConsortium: filter.cc /main/3 1996/06/11 17:36:55 cde-hal $
#include "utility/filter.h"
Boolean filter::v_assign = false;
filter_func_t filter::f_filt_func;
filter::filter()
{
}
filter::~filter()
{
}

View File

@@ -0,0 +1,70 @@
/*
* $XConsortium: filter.h /main/4 1996/08/21 15:54:29 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _filter_h
#define _filter_h 1
#ifdef C_API
#include "utility/c_strstream.h"
#else
#include <strstream.h>
#endif
#include "utility/funcs.h"
#include "utility/buffer.h"
typedef istream& (*filter_func_t)(istream&);
class filter
{
public:
filter();
virtual ~filter() ;
static Boolean assigned() { return v_assign; };
static filter_func_t filter_func() { return f_filt_func; } ;
static void reset_filter_func() { v_assign = false; };
static void set_filter_func(filter_func_t f)
{
v_assign = true;
f_filt_func = f;
};
protected:
static Boolean v_assign;
static filter_func_t f_filt_func;
};
typedef filter* filterPtr;
#endif

View File

@@ -0,0 +1,42 @@
// $XConsortium: fstream.C /main/5 1996/08/21 15:54:34 drk $
#include "utility/c_fstream.h"
istream* cin_ptr = 0;
ostream* cout_ptr = 0;
ostream* cerr_ptr = 0;
fstream::fstream () : iostream(new filebuf(-1))
{
}
fstream::fstream (int fd) : iostream(new filebuf(fd))
{
}
fstream::fstream (const char* name, int mode, int protect) :
iostream(new filebuf(name, mode, protect))
{
}
fstream::~fstream()
{
this -> close();
}
void fstream::open(const char* name, int mode, int protect)
{
((filebuf*)sbuf) -> open(name, mode, protect);
}
void fstream::close()
{
((filebuf*)sbuf) -> close();
}
filebuf* fstream::rdbuf()
{
return (filebuf*)sbuf;
}

View File

@@ -0,0 +1,784 @@
/*
* $TOG: funcs.C /main/16 1998/04/17 11:51:14 mgreess $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/funcs.h"
#include "unique_id.h"
#define X_INCLUDE_TIME_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
/* Imake stuff defines SYSV; this code uses SVR4 ... here's the quick-fix */
#if defined(SYSV) && ! defined(SVR4)
#define SVR4
#endif
#ifdef SVR4
#include <sys/utsname.h>
#endif
#if defined(linux)
#include <sys/vfs.h>
#elif defined(_AIX)
#include <sys/vfs.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
#else
#include <sys/statvfs.h>
#endif
#ifdef __osf__
extern "C"
{
int statvfs(const char *, struct statvfs *);
int getdomainname(char *, int);
}
#endif /* __osf__ */
#include <sys/stat.h>
#ifdef USL
int _DtMmdbStrcasecmp(register const char* s1, register const char* s2)
{
register int c1, c2;
while (*s1 && *s2) {
c1 = isupper(*s1) ? tolower(*s1) : *s1;
c2 = isupper(*s2) ? tolower(*s2) : *s2;
if (c1 != c2)
return (c1 - c2);
s1++;
s2++;
}
return (int) (*s1 - *s2);
}
int _DtMmdbStrncasecmp(register const char* s1,
register const char* s2,
register int count)
{
register int c1, c2;
if (!count)
return 0;
while (*s1 && *s2) {
c1 = isupper(*s1) ? tolower(*s1) : *s1;
c2 = isupper(*s2) ? tolower(*s2) : *s2;
if ((c1 != c2) || (! --count))
return (c1 - c2);
s1++;
s2++;
}
return (int) (*s1 - *s2);
}
#endif
#ifdef mips
#include <sys/utsname.h>
int gethostname(char* name, int namelen)
{
struct utsname myuname;
if ( uname(&myuname) != 0 ) {
MESSAGE(cerr, "gethostname(): uname() failed");
throw(Exception());
}
int l = strlen(myuname.nodename);
if ( l >= namelen ) {
cerr << "gethostname(): name array too short.\n";
throw(Exception());
} else
memcpy(name, myuname.nodename, l);
return 0;
}
#endif
int compare_stream(ostrstream& x, ostrstream& y)
{
if ( x.pcount() != y.pcount() ) {
cerr << x.pcount() << "---" << y.pcount() << endl;
//debug(cerr, x.str());
//debug(cerr, y.str());
return 1;
} else {
char* u = x.str();
char* v = y.str();
//debug(cerr, u);
//debug(cerr, v);
//fprintf(stderr, "u=%s, pcount() = %d\n", u, x.pcount());
//fprintf(stderr, "v=%s, pcount() = %d\n", v, y.pcount());
if ( memcmp(u, v, x.pcount()) != 0 ) {
STDERR_MESSAGE("two streams do not match.");
debug(cerr, u);
debug(cerr, v);
return 1;
} else {
//STDERR_MESSAGE("two streams match.");
return 0;
}
}
}
/*
float flog2(unsigned int x)
{
return (float)(log((double)x) / log((double)2));
}
float flog2(const float x)
{
return (float)log((double)x) / (float)log((float)2);
}
int pow2(const int x)
{
return (int)pow((double)2, (double)x);
}
int pow2(const float x)
{
return (int)pow((double)2, (double)x);
}
int bits(const int x)
{
return (int)flog2((unsigned int)x);
}
*/
int pos_of_LSB(const unsigned int y)
{
switch (y) {
case 8192: return 14;
case 1024: return 11;
default:
{
unsigned int x = y;
//debug(cerr, x);
//debug(cerr, hex(x));
for ( int i =0; i<sizeof(x); i++ ) {
if ( ( 0x000000ff & x) == 0 )
x >>= 8;
else
break;
}
//debug(cerr, i);
for ( int j =1; j<=8; j++ )
if ( (0x00000001 & x) == 0 )
x >>= 1;
else
break;
//debug(cerr, j);
//debug(cerr, i*8+j);
return i*8 + j;
}
}
}
/*
void char_swap(char& c1, char& c2)
{
char tmp = c1;
c1 = c2;
c2 = tmp;
}
void short_swap(short& c1, short& c2)
{
short tmp = c1;
c1 = c2;
c2 = tmp;
}
void int_swap(int& c1, int& c2)
{
int tmp = c1;
c1 = c2;
c2 = tmp;
}
*/
int ceiling(const float x)
{
if ( int(x) > x )
return int(x)+1;
else
return int(x);
}
unsigned getbits(unsigned x, unsigned p, unsigned n)
{
return((x>> (p-n)) & ~(~0 << n));
}
int del_file(const char* filename, const char* pathname)
{
static char buf[512];
int ok;
if ( pathname == 0 )
ok = unlink(filename);
else {
if ( strlen(filename) + strlen(pathname) > 511 )
throw(boundaryException(1, 512, strlen(filename) + strlen(pathname)));
buf[0] = 0;
strcpy(buf, pathname);
strcat(buf, "/");
strcat(buf, filename);
ok = unlink(buf);
}
if ( ok == -1 ) {
debug(cerr, pathname);
debug(cerr, filename);
MESSAGE(cerr, form("unlink %s/%s failed", pathname, filename));
throw(systemException(errno));
}
return 0;
}
Boolean copy_file(const char* source, const char* sink)
{
fstream in(source, ios::in);
fstream out(sink, ios::out);
if ( !in || ! out )
return false;
int c;
while ( (c=in.get()) != EOF ) {
out.put((unsigned char)c);
}
in.close();
if ( out.fail() )
return false;
else
return true;
}
Boolean
copy_file(const char* path, const char* file,
const char* source_ext, const char* target_ext)
{
char source[PATHSIZ];
char target[PATHSIZ];
sprintf(source, "%s/%s.%s", path, file, source_ext);
sprintf(target, "%s/%s.%s", path, file, target_ext);
return copy_file(source, target) ;
}
Boolean exist_file(const char* filename, const char* pathname)
{
int ok;
struct stat stat_info;
if ( pathname )
ok = stat(form("%s/%s", pathname, filename), &stat_info);
else
ok = stat( filename, &stat_info );
if ( ok == 0 )
return S_ISREG(stat_info.st_mode) ? true : false ;
switch (errno) {
case ENOENT:
return false;
default:
MESSAGE(cerr, "exist_file(): stat() failed. an exception");
throw(systemException(errno));
}
}
int check_file(istream& in, const char* msg)
{
char c;
in.get(c);
in.putback(c);
cerr << c << " " << (int)c << " <---" << msg << "\n";
return 0;
}
Boolean
cat_file(const char* source1, const char* source2, const char* target)
{
/*
MESSAGE(cerr, "in cat_file");
debug(cerr, source1);
debug(cerr, source2);
debug(cerr, target);
*/
fstream in1(source1, ios::in);
fstream out(target, ios::out);
if ( !in1 || ! out )
return false;
char buf[BUFSIZ];
while ( in1.getline(buf, BUFSIZ) ) {
out << buf;
if ( in1.gcount() < BUFSIZ - 1 )
out << '\n';
}
in1.close();
fstream in2(source2, ios::in);
if ( !in2 )
return false;
while ( in2.getline(buf, BUFSIZ) ) {
out << buf;
if ( in2.gcount() < BUFSIZ - 1 )
out << '\n';
}
in2.close();
out.close();
return ( out.fail() ) ? false : true;
}
Boolean exist_dir(const char* pathname)
{
struct stat stat_info;
if ( stat( pathname, &stat_info ) == 0 )
return S_ISDIR(stat_info.st_mode) ? true : false ;
switch ( errno ) {
case ENOENT:
return false;
default:
MESSAGE(cerr, "exist_dir() failed");
debug(cerr, pathname);
throw(systemException(errno));
}
}
Boolean check_and_create_dir(const char* path)
{
if ( exist_dir(path) == true )
return true;
const char* path_tail = path + 1; // skip the first '/'
char* slash_ptr;
// create the subdirecties
while ( path_tail[0] != 0 &&
( slash_ptr = strchr(path_tail, '/') ) ) {
path_tail = slash_ptr + 1; // set for the next check
slash_ptr[0] = 0; // temp. set the slash to 0.
//debug(cerr, path);
if ( exist_dir(path) == false ) {
if ( mkdir(path, 0777) != 0 ) {
debug(cerr, path);
slash_ptr[0] = '/'; //reset to '/'
perror(0);
MESSAGE(cerr, form( "mkdir failed on path %s", path));
throw(systemException(errno));
}
}
slash_ptr[0] = '/'; //reset to '/'
}
// create the full path
if ( mkdir(path, 0777) != 0 ) {
cerr << "mkdir failed on path " << path << "\n";
throw(systemException(errno));
}
return true;
}
static
int open_prot(int min, int def)
{
int prot;
umask(prot = umask(0));
prot = min | (def & ~(prot & 0777));
return prot;
}
int open_file_prot()
{
return open_prot(0600,0666);
}
int open_dir_prot()
{
return open_prot(0700,0777);
}
Boolean int_eq(void* x, void* y)
{
if ( *(int*)x == *(int*)y )
return true;
else
return false;
}
Boolean int_ls(void* x, void* y)
{
if ( *(int*)x < *(int*)y )
return true;
else
return false;
}
int ll4(int x)
{
int u = sizeof(void*);
int delta = x % u ;
return ( delta == 0 ) ? x : x + u - delta;
}
//Boolean fcntl_lock( int fd, lock_t lt )
//{
// flock flock_record;
//
// switch ( lt ) {
// case SHARED:
// flock_record.l_type = F_RDLCK;
// break;
// case EXCLUSIVE:
// flock_record.l_type = F_WRLCK;
// break;
// default:
// perror("fcntl_lock(): unknown lock type");
// exit(-2);
// }
//
///****************************/
//// the entire file is locked
///****************************/
// flock_record.l_whence = SEEK_SET,
// flock_record.l_start = 0;
// flock_record.l_len = 0;
//
// if ( fcntl(fd, F_SETLKW, (int)&flock_record) != -1 ) {
// return true;
// } else {
// return false;
// }
//}
//
//Boolean fcntl_unlock( int fd )
//{
// flock flock_record;
//
///****************************/
//// the entire file is unlocked
///****************************/
// flock_record.l_type = F_UNLCK;
// flock_record.l_whence = SEEK_SET;
// flock_record.l_start = 0;
// flock_record.l_len = 0;
//
// if ( fcntl(fd, F_SETLKW, (int)&flock_record) != -1 ) {
// return true;
// } else
// return false;
//}
//
//static Boolean time_out;
//
//Boolean timed_lock(int fd, lock_t lt, int seconds)
//{
// signal(SIGALRM, (SIG_PF)onalarm);
// alarm(seconds);
// time_out = false;
//
// while ( fcntl_lock(fd, lt) == false ) {
// switch ( errno ) {
// case EINTR:
//
// if ( time_out == true ) {
//#ifdef DEBUG
// MESSAGE(cerr, "time out after");
// debug(cerr, seconds);
//#endif
// return false;
// }
//
// break;
//
// default:
//#ifdef DEBUG
// MESSAGE(cerr, "error in fcntl_lock()");
// perror(0);
// debug(cerr, fd);
//#endif
// return false;
// }
// }
// signal(SIGALRM, SIG_IGN);
// return true;
//}
//
//Boolean timed_unlock(int fd, int seconds)
//{
// signal(SIGALRM, (SIG_PF)onalarm);
// alarm(seconds);
// time_out = false;
//
// while ( fcntl_unlock(fd) == false ) {
// switch ( errno ) {
// case EINTR:
//
// if ( time_out == true )
// return false;
//
// break;
//
// default:
// return false;
// }
// }
// signal(SIGALRM, SIG_IGN);
// return true;
//}
//
//void onalarm(int)
//{
// time_out = true;
//}
static
char* time_stamp(_Xctimeparams *ctime_buf)
{
time_t x;
time(&x);
return _XCtime(&x, *ctime_buf);
}
int bytes(fstream& fs)
{
struct stat file_info;
if ( fstat( fs.rdbuf() -> fd(), &file_info) != 0 )
return 0;
else
return int(file_info.st_size);
}
int bytes(int fd)
{
struct stat file_info;
if ( fstat( fd, &file_info) != 0 )
return 0;
else
return int(file_info.st_size);
}
static char info_buf[BUFSIZ];
char* access_info( char* request )
{
#ifndef SVR4
char dm_name[PATHSIZ];
int dm_name_sz = PATHSIZ;
if ( getdomainname(dm_name, dm_name_sz) == -1 ) {
MESSAGE(cerr, "getdomainname() failed");
throw(systemException(errno));
}
#endif
#ifdef SVR4
struct utsname name ;
uname(&name);
#else
char host_name[PATHSIZ];
int host_name_sz = PATHSIZ;
if ( gethostname(host_name, host_name_sz) == -1 ) {
MESSAGE(cerr, "gethostname() failed");
throw(systemException(errno));
}
#endif
_Xctimeparams ctime_buf;
char* x = time_stamp(&ctime_buf);
x[strlen(x)-1] = 0;
char userid[L_cuserid];
#ifndef SVR4
sprintf(info_buf, "%s-%s-%s-%ld-%s-%s",
host_name, dm_name,
( cuserid(userid)[0] == 0 ) ? "???" : userid,
/* getenv("USER"), */
(long)getpid(), x, request
);
#else
sprintf(info_buf, "%s-%s-%ld-%s-%s",
name.nodename,
( cuserid(userid)[0] == 0 ) ? "???" : userid,
/* getenv("USER"), */
(long)getpid(), x, request
);
#endif
return info_buf;
}
void lsb_putbits(unsigned& target, unsigned position_from_lsb,
unsigned bits, unsigned source)
{
target |= ((source & ~( ~0 << bits )) << position_from_lsb) ;
}
unsigned lsb_getbits(unsigned source, unsigned position_from_lsb, unsigned bits)
{
return ( ( source >> position_from_lsb ) & ~( ~0 << bits ) );
}
Boolean cc_is_digit(istream& in)
{
int c = in.get();
int ok = isdigit(c);
in.putback(c);
return ( ok ) ? true : false;
}
unsigned long disk_space(const char* path)
{
#if defined(__osf__) || defined (hpux) || defined (SVR4)
struct statvfs statfs_buf;
#else
struct statfs statfs_buf;
#endif
long free_bytes;
#if defined(__osf__) || defined (hpux) || defined (SVR4)
if ( statvfs(path, &statfs_buf) == 0 ) {
free_bytes = statfs_buf.f_bavail * statfs_buf.f_frsize ;
#else
if ( statfs(path, &statfs_buf) == 0 ) {
free_bytes = statfs_buf.f_bavail * statfs_buf.f_bsize ;
#endif
} else {
throw(stringException(form("statfs failed on %s", path)));
}
return free_bytes;
}
Boolean writeToTmpFile(char* unique_nm, char* str, int size)
{
Boolean ok = false;
fstream *out = 0;
char* tmp_dir_tbl[4];
tmp_dir_tbl[0] = getenv("TMPDIR");
tmp_dir_tbl[1] = "/tmp";
tmp_dir_tbl[2] = "/usr/tmp";
tmp_dir_tbl[3] = getenv("HOME");
int tmp_dir_tbl_size = 4;
const char* uid = unique_id();
for ( int i=0; i<tmp_dir_tbl_size; i++ ) {
if ( tmp_dir_tbl[i] == 0 )
continue;
strcpy(unique_nm, form("%s/tmp.%s", tmp_dir_tbl[i], uid));
try {
//debug(cerr, tmp_dir_tbl[i]);
//debug(cerr, disk_space(tmp_dir_tbl[i]));
if ( disk_space(tmp_dir_tbl[i]) <= size )
continue;
out = new fstream(unique_nm, ios::out);
if ( !(*out) ) {
delete out;
continue;
}
if ( ! (out->write(str, size) ) ) {
out -> close();
delete out;
del_file(unique_nm);
continue;
} else {
ok = true;
out -> close();
delete out;
break;
}
}
catch_any()
{
continue;
}
end_try;
}
return ok;
}

View File

@@ -0,0 +1,209 @@
/*
* $XConsortium: funcs.h /main/12 1996/09/13 20:48:55 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _funcs_h
#define _funcs_h 1
#if !defined(USL) && !defined(__osf__)
#include <libc.h>
#endif
#if defined(hpux) || defined(sgi) || defined(USL) ||defined(__osf__)
#include <unistd.h>
#else
#include <sysent.h>
#endif
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef C_API
#include "utility/c_stream.h"
#include "utility/c_fstream.h"
#include "utility/c_strstream.h"
#else
#include <assert.h>
#include <stream.h>
#include <fstream.h>
#include <strstream.h>
#endif
#include <math.h>
#ifdef __CENTERLINE__
// centerline does not define these
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif
#include "utility/debug.h"
#include "utility/types.h"
#include "utility/const.h"
#include "utility/macro.h"
#include "utility/mmdb_exception.h"
#ifdef USL
int _DtMmdbStrcasecmp(const char *s1, const char *s2);
int _DtMmdbStrncasecmp(const char *s1, const char *s2, int n);
#define strcasecmp(s1,s2) _DtMmdbStrcasecmp(s1,s2)
#define strncasecmp(s1,s2,n) _DtMmdbStrncasecmp(s1,s2,n)
#endif
#ifdef _IBMR2
/* no C++ version of <strings.h>, C version causes conflicts */
extern "C" {
extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, size_t);
}
#endif
#ifdef mips
int gethostname(char* name, int namelen);
#endif
int compare_stream(ostrstream& x, ostrstream& y);
inline float flog2(unsigned int x) {
return (float)(log((double)x) / log((double)2));
#if defined(__osf__)
} // return log_2(x)
#else
}; // return log_2(x)
#endif /* (__osf__) */
inline float flog2(const float x) {
return (float)log((double)x) / (float)log((float)2);
#if defined(__osf__)
}
#else
};
#endif /* (__osf__) */
inline int pow2(const int x) {
return (int)pow((double)2, (double)x);
#if defined(__osf__)
} // x's power of 2
#else
}; // x's power of 2
#endif /* (__osf__) */
inline int pow2(const float x) {
return (int)pow((double)2, (double)x);
#if defined(__osf__)
} // x's power of 2
#else
}; // x's power of 2
#endif /* (__osf__) */
int pos_of_LSB(const unsigned int x); // position of the MSB
int ceiling(const float); // ceiling of x
unsigned getbits(unsigned, unsigned, unsigned);
inline void char_swap(char& c1, char& c2) {
char tmp = c1; c1 = c2; c2 = tmp;
#if defined(__osf__)
} // switch two chars
#else
}; // switch two chars
#endif /* (__osf__) */
inline void short_swap(short& s1, short& s2) {
short tmp = s1; s1 = s2; s2 = tmp;
#if defined(__osf__)
}// switch two shorts
#else
};// switch two shorts
#endif /* (__osf__) */
inline void int_swap(int& i1, int& i2) {
int tmp = i1; i1 = i2; i2 = tmp;
#if defined(__osf__)
} // switch two ints
#else
}; // switch two ints
#endif /* (__osf__) */
// file functions
int del_file(const char* file_nm, const char* path_nm = 0);
Boolean copy_file(const char* source, const char* sink);
Boolean copy_file(const char* path, const char* filenm,
const char* source_ext, const char* target_ext);
Boolean exist_file(const char* name, const char* path = 0);
Boolean cat_file(const char* source1, const char* source2,
const char* target);
int check_file(istream&, const char* msg = "");
Boolean exist_dir(const char* path);
Boolean check_and_create_dir(const char* path);
int open_file_prot();
int open_dir_prot();
Boolean cc_is_digit(istream&); // "cc" stands for current char
int bytes(fstream&);
unsigned long disk_space(const char* path);
Boolean int_eq(void*, void*);
Boolean int_ls(void*, void*);
// return an lease largest int of x, the returned value is
// also a multiple of sizeof(void*)
int ll4(int x);
/*
enum lock_t { SHARED, EXCLUSIVE };
Boolean fcntl_lock( int fd, lock_t lt );
Boolean fcntl_unlock( int fd );
Boolean timed_lock( int fd, lock_t lt, int seconds = 5);
Boolean timed_unlock( int fd, int seconds = 5);
void onalarm(int);
*/
int bytes(int fd);
char* access_info( char* request );
// lsb is considered as the 0th bit
void lsb_putbits(unsigned& target, unsigned position_from_lsb,
unsigned bits, unsigned source);
unsigned lsb_getbits(unsigned source, unsigned position_from_lsb, unsigned bits);
Boolean writeToTmpFile(char* unique_nm, char* str, int size);
#endif

View File

@@ -0,0 +1,31 @@
// $XConsortium: ios.C /main/4 1996/08/21 15:54:46 drk $
#include "utility/c_ios.h"
#include <ctype.h>
#include <stdio.h>
ios::ios(streambuf* sb) : sbuf(sb), f_state(OK)
{
}
ios::~ios()
{
delete sbuf;
}
int ios::fail()
{
if ( bad() ) return 1;
if ( BIT_TEST(f_state, FAIL) )
return 1;
else
return 0;
}
int ios::bad()
{
if ( BIT_TEST(f_state, BAD) )
return 1;
else
return 0;
}

View File

@@ -0,0 +1,359 @@
// $XConsortium: iostream.C /main/4 1996/08/21 15:54:53 drk $
#include "utility/c_iostream.h"
#include <stdio.h>
#include <ctype.h>
istream&
istream::seekg(streampos delta, ios::seek_dir d)
{
if ( fail() ) return *this;
if ( d != ios::beg || sbuf -> seekg(delta) == EOF ) {
set_bad();
set_fail();
}
return *this;
}
int istream::get()
{
return sbuf -> get();
}
istream& istream::get(char& c)
{
if ( fail() ) return *this;
int i = sbuf -> get();
if ( i == EOF ) {
set_fail();
return *this;
}
c = i;
return *this;
}
istream&
istream::putback(char c)
{
sbuf -> putback(c);
return *this;
}
istream& istream::getline(char* b, int lim, char delim)
{
return _getline(b, lim, delim, 1);
}
istream& istream::_getline(char* b, int lim, int delim, int fill_zero)
{
if ( fail() ) return *this;
if ( sbuf -> examine() == EOF ) {
set_fail();
return *this;
}
sbuf -> clear_gcount();
int i;
for ( int count = 0 ; count < lim-1; count++ ) {
i = sbuf -> get();
if ( i == EOF || i == delim ) {
//fprintf(stderr, "prematual break in _getline(): i=%d, count = %d\n", i, count);
break;
}
b[count] = char(i);
}
if ( fill_zero )
b[count] = 0;
return *this;
}
istream&
istream::read(char* s, int n)
{
return _getline(s, n+1, EOF, 0);
}
int
istream::gcount()
{
return sbuf -> gcount();
}
istream& istream::operator>>(char& c)
{
int x;
if ( (x=sbuf->examine()) == EOF ) return *this;
c = (char)x;
sbuf -> get();
return *this;
}
int istream::eatw()
{
if ( fail() ) return EOF;
int c = sbuf->examine();
if (c == EOF) set_fail();
while (isspace(c) && c != EOF) {
sbuf->get();
c = sbuf->examine();
}
if ( c == EOF ) set_fail();
return c;
}
istream& istream::operator>>(char* s)
{
int c;
if ( (c=eatw()) == EOF ) return *this;
do {
*s++ = c;
sbuf->get();
c = sbuf -> examine();
} while (!isspace(c) && c != EOF) ;
*s = '\0';
if (c == EOF) {
set_fail();
}
return *this;
}
istream&
istream::operator>>(unsigned short& x)
{
unsigned int l = 0;
*this >> l;
x = (unsigned short)l;
return *this;
}
istream&
istream::operator>>(unsigned int& n)
{
int x;
if ( (x=eatw()) == EOF ) return *this;
n = 0;
if ( isdigit(x) ) {
do {
sbuf -> get();
n = n*10+x-'0';
} while (isdigit(x=sbuf->examine()));
} else {
set_fail();
return *this;
}
return *this;
}
istream&
istream::operator>>(int& x)
{
long l = 0;
*this >> l;
x = int(l);
return *this;
}
istream&
istream::operator>>(long& n)
{
int x;
if ( (x=eatw()) == EOF ) return *this;
int sign = '+';
switch (x) {
case '+':
case '-':
sign = x;
sbuf -> get();
x = sbuf -> examine();
break;
case EOF:
set_fail();
return *this;
}
n = 0;
if ( isdigit(x) ) {
do {
sbuf -> get();
n = n*10+x-'0';
} while (isdigit(x=sbuf->examine()));
if (sign=='-')
n = -n;
} else {
set_fail();
return *this;
}
return *this;
}
/////////////////////
ostream&
ostream::operator<<(void* a)
{
if ( fail() ) return *this;
long x = (long)a;
*this << x;
return *this;
}
ostream&
ostream::operator<<(const char* str)
{
if ( str == 0 ) {
set_bad();
return *this;
}
while (*str) {
if (sbuf->put(*str++) == EOF) {
set_fail();
break;
}
}
return *this;
}
ostream&
ostream::operator<<(char c)
{
if ( fail() ) return *this;
sbuf -> put(c);
return *this;
}
ostream&
ostream::operator<<(int i)
{
long x = i;
*this << x;
return *this;
}
ostream&
ostream::operator<<(unsigned int l)
{
long x = l;
*this << x;
return *this;
}
ostream&
ostream::operator<<(long x)
{
if ( fail() ) return *this;
char buf[32];
char *p = buf;
if (x < 0) {
sbuf->put('-');
x = -x;
}
do {
*p++ = '0' + char(x%10);
x /= 10;
} while (x > 0);
do {
if (sbuf->put(*--p) == EOF) {
set_fail();
break;
}
} while (p != buf);
return *this;
}
ostream&
ostream::operator<< (ostream& (*f)(ostream&))
{
return (*f)(*this) ;
}
ostream& ostream::put(char c)
{
if ( fail() ) return *this;
sbuf -> put(c);
return *this;
}
ostream& ostream::flush()
{
if ( fail() ) return *this;
sbuf -> flush();
return *this;
}
ostream&
ostream::write(const char* s, int n)
{
for ( int i=0; i<n; i++ ) {
if ( sbuf->put(s[i]) == EOF )
break;
}
return *this;
}
ostream& endl(ostream& out)
{
return out << '\n';
}
istream::istream(streambuf* sb) : ios(sb)
{
sbuf = sb;
}
ostream::ostream(streambuf* sb) : ios(sb)
{
sbuf = sb;
}
iostream::iostream(streambuf* sb) : istream(sb), ostream(sb)
{
sbuf = sb;
}

View File

@@ -0,0 +1,30 @@
/*
* $XConsortium: key.h /main/3 1996/06/11 17:37:46 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _key_h
#define _key_h 1
#include "utility/ostring.h"
typedef ostring key_type;
#endif

View File

@@ -0,0 +1,112 @@
/*
* $XConsortium: macro.h /main/4 1996/07/18 14:59:08 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _macro_h
#define _macro_h 1
/* bit manipulation macros */
#define BIT_TEST(x, y) ( ((x) & (y)) == (y) )
#define RESET_BIT(x, y) x &= (~(y))
#define SET_BIT(x, y) x |= (y)
#define BITS_IN(TYPE) ( 8*sizeof(TYPE) )
/* comparison macros */
#define INRANGE(x, low, high) ((x>=low) && (x<=high))
#undef MIN
#undef MAX
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define TOBOOLEAN(x) ( ((x) == 1 ) ? true : false )
#define TOBIT(x) ( ((x) == true ) ? 1 : 0 )
/* little endian to/from big endian swap macros. */
#ifndef __osf__
#define ORDER_SWAP_LONG(x) \
{ \
long tmp_long = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_long)[3]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_long)[2]; \
((unsigned char*)&x)[2] = ((unsigned char*)&tmp_long)[1]; \
((unsigned char*)&x)[3] = ((unsigned char*)&tmp_long)[0]; \
}
#else
#define ORDER_SWAP_LONG(x) \
{ \
long tmp_long = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_long)[7]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_long)[6]; \
((unsigned char*)&x)[2] = ((unsigned char*)&tmp_long)[5]; \
((unsigned char*)&x)[3] = ((unsigned char*)&tmp_long)[4]; \
((unsigned char*)&x)[4] = ((unsigned char*)&tmp_long)[3]; \
((unsigned char*)&x)[5] = ((unsigned char*)&tmp_long)[2]; \
((unsigned char*)&x)[6] = ((unsigned char*)&tmp_long)[1]; \
((unsigned char*)&x)[7] = ((unsigned char*)&tmp_long)[0]; \
}
#endif
#define ORDER_SWAP_FLOAT(x) \
{ \
float tmp_float = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_float)[3]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_float)[2]; \
((unsigned char*)&x)[2] = ((unsigned char*)&tmp_float)[1]; \
((unsigned char*)&x)[3] = ((unsigned char*)&tmp_float)[0]; \
}
#define ORDER_SWAP_INT(x) \
{ \
int tmp_uint = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_uint)[3]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_uint)[2]; \
((unsigned char*)&x)[2] = ((unsigned char*)&tmp_uint)[1]; \
((unsigned char*)&x)[3] = ((unsigned char*)&tmp_uint)[0]; \
}
#define ORDER_SWAP_UINT(x) \
{ \
unsigned int tmp_uint = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_uint)[3]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_uint)[2]; \
((unsigned char*)&x)[2] = ((unsigned char*)&tmp_uint)[1]; \
((unsigned char*)&x)[3] = ((unsigned char*)&tmp_uint)[0]; \
}
#define ORDER_SWAP_USHORT(x) \
{ \
unsigned short tmp_ushort = x; \
((unsigned char*)&x)[0] = ((unsigned char*)&tmp_ushort)[1]; \
((unsigned char*)&x)[1] = ((unsigned char*)&tmp_ushort)[0]; \
}
#endif

View File

@@ -0,0 +1,62 @@
/*
* $XConsortium: mmdb_exception.cc /main/3 1996/06/11 17:37:57 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "mmdb_exception.h"
ostream& mmdbException::asciiOut(ostream& out)
{
out << "mmdbException::asciiOut() called\n";
return out;
}
ostream& stringException::asciiOut(ostream& out)
{
out << msg << "\n";
return out;
}
//////////////////////////////////////////
//////////////////////////////////////////
ostream& intException::asciiOut(ostream& out)
{
out << v_code << "\n";
return out;
}
//////////////////////////////////////////
//////////////////////////////////////////
ostream& boundaryException::asciiOut(ostream& out)
{
cerr << low << "\t";
cerr << high << "\t";
cerr << index << "\n";
return out;
}

View File

@@ -0,0 +1,201 @@
/*
* $XConsortium: mmdb_exception.h /main/6 1996/11/01 10:19:24 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _mmdb_exception_h
#define _mmdb_exception_h 1
#include "Exceptions.hh"
#ifdef C_API
#include "utility/c_fstream.h"
#else
#include <fstream.h>
#endif
#define END_TRY end_try
#include <X11/Xosdefs.h>
#include <errno.h>
#ifdef X_NOT_STDC_ENV
extern int errno;
#endif
class mmdbException : public Exception
{
public:
DECLARE_EXCEPTION(mmdbException, Exception);
virtual ~mmdbException() {};
virtual ostream& asciiOut(ostream&);
friend ostream& operator <<(ostream& out, mmdbException& e) {
return e.asciiOut(out);
}
};
class stringException : public mmdbException
{
protected:
char* msg;
public:
DECLARE_EXCEPTION(stringException, mmdbException);
stringException(char* m) : msg(m) {};
~stringException() {};
virtual ostream& asciiOut(ostream&);
};
class formatException : public stringException
{
protected:
public:
DECLARE_EXCEPTION(formatException, stringException);
formatException(char* m) : stringException(m) {};
~formatException() {};
};
class intException : public mmdbException
{
protected:
int v_code;
public:
DECLARE_EXCEPTION(intException, mmdbException);
intException(int c) : v_code(c) {};
~intException() {};
int code() { return v_code; };
virtual ostream& asciiOut(ostream&);
};
class systemException : public intException
{
public:
DECLARE_EXCEPTION(systemException, intException);
systemException(int c) : intException(c) {};
~systemException() {};
};
class streamException : public intException
{
protected:
public:
DECLARE_EXCEPTION(streamException, intException);
streamException(int c) : intException(c) {};
~streamException() {};
};
class boundaryException : public mmdbException
{
protected:
long low;
long high;
long index;
public:
DECLARE_EXCEPTION(boundaryException, mmdbException);
boundaryException(long l, long h, long i) :
low(l), high(h), index(i) {};
~boundaryException() {};
virtual ostream& asciiOut(ostream&);
};
class beginTransException: public mmdbException
{
public:
DECLARE_EXCEPTION(beginTransException, mmdbException);
beginTransException() {};
~beginTransException() {};
};
class commitTransException: public mmdbException
{
public:
DECLARE_EXCEPTION(commitTransException, mmdbException);
commitTransException() {};
~commitTransException() {};
};
class rollbackTransException: public mmdbException
{
public:
DECLARE_EXCEPTION(rollbackTransException, mmdbException);
rollbackTransException() {};
~rollbackTransException() {};
};
class demoException : public mmdbException
{
protected:
const char* f_path;
const char* f_name;
public:
DECLARE_EXCEPTION(demoException, mmdbException);
demoException(const char* p, const char* n) : f_path(p), f_name(n) {};
virtual ~demoException() {};
const char* path() { return f_path; };
const char* name() { return f_name; };
virtual ostream& asciiOut(ostream& out) {
out << f_path << "\t" << f_name << "\n";
return out;
}
friend ostream& operator <<(ostream& out, demoException& e) {
return e.asciiOut(out);
}
};
#endif

View File

@@ -0,0 +1,261 @@
/*
* $XConsortium: ostring.cc /main/3 1996/06/11 17:38:07 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/ostring.h"
#ifdef C_API
char* ostring::input_buf = 0;
#else
char ostring::input_buf[LBUFSIZ];
#endif
ostring::ostring() : v_sz(0), v_allo_sz(1)
{
v_p = new char[1];
}
ostring::ostring(const int i) : v_sz(0), v_allo_sz(i+1)
{
v_p = new char[i+1];
}
ostring::ostring(char* x, const int i)
{
int w = i;
if ( w == -1 ) {
w = strlen(x);
}
v_sz = w;
v_allo_sz = w+1;
v_p = new char[w+1];
memcpy(v_p, x, w);
v_p[w] = 0;
}
ostring::ostring(const ostring& s) :
v_sz(s.v_sz), v_allo_sz(s.v_allo_sz)
{
v_p = new char[v_allo_sz];
memcpy(v_p, s.v_p, v_sz);
v_p[v_sz] = 0;
}
/*
ostring::~ostring()
{
delete v_p;
}
*/
Boolean ostring::set(const char* x, int l)
{
expand(l+1);
memcpy(v_p, x, l);
v_p[l] = 0;
v_sz = l;
return true;
}
/*
Boolean ostring::set(const char* x)
{
return set(x, strlen(x));
}
void ostring::reset()
{
v_sz = 0;
}
void ostring::set_size(const int s)
{
v_sz = s;
v_p[v_sz] = 0;
}
*/
/********************************************/
// set alloc_sz to at least new_alloc_sz bytes
/********************************************/
Boolean ostring::expand(const int new_alloc_sz, Boolean pre_zero)
{
if ( new_alloc_sz > v_allo_sz ) {
v_allo_sz = new_alloc_sz+1;
char* new_p = new char[v_allo_sz];
if ( pre_zero == true )
memset(new_p, char(0), v_allo_sz);
if ( v_p ) {
memcpy(new_p, v_p, v_sz);
delete v_p;
}
v_p = new_p;
}
return true;
}
char* ostring::acquire()
{
v_allo_sz = v_sz = 0;
char *x = v_p;
v_p = 0;
return x;
}
Boolean ostring::append(const char* x, int l)
{
expand(v_sz+l+1);
memcpy(v_p+v_sz, x, l);
v_sz += l;
v_p[v_sz] = 0;
return true;
}
Boolean ostring::update(const char* x, int l, int offset)
{
if ( offset + l > v_sz ) {
MESSAGE(cerr, "update(): char chunk too small");
throw(boundaryException(0, v_sz, offset+l));
}
memcpy(v_p+offset, x, l);
return true;
}
int ostring::substr(ostring& s)
{
if ( v_p == 0 || s.v_p == 0 )
return -1;
char* sub_p = strstr(v_p, s.v_p);
if ( sub_p == 0 )
return -1;
else
return (int)(sub_p - v_p);
}
/*
int ostring::size() const
{
return v_sz;
}
int ostring::alloc_size() const
{
return v_allo_sz;
}
*/
ostring& ostring::operator +(ostring& s)
{
int l1 = v_sz;
int l2 = s.v_sz;
ostring *new_ostring = new ostring(l1+l2);
for ( int i = 0; i<l1; (*new_ostring).v_p[i] = s.v_p[i] ) i++;
for ( i = 0; i<l2; (*new_ostring).v_p[l1 + i] = s.v_p[i] ) i++;
return *new_ostring;
}
Boolean ostring::string_LS(ostring& y) const
{
char* x_str = this -> get() ;
char* y_str = y.get() ;
int x_sz = this -> size() ;
int y_sz = y.size() ;
if ( x_sz == y_sz ) {
if ( memcmp(x_str, y_str, x_sz ) < 0 )
return true;
else
return false;
} else {
int min = MIN(x_sz, y_sz);
for ( int i=0; i<min; i++ ) {
if ( x_str[i] < y_str[i] )
return true;
else
if ( x_str[i] > y_str[i] )
return false;
}
if ( x_sz < y_sz )
return true;
else
return false;
}
}
Boolean ostring::string_EQ(ostring& y) const
{
if ( this -> size() == y.size() &&
memcmp(this -> get(), y.get(), this -> size() ) == 0
)
return true;
else
return false;
}
ostream& operator <<(ostream& s, const ostring& o)
{
if ( o.v_p ) {
//s << o.v_sz << ":";
for ( int i=0; i<o.v_sz; i++ )
// if ( isprint(o.v_p[i]) )
s << o.v_p[i];
// else
// s << int(o.v_p[i]);
}
return s;
}
istream& operator >>(istream& s, ostring& o)
{
s.getline( o.input_buf, LBUFSIZ );
o.set(o.input_buf);
return s;
}
ostring* ostring::operator+= (ostring* )
{
return 0;
}
ostring* ostring::concate_with(...)
{
return 0 ;
}

View File

@@ -0,0 +1,91 @@
/*
* $XConsortium: ostring.h /main/3 1996/06/11 17:38:12 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _ostring_h
#define _ostring_h 1
#include "utility/funcs.h"
class ostring {
public:
ostring();
ostring(const int chunk_size);
ostring(char* str, const int str_sz = -1); // -1 means take strlen(str)
ostring(const ostring&);
virtual ~ostring() { delete v_p; };
// length of the string
int size() const { return v_sz; };
// length of the allocated chunk
int alloc_size() const { return v_allo_sz; };
ostring& operator +(ostring&); // merge of two strings
int substr(ostring&); // substring matching
// set string to content x
Boolean set(const char* x) { return set(x, strlen(x)); };
Boolean set(const char* x, int i); // set string to content x with length i
Boolean append(const char* x, int l); // append a string x of length i
Boolean update(const char* x, int l, int offset); // update a substring x of length i at 'offset'. offset + l should be sz
//set alloc_sz to at least new_alloc_sz bytes
// pre_zero = true -> zero new space before copy old content over
Boolean expand(const int, Boolean pre_zero = false);
void reset() { v_sz = 0; };
void set_size(const int s) { v_sz = s; v_p[v_sz] = 0; };
char* get() const { return v_p; }; // get char pointer p
char* acquire() ; // return what is pointed at by p and reset
// alloc_sz, sz, and p to 0;
// append x to this and return this.
ostring* operator+= (ostring* x);
// concate all ostring arguments (ostring* 's) to this and return this.
ostring* concate_with(...);
Boolean string_LS(ostring&) const;
Boolean string_EQ(ostring&) const;
friend ostream& operator <<(ostream&, const ostring&);
friend istream& operator >>(istream&, ostring&);
protected:
char *v_p; // memory chunk pointer
int v_sz; // string size
int v_allo_sz; // allocated memory chunk size
#ifdef C_API
static char* input_buf;
friend void initialize_MMDB();
friend void quit_MMDB();
#else
static char input_buf[LBUFSIZ];
#endif
};
#endif

View File

@@ -0,0 +1,50 @@
/*
* $XConsortium: pm_random.cc /main/3 1996/06/11 17:38:16 cde-hal $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
/////////////////////////////////////////////////////////////////
// In CACM July. 1993, pp 109, Park and Miller said that
// a=48271 is little better. In that case, q=44488 and r=3399.
// -qfc, July 2, 1993
/////////////////////////////////////////////////////////////////
#include "utility/pm_random.h"
pm_random::pm_random(int sd)
{
seed(sd);
}
void
pm_random::seed(int seed)
{
if ( !INRANGE( seed, 1, 2147483646) ) {
MESSAGE(cerr,
"pm_random::seed(): seed should be in [1, 2147483646]"
);
throw(boundaryException(1, 2147483646, seed));
}
v_i_seed = seed;
int test = 16807 * (seed % 127773) - 2836 * (seed / 127773);
v_new_seed = ( test > 0 ) ? test : test + 2147483647;
}

View File

@@ -0,0 +1,61 @@
/*
* $XConsortium: pm_random.h /main/4 1996/06/11 17:38:21 cde-hal $
*
* Copyright (c) 1992 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _pm_random_h
#define _pm_random_h 1
#include "utility/macro.h"
#include "utility/funcs.h"
// from CACM 88.10 Park and Miller's paper.
// rewritten to have important member functions inline.
class pm_random {
public:
pm_random(int sd = 19) ;
virtual ~pm_random() {};
void seed(int = 19);
int initial_seed() { return v_i_seed; };
int current_seed() { return v_new_seed; };
int rand() {
int tmp = v_new_seed;
int test = 16807 * (v_new_seed % 127773) - 2836 * (v_new_seed / 127773);
v_new_seed = ( test > 0 ) ? test : test + 2147483647;
return tmp;
};
float rand_01() { return float(rand()) / 2147483647; };
private:
int v_new_seed;
int v_i_seed;
};
#endif

View File

@@ -0,0 +1,28 @@
// $XConsortium: prolatex.C /main/3 1996/06/11 17:38:26 cde-hal $
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#define BUFSIZ 1000
main()
{
char buf[BUFSIZ];
while ( cin.getline(buf, BUFSIZ) ) {
int loc = strlen("\\epsffile{") ;
char c = buf[loc];
buf[loc] = '\0';
if ( strcmp(buf, "\\epsffile{") == 0 ) {
cout << buf;
cout << getenv("PWD");
cout << "/";
buf[loc] = c;
cout << buf + loc << "\n";
} else {
buf[loc] = c;
cout << buf << "\n";
}
}
return 0;
}

View File

@@ -0,0 +1,50 @@
/* $XConsortium: prolatex.c /main/3 1996/06/11 17:38:30 cde-hal $ */
#include <stdio.h>
#include <string.h>
#define BUFSIZ 1000
int replace();
main(argc, argv)
int argc;
char* argv[];
{
char buf[BUFSIZ];
while ( fgets(buf, BUFSIZ, stdin) != NULL ) {
buf[strlen(buf)-1] = '\0';
if ( replace(buf, "\\epsffile{", argv[1]) == 0 )
continue;
if ( replace(buf, "\\input{", argv[1]) == 0 )
continue;
else {
fputs(buf, stdout);
fputs("\n", stdout);
}
}
}
int replace(buf, pattern, s)
char* buf;
char* pattern;
char* s;
{
int loc = strlen(pattern);
char c = buf[loc];
buf[loc] = '\0';
if ( strcmp(buf, pattern) == 0 ) {
fputs(buf, stdout);
/*fputs(getenv("PWD"), stdout);*/
fputs(s, stdout);
fputs("/", stdout);
buf[loc] = c;
fputs(buf + loc, stdout);
fputs("\n", stdout);
return 0;
} else {
buf[loc] = c;
return -1;
}
}

View File

@@ -0,0 +1,34 @@
// $XConsortium: randomize.cc /main/3 1996/06/11 17:38:40 cde-hal $
#include "utility/randomize.h"
randomize::randomize(int sd) : rdn(sd)
{
}
void randomize::scramble(buffer& original)
{
int bytes = original.content_sz();
char* buf = original.get_base();
for ( int i=0; i<bytes-1; i++ )
char_swap(buf[i], buf[rdn.rand() % ( bytes - i ) + i]);
}
void randomize::restore(buffer& scrambled)
{
int bytes = scrambled.content_sz();
char* buf = scrambled.get_base();
int *pos = new int[bytes-1];
for ( int i=0; i<bytes-1; i++ ) {
pos[i] = rdn.rand() % ( bytes - i ) + i;
}
for ( i=bytes-2; i>=0; i-- ) {
char_swap(buf[i], buf[pos[i]]);
}
delete pos;
}

View File

@@ -0,0 +1,50 @@
/*
* $XConsortium: randomize.h /main/3 1996/06/11 17:38:45 cde-hal $
*
* Copyright (c) 1992 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _randomize_h
#define _randomize_h 1
#include "utility/funcs.h"
#include "utility/buffer.h"
#include "utility/pm_random.h"
class randomize
{
public:
randomize(int sd = 19) ;
virtual ~randomize() {};
void scramble(buffer& original); // randomize the original content
void restore(buffer& randomized); // restore the original content
private:
pm_random rdn;
};
#endif

View File

@@ -0,0 +1,244 @@
/*
* $XConsortium: rw_lock.cc /main/3 1996/06/11 17:38:50 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "atomic_lock.h"
#include "rw_lock.h"
Boolean read_lock(char* lock_file_path,
char* writing_lock_file_path,
char* ai_path,
char* reader_info, int& offset,
char*& ai_info
)
{
atomic_lock l(lock_file_path);
if ( l.lock() == false ) {
MESSAGE(cerr, "read_lock(): can't do atomic locking");
return false;
}
Boolean ok;
if ( false == exist_file( writing_lock_file_path ) ) {
fstream x(ai_path, ios::app);
if ( !x ) {
MESSAGE(cerr, "read_lock(): can't open lock file");
throw(streamException(x.rdstate()));
}
offset = bytes(x.rdbuf() -> fd());
x << "A-" << reader_info << "\n";
x.close();
ok = true;
} else {
fstream x(ai_path, ios::in);
if ( !x ) {
MESSAGE(cerr, "read_lock(): can't open lock file");
throw(streamException(x.rdstate()));
}
int sz = bytes(x.rdbuf() -> fd());
ai_info = new char[sz+1];
ai_info[0] = 0;
x.getline(ai_info, sz);
x.close();
ok = false;
}
if ( l.unlock() == false ) {
MESSAGE(cerr, "read_lock(): can't do atomic unlocking");
return false;
}
return ok;
}
Boolean read_unlock(char* lock_file_path, char* ai_path, int offset)
{
atomic_lock l(lock_file_path);
if ( l.lock() == false ) {
MESSAGE(cerr, "read_lock(): can't do atomic locking");
return false;
}
Boolean ok ;
fstream x(ai_path, ios::in|ios::out);
if ( !x ) {
MESSAGE(cerr, "read_unlock(): can't open lock file");
throw(streamException(x.rdstate()));
}
x.seekg( offset, ios::beg );
x.put('I');
///////////////////////////////////////////////
// truncate the info_file if no active readers
// and the file size is over 1k
///////////////////////////////////////////////
if ( bytes(x.rdbuf() -> fd()) > 1024 ) {
ok = false;
char buf[BUFSIZ];
/////////////////////////////////////////
// scan the info file for active readers
/////////////////////////////////////////
while ( x.getline(buf, BUFSIZ) ) {
if ( buf[0] == 'A' ) {
ok = true;
break;
}
}
if ( ok == false )
if ( truncate(ai_path, 0) != 0 ) {
MESSAGE(cerr, "read_unlock(): can't truncate");
throw(systemException(errno));
}
}
x.close();
if ( l.unlock() == false ) {
MESSAGE(cerr, "read_lock(): can't do atomic locking");
return false;
}
return true;
}
Boolean write_lock(char* lock_file_path,
char* writing_lock_path,
char* ai_path, char* writer_info,
char*& ai_info
)
{
atomic_lock l(lock_file_path);
if ( l.lock() == false ) {
MESSAGE(cerr, "write_lock(): can't do atomic locking");
return false;
}
Boolean ok = true;
fstream x(ai_path, ios::in|ios::out);
if (!x) {
MESSAGE(cerr, "write_lock(): can't open info file");
throw(streamException(x.rdstate()));
}
char buf[BUFSIZ];
int sz = bytes(x.rdbuf() -> fd());
ai_info = new char[sz+1];
ai_info[0] = 0;
/////////////////////////////////////////
// scan the info file for active readers
/////////////////////////////////////////
while ( x.getline(buf, BUFSIZ) ) {
if ( buf[0] == 'A' ) {
ok = false;
strcat(ai_info, buf+1);
strcat(ai_info, "\n");
}
}
x.close();
if ( exist_file( writing_lock_path ) == false ) {
if ( ok == true ) {
delete ai_info;
/////////////////////////////////////////
// create the access info file
/////////////////////////////////////////
truncate(ai_path, 0);
fstream x(ai_path, ios::out);
x << "A-" << writer_info << "\n";
/////////////////////////////////////////
// create the writing lock file
/////////////////////////////////////////
if ( creat(writing_lock_path, 0755) == -1 )
ok = false;
}
} else
ok = false;
if ( l.unlock() == false ) {
MESSAGE(cerr, "write_lock(): can't do atomic unlocking");
return false;
}
return ok;
}
Boolean write_unlock(char* lock_file_path, char* writing_lock_path,
char* ai_path
)
{
atomic_lock l(lock_file_path);
if ( l.lock() == false ) {
MESSAGE(cerr, "write_unlock(): can't do atomic locking");
return false;
}
Boolean ok;
if ( del_file(writing_lock_path) == 0 &&
del_file(ai_path) == 0
)
ok = true;
else
ok = false;
if ( l.unlock() == false ) {
MESSAGE(cerr, "write_unlock(): can't do atomic unlocking");
return false;
}
return ok;
}

View File

@@ -0,0 +1,49 @@
/*
* $XConsortium: rw_lock.h /main/3 1996/06/11 17:38:55 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _rw_lock_h
#define _rw_lock_h 1
#include "atomic_lock.h"
Boolean read_lock(char* atomic_lock_path, char* writing_lock_path,
char* ai_path, char* reader_info, int& offset,
char*& ai_info
);
Boolean read_unlock(char* atomic_lock_path, char* ai_path, int offset);
Boolean write_lock(char* atomic_lock_path, char* writing_lock_path,
char* ai_path, char* writer_info,
char*& ai_info
);
Boolean write_unlock(char* atomic_lock_path, char* writing_lock_path,
char* ai_path
);
#endif

View File

@@ -0,0 +1,22 @@
// $XConsortium: stream.C /main/4 1996/08/21 15:55:05 drk $
#include <stdio.h>
#include <stdarg.h>
#include "utility/c_stream.h"
char* form(const char* fmt ...)
{
static char buf[1024];
va_list args;
va_start(args, fmt);
(void) vsprintf(buf, fmt, args);
va_end(args);
return buf;
}

View File

@@ -0,0 +1,4 @@
-12003
4040455 c 12
44
int long char (u)short (u)int

View File

@@ -0,0 +1,7 @@
Call me ishmael. Some years ago, never mind
how long precisely, having little or no money
in my purse, and nothing particular to interest
me on shore, I thought I would sail about a little
and see the watery part of the world. It is a
way I have of driving off the spleen, and
regularting the circulation.

View File

@@ -0,0 +1,4 @@
-12003
4040455 c 12
44
int long char (u)short (u)int

View File

@@ -0,0 +1 @@
12abcdefghijk

View File

@@ -0,0 +1,7 @@
Call me ishmael. Some years ago, never mind
how long precisely, having little or no money
in my purse, and nothing particular to interest
me on shore, I thought I would sail about a little
and see the watery part of the world. It is a
way I have of driving off the spleen, and
regularting the circulation.

View File

@@ -0,0 +1 @@
abcdefgh

View File

@@ -0,0 +1 @@
0123456789abcdefghijklmnopqrst

View File

@@ -0,0 +1 @@
abcdefgh

View File

@@ -0,0 +1,139 @@
/* $XConsortium: streambuf.C /main/8 1996/08/21 15:55:14 drk $ */
#include "utility/c_streambuf.h"
#if !defined(USL) && !defined(__osf__)
#include <libc.h>
#endif
#if defined(USL) || defined(__osf__)
#include <stdlib.h>
#endif
#define DEF_BUF_SIZ 4096
streambuf::streambuf() : _size(0), _capacity(DEF_BUF_SIZ), _alloc(1),
_pcount(0), _gcount(0)
{
base = (char*)malloc(DEF_BUF_SIZ);
end = base + DEF_BUF_SIZ;
get_ptr = put_ptr = base;
}
streambuf::streambuf(char* p, int l, int bufferFull) :
base(p), end(p+l), put_ptr(p), get_ptr(p), _size(0), _capacity(l),
_alloc(0), _pcount(0), _gcount(0)
{
if (bufferFull) {
_size = l;
}
}
streambuf::~streambuf()
{
if ( _alloc )
free(base);
}
int streambuf::examine()
{
notify(GET);
if ( empty() && underflow() == EOF )
return EOF;
return (unsigned char)(*get_ptr);
}
int streambuf::get()
{
notify(GET);
if ( empty() && underflow() == EOF )
return EOF;
int x = (unsigned char)(*get_ptr);
move_get_ptr(+1);
_size--;
_gcount++;
return x;
}
int streambuf::putback(char c)
{
if ( full() )
return EOF;
move_get_ptr(-1);
_size++;
*get_ptr = c;
return 0;
}
int streambuf::put(char c)
{
notify(PUT);
if ( full() && overflow() == EOF )
return EOF;
*put_ptr = c;
move_put_ptr(1);
_size++;
_pcount++;
return 0;
}
int streambuf::move_get_ptr(int one)
{
switch (one) {
case 1:
get_ptr++;
if ( get_ptr == end )
get_ptr = base;
return 0;
case -1:
get_ptr--;
if ( get_ptr == base-1 )
get_ptr = end-1;
return 0;
default:
return EOF;
}
}
int streambuf::move_put_ptr(int one)
{
switch (one) {
case 1:
if ( get_ptr == 0 )
get_ptr = put_ptr;
put_ptr++;
if ( put_ptr == end )
put_ptr = base;
return 0;
default:
return EOF;
}
}

View File

@@ -0,0 +1,48 @@
// $XConsortium: strstream.C /main/5 1996/08/21 15:55:17 drk $
#include "utility/c_strstream.h"
#include "utility/c_charbuf.h"
#include <string.h>
istrstream::istrstream(char* str) :
//ios(new charbuf(str, strlen(str))), istream(0)
istream(0)
{
sbuf = new charbuf(str, strlen(str), 1);
}
istrstream::istrstream(char* str, int size ) :
//istream(new charbuf(str, size))
istream(0)
{
sbuf = new charbuf(str, size, 1);
}
istrstream::~istrstream()
{
}
ostrstream::ostrstream(char* str, int size, int) :
//ios(new charbuf(str, size)), ostream(0)
ostream(0)
{
sbuf = new charbuf(str, size);
}
ostrstream::~ostrstream()
{
}
char* ostrstream::str()
{
char* x = sbuf -> get_buf();
x[pcount()] = 0;
return x;
}
int ostrstream::pcount()
{
int x = sbuf -> pcount();
return x;
}

View File

@@ -0,0 +1,20 @@
// $XConsortium: tst_filebuf.C /main/4 1996/08/21 15:55:25 drk $
#include <iostream.h>
#include "utility/debug.h"
#include "utility/c_fstream.h"
fstream_test1(char* nm)
{
fstream f(nm, ios::in|ios::out)
}
main()
{
streambuf_test1();
streambuf_test2();
streambuf_test3();
streambuf_test4();
}

View File

@@ -0,0 +1,9 @@
// $XConsortium: tst_form.C /main/4 1996/08/21 15:55:30 drk $
#include <stdio.h>
#include "utility/c_stream.h"
main()
{
fprintf(stderr, "%s\n", form("%d %c %s", 1, 'c', "form"));
}

View File

@@ -0,0 +1,8 @@
// $XConsortium: tst_fstream.C /main/4 1996/08/21 15:55:35 drk $
#include <stdlib.h>
#include "utility/debug.h"
#include "utility/c_fstream.h"
#include "utility/core_fstream.C"

View File

@@ -0,0 +1,114 @@
// $XConsortium: tst_streambuf.C /main/4 1996/08/21 15:55:40 drk $
#include <iostream.h>
#include "utility/debug.h"
#include "utility/c_charbuf.h"
streambuf_test1()
{
MESSAGE(cerr, "TEST 1");
char buf[5];
charbuf sb(buf, 5);
sb.put('a');
sb.put('b');
sb.put('c');
MESSAGE(cerr, "examine char a:");
debug(cerr, (char)sb.examine());
MESSAGE(cerr, "get char a:");
int c = sb.get();
debug(cerr, (char)c);
sb.put('d');
sb.put('e');
sb.putback(c);
MESSAGE(cerr, "putback char a:");
debug(cerr, (char)c);
MESSAGE(cerr, "get char a - e:");
debug(cerr, (char)sb.get());
debug(cerr, (char)sb.get());
debug(cerr, (char)sb.get());
debug(cerr, (char)sb.get());
debug(cerr, (char)sb.get());
}
streambuf_test2()
{
MESSAGE(cerr, "TEST 2");
char buf[5];
charbuf sb(buf, 5);
sb.put(0);
sb.put(1);
MESSAGE(cerr, "get 0:");
debug(cerr, sb.get());
MESSAGE(cerr, "get 1:");
debug(cerr, sb.get());
MESSAGE(cerr, "get -1:");
debug(cerr, sb.get());
sb.putback(2);
MESSAGE(cerr, "get 2:");
debug(cerr, sb.get());
}
streambuf_test3()
{
MESSAGE(cerr, "TEST 3");
char buf[5];
charbuf sb(buf, 5);
MESSAGE(cerr, "return 0:");
debug(cerr, sb.put(0));
MESSAGE(cerr, "return 0:");
debug(cerr, sb.put(1));
MESSAGE(cerr, "return 0:");
debug(cerr, sb.put(2));
MESSAGE(cerr, "return 0:");
debug(cerr, sb.put(3));
MESSAGE(cerr, "return 0:");
debug(cerr, sb.put(4));
MESSAGE(cerr, "return -1:");
debug(cerr, sb.put(5));
MESSAGE(cerr, "return -1:");
debug(cerr, sb.put(6));
}
streambuf_test4()
{
MESSAGE(cerr, "TEST 4");
char buf[5];
charbuf sb(buf, 5);
debug(cerr, sb.putback(0));
debug(cerr, sb.putback(1));
debug(cerr, sb.putback(2));
debug(cerr, sb.putback(3));
debug(cerr, sb.putback(4));
MESSAGE(cerr, "get 4:");
debug(cerr, sb.get());
MESSAGE(cerr, "get 3:");
debug(cerr, sb.get());
MESSAGE(cerr, "get 2:");
debug(cerr, sb.get());
MESSAGE(cerr, "get 1:");
debug(cerr, sb.get());
MESSAGE(cerr, "get 0:");
debug(cerr, sb.get());
}
main()
{
streambuf_test1();
streambuf_test2();
streambuf_test3();
streambuf_test4();
}

View File

@@ -0,0 +1,34 @@
// $XConsortium: tst_strstream.C /main/4 1996/08/21 15:55:44 drk $
#include <stdio.h>
#include "utility/c_strstream.h"
tst_ostrstream()
{
char buf[1024];
ostrstream os(buf, 1024);
os << "istream : virtual public ios.";
fprintf(stderr, "buf=%s\n", buf);
}
tst_istrstream()
{
char* buf = "303.0";
istrstream is(buf, strlen(buf));
int c = is.get() ;
fprintf(stderr, "c=%c\n", c);
is.putback(c) ;
int x; char ch;
is >> x; fprintf(stderr, "x=%d\n", x);
is >> ch; fprintf(stderr, "ch=%c\n", ch);
is >> x; fprintf(stderr, "x=%d\n", x);
}
main()
{
tst_ostrstream();
tst_istrstream();
}

View File

@@ -0,0 +1,66 @@
/*
* $XConsortium: types.h /main/5 1996/08/21 15:55:48 drk $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#ifndef _types_h
#define _types_h 1
#ifdef C_API
#include "utility/c_iostream.h"
#else
#include <iostream.h>
#endif
#define true 1
#define false 0
typedef char Boolean;
typedef void* voidPtr;
typedef char* charPtr;
typedef short s_int16;
typedef unsigned short u_int16;
typedef int s_int32;
typedef unsigned int u_int32;
typedef long s_long32;
typedef float s_float32;
enum io_status { done, fail };
class root;
typedef Boolean (*cmp_func_ptr_t)(const void*, const void*);
typedef void (*app_func_ptr_t)(const void*);
typedef void (*print_func_ptr_t)(ostream&, const void*);
//enum Boolean { true, false };
#ifndef __osf__
typedef long mmdb_pos_t;
#else
typedef int mmdb_pos_t;
#endif
#endif

View File

@@ -0,0 +1,80 @@
/*
* $XConsortium: xclock.cc /main/3 1996/06/11 17:39:56 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "xclock.h"
#if defined (SVR4) && !defined (_IBMR2) && !defined(SC3)
extern "C" { extern int gettimeofday(struct timeval*); }
#endif
struct timeval xclock::v_tp;
xclock::xclock()
{
v_tp.tv_sec = 0;
v_tp.tv_usec = 0;
}
char* xclock::unique_time_stamp()
{
long sec, usec;
unique_time_stamp(sec, usec);
return form("%ld.%ld", sec, usec);
}
void xclock::unique_time_stamp(long& sec, long& usec)
{
struct timeval tpx;
#if !defined (SVR4) || defined (_IBMR2) || defined(SC3)
struct timezone tzpx;
#endif
do {
if (
#if defined (SVR4) && !defined (_IBMR2) && !defined(SC3)
gettimeofday(&tpx)
#else
gettimeofday(&tpx, &tzpx)
#endif
== -1 ) {
MESSAGE(cerr, "xclock(): gettimeofday() failed");
throw(systemException(errno));
}
} while (tpx.tv_sec == v_tp.tv_sec && tpx.tv_usec == v_tp.tv_usec);
v_tp.tv_sec= tpx.tv_sec;
v_tp.tv_usec = tpx.tv_usec;
sec = v_tp.tv_sec;
usec = v_tp.tv_usec;
}
//xclock mmdb_xclock;

View File

@@ -0,0 +1,63 @@
/*
* $XConsortium: xclock.h /main/4 1996/08/21 15:55:52 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _xclock_h
#define _xclock_h 1
#include <time.h>
#include <sys/time.h>
#ifdef C_API
#include "utility/c_stream.h"
#else
#include <stream.h>
#endif
#include "utility/funcs.h"
/*******************************************/
// xclock class.
/*******************************************/
class xclock {
public:
xclock() ;
virtual ~xclock() {};
char* unique_time_stamp();
void unique_time_stamp(long& sec, long& usec);
protected:
static struct timeval v_tp;
static struct timezone v_tzp;
};
#endif

View File

@@ -0,0 +1,82 @@
/*
* $XConsortium: xtime.cc /main/13 1996/07/18 15:00:24 drk $
*
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
* States. Use of a copyright notice is precautionary only and does not
* imply publication or disclosure.
*
* This software contains confidential information and trade secrets of HaL
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
* without the prior express written permission of HaL Computer Systems, Inc.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* HaL Computer Systems, Inc.
* 1315 Dell Avenue, Campbell, CA 95008
*
*/
#include "utility/xtime.h"
#ifdef SVR4
#include <sys/time.h>
#if !defined (_IBMR2) && !defined(sun) && !defined(USL)
extern "C" { extern int gettimeofday(struct timeval *tp); }
#endif
#endif
xtime::xtime() :
v_cpu_stamp(0), v_elapsed_stamp(0)
{
}
void xtime::stop(float &cpu_time, long &elp_time)
{
cpu_time = -v_cpu_stamp;
elp_time = v_elapsed_stamp;
start();
cpu_time += v_cpu_stamp;
elp_time = v_elapsed_stamp - elp_time;
}
// add a mark
void xtime::start()
{
#if defined (SVR4) && !defined (_IBMR2) && !defined(sun) && !defined(__osf__) && !defined(USL)
if ( gettimeofday(&v_tv) != 0 ) {
#else
if ( gettimeofday(&v_tv, &v_tz) != 0 ) {
#endif
MESSAGE(cerr, "xtime::start(): gettimeofday() failed");
throw(systemException(errno));
}
v_elapsed_stamp = v_tv.tv_sec;
#if defined(SVR4) || defined(__osf__)
if ( times(&v_time_regs) == -1 )
#else
if ( times(&v_time_regs) != 0 )
#endif
{
MESSAGE(cerr, "xtime::start(): times() failed");
throw(systemException(errno));
}
v_cpu_stamp =
float(v_time_regs.tms_utime + v_time_regs.tms_stime +
v_time_regs.tms_cutime + v_time_regs.tms_cstime
) / 60.0;
}

View File

@@ -0,0 +1,64 @@
/*
* $XConsortium: xtime.h /main/4 1996/06/11 17:40:11 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved. Unpublished -- rights reserved under
* the Copyright Laws of the United States. USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
*
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _xtime_h
#define _xtime_h 1
#include <X11/Xos.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include "funcs.h"
/*******************************************/
// timer class.
/*******************************************/
class xtime
{
public:
xtime() ;
virtual ~xtime() {};
void start(); // reset clock
void stop(float &cpu_time, long &elapsed_time); // record time
private:
float v_cpu_stamp;
long v_elapsed_stamp;
struct tms v_time_regs;
struct timeval v_tv;
struct timezone v_tz;
};
#endif