home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / X_PROLOG.LZH / X_PROLOG / SOURCES / ERROR.C < prev    next >
C/C++ Source or Header  |  1990-08-13  |  2KB  |  83 lines

  1. /*
  2.  *        X PROLOG  Vers. 2.0
  3.  *
  4.  *
  5.  *    Written by :     Andreas Toenne
  6.  *            CS Dept. , IRB
  7.  *            University of Dortmund, W-Germany
  8.  *            <at@unido.uucp>
  9.  *            <....!seismo!unido!at>
  10.  *            <at@unido.bitnet>
  11.  *
  12.  *    Copyright :    This software is copyrighted by Andreas Toenne.
  13.  *            Permission is granted hereby to copy the entire
  14.  *            package including this copyright notice without fee.
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>  
  19. #include <setjmp.h>
  20. #include "prolog.h"
  21. #include "error.h"
  22. #include "extern.h"
  23.  
  24. extern long ftell();
  25. extern term *term_proto();
  26. extern functor *get_functor();
  27. extern term *term_copy();
  28. extern term *int_proto();
  29. extern term *int_copy();
  30.  
  31. static char *e_list[] = {        /* List of all hard errors */
  32. "all is fine",
  33. "Cannot create such a big prolog system",
  34. "Prototype space is full",
  35. "Copystack is full",
  36. "There is no main goal for the machine!",
  37. "The main goal has come to an unexpected end!",
  38. "Trailstack is full",
  39. "Clause space is used up",
  40. "An recoverable error has occured. Unfortunatly i could not find an error\
  41. clause\nPlease contact your local prolog guru",
  42. "Functor space is full",
  43. "There has been an boot error. Please contact your local prolog guru",
  44. "This is no valid prolog image",
  45. "Stack is full"};
  46.  
  47. /*    Handle a system error    */
  48.  
  49. void panic(which)
  50. short which;
  51. {
  52.     if (!booting && (which == STACKFULL || which == TRAILFULL ||
  53.              which == COPYFULL))
  54.     {
  55.         fprintf(stderr, "\n%s\n", e_list[which]);
  56.         longjmp(&abortpoint, TRUE);
  57.     }
  58.     printf("Prolog died by a panic :\n%s\n", e_list[which]);
  59.     exit(1);
  60. }
  61.  
  62. /*    Return a error term */
  63.  
  64. term *error(what, where)
  65. short what;
  66. term *where;
  67. {
  68.     functor *g;
  69.     term *t,*p;
  70.     
  71.     g = get_functor("error", 2);
  72.     if (!g->cp)            /* no error clause given */
  73.         panic(NOERRORCLAUSE);
  74.     t = term_copy(g);        /* create copy for error(1,2) */
  75.     ARG(t,1) = int_copy((long)what); /* first is number */
  76.     ARG(t,2) = where;        /* second is faulty term */
  77.     c_errno = 0;
  78.     p = term_copy(COMMAFUNCTOR);
  79.     ARG(p,1) = t;
  80.     ARG(p,2) = NILATOM;
  81.     return(p);
  82. }
  83.