/* * TKCreate creates a new TokenizerT object for a given set of serarator * characters (given as a string) and a tken stream (given as a string). * * TKCreate should copy the two arguments so that it is not dependant on them * staying immutable after returning. * * If the function succeeds, it returns a non-NULL TokenizerT. * Else it returns NULL. * */ TokenizerT *TKCreate ( char const *const seperators, char const *const ts ) { /* * Make copies of the two strings. * This uses malloc so it is creating dynamically allocated strings. */ char *const delimiters = simplify_string( seperators ); char *const token = simplify_string( ts ); TokenizerT *const tk = malloc( sizeof( TokenizerT ) ); /* If neither string is NULL create a TokenizerT and return a pointer. */ if ( delimiters && token && tk ) { *tk = (TokenizerT) {delimiters, token, token}; return tk; } /* Else return NULL. */ return NULL; }
char *look_in_lisp_variable(char *o, int prefix) { Lisp_Object nil, var; /* * I will start by tagging a '$' (or whatever) on in front of the * parameter name. */ o[0] = (char)prefix; var = make_undefined_symbol(o); nil = C_nil; /* * make_undefined_symbol() could fail either if we had utterly run out * of memory or if somebody generated an interrupt (eg ^C) around now. Ugh. */ if (exception_pending()) { flip_exception(); return NULL; } /* * If the variable $name was undefined then I use an empty replacement * text for it. Otherwise I need to look harder at its value. */ if (qvalue(var) == unset_var) return o; else { Header h; intptr_t len; var = qvalue(var); /* * Mostly I expect that the value will be a string or symbol. */ #ifdef COMMON if (complex_stringp(var)) { var = simplify_string(var); nil = C_nil; if (exception_pending()) { flip_exception(); return NULL; } } #endif /* COMMON */ if (symbolp(var)) { var = get_pname(var); nil = C_nil; if (exception_pending()) { flip_exception(); return NULL; } h = vechdr(var); } else if (!is_vector(var) || type_of_header(h = vechdr(var)) != TYPE_STRING) return NULL; len = length_of_header(h) - CELL; /* * Copy the characters from the string or from the name of the variable * into the file-name buffer. There could at present be a crash here * if the expansion was very very long and overflowed my buffer. Tough * luck for now - people doing that (maybe) get what they (maybe) deserve. */ memcpy(o, (char *)var + (CELL - TAG_VECTOR), (size_t)len); o = o + len; return o; } }