home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 165_01 / config.d < prev    next >
Text File  |  1988-02-18  |  19KB  |  553 lines

  1. ###portdefs.h
  2. /* portdefs.h - definitions for portability */
  3. @@ ENVIRONMENT-DEPENDENT - ADJUST TO LOCAL SYSTEM */
  4. @@ Edit your local changes, then replace each "@@" with "/*" */
  5. #ifndef PORTDEFS_H
  6. #define PORTDEFS_H
  7.  
  8. /* adjust these names to local machine/compiler environment */
  9. typedef unsigned short ushort;    @@ or "unsigned" if short-size == int-size */
  10. typedef unsigned char utiny;    @@ to get unsigned byte */
  11. typedef int void;                @@ delete if compiler supports void */
  12. typedef unsigned index_t;        @@ may be chosen ad-lib locally */
  13. typedef char *data_ptr;            @@ use ANSI "generic ptr" if available */
  14.  
  15. /* next 5 names require no local changes, will work anywhere */
  16. typedef char tbits;                /* one byte, for bitwise uses */
  17. typedef char tbool;                /* one byte: {0:1} */
  18. typedef ushort bits;            /* 16 bits (or more), for bitwise uses */            
  19. typedef int bool;                /* for function returns: {0:1} */
  20. typedef short metachar;            /* return from getchar: {EOF,0:UCHAR_MAX} */
  21.  
  22. /* modulo function giving non-negative result */
  23. #define IMOD(i, j) (((i) % (j)) < 0 ? ((i) % (j)) + (j) : ((i) % (j)))
  24. @@ if i % j is never negative, replace with the following line: */
  25. @@ #define IMOD(i, j) ((i) % (j)) */
  26.  
  27. /* portably convert unsigned number to signed */
  28. #define UI_TO_I(ui) (int)(ui)    @@ more complicated on ones complement */
  29.  
  30. /* structure offsets and bounds; adjust to local system */
  31. #define STRICT_ALIGN int        @@ adjust to local alignment requirement */
  32. #define OFFSET(st, m) \
  33.     ((char *)&((st *)&struct_addr)->m - (char *)&struct_addr)
  34. #define BOUNDOF(t) \
  35.     ((char *)(struct {char byte0; t byten; } *)&struct_addr)->byten - \
  36.     (char *)&struct_addr)
  37. static STRICT_ALIGN struct_addr = 0;
  38. #define STRUCTASST(a, b) memcpy(&(a), &(b), sizeof(a))
  39.  
  40. /* defined constants */
  41. #define FAIL            1            @@ failure exit */
  42. #define SUCCEED            0            @@ normal exit */
  43. #define STDIN            0            /* standard input */
  44. #define STDOUT            1            /* standard output */
  45. #define STDERR            2            /* standard error output */
  46. #define SEEK_SET        0            /* seek relative to start of file */
  47. #define SEEK_CUR        1            /* seek relative to current position */
  48. #define SEEK_END        2            /* seek relative to end */
  49. #endif
  50. ###stddef.h
  51. /* stddef.h - standard definitions (partial listing) */
  52. @@ ENVIRONMENT-DEPENDENT - ADJUST TO LOCAL SYSTEM */
  53. @@ Edit your local changes, then replace each "@@" with "/*" */
  54. @@ Use your compiler's own <stddef.h>, if available */
  55. #ifndef STDDEF_H
  56. #define STDDEF_H
  57. typedef unsigned size_t;    @@ use unsigned long in large-object model */
  58.  
  59. #ifndef NULL
  60. #define NULL 0                @@ use 0L if  int-size < long-size == ptr-size */
  61. #endif
  62.  
  63. extern int errno;
  64. #endif
  65. ###limits.h
  66. /* limits.h - environment limits (partial listing) */
  67. @@ ENVIRONMENT-DEPENDENT - CONFIGURE BEFORE USING */
  68. @@ Edit your local changes, then replace each "@@" with "/*" */
  69. @@ Use your compiler's own <limits.h>, if available */
  70. #ifndef LIMITS_H
  71. #define LIMITS_H
  72. #define CHAR_BIT    8    @@ CONFIGURE */
  73. #endif
  74. ###c.pro
  75. # C.PRO - A CONFIGURATION FILE FOR WHITESMITHS C 3.0
  76. #    STANDARD ANSI C LIBRARY PROTO FILE
  77. #    CNDOS86     NATIVE MSDOS
  78. #    PROGRAMMABLE FLAG OPTIONS:
  79. #
  80. #    com    : create an 8080 model .com file
  81. #    debug    : load debugger with any C compile
  82. #    fpp    : use hardware floating point
  83. #    lincl    : include header files in listing or diagnostic output
  84. #    listcs    : create c/assembler listing
  85. #    lo    : create a file (r).lst for listings (default to STDOUT)
  86. #    mods    : uniform small model (64K data and 64K text maximum)
  87. #    modp    : uniform medium model (64K data and multiple text sections)
  88. #    modd    : uniform compact model (64K text and multiple data sections)
  89. #    modf    : uniform far model (multiple text and data sections)
  90. #    proto    : enable prototype checking
  91. #    savlnk    : save linker input file as (r).lnk
  92. #    pponly    : run pp only
  93.  
  94. sp:pp        -o (o) \
  95.         -i  "|a:/headers.d/|c:/c/hdrs/" \
  96.         c:/c/hdrs/do86{modp?p:{modd?d:{modf?f:s}}}f.h (i)
  97. s:
  98.  
  99. c:pp        -o (o) {lincl?+lincl} {pponly?:-x}  \
  100.         -i  "|a:/headers.d/|c:/c/hdrs/" \
  101.         -d_PROTO \
  102.         c:/c/hdrs/do86{modp?p:{modd?d:{modf?f:s}}}f.h (i)
  103. 1:cp1        -o (o) -cm {debug?+debug} -n31 +std \
  104.         -model{modp?p:{modd?d:{modf?f:s}}} (i)
  105. 2:p286        -o (o) -f \
  106.         {listcs?+list} (i)
  107. s:as86        -o (o) \
  108.         {listcs?+list -lo (r).lst} (i)
  109.  {listcs?lm    -o (r).asl -lt (r).lst}
  110.  {listcs?pr    (r).asl {lo?>(r).lst}}
  111.  {listcs?del    (r).asl}
  112.  
  113. o::echo     -o (o) > (r).lnk
  114.  type        c:\\c\\hdrs\\do86{com?c:{modp?p:{modd?d:{modf?f:s}}}}.lf \
  115.             >> (r).lnk
  116.  echo        (i) {modp?+text:{modd?+data:{modf?+text +data}}} >> (r).lnk
  117.  echo        \
  118.         c:/c/lib/liba{modp?p:{modd?d:{modf?f:s}}}f.86 \
  119.         c:/c/lib/libb{modp?p:{modd?d:{modf?f:s}}}f.86 \
  120.         c:/c/lib/libm{modp?p:{modd?d:{modf?f:s}}}f.86 \
  121.         {modd?+bss:{modf?+bss:}} >> (r).lnk
  122.  lnk          < (r).lnk
  123.  {savlnk?:del    (r).lnk}
  124. {com?:xeq:}
  125. com:
  126. xeq:todos -o (o) (i)
  127. exe:
  128. ###makefile
  129. @@ ENVIRONMENT-DEPENDENT - HAND-TAILOR EVERY LINE WITH "@@"
  130. @@ THEN EITHER DELETE THE "@@" MESSAGE OR CHANGE TO "#"
  131. #
  132. # Assumes that all files are named  function-name.c
  133. # For complexities like atopi(#2.c, copy the last one to
  134. # a simple name like atopi.c
  135. #
  136. # Note: Successful result of a test is recorded by creation of
  137. # a file named <pgm-name>.ok; see cmpok.c for further info.
  138.  
  139. # Configuration
  140. RM = del    @@ what command removes a file
  141. CC = cc    @@ the compile command
  142. CFLAGS =     @@ what options to pass to the compile command
  143. O = obj    @@ the file "extension" for object files
  144. X = exe    @@ the file "extension" for executable files
  145. NOLINK = -c    @@ the CC option that says "don't link"
  146. LIB = lib    @@ the library/archive command
  147. LIBADD = lib -a    @@ library/archive command to add a module
  148. L = a    @@ the file "extension" for object libraries
  149. RUN =     @@ command prefix (if any) for executing a program
  150. .C.O = $(CC) $(CFLAGS) $(NOLINK) $&        @@ rule for making p.c into p.o
  151. .C.EXE = $(CC) $(CFLAGS) -o $*.$X $&    @@ rule for making p.c into p.exe
  152. .EXE.OK = $(RUN) $*.$X     @@ rule for making p.exe into p.ok
  153.  
  154.  
  155. COMMON = rdslib.$L
  156. ST_MAIN = st_main.$O st_close.$O st_pop.$O st_push.$O 
  157. T_MAIN = t_main.$O q_pop.$O q_close.$O q_insert.$O  q_push.$O q_append.$O q_r_insert.$O
  158. SCREEN = screen86.$O
  159.  
  160. all : atopi.ok  st_main.ok t_main.ok t2_main.ok tr_main.ok dq_main.ok dq2_main.ok plot_m.$X run_cars.$X rec_main.$X crhash.$X part_menu.$X part_tmenu.$X part_hmenu.$X
  161.     touch uptodate.all
  162.  
  163. rdslib.$L : itoa.$O fgetsnn.$O getsnn.$O getreply.$O getpstr.$O getplin.$O plot_trk.$O reverse.$O strfit.$O error.$O fixstr.$O
  164.     $(LIB) rdslib.$L getreply.$O getpstr.$O getplin.$O getsnn.$O fgetsnn.$O
  165.     $(LIBADD) rdslib.$L itoa.$O plot_trk.$O reverse.$O strfit.$O error.$O fixstr.$O
  166.  
  167. mu_lib.$L : mu_lib.$O mu_ask.$O mu_chv.$O mu_str.$O mu_sval.$O mu_pr.$O mu_do.$O mu_reply.$O 
  168.     $(LIB) mu_lib.$L  mu_lib.$O mu_ask.$O mu_chv.$O mu_str.$O mu_sval.$O mu_pr.$O mu_do.$O mu_reply.$O 
  169.  
  170. dq_lib.$L : dq_lib.$O dq_open.$O dq_close.$O dq_detach.$O dq_r_insert.$O dq_pop.$O dq_insert.$O dq_find.$O dq_first.$O
  171.     $(LIB) dq_lib.$L dq_lib.$O dq_open.$O dq_close.$O dq_detach.$O dq_r_insert.$O dq_pop.$O dq_insert.$O dq_find.$O dq_first.$O
  172.  
  173. tr_lib.$L : tr_delete.$O tr_lnext.$O tr_lfind.$O tr_lpfind.$O tr_insert.$O tr_detach.$O tr_close.$O tr_lfirst.$O
  174.     $(LIB) tr_lib.$L tr_delete.$O tr_lnext.$O tr_lfind.$O tr_lpfind.$O tr_insert.$O tr_detach.$O tr_close.$O tr_lfirst.$O
  175.  
  176. rec_lib.$L : rec_hfind.$O rec_havail.$O rec_open.$O rec_close.$O rec_get.$O rec_put.$O 
  177.     $(LIB) rec_lib.$L  rec_hfind.$O rec_havail.$O rec_open.$O rec_close.$O rec_get.$O rec_put.$O 
  178.  
  179. menu_lib.$L : chg_menu.$O add_menu.$O acd_menu.$O del_menu.$O
  180.     $(LIB) menu_lib.$L chg_menu.$O add_menu.$O acd_menu.$O del_menu.$O
  181.  
  182. tr_main.$X : tr_main.$O tr_lib.$L $(COMMON)
  183.     $(CC) $(CFLAGS) -o tr_main.$X tr_main.$O tr_lib.$L $(COMMON)
  184.  
  185. tr_main.ok : tr_main.$X
  186.     $(RUN) tr_main.$X >tr_main.out
  187.     cmpok tr_main
  188.  
  189. part_menu.$X : part_menu.$O mu_lib.$O menu_lib.$L part_db.$O $(SCREEN) $(COMMON)
  190.     $(CC) $(CFLAGS) -o part_menu.$X part_menu.$O mu_lib.$O menu_lib.$L part_db.$O $(SCREEN) $(COMMON)
  191.  
  192. part_tmenu.$X : part_tmenu.$O mu_lib.$O menu_lib.$L part_dbt.$O tr_lib.$L $(SCREEN) $(COMMON)
  193.     $(CC) $(CFLAGS) -o part_tmenu.$X part_tmenu.$O mu_lib.$O menu_lib.$L part_dbt.$O tr_lib.$L $(SCREEN) $(COMMON)
  194.  
  195. plot_m.$X : plot_m.$O $(SCREEN) $(COMMON)
  196.     $(CC) $(CFLAGS) -o plot_m.$X plot_m.$O $(SCREEN) $(COMMON)
  197.  
  198. cmpok.$X : cmpok.$O $(COMMON)
  199.     $(CC) $(CFLAGS) -o cmpok.$X cmpok.$O $(COMMON)
  200.  
  201. atopi.ok : atopi.$X atopi.in
  202. atopi.$X : xatopi.$O atopi.$O $(COMMON)
  203.     $(CC) $(CFLAGS) -o atopi.$X  xatopi.$O atopi.$O $(COMMON)
  204.  
  205. st_main.ok : st_main.$X st_main.in
  206.     $(RUN) st_main <st_main.in >st_main.out
  207.     cmpok st_main
  208. st_main.$X : $(ST_MAIN) $(COMMON)
  209.     $(CC) $(CFLAGS) -o st_main.$X $(ST_MAIN) $(COMMON)
  210.  
  211. t_main.ok : t_main.$X t_main.in
  212.     $(RUN) t_main <t_main.in >t_main.out
  213.     cmpok t_main
  214. t_main.$X : $(T_MAIN) $(COMMON)
  215.     $(CC) $(CFLAGS) -o t_main.$X $(T_MAIN) $(COMMON)
  216.  
  217. t2_main.ok : t2_main.$X 
  218.     $(RUN) t2_main.$X >t2_main.out
  219. t2_main.$X : t2_main.$O $(COMMON)
  220.     $(CC) $(CFLAGS) -o t2_main.$X  t2_main.$O $(COMMON)
  221.  
  222. run_cars.ok : run_cars.$X
  223.     $(RUN) run_cars.$X 2 <run_cars.in >run_cars.out
  224.     cmpok run_cars
  225. run_cars.$X : run_cars.$O dq_lib.$O $(SCREEN) $(COMMON)
  226.     $(CC) $(CFLAGS) -o run_cars.$X  run_cars.$O dq_lib.$O $(SCREEN) $(COMMON)
  227.  
  228. dq_main.ok : dq_main.$X
  229.     $(RUN) dq_main.$X  <dq_main.in >dq_main.out
  230.     cmpok dq_main
  231. dq_main.$X : dq_main.$O dq_lib.$O $(COMMON)
  232.     $(CC) $(CFLAGS) -o dq_main.$X  dq_main.$O dq_lib.$O $(COMMON) 
  233.  
  234. dq2_main.ok : dq2_main.$X
  235.     $(RUN) dq2_main.$X  >dq2_main.out
  236.     cmpok dq2_main
  237. dq2_main.$X : dq2_main.$O dq_lib.$O $(COMMON)
  238.     $(CC) $(CFLAGS) -o dq2_main.$X  dq2_main.$O dq_lib.$O $(COMMON) 
  239.  
  240. rec_main.ok : rec_main.$X
  241.     $(RUN) rec_main.$X  >rec_main.out
  242.     cmpok rec_main
  243. rec_main.$X : rec_main.$O rec_lib.$L $(COMMON)
  244.     $(CC) $(CFLAGS) -o rec_main.$X rec_main.$O rec_lib.$L  $(COMMON) 
  245.  
  246. crhash.$X : crhash.$O rec_lib.$L $(COMMON)
  247.     $(CC) $(CFLAGS) -o crhash.$X crhash.$O rec_lib.$L  $(COMMON) 
  248.  
  249. part.dat : crhash.$X
  250.     crhash.$X part.dat 5 33
  251.  
  252. part_hmenu.$X : part_menu.$O mu_lib.$O menu_lib.$L part_hash.$O rec_lib.$L $(SCREEN) $(COMMON)
  253.     $(CC) $(CFLAGS) -o part_hmenu.$X part_menu.$O mu_lib.$O menu_lib.$L part_hash.$O rec_lib.$L $(SCREEN) $(COMMON)
  254.  
  255. gen_menu.ok : gen_menu.$X
  256.     $(RUN) gen_menu.$X "<add_menu.mu >gen_menu.out"
  257.     cmpok.$X gen_menu
  258. gen_menu.$X : gen_menu.$O $(COMMON)
  259.     $(CC) $(CFLAGS) -o gen_menu.$X  gen_menu.$O $(COMMON)
  260. ###myfcntl.h
  261. /* fcntl.h - definitions for binary  open
  262.  * Compatible with UNIX Sys V, ...
  263.  */
  264. #ifndef FCNTL_H
  265. #define FCNTL_H
  266. #define O_RDONLY 0        /* delete or change to conform to local */
  267. #define O_WRONLY 1        /* delete or change to conform to local */
  268. #define O_RDWR   2        /* delete or change to conform to local */
  269. #define O_NDELAY 4        /* NOT USED BY bin_io FUNCTIONS */
  270. #define O_APPEND 8        /* delete or change to conform to local */
  271. #define O_CREAT  0x100    /* delete or change to conform to local */
  272. #define O_TRUNC  0x200    /* delete or change to conform to local */
  273. #define O_EXCL   0x400    /* delete or change to conform to local */
  274. #endif
  275. ###mystdarg.h
  276. typedef char *va_list;
  277. #define va_start(a, p) (a = ((char *)&p + sizeof(p)))
  278. #define va_arg(a, t) ((t *)(a += sizeof(t)))[-1]
  279. #define va_end(a)
  280. ###mystddef.h
  281. /* stddef.h - standard definitions (partial listing) */
  282. /* ENVIRONMENT-DEPENDENT - ADJUST TO LOCAL SYSTEM */
  283. @@ Change each @@ to start-comment after configuring */
  284. #ifndef STDDEF_H
  285. #define STDDEF_H
  286. typedef unsigned size_t;    @@ use unsigned long in large-object model */
  287.  
  288. #ifndef NULL
  289. #define NULL 0                @@ use 0L if  int-size < long-size == ptr-size */
  290. #endif
  291.  
  292. extern int errno;
  293. #endif
  294. ###mystdio.h
  295. /**
  296. *
  297. * This header file defines the information used by the standard I/O
  298. * package.
  299. *
  300. **/
  301. #define _BUFSIZ 512        /* standard buffer size */
  302. #define BUFSIZ 512        /* standard buffer size */
  303. #define _NFILE 20        /* maximum number of files */
  304.  
  305. struct _iobuf
  306. {
  307. char *_ptr;            /* current buffer pointer */
  308. int _rcnt;            /* current byte count for reading */
  309. int _wcnt;            /* current byte count for writing */
  310. char *_base;             /* base address of I/O buffer */
  311. char _flag;            /* control flags */
  312. char _file;            /* file number */
  313. int _size;            /* size of buffer */
  314. char _cbuff;            /* single char buffer */
  315. char _pad;            /* (pad to even number of bytes) */
  316. };
  317.  
  318. extern struct _iobuf _iob[_NFILE];
  319.  
  320. #define _IOREAD 1        /* read flag */
  321. #define _IOWRT 2        /* write flag */
  322. #define _IONBF 4        /* non-buffered flag */
  323. #define _IOMYBUF 8        /* private buffer flag */
  324. #define _IOEOF 16        /* end-of-file flag */
  325. #define _IOERR 32        /* error flag */
  326. #define _IOSTRG 64
  327. #define _IORW 128        /* read-write (update) flag */
  328.  
  329. #define NULL 0            /* null pointer value */
  330. #define FILE struct _iobuf    /* shorthand */
  331. #define EOF (-1)        /* end-of-file code */
  332.  
  333. #define stdin (&_iob[0])    /* standard input file pointer */
  334. #define stdout (&_iob[1])    /* standard output file pointer */
  335. #define stderr (&_iob[2])    /* standard error file pointer */
  336.  
  337. #define getc(p) (--(p)->_rcnt>=0? *(p)->_ptr++:_filbf(p))
  338. #define getchar() getc(stdin)
  339. #define putc(c,p) (--(p)->_wcnt>=0? ((int)(*(p)->_ptr++=(c))):_flsbf((c),p))
  340. #define putchar(c) putc(c,stdout)
  341. #define feof(p) (((p)->_flag&_IOEOF)!=0)
  342. #define ferror(p) (((p)->_flag&_IOERR)!=0)
  343. #define fileno(p) (p)->_file
  344. #define rewind(fp) fseek(fp,0L,0)
  345. #define fflush(fp) _flsbf(-1,fp)
  346.  
  347. FILE *fopen();
  348. FILE *freopen();
  349. long ftell();
  350. char *fgets();
  351.  
  352. #define abs(x) ((x)<0?-(x):(x))
  353. #define max(a,b) ((a)>(b)?(a):(b))
  354. #define min(a,b) ((a)<=(b)?(a):(b))
  355.  
  356. /* Additions needed by Safe C */
  357. #ifdef SC
  358. #undef getc
  359. #undef putc
  360. /* When using the D or L model, define NULL as 0L */
  361. /* */
  362. #ifdef LARGEMODEL
  363. #undef NULL
  364. #define NULL 0L
  365. #endif
  366. /* */
  367.  
  368. char *_gets(), *_fgets();
  369. struct _iobuf *__fopen(), *__freopen();
  370. long ftell();
  371. #endif
  372. ###scr_w_86.c
  373. /* screen - environment-specific terminal functions
  374.  * PC Version - uses  WSL 3.1 sys-dependent fns  
  375.  */
  376. #include "local.h"
  377. #include "screen.h"
  378. short scr_mode = SCR_TTY;    /* screen mode - TTY or RAW */
  379. short scr_lins = 24;    /* screen lines (default) */
  380. short scr_cols = 80;    /* screen columns (default) */
  381. /* rawget - get one char (assuming raw mode) */
  382. static char rawget()
  383.     {
  384.     char c;
  385.  
  386.     _read(0, &c, 1);
  387.     return (c);
  388.     }
  389. /* scr_getkey - get a (coded) keyboard char */
  390. SCR_CMDCHAR scr_getkey()
  391.     {
  392.     char c1;
  393.     
  394.     scr_refresh();    /* ensure all output is flushed */
  395.     if ((c1 = rawget()) != '\0')
  396.         return (c1 & 0x7F);
  397.     switch (c1 = rawget())
  398.         {
  399.     /* no "break" needed - all returns */
  400.     case 'H':    return (SCR_UP);
  401.     case 'P':    return (SCR_DOWN);
  402.     case 'M':    return (SCR_RIGHT);
  403.     case 'K':    return (SCR_LEFT);
  404.     case 'G':    return (SCR_HOME);
  405.     case ';':    return (SCR_EXIT);    /* F1 function key */
  406.     case 'O':    return ('\r');    /* use END for RETURN */
  407.     default:    return (scr_getkey());
  408.         }
  409.     }
  410. /* remark - print error message, appropriate for scr_mode */
  411. void remark(s1, s2)
  412.     char s1[], s2[];    /* strings to be printed */
  413.     {
  414.     if (scr_mode == SCR_TTY)
  415.         fprintf(stderr, "%s %s\n", s1, s2);
  416.     else
  417.         {
  418.         scr_curs(scr_lins-1, 0);
  419.         scr_print("%s %s; hit any key to continue", s1, s2);
  420.         scr_getkey();
  421.         }
  422.     }
  423. /* scr_open - enter "raw" screen mode */
  424. void scr_open()
  425.     {
  426.     scr_mode = SCR_RAW;
  427.     _rawmode(0, 1);
  428.     _rawmode(1, 1);
  429.  
  430.     /* DEBUGGING: REMOVE BEFORE FINAL PRINTING */
  431.     if (strcmp(getenv("BUFTYPE"), "setbuf") == 0)
  432.         setbuf(stdout, NULL);
  433.     else if (strcmp(getenv("BUFTYPE"), "setvbuf") == 0)
  434.         setvbuf(stdout, NULL, _IONBF, 0);
  435.     /* END OF DEBUGGING */
  436.     }
  437. /* scr_close - restore normal tty state */
  438. void scr_close()
  439.     {
  440.     scr_mode = SCR_TTY;
  441.     _rawmode(0, 0);
  442.     _rawmode(1, 0);
  443.     }
  444. ###wsl_bin_io.h
  445. /* bin_io.h - header for binary file I/O functions */
  446. /* Whitesmiths 2.3 version */
  447. #ifndef BIN_IO_H
  448. #define BIN_IO_H
  449. #include "local.h"
  450.  
  451. #define BIN_FILE FILE
  452.  
  453. int bin_fclose();        /* PARMS(BIN_FILE *bf) */
  454. long bin_fseek();        /* PARMS(BIN_FILE *bf, long offset, int whence) */
  455. BIN_FILE *bin_fopen();    /* PARMS(char fname[], char type[]) */
  456. int bin_fread();
  457.             /* PARMS(data_ptr buf, size_t size, int n, BIN_FILE *bf) */
  458. int bin_fread();
  459.             /* PARMS(data_ptr buf, size_t size, int n, BIN_FILE *bf) */
  460.  
  461. /* {{ CHANGE THE FOLLOWING TO ANSI STYLE BEFORE PRINTING }} */
  462.  
  463. #define bin_b4r_seek(bf)    /* nothing, no action needed */
  464. #define bin_b4w_seek(bf)    /* nothing, no action needed */
  465.  
  466. #define bin_fclose(bf)        close(bf)
  467. #define bin_fseek(bf, o, w)    (long)lseek(bf, o, w)    /* WSL - no "tell" */
  468. #define bin_fwrite(b, sz, n, bf)    write(bf, b, (sz)*(n))
  469.  
  470. #endif
  471. ###w_bin_open.c
  472. /* bin_open - open a binary file 
  473.  * WSL 2.3 version
  474.  */
  475. #include "bin_io.h"
  476. bin_fd bin_open(fname, type)
  477.     char fname[];
  478.     int type;
  479.     {
  480.     int fd;
  481.  
  482.     if ((type & O_TRUNC) != O_TRUNC)    /* not TRUNC mode */
  483.         {
  484.         fd = open(fname, type & O_RWMODE, 1);        /* attempt open */
  485.         if (fd >= 0)
  486.             {
  487.             if ((type & (O_EXCL|O_CREAT)) == (O_EXCL|O_CREAT))
  488.                 return (-1);            /* not allowed to exist */
  489.             else
  490.                 return (fd);            /* open succeeded */
  491.             }
  492.         else if ((type & O_RWMODE) == O_RDONLY)
  493.             return (fd);                /* rdonly, open failed */
  494.         }
  495.     if ((type & O_CREAT) != O_CREAT)
  496.         return (-1);                    /* not allowed to create */
  497.     fd = create(fname, type & O_RWMODE, 1);        /* attempt create */
  498.     return (fd);
  499.     }
  500. ###xatopi.c
  501. /* xatopi - test harness for atopi function */
  502. #include "local.h"
  503. #define MINIMAL_WRITE(f) /* write nothing; empty file ok for semaphore */
  504. void fixstr(char *);
  505. main()
  506.     {
  507.     int i;        /* which case {0:N} */
  508.     int ret;    /* returned value from atopi */
  509.     char source[80];    /* source string for atopi */
  510.     char desc[80];        /* description of test case */
  511.     int expect;        /* expected result */
  512.     bool was_ok = YES;    /* successful test? */
  513.     FILE *fin;        /* input file with test cases */
  514.     FILE *fout;        /* output file for "ok" */
  515.     int nread;        /* number of input items read */
  516.  
  517.     fin = fopen("atopi.in", "r");
  518.     if (fin == NULL)
  519.         error("can't open", "atopi.in");
  520.     while (getc(fin) != '\n')
  521.         ;
  522.     while (getc(fin) != '\n')
  523.         ;
  524.     FOREVER
  525.         {
  526.         nread = fscanf(fin,
  527.             "%s %d %[^\n]",
  528.             source, &expect, desc);
  529.         if (nread == EOF)
  530.             break;
  531.         else if (nread != 3)
  532.             error("bad input at or after source =", source);
  533.         fixstr(source);
  534.         ret = atopi(source);
  535.         if (ret != expect)
  536.             {
  537.             printf("Failed case: <%s>: ", desc);
  538.             printf("source=<%s>, ret=<%d>\n", source, ret);
  539.             was_ok = NO;
  540.             }
  541.         }
  542.     if (was_ok)
  543.         {
  544.         fout = fopen("atopi.ok", "w");
  545.         MINIMAL_WRITE(fout);
  546.         fclose(fout);
  547.         exit(SUCCEED);
  548.         }
  549.     else
  550.         exit(FAIL);
  551.     }
  552. ###EOF
  553.