home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- CAL.C
- (C) ¬⌐┼v 1988-1992 Autodesk ñ╜Ñq
-
- Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
- ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
- ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
-
- ( i) │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
- (ii) ╕ⁿª│íu¬⌐┼v (C) 1988-1992 Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
-
-
-
- AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
- Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
- ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
- íuº╣Ñ■╡L╗~ív¬║½O├╥íC
-
-
- Description: The main file of the "Geometry Calculator" ADS application.
-
- Notes:
-
- The Geometry Calculator application consists of the following files:
-
- cal.c ... The main file establishing link with ADS
- callex.c ... Lexical analyser
- calexpr.c ... Syntax analyser
- calmngf.c ... Management of calculator functions
- calstdf.c ... Standard calculator functions
- calusrf.c ... User-defined calculator functions
- calerr.c ... Error handling
- util.c ... Some utility functions
-
- callex.h ... Hearer file for callex.c
- calexpr.h ... Header file for calexpr.c
- calmngf.h ... Header file for calmngf.c
- calerr.h ... Header file for calerr.c
- util.h ... Header file for util.c
- cal.h ... Includes all the above include files plus some basic
- C include files.
-
- *****************************************************************************/
-
-
- /****************************************************************************/
- /* INCLUDES */
- /****************************************************************************/
-
- #include "cal.h"
-
-
- /****************************************************************************/
- /* IMPORTED FUNCTIONS */
- /****************************************************************************/
-
- void cal_register_standard_functions();
- void cal_register_user_functions();
-
-
- /****************************************************************************/
- /* STATIC VARIABLES ANF FUNCTIONS */
- /****************************************************************************/
-
- static void calculator_function _((struct resbuf *buff));
-
- static struct {char *name; void (*func)();} ADS_funcs_table[] =
- {
- "CAL", calculator_function,
- "C:CAL", calculator_function,
- };
-
-
- /****************************************************************************/
- /*.doc load_ADS_functions(internal)*/
- /*+
- Standard code for loading the ADS functions from 'ADS_funcs_table[]'.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/load_ADS_functions()
- {
- int i;
-
- for (i = 0; i < ELEMENTS(ADS_funcs_table); i++)
- if (ads_defun(ADS_funcs_table[i].name, i) != RTNORM) {
- return(RSERR);
- }
- return(RSRSLT);
- } /*load_ADS_functions*/
-
-
- /****************************************************************************/
- /*.doc execute_ADS_function(internal)*/
- /*+
- Standard code for executing an ADS function from 'ADS_funcs_table[]'.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/execute_ADS_function()
- {
- struct resbuf *buff;
- int i;
-
- if (((i = ads_getfuncode()) < 0) ||
- (i >= ELEMENTS(ADS_funcs_table))) {
- return(RSERR);
- }
-
- ads_retnil();
-
- buff = ads_getargs();
- (*ADS_funcs_table[i].func)(buff);
-
- return(RSRSLT);
- } /*execute_ADS_function*/
-
-
- /****************************************************************************/
- /*.doc main(external)*/
- /*+
- The main function.
- -*/
- /****************************************************************************/
-
-
- void
- /*FCN*/main(argc, argv)
-
- int argc;
- char *argv[];
- {
- int request;
- short success = RSRSLT;
- int load_first_time = TRUE;
-
- ads_init(argc,argv);
- cal_err = FALSE;
-
- for (;;) {
-
- if ((request = ads_link(success)) < 0) {
- fflush(stdout);
- exit(1);
- }
- success = RSRSLT;
-
- switch (request) {
-
- case RQXLOAD:
- if (load_first_time) {
- cal_register_standard_functions();
- cal_register_user_functions();
- if (cal_err)
- exit(1);
- load_first_time = FALSE;
- }
- success = load_ADS_functions();
- break;
-
- case RQSUBR:
- success = execute_ADS_function();
- break;
-
- case RQXUNLD:
- case RQSAVE:
- case RQQUIT:
- case RQEND:
- break;
-
- default:
- break;
- } /*switch*/
- } /*forever*/
-
- } /*main*/
-
-
- /****************************************************************************/
- /*.doc calculator_function(internal)*/
- /*+
- Function evaluates arithmetic expression string which it receives
- in 'buff'. If no result buffer is provided, the function prompts
- for a string.
- -*/
- /****************************************************************************/
-
-
- static void
- /*FCN*/calculator_function(buff)
-
- struct resbuf *buff;
- {
- int success;
- vector_real_int value;
- char line[MAX_LINE_LENGTH+1];
-
- do {
- cal_err = 0; /* Reset the global error flag */
-
- /* Get the input entier from the string resbuf, or,
- if not present, prompt the user to enter a string */
-
- if (buff != NULL) {
- if ((buff->restype != RTSTR) || (buff->rbnext != NULL)) {
- error(27, NULL);
- return;
- } else {
- strcpy(line, buff->resval.rstring);
- }
- } else {
- do {
- ads_initget(1, NULL);
- success = ads_getstring(TRUE, ">> ¡zÑy: ", line);
-
- if (success == RTCAN) {
- return;
- } else if (success != RTNORM) {
- error(27, NULL);
- return;
- }
- } while (line[0] == EOS);
- }
-
- success = cal_evaluate_expression(line, &value);
-
- if (success) {
- switch (value.type) {
- case vector_type:
- ads_retpoint(value.v);
- break;
- case real_type:
- ads_retreal(value.r);
- break;
- case int_type:
- ads_retint((int)value.r);
- break;
- default:
- break;
- } /*switch*/
- }
- } while (!success && (buff == NULL));
-
- } /*calculator_function*/
-
-
-