static void parse_tacplus_keys( const char *keys_from_option ) { char *key_copy,*s,*s1; /* Drop old keys */ if( tacplus_keys ) { g_slist_free( tacplus_keys ); tacplus_keys=NULL; } if( !strchr( keys_from_option, '/' ) ){ /* option not in client/server=key format */ return ; } key_copy=g_strdup(keys_from_option); s=key_copy; while(s){ if( (s1=strchr( s, ' ' )) != NULL ) *s1++='\0'; parse_tuple( s ); s=s1; } g_free( key_copy ); #ifdef DEB_TACPLUS g_slist_foreach( tacplus_keys, tacplus_print_key_entry, GINT_TO_POINTER(1) ); #endif }
/* carrega todos os pares CHAVE=VALOR do arquivo de tradução * numa hash_table, para eliminar a necessidade de abrir varias * vezes o arquivo. */ hash_table *load_translation() { char *filename; hash_table *trans = NULL; FILE *fp; char buffer[256]; int buf_size; /* obter a localização do arquivo de tradução no ldc.conf */ filename = TRANSLATION_FILE; if (filename == NULL) return NULL; if ((fp = fopen(filename, "r")) == NULL) return NULL; /* criar hash_table para armazenar as tuplas de tradução */ trans = new_hash_table(); buf_size = sizeof(buffer)/sizeof(buffer[0]); while (fgets(buffer, buf_size, fp) != NULL) { struct tuple *tmp = parse_tuple(buffer); if (tmp != NULL) add_hash_info(trans, tmp->key, tmp->value); free_tuple (&tmp); } fclose(fp); return trans; }
/* кортеж - аналогичен списку, но не создаёт собственного синтаксического узла */ int parse_tuple(char *text,char **endptr,Tag *toptag) { char *s,*p; Tag *tag; tag=NULL; if (text[0]!='(') return 1; s=text; if (toptag) tag=toptag; mark_len(NULL,1,s,&s,tag); // открывающая { while(*s) { p=s; mark_ctype(NULL,isblank,s,&s,tag); // лидирующие/разделяющие пробелы if ('('==*s) parse_tuple(s,&s,tag); else parse_word(s,&s,tag); // слово if (s[0]==')') { mark_len(NULL,1,s,&s,tag); // закрывающая } break; } if (strchr(EXPTERM,*s)!=NULL) break; if (p==s) break; } if (endptr) (*endptr)=s; return 0; }
static PyObject* chi2_chi2(PyObject* self, PyObject* args) { double m, b; npyarray<double> x, y, yerr; if (!parse_tuple(args, m, b, x, y, yerr)) { return NULL; } double value = chi2(m, b, x.data(), y.data(), yerr.data(), x.size()); if (value < 0.0) { PyErr_SetString(PyExc_RuntimeError, "Chi-squared returned an impossible value."); return NULL; } return Py_BuildValue("d", value); }
/** разобрать "выражение" выражение: последовательность слов разделённых пробелами **/ int parse_expression(char *text,char **endptr,Tag *toptag) { char *s,*p; Tag *tag; int comma; TRACE(""); if (!text) return 0; s=text; tag=NULL; comma=1; if (toptag) tag=mark(EXPR,text,text,toptag); while(*s) { p=s; mark_ctype(NULL,isblank,s,&s,tag); if (s[0]==',') { /* слова в выражении разделены , */ if (comma) { mark(NIL,s,s,tag); } mark_len(NULL,1,s,&s,tag); // отметить , mark_ctype(NULL,isspace,s,&s,tag); // после , разрешён \n comma=1; continue; } else { comma=0; } if (s[0]=='#' && s[1]=='!') parse_comment(s,&s,tag); if (s[0]=='#' && s[1]=='?' && s[2]=='>') parse_print(s,&s,tag); if (strchr(EXPTERM,*s)) break; if ('('==*s) { parse_tuple(s,&s,tag); } else parse_word(s,&s,tag); if (p==s) break; } if (comma) { mark(NIL,s,s,tag); s++; } if (endptr) *endptr=s; return 0; }
/* разобрать имя переменной */ int parse_variable(char *text,char **endptr,Tag *toptag) { char *s; Tag *tag; if (text[0]!='$') return 0; // имя переменной с $ tag=NULL; s=text; if (toptag) tag=mark(VAR,text,text,toptag); mark_len(NULL,1,s,&s,tag); // символ $ if (s[0]!='(') { Tag *exp; parse_word(s,&s,tag); // первая часть } while(s[0]=='(') { parse_tuple(s,&s,tag); // индекс if (s[0]==')') { mark_len(NULL,1,s,&s,tag); // закрывающая скобка } else if (strchr(EXPTERM,*s)) { break; } } if (endptr) (*endptr)=s; return 0; }