⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs274ngc_pre.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 3 页
字号:
   If any of the following errors occur, this returns the error code shown.   Otherwise, this returns INTERP_OK.   1. _setup.tool_max is larger than CANON_TOOL_MAX: NCE_TOOL_MAX_TOO_LARGESide Effects:   _setup.tool_table[] is modified.Called By:   Interp::synch   external programsThis function calls the canonical interface function GET_EXTERNAL_TOOL_TABLEto load the whole tool table into the _setup.The CANON_TOOL_MAX is an upper limit for this software. The_setup.tool_max is intended to be set for a particular machine.*/int Interp::load_tool_table(){  static char name[] = "Interp::load_tool_table";  int n;  CHK((_setup.tool_max > CANON_TOOL_MAX), NCE_TOOL_MAX_TOO_LARGE);  for (n = 0; n <= _setup.tool_max; n++) {    _setup.tool_table[n] = GET_EXTERNAL_TOOL_TABLE(n);  }  for (; n <= CANON_TOOL_MAX; n++) {    _setup.tool_table[n].id = 0;    _setup.tool_table[n].length = 0;    _setup.tool_table[n].diameter = 0;  }  return INTERP_OK;}/***********************************************************************//*! Interp::openReturned Value: int   If any of the following errors occur, this returns the error code shown.   Otherwise it returns INTERP_OK.   1. A file is already open: NCE_A_FILE_IS_ALREADY_OPEN   2. The name of the file is too long: NCE_FILE_NAME_TOO_LONG   3. The file cannot be opened: NCE_UNABLE_TO_OPEN_FILESide Effects: See belowCalled By: external programsThe file is opened for reading and _setup.file_pointer is set.The file name is copied into _setup.filename.The _setup.sequence_number, is set to zero.Interp::reset() is called, changing several more _setup attributes.The manual [NCMS, page 3] discusses the use of the "%" character at thebeginning of a "tape". It is not clear whether it is intended thatevery NC-code file should begin with that character.In the following, "uses percents" means the first non-blank lineof the file must consist of nothing but the percent sign, with optionalleading and trailing white space, and there must be a second lineof the same sort later on in the file. If a file uses percents,execution stops at the second percent line. Any lines after thesecond percent line are ignored.In this interpreter (recalling that M2 and M30 always ends execution):1. If execution of a file is ended by M2 or M30 (not necessarily onthe last line of the file), then it is optional that the fileuses percents.2. If execution of a file is not ended by M2 or M30, then it isrequired that the file uses percents.If the file being opened uses percents, this function turns on the_setup.percent flag, reads any initial blank lines, and reads thefirst line with the "%". If not, after reading enough to determinethat, this function puts the file pointer back at the beginning of thefile.*/int Interp::open(const char *filename) //!< string: the name of the input NC-program file{  static char name[] = "Interp::open";  char *line;  int index;  int length;  CHK((_setup.file_pointer != NULL), NCE_A_FILE_IS_ALREADY_OPEN);  CHK((strlen(filename) > (LINELEN - 1)), NCE_FILE_NAME_TOO_LONG);  _setup.file_pointer = fopen(filename, "r");  CHK((_setup.file_pointer == NULL), NCE_UNABLE_TO_OPEN_FILE);  line = _setup.linetext;  for (index = -1; index == -1;) {      /* skip blank lines */    CHK((fgets(line, LINELEN, _setup.file_pointer) ==         NULL), NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN);    length = strlen(line);    if (length == (LINELEN - 1)) {   // line is too long. need to finish reading the line to recover      for (; fgetc(_setup.file_pointer) != '\n';);      // could look for EOF      ERM(NCE_COMMAND_TOO_LONG);    }    for (index = (length - 1);  // index set on last char         (index >= 0) && (isspace(line[index])); index--);  }  if (line[index] == '%') {    for (index--; (index >= 0) && (isspace(line[index])); index--);    if (index == -1) {      _setup.percent_flag = ON;      _setup.sequence_number = 1;       // We have already read the first line      // and we are not going back to it.    } else {      fseek(_setup.file_pointer, 0, SEEK_SET);      _setup.percent_flag = OFF;      _setup.sequence_number = 0;       // Going back to line 0    }  } else {    fseek(_setup.file_pointer, 0, SEEK_SET);    _setup.percent_flag = OFF;    _setup.sequence_number = 0; // Going back to line 0  }  strcpy(_setup.filename, filename);  reset();  return INTERP_OK;}/***********************************************************************//*! Interp::readReturned Value: int   If any of the following errors occur, this returns the error code shown.   Otherwise, this returns:       a. INTERP_ENDFILE if the only non-white character on the line is %,       b. INTERP_EXECUTE_FINISH if the first character of the          close_and_downcased line is a slash, and       c. INTERP_OK otherwise.   1. The command and_setup.file_pointer are both NULL: INTERP_FILE_NOT_OPEN   2. The probe_flag is ON but the HME command queue is not empty:      NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING   3. If read_text (which gets a line of NC code from file) or parse_line     (which parses the line) returns an error code, this returns that code.Side Effects:   _setup.sequence_number is incremented.   The _setup.block1 is filled with data.Called By: external programsThis reads a line of NC-code from the command string or, (if thecommand string is NULL) from the currently open file. The_setup.line_length will be set by read_text. This will be zero if theline is blank or consists of nothing but a slash. If the length is notzero, this parses the line into the _setup.block1.*/int Interp::read(const char *command)  //!< may be NULL or a string to read{  static char name[] = "Interp::read";  int status;  int read_status;  if (_setup.probe_flag == ON) {    CHK((GET_EXTERNAL_QUEUE_EMPTY() == 0),        NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING);    set_probe_data(&_setup);    _setup.probe_flag = OFF;  }  CHK(((command == NULL) && (_setup.file_pointer == NULL)),      INTERP_FILE_NOT_OPEN);  if(_setup.file_pointer)  {     _setup.block1.offset = ftell(_setup.file_pointer);  }  read_status =    read_text(command, _setup.file_pointer, _setup.linetext,              _setup.blocktext, &_setup.line_length);  if(command)logDebug("%s:[cmd]:|%s|", name, command);  else logDebug("%s:|%s|", name, _setup.linetext);  if ((read_status == INTERP_EXECUTE_FINISH)      || (read_status == INTERP_OK)) {    if (_setup.line_length != 0) {      CHP(parse_line(_setup.blocktext, &(_setup.block1), &_setup));    }    else // Blank line (zero length)    {          /* RUM - this case reached when the block delete '/' character              is used, or READ_FULL_COMMENT is OFF and a comment is the             only content of a line.              If a block o-type is in effect, block->o_number needs to be              incremented to allow o-extensions to work.              Note that the the block is 'refreshed' by init_block(),             not created new, so this is a legal operation on block1. */        if (_setup.block1.o_type != O_none)        {            // Clear o_type, this isn't line isn't a command...            _setup.block1.o_type = 0;            // increment o_number            _setup.block1.o_number++;        }    }  } else if (read_status == INTERP_ENDFILE);  else    ERP(read_status);  return read_status;}/***********************************************************************//*! Interp::resetReturned Value: int (INTERP_OK)Side Effects: See belowCalled By:   external programs   Interp::close   Interp::exit   Interp::openThis function resets the parts of the _setup model having to do withreading and interpreting one line. It does not affect the parts of themodel dealing with a file being open; Interp::open and Interp::closedo that.There is a hierarchy of resetting the interpreter. Each of the followingcalls does everything the ones above it do.Interp::reset()Interp::close()Interp::init()In addition, Interp::synch and Interp::restore_parameters (both ofwhich are called by Interp::init) change the model.*/int Interp::reset(){  _setup.linetext[0] = 0;  _setup.blocktext[0] = 0;  _setup.line_length = 0;  // initialization stuff for subroutines and control structures  _setup.call_level = 0;  _setup.defining_sub = 0;  _setup.skipping_o = 0;  _setup.oword_labels = 0;  return INTERP_OK;}/***********************************************************************//*! Interp::restore_parametersReturned Value:  If any of the following errors occur, this returns the error code shown.  Otherwise it returns INTERP_OK.  1. The parameter file cannot be opened for reading: NCE_UNABLE_TO_OPEN_FILE  2. A parameter index is out of range: NCE_PARAMETER_NUMBER_OUT_OF_RANGE  3. A required parameter is missing from the file:     NCE_REQUIRED_PARAMETER_MISSING  4. The parameter file is not in increasing order:     NCE_PARAMETER_FILE_OUT_OF_ORDERSide Effects: See belowCalled By:  external programs  Interp::initThis function restores the parameters from a file, modifying theparameters array. Usually parameters is _setup.parameters. The filecontains lines of the form:<variable number> <value>e.g.5161 10.456The variable numbers must be in increasing order, and certainparameters must be included, as given in the _required_parametersarray. These are the axis offsets, the origin index (5220), and ninesets of origin offsets. Any parameter not given a value in the filehas its value set to zero.*/int Interp::restore_parameters(const char *filename)   //!< name of parameter file to read  {  static char name[] = "Interp::restore_parameters";  FILE *infile;  char line[256];  int variable;  double value;  int required;                 // number of next required parameter  int index;                    // index into _required_parameters  double *pars;                 // short name for _setup.parameters  int k;  // open original for reading  infile = fopen(filename, "r");  CHK((infile == NULL), NCE_UNABLE_TO_OPEN_FILE);  pars = _setup.parameters;  k = 0;  index = 0;  required = _required_parameters[index++];  while (feof(infile) == 0) {    if (fgets(line, 256, infile) == NULL) {      break;    }    // try for a variable-value match in the file    if (sscanf(line, "%d %lf", &variable, &value) == 2) {      CHK(((variable <= 0)           || (variable >= RS274NGC_MAX_PARAMETERS)),          NCE_PARAMETER_NUMBER_OUT_OF_RANGE);      for (; k < RS274NGC_MAX_PARAMETERS; k++) {        if (k > variable)          ERM(NCE_PARAMETER_FILE_OUT_OF_ORDER);        else if (k == variable) {          pars[k] = value;          if (k == required)            required = _required_parameters[index++];          k++;          break;        } else                  // if (k < variable)        {          if (k == required)            ERM(NCE_REQUIRED_PARAMETER_MISSING);          else            pars[k] = 0;        }      }    }  }  fclose(infile);  CHK((required != RS274NGC_MAX_PARAMETERS), NCE_REQUIRED_PARAMETER_MISSING);  for (; k < RS274NGC_MAX_PARAMETERS; k++) {    pars[k] = 0;  }  return INTERP_OK;}/***********************************************************************//*! Interp::save_parametersReturned Value:  If any of the following errors occur, this returns the error code shown.  Otherwise it returns INTERP_OK.  1. The existing file cannot be renamed:  NCE_CANNOT_CREATE_BACKUP_FILE  2. The renamed file cannot be opened to read: NCE_CANNOT_OPEN_BACKUP_FILE  3. The new file cannot be opened to write: NCE_CANNOT_OPEN_VARIABLE_FILE  4. A parameter index is out of range: NCE_PARAMETER_NUMBER_OUT_OF_RANGE  5. The renamed file is out of order: NCE_PARAMETER_FILE_OUT_OF_ORDERSide Effects: See belowCalled By:   external programs   Interp::exitA file containing variable-value assignments is updated. The oldversion of the file is saved under a different name.  For eachvariable-value pair in the old file, a line is written in the new filegiving the current value of the variable.  File lines have the form:<variable number> <value>e.g.5161 10.456If a required parameter is missing from the input file, this does notcomplain, but does write it in the output file.*/int Interp::save_parameters(const char *filename,      //!< name of file to write                             const double parameters[]) //!< parameters to save   {  static char name[] = "Interp::save_parameters";  FILE *infile;  FILE *outfile;  char line[256];  int variable;  double value;  int required;                 // number of next required parameter  int index;                    // index into _required_parameters  int k;  // rename as .bak

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -