X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fkstddef.h;h=dfb35431e281c53a15218d0c0bc9fdc5165ece67;hp=e80e3e56f8311b35920f95493a5633ed2514e76b;hb=031437896d0dc6cac70c16e5604b10f5aa4d0767;hpb=2ddfd9280d343189cd52abe2ba0d7bd4879f9f2c diff --git a/include/kstddef.h b/include/kstddef.h index e80e3e5..dfb3543 100644 --- a/include/kstddef.h +++ b/include/kstddef.h @@ -1,14 +1,15 @@ /***************************************************************************** +** FILE IDENTIFICATION +** +** File Name: kstddef.h +** Author: Kevin Rosenberg +** Purpose: Header file containing KRL standard C definitions +** Date Started: Dec. 83 +** ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: kstddef.h,v 1.3 2000/04/28 17:38:16 kevin Exp $ -** $Log: kstddef.h,v $ -** Revision 1.3 2000/04/28 17:38:16 kevin -** Removed unused files -** -** Revision 1.2 2000/04/28 14:14:16 kevin -** *** empty log message *** +** $Id: kstddef.h,v 1.16 2000/06/13 16:20:31 kevin Exp $ ** ** ** This program is free software; you can redistribute it and/or modify @@ -24,43 +25,27 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/****************************************************************************** - * - * FILE IDENTIFICATION - * - * File Name: STDDEF.H - * Author: Kevin Rosenberg - * Purpose: Header file containing KRL standard C definitions - * Date Started: Dec. 83 - * - * DESCRIPTION - * Header file contains KRL standard C definitions - * - * MODIFICATION LOG - * - *****************************************************************************/ #ifndef STDDEF_H #define STDDEF_H -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#undef SHELL +#ifdef _WIN32 +#define snprintf _snprintf +#endif #define STR_MAX_LEN 255 #define STR_SIZE STR_MAX_LEN+1 -#ifndef bool -typedef signed int bool; /* Boolean variable type */ -#endif - -typedef unsigned char string[STR_SIZE]; +#include +#include +#include +#include -#define UNSIGNLONG unsigned long int -#define UNSIGNCHAR unsigned char +#undef SHELL #define TRUE 1 #define FALSE 0 @@ -68,8 +53,6 @@ typedef unsigned char string[STR_SIZE]; #define ERROR FALSE #define YES TRUE #define NO FALSE -#define ON TRUE -#define OFF FALSE /*----------------------------------------------------------------------*/ @@ -77,11 +60,6 @@ typedef unsigned char string[STR_SIZE]; /*----------------------------------------------------------------------*/ -#define INTERNAL_FUNC static -#define INTERNAL_VAR static - -/*----------------------------------------------------------------------*/ - #define NEWLINE '\n' #define TAB '\t' #define EOS '\0' @@ -101,18 +79,15 @@ typedef unsigned char string[STR_SIZE]; #define ABS(x) ((x) < 0 ? -(x) : (x)) #define SQR(x) ((x) * (x)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define MIN(a,b) ((a) <= (b) ? (a) : (b)) #define ISWAP(a,b) {int i; i = a; a = b; b = i;} #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub -#define FOREVER for (;;) #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0) /*----------------------------------------------------------------------*/ struct time_st { - int hour, minute, second, hs; + int hour, minute, second, ms; }; struct date_st { @@ -136,13 +111,9 @@ typedef struct timedate_st TIMEDATE; /*----------------------------------------------------------------------*/ -/* codes for open command */ -#ifdef LATTICE -#define OPEN_RDONLY 0x8000 /* Lattice codes for binary i/o */ -#define OPEN_WRONLY 0x8001 -#define OPEN_RDWR 0x8002 -#elif MICROSOFT +/* codes for open command */ +#if MICROSOFT #define OPEN_RDONLY O_RDONLY /* other system use standard codes */ #define OPEN_WRONLY O_WRONLY /* for binary */ #define OPEN_RDWR O_RDWR @@ -171,65 +142,61 @@ typedef struct timedate_st TIMEDATE; #define S_IWRITE S_IWUSR #endif -/* alloc.c */ -void *alloc(unsigned int nbytes); -/* allocnum.c */ -float *alloc_float(int n); -double *alloc_double(int n); -int *alloc_int(int n); -/* cdate.c */ -char *td_str_cdate(DATE *d); -char *td_month_name(int n); -char *td_day_name(int n); -/* ctoi.c */ -char *ctoi(const char *s, int *ival); -/* fexist.c */ -int file_exists(const char *fname); -/* fmax.c */ -double fmax(double a, double b); -/* get_yn.c */ -int get_yn(const char *prompt); -/* getch.c */ -int getch(void); -void ungetch(int c); -/* iclip.c */ -int iclip(int n, int lb, int ub); -/* irand.c */ -unsigned int irand(unsigned int n); -/* ltostr.c */ -int ltostr(long val, char *cp, int base); -/* s_clip.c */ -char *str_clip_tail(char *str, unsigned int nclip); -/* s_head.c */ -char *str_skip_head(const char *str, const char *charlist); -/* s_lower.c */ +/*----------------------------------------------------------------------*/ + +#if defined(MICROSOFT) || ! defined(SIZEOF_INT) + #define SIZEOF_INT 4 + #define SIZEOF_LONG 4 + #define SIZEOF_SHORT 2 + #define SIZEOF_FLOAT 4 + #define SIZEOF_DOUBLE 8 +#endif + +typedef signed char kint8; +typedef unsigned char kuint8; + +#if SIZEOF_INT == 4 + typedef int kint32; + typedef unsigned int kuint32; +#elif SIZEOF_LONG == 4 + typedef long int kint32; + typedef unsigned int kuint32; +#endif + +#if SIZEOF_SHORT == 2 + typedef short int kint16; + typedef unsigned short int kuint16; +#elif SIZEOF_INT == 2 + typedef int kint16; + typedef unsigned int kuint16; +#endif + +#if SIZEOF_FLOAT == 4 + typedef float kfloat32; +#endif +#if SIZEOF_DOUBLE == 8 + typedef double kfloat64; +#endif + +/* filefuncs.cpp */ +bool file_exists(const char* fname); +const char* fileBasename(const char* filename); +FILE *sys_fopen(const char *filename, const char *mode, const char *progname); + +/* strfuncs.cpp */ +const char* str_skip_head(char* const str, const char* const charlist); +char* str_skip_head(char* str, char* charlist); char *str_lower(char *s); -/* s_make.c */ -char *str_make(char *str, int c, const int n); -/* s_rmhead.c */ -char *str_wrm_head(char *str); -char *str_rm_head(char *str, const char *skip_str); -/* s_rmtail.c */ -char *str_rm_tail(char *str, const char *charlist); -/* s_save.c */ -char *str_save(const char *s); -/* s_upper.c */ -char *str_upper(char *str); -/* s_wtail.c */ char *str_wrm_tail(char *str); -/* strncmpc.c */ -int strncmpc(const char *s, const char *t, int n); -/* sysalloc.c */ -void *sys_alloc(const int nbytes, const char *name); -/* syserror.c */ +char *str_rm_tail(char *str, const char* const charlist); +char *str_upper(char *str); + +/* syserror.cpp */ void sys_error(int severity, const char *msg, ...); void sys_verror(int severity, const char *msg, va_list arg); void sys_error_level(int severity); -/* sysfopen.c */ -FILE *sys_fopen(const char *filename, const char *mode, const char *progname); -/* sysfree.c */ -void sys_free(void *ptr, const char *name); -/* timedate.c */ + +/* timedate.cpp */ DATE *td_get_date(DATE *d); TIME *td_get_time(TIME *t); double td_current_sec(void); @@ -243,7 +210,21 @@ const char *td_str_tmdt(const TIMEDATE *td); const char *td_str_time(const TIME *t); const char *td_str_stime(const TIME *t); const char *td_str_date(const DATE *d); -/* kbasename.c */ -char *kbasename(const char *filename); +char *td_str_cdate(DATE *d); +char *td_month_name(int n); +char *td_day_name(int n); + +/* netorder.cpp */ +void *strreverse (void *dest, const void *src, size_t n); +int read_nint16 (kuint16 *n, int fd); +int write_nint16 (kuint16 const *n, int fd); +int read_nint32 (kuint32 *n, int fd); +int write_nint32 (kuint32 const *n, int fd); +int read_nfloat32 (float *f, int fd); +int write_nfloat32 (float const *f, int fd); +int read_nfloat64 (double *d, int fd); +int write_nfloat64 (double const *d, int fd); +void ConvertNetworkOrder (void* buffer, size_t bytes); +void ConvertReverseNetworkOrder (void* buffer, size_t bytes); #endif