home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d172 / spiff.lha / Spiff / misc.c.orig < prev    next >
Text File  |  1988-11-22  |  2KB  |  120 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2. **                            All Rights Reserved
  3. **       Permission is granted to copy or use this program, EXCEPT that it
  4. **       may not be sold for profit, the copyright notice must be reproduced
  5. **       on copies, and credit should be given to Bellcore where it is due.
  6. **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7. */
  8.  
  9.  
  10. #ifndef lint
  11. static char rcsid[]= "$Header: misc.c,v 1.1 88/09/15 11:34:01 daniel Rel $";
  12. #endif
  13.  
  14. #include <stdio.h>
  15. #include "misc.h"
  16. #include "visual.h"
  17. #include "output.h"
  18.  
  19. /*
  20. **    various routines used throughout the program
  21. */
  22.  
  23. static int _Z_qflag = 0;
  24.  
  25. void
  26. Z_setquiet()
  27. {
  28.     _Z_qflag = 1;
  29. }
  30.  
  31. char Z_err_buf[Z_LINELEN];
  32.  
  33. #ifndef NOCHATTER
  34. /*
  35. **    I/O coverup to reassure users with HUGE files
  36. **    that spiff is doing something
  37. */
  38. void
  39. Z_chatter(str)
  40. char *str;
  41. {
  42.     if (!_Z_qflag)
  43.     {
  44.         (void) fputs("spiff -- ",stderr);
  45.         (void) fputs(str,stderr);
  46.     }
  47. }
  48. #endif
  49.  
  50. /*
  51. **    complain unless you've been told to be quiet
  52. */
  53. void
  54. Z_complain(str)
  55. char *str;
  56. {
  57.     if (!_Z_qflag)
  58.         (void) fputs(str,stderr);
  59. }
  60.  
  61. /*
  62. **    quit with an error code
  63. */
  64. static void
  65. _Z_errexit()
  66. {
  67.     (void) exit(2);
  68. }
  69.  
  70. /*
  71. **    complain and die
  72. */
  73. void
  74. _Z_qfatal(str)
  75. char *str;
  76. {
  77.     V_cleanup();    /* try reset the device to normal */
  78.     O_cleanup();    /*  "    "    "     "   "    "    */
  79.     Z_complain(str);
  80.     _Z_errexit();
  81. }
  82.  
  83. /*
  84. **    scream and die
  85. */
  86. void
  87. Z_fatal(str)
  88. char *str;
  89. {
  90.     V_cleanup();    /* try reset the device to normal */
  91.     O_cleanup();    /*  "    "    "     "   "    "    */
  92.     (void) fputs(str,stderr);
  93.     _Z_errexit();
  94. }
  95.  
  96. /*
  97. **    allocate memory with error checking
  98. */
  99. int*
  100. _Z_myalloc(k)
  101. int k;
  102. {
  103.     int *tmp;
  104.     if (tmp = (int*) calloc((unsigned)k,(unsigned)1))
  105.     {
  106.         return(tmp);
  107.     }
  108.     Z_fatal("Out of Memory\n");
  109.     return(tmp);    /* boilerplate to shut up lint */
  110. }
  111.  
  112. void
  113. Z_exceed(d)
  114. int d;
  115. {
  116.     (void) sprintf(Z_err_buf,
  117.         "The files differ in more than %d places\n", d);
  118.     _Z_qfatal(Z_err_buf);
  119. }
  120.