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

📄 lread.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
DEFUN ("eval-region", Feval_region, Seval_region, 2, 3, "r",  "Execute the region as Lisp code.\n\When called from programs, expects two arguments,\n\giving starting and ending indices in the current buffer\n\of the text to be executed.\n\Programs can pass third argument PRINTFLAG which controls printing of output:\n\nil means discard it; anything else is stream for print.")  (b, e, printflag)     Lisp_Object b, e, printflag;{  int count = specpdl_ptr - specpdl;  Lisp_Object tem;  if (NULL (printflag))    tem = Qsymbolp;  else    tem = printflag;  specbind (Qstandard_output, tem);  if (NULL (printflag))    record_unwind_protect (save_excursion_restore, save_excursion_save ());  record_unwind_protect (save_restriction_restore, save_restriction_save ());  /* This both uses b and checks its type.  */  Fgoto_char (b);  Fnarrow_to_region (make_number (BEGV), e);  readevalloop (Fcurrent_buffer (), 0, Feval, !NULL (printflag));  unbind_to (count);  return Qnil;}#endif standaloneDEFUN ("read", Fread, Sread, 0, 1, 0,  "Read one Lisp expression as text from STREAM, return as Lisp object.\n\If STREAM is nil, use the value of standard-input (which see).\n\STREAM or standard-input may be:\n\ a buffer (read from point and advance it)\n\ a marker (read from where it points and advance it)\n\ a function (call it with no arguments for each character)\n\ a string (takes text from string, starting at the beginning)\n\ t (read text line using minibuffer and use it).")  (readcharfun)     Lisp_Object readcharfun;{  extern Lisp_Object Fread_minibuffer ();  unrch = -1;	/* Allow buffering-back only within a read. */  if (NULL (readcharfun))    readcharfun = Vstandard_input;  if (EQ (readcharfun, Qt))    readcharfun = Qread_char;#ifndef standalone  if (EQ (readcharfun, Qread_char))    return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);#endif  if (XTYPE (readcharfun) == Lisp_String)    return Fcar (Fread_from_string (readcharfun, Qnil, Qnil));  return read0 (readcharfun);}DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,  "Read one Lisp expression which is represented as text by STRING.\n\Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\START and END optionally delimit a substring of STRING from which to read;\n\ they default to 0 and (length STRING) respectively.")  (string, start, end)     Lisp_Object string, start, end;{  int startval, endval;  Lisp_Object tem;  CHECK_STRING (string,0);  if (NULL (end))    endval = XSTRING (string)->size;  else    { CHECK_NUMBER (end,2);      endval = XINT (end);      if (endval < 0 || endval > XSTRING (string)->size)	args_out_of_range (string, end);    }  if (NULL (start))    startval = 0;  else    { CHECK_NUMBER (start,1);      startval = XINT (start);      if (startval < 0 || startval > endval)	args_out_of_range (string, start);    }  read_from_string_index = startval;  read_from_string_limit = endval;  unrch = -1;	/* Allow buffering-back only within a read. */  tem = read0 (string);  return Fcons (tem, make_number (read_from_string_index));}/* Use this for recursive reads, in contexts where internal tokens are not allowed. */static Lisp_Objectread0 (readcharfun)     Lisp_Object readcharfun;{  register Lisp_Object val;  char c;  val = read1 (readcharfun);  if (XTYPE (val) == Lisp_Internal)    {      c = XINT (val);      return Fsignal (Qinvalid_read_syntax, Fcons (make_string (&c, 1), Qnil));    }  return val;}static int read_buffer_size;static char *read_buffer;static Lisp_Objectread1 (readcharfun)     register Lisp_Object readcharfun;{  register int c; retry:  c = READCHAR;  if (c < 0) return Fsignal (Qend_of_file, Qnil);  switch (c)    {    case '(':      return read_list (0, readcharfun);    case '[':      return read_vector (readcharfun);    case ')':    case ']':    case '.':      {	register Lisp_Object val;	XSET (val, Lisp_Internal, c);	return val;      }    case '#':      return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));    case ';':      while ((c = READCHAR) >= 0 && c != '\n');      goto retry;    case '\'':      {	return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));      }    case '?':      {	register Lisp_Object val;	XSET (val, Lisp_Int, READCHAR);	if (XFASTINT (val) == '\\')	  XSETINT (val, read_escape (readcharfun));	return val;      }    case '\"':      {	register char *p = read_buffer;	register char *end = read_buffer + read_buffer_size;	register int c;	int cancel = 0;	while ((c = READCHAR) >= 0 &&		(c != '\"' || (c = READCHAR) == '\"'))	  {	    if (p == end)	      {		char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);		p += new - read_buffer;		read_buffer += new - read_buffer;		end = read_buffer + read_buffer_size;	      }	    if (c == '\\')	      c = read_escape (readcharfun);	    /* c is -1 if \ newline has just been seen */	    if (c < 0)	      {		if (p == read_buffer)		  cancel = 1;	      }	    else	      *p++ = c;	  }	UNREAD (c);	/* If purifying, and string starts with \ newline,	   return zero instead.  This is for doc strings	   that we are really going to find in etc/DOC.nn.nn  */	if (!NULL (Vpurify_flag) && NULL (Vdoc_file_name) && cancel)	  return make_number (0);	if (read_pure)	  return make_pure_string (read_buffer, p - read_buffer);	else	  return make_string (read_buffer, p - read_buffer);      }    default:      if (c <= 040) goto retry;      {	register char *p = read_buffer;	{	  register char *end = read_buffer + read_buffer_size;	  while (c > 040 && 		 !(c == '\"' || c == '\'' || c == ';' || c == '?'		   || c == '(' || c == ')' || c =='.'		   || c == '[' || c == ']' || c == '#'		   ))	    {	      if (p == end)		{		  register char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);		  p += new - read_buffer;		  read_buffer += new - read_buffer;		  end = read_buffer + read_buffer_size;		}	      if (c == '\\')		c = READCHAR;	      *p++ = c;	      c = READCHAR;	    }	  if (p == end)	    {	      char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);	      p += new - read_buffer;	      read_buffer += new - read_buffer;/*	      end = read_buffer + read_buffer_size;  */	    }	  *p = 0;	  UNREAD (c);	}	/* Is it an integer? */	{	  register char *p1;	  register Lisp_Object val;	  p1 = read_buffer;	  if (*p1 == '+' || *p1 == '-') p1++;	  if (p1 != p)	    {	      while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;	      if (p1 == p)		/* It is. */		{		  XSET (val, Lisp_Int, atoi (read_buffer));		  return val;		}	    }	}	return intern (read_buffer);      }    }}static Lisp_Objectread_vector (readcharfun)     Lisp_Object readcharfun;{  register int i;  register int size;  register Lisp_Object *ptr;  register Lisp_Object tem, vector;  register struct Lisp_Cons *otem;  Lisp_Object len;  tem = read_list (1, readcharfun);  len = Flength (tem);  vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));  size = XVECTOR (vector)->size;  ptr = XVECTOR (vector)->contents;  for (i = 0; i < size; i++)    {      ptr[i] = read_pure ? Fpurecopy (Fcar (tem)) : Fcar (tem);      otem = XCONS (tem);      tem = Fcdr (tem);      free_cons (otem);    }  return vector;}  /* flag = 1 means check for ] to terminate rather than ) and .   flag = -1 means check for starting with defun    and make structure pure.  */static Lisp_Objectread_list (flag, readcharfun)     int flag;     register Lisp_Object readcharfun;{  /* -1 means check next element for defun,     0 means don't check,     1 means already checked and found defun. */  int defunflag = flag < 0 ? -1 : 0;  Lisp_Object val, tail;  register Lisp_Object elt, tem;  struct gcpro gcpro1, gcpro2;  val = Qnil;  tail = Qnil;  while (1)    {      GCPRO2 (val, tail);      elt = read1 (readcharfun);      UNGCPRO;      if (XTYPE (elt) == Lisp_Internal)	{	  if (flag > 0)	    {	      if (XINT (elt) == ']')		return val;	      return Fsignal (Qinvalid_read_syntax, Fcons (make_string (") or . in a vector", 18), Qnil));	    }	  if (XINT (elt) == ')')	    return val;	  if (XINT (elt) == '.')	    {	      GCPRO2 (val, tail);	      if (!NULL (tail))		XCONS (tail)->cdr = read0 (readcharfun);	      else		val = read0 (readcharfun);	      elt = read1 (readcharfun);	      UNGCPRO;	      if (XTYPE (elt) == Lisp_Internal && XINT (elt) == ')')		return val;	      return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));	    }	  return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));	}      tem = (read_pure && flag <= 0	     ? pure_cons (elt, Qnil)	     : Fcons (elt, Qnil));      if (!NULL (tail))	XCONS (tail)->cdr = tem;      else	val = tem;      tail = tem;      if (defunflag < 0)	defunflag = EQ (elt, Qdefun);      else if (defunflag > 0)	read_pure = 1;    }}static intread_escape (readcharfun)     Lisp_Object readcharfun;{  register int c = READCHAR;  switch (c)    {    case 'a':      return 007;    case 'b':      return '\b';    case 'e':      return 033;    case 'f':      return '\f';    case 'n':      return '\n';    case 'r':      return '\r';    case 't':      return '\t';    case 'v':      return '\v';    case '\n':      return -1;    case 'M':      c = READCHAR;      if (c != '-')	error ("Invalid escape character syntax");      c = READCHAR;      if (c == '\\')	c = read_escape (readcharfun);      return c | 0200;    case 'C':      c = READCHAR;      if (c != '-')	error ("Invalid escape character syntax");    case '^':      c = READCHAR;      if (c == '\\')	c = read_escape (readcharfun);      if (c == '?')	return 0177;      return (c & 0200) | (c & 037);          case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':      {	register int i = c - '0';	register int count = 0;	while (++count < 3)	  {	    if ((c = READCHAR) >= '0' && c <= '7')	      {		i *= 8;

⌨️ 快捷键说明

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