📄 varable.cpp
字号:
/********************************************************************** * File: varable.c (Formerly variable.c) * Description: Initialization and setting of VARIABLEs. * Author: Ray Smith * Created: Fri Feb 22 16:22:34 GMT 1991 * * (C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. * **********************************************************************/#include "mfcpch.h" //precompiled headers#include <stdio.h>#include <string.h>#include <stdlib.h>#include "tprintf.h"//#include "ipeerr.h"#include "varable.h"#include "scanutils.h"#define PLUS '+' //flag states#define MINUS '-'#define EQUAL '='CLISTIZE (INT_VARIABLE)CLISTIZE (BOOL_VARIABLE) CLISTIZE (STRING_VARIABLE) CLISTIZE (double_VARIABLE)INT_VAR_FROMINT_VARIABLE::copy;INT_VARIABLE_CLISTINT_VARIABLE::head; //global definitionINT_VAR_TOINT_VARIABLE::replace;BOOL_VAR_FROMBOOL_VARIABLE::copy;BOOL_VARIABLE_CLISTBOOL_VARIABLE::head; //global definitionBOOL_VAR_TOBOOL_VARIABLE::replace;STRING_VAR_FROMSTRING_VARIABLE::copy;STRING_VARIABLE_CLISTSTRING_VARIABLE::head; //global definitionSTRING_VAR_TOSTRING_VARIABLE::replace;double_VAR_FROMdouble_VARIABLE::copy;double_VARIABLE_CLISTdouble_VARIABLE::head; //global definitiondouble_VAR_TOdouble_VARIABLE::replace;/********************************************************************** * INT_VAR_FROM::INT_VAR_FROM * * Constructor to copy the list to a temporary location while the * list head gets constructed. **********************************************************************/INT_VAR_FROM::INT_VAR_FROM() { //constructor INT_VARIABLE_C_IT start_it = &INT_VARIABLE::head; INT_VARIABLE_C_IT end_it = &INT_VARIABLE::head; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); //move to copy list.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * INT_VAR_TO::INT_VAR_TO * * Constructor to copy the list back to its rightful place. **********************************************************************/INT_VAR_TO::INT_VAR_TO() { //constructor INT_VARIABLE_C_IT start_it = &INT_VARIABLE::copy.list; INT_VARIABLE_C_IT end_it = &INT_VARIABLE::copy.list; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); INT_VARIABLE::head.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * INT_VARIABLE::INT_VARIABLE * * Constructor for INT_VARIABLE. Add the variable to the static list. **********************************************************************/INT_VARIABLE::INT_VARIABLE( //constructor INT32 v, //the variable const char *vname, //of variable const char *comment //info on variable ) { INT_VARIABLE_C_IT it = &head; //list iterator //tprintf("Constructing %s\n",vname); set_value(v); //set the value name = vname; //strings must be static info = comment; it.add_before_stay_put (this); //add it to stack}INT_VARIABLE::~INT_VARIABLE ( //constructor) { INT_VARIABLE_C_IT it = &head; //list iterator for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) if (it.data () == this) it.extract ();}/********************************************************************** * INT_VARIABLE::get_head * * Get the head of the list of the variables. **********************************************************************/INT_VARIABLE_CLIST *INT_VARIABLE::get_head() { //access to static return &head;}/********************************************************************** * INT_VARIABLE::print * * Print the entire list of INT_VARIABLEs. **********************************************************************/void INT_VARIABLE::print( //print full list FILE *fp //file to print on ) { INT_VARIABLE_C_IT it = &head; //list iterator INT_VARIABLE *elt; //current element if (fp == stdout) { tprintf ("#Variables of type INT_VARIABLE:\n"); for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { elt = it.data (); tprintf ("%s %d #%s\n", elt->name, elt->value, elt->info); } } else { fprintf (fp, "#Variables of type INT_VARIABLE:\n"); for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { elt = it.data (); fprintf (fp, "%s " INT32FORMAT " #%s\n", elt->name, elt->value, elt->info); } }}/********************************************************************** * BOOL_VAR_FROM::BOOL_VAR_FROM * * Constructor to copy the list to a temporary location while the * list head gets constructed. **********************************************************************/BOOL_VAR_FROM::BOOL_VAR_FROM() { //constructor BOOL_VARIABLE_C_IT start_it = &BOOL_VARIABLE::head; BOOL_VARIABLE_C_IT end_it = &BOOL_VARIABLE::head; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); //move to copy list.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * BOOL_VAR_TO::BOOL_VAR_TO * * Constructor to copy the list back to its rightful place. **********************************************************************/BOOL_VAR_TO::BOOL_VAR_TO() { //constructor BOOL_VARIABLE_C_IT start_it = &BOOL_VARIABLE::copy.list; BOOL_VARIABLE_C_IT end_it = &BOOL_VARIABLE::copy.list; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); BOOL_VARIABLE::head.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * BOOL_VARIABLE::BOOL_VARIABLE * * Constructor for BOOL_VARIABLE. Add the variable to the static list. **********************************************************************/BOOL_VARIABLE::BOOL_VARIABLE( //constructor BOOL8 v, //the variable const char *vname, //of variable const char *comment //info on variable ) { BOOL_VARIABLE_C_IT it = &head; //list iterator //tprintf("Constructing %s\n",vname); set_value(v); //set the value name = vname; //strings must be static info = comment; it.add_before_stay_put (this); //add it to stack}/********************************************************************** * BOOL_VARIABLE::BOOL_VARIABLE * * Constructor for BOOL_VARIABLE. Add the variable to the static list. **********************************************************************/BOOL_VARIABLE::~BOOL_VARIABLE () { BOOL_VARIABLE_C_IT it = &head; //list iterator for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) if (it.data () == this) it.extract ();}/********************************************************************** * BOOL_VARIABLE::get_head * * Get the head of the list of the variables. **********************************************************************/BOOL_VARIABLE_CLIST *BOOL_VARIABLE::get_head() { //access to static return &head;}/********************************************************************** * BOOL_VARIABLE::print * * Print the entire list of BOOL_VARIABLEs. **********************************************************************/void BOOL_VARIABLE::print( //print full list FILE *fp //file to print on ) { BOOL_VARIABLE_C_IT it = &head; //list iterator BOOL_VARIABLE *elt; //current element if (fp == stdout) { tprintf ("#Variables of type BOOL_VARIABLE:\n"); for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { elt = it.data (); tprintf ("%s %c #%s\n", elt->name, elt->value ? 'T' : 'F', elt->info); } } else { fprintf (fp, "#Variables of type BOOL_VARIABLE:\n"); for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { elt = it.data (); fprintf (fp, "%s %c #%s\n", elt->name, elt->value ? 'T' : 'F', elt->info); } }}/********************************************************************** * STRING_VAR_FROM::STRING_VAR_FROM * * Constructor to copy the list to a temporary location while the * list head gets constructed. **********************************************************************/STRING_VAR_FROM::STRING_VAR_FROM() { //constructor STRING_VARIABLE_C_IT start_it = &STRING_VARIABLE::head; STRING_VARIABLE_C_IT end_it = &STRING_VARIABLE::head; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); //move to copy list.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * STRING_VAR_TO::STRING_VAR_TO * * Constructor to copy the list back to its rightful place. **********************************************************************/STRING_VAR_TO::STRING_VAR_TO() { //constructor STRING_VARIABLE_C_IT start_it = &STRING_VARIABLE::copy.list; STRING_VARIABLE_C_IT end_it = &STRING_VARIABLE::copy.list; if (!start_it.empty ()) { while (!end_it.at_last ()) end_it.forward (); STRING_VARIABLE::head.assign_to_sublist (&start_it, &end_it); }}/********************************************************************** * STRING_VARIABLE::STRING_VARIABLE * * Constructor for STRING_VARIABLE. Add the variable to the static list. **********************************************************************/STRING_VARIABLE::STRING_VARIABLE ( //constructorconst char *v, //the variableconst char *vname, //of variableconst char *comment //info on variable):value(v) { //list iterator STRING_VARIABLE_C_IT it = &head; //tprintf("Constructing %s\n",vname); name = vname; //strings must be static info = comment; it.add_before_stay_put (this); //add it to stack}/**********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -