home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / helpsub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  2.2 KB  |  98 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * helpsubr.c --- subroutines for the FORTH online help utilities.
  31.  * (duz 13Sep94)
  32.  */
  33.  
  34. #include "config.h"
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <stdarg.h>
  39. #include <string.h>
  40. #include <errno.h>
  41.  
  42. #include "const.h"
  43. #include "options.h"
  44. #include "help.h"
  45.  
  46.  
  47. /*
  48.  * Simple error handling: Report and abort.
  49.  */
  50.  
  51. char *progname;            /* points in argv [0] */
  52.  
  53. void
  54. fatal (const char *msg, ...)
  55. /*
  56.  * quit with error message, formatting like printf()
  57.  */
  58. {
  59.   char buf [0x400];
  60.   va_list v;
  61.  
  62.   va_start (v, msg);
  63.   vsprintf (buf, msg, v);
  64.   va_end (v);
  65.   fprintf (stderr, "%s: %s.\n", progname, buf);
  66.   exit (1);
  67. }
  68.  
  69. void
  70. sys_error (void)
  71. /*
  72.  * quit with an error message from strerror ()
  73.  */
  74. {
  75.   fatal ("%s", strerror (errno));
  76. }
  77.  
  78. void
  79. file_errorz (const char *fn)
  80. /*
  81.  * like sys_error when a file name is at hand.
  82.  */
  83. {
  84.   fatal ("File %s: %s", strerror (errno));
  85. }
  86.  
  87. void *
  88. xalloc (size_t size)
  89. /*
  90.  * like calloc() but dies with erro message when failed.
  91.  */
  92. {
  93.   void *p = malloc (size);
  94.   if (p == NULL)
  95.     sys_error ();
  96.   return p;
  97. }
  98.