home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff232.lzh / Dbug / useful.h < prev    next >
C/C++ Source or Header  |  1989-08-02  |  2KB  |  83 lines

  1. /*
  2.  * Copyright June 1987, Binayak Banerjee
  3.  * All rights reserved.
  4.  *
  5.  * This program may be freely distributed under the same terms and
  6.  * conditions as Fred Fish's Dbug package.
  7.  *
  8.  * Useful macros which I use a lot.
  9.  *
  10.  * Conditionally include some useful files.
  11.  */
  12.  
  13. # ifndef EOF
  14. #    include <stdio.h>
  15. # endif
  16.  
  17. /*
  18.  *    For BSD systems, you can include <sysexits.h> for more detailed
  19.  *    exit information.  For non-BSD systems (which also includes
  20.  *    non-unix systems) just map everything to "failure" = 1 and
  21.  *    "success" = 0.        -Fred Fish 9-Sep-87
  22.  */
  23.  
  24. # ifdef BSD
  25. #    include <sysexits.h>
  26. # else
  27. #    define EX_SOFTWARE 1
  28. #    define EX_DATAERR 1
  29. #    define EX_USAGE 1
  30. #    define EX_OSERR 1
  31. #    define EX_IOERR 1
  32. #    define EX_OK 0
  33. # endif
  34.  
  35.  
  36. /*
  37.  * Fred Fish's debugging stuff.  Define DBUG_OFF in order to disable if
  38.  * you don't have these.
  39.  */
  40.  
  41. # ifndef DBUG_OFF
  42. #    include "dbug.h"        /* Use local version */
  43. # else
  44. #    define DBUG_ENTER(a1)
  45. #    define DBUG_RETURN(a1) return(a1)
  46. #    define DBUG_VOID_RETURN return
  47. #    define DBUG_EXECUTE(keyword,a1)
  48. #    define DBUG_2(keyword,format)
  49. #    define DBUG_3(keyword,format,a1)
  50. #    define DBUG_4(keyword,format,a1,a2)
  51. #    define DBUG_5(keyword,format,a1,a2,a3)
  52. #    define DBUG_PUSH(a1)
  53. #    define DBUG_POP()
  54. #    define DBUG_PROCESS(a1)
  55. #    define DBUG_PRINT(x,y)
  56. #    define DBUG_FILE (stderr)
  57. # endif
  58.  
  59. #define __MERF_OO_ "%s: Malloc Failed in %s: %d\n"
  60.  
  61. #define Nil(Typ)    ((Typ *) 0)    /* Make Lint happy */
  62.  
  63. #define MALLOC(Ptr,Num,Typ) do    /* Malloc w/error checking & exit */ \
  64.     if ((Ptr = (Typ *)malloc((Num)*(sizeof(Typ)))) == Nil(Typ)) \
  65.         {fprintf(stderr,__MERF_OO_,my_name,__FILE__,__LINE__);\
  66.         exit(EX_OSERR);} while(0)
  67.  
  68. #define Malloc(Ptr,Num,Typ) do    /* Weaker version of above */\
  69.     if ((Ptr = (Typ *)malloc((Num)*(sizeof(Typ)))) == Nil(Typ)) \
  70.         fprintf(stderr,__MERF_OO_,my_name,__FILE__,__LINE__);\
  71.          while(0)
  72.  
  73. #define FILEOPEN(Fp,Fn,Mod) do    /* File open with error exit */ \
  74.     if((Fp = fopen(Fn,Mod)) == Nil(FILE))\
  75.         {fprintf(stderr,"%s: Couldn't open %s\n",my_name,Fn);\
  76.         exit(EX_IOERR);} while(0)
  77.  
  78. #define Fileopen(Fp,Fn,Mod) do    /* Weaker version of above */ \
  79.     if((Fp = fopen(Fn,Mod)) == Nil(FILE)) \
  80.         fprintf(stderr,"%s: Couldn't open %s\n",my_name,Fn);\
  81.     while(0)
  82.  
  83.