Пример #1
0
FILE *open_file(NODE *arg, char *access) {
    char *fnstr;
    FILE *tstrm;
    char *old_stringptr = print_stringptr;
    int old_stringlen = print_stringlen;

    if (is_list(arg)) { /* print to string */
	if (*access != 'w') {
	    err_logo(BAD_DATA_UNREC, arg);
	    return NULL;
	} else {
	    FIXNUM i = int_arg(cdr(arg));
	    if (NOT_THROWING && i > 0 && cddr(arg) == NIL) {
		char *tmp = (char *)malloc(i);
		*tmp = '\0';
		return (FILE *)tmp;
	    }
	    err_logo(BAD_DATA_UNREC, car(arg));
	    return NULL;
	}
    }

    arg = cnv_node_to_strnode(arg);
    if (arg == UNBOUND) return(NULL);
    if (file_prefix != NIL) {
	print_stringlen = getstrlen(file_prefix) +
			    getstrlen(arg) + 2;
	fnstr = (char *)malloc((size_t)print_stringlen + 1);
    } else
	fnstr = (char *) malloc((size_t)getstrlen(arg) + 1);
    if (fnstr == NULL) {
	err_logo(FILE_ERROR, make_static_strnode(message_texts[MEM_LOW]));
	print_stringptr = old_stringptr;
	print_stringlen = old_stringlen;
	return NULL;
    }
    if (file_prefix != NIL) {
	print_stringptr = fnstr;
	ndprintf((FILE *)NULL, "%p%t%p", file_prefix, separator, arg);
	*print_stringptr = '\0';
	print_stringptr = old_stringptr;
	print_stringlen = old_stringlen;
    } else
	noparity_strnzcpy(fnstr, getstrptr(arg), getstrlen(arg));
    tstrm = fopen(fnstr, access);
    free(fnstr);
    return(tstrm);
}
Пример #2
0
NODE *cnv_node_to_numnode(NODE *ndi)
   {
   NODE *val;
   int dr;
   char s2[MAX_NUMBER], *s = s2;

   if (is_number(ndi))
      return (ndi);
   ndi = cnv_node_to_strnode(ndi);
   if (ndi == UNBOUND) return (UNBOUND);
   if (((getstrlen(ndi)) < MAX_NUMBER) && (dr = numberp(ndi)))
      {
      if (backslashed(ndi))
         noparity_strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
      else
         strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
      if (*s == '+') ++s;
      if (s2[getstrlen(ndi) - 1] == '.') s2[getstrlen(ndi) - 1] = 0;
      if (/*TRUE || */ dr - 1 || getstrlen(ndi) > 9)
         {
         val = newnode(FLOAT);
         setfloat(val, atof(s));
         }
      else
         {
         val = newnode(INT);
         setint(val, atol(s));
         }
      gcref(ndi);
      return (val);
      }
   else
      {
      gcref(ndi);
      return (UNBOUND);
      }
   }
Пример #3
0
char *asciiz(NODE *arg) {
    char *out = (char *)malloc(getstrlen(arg)+1);
    return noparity_strnzcpy(out, getstrptr(arg), getstrlen(arg));
}