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

📄 interp_read.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 5 页
字号:
/********************************************************************* Description: interp_read.cc**   Derived from a work by Thomas Kramer** Author:* License: GPL Version 2* System: Linux*    * Copyright (c) 2004 All rights reserved.** Last change:* $Revision: 1.10 $* $Author: alex_joni $* $Date: 2006/03/20 21:15:40 $********************************************************************/#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#include <sys/types.h>#include <sys/stat.h>#include "rs274ngc.hh"#include "rs274ngc_return.hh"#include "interp_internal.hh"/****************************************************************************//*! read_aReturned Value: int   If read_real_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character read is not a:      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED   2. An a_coordinate has already been inserted in the block:      NCE_MULTIPLE_A_WORDS_ON_ONE_LINE.   3. A values are not allowed: NCE_CANNOT_USE_A_WORD.Side effects:   counter is reset.   The a_flag in the block is turned on.   An a_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'a', indicating an a_coordinatesetting. The function reads characters which tell how to set thecoordinate, up to the start of the next item or the end of the line.The counter is then set to point to the character following.The value may be a real number or something that evaluates to areal number, so read_real_value is used to read it. Parametersmay be involved.If the AA compiler flag is defined, the a_flag in the block is turnedon and the a_number in the block is set to the value read. If theAA flag is not defined, (i) if the AXIS_ERROR flag is defined, that meansA values are not allowed, and an error value is returned, (ii) if theAXIS_ERROR flag is not defined, nothing is done.*/int Interp::read_a(char *line,   //!< string: line of RS274/NGC code being processed                  int *counter, //!< pointer to a counter for position on the line                   block_pointer block,  //!< pointer to a block being filled from the line                   double *parameters)   //!< array of system parameters                    {  static char name[] = "read_a";  double value;  int status;  CHK((line[*counter] != 'a'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  *counter = (*counter + 1);  CHK((block->a_flag != OFF), NCE_MULTIPLE_A_WORDS_ON_ONE_LINE);  CHP(read_real_value(line, counter, &value, parameters));  block->a_flag = ON;  block->a_number = value;  return INTERP_OK;}/****************************************************************************//*! read_atanReturned Value: int   If read_real_expression returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character to read is not a slash:      NCE_SLASH_MISSING_AFTER_FIRST_ATAN_ARGUMENT   2. The second character to read is not a left bracket:      NCE_LEFT_BRACKET_MISSING_AFTER_SLASH_WITH_ATANSide effects:   The computed value is put into what double_ptr points at.   The counter is reset to point to the first character after the   characters which make up the value.Called by:   read_unaryWhen this function is called, the characters "atan" and the firstargument have already been read, and the value of the first argumentis stored in double_ptr.  This function attempts to read a slash andthe second argument to the atan function, starting at the index givenby the counter and then to compute the value of the atan operationapplied to the two arguments.  The computed value is inserted intowhat double_ptr points at.The computed value is in the range from -180 degrees to +180 degrees.The range is not specified in the RS274/NGC manual [NCMS, page 51],although using degrees (not radians) is specified.*/int Interp::read_atan(char *line,        //!< string: line of RS274/NGC code being processed                     int *counter,      //!< pointer to a counter for position on line                          double *double_ptr,        //!< pointer to double to be read                                       double *parameters)        //!< array of system parameters                    {  static char name[] = "read_atan";  double argument2;  int status;  CHK((line[*counter] != '/'), NCE_SLASH_MISSING_AFTER_FIRST_ATAN_ARGUMENT);  *counter = (*counter + 1);  CHK((line[*counter] != '['),      NCE_LEFT_BRACKET_MISSING_AFTER_SLASH_WITH_ATAN);  CHP(read_real_expression(line, counter, &argument2, parameters));  *double_ptr = atan2(*double_ptr, argument2);  /* value in radians */  *double_ptr = ((*double_ptr * 180.0) / M_PIl);   /* convert to degrees */  return INTERP_OK;}/****************************************************************************//*! read_bReturned Value: int   If read_real_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character read is not b:      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED   2. A b_coordinate has already been inserted in the block:      NCE_MULTIPLE_B_WORDS_ON_ONE_LINE.   3. B values are not allowed: NCE_CANNOT_USE_B_WORDSide effects:   counter is reset.   The b_flag in the block is turned on.   A b_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'b', indicating a b_coordinatesetting. The function reads characters which tell how to set thecoordinate, up to the start of the next item or the end of the line.The counter is then set to point to the character following.The value may be a real number or something that evaluates to areal number, so read_real_value is used to read it. Parametersmay be involved.If the BB compiler flag is defined, the b_flag in the block is turnedon and the b_number in the block is set to the value read. If theBB flag is not defined, (i) if the AXIS_ERROR flag is defined, that meansB values are not allowed, and an error value is returned, (ii) if theAXIS_ERROR flag is not defined, nothing is done.*/int Interp::read_b(char *line,   //!< string: line of RS274/NGC code being processed                  int *counter, //!< pointer to a counter for position on the line                   block_pointer block,  //!< pointer to a block being filled from the line                   double *parameters)   //!< array of system parameters                    {  static char name[] = "read_b";  double value;  int status;  CHK((line[*counter] != 'b'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  *counter = (*counter + 1);  CHK((block->b_flag != OFF), NCE_MULTIPLE_B_WORDS_ON_ONE_LINE);  CHP(read_real_value(line, counter, &value, parameters));  block->b_flag = ON;  block->b_number = value;  return INTERP_OK;}/****************************************************************************//*! read_cReturned Value: int   If read_real_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character read is not c:      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED   2. An c_coordinate has already been inserted in the block:      NCE_MULTIPLE_C_WORDS_ON_ONE_LINE   3. C values are not allowed: NCE_CANNOT_USE_C_WORDSide effects:   counter is reset.   The c_flag in the block is turned on.   A c_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'c', indicating an c_coordinatesetting. The function reads characters which tell how to set thecoordinate, up to the start of the next item or the end of the line.The counter is then set to point to the character following.The value may be a real number or something that evaluates to areal number, so read_real_value is used to read it. Parametersmay be involved.If the CC compiler flag is defined, the c_flag in the block is turnedon and the c_number in the block is set to the value read. If theCC flag is not defined, (i) if the AXIS_ERROR flag is defined, that meansC values are not allowed, and an error value is returned, (ii) if theAXIS_ERROR flag is not defined, nothing is done.*/int Interp::read_c(char *line,   //!< string: line of RS274/NGC code being processed                  int *counter, //!< pointer to a counter for position on the line                   block_pointer block,  //!< pointer to a block being filled from the line                   double *parameters)   //!< array of system parameters                    {  static char name[] = "read_c";  double value;  int status;  CHK((line[*counter] != 'c'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  *counter = (*counter + 1);  CHK((block->c_flag != OFF), NCE_MULTIPLE_C_WORDS_ON_ONE_LINE);  CHP(read_real_value(line, counter, &value, parameters));  block->c_flag = ON;  block->c_number = value;  return INTERP_OK;}/****************************************************************************//*! read_commentReturned Value: int  If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character read is not '(' ,      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLEDSide effects:   The counter is reset to point to the character following the comment.   The comment string, without parentheses, is copied into the comment   area of the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character '(', indicating a comment isbeginning. The function reads characters of the comment, up to andincluding the comment closer ')'.It is expected that the format of a comment will have been checked (byread_text or read_keyboard_line) and bad format comments willhave prevented the system from getting this far, so that this functioncan assume a close parenthesis will be found when an open parenthesishas been found, and that comments are not nested.The "parameters" argument is not used in this function. That argument ispresent only so that this will have the same argument list as the other"read_XXX" functions called using a function pointer by read_one_item.*/int Interp::read_comment(char *line,     //!< string: line of RS274 code being processed                           int *counter,   //!< pointer to a counter for position on the line                        block_pointer block,    //!< pointer to a block being filled from the line                        double *parameters)     //!< array of system parameters                   {  static char name[] = "read_comment";  int n;  CHK((line[*counter] != '('), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  (*counter)++;  for (n = 0; line[*counter] != ')'; (*counter)++, n++) {    block->comment[n] = line[*counter];  }  block->comment[n] = 0;  (*counter)++;  return INTERP_OK;}/****************************************************************************//*! read_dReturned Value: int   If read_integer_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The first character read is not d:      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED   2. A d_number has already been inserted in the block:      NCE_MULTIPLE_D_WORDS_ON_ONE_LINE   3. The d_number is negative: NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED   4. The d_number is more than _setup.tool_max: NCE_TOOL_RADIUS_INDEX_TOO_BIGSide effects:   counter is reset to the character following the tool number.   A d_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'd', indicating an index into atable of tool diameters.  The function reads characters which give the(integer) value of the index. The value may not be more than_setup.tool_max and may not be negative, but it may be zero. The rangeis checked here.read_integer_value allows a minus sign, so a check for a negative valueis made here, and the parameters argument is also needed.*/int Interp::read_d(char *line,   //!< string: line of RS274 code being processed                     int *counter, //!< pointer to a counter for position on the line                  block_pointer block,  //!< pointer to a block being filled from the line                  double *parameters)   //!< array of system parameters                   {  static char name[] = "read_d";  int value;  int status;  CHK((line[*counter] != 'd'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  *counter = (*counter + 1);  CHK((block->d_number > -1), NCE_MULTIPLE_D_WORDS_ON_ONE_LINE);  CHP(read_integer_value(line, counter, &value, parameters));  CHK((value < 0), NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED);  CHK((value > _setup.tool_max), NCE_TOOL_RADIUS_INDEX_TOO_BIG);  block->d_number = value;  return INTERP_OK;}/****************************************************************************//*! read_fReturned Value: int   If read_real_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.

⌨️ 快捷键说明

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