home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
- #include <process.h>
- #include <graphics.h>
- #include <stdlib.h>
- #include <string.h>
- #include <alloc.h>
- #include <math.h>
- #include <time.h>
- #include <conio.h>
- #include <dos.h>
-
- #define TRUE 1
- #define FALSE 0
-
- typedef struct text
- {
- int length;
- unsigned char *value;
- } *text_ptr;
-
- typedef struct value_header
- {
- char type;
- union
- {
- int *boolean;
- FILE **dataset;
- long *integer;
- double *real;
- text_ptr string;
- } value_ptr;
- } *value_header_ptr;
-
- typedef struct queue_node
- {
- value_header_ptr argument_header_ptr;
- struct queue_node *next;
- } *queue_node_ptr;
-
- typedef struct variable
- {
- char *name;
- queue_node_ptr subscripts;
- value_header_ptr variable_value_header_ptr;
- struct variable *predecessor_ptr;
- struct variable *smaller_successor_ptr;
- struct variable *larger_successor_ptr;
- } *variable_ptr;
-
- typedef struct prime_rec
- {
- float x;
- float y;
- float z;
- struct prime_rec *right;
- struct prime_rec *down;
- struct prime_rec *lesser_x;
- struct prime_rec *greater_x;
- } *prime_rec_ptr;
-
- typedef struct up_rec
- {
- prime_rec_ptr up;
- struct up_rec *next;
- struct up_rec *previous;
- } *up_rec_ptr;
-
- static value_header_ptr abs_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr add_terms(value_header_ptr,value_header_ptr);
- static void adjust_perspective(prime_rec_ptr,prime_rec_ptr *,
- prime_rec_ptr *,double,double,double,double,double);
- static value_header_ptr and_factors(value_header_ptr,value_header_ptr);
- static value_header_ptr atan_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr boolean_comparison(value_header_ptr,char *,
- value_header_ptr);
- static value_header_ptr char_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr concatenate_terms(value_header_ptr,value_header_ptr);
- static value_header_ptr copy_of_arguments(value_header_ptr);
- static queue_node_ptr copy_of_queue(queue_node_ptr);
- static value_header_ptr copy_of_subscripts(value_header_ptr);
- static value_header_ptr cos_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr dataset_comparison(value_header_ptr,char *,
- value_header_ptr);
- static value_header_ptr date_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr divide_factors(value_header_ptr,value_header_ptr);
- static value_header_ptr endfile_header_ptr(queue_node_ptr,char *,int);
- static void evaluate_and_transform(double,double,double,double,int,
- int,double,double,prime_rec_ptr *,prime_rec_ptr *,
- prime_rec_ptr *,double *,double *,double *,double *,
- double *);
- static value_header_ptr exec_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr exp_header_ptr(queue_node_ptr,char *,int);
- static double f(double,double);
- static value_header_ptr factor_header_ptr(int);
- static value_header_ptr false_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr float_header_ptr(queue_node_ptr,char *,int);
- static void free_value(value_header_ptr);
- void free_variables(void);
- static value_header_ptr function_header_ptr(int);
- void get_boolean_variable(char *,int *,int *);
- void get_buffer(char *);
- static void get_comparison_operator(char *);
- static void get_factor_operator(char *);
- void get_integer_variable(char *,long *,int *);
- void get_real_variable(char *,double *,int *);
- static void get_source_char(void);
- void get_string_variable(char *,char *,int,int *);
- static void get_term_operator(char *);
- static void get_token(void);
- static value_header_ptr getchar_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr getint_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr getreal_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr getstring_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr index_header_ptr(queue_node_ptr,char *,int);
- static void input_domain(double *,double *,double *,double *);
- static void input_num_divisions(int *,int *);
- static void input_rotation(double *);
- static void input_tilt(double *);
- static value_header_ptr integer_comparison(value_header_ptr,char *,
- value_header_ptr);
- static void interpret_assignment(int,queue_node_ptr);
- void interpret_buffer(void);
- static void interpret_do(int);
- static value_header_ptr interpret_expression(int);
- static void interpret_if(int);
- static void interpret_procedure(int,queue_node_ptr);
- static void interpret_statement(int);
- static value_header_ptr length_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr lineno_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr log_header_ptr(queue_node_ptr,char *,int);
- void main(void);
- static value_header_ptr mod_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr multiply_factors(value_header_ptr,value_header_ptr);
- static value_header_ptr new_boolean_header_ptr(void);
- static value_header_ptr new_dataset_header_ptr(void);
- static value_header_ptr new_integer_header_ptr(void);
- static value_header_ptr new_real_header_ptr(void);
- static value_header_ptr new_string_header_ptr(unsigned);
- static value_header_ptr open_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr or_terms(value_header_ptr,value_header_ptr);
- static value_header_ptr ord_header_ptr(queue_node_ptr,char *,int);
- static void perform_close(int,queue_node_ptr);
- static void perform_clrscr(int,queue_node_ptr);
- static void perform_print(int,queue_node_ptr);
- static void perform_putcrlf(int,queue_node_ptr);
- static void perform_troff(int,queue_node_ptr);
- static void perform_tron(int,queue_node_ptr);
- static value_header_ptr pi_header_ptr(queue_node_ptr,char *,int);
- static int pli_strcmp(text_ptr,text_ptr);
- static void pli_strcpy(text_ptr,text_ptr);
- static void plot(prime_rec_ptr,double,double,double,double,
- int,int);
- static value_header_ptr real_comparison(value_header_ptr,char *,
- value_header_ptr);
- static value_header_ptr repeat_header_ptr(queue_node_ptr,char *,int);
- void set_boolean_variable(char *,int);
- void set_integer_variable(char *,long);
- void set_real_variable(char *,double);
- void set_string_variable(char *,char *);
- static value_header_ptr simple_expression_header_ptr(int);
- static value_header_ptr sin_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr sqr_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr sqrt_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr str_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr string_comparison(value_header_ptr,char *,
- value_header_ptr);
- static value_header_ptr string_header_ptr(int);
- static value_header_ptr substr_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr subtract_terms(value_header_ptr,value_header_ptr);
- static value_header_ptr sysin_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr sysprint_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr term_header_ptr(int);
- static value_header_ptr time_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr translate_header_ptr(queue_node_ptr,char *,int);
- static long tree_balancer(long);
- static value_header_ptr true_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr trunc_header_ptr(queue_node_ptr,char *,int);
- static value_header_ptr unsigned_integer_header_ptr(void);
- static value_header_ptr unsigned_number_header_ptr(int);
- static value_header_ptr upper_header_ptr(queue_node_ptr,char *,int);
- static int variable_comparison(char *,queue_node_ptr,char *,
- queue_node_ptr);
- static value_header_ptr variable_header_ptr(char *,int,queue_node_ptr);
- static value_header_ptr verify_header_ptr(queue_node_ptr,char *,int);
-
- static int fatal_error = 0;
- static char file_name [256];
- static char identifier [256];
- static char source_buffer [16384];
- static char source_char;
- static long source_column_num;
- static int source_eof;
- FILE *source_file;
- static int source_index;
- static long source_line_num;
- static char source_token [256];
- static unsigned char substitute [256] =
- {
- 0x8d,0x8f,0x47,0xba,0xcc,0x12,0x09,0x74,
- 0xcb,0xf3,0xb4,0x88,0xf8,0xd1,0x08,0x4c,
- 0xa1,0x32,0x48,0x98,0xbd,0xaa,0xea,0xa2,
- 0x28,0xbc,0x66,0xe8,0xf4,0x5a,0x83,0x46,
- 0xa4,0x0e,0x3b,0x3e,0x14,0x4d,0x1c,0x0a,
- 0x92,0xfd,0x79,0xa8,0x67,0x41,0xe3,0x70,
- 0xc2,0x56,0xdd,0x6c,0xbb,0x38,0x17,0xc1,
- 0xae,0xb7,0x60,0x43,0x9e,0x34,0x22,0x7b,
- 0xe6,0x61,0x54,0xa0,0x00,0xcf,0xd0,0x64,
- 0xab,0x93,0xb6,0x86,0xee,0xdb,0x8e,0xb8,
- 0x6f,0xb2,0x57,0xd5,0xe9,0x85,0x0d,0x5d,
- 0x18,0xd9,0x82,0x6e,0x94,0x2b,0xb1,0xda,
- 0x2d,0x0f,0x90,0xed,0xde,0x95,0x4b,0xf1,
- 0x3d,0x3c,0x6b,0x2a,0xc9,0x21,0xfc,0xdf,
- 0x16,0x3a,0x9d,0x7f,0x37,0xbf,0xc7,0x9a,
- 0x25,0x49,0x0c,0xb9,0x91,0x03,0x97,0x35,
- 0x39,0x2c,0x63,0x62,0x1e,0x73,0x7e,0xa3,
- 0x45,0x71,0x44,0x40,0x9f,0xe2,0x13,0x3f,
- 0x68,0xc6,0xc4,0xfa,0x4a,0x07,0x58,0x23,
- 0xa5,0x4e,0x27,0x10,0x7c,0xd2,0x84,0x26,
- 0x76,0xac,0x55,0xad,0x5e,0xe7,0x5b,0x04,
- 0xd4,0xd7,0x89,0x96,0x0b,0x72,0xff,0xca,
- 0xc0,0x6a,0x8a,0xfe,0x5c,0x99,0x01,0xd6,
- 0x1f,0xdc,0xa7,0x78,0xf6,0x50,0x1b,0xe5,
- 0xec,0x42,0x8b,0x36,0xcd,0x75,0x59,0x30,
- 0x1d,0xe1,0x2e,0xbe,0x77,0xc5,0xb3,0xf2,
- 0x11,0x52,0x53,0xe4,0x87,0x15,0x2f,0xf5,
- 0x1a,0xb0,0x5f,0x9c,0xa6,0x69,0x05,0x7a,
- 0xf7,0x6d,0xb5,0x24,0x81,0x80,0x9b,0xce,
- 0x33,0xf9,0x65,0x19,0xeb,0xd3,0x31,0xef,
- 0x20,0xf0,0x51,0x7d,0xa9,0x8c,0x02,0xaf,
- 0x29,0xc3,0xc8,0xe0,0xfb,0xd8,0x4f,0x06
- };
- static int trace;
- static variable_ptr variable_head = NULL;
-
- void main(void)
- {
- int error_code;
- int file_index;
- int finished;
- int graphics_driver;
- int graphics_mode;
- int max_y_out;
- int max_z_out;
- int num_x_divisions;
- int num_y_divisions;
- prime_rec_ptr prime_cornor;
- prime_rec_ptr prime_head;
- prime_rec_ptr prime_ptr;
- prime_rec_ptr prime_tail;
- char response;
- double rotation;
- double tilt;
- double x_max;
- double x_min;
- double x_prime_max;
- double y_max;
- double y_min;
- double y_prime_max;
- double y_prime_min;
- double z_prime_max;
- double z_prime_min;
-
- /* See BGIOBJ in the Turbo C 2.0 User Guide for instructions
- on modifying GRAPHICS.LIB to include Turbo BGI files */
- registerfarbgidriver(CGA_driver_far);
- registerfarbgidriver(EGAVGA_driver_far);
- registerfarbgidriver(Herc_driver_far);
- registerfarbgidriver(ATT_driver_far);
- registerfarbgidriver(PC3270_driver_far);
- registerfarbgidriver(IBM8514_driver_far);
- detectgraph(&graphics_driver,&graphics_mode);
- error_code=graphresult();
- if (error_code != 0)
- printf("Fatal error: %s\n",grapherrormsg(error_code));
- else
- {
- initgraph(&graphics_driver,&graphics_mode,"");
- max_y_out=getmaxx();
- max_z_out=getmaxy();
- closegraph();
- printf(" Three Dimensional Plot\n");
- printf("\n\n\n");
- printf("File name (without extension)? ");
- scanf("%s",&file_name[0]);
- file_index=strlen(&file_name[0]);
- strcat(&file_name[0],".INI");
- printf("Initializing function...\n");
- get_buffer(&file_name[0]);
- if (! fatal_error)
- interpret_buffer();
- if (! fatal_error)
- {
- file_name[++file_index]='X';
- file_name[++file_index]='Y';
- file_name[++file_index]='Z';
- get_buffer(&file_name[0]);
- }
- if (! fatal_error)
- {
- input_domain(&x_min,&x_max,&y_min,&y_max);
- input_num_divisions(&num_x_divisions,&num_y_divisions);
- finished=FALSE;
- prime_head=NULL;
- while ((! fatal_error) && (! finished))
- {
- input_rotation(&rotation);
- input_tilt(&tilt);
- printf(
- "After the plot is displayed, press some key to continue.\n");
- printf("Evaluating function...\n");
- evaluate_and_transform(x_min,x_max,y_min,y_max,num_x_divisions,
- num_y_divisions,rotation,tilt,&prime_cornor,&prime_head,
- &prime_tail,&x_prime_max,&y_prime_min,&y_prime_max,
- &z_prime_min,&z_prime_max);
- if (! fatal_error)
- {
- printf("Adjusting perspective...\n");
- adjust_perspective(prime_cornor,&prime_head,&prime_tail,
- x_prime_max,y_prime_min,y_prime_max,z_prime_min,
- z_prime_max);
- }
- if (! fatal_error)
- {
- initgraph(&graphics_driver,&graphics_mode,"");
- plot(prime_tail,y_prime_min,y_prime_max,z_prime_min,
- z_prime_max,max_y_out,max_z_out);
- response=getch();
- closegraph();
- printf(
- " Three Dimensional Plot\n");
- printf("\n\n\n");
- printf("Again (y or n)? ");
- response=getch();
- if ((response != 'Y') && (response != 'y'))
- finished=TRUE;
- else
- printf("\n");
- while (prime_head != NULL)
- {
- prime_ptr=prime_head->greater_x;
- free((char *) prime_head);
- prime_head=prime_ptr;
- }
- }
- }
- free_variables();
- }
- }
- return;
- }
-
- static double f(x,y)
- double x;
- double y;
- {
- double z;
-
- z=0.0;
- set_real_variable("x",x);
- set_real_variable("y",y);
- set_real_variable("z",z);
- interpret_buffer();
- if (! fatal_error)
- get_real_variable("z",&z,&fatal_error);
- return(z);
- }
-
- static void input_domain(x_min,x_max,y_min,y_max)
- double *x_min;
- double *x_max;
- double *y_min;
- double *y_max;
- {
- printf("Smallest value for x? ");
- scanf("%lf",x_min);
- printf("Largest value for x? ");
- scanf("%lf",x_max);
- printf("Smallest value for y? ");
- scanf("%lf",y_min);
- printf("Largest value for y? ");
- scanf("%lf",y_max);
- return;
- }
-
- static void input_num_divisions(num_x_divisions,num_y_divisions)
- int *num_x_divisions;
- int *num_y_divisions;
- {
- do
- {
- printf("Number of divisions for x? ");
- scanf("%d",num_x_divisions);
- if (*num_x_divisions < 1)
- printf("? there must be at least 1 division\n");
- }
- while (*num_x_divisions < 1);
- do
- {
- printf("Number of divisions for y? ");
- scanf("%d",num_y_divisions);
- if (*num_y_divisions < 1)
- printf("? there must be at least 1 division\n");
- }
- while (*num_y_divisions < 1);
- return;
- }
-
- static void input_rotation(rotation)
- double *rotation;
- {
- printf("Rotation about the z-axis (degrees)? ");
- scanf("%lf",rotation);
- return;
- }
-
- static void input_tilt(tilt)
- double *tilt;
- {
- printf("Tilt about the resulting y-axis (degrees)? ");
- scanf("%lf",tilt);
- return;
- }
-
- static void evaluate_and_transform(x_min,x_max,y_min,y_max,num_x_divisions,
- num_y_divisions,rotation,tilt,prime_cornor,prime_head,prime_tail,x_prime_max,
- y_prime_min,y_prime_max,z_prime_min,z_prime_max)
- double x_min;
- double x_max;
- double y_min;
- double y_max;
- int num_x_divisions;
- int num_y_divisions;
- double rotation;
- double tilt;
- prime_rec_ptr *prime_cornor;
- prime_rec_ptr *prime_head;
- prime_rec_ptr *prime_tail;
- double *x_prime_max;
- double *y_prime_min;
- double *y_prime_max;
- double *z_prime_min;
- double *z_prime_max;
- {
- double cos_rotation;
- double cos_tilt;
- double delta_x;
- double delta_y;
- prime_rec_ptr last_prime_ptr;
- prime_rec_ptr prime_ptr;
- double radians;
- double radians_per_degree;
- prime_rec_ptr left;
- double sin_rotation;
- double sin_tilt;
- up_rec_ptr up_head;
- up_rec_ptr up_ptr;
- up_rec_ptr up_tail;
- double x;
- int x_division_num;
- double y;
- int y_division_num;
- double x_rotated;
- double z;
-
- radians_per_degree=atan(1.0)/45.0;
- radians=tilt*radians_per_degree;
- cos_tilt=cos(radians);
- sin_tilt=sin(radians);
- radians=rotation*radians_per_degree;
- cos_rotation=cos(radians);
- sin_rotation=sin(radians);
- z=f(x_min,y_min);
- x_rotated=x_min*cos_rotation+y_min*sin_rotation;
- *y_prime_min=-x_min*sin_rotation+y_min*cos_rotation;
- *z_prime_min=-x_rotated*sin_tilt+z*cos_tilt;
- *x_prime_max=x_rotated*cos_tilt+z*sin_tilt;
- *y_prime_max=*y_prime_min;
- *z_prime_max=*z_prime_min;
- last_prime_ptr=NULL;
- delta_x=(double) num_x_divisions;
- delta_x=(x_max-x_min)/delta_x;
- delta_y=(double) num_y_divisions;
- delta_y=(y_max-y_min)/delta_y;
- up_head=NULL;
- up_tail=NULL;
- for (y_division_num=1;
- ((! fatal_error) && (y_division_num <= num_y_divisions));
- y_division_num++)
- {
- if ((up_ptr=(struct up_rec *) malloc(
- (unsigned) sizeof(struct up_rec))) == NULL)
- {
- fatal_error=TRUE;
- printf("? out of memory\n");
- }
- else
- {
- up_ptr->up=NULL;
- if (up_head == NULL)
- {
- up_head=up_ptr;
- up_ptr->previous=NULL;
- }
- else
- {
- up_tail->next=up_ptr;
- up_ptr->previous=up_tail;
- }
- up_ptr->next=NULL;
- up_tail=up_ptr;
- }
- }
- x=x_min;
- for (x_division_num=1;
- ((! fatal_error) && (x_division_num <= num_x_divisions));
- x_division_num++)
- {
- left=NULL;
- up_ptr=up_head;
- y=y_min;
- for (y_division_num=1;
- ((! fatal_error) && (y_division_num <= num_y_divisions));
- y_division_num++)
- {
- z=f(x,y);
- if ((prime_ptr=(struct prime_rec *) malloc(
- (unsigned) sizeof(struct prime_rec))) == NULL)
- {
- fatal_error=TRUE;
- printf("? out of memory\n");
- }
- else
- {
- if (left != NULL)
- left->right=prime_ptr;
- if (up_ptr->up != NULL)
- (up_ptr->up)->down=prime_ptr;
- x_rotated=x*cos_rotation+y*sin_rotation;
- prime_ptr->y=(float) (-x*sin_rotation+y*cos_rotation);
- prime_ptr->x=(float) (x_rotated*cos_tilt+z*sin_tilt);
- prime_ptr->z=(float) (-x_rotated*sin_tilt+z*cos_tilt);
- if ((double) (prime_ptr->x) > *x_prime_max)
- *x_prime_max=(double) (prime_ptr->x);
- if ((double) (prime_ptr->y) < *y_prime_min)
- *y_prime_min=(double) (prime_ptr->y);
- if ((double) (prime_ptr->y) > *y_prime_max)
- *y_prime_max=(double) (prime_ptr->y);
- if ((double) (prime_ptr->z) < *z_prime_min)
- *z_prime_min=(double) (prime_ptr->z);
- if ((double) (prime_ptr->z) > *z_prime_max)
- *z_prime_max=(double) (prime_ptr->z);
- prime_ptr->lesser_x=NULL;
- if (last_prime_ptr == NULL)
- {
- *prime_tail=prime_ptr;
- *prime_cornor=prime_ptr;
- prime_ptr->greater_x=NULL;
- }
- else
- {
- (*prime_head)->lesser_x=prime_ptr;
- prime_ptr->greater_x=*prime_head;
- }
- *prime_head=prime_ptr;
- left=prime_ptr;
- up_ptr->up=prime_ptr;
- up_ptr=up_ptr->next;
- last_prime_ptr=prime_ptr;
- y+=delta_y;
- }
- }
- left->right=NULL;
- x+=delta_x;
- }
- while ((! fatal_error) && (up_head != NULL))
- {
- (up_head->up)->down=NULL;
- up_ptr=up_head->next;
- free((char *) up_head);
- up_head=up_ptr;
- }
- }
-
- static void adjust_perspective(prime_cornor,prime_head,prime_tail,
- x_prime_max,y_prime_min,y_prime_max,z_prime_min,z_prime_max)
- prime_rec_ptr prime_cornor;
- prime_rec_ptr *prime_head;
- prime_rec_ptr *prime_tail;
- double x_prime_max;
- double y_prime_min;
- double y_prime_max;
- double z_prime_min;
- double z_prime_max;
- {
- double delta_x;
- double delta_y;
- double delta_z;
- int finished;
- prime_rec_ptr last_prime_ptr;
- prime_rec_ptr left;
- prime_rec_ptr new_prime_head;
- prime_rec_ptr new_prime_ptr;
- prime_rec_ptr new_prime_tail;
- prime_rec_ptr next_prime_row;
- prime_rec_ptr prime_column;
- prime_rec_ptr prime_ptr;
- prime_rec_ptr prime_row;
- up_rec_ptr up_head;
- up_rec_ptr up_ptr;
- up_rec_ptr up_tail;
- double x_eye;
- double y_center;
- double z_center;
-
- if ((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
- x_eye=2.0*(y_prime_max-y_prime_min)+x_prime_max;
- else
- x_eye=2.0*(z_prime_max-z_prime_min)+x_prime_max;
- if (x_eye != x_prime_max)
- {
- up_head=NULL;
- up_tail=NULL;
- prime_column=prime_cornor;
- while ((! fatal_error) && (prime_column != NULL))
- {
- if ((up_ptr=(struct up_rec *) malloc(
- (unsigned) sizeof(struct up_rec))) == NULL)
- {
- fatal_error=TRUE;
- printf("? out of memory\n");
- }
- else
- {
- up_ptr->up=NULL;
- if (up_head == NULL)
- {
- up_head=up_ptr;
- up_ptr->previous=NULL;
- }
- else
- {
- up_tail->next=up_ptr;
- up_ptr->previous=up_tail;
- }
- up_ptr->next=NULL;
- up_tail=up_ptr;
- prime_column=prime_column->right;
- }
- }
- y_center=(y_prime_max+y_prime_min)/2.0;
- z_center=(z_prime_max+z_prime_min)/2.0;
- last_prime_ptr=NULL;
- new_prime_head=NULL;
- new_prime_tail=NULL;
- prime_row=prime_cornor;
- while (prime_row != NULL)
- {
- left=NULL;
- up_ptr=up_head;
- next_prime_row=prime_row->down;
- prime_column=prime_row;
- while (prime_column != NULL)
- {
- if ((new_prime_ptr=(struct prime_rec *) malloc(
- (unsigned) sizeof(struct prime_rec))) == NULL)
- {
- fatal_error=TRUE;
- printf("? out of memory\n");
- }
- else
- {
- if (left != NULL)
- left->right=new_prime_ptr;
- if (up_ptr->up != NULL)
- (up_ptr->up)->down=new_prime_ptr;
- delta_x=(prime_column->x)-x_eye;
- delta_y=(prime_column->y)-y_center;
- delta_z=(prime_column->z)-z_center;
- new_prime_ptr->x
- =sqrt(delta_x*delta_x+delta_y*delta_y+delta_z*delta_z);
- new_prime_ptr->y=y_center
- +((prime_column->y)-y_center)*(x_eye-x_prime_max)
- /(x_eye-(prime_column->x));
- new_prime_ptr->z=z_center
- +((prime_column->z)-z_center)*(x_eye-x_prime_max)
- /(x_eye-(prime_column->x));
- if (last_prime_ptr == NULL)
- {
- new_prime_head=new_prime_ptr;
- new_prime_tail=new_prime_ptr;
- new_prime_ptr->lesser_x=NULL;
- new_prime_ptr->greater_x=NULL;
- }
- else
- if (new_prime_ptr->x < last_prime_ptr->x)
- {
- finished=FALSE;
- while (! finished)
- {
- last_prime_ptr=last_prime_ptr->lesser_x;
- if (last_prime_ptr == NULL)
- finished=TRUE;
- else
- {
- if (new_prime_ptr->x >= last_prime_ptr->x)
- finished=TRUE;
- }
- }
- new_prime_ptr->lesser_x=last_prime_ptr;
- if (last_prime_ptr == NULL)
- {
- new_prime_head->lesser_x=new_prime_ptr;
- new_prime_ptr->greater_x=new_prime_head;
- new_prime_head=new_prime_ptr;
- }
- else
- {
- new_prime_ptr->greater_x
- =last_prime_ptr->greater_x;
- (last_prime_ptr->greater_x)->lesser_x
- =new_prime_ptr;
- last_prime_ptr->greater_x=new_prime_ptr;
- }
- }
- else
- {
- finished=FALSE;
- while (! finished)
- {
- last_prime_ptr=last_prime_ptr->greater_x;
- if (last_prime_ptr == NULL)
- finished=TRUE;
- else
- {
- if (new_prime_ptr->x <= last_prime_ptr->x)
- finished=TRUE;
- }
- }
- new_prime_ptr->greater_x=last_prime_ptr;
- if (last_prime_ptr == NULL)
- {
- new_prime_tail->greater_x=new_prime_ptr;
- new_prime_ptr->lesser_x=new_prime_tail;
- new_prime_tail=new_prime_ptr;
- }
- else
- {
- new_prime_ptr->lesser_x
- =last_prime_ptr->lesser_x;
- (last_prime_ptr->lesser_x)->greater_x
- =new_prime_ptr;
- last_prime_ptr->lesser_x=new_prime_ptr;
- }
- }
- left=new_prime_ptr;
- up_ptr->up=new_prime_ptr;
- up_ptr=up_ptr->next;
- last_prime_ptr=new_prime_ptr;
- prime_ptr=prime_column->right;
- free((char *) prime_column);
- prime_column=prime_ptr;
- }
- }
- left->right=NULL;
- prime_row=next_prime_row;
- }
- *prime_head=new_prime_head;
- *prime_tail=new_prime_tail;
- while ((! fatal_error) && (up_head != NULL))
- {
- (up_head->up)->down=NULL;
- up_ptr=up_head->next;
- free((char *) up_head);
- up_head=up_ptr;
- }
- }
- }
-
- static void plot(prime_tail,y_prime_min,y_prime_max,z_prime_min,
- z_prime_max,max_y_out,max_z_out)
- prime_rec_ptr prime_tail;
- double y_prime_min;
- double y_prime_max;
- double z_prime_min;
- double z_prime_max;
- int max_y_out;
- int max_z_out;
- {
- double aspect_y;
- double aspect_z;
- double aspect_ratio;
- int box [8];
- double pixels_per_unit;
- prime_rec_ptr prime_ptr;
- int y_aspect;
- double y_offset;
- double y_out_max;
- int z_aspect;
- double z_offset;
- double z_out_max;
-
- getaspectratio(&y_aspect,&z_aspect);
- aspect_y=(double) y_aspect;
- aspect_z=(double) z_aspect;
- aspect_ratio=aspect_z/aspect_y;
- y_out_max=(double) max_y_out;
- z_out_max=(double) max_z_out;
- if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
- > y_out_max*(z_prime_max-z_prime_min))
- {
- pixels_per_unit
- =y_out_max/(aspect_ratio*(y_prime_max-y_prime_min));
- y_offset=0.0;
- z_offset
- =-(z_out_max-pixels_per_unit*(z_prime_max-z_prime_min))/2.0;
- }
- else
- if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
- < y_out_max*(z_prime_max-z_prime_min))
- {
- pixels_per_unit=z_out_max/(z_prime_max-z_prime_min);
- y_offset=(y_out_max
- -aspect_ratio*pixels_per_unit*(y_prime_max-y_prime_min))
- /2.0;
- z_offset=0.0;
- }
- else /* plot degenerates to a single point */
- {
- pixels_per_unit=1.0;
- y_offset=y_out_max/2.0;
- z_offset=-z_out_max/2.0;
- }
- setcolor(getmaxcolor());
- setfillstyle(SOLID_FILL,0);
- setlinestyle(SOLID_LINE,0,NORM_WIDTH);
- prime_ptr=prime_tail;
- while (prime_ptr != NULL)
- {
- if (prime_ptr->right != NULL)
- {
- if (prime_ptr->down != NULL)
- {
- box[0]=(int) (y_offset+pixels_per_unit
- *aspect_ratio*(((double) (prime_ptr->y))-y_prime_min));
- box[1]=(int) (z_offset+z_out_max
- -pixels_per_unit
- *(((double) (prime_ptr->z))-z_prime_min));
- box[2]=(int) (y_offset+pixels_per_unit
- *aspect_ratio*(((double) (prime_ptr->right)->y)-y_prime_min));
- box[3]=(int) (z_offset+z_out_max
- -pixels_per_unit
- *(((double) (prime_ptr->right)->z)-z_prime_min));
- box[6]=(int) (y_offset+pixels_per_unit
- *aspect_ratio*(((double) (prime_ptr->down)->y)-y_prime_min));
- box[7]=(int) (z_offset+z_out_max
- -pixels_per_unit
- *(((double) (prime_ptr->down)->z)-z_prime_min));
- box[4]=(int) (y_offset+pixels_per_unit
- *aspect_ratio
- *(((double) ((prime_ptr->down)->right)->y)-y_prime_min));
- box[5]=(int) (z_offset+z_out_max
- -pixels_per_unit
- *(((double) ((prime_ptr->down)->right)->z)-z_prime_min));
- fillpoly(4,&box[0]);
- }
- }
- prime_ptr=prime_ptr->lesser_x;
- }
- }
-
- void get_buffer(file_name)
- char *file_name;
- {
- int source_file_size;
-
- if ((source_file=fopen(file_name,"rb")) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: cannot open %s for input.\n",
- file_name);
- }
- else
- {
- source_file_size=fread(&source_buffer[0],1,16384,source_file);
- fclose(source_file);
- if (source_file_size == 16384)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: %s exceeds 16383 bytes in length.\n",
- file_name);
- }
- else
- source_buffer[source_file_size]=(char) 26;
- }
- return;
- }
-
- void interpret_buffer()
- {
- source_char=' ';
- source_eof=FALSE;
- source_line_num=(long) 1;
- source_column_num=(long) 0;
- source_index=-1;
- while ((! source_eof) && (! fatal_error))
- {
- get_token();
- if (source_token[0] != ' ')
- interpret_statement(TRUE);
- }
- return;
- }
-
- void free_variables()
- {
- int bypass_smaller_name;
- variable_ptr current_ptr;
- int finished;
- int larger_predecessor_found;
- queue_node_ptr new_queue_head;
- variable_ptr previous_ptr;
- queue_node_ptr queue_head;
-
- if (variable_head != NULL)
- {
- current_ptr=variable_head;
- finished=FALSE;
- bypass_smaller_name=FALSE;
- do
- {
- if (! bypass_smaller_name)
- while ((*current_ptr).smaller_successor_ptr != NULL)
- current_ptr=(*current_ptr).smaller_successor_ptr;
- free_value((*current_ptr).variable_value_header_ptr);
- if ((*current_ptr).larger_successor_ptr != NULL)
- {
- current_ptr=(*current_ptr).larger_successor_ptr;
- bypass_smaller_name=FALSE;
- }
- else
- {
- larger_predecessor_found=FALSE;
- do
- {
- if ((*current_ptr).predecessor_ptr == NULL)
- finished=TRUE;
- else
- {
- previous_ptr=current_ptr;
- current_ptr=(*previous_ptr).predecessor_ptr;
- if (variable_comparison((*current_ptr).name,
- (*current_ptr).subscripts,(*previous_ptr).name,
- (*previous_ptr).subscripts) > 0)
- larger_predecessor_found=TRUE;
- free((*previous_ptr).name);
- queue_head=(*previous_ptr).subscripts;
- while (queue_head != NULL)
- {
- new_queue_head=(*queue_head).next;
- free_value((*queue_head).argument_header_ptr);
- free((char *) queue_head);
- queue_head=new_queue_head;
- }
- free((char *) previous_ptr);
- }
- }
- while ((! finished) && (! larger_predecessor_found));
- bypass_smaller_name=TRUE;
- }
- }
- while (! finished);
- free((*variable_head).name);
- queue_head=(*variable_head).subscripts;
- while (queue_head != NULL)
- {
- new_queue_head=(*queue_head).next;
- free_value((*queue_head).argument_header_ptr);
- free((char *) queue_head);
- queue_head=new_queue_head;
- }
- free((char *) variable_head);
- }
- return;
- }
-
- static void get_source_char()
- {
- if (source_eof)
- source_char=' ';
- else
- {
- do
- {
- source_char=source_buffer[++source_index];
- if (source_char != (char) 26)
- {
- if (source_char == (char) 13)
- {
- source_line_num++;
- source_column_num=(long) 0;
- }
- else
- {
- if (source_char != (char) 10)
- {
- if (source_char == '\t')
- source_char=' ';
- source_column_num++;
- }
- }
- }
- }
- while ((source_char != (char) 26)
- && ((source_char == (char) 13) || (source_char == (char) 10)));
- source_eof=(source_char == (char) 26);
- if (source_eof) source_char=' ';
- }
- return;
- }
-
- static void get_token()
- {
- static int asterisk_found;
- static int eating_spaces;
- static int slash_found;
- static int slash_index;
- register int token_index;
-
- eating_spaces=TRUE;
- while (eating_spaces)
- {
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- if (source_char == '/')
- {
- slash_index=source_index;
- get_source_char();
- if (source_char == '*')
- {
- asterisk_found=FALSE;
- slash_found=FALSE;
- while ((! source_eof)
- && ((! asterisk_found) || (! slash_found)))
- {
- get_source_char();
- if (asterisk_found)
- if (source_char == '/')
- slash_found=TRUE;
- else
- asterisk_found=FALSE;
- else
- {
- if (source_char == '*')
- asterisk_found=TRUE;
- }
- }
- if (source_eof)
- eating_spaces=FALSE;
- else
- get_source_char();
- }
- else
- {
- source_index=slash_index;
- source_char=source_buffer[source_index];
- eating_spaces=FALSE;
- }
- }
- else
- eating_spaces=FALSE;
- }
- if (isalpha((int) source_char))
- {
- token_index=0;
- while ((isalnum((int) source_char) || (source_char == '_'))
- && (! source_eof))
- {
- if (token_index < 255)
- source_token[token_index++]=(char) toupper((int) source_char);
- get_source_char();
- }
- source_token[token_index]='\0';
- }
- else
- {
- source_token[0]=source_char;
- source_token[1]='\0';
- get_source_char();
- }
- return;
- }
-
- static void free_value(header_ptr)
- value_header_ptr header_ptr;
- {
- if (header_ptr != NULL)
- {
- switch ((*header_ptr).type)
- {
- case 'B':
- free((char *) (*header_ptr).value_ptr.boolean);
- break;
- case 'D':
- free((char *) (*header_ptr).value_ptr.dataset);
- break;
- case 'I':
- free((char *) (*header_ptr).value_ptr.integer);
- break;
- case 'R':
- free((char *) (*header_ptr).value_ptr.real);
- break;
- default:
- free((*((*header_ptr).value_ptr.string)).value);
- free((char *) (*header_ptr).value_ptr.string);
- break;
- }
- free((char *) header_ptr);
- }
- return;
- }
-
- static value_header_ptr new_boolean_header_ptr()
- {
- value_header_ptr result_header_ptr;
-
- if ((result_header_ptr=(struct value_header *)
- malloc((unsigned) sizeof(struct value_header))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*result_header_ptr).type='B';
- if (((*result_header_ptr).value_ptr.boolean=(int *)
- malloc((unsigned) sizeof(int))) == NULL)
- {
- fatal_error=TRUE;
- free((char *) result_header_ptr);
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr new_dataset_header_ptr()
- {
- value_header_ptr result_header_ptr;
-
- if ((result_header_ptr=(struct value_header *)
- malloc((unsigned) sizeof(struct value_header))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*result_header_ptr).type='D';
- if (((*result_header_ptr).value_ptr.dataset=(FILE **)
- malloc((unsigned) sizeof(FILE *))) == NULL)
- {
- fatal_error=TRUE;
- free((char *) result_header_ptr);
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.dataset)=NULL;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr new_integer_header_ptr()
- {
- value_header_ptr result_header_ptr;
-
- if ((result_header_ptr=(struct value_header *)
- malloc((unsigned) sizeof(struct value_header))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*result_header_ptr).type='I';
- if (((*result_header_ptr).value_ptr.integer=(long *)
- malloc((unsigned) sizeof(long))) == NULL)
- {
- fatal_error=TRUE;
- free((char *) result_header_ptr);
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)=0;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr new_real_header_ptr()
- {
- value_header_ptr result_header_ptr;
-
- if ((result_header_ptr=(struct value_header *)
- malloc((unsigned) sizeof(struct value_header))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*result_header_ptr).type='R';
- if (((*result_header_ptr).value_ptr.real=(double *)
- malloc((unsigned) sizeof(double))) == NULL)
- {
- fatal_error=TRUE;
- free((char *) result_header_ptr);
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)=0.0;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr new_string_header_ptr(string_length)
- unsigned string_length;
- {
- value_header_ptr result_header_ptr;
-
- if (string_length > (unsigned) 32767)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: string length exceeds 32767 at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if ((result_header_ptr=(struct value_header *)
- malloc((unsigned) sizeof(struct value_header))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*result_header_ptr).type='S';
- if (((*result_header_ptr).value_ptr.string=(struct text *)
- malloc((unsigned) sizeof(struct text))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*((*result_header_ptr).value_ptr.string)).length
- =string_length;
- if (((*((*result_header_ptr).value_ptr.string)).value=
- (unsigned char *) malloc((unsigned) (1+string_length)))
- == NULL)
- {
- fatal_error=TRUE;
- free((char *) result_header_ptr);
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- }
- }
- return(result_header_ptr);
- }
-
- static int pli_strcmp(string_1,string_2)
- text_ptr string_1;
- text_ptr string_2;
- {
- unsigned char char_1;
- unsigned char char_2;
- register int char_index;
- unsigned char *char_ptr_1;
- unsigned char *char_ptr_2;
- int length_1;
- int length_2;
- int result;
-
- result=0;
- char_index=0;
- char_ptr_1=(*string_1).value;
- char_ptr_2=(*string_2).value;
- length_1=(*string_1).length;
- length_2=(*string_2).length;
- while ((result == 0)
- && (char_index < length_1)
- && (char_index < length_2))
- {
- char_1=*char_ptr_1;
- char_2=*char_ptr_2;
- if (char_1 < char_2)
- result=-1;
- else
- if (char_1 > char_2)
- result=1;
- else
- {
- char_index++;
- char_ptr_1++;
- char_ptr_2++;
- }
- }
- char_2=(unsigned char) ' ';
- while ((result == 0)
- && (char_index < length_1))
- {
- char_1=*char_ptr_1;
- if (char_1 < char_2)
- result=-1;
- else
- if (char_1 > char_2)
- result=1;
- else
- {
- char_index++;
- char_ptr_1++;
- }
- }
- char_1=(unsigned char) ' ';
- while ((result == 0)
- && (char_index < length_2))
- {
- char_2=*char_ptr_2;
- if (char_1 < char_2)
- result=-1;
- else
- if (char_1 > char_2)
- result=1;
- else
- {
- char_index++;
- char_ptr_2++;
- }
- }
- return(result);
- }
-
- static void pli_strcpy(string_1,string_2)
- text_ptr string_1;
- text_ptr string_2;
- {
- register int char_index;
- unsigned char *char_ptr_1;
- unsigned char *char_ptr_2;
- int string_length;
-
- char_ptr_1=(*string_1).value;
- char_ptr_2=(*string_2).value;
- string_length=(*string_2).length;
- for (char_index=0; char_index < string_length; char_index++)
- {
- *char_ptr_1=*char_ptr_2;
- char_ptr_1++;
- char_ptr_2++;
- }
- *char_ptr_1=(unsigned char) '\0';
- return;
- }
-
- static value_header_ptr string_header_ptr(evaluate)
- int evaluate;
- {
- value_header_ptr new_result_header_ptr;
- value_header_ptr result_header_ptr;
- int string_index;
- unsigned string_length;
- int string_terminated;
-
- string_index=-1;
- string_length=(unsigned) 0;
- result_header_ptr=new_string_header_ptr((unsigned) 0);
- string_terminated=FALSE;
- while ((! fatal_error) && (! string_terminated) && (! source_eof))
- {
- get_source_char();
- if (source_char == '\'')
- {
- get_source_char();
- if (source_char == '\'')
- {
- string_length++;
- new_result_header_ptr=new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- pli_strcpy((*new_result_header_ptr).value_ptr.string,
- (*result_header_ptr).value_ptr.string);
- string_index++;
- (*((*new_result_header_ptr).value_ptr.string)).value[
- string_index]=(unsigned char) source_char;
- (*((*new_result_header_ptr).value_ptr.string)).value[
- string_length]=(unsigned char) '\0';
- free_value(result_header_ptr);
- result_header_ptr=new_result_header_ptr;
- }
- }
- else
- string_terminated=TRUE;
- }
- else
- {
- string_length++;
- new_result_header_ptr=new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- pli_strcpy((*new_result_header_ptr).value_ptr.string,
- (*result_header_ptr).value_ptr.string);
- string_index++;
- (*((*new_result_header_ptr).value_ptr.string)).value[
- string_index]=(unsigned char) source_char;
- (*((*new_result_header_ptr).value_ptr.string)).value[
- string_length]=(unsigned char) '\0';
- free_value(result_header_ptr);
- result_header_ptr=new_result_header_ptr;
- }
- }
- }
- if (! evaluate)
- {
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- }
- return(result_header_ptr);
- }
-
- static long tree_balancer(argument)
- long argument;
- {
- union
- {
- struct
- {
- unsigned char number_1;
- unsigned char number_2;
- unsigned char number_3;
- unsigned char number_4;
- } byte;
- struct
- {
- unsigned int number_01 : 1;
- unsigned int number_02 : 1;
- unsigned int number_03 : 1;
- unsigned int number_04 : 1;
- unsigned int number_05 : 1;
- unsigned int number_06 : 1;
- unsigned int number_07 : 1;
- unsigned int number_08 : 1;
- unsigned int number_09 : 1;
- unsigned int number_10 : 1;
- unsigned int number_11 : 1;
- unsigned int number_12 : 1;
- unsigned int number_13 : 1;
- unsigned int number_14 : 1;
- unsigned int number_15 : 1;
- unsigned int number_16 : 1;
- unsigned int number_17 : 1;
- unsigned int number_18 : 1;
- unsigned int number_19 : 1;
- unsigned int number_20 : 1;
- unsigned int number_21 : 1;
- unsigned int number_22 : 1;
- unsigned int number_23 : 1;
- unsigned int number_24 : 1;
- unsigned int number_25 : 1;
- unsigned int number_26 : 1;
- unsigned int number_27 : 1;
- unsigned int number_28 : 1;
- unsigned int number_29 : 1;
- unsigned int number_30 : 1;
- unsigned int number_31 : 1;
- unsigned int number_32 : 1;
- } bit;
- } intermediate;
- union
- {
- long signed_long;
- struct
- {
- unsigned char number_1;
- unsigned char number_2;
- unsigned char number_3;
- unsigned char number_4;
- } byte;
- struct
- {
- unsigned int number_01 : 1;
- unsigned int number_02 : 1;
- unsigned int number_03 : 1;
- unsigned int number_04 : 1;
- unsigned int number_05 : 1;
- unsigned int number_06 : 1;
- unsigned int number_07 : 1;
- unsigned int number_08 : 1;
- unsigned int number_09 : 1;
- unsigned int number_10 : 1;
- unsigned int number_11 : 1;
- unsigned int number_12 : 1;
- unsigned int number_13 : 1;
- unsigned int number_14 : 1;
- unsigned int number_15 : 1;
- unsigned int number_16 : 1;
- unsigned int number_17 : 1;
- unsigned int number_18 : 1;
- unsigned int number_19 : 1;
- unsigned int number_20 : 1;
- unsigned int number_21 : 1;
- unsigned int number_22 : 1;
- unsigned int number_23 : 1;
- unsigned int number_24 : 1;
- unsigned int number_25 : 1;
- unsigned int number_26 : 1;
- unsigned int number_27 : 1;
- unsigned int number_28 : 1;
- unsigned int number_29 : 1;
- unsigned int number_30 : 1;
- unsigned int number_31 : 1;
- unsigned int number_32 : 1;
- } bit;
- } result;
- register int round;
-
- result.signed_long=argument;
- for (round=1; round <= 8; round++)
- {
- intermediate.bit.number_01=result.bit.number_04;
- intermediate.bit.number_02=result.bit.number_29;
- intermediate.bit.number_03=result.bit.number_06;
- intermediate.bit.number_04=result.bit.number_09;
- intermediate.bit.number_05=result.bit.number_26;
- intermediate.bit.number_06=result.bit.number_25;
- intermediate.bit.number_07=result.bit.number_16;
- intermediate.bit.number_08=result.bit.number_15;
- intermediate.bit.number_09=result.bit.number_24;
- intermediate.bit.number_10=result.bit.number_31;
- intermediate.bit.number_11=result.bit.number_02;
- intermediate.bit.number_12=result.bit.number_18;
- intermediate.bit.number_13=result.bit.number_32;
- intermediate.bit.number_14=result.bit.number_03;
- intermediate.bit.number_15=result.bit.number_20;
- intermediate.bit.number_16=result.bit.number_30;
- intermediate.bit.number_17=result.bit.number_08;
- intermediate.bit.number_18=result.bit.number_27;
- intermediate.bit.number_19=result.bit.number_13;
- intermediate.bit.number_20=result.bit.number_11;
- intermediate.bit.number_21=result.bit.number_01;
- intermediate.bit.number_22=result.bit.number_17;
- intermediate.bit.number_23=result.bit.number_10;
- intermediate.bit.number_24=result.bit.number_05;
- intermediate.bit.number_25=result.bit.number_07;
- intermediate.bit.number_26=result.bit.number_14;
- intermediate.bit.number_27=result.bit.number_19;
- intermediate.bit.number_28=result.bit.number_23;
- intermediate.bit.number_29=result.bit.number_21;
- intermediate.bit.number_30=result.bit.number_28;
- intermediate.bit.number_31=result.bit.number_12;
- intermediate.bit.number_32=result.bit.number_22;
- result.byte.number_1=substitute[intermediate.byte.number_1];
- result.byte.number_2=substitute[intermediate.byte.number_2];
- result.byte.number_3=substitute[intermediate.byte.number_3];
- result.byte.number_4=substitute[intermediate.byte.number_4];
- }
- return(result.signed_long);
- }
-
- static int variable_comparison(name_1,queue_head_1,name_2,queue_head_2)
- char *name_1;
- queue_node_ptr queue_head_1;
- char *name_2;
- queue_node_ptr queue_head_2;
- {
- int boolean_1;
- int boolean_2;
- union {
- FILE *file_ptr;
- long address;
- } dataset_1;
- union {
- FILE *file_ptr;
- long address;
- } dataset_2;
- long integer_1;
- long integer_2;
- double real_1;
- double real_2;
- int result;
- char type_1;
- char type_2;
-
- result=strcmp(name_1,name_2);
- if (result == 0)
- {
- while ((result == 0)
- && (queue_head_1 != NULL)
- && (queue_head_2 != NULL))
- {
- type_1=(*((*queue_head_1).argument_header_ptr)).type;
- type_2=(*((*queue_head_2).argument_header_ptr)).type;
- if (type_1 < type_2)
- result=-1;
- else
- if (type_1 > type_2)
- result=1;
- else
- switch (type_1)
- {
- case 'B':
- boolean_1=*((*((*queue_head_1).argument_header_ptr)).
- value_ptr.boolean);
- boolean_2=*((*((*queue_head_2).argument_header_ptr)).
- value_ptr.boolean);
- if (boolean_1)
- {
- if (! boolean_2)
- result=1;
- }
- else
- {
- if (boolean_2)
- result=-1;
- }
- break;
- case 'D':
- dataset_1.file_ptr
- =*((*((*queue_head_1).argument_header_ptr)).
- value_ptr.dataset);
- dataset_2.file_ptr
- =*((*((*queue_head_2).argument_header_ptr)).
- value_ptr.dataset);
- if (dataset_1.address < dataset_2.address)
- result=-1;
- else
- {
- if (dataset_1.address > dataset_2.address)
- result=1;
- }
- break;
- case 'I':
- integer_1=*((*((*queue_head_1).argument_header_ptr)).
- value_ptr.integer);
- integer_2=*((*((*queue_head_2).argument_header_ptr)).
- value_ptr.integer);
- if (integer_1 < integer_2)
- result=-1;
- else
- {
- if (integer_1 > integer_2)
- result=1;
- }
- break;
- case 'R':
- real_1=*((*((*queue_head_1).argument_header_ptr)).
- value_ptr.real);
- real_2=*((*((*queue_head_2).argument_header_ptr)).
- value_ptr.real);
- if (real_1 < real_2)
- result=-1;
- else
- {
- if (real_1 > real_2)
- result=1;
- }
- break;
- default:
- result=pli_strcmp(
- (*((*queue_head_1).argument_header_ptr)).
- value_ptr.string,
- (*((*queue_head_2).argument_header_ptr)).
- value_ptr.string);
- break;
- }
- queue_head_1=(*queue_head_1).next;
- queue_head_2=(*queue_head_2).next;
- }
- if (result == 0)
- {
- if (queue_head_1 == NULL)
- {
- if (queue_head_2 != NULL)
- result=-1;
- }
- else
- {
- if (queue_head_2 == NULL)
- result=1;
- }
- }
- }
- return(result);
- }
-
- static value_header_ptr copy_of_arguments(argument_header_ptr)
- value_header_ptr argument_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (argument_header_ptr == NULL)
- result_header_ptr=NULL;
- else
- switch ((*argument_header_ptr).type)
- {
- case 'B':
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.boolean)
- =*((*argument_header_ptr).value_ptr.boolean);
- break;
- case 'D':
- result_header_ptr=new_dataset_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.dataset)
- =*((*argument_header_ptr).value_ptr.dataset);
- break;
- case 'I':
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.integer)
- =*((*argument_header_ptr).value_ptr.integer);
- break;
- case 'R':
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.real)
- =*((*argument_header_ptr).value_ptr.real);
- break;
- default:
- result_header_ptr
- =new_string_header_ptr((unsigned)
- (*((*argument_header_ptr).value_ptr.string)).length);
- if (! fatal_error)
- pli_strcpy((*(result_header_ptr)).value_ptr.string,
- (*argument_header_ptr).value_ptr.string);
- break;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr copy_of_subscripts(argument_header_ptr)
- value_header_ptr argument_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (argument_header_ptr == NULL)
- result_header_ptr=NULL;
- else
- switch ((*argument_header_ptr).type)
- {
- case 'B':
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.boolean)
- =*((*argument_header_ptr).value_ptr.boolean);
- break;
- case 'D':
- result_header_ptr=new_dataset_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.dataset)
- =*((*argument_header_ptr).value_ptr.dataset);
- break;
- case 'I':
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.integer)
- =tree_balancer(*((*argument_header_ptr).value_ptr.integer));
- break;
- case 'R':
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*(result_header_ptr)).value_ptr.real)
- =*((*argument_header_ptr).value_ptr.real);
- break;
- default:
- result_header_ptr
- =new_string_header_ptr((unsigned)
- (*((*argument_header_ptr).value_ptr.string)).length);
- if (! fatal_error)
- pli_strcpy((*(result_header_ptr)).value_ptr.string,
- (*argument_header_ptr).value_ptr.string);
- break;
- }
- return(result_header_ptr);
- }
-
- static queue_node_ptr copy_of_queue(queue_head)
- queue_node_ptr queue_head;
- {
- queue_node_ptr copy_queue_head;
- queue_node_ptr copy_queue_tail;
- queue_node_ptr new_copy_queue_tail;
- queue_node_ptr new_queue_head;
-
- copy_queue_head=NULL;
- copy_queue_tail=NULL;
- while ((queue_head != NULL) && (! fatal_error))
- {
- new_queue_head=(*queue_head).next;
- if (copy_queue_head == NULL)
- if ((copy_queue_head=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node))) == NULL)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- copy_queue_tail=copy_queue_head;
- (*copy_queue_head).next=NULL;
- (*copy_queue_head).argument_header_ptr
- =copy_of_subscripts((*queue_head).argument_header_ptr);
- }
- else
- if ((new_copy_queue_tail=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node))) == NULL)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*new_copy_queue_tail).next=NULL;
- (*copy_queue_tail).next=new_copy_queue_tail;
- copy_queue_tail=new_copy_queue_tail;
- (*new_copy_queue_tail).argument_header_ptr
- =copy_of_subscripts((*queue_head).argument_header_ptr);
- }
- queue_head=new_queue_head;
- }
- return(copy_queue_head);
- }
-
- static value_header_ptr variable_header_ptr(variable_name,evaluate,queue_head)
- char *variable_name;
- int evaluate;
- queue_node_ptr queue_head;
- {
- int comparison;
- int finished;
- queue_node_ptr new_queue_copy;
- variable_ptr parameter_ptr;
- queue_node_ptr queue_copy;
- value_header_ptr result_header_ptr;
- int variable_found;
-
- if (evaluate)
- {
- variable_found=FALSE;
- if (variable_head != NULL)
- {
- parameter_ptr=variable_head;
- queue_copy=copy_of_queue(queue_head);
- finished=FALSE;
- do
- {
- comparison=variable_comparison(variable_name,queue_copy,
- (*parameter_ptr).name,(*parameter_ptr).subscripts);
- if (comparison < 0)
- if ((*parameter_ptr).smaller_successor_ptr == NULL)
- finished=TRUE;
- else
- parameter_ptr=(*parameter_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*parameter_ptr).larger_successor_ptr == NULL)
- finished=TRUE;
- else
- parameter_ptr=(*parameter_ptr).larger_successor_ptr;
- else
- {
- variable_found=TRUE;
- result_header_ptr
- =copy_of_arguments(
- (*parameter_ptr).variable_value_header_ptr);
- finished=TRUE;
- }
- }
- while (! finished);
- while (queue_copy != NULL)
- {
- new_queue_copy=(*queue_copy).next;
- free_value((*queue_copy).argument_header_ptr);
- free((char *) queue_copy);
- queue_copy=new_queue_copy;
- }
- }
- if (! variable_found)
- result_header_ptr=NULL;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr unsigned_integer_header_ptr()
- {
- unsigned long result;
- value_header_ptr result_header_ptr;
- unsigned long tem_unsigned_long;
-
- result=(unsigned long) 0;
- do
- {
- if ((source_char >= '0') && (source_char <= '9'))
- {
- tem_unsigned_long=(unsigned long) source_char;
- tem_unsigned_long-=(unsigned long) '0';
- result*=(unsigned long) 10;
- result+=tem_unsigned_long;
- if (result <= (unsigned long) 0x7fffffff)
- get_source_char();
- }
- }
- while ((source_char >= '0') && (source_char <= '9')
- && (result <= (unsigned long) 0x7fffffff));
- if (result <= (unsigned long) 0x7fffffff)
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=(long) result;
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: integer constant too big at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr unsigned_number_header_ptr(evaluate)
- int evaluate;
- {
- value_header_ptr exponent_header_ptr;
- char exponent_sign;
- long exponent_value;
- double factor;
- value_header_ptr result_header_ptr;
- double tem_real_1;
- double tem_real_2;
-
- result_header_ptr=unsigned_integer_header_ptr();
- if (! fatal_error)
- {
- if (source_char == '.')
- {
- tem_real_1=(double) *((*result_header_ptr).value_ptr.integer);
- free_value(result_header_ptr);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- *((*result_header_ptr).value_ptr.real)=tem_real_1;
- get_source_char();
- if (isdigit((int) source_char))
- {
- factor=1.0;
- while (isdigit((int) source_char))
- {
- factor=factor/10.0;
- tem_real_2=(float) source_char;
- tem_real_2-=(float) '0';
- tem_real_1+=factor*tem_real_2;
- get_source_char();
- }
- *((*result_header_ptr).value_ptr.real)=tem_real_1;
- }
- else
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: decimal part of real number is missing at\n");
- printf(
- "line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- }
- }
- if (! fatal_error)
- {
- if ((source_char == 'e') || (source_char == 'E'))
- {
- if ((*result_header_ptr).type == 'I')
- {
- tem_real_1
- =(double) *((*result_header_ptr).value_ptr.integer);
- free_value(result_header_ptr);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=tem_real_1;
- }
- if (! fatal_error)
- {
- get_source_char();
- if (source_eof)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: file ends before real number ");
- printf(
- "completed.\n");
- }
- }
- if (! fatal_error)
- {
- if ((source_char == '+')
- || (source_char == '-'))
- {
- exponent_sign=source_char;
- get_source_char();
- }
- else
- exponent_sign=' ';
- }
- if (! fatal_error)
- {
- if (source_eof)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: file ends before real number ");
- printf(
- "completed.\n");
- }
- }
- if (! fatal_error)
- {
- if (! isdigit((int) source_char))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: nonnumeric exponent at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- if (! fatal_error)
- exponent_header_ptr=unsigned_integer_header_ptr();
- if (! fatal_error)
- {
- if (*((*exponent_header_ptr).value_ptr.integer)
- > (long) 37)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- free_value(exponent_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: exponent too large at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- if (! fatal_error)
- {
- tem_real_1=1.0;
- exponent_value
- =*((*exponent_header_ptr).value_ptr.integer);
- free_value(exponent_header_ptr);
- while (exponent_value > (long) 0)
- {
- exponent_value--;
- tem_real_1*=10.0;
- }
- if (exponent_sign == '-')
- tem_real_1=1.0/tem_real_1;
- if (*((*result_header_ptr).value_ptr.real) != 0.0)
- {
- tem_real_2=(log(tem_real_1)
- +log(fabs(*((*result_header_ptr).value_ptr.real))))
- /log(10.0);
- if (tem_real_2 < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real_2 > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: real too large at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- *=tem_real_1;
- }
- }
- }
- }
- }
- if (! evaluate)
- {
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr abs_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)
- =labs(*((*((*queue_head).argument_header_ptr)).
- value_ptr.integer));
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =fabs(*((*((*queue_head).argument_header_ptr)).
- value_ptr.real));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr atan_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=atan(tem_real);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =atan(*((*((*queue_head).argument_header_ptr)).
- value_ptr.real));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr char_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- long tem_integer;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_integer=*((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- if (((long) 0 <= tem_integer) && (tem_integer <= (long) 255))
- {
- result_header_ptr=new_string_header_ptr((unsigned) 1);
- if (! fatal_error)
- {
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) tem_integer;
- *((*((*result_header_ptr).value_ptr.string)).value+1)
- =(unsigned char) '\0';
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to CHAR is not between 0 and 255\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to CHAR is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr cos_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=cos(tem_real);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =cos(*((*((*queue_head).argument_header_ptr)).
- value_ptr.real));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr date_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- unsigned char *char_ptr_1;
- char *char_ptr_2;
- char date_and_time [26];
- long elapsed_time;
- struct tm *local_time;
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_string_header_ptr(6);
- if (! fatal_error)
- {
- char_ptr_1=(*((*result_header_ptr).value_ptr.string)).value;
- time(&elapsed_time);
- local_time=localtime(&elapsed_time);
- strcpy(&date_and_time[0],asctime(local_time));
- strncpy((char *) char_ptr_1,&date_and_time[22],2);
- *(char_ptr_1+2)=(unsigned char) '\0';
- date_and_time[7]='\0';
- char_ptr_2=&date_and_time[4];
- if (strcmp(char_ptr_2,"Jan") == 0)
- strcat((char *) char_ptr_1,"01");
- else if (strcmp(char_ptr_2,"Feb") == 0)
- strcat((char *) char_ptr_1,"02");
- else if (strcmp(char_ptr_2,"Mar") == 0)
- strcat((char *) char_ptr_1,"03");
- else if (strcmp(char_ptr_2,"Apr") == 0)
- strcat((char *) char_ptr_1,"04");
- else if (strcmp(char_ptr_2,"May") == 0)
- strcat((char *) char_ptr_1,"05");
- else if (strcmp(char_ptr_2,"Jun") == 0)
- strcat((char *) char_ptr_1,"06");
- else if (strcmp(char_ptr_2,"Jul") == 0)
- strcat((char *) char_ptr_1,"07");
- else if (strcmp(char_ptr_2,"Aug") == 0)
- strcat((char *) char_ptr_1,"08");
- else if (strcmp(char_ptr_2,"Sep") == 0)
- strcat((char *) char_ptr_1,"09");
- else if (strcmp(char_ptr_2,"Oct") == 0)
- strcat((char *) char_ptr_1,"10");
- else if (strcmp(char_ptr_2,"Nov") == 0)
- strcat((char *) char_ptr_1,"11");
- else
- strcat((char *) char_ptr_1,"12");
- strncat((char *) char_ptr_1,&date_and_time[8],2);
- }
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr endfile_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- FILE *file;
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (feof(stdin) == 0)
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- }
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- file=*((*((*queue_head).argument_header_ptr)).
- value_ptr.dataset);
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (feof(file) == 0)
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to ENDFILE is other than a file pointer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr exec_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (system(
- (char *) (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value) == 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a string supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr exp_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real_1;
- double tem_real_2;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real_1=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- tem_real_2=tem_real_1/log(10.0);
- if (tem_real_2 < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real_2 > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to EXP is too large at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)=exp(tem_real_1);
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- tem_real_1=*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- tem_real_2=tem_real_1/log(10.0);
- if (tem_real_2 < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real_2 > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to EXP is too large at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =exp(tem_real_1);
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr false_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr float_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- int status;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'B')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- if (*((*((*queue_head).argument_header_ptr)).
- value_ptr.boolean))
- *((*result_header_ptr).value_ptr.real)=1.0;
- else
- *((*result_header_ptr).value_ptr.real)=0.0;
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- status=sscanf((char *)
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value,"%lf",
- (*result_header_ptr).value_ptr.real);
- if ((status == EOF) || (status == 0))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to FLOAT cannot be converted on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to FLOAT is other than Boolean, number, or string\n");
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr getchar_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- int current_char;
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- current_char=fgetc(
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset));
- if (current_char == EOF)
- {
- result_header_ptr=new_string_header_ptr(0);
- if (! fatal_error)
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- }
- else
- {
- result_header_ptr=new_string_header_ptr(1);
- if (! fatal_error)
- {
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) current_char;
- *((*((*result_header_ptr).value_ptr.string)).value+1)
- =(unsigned char) '\0';
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to GETCHAR is other than a file pointer on\n");
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- current_char=fgetc(stdin);
- if (current_char == EOF)
- {
- result_header_ptr=new_string_header_ptr(0);
- if (! fatal_error)
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- }
- else
- {
- result_header_ptr=new_string_header_ptr(1);
- if (! fatal_error)
- {
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) current_char;
- *((*((*result_header_ptr).value_ptr.string)).value+1)
- =(unsigned char) '\0';
- }
- }
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr getint_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- int num_fields_read;
- value_header_ptr result_header_ptr;
- long tem_integer;
-
- if (queue_head != NULL)
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- num_fields_read=fscanf(
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset),
- "%I",&tem_integer);
- if (num_fields_read == 0)
- tem_integer=(long) 0;
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=tem_integer;
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to GETINT is other than a file pointer on\n");
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- num_fields_read=scanf("%I",&tem_integer);
- if (num_fields_read == 0)
- tem_integer=(long) 0;
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=tem_integer;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr getreal_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- int num_fields_read;
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head != NULL)
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- num_fields_read=fscanf(
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset),
- "%lf",&tem_real);
- if (num_fields_read == 0)
- tem_real=0.0;
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=tem_real;
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to GETREAL is other than a file pointer on\n");
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- num_fields_read=scanf("%lf",&tem_real);
- if (num_fields_read == 0)
- tem_real=0.0;
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=tem_real;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr getstring_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- int current_char;
- value_header_ptr new_result_header_ptr;
- value_header_ptr result_header_ptr;
- unsigned string_length;
-
- if (queue_head != NULL)
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- string_length=0;
- result_header_ptr=new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- do
- {
- current_char=fgetc(
- *((*((*queue_head).argument_header_ptr)).value_ptr.
- dataset));
- if ((current_char != EOF)
- && (current_char != 10))
- {
- string_length++;
- new_result_header_ptr
- =new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- pli_strcpy(
- (*new_result_header_ptr).value_ptr.string,
- (*result_header_ptr).value_ptr.string);
- (*((*new_result_header_ptr).value_ptr.string)).
- value[string_length-1]
- =(unsigned char) current_char;
- (*((*new_result_header_ptr).value_ptr.string)).
- value[string_length]=(unsigned char) '\0';
- free_value(result_header_ptr);
- result_header_ptr=new_result_header_ptr;
- }
- }
- }
- while ((! fatal_error)
- && (current_char != EOF)
- && (current_char != 10));
- if ((*((*result_header_ptr).value_ptr.string)).value[
- string_length-1] == (unsigned) 13)
- {
- string_length--;
- (*((*result_header_ptr).value_ptr.string)).value[
- string_length]=(unsigned char) '\0';
- (*((*result_header_ptr).value_ptr.string)).length
- =string_length;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to GETSTRING is other than a file pointer on\n");
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- string_length=0;
- result_header_ptr=new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- fflush(stdin);
- do
- {
- current_char=fgetc(stdin);
- if ((current_char != EOF)
- && (current_char != 10))
- {
- string_length++;
- new_result_header_ptr
- =new_string_header_ptr(string_length);
- if (! fatal_error)
- {
- pli_strcpy(
- (*new_result_header_ptr).value_ptr.string,
- (*result_header_ptr).value_ptr.string);
- (*((*new_result_header_ptr).value_ptr.string)).
- value[string_length-1]
- =(unsigned char) current_char;
- (*((*new_result_header_ptr).value_ptr.string)).
- value[string_length]=(unsigned char) '\0';
- free_value(result_header_ptr);
- result_header_ptr=new_result_header_ptr;
- }
- }
- }
- while ((! fatal_error)
- && (current_char != EOF)
- && (current_char != 10));
- if ((*((*result_header_ptr).value_ptr.string)).value[
- string_length-1] == (unsigned) 13)
- {
- string_length--;
- (*((*result_header_ptr).value_ptr.string)).value[
- string_length]=(unsigned char) '\0';
- (*((*result_header_ptr).value_ptr.string)).length
- =string_length;
- }
- }
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr index_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- long char_index_2;
- unsigned char *char_ptr_1;
- unsigned char *char_ptr_2;
- unsigned char *char_ptr_3;
- unsigned char *char_ptr_4;
- unsigned char *char_ptr_5;
- long length_1;
- long length_2;
- int match_found;
- long num_trials;
- long result;
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'S')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- char_ptr_1=(*((*((*queue_head).
- argument_header_ptr)).value_ptr.string)).value;
- length_1=(*((*((*queue_head).
- argument_header_ptr)).value_ptr.string)).length;
- char_ptr_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value;
- length_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).length;
- if (length_2 == (long) 0)
- *((*result_header_ptr).value_ptr.integer)=(long) 0;
- else
- {
- num_trials=length_1-length_2+(long) 1;
- char_ptr_3=char_ptr_1;
- match_found=FALSE;
- result=(long) 1;
- while ((result <= num_trials)
- && (! match_found))
- {
- char_ptr_4=char_ptr_2;
- char_index_2=(long) 1;
- char_ptr_5=char_ptr_3;
- while ((char_index_2 <= length_2)
- && (*char_ptr_4 == *char_ptr_5))
- {
- char_ptr_4++;
- char_ptr_5++;
- char_index_2++;
- }
- if (char_index_2 > length_2)
- match_found=TRUE;
- else
- {
- char_ptr_3++;
- result++;
- }
- }
- if (match_found)
- *((*result_header_ptr).value_ptr.integer)=result;
- else
- *((*result_header_ptr).value_ptr.integer)
- =(long) 0;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to INDEX is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to INDEX is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr length_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=(long)
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to LENGTH is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr lineno_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=source_line_num;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr log_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- if (tem_real > 0.0)
- *((*result_header_ptr).value_ptr.real)=log(tem_real);
- else
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to LOG is not positive at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- tem_real=*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- if (tem_real > 0.0)
- *((*result_header_ptr).value_ptr.real)=log(tem_real);
- else
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to LOG is not positive at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr mod_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- long tem_int_1;
- long tem_int_2;
- long tem_int_3;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'I')
- if (*((*((*((*queue_head).next)).argument_header_ptr)).
- value_ptr.integer) == 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to MOD is zero\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- tem_int_1
- =*((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- tem_int_2
- =*((*((*((*queue_head).next)).argument_header_ptr)).
- value_ptr.integer);
- tem_int_3=tem_int_1/tem_int_2;
- tem_int_3*=tem_int_2;
- *((*result_header_ptr).value_ptr.integer)
- =tem_int_1-tem_int_3;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to MOD is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to MOD is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr open_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'S')
- {
- result_header_ptr=new_dataset_header_ptr();
- if (! fatal_error)
- {
- *((*result_header_ptr).value_ptr.dataset)
- =fopen((char *) (*((*((*queue_head).
- argument_header_ptr)).value_ptr.string)).value,
- (char *) (*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value);
- if (*((*result_header_ptr).value_ptr.dataset) == NULL)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: cannot OPEN \"%s\" in mode \"%s\" on\n",
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value,
- (*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value);
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to OPEN is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to OPEN is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr ord_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).argument_header_ptr)).value_ptr.string)).
- length == 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to ORD has length zero\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)
- =(long) *((*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to ORD is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr pi_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=4.0*atan(1.0);
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr repeat_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- long char_index;
- unsigned char *char_ptr_1;
- unsigned char *char_ptr_2;
- unsigned char *char_ptr_3;
- value_header_ptr result_header_ptr;
- long tem_int_1;
- long tem_int_2;
- long result_length;
- double tem_real_1;
- double tem_real_2;
- double tem_real_3;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'I')
- {
- char_ptr_1=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- tem_int_1=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- tem_int_2
- =*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.integer);
- if (tem_int_2 >= (long) 0)
- if (tem_int_1 == 0)
- {
- result_header_ptr
- =new_string_header_ptr((unsigned) 0);
- if (! fatal_error)
- *((*((*result_header_ptr).value_ptr.string)).value)
- =(unsigned char) '\0';
- }
- else
- {
- tem_real_1=(double) tem_int_1;
- tem_real_2=(double) tem_int_2;
- tem_real_3
- =(log(fabs(tem_real_1))+log(fabs(tem_real_2+1.0)))
- /log(2.0);
- if (tem_real_3 >= 15.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: result of REPEAT too long on line\n");
- printf(
- " %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- result_length=tem_int_1;
- result_length*=(tem_int_2+(long) 1);
- result_header_ptr
- =new_string_header_ptr(
- (unsigned) result_length);
- if (! fatal_error)
- {
- char_ptr_3
- =(*((*result_header_ptr).value_ptr.string)).
- value;
- while (tem_int_2 >= (long) 0)
- {
- char_ptr_2=char_ptr_1;
- for (char_index=(long) 0;
- char_index < tem_int_1;
- char_index++)
- {
- *char_ptr_3=*char_ptr_2;
- char_ptr_3++;
- char_ptr_2++;
- }
- tem_int_2--;
- }
- }
- }
- }
- else
- result_header_ptr=copy_of_arguments(
- (*queue_head).argument_header_ptr);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to REPEAT is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to REPEAT is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr sin_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=sin(tem_real);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)
- =sin(*((*((*queue_head).argument_header_ptr)).
- value_ptr.real));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr sqr_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- long tem_integer;
- double tem_real_1;
- double tem_real_2;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- tem_integer
- =*((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- if (tem_integer == 0)
- *((*result_header_ptr).value_ptr.integer)=0;
- else
- {
- tem_real_1=(double) tem_integer;
- tem_real_2=2.0*log(fabs(tem_real_1))/log(2.0);
- if (tem_real_2 >= 31.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to SQR too large on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =tem_integer*tem_integer;
- }
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- tem_real_1
- =*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- if (tem_real_1 == 0.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- {
- tem_real_2=2.0*log(fabs(tem_real_1))/log(10.0);
- if (tem_real_2 < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real_2 > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to SQR too large on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =tem_real_1*tem_real_1;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr sqrt_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- double tem_real;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- tem_real=(double) *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- if (tem_real < 0.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is negative\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- tem_real=sqrt(tem_real);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=tem_real;
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- tem_real=*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- if (tem_real < 0.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is negative\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- tem_real=sqrt(tem_real);
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.real)=tem_real;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a number supplied as argument to function \"%s\"\n",
- function_name);
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr str_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- char buffer [256];
- value_header_ptr result_header_ptr;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- switch ((*((*queue_head).argument_header_ptr)).type)
- {
- case 'B':
- if
- (*((*((*queue_head).argument_header_ptr)).value_ptr.boolean))
- {
- result_header_ptr=new_string_header_ptr((unsigned) 4);
- if (! fatal_error)
- strcpy((char *)
- (*((*result_header_ptr).value_ptr.string)).value,
- "TRUE");
- }
- else
- {
- result_header_ptr=new_string_header_ptr((unsigned) 5);
- if (! fatal_error)
- strcpy((char *)
- (*((*result_header_ptr).value_ptr.string)).value,
- "FALSE");
- }
- break;
- case 'D':
- buffer[sprintf(buffer,"%p",
- *((*((*queue_head).argument_header_ptr)).value_ptr.
- dataset))]='\0';
- result_header_ptr
- =new_string_header_ptr((unsigned) strlen(buffer));
- if (! fatal_error)
- strcpy((char *)
- (*((*result_header_ptr).value_ptr.string)).value,buffer);
- break;
- case 'I':
- buffer[sprintf(buffer,"%ld",
- *((*((*queue_head).argument_header_ptr)).value_ptr.integer))]
- ='\0';
- result_header_ptr
- =new_string_header_ptr((unsigned) strlen(buffer));
- if (! fatal_error)
- strcpy((char *)
- (*((*result_header_ptr).value_ptr.string)).value,buffer);
- break;
- case 'R':
- buffer[sprintf(buffer,"%lG",
- *((*((*queue_head).argument_header_ptr)).value_ptr.real))]
- ='\0';
- result_header_ptr
- =new_string_header_ptr((unsigned) strlen(buffer));
- if (! fatal_error)
- strcpy((char *)
- (*((*result_header_ptr).value_ptr.string)).value,buffer);
- break;
- default:
- result_header_ptr=new_string_header_ptr((unsigned)
- (*((*((*queue_head).argument_header_ptr)).value_ptr.
- string)).length);
- if (! fatal_error)
- pli_strcpy((*result_header_ptr).value_ptr.string,
- (*((*queue_head).argument_header_ptr)).value_ptr.string);
- break;
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr substr_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- unsigned char *char_ptr;
- unsigned char *destination_ptr;
- long final_column;
- long num_columns;
- int offset;
- value_header_ptr result_header_ptr;
- unsigned char *source_ptr;
- long starting_column;
- int string_length;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'I')
- {
- char_ptr=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- string_length=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- starting_column
- =*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.integer);
- if (starting_column <= (long) 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to SUBSTR is not positive\n");
- printf(
- " on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (starting_column > string_length)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to SUBSTR exceeds length of first argument\n");
- printf(
- " on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- num_columns=string_length-starting_column+(long) 1;
- result_header_ptr
- =new_string_header_ptr((unsigned) num_columns);
- if (! fatal_error)
- {
- offset=(int) starting_column;
- offset--;
- source_ptr=char_ptr+offset;
- destination_ptr
- =(*((*result_header_ptr).value_ptr.string)).
- value;
- while (num_columns > 0)
- {
- *destination_ptr=*source_ptr;
- source_ptr++;
- destination_ptr++;
- num_columns--;
- }
- *destination_ptr=(unsigned char) '\0';
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to SUBSTR is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to SUBSTR is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- if ((*((*((*queue_head).next)).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'I')
- if ((*((*((*((*queue_head).next)).next)).
- argument_header_ptr)).type == 'I')
- {
- char_ptr=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- string_length
- =(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- starting_column
- =*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.integer);
- if (starting_column <= (long) 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to SUBSTR is not positive\n");
- printf(
- " on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- num_columns
- =*((*((*((*((*queue_head).next)).next)).
- argument_header_ptr)).value_ptr.integer);
- if (num_columns == (long) 0)
- {
- result_header_ptr=new_string_header_ptr(0);
- if (! fatal_error)
- *((*((*result_header_ptr).value_ptr.string)).
- value)=(unsigned char) '\0';
- }
- else
- {
- final_column=starting_column+num_columns-1;
- if (final_column > string_length)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: SUBSTRing extends beyond end of first argument\n");
- printf(
- " on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (final_column < starting_column)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: third argument to SUBSTR is not positive\n");
- printf(
- " on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr
- =new_string_header_ptr(
- (unsigned) num_columns);
- if (! fatal_error)
- {
- offset=(int) starting_column;
- offset--;
- source_ptr=char_ptr+offset;
- destination_ptr
- =(*((*result_header_ptr).
- value_ptr.string)).value;
- while (final_column
- >= starting_column)
- {
- *destination_ptr=*source_ptr;
- source_ptr++;
- destination_ptr++;
- starting_column++;
- }
- *destination_ptr='\0';
- }
- }
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: third argument to SUBSTR is other than an integer\n");
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to SUBSTR is other than an integer\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to SUBSTR is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr sysin_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_dataset_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.dataset)=stdin;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr sysprint_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_dataset_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.dataset)=stdout;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr time_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- unsigned char *char_ptr;
- char date_and_time [26];
- long elapsed_time;
- struct tm *local_time;
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_string_header_ptr((unsigned) 9);
- if (! fatal_error)
- {
- char_ptr=(*((*result_header_ptr).value_ptr.string)).value;
- time(&elapsed_time);
- local_time=localtime(&elapsed_time);
- strcpy(&date_and_time[0],asctime(local_time));
- *char_ptr=(unsigned char) date_and_time[11];
- char_ptr++;
- *char_ptr=(unsigned char) date_and_time[12];
- char_ptr++;
- *char_ptr=(unsigned char) date_and_time[14];
- char_ptr++;
- *char_ptr=(unsigned char) date_and_time[15];
- char_ptr++;
- *char_ptr=(unsigned char) date_and_time[17];
- char_ptr++;
- *char_ptr=(unsigned char) date_and_time[18];
- char_ptr++;
- *char_ptr=(unsigned char) '0';
- char_ptr++;
- *char_ptr=(unsigned char) '0';
- char_ptr++;
- *char_ptr=(unsigned char) '0';
- char_ptr++;
- *char_ptr=(unsigned char) '\0';
- }
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr translate_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- unsigned char_index_1;
- int char_index_2;
- unsigned char_index_3;
- unsigned char *char_ptr_1;
- unsigned char *char_ptr_2;
- unsigned char *char_ptr_3;
- unsigned char *char_ptr_4;
- unsigned char *char_ptr_5;
- value_header_ptr result_header_ptr;
- unsigned length_1;
- int length_2;
- unsigned length_3;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'S')
- {
- char_ptr_1
- =(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- length_1
- =(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- char_ptr_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value;
- length_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).length;
- result_header_ptr=new_string_header_ptr((unsigned)
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length);
- if (! fatal_error)
- {
- char_ptr_5
- =(*((*result_header_ptr).value_ptr.string)).value;
- char_index_1=(unsigned) 1;
- while (char_index_1 <= length_1)
- {
- char_index_2=(int) *char_ptr_1;
- if (char_index_2 < length_2)
- *char_ptr_5=*(char_ptr_2+char_index_2);
- else
- *char_ptr_5=(unsigned char) ' ';
- char_index_1++;
- char_ptr_1++;
- char_ptr_5++;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to TRANSLATE is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to TRANSLATE is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- if ((*((*((*queue_head).next)).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'S')
- if ((*((*((*((*queue_head).next)).next)).
- argument_header_ptr)).type == 'S')
- {
- char_ptr_1
- =(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- length_1
- =(unsigned) (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- char_ptr_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value;
- length_2=(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).length;
- char_ptr_3=(*((*((*((*((*queue_head).next)).next)).
- argument_header_ptr)).value_ptr.string)).value;
- length_3
- =(unsigned) (*((*((*((*((*queue_head).next)).next)).
- argument_header_ptr)).value_ptr.string)).length;
- result_header_ptr=new_string_header_ptr((unsigned)
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length);
- if (! fatal_error)
- {
- char_ptr_5
- =(*((*result_header_ptr).value_ptr.string)).value;
- char_index_1=(unsigned) 1;
- while (char_index_1 <= length_1)
- {
- char_index_2=0;
- char_ptr_4=char_ptr_3;
- char_index_3=1;
- while ((char_index_3 <= length_3)
- && (*char_ptr_4 != *char_ptr_1))
- {
- char_ptr_4++;
- char_index_2++;
- char_index_3++;
- }
- if (char_index_3 <= length_3)
- {
- if ((long) char_index_2 >= length_2)
- *char_ptr_5=(unsigned char) ' ';
- else
- *char_ptr_5=*(char_ptr_2+char_index_2);
- }
- else
- *char_ptr_5=*char_ptr_1;
- char_ptr_1++;
- char_ptr_5++;
- char_index_1++;
- }
- *char_ptr_5=(unsigned char) '\0';
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: third argument to TRANSLATE is other than a string\n");
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to TRANSLATE is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to TRANSLATE is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr true_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- if (queue_head != NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if (evaluate)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- }
- else
- result_header_ptr=NULL;
- return(result_header_ptr);
- }
-
- static value_header_ptr trunc_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- value_header_ptr result_header_ptr;
- int status;
- double tem_real_1;
- double tem_real_2;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'I')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)
- =*((*((*queue_head).argument_header_ptr)).
- value_ptr.integer);
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'R')
- {
- tem_real_1=*((*((*queue_head).argument_header_ptr)).
- value_ptr.real);
- if (tem_real_1 == 0.0)
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)=(long) 0;
- }
- else
- {
- tem_real_2=log(fabs(tem_real_1))/log(2.0);
- if (tem_real_2 >= 31.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: magnitude of argument to TRUNC too large\n");
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.integer)
- =(long) tem_real_1;
- }
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'B')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- if (*((*((*queue_head).argument_header_ptr)).
- value_ptr.boolean))
- *((*result_header_ptr).value_ptr.integer)=1;
- else
- *((*result_header_ptr).value_ptr.integer)=0;
- }
- }
- else
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- status=sscanf((char *)
- (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value,"%I",
- (*result_header_ptr).value_ptr.integer);
- if ((status == EOF) || (status == 0))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to TRUNC cannot be converted on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to TRUNC is other than Boolean, number, or string\n");
- printf(" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr upper_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- register int char_index;
- unsigned char *char_ptr;
- value_header_ptr result_header_ptr;
- int string_length;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- {
- result_header_ptr=new_string_header_ptr((unsigned)
- (*((*((*queue_head).argument_header_ptr)).value_ptr.string)).
- length);
- if (! fatal_error)
- {
- pli_strcpy((*result_header_ptr).value_ptr.string,
- (*((*queue_head).argument_header_ptr)).value_ptr.string);
- char_ptr=(*((*result_header_ptr).value_ptr.string)).value;
- string_length
- =(*((*result_header_ptr).value_ptr.string)).length;
- for (char_index=0; char_index < string_length;
- char_index++)
- {
- *char_ptr=(unsigned char) toupper((int) *char_ptr);
- char_ptr++;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to UPPER is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr verify_header_ptr(queue_head,function_name,evaluate)
- queue_node_ptr queue_head;
- char *function_name;
- int evaluate;
- {
- long char_index;
- int char_okay;
- unsigned char *char_ptr;
- value_header_ptr result_header_ptr;
- unsigned rule_index;
- unsigned rule_length;
- unsigned char *rule_ptr;
- long string_length;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*queue_head).next == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: argument to function \"%s\" is missing on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- if ((*((*queue_head).next)).next == NULL)
- if (evaluate)
- if ((*((*queue_head).argument_header_ptr)).type == 'S')
- if ((*((*((*queue_head).next)).argument_header_ptr)).type
- == 'S')
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- char_ptr=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- string_length
- =(long) (*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- char_index=(long) 1;
- char_okay=TRUE;
- while ((char_index <= string_length)
- && (char_okay))
- {
- char_okay=FALSE;
- rule_ptr
- =(*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).value;
- rule_length
- =(unsigned) (*((*((*((*queue_head).next)).
- argument_header_ptr)).value_ptr.string)).length;
- rule_index=(unsigned) 1;
- while ((! char_okay)
- && (rule_index <= rule_length))
- if (*rule_ptr == *char_ptr)
- char_okay=TRUE;
- else
- {
- rule_ptr++;
- rule_index++;
- }
- if (char_okay)
- {
- char_ptr++;
- char_index++;
- }
- }
- if (char_okay)
- *((*result_header_ptr).value_ptr.integer)=(long) 0;
- else
- *((*result_header_ptr).value_ptr.integer)
- =char_index;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: second argument to VERIFY is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: first argument to VERIFY is other than a string\n");
- printf(" on line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- result_header_ptr=NULL;
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: extraneous argument supplied to function \"%s\" on\n",
- function_name);
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr function_header_ptr(evaluate)
- int evaluate;
- {
- queue_node_ptr new_queue_head;
- queue_node_ptr new_queue_tail;
- queue_node_ptr queue_head;
- queue_node_ptr queue_tail;
- value_header_ptr result_header_ptr;
- char function_name [256];
-
- get_token();
- strcpy(function_name,source_token);
- queue_head=NULL;
- queue_tail=NULL;
- if (source_char == '(')
- {
- get_token();
- if ((queue_head=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node)))
- == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- queue_tail=queue_head;
- (*queue_head).next=NULL;
- (*queue_head).argument_header_ptr
- =interpret_expression(evaluate);
- }
- if (! fatal_error)
- get_token();
- while ((! fatal_error)
- && (! source_eof)
- && (source_token[0] != ')'))
- {
- if ((new_queue_tail=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node)))
- == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*new_queue_tail).next=NULL;
- (*queue_tail).next=new_queue_tail;
- queue_tail=new_queue_tail;
- (*new_queue_tail).argument_header_ptr
- =interpret_expression(evaluate);
- }
- if (! fatal_error)
- get_token();
- }
- if (! fatal_error)
- {
- if (source_token[0] != ')')
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: file ends before arguments to function \"%s\" completed.\n",
- function_name);
- }
- }
- }
- if (! fatal_error)
- {
- result_header_ptr
- =variable_header_ptr(function_name,evaluate,queue_head);
- if (! fatal_error)
- {
- if (result_header_ptr == NULL)
- {
- if (strcmp(function_name,"ABS") == 0)
- result_header_ptr
- =abs_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"ATAN") == 0)
- result_header_ptr
- =atan_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"CHAR") == 0)
- result_header_ptr
- =char_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"COS") == 0)
- result_header_ptr
- =cos_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"DATE") == 0)
- result_header_ptr
- =date_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"ENDFILE") == 0)
- result_header_ptr
- =endfile_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"EXEC") == 0)
- result_header_ptr
- =exec_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"EXP") == 0)
- result_header_ptr
- =exp_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"FALSE") == 0)
- result_header_ptr
- =false_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"FLOAT") == 0)
- result_header_ptr
- =float_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"GETCHAR") == 0)
- result_header_ptr
- =getchar_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"GETINT") == 0)
- result_header_ptr
- =getint_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"GETREAL") == 0)
- result_header_ptr
- =getreal_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"GETSTRING") == 0)
- result_header_ptr
- =getstring_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"INDEX") == 0)
- result_header_ptr
- =index_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"LENGTH") == 0)
- result_header_ptr
- =length_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"LINENO") == 0)
- result_header_ptr
- =lineno_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"LOG") == 0)
- result_header_ptr
- =log_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"MOD") == 0)
- result_header_ptr
- =mod_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"OPEN") == 0)
- result_header_ptr
- =open_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"ORD") == 0)
- result_header_ptr
- =ord_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"PI") == 0)
- result_header_ptr
- =pi_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"REPEAT") == 0)
- result_header_ptr
- =repeat_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SIN") == 0)
- result_header_ptr
- =sin_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SQR") == 0)
- result_header_ptr
- =sqr_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SQRT") == 0)
- result_header_ptr
- =sqrt_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"STR") == 0)
- result_header_ptr
- =str_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SUBSTR") == 0)
- result_header_ptr
- =substr_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SYSIN") == 0)
- result_header_ptr
- =sysin_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"SYSPRINT") == 0)
- result_header_ptr
- =sysprint_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"TIME") == 0)
- result_header_ptr
- =time_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"TRANSLATE") == 0)
- result_header_ptr
- =translate_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"TRUE") == 0)
- result_header_ptr
- =true_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"TRUNC") == 0)
- result_header_ptr
- =trunc_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"UPPER") == 0)
- result_header_ptr
- =upper_header_ptr(queue_head,function_name,evaluate);
- else if (strcmp(function_name,"VERIFY") == 0)
- result_header_ptr
- =verify_header_ptr(queue_head,function_name,evaluate);
- else
- {
- if (evaluate)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: the function \"%s\" on line %ld, column %ld\n",
- function_name,source_line_num,source_column_num);
- printf(" is unknown.\n");
- }
- }
- }
- }
- }
- while (queue_head != NULL)
- {
- new_queue_head=(*queue_head).next;
- free_value((*queue_head).argument_header_ptr);
- free((char *) queue_head);
- queue_head=new_queue_head;
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr factor_header_ptr(evaluate)
- int evaluate;
- {
- value_header_ptr result_header_ptr;
-
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- if (source_eof)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: end of file encountered where factor expected.\n");
- }
- else
- {
- switch (source_char)
- {
- case '(':
- get_source_char();
- result_header_ptr=interpret_expression(evaluate);
- if (! fatal_error)
- {
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- if (source_eof)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: end of file encountered where \"(\" expected.\n");
- }
- else
- if (source_char == ')')
- get_source_char();
- else
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: expression not followed by \"(\" on line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- break;
- case '!':
- get_source_char();
- result_header_ptr=factor_header_ptr(evaluate);
- if (! fatal_error)
- {
- if (evaluate)
- if ((*result_header_ptr).type == 'B')
- *((*result_header_ptr).value_ptr.boolean)
- =! (*((*result_header_ptr).value_ptr.boolean));
- else
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: other than a boolean negated at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- result_header_ptr=NULL;
- }
- break;
- case '\'':
- result_header_ptr=string_header_ptr(evaluate);
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- result_header_ptr=unsigned_number_header_ptr(evaluate);
- break;
- default:
- result_header_ptr=function_header_ptr(evaluate);
- break;
- }
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr and_factors(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (((*left_header_ptr).type == 'B')
- && ((*right_header_ptr).type == 'B'))
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.boolean)
- =(*((*left_header_ptr).value_ptr.boolean))
- && (*((*right_header_ptr).value_ptr.boolean));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to \"and\" other than two booleans\n");
- printf(
- "at line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr divide_factors(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- double left_value;
- value_header_ptr result_header_ptr;
- double right_value;
- double tem_real;
-
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'I'))
- {
- if (*((*right_header_ptr).value_ptr.integer) == (long) 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: division by zero attempted at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- *((*result_header_ptr).value_ptr.integer)
- =(*((*left_header_ptr).value_ptr.integer))
- /(*((*right_header_ptr).value_ptr.integer));
- }
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'R'))
- {
- if (*((*right_header_ptr).value_ptr.real) == 0.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: division by zero attempted at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_value=*((*left_header_ptr).value_ptr.real);
- right_value=*((*right_header_ptr).value_ptr.real);
- if (left_value == 0.0)
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_value))-log(fabs(right_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in division at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_value/right_value;
- }
- }
- }
- else
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'R'))
- {
- if (*((*right_header_ptr).value_ptr.real) == 0.0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: division by zero attempted at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_value
- =(float) *((*left_header_ptr).value_ptr.integer);
- right_value=*((*right_header_ptr).value_ptr.real);
- if (left_value == 0.0)
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_value))-log(fabs(right_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in division at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_value/right_value;
- }
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'I'))
- {
- if (*((*right_header_ptr).value_ptr.integer) == 0)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: division by zero attempted at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_value=*((*left_header_ptr).value_ptr.real);
- right_value
- =(float) *((*right_header_ptr).value_ptr.integer);
- if (left_value == 0.0)
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_value))-log(fabs(right_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in division at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_value/right_value;
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to divide other than two numbers at\n");
- printf(
- "line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr multiply_factors(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- long left_integer_value;
- double left_real_value;
- value_header_ptr result_header_ptr;
- long right_integer_value;
- double right_real_value;
- double tem_real;
-
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- left_integer_value=*((*left_header_ptr).value_ptr.integer);
- right_integer_value=*((*right_header_ptr).value_ptr.integer);
- if ((left_integer_value == 0) || (right_integer_value == 0))
- tem_real=0.0;
- else
- {
- left_real_value=(float) left_integer_value;
- right_real_value=(float) right_integer_value;
- tem_real
- =(log(fabs(left_real_value))+log(fabs(right_real_value)))
- /log(2.0);
- }
- if (tem_real >= 31.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in multiplication at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value*right_integer_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value == 0.0) || (right_real_value == 0.0))
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_real_value))+log(fabs(right_real_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in multiplication at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value*right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value
- =(float) *((*left_header_ptr).value_ptr.integer);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value == 0.0) || (right_real_value == 0.0))
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_real_value))+log(fabs(right_real_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in multiplication at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value*right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value
- =(float) *((*right_header_ptr).value_ptr.integer);
- if ((left_real_value == 0.0) || (right_real_value == 0.0))
- tem_real=0.0;
- else
- tem_real
- =(log(fabs(left_real_value))
- +log(fabs(right_real_value)))
- /log(10.0);
- if (tem_real < -37.0)
- *((*result_header_ptr).value_ptr.real)=0.0;
- else
- if (tem_real > 37.0)
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in multiplication at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value*right_real_value;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to multiply other than two numbers at\n");
- printf(
- "line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static void get_factor_operator(operator)
- char *operator;
- {
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- switch (source_char)
- {
- case '*':
- *operator=source_char;
- get_source_char();
- break;
- case '/':
- *operator=source_char;
- get_source_char();
- break;
- case '&':
- *operator=source_char;
- get_source_char();
- break;
- default:
- *operator='\0';
- break;
- }
- return;
- }
-
- static value_header_ptr term_header_ptr(evaluate)
- int evaluate;
- {
- value_header_ptr left_header_ptr;
- char operator;
- int operator_found;
- value_header_ptr result_header_ptr;
- value_header_ptr right_header_ptr;
-
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- if (source_char == ' ')
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: end of file encountered where term expected.\n");
- }
- else
- {
- result_header_ptr=factor_header_ptr(evaluate);
- operator_found=TRUE;
- while ((! fatal_error)
- && (operator_found))
- {
- get_factor_operator(&operator);
- if ((operator != '*')
- && (operator != '/')
- && (operator != '&'))
- operator_found=FALSE;
- else
- {
- right_header_ptr=factor_header_ptr(evaluate);
- if (fatal_error)
- {
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- }
- else
- {
- left_header_ptr=result_header_ptr;
- if (evaluate)
- {
- switch (operator)
- {
- case '*':
- result_header_ptr=multiply_factors(
- left_header_ptr,right_header_ptr);
- break;
- case '/':
- result_header_ptr=divide_factors(
- left_header_ptr,right_header_ptr);
- break;
- default:
- result_header_ptr=and_factors(
- left_header_ptr,right_header_ptr);
- break;
- }
- free_value(left_header_ptr);
- free_value(right_header_ptr);
- }
- else
- result_header_ptr=NULL;
- }
- }
- }
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr concatenate_terms(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- register int char_index;
- unsigned char *char_ptr;
- unsigned char *result_char_ptr;
- value_header_ptr result_header_ptr;
- unsigned string_length;
-
- if (((*left_header_ptr).type == 'S')
- && ((*right_header_ptr).type == 'S'))
- {
- result_header_ptr=new_string_header_ptr((unsigned)
- (*((*left_header_ptr).value_ptr.string)).length
- +(unsigned) (*((*right_header_ptr).value_ptr.string)).length);
- if (! fatal_error)
- {
- result_char_ptr=(*((*result_header_ptr).value_ptr.string)).value;
- char_ptr=(*((*left_header_ptr).value_ptr.string)).value;
- string_length=(*((*left_header_ptr).value_ptr.string)).length;
- for (char_index=0; char_index < string_length; char_index++)
- {
- *result_char_ptr=*char_ptr;
- result_char_ptr++;
- char_ptr++;
- }
- char_ptr=(*((*right_header_ptr).value_ptr.string)).value;
- string_length=(*((*right_header_ptr).value_ptr.string)).length;
- for (char_index=0; char_index < string_length; char_index++)
- {
- *result_char_ptr=*char_ptr;
- result_char_ptr++;
- char_ptr++;
- }
- *result_char_ptr=(unsigned char) '\0';
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to concatenate other than two strings\n");
- printf(
- "at line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr add_terms(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- long left_integer_value;
- double left_real_value;
- value_header_ptr result_header_ptr;
- long right_integer_value;
- double right_real_value;
-
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- left_integer_value=*((*left_header_ptr).value_ptr.integer);
- right_integer_value=*((*right_header_ptr).value_ptr.integer);
- if ((left_integer_value > 0) && (right_integer_value > 0))
- if (left_integer_value
- > ((long) 0x7fffffff - right_integer_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value+right_integer_value;
- else
- if ((left_integer_value < 0) && (right_integer_value < 0))
- if (left_integer_value
- < (-((long) 0x7fffffff) - right_integer_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value+right_integer_value;
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value+right_integer_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value > 0.0) && (right_real_value > 0.0))
- if (left_real_value > (1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- if ((left_real_value < 0.0) && (right_real_value < 0.0))
- if (left_real_value < (-1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=(double)
- *((*left_header_ptr).value_ptr.integer);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value > 0.0) && (right_real_value > 0.0))
- if (left_real_value > (1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- if ((left_real_value < 0.0) && (right_real_value < 0.0))
- if (left_real_value < (-1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value > 0.0)
- && (right_real_value > 0.0))
- if (left_real_value > (1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- if ((left_real_value < 0.0)
- && (right_real_value < 0.0))
- if (left_real_value < (-1.0E37 - right_real_value))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value+right_real_value;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to add other than two numbers at\n");
- printf(
- "line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr subtract_terms(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- long left_integer_value;
- double left_real_value;
- value_header_ptr result_header_ptr;
- long right_integer_value;
- double right_real_value;
-
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_integer_header_ptr();
- if (! fatal_error)
- {
- left_integer_value=*((*left_header_ptr).value_ptr.integer);
- right_integer_value=*((*right_header_ptr).value_ptr.integer);
- if ((left_integer_value < 0) && (right_integer_value > 0))
- if (left_integer_value
- < (right_integer_value-((long) 0x7fffffff)))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value-right_integer_value;
- else
- if ((left_integer_value > 0) && (right_integer_value < 0))
- if (left_integer_value
- > (right_integer_value+(long) 0x7fffffff))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value-right_integer_value;
- else
- *((*result_header_ptr).value_ptr.integer)
- =left_integer_value-right_integer_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value < 0.0) && (right_real_value > 0.0))
- if (left_real_value < (right_real_value-1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- if ((left_real_value > 0.0) && (right_real_value < 0.0))
- if (left_real_value > (right_real_value+1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'R'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=(double)
- *((*left_header_ptr).value_ptr.integer);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value < 0.0) && (right_real_value > 0.0))
- if (left_real_value < (right_real_value-1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- if ((left_real_value > 0.0) && (right_real_value < 0.0))
- if (left_real_value > (right_real_value+1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'I'))
- {
- result_header_ptr=new_real_header_ptr();
- if (! fatal_error)
- {
- left_real_value=*((*left_header_ptr).value_ptr.real);
- right_real_value=*((*right_header_ptr).value_ptr.real);
- if ((left_real_value < 0.0)
- && (right_real_value > 0.0))
- if (left_real_value < (right_real_value-1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- if ((left_real_value > 0.0)
- && (right_real_value < 0.0))
- if (left_real_value > (right_real_value+1.0E37))
- {
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: overflow detected in addition at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- else
- *((*result_header_ptr).value_ptr.real)
- =left_real_value-right_real_value;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to add other than two numbers at\n");
- printf(
- "line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr or_terms(left_header_ptr,right_header_ptr)
- value_header_ptr left_header_ptr;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (((*left_header_ptr).type == 'B')
- && ((*right_header_ptr).type == 'B'))
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- *((*result_header_ptr).value_ptr.boolean)
- =(*((*left_header_ptr).value_ptr.boolean))
- || (*((*right_header_ptr).value_ptr.boolean));
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: attempt to \"or\" other than two booleans\n");
- printf(
- "at line %ld, column %ld.\n",source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static void get_term_operator(operator)
- char *operator;
- {
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- switch (source_char)
- {
- case '+':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- break;
- case '-':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- break;
- case '|':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- if (source_char == '|')
- {
- operator[1]='|';
- operator[2]='\0';
- get_source_char();
- }
- break;
- default:
- operator[0]='\0';
- break;
- }
- return;
- }
-
- static value_header_ptr simple_expression_header_ptr(evaluate)
- int evaluate;
- {
- char leading_sign;
- value_header_ptr left_header_ptr;
- char operator [3];
- int operator_found;
- value_header_ptr result_header_ptr;
- value_header_ptr right_header_ptr;
-
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- if (source_char == ' ')
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf(
- "Fatal error: end of file encountered where simple expression expected.\n");
- }
- else
- {
- leading_sign=' ';
- if ((source_char == '+') || (source_char == '-'))
- {
- leading_sign=source_char;
- get_source_char();
- }
- result_header_ptr=term_header_ptr(evaluate);
- if (! fatal_error)
- {
- if ((evaluate) && (leading_sign != ' '))
- switch ((*result_header_ptr).type)
- {
- case 'I':
- if (leading_sign == '-')
- *((*result_header_ptr).value_ptr.integer)
- =-(*((*result_header_ptr).value_ptr.integer));
- break;
- case 'R':
- if (leading_sign == '-')
- *((*result_header_ptr).value_ptr.real)
- =-(*((*result_header_ptr).value_ptr.real));
- break;
- default:
- fatal_error=TRUE;
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- printf(
- "Fatal error: sign applied to other than number at ");
- printf(
- "line %ld, column %ld.\n",
- source_line_num,source_column_num);
- break;
- }
- operator_found=TRUE;
- while ((! fatal_error)
- && (operator_found))
- {
- get_term_operator(operator);
- if ((strcmp(operator,"||") != 0)
- && (strcmp(operator,"|") != 0)
- && (strcmp(operator,"+") != 0)
- && (strcmp(operator,"-") != 0))
- operator_found=FALSE;
- else
- {
- right_header_ptr=term_header_ptr(evaluate);
- if (fatal_error)
- {
- free_value(result_header_ptr);
- result_header_ptr=NULL;
- }
- else
- {
- left_header_ptr=result_header_ptr;
- if (evaluate)
- {
- if (strcmp(operator,"||") == 0)
- result_header_ptr=concatenate_terms(
- left_header_ptr,right_header_ptr);
- else
- switch (operator[0])
- {
- case '+':
- result_header_ptr=add_terms(
- left_header_ptr,right_header_ptr);
- break;
- case '-':
- result_header_ptr=subtract_terms(
- left_header_ptr,right_header_ptr);
- break;
- default:
- result_header_ptr=or_terms(
- left_header_ptr,right_header_ptr);
- break;
- }
- free_value(left_header_ptr);
- free_value(right_header_ptr);
- }
- else
- result_header_ptr=NULL;
- }
- }
- }
- }
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr boolean_comparison(left_header_ptr,operator,
- right_header_ptr)
- value_header_ptr left_header_ptr;
- char *operator;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (strcmp(operator,"!=") == 0)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (*((*left_header_ptr).value_ptr.boolean)
- != *((*right_header_ptr).value_ptr.boolean))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- }
- else
- if (strcmp(operator,"=") == 0)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (*((*left_header_ptr).value_ptr.boolean)
- == *((*right_header_ptr).value_ptr.boolean))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: \"%s\" used to compare booleans at ",
- operator);
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr dataset_comparison(left_header_ptr,operator,
- right_header_ptr)
- value_header_ptr left_header_ptr;
- char *operator;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- if (strcmp(operator,"!=") == 0)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (*((*left_header_ptr).value_ptr.dataset)
- != *((*right_header_ptr).value_ptr.dataset))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- }
- else
- if (strcmp(operator,"=") == 0)
- {
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (*((*left_header_ptr).value_ptr.dataset)
- == *((*right_header_ptr).value_ptr.dataset))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: \"%s\" used to compare file pointers at ",
- operator);
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return(result_header_ptr);
- }
-
- static value_header_ptr integer_comparison(left_header_ptr,operator,
- right_header_ptr)
- value_header_ptr left_header_ptr;
- char *operator;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (strcmp(operator,"<=") == 0)
- if (*((*left_header_ptr).value_ptr.integer)
- <= *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">=") == 0)
- if (*((*left_header_ptr).value_ptr.integer)
- >= *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"!=") == 0)
- if (*((*left_header_ptr).value_ptr.integer)
- != *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">") == 0)
- if (*((*left_header_ptr).value_ptr.integer)
- > *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"<") == 0)
- if (*((*left_header_ptr).value_ptr.integer)
- < *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (*((*left_header_ptr).value_ptr.integer)
- == *((*right_header_ptr).value_ptr.integer))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- return(result_header_ptr);
- }
-
-
- static value_header_ptr real_comparison(left_header_ptr,operator,
- right_header_ptr)
- value_header_ptr left_header_ptr;
- char *operator;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (strcmp(operator,"<=") == 0)
- if (*((*left_header_ptr).value_ptr.real)
- <= *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">=") == 0)
- if (*((*left_header_ptr).value_ptr.real)
- >= *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"!=") == 0)
- if (*((*left_header_ptr).value_ptr.real)
- != *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">") == 0)
- if (*((*left_header_ptr).value_ptr.real)
- > *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"<") == 0)
- if (*((*left_header_ptr).value_ptr.real)
- < *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (*((*left_header_ptr).value_ptr.real)
- == *((*right_header_ptr).value_ptr.real))
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- return(result_header_ptr);
- }
-
-
- static value_header_ptr string_comparison(left_header_ptr,operator,
- right_header_ptr)
- value_header_ptr left_header_ptr;
- char *operator;
- value_header_ptr right_header_ptr;
- {
- value_header_ptr result_header_ptr;
-
- result_header_ptr=new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (strcmp(operator,"<=") == 0)
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) <= 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">=") == 0)
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) >= 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"!=") == 0)
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) != 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,"<") == 0)
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) < 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (strcmp(operator,">") == 0)
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) > 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- else
- if (pli_strcmp((*left_header_ptr).value_ptr.string,
- (*right_header_ptr).value_ptr.string) == 0)
- *((*result_header_ptr).value_ptr.boolean)=TRUE;
- else
- *((*result_header_ptr).value_ptr.boolean)=FALSE;
- }
- return(result_header_ptr);
- }
-
- static void get_comparison_operator(operator)
- char *operator;
- {
- while ((source_char == ' ')
- && (! source_eof))
- get_source_char();
- switch (source_char)
- {
- case '=':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- break;
- case '<':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- if (source_char == '=')
- {
- operator[1]='=';
- operator[2]='\0';
- get_source_char();
- }
- break;
- case '!':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- if (source_char == '=')
- {
- operator[1]='=';
- operator[2]='\0';
- get_source_char();
- }
- break;
- case '>':
- operator[0]=source_char;
- operator[1]='\0';
- get_source_char();
- if (source_char == '=')
- {
- operator[1]='=';
- operator[2]='\0';
- get_source_char();
- }
- break;
- default:
- operator[0]='\0';
- break;
- }
- return;
- }
-
- static value_header_ptr interpret_expression(evaluate)
- int evaluate;
- {
- value_header_ptr left_header_ptr;
- char operator [3];
- value_header_ptr result_header_ptr;
- value_header_ptr right_header_ptr;
- double tem_real_1;
-
- left_header_ptr=simple_expression_header_ptr(evaluate);
- if (fatal_error)
- result_header_ptr=NULL;
- else
- {
- get_comparison_operator(operator);
- if ((strcmp(operator,"<=") != 0)
- && (strcmp(operator,">=") != 0)
- && (strcmp(operator,"!=") != 0)
- && (strcmp(operator,"<") != 0)
- && (strcmp(operator,">") != 0)
- && (strcmp(operator,"=") != 0))
- result_header_ptr=left_header_ptr;
- else
- {
- right_header_ptr=simple_expression_header_ptr(evaluate);
- if (fatal_error)
- {
- free_value(left_header_ptr);
- result_header_ptr=NULL;
- }
- else
- {
- if (evaluate)
- {
- if ((*left_header_ptr).type
- == (*right_header_ptr).type)
- switch ((*left_header_ptr).type)
- {
- case 'B':
- result_header_ptr=boolean_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- break;
- case 'D':
- result_header_ptr=dataset_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- break;
- case 'I':
- result_header_ptr=integer_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- break;
- case 'R':
- result_header_ptr=real_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- break;
- default:
- result_header_ptr=string_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- break;
- }
- else
- if (((*left_header_ptr).type == 'I')
- && ((*right_header_ptr).type == 'R'))
- {
- tem_real_1=(double)
- *((*left_header_ptr).value_ptr.integer);
- free((char *)
- (*left_header_ptr).value_ptr.integer);
- if (((*left_header_ptr).value_ptr.real
- =(double *)
- malloc((unsigned) sizeof(double))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) left_header_ptr);
- free_value(right_header_ptr);
- }
- else
- {
- *((*left_header_ptr).value_ptr.real)
- =tem_real_1;
- (*left_header_ptr).type='R';
- result_header_ptr=real_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- }
- }
- else
- if (((*left_header_ptr).type == 'R')
- && ((*right_header_ptr).type == 'I'))
- {
- tem_real_1=(double)
- *((*right_header_ptr).value_ptr.integer);
- free((char *)
- (*right_header_ptr).value_ptr.integer);
- if (((*right_header_ptr).value_ptr.real
- =(double *)
- malloc((unsigned) sizeof(double))) == NULL)
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: out of memory ");
- printf("at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) right_header_ptr);
- free_value(left_header_ptr);
- }
- else
- {
- *((*right_header_ptr).value_ptr.real)
- =tem_real_1;
- (*right_header_ptr).type='R';
- result_header_ptr=real_comparison(
- left_header_ptr,operator,
- right_header_ptr);
- }
- }
- else
- {
- fatal_error=TRUE;
- result_header_ptr=NULL;
- printf("Fatal error: comparands differ ");
- printf("in type at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free_value(left_header_ptr);
- free_value(right_header_ptr);
- }
- if (! fatal_error)
- {
- free_value(left_header_ptr);
- free_value(right_header_ptr);
- }
- }
- else
- result_header_ptr=NULL;
- }
- }
- }
- return(result_header_ptr);
- }
-
- static void interpret_do(evaluate)
- int evaluate;
- {
- int condition_is_true;
- value_header_ptr expression_header_ptr;
- char while_char;
- long while_column_num;
- int while_eof;
- int while_index;
- long while_line_num;
-
- get_token();
- if (source_token[0] == ';')
- {
- do
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf("Fatal error: file ends before \"END;\" ");
- printf("corresponding to \"DO;\".\n");
- }
- else
- {
- if (strcmp(source_token,"END") != 0)
- interpret_statement(evaluate);
- }
- }
- while ((strcmp(source_token,"END") != 0)
- && (! fatal_error));
- if (! fatal_error)
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf("Fatal error: file ends where \";\" of \"END;\" ");
- printf("expected.\n");
- }
- else
- {
- if (source_token[0] != ';')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \";\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- }
- else
- if (strcmp(source_token,"WHILE") == 0)
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends where \"(\" of \"DO WHILE(\" expected.\n");
- }
- else
- if (source_token[0] == '(')
- {
- while_index=source_index;
- while_char=source_char;
- while_column_num=source_column_num;
- while_eof=source_eof;
- while_line_num=source_line_num;
- do
- {
- if (while_index != source_index)
- {
- source_index=while_index;
- source_char=source_buffer[source_index];
- }
- source_char=while_char;
- source_column_num=while_column_num;
- source_eof=while_eof;
- source_line_num=while_line_num;
- expression_header_ptr=interpret_expression(evaluate);
- if (! fatal_error)
- {
- if ((! evaluate)
- || ((*expression_header_ptr).type == 'B'))
- {
- get_token();
- if (source_token[0] == ')')
- {
- get_token();
- if (source_token[0] == ';')
- {
- if (evaluate)
- condition_is_true
- =*((*expression_header_ptr).value_ptr.boolean);
- else
- condition_is_true=FALSE;
- do
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends before \"END;\" ");
- printf(
- "corresponding to \"DO WHILE();\".\n");
- }
- else
- {
- if (strcmp(source_token,"END")
- != 0)
- interpret_statement(
- evaluate && condition_is_true);
- }
- }
- while ((strcmp(source_token,"END") != 0)
- && (! fatal_error));
- }
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends before \";\" of \"DO WHILE();\".\n");
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \";\" of \"DO WHILE();\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends before \")\" of \"DO WHILE()\".\n");
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \")\" of \"DO WHILE()\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: the expression preceding column %ld on line %d\n",
- source_column_num,source_line_num);
- printf(
- " should be Boolean but isn\'t.\n");
- }
- free_value(expression_header_ptr);
- }
- if (! fatal_error)
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf("Fatal error: file ends where \";\" ");
- printf("of \"END;\" expected.\n");
- }
- else
- {
- if (source_token[0] != ';')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \";\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- }
- while((! fatal_error)
- && (evaluate)
- && (condition_is_true));
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "\"(\" of \"DO WHILE(\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends before \"DO\" statement completed.\n");
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \";\" or \"WHILE\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void interpret_if(evaluate)
- int evaluate;
- {
- char else_char;
- long else_column_num;
- int else_eof;
- long else_line_num;
- int else_index;
- char else_token [256];
- value_header_ptr expression_header_ptr;
-
- expression_header_ptr=interpret_expression(evaluate);
- if (! fatal_error)
- {
- if ((! evaluate)
- || ((*expression_header_ptr).type == 'B'))
- {
- get_token();
- if (strcmp(source_token,"THEN") == 0)
- {
- get_token();
- if (evaluate)
- if (*((*expression_header_ptr).value_ptr.boolean))
- interpret_statement(TRUE);
- else
- interpret_statement(FALSE);
- else
- interpret_statement(FALSE);
- else_char=source_char;
- else_column_num=source_column_num;
- else_eof=source_eof;
- else_index=source_index;
- else_line_num=source_line_num;
- strcpy(else_token,source_token);
- get_token();
- if (strcmp(source_token,"ELSE") == 0)
- {
- get_token();
- if (evaluate)
- if (*((*expression_header_ptr).value_ptr.boolean))
- interpret_statement(FALSE);
- else
- interpret_statement(TRUE);
- else
- interpret_statement(FALSE);
- }
- else
- {
- if (else_index != source_index)
- {
- source_index=else_index;
- source_char=source_buffer[source_index];
- }
- source_char=else_char;
- source_column_num=else_column_num;
- source_eof=else_eof;
- source_line_num=else_line_num;
- strcpy(source_token,else_token);
- }
- }
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends where \"THEN\" expected.\n");
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \"THEN\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: the expression preceding column %ld on line %ld\n",
- source_column_num,source_line_num);
- printf(
- " is not a Boolean expression.\n");
- }
- free_value(expression_header_ptr);
- }
- return;
- }
-
- static void interpret_assignment(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- int comparison;
- value_header_ptr expression_header_ptr;
- int finished;
- queue_node_ptr new_queue_copy;
- variable_ptr new_variable_ptr;
- variable_ptr old_variable_ptr;
- queue_node_ptr queue_copy;
-
- expression_header_ptr=interpret_expression(evaluate);
- if (! fatal_error)
- {
- if (evaluate)
- {
- if (variable_head == NULL)
- if ((variable_head=(struct variable *)
- malloc((unsigned) sizeof(struct variable))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*variable_head).name
- =malloc((unsigned) (1+strlen(identifier)))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*variable_head).name,identifier);
- (*variable_head).subscripts=copy_of_queue(queue_head);
- if (! fatal_error)
- (*variable_head).variable_value_header_ptr
- =copy_of_arguments(expression_header_ptr);
- if (fatal_error)
- {
- free((*variable_head).name);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- (*variable_head).predecessor_ptr=NULL;
- (*variable_head).smaller_successor_ptr=NULL;
- (*variable_head).larger_successor_ptr=NULL;
- }
- }
- else
- {
- old_variable_ptr=variable_head;
- finished=FALSE;
- queue_copy=copy_of_queue(queue_head);
- do
- {
- comparison=variable_comparison(identifier,queue_copy,
- (*old_variable_ptr).name,
- (*old_variable_ptr).subscripts);
- if (comparison < 0)
- if ((*old_variable_ptr).smaller_successor_ptr == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,identifier);
- (*new_variable_ptr).subscripts=queue_copy;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =copy_of_arguments(expression_header_ptr);
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- smaller_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*old_variable_ptr).larger_successor_ptr
- == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,
- identifier);
- (*new_variable_ptr).subscripts=queue_copy;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =copy_of_arguments(
- expression_header_ptr);
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- larger_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).larger_successor_ptr;
- else
- {
- finished=TRUE;
- while (queue_copy != NULL)
- {
- new_queue_copy=(*queue_copy).next;
- free_value((*queue_copy).argument_header_ptr);
- free((char *) queue_copy);
- queue_copy=new_queue_copy;
- }
- free_value(
- (*old_variable_ptr).variable_value_header_ptr);
- (*old_variable_ptr).variable_value_header_ptr
- =copy_of_arguments(expression_header_ptr);
- }
- }
- while (! finished);
- }
- free_value(expression_header_ptr);
- }
- }
- if (! fatal_error)
- {
- get_token();
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends where \";\" expected.\n");
- }
- else
- {
- if (source_token[0] != ';')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \";\" expected at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- }
-
- static void perform_close(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- if (queue_head == NULL)
- {
- if (evaluate)
- fclose(stdin);
- }
- else
- if ((*queue_head).next == NULL)
- {
- if (evaluate)
- {
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- fclose(
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset));
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: argument to CLOSE is not a file pointer on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: extraneous arguments supplied to CLOSE on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void perform_clrscr(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- union REGS inreg;
- union REGS outreg;
-
- if (queue_head == NULL)
- {
- if (evaluate)
- {
- inreg.h.ah=(unsigned char) 15;
- int86(16,&inreg,&outreg);
- inreg.h.ah=(unsigned char) 0;
- inreg.h.al=outreg.h.al;
- int86(16,&inreg,&outreg);
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: extraneous arguments supplied to CLOSE on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void perform_print(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- register int char_index;
- unsigned char *char_ptr;
- FILE *file;
- int string_length;
-
- if (queue_head == NULL)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: first parameter to PRINT is missing on\n");
- printf(
- " line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- else
- {
- if (evaluate)
- {
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- {
- file=
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset);
- queue_head=(*queue_head).next;
- while (queue_head != NULL)
- {
- switch ((*((*queue_head).argument_header_ptr)).type)
- {
- case 'B':
- if (*((*((*queue_head).argument_header_ptr)).
- value_ptr.boolean))
- fprintf(file,"TRUE");
- else
- fprintf(file,"FALSE");
- break;
- case 'D':
- fprintf(file,"%p",(char far *)
- *((*((*queue_head).argument_header_ptr)).
- value_ptr.dataset));
- break;
- case 'I':
- fprintf(file,"%ld",
- *((*((*queue_head).argument_header_ptr)).
- value_ptr.integer));
- break;
- case 'R':
- fprintf(file,"%lG",
- *((*((*queue_head).argument_header_ptr)).
- value_ptr.real));
- break;
- default:
- char_ptr=(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).value;
- string_length
- =(*((*((*queue_head).argument_header_ptr)).
- value_ptr.string)).length;
- for (char_index=0; char_index < string_length;
- char_index++)
- {
- fputc((int) *char_ptr,file);
- char_ptr++;
- }
- break;
- }
- queue_head=(*queue_head).next;
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: first parameter to PRINT is not a file pointer on\n");
- printf(
- " line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- }
- }
- return;
- }
-
- static void perform_putcrlf(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- if (queue_head == NULL)
- {
- if (evaluate)
- printf("\n");
- }
- else
- if ((*queue_head).next == NULL)
- {
- if (evaluate)
- {
- if ((*((*queue_head).argument_header_ptr)).type == 'D')
- fprintf(
- *((*((*queue_head).argument_header_ptr)).value_ptr.dataset),
- "\n");
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: argument to PUTCRLF is not a file pointer on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- }
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: extraneous arguments supplied to PUTCRLF on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void perform_troff(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- if (queue_head == NULL)
- {
- if (evaluate)
- trace=FALSE;
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: extraneous arguments supplied to TROFF on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void perform_tron(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- if (queue_head == NULL)
- {
- if (evaluate)
- trace=TRUE;
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: extraneous arguments supplied to TRON on\n");
- printf(" line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- return;
- }
-
- static void interpret_procedure(evaluate,queue_head)
- int evaluate;
- queue_node_ptr queue_head;
- {
- if (strcmp(identifier,"CLOSE") == 0)
- perform_close(evaluate,queue_head);
- else if (strcmp(identifier,"CLRSCR") == 0)
- perform_clrscr(evaluate,queue_head);
- else if (strcmp(identifier,"PRINT") == 0)
- perform_print(evaluate,queue_head);
- else if (strcmp(identifier,"PUTCRLF") == 0)
- perform_putcrlf(evaluate,queue_head);
- else if (strcmp(identifier,"TROFF") == 0)
- perform_troff(evaluate,queue_head);
- else if (strcmp(identifier,"TRON") == 0)
- perform_tron(evaluate,queue_head);
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: unrecognized procedure \"%s\" at ",
- identifier);
- printf(
- "line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- return;
- }
-
- static void interpret_statement(evaluate)
- int evaluate;
- {
- queue_node_ptr new_queue_head;
- queue_node_ptr new_queue_tail;
- queue_node_ptr queue_head;
- queue_node_ptr queue_tail;
-
- if ((evaluate) && (trace))
- printf("[%ld]",source_line_num);
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf("Fatal error: end of file encountered where statement ");
- printf("expected.\n");
- }
- else
- if (strcmp(source_token,"DO") == 0)
- interpret_do(evaluate);
- else
- if (strcmp(source_token,"IF") == 0)
- interpret_if(evaluate);
- else
- {
- if (strcmp(source_token,";") != 0)
- {
- if (isalpha((int) source_token[0]))
- {
- queue_tail=NULL;
- queue_head=NULL;
- strcpy(identifier,source_token);
- get_token();
- if (source_token[0] == '(')
- {
- if ((queue_head=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node)))
- == NULL)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- queue_tail=queue_head;
- (*queue_head).next=NULL;
- (*queue_head).argument_header_ptr
- =interpret_expression(evaluate);
- }
- if (! fatal_error)
- get_token();
- while ((! fatal_error)
- && (! source_eof)
- && (source_token[0] != ')'))
- {
- if ((new_queue_tail=(queue_node_ptr)
- malloc((unsigned) sizeof(struct queue_node)))
- == NULL)
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: out of memory at line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- {
- (*new_queue_tail).next=NULL;
- (*queue_tail).next=new_queue_tail;
- queue_tail=new_queue_tail;
- (*new_queue_tail).argument_header_ptr
- =interpret_expression(evaluate);
- }
- if (! fatal_error)
- get_token();
- }
- if (! fatal_error)
- {
- if (source_token [0] == ')')
- get_token();
- }
- }
- if (! fatal_error)
- {
- if (source_token[0] == '=')
- interpret_assignment(evaluate,queue_head);
- else
- if (source_token[0] == ';')
- interpret_procedure(evaluate,queue_head);
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: file ends where \"=\" or \";\" expected.\n");
- }
- else
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: \"=\", or \";\" expected at line %ld,\n",
- source_line_num);
- printf(
- " column %ld.\n",source_column_num);
- }
- }
- while (queue_head != NULL)
- {
- new_queue_head=(*queue_head).next;
- free_value((*queue_head).argument_header_ptr);
- free((char *) queue_head);
- queue_head=new_queue_head;
- }
- }
- else
- if (source_token[0] == ' ')
- {
- fatal_error=TRUE;
- printf(
- "Fatal error: end of file encountered where statement expected.\n");
- }
- else
- {
- fatal_error=TRUE;
- printf("Fatal error: expected statement at ");
- printf(" line %ld, column %ld.\n",source_line_num,
- source_column_num);
- }
- }
- }
- return;
- }
-
- void set_boolean_variable(identifier,value)
- char *identifier;
- int value;
- {
- int comparison;
- char current_identifier [256];
- int finished;
- variable_ptr new_variable_ptr;
- variable_ptr old_variable_ptr;
-
- if (variable_head == NULL)
- if ((variable_head=(struct variable *)
- malloc((unsigned) sizeof(struct variable))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*variable_head).name
- =malloc((unsigned) (1+strlen(identifier)))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*variable_head).name,identifier);
- strupr((*variable_head).name);
- (*variable_head).subscripts=NULL;
- if (! fatal_error)
- (*variable_head).variable_value_header_ptr
- =new_boolean_header_ptr();
- if (fatal_error)
- {
- free((*variable_head).name);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- if (value)
- *((*((*variable_head).variable_value_header_ptr)).value_ptr.
- boolean)=TRUE;
- else
- *((*((*variable_head).variable_value_header_ptr)).value_ptr.
- boolean)=FALSE;
- (*variable_head).predecessor_ptr=NULL;
- (*variable_head).smaller_successor_ptr=NULL;
- (*variable_head).larger_successor_ptr=NULL;
- }
- }
- else
- {
- strcpy(current_identifier,identifier);
- strupr(current_identifier);
- old_variable_ptr=variable_head;
- finished=FALSE;
- do
- {
- comparison=variable_comparison(current_identifier,NULL,
- (*old_variable_ptr).name,
- (*old_variable_ptr).subscripts);
- if (comparison < 0)
- if ((*old_variable_ptr).smaller_successor_ptr == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_boolean_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- if (value)
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =TRUE;
- else
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =FALSE;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- smaller_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*old_variable_ptr).larger_successor_ptr
- == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,
- current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_boolean_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- if (value)
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =TRUE;
- else
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =FALSE;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- larger_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).larger_successor_ptr;
- else
- {
- finished=TRUE;
- free_value(
- (*old_variable_ptr).variable_value_header_ptr);
- (*old_variable_ptr).variable_value_header_ptr
- =new_boolean_header_ptr();
- if (! fatal_error)
- {
- if (value)
- *((*((*old_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =TRUE;
- else
- *((*((*old_variable_ptr).
- variable_value_header_ptr)).value_ptr.boolean)
- =FALSE;
- }
- }
- }
- while (! finished);
- }
- }
-
- void set_integer_variable(identifier,value)
- char *identifier;
- long value;
- {
- int comparison;
- char current_identifier [256];
- int finished;
- variable_ptr new_variable_ptr;
- variable_ptr old_variable_ptr;
-
- if (variable_head == NULL)
- if ((variable_head=(struct variable *)
- malloc((unsigned) sizeof(struct variable))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*variable_head).name
- =malloc((unsigned) (1+strlen(identifier)))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*variable_head).name,identifier);
- strupr((*variable_head).name);
- (*variable_head).subscripts=NULL;
- if (! fatal_error)
- (*variable_head).variable_value_header_ptr
- =new_integer_header_ptr();
- if (fatal_error)
- {
- free((*variable_head).name);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- *((*((*variable_head).variable_value_header_ptr)).value_ptr.
- integer)=value;
- (*variable_head).predecessor_ptr=NULL;
- (*variable_head).smaller_successor_ptr=NULL;
- (*variable_head).larger_successor_ptr=NULL;
- }
- }
- else
- {
- strcpy(current_identifier,identifier);
- strupr(current_identifier);
- old_variable_ptr=variable_head;
- finished=FALSE;
- do
- {
- comparison=variable_comparison(current_identifier,NULL,
- (*old_variable_ptr).name,
- (*old_variable_ptr).subscripts);
- if (comparison < 0)
- if ((*old_variable_ptr).smaller_successor_ptr == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_integer_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.integer)
- =value;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- smaller_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*old_variable_ptr).larger_successor_ptr
- == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,
- current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_integer_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.integer)
- =value;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- larger_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).larger_successor_ptr;
- else
- {
- finished=TRUE;
- free_value(
- (*old_variable_ptr).variable_value_header_ptr);
- (*old_variable_ptr).variable_value_header_ptr
- =new_integer_header_ptr();
- if (! fatal_error)
- *((*((*old_variable_ptr).
- variable_value_header_ptr)).value_ptr.integer)=value;
- }
- }
- while (! finished);
- }
- }
-
- void set_real_variable(identifier,value)
- char *identifier;
- double value;
- {
- int comparison;
- char current_identifier [256];
- int finished;
- variable_ptr new_variable_ptr;
- variable_ptr old_variable_ptr;
-
- if (variable_head == NULL)
- if ((variable_head=(struct variable *)
- malloc((unsigned) sizeof(struct variable))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*variable_head).name
- =malloc((unsigned) (1+strlen(identifier)))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*variable_head).name,identifier);
- strupr((*variable_head).name);
- (*variable_head).subscripts=NULL;
- if (! fatal_error)
- (*variable_head).variable_value_header_ptr
- =new_real_header_ptr();
- if (fatal_error)
- {
- free((*variable_head).name);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- *((*((*variable_head).variable_value_header_ptr)).value_ptr.
- real)=value;
- (*variable_head).predecessor_ptr=NULL;
- (*variable_head).smaller_successor_ptr=NULL;
- (*variable_head).larger_successor_ptr=NULL;
- }
- }
- else
- {
- strcpy(current_identifier,identifier);
- strupr(current_identifier);
- old_variable_ptr=variable_head;
- finished=FALSE;
- do
- {
- comparison=variable_comparison(current_identifier,NULL,
- (*old_variable_ptr).name,
- (*old_variable_ptr).subscripts);
- if (comparison < 0)
- if ((*old_variable_ptr).smaller_successor_ptr == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_real_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.real)
- =value;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- smaller_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*old_variable_ptr).larger_successor_ptr
- == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,
- current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_real_header_ptr();
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- *((*((*new_variable_ptr).
- variable_value_header_ptr)).value_ptr.real)
- =value;
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- larger_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).larger_successor_ptr;
- else
- {
- finished=TRUE;
- free_value(
- (*old_variable_ptr).variable_value_header_ptr);
- (*old_variable_ptr).variable_value_header_ptr
- =new_real_header_ptr();
- if (! fatal_error)
- *((*((*old_variable_ptr).
- variable_value_header_ptr)).value_ptr.real)=value;
- }
- }
- while (! finished);
- }
- }
-
- void set_string_variable(identifier,value)
- char *identifier;
- char *value;
- {
- int comparison;
- char current_identifier [256];
- int finished;
- variable_ptr new_variable_ptr;
- variable_ptr old_variable_ptr;
-
- if (variable_head == NULL)
- if ((variable_head=(struct variable *)
- malloc((unsigned) sizeof(struct variable))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*variable_head).name
- =malloc((unsigned) (1+strlen(identifier)))) == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*variable_head).name,identifier);
- strupr((*variable_head).name);
- (*variable_head).subscripts=NULL;
- if (! fatal_error)
- (*variable_head).variable_value_header_ptr
- =new_string_header_ptr(strlen(value));
- if (fatal_error)
- {
- free((*variable_head).name);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((char *)
- (*((*((*variable_head).variable_value_header_ptr)).value_ptr.string)).value,
- value);
- (*variable_head).predecessor_ptr=NULL;
- (*variable_head).smaller_successor_ptr=NULL;
- (*variable_head).larger_successor_ptr=NULL;
- }
- }
- else
- {
- strcpy(current_identifier,identifier);
- strupr(current_identifier);
- old_variable_ptr=variable_head;
- finished=FALSE;
- do
- {
- comparison=variable_comparison(current_identifier,NULL,
- (*old_variable_ptr).name,
- (*old_variable_ptr).subscripts);
- if (comparison < 0)
- if ((*old_variable_ptr).smaller_successor_ptr == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_string_header_ptr(strlen(value));
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- strcpy((char *)
- (*((*((*new_variable_ptr).
- variable_value_header_ptr)).
- value_ptr.string)).value,
- value);
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- smaller_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).smaller_successor_ptr;
- else
- if (comparison > 0)
- if ((*old_variable_ptr).larger_successor_ptr
- == NULL)
- {
- if ((new_variable_ptr=(struct variable *)
- malloc((unsigned) sizeof(struct variable)))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- }
- else
- if (((*new_variable_ptr).name
- =malloc((unsigned) (1+strlen(current_identifier))))
- == NULL)
- {
- fatal_error=TRUE;
- printf("Fatal error: out of memory at ");
- printf("line %ld, column %ld.\n",
- source_line_num,source_column_num);
- free((char *) variable_head);
- variable_head=NULL;
- }
- else
- {
- strcpy((*new_variable_ptr).name,
- current_identifier);
- (*new_variable_ptr).subscripts=NULL;
- if (! fatal_error)
- (*new_variable_ptr).
- variable_value_header_ptr
- =new_string_header_ptr(strlen(value));
- if (fatal_error)
- {
- free((*new_variable_ptr).name);
- free((char *) new_variable_ptr);
- new_variable_ptr=NULL;
- }
- else
- {
- strcpy((char *)
- (*((*((*new_variable_ptr).
- variable_value_header_ptr)).
- value_ptr.string)).value,
- value);
- (*new_variable_ptr).predecessor_ptr
- =old_variable_ptr;
- (*new_variable_ptr).
- smaller_successor_ptr=NULL;
- (*new_variable_ptr).
- larger_successor_ptr=NULL;
- (*old_variable_ptr).
- larger_successor_ptr
- =new_variable_ptr;
- }
- }
- finished=TRUE;
- }
- else
- old_variable_ptr
- =(*old_variable_ptr).larger_successor_ptr;
- else
- {
- finished=TRUE;
- free_value(
- (*old_variable_ptr).variable_value_header_ptr);
- (*old_variable_ptr).variable_value_header_ptr
- =new_string_header_ptr(strlen(value));
- if (! fatal_error)
- strcpy((char *)
- (*((*((*old_variable_ptr).
- variable_value_header_ptr)).
- value_ptr.string)).value,
- value);
- }
- }
- while (! finished);
- }
- }
-
- void get_boolean_variable(identifier,value,fatal_error)
- char *identifier;
- int *value;
- int *fatal_error;
- {
- static value_header_ptr result_header_ptr;
- static char variable_name [256];
-
- strcpy(&variable_name[0],identifier);
- strupr(&variable_name[0]);
- result_header_ptr=variable_header_ptr(variable_name,TRUE,NULL);
- if ((*result_header_ptr).type == 'B')
- *value=*((*result_header_ptr).value_ptr.boolean);
- else
- {
- *fatal_error=TRUE;
- printf(
- "\007 Fatal error: the variable %s is no longer boolean.\n",
- identifier);
- }
- free_value(result_header_ptr);
- return;
- }
-
- void get_integer_variable(identifier,value,fatal_error)
- char *identifier;
- long *value;
- int *fatal_error;
- {
- static value_header_ptr result_header_ptr;
- static char variable_name [256];
-
- strcpy(&variable_name[0],identifier);
- strupr(&variable_name[0]);
- result_header_ptr=variable_header_ptr(variable_name,TRUE,NULL);
- if ((*result_header_ptr).type == 'I')
- *value=*((*result_header_ptr).value_ptr.integer);
- else
- {
- *fatal_error=TRUE;
- printf(
- "\007 Fatal error: the variable %s is no longer integer.\n",
- identifier);
- }
- free_value(result_header_ptr);
- return;
- }
-
- void get_real_variable(identifier,value,fatal_error)
- char *identifier;
- double *value;
- int *fatal_error;
- {
- static value_header_ptr result_header_ptr;
- static char variable_name [256];
-
- strcpy(&variable_name[0],identifier);
- strupr(&variable_name[0]);
- result_header_ptr=variable_header_ptr(variable_name,TRUE,NULL);
- if ((*result_header_ptr).type == 'R')
- *value=*((*result_header_ptr).value_ptr.real);
- else
- {
- *fatal_error=TRUE;
- printf(
- "\007 Fatal error: the variable %s is no longer real.\n",
- identifier);
- }
- free_value(result_header_ptr);
- return;
- }
-
- void get_string_variable(identifier,value,length,fatal_error)
- char *identifier;
- char *value;
- int length;
- int *fatal_error;
- {
- register int char_index;
- static char *char_ptr_1;
- static char *char_ptr_2;
- static value_header_ptr result_header_ptr;
- static char variable_name [256];
-
- strcpy(&variable_name[0],identifier);
- strupr(&variable_name[0]);
- result_header_ptr=variable_header_ptr(variable_name,TRUE,NULL);
- if ((*result_header_ptr).type == 'S')
- {
- char_index=1;
- char_ptr_1=(char *) (*((*result_header_ptr).value_ptr.string)).value;
- char_ptr_2=value;
- while ((char_index
- <= (*((*result_header_ptr).value_ptr.string)).length)
- && (char_index <= length))
- {
- if (*char_ptr_1 == (unsigned char) 0)
- *char_ptr_2=' ';
- else
- *char_ptr_2=(char) *char_ptr_1;
- char_ptr_1++;
- char_ptr_2++;
- char_index++;
- }
- *char_ptr_2='\0';
- }
- else
- {
- *fatal_error=TRUE;
- printf(
- "\007 Fatal error: the variable %s is no longer string.\n",
- identifier);
- }
- free_value(result_header_ptr);
- return;
- }
-