1 /* 2 ATP QWK MAIL READER FOR READING AND REPLYING TO QWK MAIL PACKETS. 3 Copyright (C) 1992, 1993, 1997 Thomas McWilliams 4 Copyright (C) 1990 Rene Cougnenc 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 /* 22 system.h 23 */ 24 25 #ifndef _ATP_SYSTEM_H 26 #define _ATP_SYSTEM_H 1 27 28 #include <ctype.h> 29 #include <time.h> 30 #include <signal.h> 31 #if !defined(ATPDBG) || defined(_QC) 32 #define NDEBUG 1 33 #endif 34 #include <assert.h> 35 #include "atptypes.h" 36 37 #ifndef EXIT_FAILURE 38 #define EXIT_FAILURE 1 39 #endif 40 41 char *mygetcwd( char *buf, size_t siz ); 42 43 #if defined(SYS_UNIX) && !defined(unix) 44 #define unix 1 45 #endif 46 47 #if !defined(SYS_UNIX) && !defined(unix) /* non-unix includes */ 48 # if defined(_MSC_) /* microsoft c */ 49 # include <malloc.h> 50 # include <direct.h> 51 # else /* borland et al dos */ 52 # include <alloc.h> 53 # include <dir.h> 54 # endif 55 # include <process.h> 56 # include <io.h> 57 # include <dos.h> 58 #endif 59 60 #if defined(__cplusplus) 61 # define ATP_INLINE static inline 62 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) && (__GNUC__ > 1 ) 63 # define ATP_INLINE static inline 64 #else 65 # define ATP_INLINE static 66 #endif 67 68 #if defined(MEMDEBUG) 69 #include <memdebug.h> 70 #elif defined(DBMALLOC) 71 #include <dbmalloc.h> 72 #endif 73 74 #if defined(GC_DEBUG) || defined(MYGC) 75 #undef calloc 76 #undef realloc 77 #undef malloc 78 #undef free 79 #define malloc(s) GC_MALLOC((s)) 80 #define realloc(n,s) GC_REALLOC((n),(s)) 81 #define free(s) GC_FREE((s)) 82 /* #define free(s) ;*/ 83 #define calloc(n,s) GC_MALLOC((n)*(s)) 84 #include <gc.h> 85 #endif 86 87 #if defined(__EMX__) 88 #ifndef _OS2 89 #define _OS2 1 90 #endif 91 #define unix 1 92 #define CHPATH _chdir2 93 #define GETCWD _getcwd2 94 #define ADDRIVE(X) addrive(X) 95 #define HAVE_DIRENT_H 1 96 #define HAVE_GETCWD 1 97 #define HAVE_PERROR 1 98 #define HAVE_SIGACTION 1 99 #define HAVE_STRDUP 1 100 #define HAVE_STRNICMP 1 101 #define HAVE_STRSTR 1 102 #define HAVE_STRUPR 1 103 #define HAVE_TMPNAM 1 104 #define HAVE_UNISTD_H 1 105 #define HAVE_UTIME 1 106 #define DOSTIME 1 107 #include <utime.h> 108 #include <io.h> 109 extern void addrive(char *path); 110 #endif 111 112 /* D.J.Delore gcc for ms-dos */ 113 #ifdef DJGPP 114 #ifndef __MSDOS__ 115 #define __MSDOS__ 116 #endif 117 #include <gppconio.h> 118 #define HAVE_DIRENT_H 119 #define NEEDISKS 1 120 #define HAVE_PERROR 1 121 #define HAVE_STRDUP 1 122 #define HAVE_STRNICMP 1 123 #define HAVE_STRSTR 1 124 #define HAVE_STRUPR 1 125 /* #define HAVE_TMPNAM <-- this is partly broken under djgpp 1.12 */ 126 #define HAVE_UNISTD_H 1 127 #define HAVE_UTIME 1 128 #include <utime.h> 129 #define HAVE_GETCWD 1 130 #define GETCWD getcwd 131 #endif 132 133 #ifdef unix 134 # include <sys/param.h> 135 # if defined(HAVE_UNISTD_H) || !defined(SYS_UNIX) 136 # include <unistd.h> 137 # endif 138 #endif 139 140 #if defined(unix) 141 # if defined(HAVE_DIRENT_H) 142 # include <sys/types.h> 143 # include <dirent.h> 144 # define DIRENTRY dirent 145 # else 146 # if defined(HAVE_SYS_DIR_H) 147 # include <sys/dir.h> 148 # elif defined(HAVE_SYS_NDIR_H) 149 # include <sys/ndir.h> 150 # elif defined(HAVE_NDIR_H) 151 # include <ndir.h> 152 # else 153 # include <dir.h> 154 # endif 155 # define DIRENTRY direct 156 # endif 157 158 # ifndef S_IRWXU 159 # define S_IRWXU 0700 160 # endif 161 # define my_mkdir(c) mkdir(c,S_IRWXU) 162 163 # if defined(SYS_UNIX) 164 # if defined(HAVE_GETCWD) 165 # define GETCWD getcwd 166 # else 167 # define GETCWD mygetcwd 168 # endif 169 # define CHPATH chdir 170 # define SHELL "SHELL" 171 # define UNIXCMDS 1 172 # define HAVE_LINK 1 173 # define HAVE_UTIME 1 174 # define USE_FORK 1 175 # define SEP '/' 176 # include <sys/ioctl.h> 177 # if !defined(HAVE_UTIME_H) 178 struct utimbuf { time_t actime; time_t modtime ; } ; 179 # endif 180 void save_terminal( void ); 181 void restore_terminal( void); 182 # endif 183 #endif 184 185 /* define LATIN1 if your terminal supports ISO character set */ 186 187 #ifdef __linux__ 188 #define VT220 1 189 #define LATIN1 1 190 #endif 191 192 #ifdef SIMP 193 #define NEEDREADLINE 1 /* not using Salz/Tumlee editline lib */ 194 #define add_history(x) /* null x */ 195 #endif 196 197 #ifdef _OS2 198 # include <io.h> 199 # include <process.h> 200 # ifndef __EMX__ 201 typedef int pid_t ; 202 # define GETCWD getcwd 203 # define CHPATH chdir 204 # define unlink(X) remove(X) 205 # define SEP '\\' 206 # else 207 # define SEP '/' 208 # endif 209 # define SHELL "COMSPEC" 210 #endif 211 212 #ifdef MSDOS 213 #ifndef __MSDOS__ 214 #define __MSDOS__ 1 215 #endif 216 #endif 217 218 #ifdef WIN32 219 typedef int pid_t ; 220 #define CHPATH chdir 221 #define ADDRIVE(X) addrive(X) 222 #define my_mkdir(c) mkdir(c) 223 #define sleep(t) _sleep(t) 224 #define GETCWD getcwd 225 #define SHELL "COMSPEC" /* environment variable used for command shell */ 226 #define SEP '\\' 227 #endif 228 229 #ifdef __MSDOS__ 230 #define MAXPATHS 128 231 #define SHELL "COMSPEC" /* environment variable used for command shell */ 232 #define SEP '\\' 233 #define ADDRIVE(X) addrive(X) 234 extern void addrive(char *path); 235 #define CHPATH DosChPath 236 extern atp_ERROR_T DosChPath(const char *path); 237 #if defined(SPAWNO) 238 # ifdef _CDECL 239 # define _Cdecl _CDECL 240 # endif 241 # include <spawno.h> 242 #endif /* msdos only */ 243 244 #ifdef _MSC_ 245 extern char *getcwd( char *p, int len ); 246 extern void sleep(unsigned sec); 247 #define GETCWD getcwd 248 #include <sys/utime.h> 249 #define __ATP_LOOSE__ 1 250 #define DOSTIME 1 251 #define NEEDISKS 1 252 #define HAVE_GETCWD 1 253 #define HAVE_PERROR 1 254 #define HAVE_STRNICMP 1 255 #define HAVE_STRSTR 1 256 #define HAVE_STRUPR 1 257 #define HAVE_TMPNAM 1 258 #define HAVE_UTIME 1 259 #define findfirst(A,B,C) _dos_findfirst(A,C,B) 260 #define findnext _dos_findnext 261 #define ffblk find_t 262 #define ff_name name 263 #endif 264 265 #ifndef DJGPP 266 #define GETCWD getcwd 267 /* extern int getch( void );*/ 268 /* #define unlink(X) remove(X) */ 269 #define my_mkdir(X) mkdir(X) 270 #endif 271 272 #ifdef __TURBOC__ 273 #include <conio.h> 274 #ifndef __LINT__ 275 #define HAVE_GETCWD 1 276 #define HAVE_PERROR 1 277 #define HAVE_STRNICMP 1 278 #define HAVE_STRSTR 1 279 #define HAVE_STRUPR 1 280 #define HAVE_TMPNAM 1 281 #else 282 #undef GETCWD 283 #define GETCWD mygetcwd 284 char *strdup(const char *s); 285 extern long timezone ; 286 extern void tzset(void); 287 extern int putenv(const char *name); 288 #endif /* __LINT__ */ 289 #define DOSTIME 1 290 #define HAVE_FTIME /* getftime() and setftime() library functions */ 291 #endif /* __TURBOC__ */ 292 293 #else /* NOT MSDOS */ 294 #ifndef ADDRIVE 295 #define ADDRIVE(X) /* nothing X */ 296 #endif 297 #define MAXPATHS 1024 298 #endif /* if __MSDOS__ */ 299 300 #if defined(SYS_UNIX) 301 # if defined(HAVE_TERMIOS_H) 302 # include <termios.h> 303 # define ATPSRTERM termios 304 # define ATPGETERM tcgetattr(STDIN_FILENO, &savedterm ) 305 # define ATPSETERM tcsetattr(STDIN_FILENO, TCSANOW, &savedterm ) 306 # elif defined(HAVE_TERMIO_H) 307 # include <sys/ioctl.h> 308 # include <termio.h> 309 # define ATPSRTERM termio 310 # define ATPGETERM ioctl(STDIN_FILENO, TCGETA, &savedterm ) 311 # define ATPSETERM ioctl(STDIN_FILENO, TCSETA, &savedterm ) 312 # elif defined(HAVE_SGTTY_H) 313 # include <sgtty.h> 314 # include <sys/ioctl.h> 315 # define ATPSRTERM sgttyb 316 # define ATPGETERM ioctl(STDIN_FILENO, TIOCGETP, &savedterm ) 317 # define ATPSETERM ioctl(STDIN_FILENO, TIOCSETP, &savedterm ) 318 # endif 319 #else 320 # define ATPGETERM ; 321 # define ATPSETERM ; 322 # define save_terminal() ; 323 # define restore_terminal() ; 324 #endif 325 326 #ifndef CLSCRN 327 #define CLSCRN cls 328 #endif 329 330 #ifdef __ATP_LOOSE__ 331 #define CONSPTR * 332 #else 333 #define CONSPTR *const 334 #endif 335 336 #ifndef STDIN_FILENO 337 #define STDIN_FILENO 0 338 #define STDOUT_FILENO 1 339 #define STDERR_FILENO 2 340 #endif 341 342 343 #ifdef __cplusplus 344 #define EXTERNC extern "C" 345 #else 346 #define EXTERNC extern 347 #endif 348 349 #if !defined(HAVE_STRNICMP) 350 #if defined(HAVE_STRNCASECMP) 351 #define strnicmp strncasecmp 352 #define stricmp strcasecmp 353 #define HAVE_STRNICMP 354 EXTERNC int strncasecmp(const char *s1, const char *s2, size_t n); 355 EXTERNC int strcasecmp(const char *s1, const char *s2); 356 #else 357 int strnicmp(const char *s1, const char *s2, size_t n); 358 int stricmp(const char *s1, const char *s2); 359 #endif 360 #endif 361 362 363 #ifdef NEEDISKS /* brain dead dos stuff */ 364 #ifdef __MSDOS__ 365 int getdisk(void); 366 int setdisk(int driv); 367 #endif 368 #endif 369 370 #ifndef R_OK 371 #define R_OK 4 372 #define W_OK 2 373 #define X_OK 1 374 #define F_OK 0 375 #endif 376 377 #ifndef SEEK_SET 378 #define SEEK_SET 0 379 #define SEEK_CUR 1 380 #define SEEK_END 2 381 #endif 382 383 /* define ATP tagline */ 384 385 #define ATPVER " 1.50 " /* DON'T CHANGE THIS it will mess up formatting */ 386 387 /* #define ATPSYST "your_system" */ /* you shouldn't have to define this */ 388 389 #ifndef ATPSYST 390 #ifdef __linux__ 391 #define ATPSYST "Linux" 392 #elif defined(hurd) 393 #define ATPSYST "Hurd" 394 #elif defined(esix) 395 #define ATPSYST "Esix" 396 #elif defined(NeXT) 397 #define ATPSYST "NeXT" 398 #elif defined(__IBCS2__) 399 #define ATPSYST "ibcs2" 400 #elif defined(WIN32) 401 #define ATPSYST "Win32" 402 #elif defined(__EMX__) 403 #define ATPSYST "OS2" 404 #elif defined(_OS2) 405 #define ATPSYST "OS2" 406 #elif defined(xenix) 407 #define ATPSYST "Xenix" 408 #elif defined(usl) 409 #define ATPSYST "USL" 410 #elif defined(DJGPP) 411 #define ATPSYST "djgpp" 412 #elif defined _MSC_ 413 #define ATPSYST "msc" 414 #elif defined(__MSDOS__) 415 #define ATPSYST "qwk" 416 #elif defined(amiga) 417 #define ATPSYST "Amiga" 418 #elif defined(mach) 419 #define ATPSYST "Mach" 420 #elif defined(sun) 421 #define ATPSYST "Sun" 422 #elif defined(BSD) 423 #define ATPSYST "bsd" 424 #elif defined(ATPUNAM) 425 #define ATPSYST ATPUNAM 426 #elif defined(unix) 427 #define ATPSYST "Unix" 428 #else 429 #define ATPSYST "QWK" 430 #endif 431 #endif 432 433 #define NTAG "\n---\n \376 ATP/" ATPSYST ATPVER "\376 " 434 #define FTAG "\n...\n * ATP/" ATPSYST ATPVER "* " 435 #ifdef __EMX__ 436 #define NTAX "\n---\n \376 ATP/emx" ATPVER "\376 " 437 #define FTAX "\n...\n * ATP/emx" ATPVER "* " 438 #endif 439 440 #ifdef BADLWR /* some versions of GCC 1.40 and before */ 441 #undef tolower(c) 442 #undef toupper(c) 443 #define tolower(x) (((x)>0x40)&&((x)<0x5b)?((x)|0x20):(x)) 444 #define toupper(x) (((x)>0x60)&&((x)<0x7b)?((x)&0xdf):(x)) 445 #endif 446 447 /* provide the posix tmpnam() if it is missing; define it in system.c */ 448 #ifndef L_tmpnam 449 #define L_tmpnam 30 450 #define NEEDTMPNAM 451 #endif 452 453 #if !defined(HAVE_TMPNAM) || defined(NEEDTMPNAM) 454 char *mytmprnam(/*@out@*/ char *buf ); 455 #define tmpnam(s) mytmprnam(s) 456 #endif 457 458 #if !defined(HAVE_STRSTR) 459 char *strstr(const char *haystack, const char *needle); 460 #endif 461 462 #if !defined(HAVE_PERROR) 463 #define perror(X) fprintf(stderr,"%s %s: %d\n", X , __FILE__ , __LINE__ ) 464 #endif 465 466 #if !defined(CHPATH) 467 #define CHPATH chdir 468 #endif 469 470 #if !defined(GETCWD) 471 #define GETCWD getcwd 472 #endif 473 474 #if defined(HAVE_SYS_WAIT_H) 475 #include <sys/wait.h> 476 #endif 477 478 /* define DESQVP to make program DESQview aware */ 479 480 #if defined(DESQVP) && defined(__MSDOS__) 481 #define A_DVPAUZ dv_pause(); 482 #define FCPYBUF (size_t)1024 483 void dv_pause( void ); 484 #else 485 #define A_DVPAUZ ; 486 #define FCPYBUF (size_t)4096 487 #endif 488 489 #ifndef ROW_OFFSET 490 #define ROW_OFFSET 3 491 #endif 492 493 #ifdef DOSTIME 494 #define ADJUST_DOS_TIME t -= timezone; 495 extern void msdos_time_init( void ); 496 #else 497 #define ADJUST_DOS_TIME /* nothing */ 498 #endif 499 500 #endif /* _ATP_SYSTEM_H */ 501 502