00001
00002
00003
00004
00005 #ifndef __TGLOBALS_H
00006 #define __TGLOBALS_H
00007
00008 #include <pthread.h>
00009
00010 #include <X11/Xlib.h>
00011 #include <X11/Xutil.h>
00012 #include <X11/Xatom.h>
00013 #include <X11/cursorfont.h>
00014 #include <X11/keysym.h>
00015 #include <X11/xpm.h>
00016
00017 #include <stdio.h>
00018 #include <string.h>
00019 #include <fstream>
00020 #include <stdlib.h>
00021 #include <time.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <sys/un.h>
00025 #include <fcntl.h>
00026 #include <sys/time.h>
00027 #include <sys/times.h>
00028 #include <errno.h>
00029 #include <math.h>
00030 #include <sys/socket.h>
00031 #include <netinet/in.h>
00032 #include <arpa/inet.h>
00033 #include <netdb.h>
00034 #include <signal.h>
00035 #include <sys/ioctl.h>
00036 #include <sys/ipc.h>
00037 #include <sys/sem.h>
00038 #include <sys/shm.h>
00039 #include <sys/wait.h>
00040 #include <termios.h>
00041 #include <sys/mman.h>
00042 #include <term.h>
00043 #include <ncurses.h>
00044 #include <unistd.h>
00045 #include <limits.h>
00046 #include <values.h>
00047
00048 #ifdef __CLDAQ_ZLIB_USE
00049 #include <zlib.h>
00050 #endif
00051
00052 #include <linux/param.h>
00053
00054 #ifndef __USE_BSD
00055 typedef __caddr_t caddr_t;
00056 #endif
00057
00058 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
00059
00060 #else
00061
00062 union semun {
00063 int val;
00064 struct semid_ds* buf;
00065 unsigned short int* array;
00066 struct seminfo* __buf;
00067 };
00068 #endif
00069
00070 #include "Ttypes.h"
00071
00072 extern Tchar** environ;
00073
00074 static const Tint _digits = 6;
00075 static const Tsize_t _buflen = 64;
00076 static const Tsize_t _precision = 6;
00077
00078 inline static Tstring itostr( Tint i, Tint digits = _digits )
00079 {
00080 static const Tsize_t buflen = _buflen;
00081 static Tchar buf[ buflen ];
00082 Tostrstream os( buf, buflen );
00083
00084 if ( i >= 0 ) {
00085 os << setfill( '0' ) << setiosflags( Tios::right ) << setw( digits );
00086 os << i << Tends;
00087 Tstring s = os.str();
00088 return( s );
00089 } else {
00090 os << i << Tends;
00091 Tstring s = os.str();
00092 Tint nzero = digits - s.size();
00093 if ( nzero > 0 ) {
00094 s.insert( 1, nzero, '0' );
00095 }
00096 return( s );
00097 }
00098 }
00099
00100 inline static Tstring ltostr( Tlong l, Tint digits = _digits )
00101 {
00102 static const Tsize_t buflen = _buflen;
00103 static Tchar buf[ buflen ];
00104 Tostrstream os( buf, buflen );
00105
00106 if ( l >= 0 ) {
00107 os << setfill( '0' ) << setiosflags( Tios::right ) << setw( digits );
00108 os << l << Tends;
00109 Tstring s = os.str();
00110 return( s );
00111 } else {
00112 os << l << Tends;
00113 Tstring s = os.str();
00114 Tint nzero = digits - s.size();
00115 if ( nzero > 0 ) {
00116 s.insert( 1, nzero, '0' );
00117 }
00118 return( s );
00119 }
00120 }
00121
00122 inline static Tstring ultostr( TUlong ul, Tint digits = _digits )
00123 {
00124 static const Tsize_t buflen = _buflen;
00125 static Tchar buf[ buflen ];
00126 Tostrstream os( buf, buflen );
00127
00128 if ( ul >= 0 ) {
00129 os << setfill( '0' ) << setiosflags( Tios::right ) << setw( digits );
00130 os << ul << Tends;
00131 Tstring s = os.str();
00132 return( s );
00133 } else {
00134 os << ul << Tends;
00135 Tstring s = os.str();
00136 Tint nzero = digits - s.size();
00137 if ( nzero > 0 ) {
00138 s.insert( 1, nzero, '0' );
00139 }
00140 return( s );
00141 }
00142 }
00143
00144 inline static Tstring dtostr( Tdouble d, Tint precision = _precision )
00145 {
00146 static const Tsize_t buflen = _buflen;
00147 static Tchar buf[ buflen ];
00148 Tostrstream os( buf, buflen );
00149
00150 os << setprecision( precision ) << d << Tends;
00151 Tstring s = os.str();
00152 return( s );
00153 }
00154
00155 inline static Tstring ftostr( Tfloat f, Tint precision = _precision )
00156 {
00157 return( dtostr( (Tdouble)f, precision ) );
00158 }
00159
00160 inline static Tbool isexist( const Tstring& filename )
00161 {
00162 if ( access( filename.c_str(), F_OK ) == 0 ) {
00163 return( Ttrue );
00164 } else {
00165 return( Tfalse );
00166 }
00167 }
00168
00169 inline static Tvoid showbit( Tint bit )
00170 {
00171 Tint nbit = Tsizeof( bit ) * 8;
00172 for ( Tint i = nbit; i > 0; i -- ) {
00173 Tcout << ( ( bit >> i - 1 ) & 0x01 );
00174 }
00175 Tcout << Tendl;
00176 return;
00177 }
00178
00179 #endif