home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / IRITS.ZIP / IPRSRTST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  8.9 KB  |  294 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Test program of the InptPrsr.c module:                     *
  7. * Note you can set DEBUG for InptPrsr preprocessor for intermidiate results: *
  8. *****************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <setjmp.h>
  14. #include <alloc.h>
  15. #include "program.h"
  16. #include "inptprsg.h"
  17. #include "dosintrg.h"
  18. #include "matherr.h"
  19.  
  20. char CurrentWorkingDir[LINE_LEN];      /* Save start CWD to recover on exit. */
  21.  
  22. struct ObjectStruct *GlblObjList = NULL;   /* All objects defined on system. */
  23.  
  24. int  WasCtrlBrk = FALSE;          /* True if control break/C was pressed. */
  25. int  GlblFatalError = FALSE;      /* True if disaster in system - must quit! */
  26. int  LoadColor = 1, BoolColor = 2, ICrvColor = 14, PrimColor = 4;
  27.  
  28. char *HelpFileName = "irit.hlp";
  29.  
  30. jmp_buf LongJumpBuffer;                      /* Used in error recovery. */
  31.  
  32. extern unsigned int _stklen = 16384;         /* Increase default stack size. */
  33.  
  34. static void PrintInptPrsrError(void);
  35.  
  36. /*****************************************************************************
  37. * Simple main routine to emulate the needed parameters for InputParser:      *
  38. *****************************************************************************/
  39. void main(void)
  40. {
  41.     SetUpPredefObjects();          /* Prepare the predefined objects. */
  42.     fprintf(stderr, "Input Parser Test Program (type expression follows by ';'):\n");
  43.  
  44.     DosGetTime(1.0);                    /* Reset the time count. */
  45.     AliasReset();
  46.  
  47.     /* If one long jumped to here with value 2, we must quit the program!    */
  48.     if (setjmp(LongJumpBuffer) == 2)              /* Used in error recovery. */
  49.     exit(1);
  50.  
  51.     while (TRUE) {                          /* Do forever. */
  52.     if (!InputParser())             /* Error was found - handle it. */
  53.         PrintInptPrsrError();
  54.     fprintf(stderr, "\nCurrent defined objects (Core left = %lx) :\n",
  55.                                 coreleft());
  56.     PrintObjectList(GlblObjList);
  57.     }
  58. }
  59.  
  60. /*****************************************************************************
  61. * Routine to query (and print) the errors found in InputParser:             *
  62. *****************************************************************************/
  63. static void PrintInptPrsrError(void)
  64. {
  65.     int ErrorNum;
  66.     char *ErrorMsg;
  67.  
  68.     if ((ErrorNum = InptPrsrParseError(&ErrorMsg)) != 0) {/* Error in parse. */
  69.     fprintf(stderr, "Parsing Error: ");
  70.     switch(ErrorNum) {
  71.         case IP_ERR_WrongSyntax:
  72.         fprintf(stderr, "Wrong syntax\n");
  73.         break;
  74.         case IP_ERR_ParamExpect:
  75.         fprintf(stderr, "Parameter Expected - %s\n", ErrorMsg);
  76.         break;
  77.         case IP_ERR_OneOperand:
  78.         fprintf(stderr, "Wrong Number of operands (1) - %s\n", ErrorMsg);
  79.         break;
  80.         case IP_ERR_TwoOperand:
  81.         fprintf(stderr, "Wrong Number of operands (2) - %s\n", ErrorMsg);
  82.         break;
  83.         case IP_ERR_StackOV:
  84.         fprintf(stderr, "Internal Stack OverFlow at - %s\n", ErrorMsg);
  85.         break;
  86.         case IP_ERR_ParaMatch:
  87.         fprintf(stderr, "Parenthesis mismatch - %s\n", ErrorMsg);
  88.         break;
  89.         case IP_ERR_UndefToken:
  90.         fprintf(stderr, "Undefined token - %s\n", ErrorMsg);
  91.         break;
  92.         case IP_ERR_UndefFunc:
  93.         fprintf(stderr, "Undefined function - %s\n", ErrorMsg);
  94.         break;
  95.         case IP_ERR_NameTooLong:
  96.         fprintf(stderr, "Object name too long - %s\n", ErrorMsg);
  97.         break;
  98.         case IP_ERR_ParamFunc:
  99.         fprintf(stderr, "Parameters expected in func %s\n", ErrorMsg);
  100.         break;
  101.         case IP_ERR_NoParamFunc:
  102.         fprintf(stderr, "No Parameters expected in func %s\n", ErrorMsg);
  103.         break;
  104.     }
  105.     return;
  106.     }
  107.  
  108.     if ((ErrorNum = InptPrsrEvalError(&ErrorMsg)) != 0) {  /* Error in eval. */
  109.     fprintf(stderr, "Eval Error: ");
  110.     switch(ErrorNum) {
  111.         case IE_ERR_FatalError:
  112.         fprintf(stderr, "Fatal Error - %s\n", ErrorMsg);
  113.         break;
  114.         case IE_ERR_DivByZero:
  115.         fprintf(stderr, "Division by zero - %s\n", ErrorMsg);
  116.         break;
  117.         case IE_ERR_NoObjMethod:
  118.         fprintf(stderr, "No such method for object - %s\n", ErrorMsg);
  119.         break;
  120.         case IE_ERR_TypeMismatch:
  121.         fprintf(stderr, "Parameter type mismatch - %s\n", ErrorMsg);
  122.         break;
  123.         case IE_ERR_AssignLeftOp:
  124.         fprintf(stderr, "Lval is not a parameter - %s\n", ErrorMsg);
  125.         break;
  126.         case IE_ERR_MixedObj:
  127.         fprintf(stderr, "Mixed types in expression - %s\n", ErrorMsg);
  128.         break;
  129.         case IE_ERR_UndefObject:
  130.         fprintf(stderr, "No such object defined - %s\n", ErrorMsg);
  131.         break;
  132.         case IE_ERR_NoAssignment:
  133.         fprintf(stderr, "Assignment was expected\n");
  134.         break;
  135.         case IE_ERR_FPError:
  136.         fprintf(stderr, "Floating Point Error - %s\n", ErrorMsg);
  137.         break;
  138.         case IE_ERR_NumPrmMismatch:
  139.         fprintf(stderr, "Number of func. param. mismatch - %s\n", ErrorMsg);
  140.         break;
  141.         case IE_ERR_MatPower:
  142.         fprintf(stderr, "Wrong range or result exists, operator - %s\n", ErrorMsg);
  143.         break;
  144.         case IE_ERR_FreeSimple:
  145.         fprintf(stderr, "Free only Geometric Objects - %s\n", ErrorMsg);
  146.         break;
  147.         case IE_ERR_ModifIterVar:
  148.         fprintf(stderr,
  149.             "Iteration var. type modified or freed - %s\n", ErrorMsg);
  150.         break;
  151.         case IE_ERR_BooleanErr:
  152.         fprintf(stderr,
  153.             "Geometric Boolean operation error - %s\n", ErrorMsg);
  154.         break;
  155.         case IE_ERR_ListTooLong:
  156.         fprintf(stderr,
  157.             "List length too big - up to %d only.\n", MAX_OBJ_LIST);
  158.         break;
  159.         case IE_ERR_NonParamInList:
  160.         fprintf(stderr,
  161.             "List element not an object (expression!?)\n");
  162.         break;
  163.         case IE_ERR_FreeNoRefObj:
  164.         fprintf(stderr,
  165.             "Cannt free referenced (by others!) object %s\n", ErrorMsg);
  166.         break;
  167.         case IE_ERR_DataPrsrError:
  168.         fprintf(stderr, "%s", ErrorMsg);
  169.         break;
  170.     }
  171.     return;
  172.     }
  173. }
  174.  
  175. /*****************************************************************************
  176. * MyExit routine.                                  *
  177. *****************************************************************************/
  178. void MyExit(int ExitCode)
  179. {
  180.     exit(ExitCode);
  181. }
  182.  
  183. /*****************************************************************************
  184. * FatalEror routine. same as MyExit routine, but print error message         *
  185. * before it dies.                                 *
  186. *****************************************************************************/
  187. void FatalError(char *ErrorMsg)
  188. {
  189.     fprintf(stderr, "%s\n", ErrorMsg);
  190.  
  191.     exit(99);
  192. }
  193.  
  194. /*****************************************************************************
  195. *   Routine that is called from the floating point package in case of fatal  *
  196. * floating point error. Print error message, long jump to main loop. Default *
  197. * FPE handler - must be reset after redirected to other module.             *
  198. *****************************************************************************/
  199. void DefaultFPEHandler(int Sig, int Type, int *RegList)
  200. {
  201.     PrintFPError(Type);             /* Print the floating point error type. */
  202.  
  203.     longjmp(LongJumpBuffer, 1);
  204. }
  205.  
  206. /*****************************************************************************
  207. *  And other emulations to the routines:                     *
  208. *****************************************************************************/
  209. void WndwPause()
  210. {
  211.     fprintf(stderr, "Pause was called, press anything:");
  212.     getch();
  213. }
  214.  
  215. void WndwInputWindowGetStr(char *Str, int Length)
  216. {
  217.     gets(Str);
  218. }
  219.  
  220. void WndwLogPrint(RealType *R)
  221. {
  222.     fprintf(stderr, "Log file toggle - value = %lf\n", *R);
  223. }
  224.  
  225. void WndwInputWindowPutStr(char *Str, int Color)
  226. {
  227.     printf("%s\n", Str);
  228. }
  229.  
  230. void WndwInputWindowPutStrFS(char *Str, int Color, int Reset)
  231. {
  232.     printf("%s\n", Str);
  233. }
  234.  
  235. void WndwViewGeomObject(ObjectStruct *PObj, RealType *ClearScreen)
  236. {
  237.     fprintf(stderr,
  238.     "VIEW: object %s (Clear = %g)\n", PObj->Name, *ClearScreen);
  239. }
  240.  
  241. void WndwStatusWindowUpdate()
  242. {
  243.     fprintf(stderr, "Core left = %lx\n", coreleft());
  244. }
  245.  
  246. void DosChangeDir(char *s)
  247. {
  248.     fprintf(stderr, "CHDIR: to directory %s\n", s);
  249. }
  250.  
  251. double DosGetTime(double ResetTime)
  252. {
  253.     fprintf(stderr, "Time invoked with reset = %lf\n", ResetTime);
  254.     return 1234.5678;
  255. }
  256.  
  257. void DosEditFile(char *s)
  258. {
  259.     fprintf(stderr, "Edit invoked with file \"%s\"\n", s);
  260. }
  261.  
  262. void DosSystem()
  263. {
  264.     fprintf(stderr, "System invoked\n");
  265. }
  266.  
  267. void DosPrintDir(char *s)
  268. {
  269.     fprintf(stderr, "Print Dir entered (%s)\n", s);
  270. }
  271.  
  272. void InteractGeomObject(ObjectStruct *PObj, RealType *UpdateGlblMat)
  273. {
  274.     fprintf(stderr, "View Object entered, object %s, Update= %lf\n",
  275.                         PObj -> Name, *UpdateGlblMat);
  276. }
  277.  
  278. void ViewGeomObject(ObjectStruct *PObj)
  279. {
  280.     fprintf(stderr, "View Object entered, object %s\n", PObj -> Name);
  281. }
  282.  
  283. void ViewSetNormals(RealType *Active, RealType *Size, RealType *Color)
  284. {
  285.     fprintf(stderr,
  286.     "View set normals entered, Active = %g Size = %g Color = %g\n",
  287.         *Active, *Size, *Color);
  288. }
  289.  
  290. void GGTone(int Freq, int Time)
  291. {
  292.     fprintf(stderr, "Beep invoked, Freq = %d, Time = %d\n", Freq, Time);
  293. }
  294.