home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_04 / 1n04028a < prev    next >
Text File  |  1990-03-29  |  868b  |  61 lines

  1. /*             LISTING 3                */
  2.  
  3.  
  4. /*    Example program to test error module */
  5.  
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include "err.h"
  10.  
  11. /* Local prototypes */
  12. BOOLEAN sub_a(int);
  13. BOOLEAN sub_b(void);
  14. BOOLEAN sub_c(PSTR);
  15.  
  16. void main()
  17. {
  18.     if (!sub_a(27)) {
  19.         err_push(ERR_FINISH_CMD, NULL);
  20.     }
  21.     if (err_state()) {
  22.         err_disp();
  23.         exit(1);
  24.     }
  25.     exit(0);
  26. }
  27.  
  28. BOOLEAN sub_a(int n)
  29. {
  30.     char str[30];
  31.  
  32.     if (!sub_b()) {
  33.         sprintf(str, " %d", n);
  34.         err_push(ERR_DELETE_RECORD, str);
  35.         return(FALSE);
  36.     }
  37.     return(TRUE);
  38. }
  39.  
  40. BOOLEAN sub_b()
  41. {
  42.     static char fname[] = "data.idx";
  43.  
  44.     if (!sub_c(fname)) {
  45.         err_push(ERR_OPEN_INDEX, fname);
  46.         return(FALSE);
  47.     }
  48.     return(TRUE);
  49. }
  50.  
  51. BOOLEAN sub_c(PSTR file)
  52. {
  53.     FILE *fd;
  54.  
  55.     if ((fd = fopen(file, "r")) == NULL) {
  56.         err_push(errno, file);
  57.         return(FALSE);
  58.     }
  59.     return(TRUE);
  60. }
  61.