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

📄 print.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Lisp object printing and output streams.   Copyright (C) 1985, 1986, 1990 Free Software Foundation, Inc.This file is part of GNU Emacs.GNU Emacs is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 1, or (at your option)any later version.GNU Emacs is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Emacs; see the file COPYING.  If not, write tothe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */#include "config.h"#include <stdio.h>#undef NULL#include "lisp.h"#ifndef standalone#include "buffer.h"#include "window.h"#include "process.h"#include "dispextern.h"#include "termchar.h"#endif /* not standalone */Lisp_Object Vstandard_output, Qstandard_output;/* Avoid actual stack overflow in print.  */int print_depth;/* Maximum length of list to print in full; noninteger means   effectively infinity */Lisp_Object Vprint_length;/* Nonzero means print newlines in strings as \n.  */int print_escape_newlines;/* Nonzero means print newline before next minibuffer message.   Defined in xdisp.c */extern int noninteractive_need_newline;#ifdef MAX_PRINT_CHARSstatic int print_chars;static int max_print;#endif /* MAX_PRINT_CHARS *//* Low level output routines for charaters and strings *//* Lisp functions to do output using a stream must have the stream in a variable called printcharfun and must start with PRINTPREPARE and end with PRINTFINISH. Use PRINTCHAR to output one character, or call strout to output a block of characters. Also, each one must have the declarations   struct buffer *old = current_buffer;   int old_point = -1, start_point;   Lisp_Object original;*/ #define PRINTPREPARE \   original = printcharfun; \   if (NULL (printcharfun)) printcharfun = Qt; \   if (XTYPE (printcharfun) == Lisp_Buffer) \     { if (XBUFFER (printcharfun) != current_buffer) Fset_buffer (printcharfun); \       printcharfun = Qnil;}\   if (XTYPE (printcharfun) == Lisp_Marker) \     { if (XMARKER (original)->buffer != current_buffer) \         set_buffer_internal (XMARKER (original)->buffer); \       old_point = point; \       SET_PT (marker_position (printcharfun)); \       start_point = point; \       printcharfun = Qnil;}#define PRINTFINISH \   if (XTYPE (original) == Lisp_Marker) \     Fset_marker (original, make_number (point), Qnil); \   if (old_point >= 0) \     SET_PT ((old_point >= start_point ? point - start_point : 0) + old_point); \   if (old != current_buffer) \     set_buffer_internal (old)#define PRINTCHAR(ch) printchar (ch, printcharfun)/* Index of first unused element of message_buf.  */static int printbufidx;static voidprintchar (ch, fun)     unsigned char ch;     Lisp_Object fun;{  Lisp_Object ch1;#ifdef MAX_PRINT_CHARS  if (max_print)    print_chars++;#endif /* MAX_PRINT_CHARS */#ifndef standalone  if (EQ (fun, Qnil))    {      QUIT;      insert (&ch, 1);      return;    }  if (EQ (fun, Qt))    {      if (noninteractive)	{	  putchar (ch);	  noninteractive_need_newline = 1;	  return;	}      if (echo_area_contents != message_buf)	echo_area_contents = message_buf, printbufidx = 0;      if (printbufidx < screen_width)	message_buf[printbufidx++] = ch;      message_buf[printbufidx] = 0;      return;    }#endif /* not standalone */  XFASTINT (ch1) = ch;  call1 (fun, ch1);}static voidstrout (ptr, size, printcharfun)     char *ptr;     int size;     Lisp_Object printcharfun;{  int i = 0;  if (EQ (printcharfun, Qnil))    {      insert (ptr, size >= 0 ? size : strlen (ptr));#ifdef MAX_PRINT_CHARS      if (max_print)        print_chars += size >= 0 ? size : strlen(ptr);#endif /* MAX_PRINT_CHARS */      return;    }  if (EQ (printcharfun, Qt))    {      i = size >= 0 ? size : strlen (ptr);#ifdef MAX_PRINT_CHARS      if (max_print)        print_chars += i;#endif /* MAX_PRINT_CHARS */      if (noninteractive)	{	  fwrite (ptr, 1, i, stdout);	  noninteractive_need_newline = 1;	  return;	}      if (echo_area_contents != message_buf)	echo_area_contents = message_buf, printbufidx = 0;      if (i > screen_width - printbufidx)	i = screen_width - printbufidx;      bcopy (ptr, &message_buf[printbufidx], i);      printbufidx += i;      message_buf[printbufidx] = 0;      return;    }  if (size >= 0)    while (i < size)      PRINTCHAR (ptr[i++]);  else    while (ptr[i])      PRINTCHAR (ptr[i++]);}DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,  "Output character CHAR to stream STREAM.\n\STREAM defaults to the value of `standard-output' (which see).")  (ch, printcharfun)     Lisp_Object ch, printcharfun;{  struct buffer *old = current_buffer;  int old_point = -1;  int start_point;  Lisp_Object original;  if (NULL (printcharfun))    printcharfun = Vstandard_output;  CHECK_NUMBER (ch, 0);  PRINTPREPARE;  PRINTCHAR (XINT (ch));  PRINTFINISH;  return ch;}write_string (data, size)     char *data;     int size;{  struct buffer *old = current_buffer;  Lisp_Object printcharfun;  int old_point = -1;  int start_point;  Lisp_Object original;  printcharfun = Vstandard_output;  PRINTPREPARE;  strout (data, size, printcharfun);  PRINTFINISH;}write_string_1 (data, size, printcharfun)     char *data;     int size;     Lisp_Object printcharfun;{  struct buffer *old = current_buffer;  int old_point = -1;  int start_point;  Lisp_Object original;  PRINTPREPARE;  strout (data, size, printcharfun);  PRINTFINISH;}#ifndef standalonetemp_output_buffer_setup (bufname)    char *bufname;{  register struct buffer *old = current_buffer;  register Lisp_Object buf;  Fset_buffer (Fget_buffer_create (build_string (bufname)));  current_buffer->read_only = Qnil;  Ferase_buffer ();  XSET (buf, Lisp_Buffer, current_buffer);  specbind (Qstandard_output, buf);  set_buffer_internal (old);}Lisp_Objectinternal_with_output_to_temp_buffer (bufname, function, args)     char *bufname;     Lisp_Object (*function) ();     Lisp_Object args;{  int count = specpdl_ptr - specpdl;  Lisp_Object buf, val;  record_unwind_protect (Fset_buffer, Fcurrent_buffer ());  temp_output_buffer_setup (bufname);  buf = Vstandard_output;  val = (*function) (args);  temp_output_buffer_show (buf);  unbind_to (count);  return val;}DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,       1, UNEVALLED, 0,  "Binding `standard-output' to buffer named BUFNAME, execute BODY then display that buffer.\n\The buffer is cleared out initially, and marked as unmodified when done.\n\All output done by BODY is inserted in that buffer by default.\n\It is displayed in another window, but not selected.\n\The value of the last form in BODY is returned.\n\If variable `temp-buffer-show-hook' is non-nil, call it at the end\n\to get the buffer displayed.  It gets one argument, the buffer to display.")  (args)     Lisp_Object args;{  struct gcpro gcpro1;  Lisp_Object name;  int count = specpdl_ptr - specpdl;  Lisp_Object buf, val;  GCPRO1(args);  name = Feval (Fcar (args));  UNGCPRO;  CHECK_STRING (name, 0);  temp_output_buffer_setup (XSTRING (name)->data);  buf = Vstandard_output;  val = Fprogn (Fcdr (args));  temp_output_buffer_show (buf);  unbind_to (count);  return val;}#endif /* not standalone */static void print ();DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,  "Output a newline to STREAM (or value of standard-output).")  (printcharfun)     Lisp_Object printcharfun;{  struct buffer *old = current_buffer;  int old_point = -1;  int start_point;  Lisp_Object original;  if (NULL (printcharfun))    printcharfun = Vstandard_output;  PRINTPREPARE;  PRINTCHAR ('\n');  PRINTFINISH;  return Qt;}DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,  "Output the printed representation of OBJECT, any Lisp object.\n\Quoting characters are printed when needed to make output that `read'\n\can handle, whenever this is possible.\n\Output stream is STREAM, or value of `standard-output' (which see).")  (obj, printcharfun)     Lisp_Object obj, printcharfun;{  struct buffer *old = current_buffer;  int old_point = -1;  int start_point;  Lisp_Object original;#ifdef MAX_PRINT_CHARS  max_print = 0;#endif /* MAX_PRINT_CHARS */  if (NULL (printcharfun))    printcharfun = Vstandard_output;  PRINTPREPARE;  print_depth = 0;  print (obj, printcharfun, 1);

⌨️ 快捷键说明

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