interp_read.cc
来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,969 行 · 第 1/5 页
CC
1,969 行
Returned 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 p: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. A p value has already been inserted in the block: NCE_MULTIPLE_P_WORDS_ON_ONE_LINESide effects: counter is reset to point to the first character following the p value. The p value setting is inserted in block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'p', indicating a p valuesetting. The function reads characters which tell how to set the pvalue, up to the start of the next item or the end of the line. Thisinformation is inserted in the block.P codes are used for:1. Dwell time in canned cycles g82, G86, G88, G89 [NCMS pages 98 - 100].2. A key with G10 [NCMS, pages 9, 10].*/int Interp::read_p(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_p"; double value; int status; CHK((line[*counter] != 'p'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->p_number > -1.0), NCE_MULTIPLE_P_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); // FMP removed check for negatives, since we may want them for // user-defined codes // CHK((value < 0.0), NCE_NEGATIVE_P_WORD_USED); block->p_number = value; block->p_flag = ON; return INTERP_OK;}int Interp::read_name( char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line char *nameBuf) //!< pointer to name to be read{ static char name[] = "read_name"; int done = 0; int i; CHK(((line[*counter] != '<') && !isalpha(line[*(counter)])), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); // skip over the '<' *counter = (*counter + 1); for(i=0; (i<LINELEN) && (line[*counter]); i++) { if(line[*counter] == '>') { nameBuf[i] = 0; // terminate the name *counter = (*counter + 1); done = 1; break; } nameBuf[i] = line[*counter]; *counter = (*counter + 1); } // !!!KL need to rename the error message and change text CHK((!done), NCE_NAMED_PARAMETER_NOT_TERMINATED); return INTERP_OK;}int Interp::find_named_param( char *nameBuf, //!< pointer to name to be read int *status, //!< pointer to return status 1 => found double *value //!< pointer to value of found parameter ) { //static char name[] = "find_named_param"; struct named_parameters_struct *nameList; int level; int i; // now look it up if(nameBuf[0] != '_') // local scope { level = _setup.call_level; } else { // call level zero is global scope level = 0; } nameList = &_setup.sub_context[level].named_parameters; for(i=0; i<nameList->named_parameter_used_size; i++) { if(0 == strcmp(nameList->named_parameters[i], nameBuf)) { *value = nameList->named_param_values[i]; *status = 1; return INTERP_OK; } } *value = 0.0; *status = 0; return INTERP_OK;}int Interp::store_named_param( char *nameBuf, //!< pointer to name to be written double value //!< value to be written ) { //static char name[] = "store_named_param"; struct named_parameters_struct *nameList; int level; int i; // now look it up if(nameBuf[0] != '_') // local scope { level = _setup.call_level; } else { // call level zero is global scope level = 0; } nameList = &_setup.sub_context[level].named_parameters; logDebug("store_named_parameter: nameList[%d]=0x%x storing:|%s|", level, nameList, nameBuf); logDebug("store_named_parameter: named_parameter_used_size=%d", nameList->named_parameter_used_size); for(i=0; i<nameList->named_parameter_used_size; i++) {#if 0 logDebug("store_named_parameter: named_parameter[%d]=|%s|", i, nameList->named_parameters[i]);#endif if(0 == strcmp(nameList->named_parameters[i], nameBuf)) { nameList->named_param_values[i] = value; logDebug("store_named_parameter: level[%d] %s value=%lf", level, nameBuf, value); return INTERP_OK; } } logDebug("%s: param:|%s| returning not defined", "store_named_param", nameBuf); return NCE_NAMED_PARAMETER_NOT_DEFINED;}int Interp::add_named_param( char *nameBuf //!< pointer to name to be added ) { static char name[] = "add_named_param"; struct named_parameters_struct *nameList; int status; int findStatus; double value; int level; char *dup; // look it up to see if already exists CHP(find_named_param(nameBuf, &findStatus, &value)); if(findStatus) { logDebug("%s: parameter:|%s| already exists", name, nameBuf); return INTERP_OK; } // must do an add if(nameBuf[0] != '_') // local scope { level = _setup.call_level; } else { // call level zero is global scope level = 0; } nameList = &_setup.sub_context[level].named_parameters; if(nameList->named_parameter_used_size >= nameList->named_parameter_alloc_size) { // must realloc space nameList->named_parameter_alloc_size += NAMED_PARAMETERS_ALLOC_UNIT; logDebug("realloc space level[%d] size:%d", level, nameList->named_parameter_alloc_size); nameList->named_parameters = (char **)realloc((void *)nameList->named_parameters, sizeof(char *)*nameList->named_parameter_alloc_size); nameList->named_param_values = (double *)realloc((void *)nameList->named_param_values, sizeof(double)*nameList->named_parameter_alloc_size); if((nameList->named_parameters == 0) || (nameList->named_param_values == 0)) { ERP(NCE_OUT_OF_MEMORY); } } dup = strdup(nameBuf); if(dup == 0) { ERP(NCE_OUT_OF_MEMORY); } logDebug("%s strdup[0x%x]:|%s|", name, dup, dup); nameList->named_parameters[nameList->named_parameter_used_size++] = dup; return INTERP_OK;}/****************************************************************************//*! read_named_parameterReturned 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, this returns INTERP_OK. 1. The first character read is not a <: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. The named parameter string is not terminated by >: NCE_NAMED_PARAMETER_NOT_TERMINATED 3. The named parameter has not been defined before use: NCE_NAMED_PARAMETER_NOT_DEFINEDSide effects: The value of the given parameter 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_parameterThis attempts to read the value of a parameter out of the line,starting at the index given by the counter.According to the RS274/NGC manual [NCMS, p. 62], the characters following# may be any "parameter expression". Thus, the following are legaland mean the same thing (the value of the parameter whose number isstored in parameter 2): ##2 #[#2]!!!KL ADDED by K. LermanNamed parameters are now supported.#<_abcd> is a parameter with name "abcd" of global scope#<abce> is a named parameter of local scope.*/int Interp::read_named_parameter( char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line double *double_ptr, //!< pointer to double to be read double *parameters) //!< array of system parameters{ static char name[] = "read_named_parameter"; char paramNameBuf[LINELEN+1]; int status; int level; int i; struct named_parameters_struct *nameList; CHK((line[*counter] != '<'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); CHP(read_name(line, counter, paramNameBuf)); // now look it up if(paramNameBuf[0] != '_') // local scope { level = _setup.call_level; } else { // call level zero is global scope level = 0; } nameList = &_setup.sub_context[level].named_parameters; for(i=0; i<nameList->named_parameter_used_size; i++) { if(0 == strcmp(nameList->named_parameters[i], paramNameBuf)) { *double_ptr = nameList->named_param_values[i]; return INTERP_OK; } } *double_ptr = 0.0; logDebug("%s: level[%d] param:|%s| returning not defined", name, level, paramNameBuf); return NCE_NAMED_PARAMETER_NOT_DEFINED;}/****************************************************************************//*! read_parameterReturned 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, this returns INTERP_OK. 1. The first character read is not # : NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. The parameter number is out of bounds: NCE_PARAMETER_NUMBER_OUT_OF_RANGESide effects: The value of the given parameter 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_real_valueThis attempts to read the value of a parameter out of the line,starting at the index given by the counter.According to the RS274/NGC manual [NCMS, p. 62], the characters following# may be any "parameter expression". Thus, the following are legaland mean the same thing (the value of the parameter whose number isstored in parameter 2): ##2 #[#2]Parameter setting is done in parallel, not sequentially. For exampleif #1 is 5 before the line "#1=10 #2=#1" is read, then after the lineis is executed, #1 is 10 and #2 is 5. If parameter setting were donesequentially, the value of #2 would be 10 after the line was executed.!!!KL ADDED by K. LermanNamed parameters are now supported.#[abcd] is a parameter with name "abcd"#[#2] is NOT a named parameter.When a [ is seen after a #, if the next char is not a #, it is a namedparameter.*/int Interp::read_parameter( char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line double *double_ptr, //!< pointer to double to be read double *parameters) //!< array of system parameters { static char name[] = "read_parameter"; int index; int status; CHK((line[*counter]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?