home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / gawk2.0.t.Z / gawk2.0.t / awk5.c < prev    next >
Text File  |  1988-12-31  |  3KB  |  153 lines

  1. /*
  2.  * routines for error messages
  3.  *
  4.  * $Log:    awk5.c,v $
  5.  * Revision 1.10  88/12/08  11:00:07  david
  6.  * add $Log$
  7.  * 
  8.  */
  9.  
  10. /*
  11.  * GAWK is distributed in the hope that it will be useful, but WITHOUT ANY
  12.  * WARRANTY.  No author or distributor accepts responsibility to anyone for
  13.  * the consequences of using it or for whether it serves any particular
  14.  * purpose or works at all, unless he says so in writing. Refer to the GAWK
  15.  * General Public License for full details. 
  16.  *
  17.  * Everyone is granted permission to copy, modify and redistribute GAWK, but
  18.  * only under the conditions described in the GAWK General Public License.  A
  19.  * copy of this license is supposed to have been given to you along with GAWK
  20.  * so you can know your rights and responsibilities.  It should be in a file
  21.  * named COPYING.  Among other things, the copyright notice and this notice
  22.  * must be preserved on all copies. 
  23.  *
  24.  * In other words, go ahead and share GAWK, but don't try to stop anyone else
  25.  * from sharing it farther.  Help stamp out software hoarding! 
  26.  */
  27.  
  28. #include "awk.h"
  29.  
  30. int sourceline = 0;
  31. char *source = NULL;
  32.  
  33. err(s, argp)
  34. char *s;
  35. va_list *argp;
  36. {
  37.     char *fmt;
  38.     int line;
  39.     char *file;
  40.  
  41.     (void) fprintf(stderr, "%s: %s ", myname, s);
  42.     fmt = va_arg(*argp, char *);
  43.     vfprintf(stderr, fmt, *argp);
  44.     (void) fprintf(stderr, "\n");
  45.     line = (int) FNR_node->var_value->numbr;
  46.     if (line)
  47.         (void) fprintf(stderr, " input line number %d", line);
  48.     file = FILENAME_node->var_value->stptr;
  49.     if (file && strcmp(file, "-") != 0)
  50.         (void) fprintf(stderr, ", file `%s'", file);
  51.     (void) fprintf(stderr, "\n");
  52.     if (sourceline)
  53.         (void) fprintf(stderr, " source line number %d", sourceline);
  54.     if (source)
  55.         (void) fprintf(stderr, ", file `%s'", source);
  56.     (void) fprintf(stderr, "\n");
  57. }
  58.  
  59. /*VARARGS0*/
  60. void
  61. msg(va_alist)
  62. va_dcl
  63. {
  64.     va_list args;
  65.  
  66.     va_start(args);
  67.     err("", &args);
  68.     va_end(args);
  69. }
  70.  
  71. /*VARARGS0*/
  72. void
  73. warning(va_alist)
  74. va_dcl
  75. {
  76.     va_list args;
  77.  
  78.     va_start(args);
  79.     err("warning:", &args);
  80.     va_end(args);
  81. }
  82.  
  83. /*VARARGS0*/
  84. void
  85. fatal(va_alist)
  86. va_dcl
  87. {
  88.     va_list args;
  89.     extern char *sourcefile;
  90.  
  91.     va_start(args);
  92.     err("fatal error:", &args);
  93.     va_end(args);
  94. #ifdef DEBUG
  95.     abort();
  96. #endif
  97.     exit(1);
  98. }
  99.  
  100. char *
  101. safe_malloc(size)
  102. unsigned size;
  103. {
  104.     char *ret;
  105.  
  106.     ret = malloc(size);
  107.     if (ret == NULL)
  108.         fatal("safe_malloc: can't allocate memory (%s)",
  109.             sys_errlist[errno]);
  110.     return ret;
  111. }
  112.  
  113. #if defined(BSD) && !defined(VPRINTF)
  114. int
  115. vsprintf(str, fmt, ap)
  116.     char *str, *fmt;
  117.     va_list ap;
  118. {
  119.     FILE f;
  120.     int len;
  121.  
  122.     f._flag = _IOWRT+_IOSTRG;
  123.     f._ptr = str;
  124.     f._cnt = 32767;
  125.     len = _doprnt(fmt, ap, &f);
  126.     *f._ptr = 0;
  127.     return (len);
  128. }
  129.  
  130. int
  131. vfprintf(iop, fmt, ap)
  132.     FILE *iop;
  133.     char *fmt;
  134.     va_list ap;
  135. {
  136.     int len;
  137.  
  138.     len = _doprnt(fmt, ap, iop);
  139.     return (ferror(iop) ? EOF : len);
  140. }
  141.  
  142. int
  143. vprintf(fmt, ap)
  144.     char *fmt;
  145.     va_list ap;
  146. {
  147.     int len;
  148.  
  149.     len = _doprnt(fmt, ap, stdout);
  150.     return (ferror(stdout) ? EOF : len);
  151. }
  152. #endif
  153.