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

📄 io.c

📁 indent为linux下代码自动格式化工具
💻 C
📖 第 1 页 / 共 2 页
字号:
{  int fd;  struct stat file_stats;  int namelen = strlen (filename);  fd = open (filename, O_RDONLY, 0777);  if (fd < 0)    sys_error (filename);  if (fstat (fd, &file_stats) < 0)    sys_error (filename);  if (fileptr.data != 0)    free (fileptr.data);  fileptr.size = file_stats.st_size;  fileptr.data = (char *) xmalloc (file_stats.st_size + 1);  if (read (fd, fileptr.data, fileptr.size) < 0)    sys_error (filename);  if (close (fd) < 0)    sys_error (filename);  fileptr.name = (char *) xmalloc (namelen + 1);  memcpy (fileptr.name, filename, namelen);  fileptr.name[namelen] = '\0';  fileptr.data[fileptr.size] = '\0';  return &fileptr;}/* This should come from stdio.h and be some system-optimal number */#ifndef BUFSIZ#define BUFSIZ 1024#endif/* Suck the standard input into a file_buffer structure, and   return a pointer to that structure. */struct file_buffer stdinptr;struct file_buffer *read_stdin (){  unsigned int size = 15 * BUFSIZ;  int ch;  register char *p;  if (stdinptr.data != 0)    free (stdinptr.data);  stdinptr.data = (char *) xmalloc (size + 1);  stdinptr.size = 0;  p = stdinptr.data;  do    {      while (stdinptr.size < size)	{	  ch = getc (stdin);	  if (ch == EOF)	    break;	  *p++ = ch;	  stdinptr.size++;	}      if (ch != EOF)	{	  size += (2 * BUFSIZ);	  stdinptr.data = xrealloc (stdinptr.data, size);	}    }  while (ch != EOF);  stdinptr.name = "Standard Input";  stdinptr.data[stdinptr.size] = '\0';  return &stdinptr;}/* Advance buf_ptr so that it points to the next line of input.  Skip over   indent errors (comments beginning with *INDENT**), ignoring them.  Process   INDENT ON and INDENT OFF. (Note: the name of this function is a historical   artifact from before the time that indent kept the whole source file in   memory). */INLINE voidfill_buffer (){  /* Point various places in the buffer.  */  register char *p;  /* Character P points to. */  register char c;  /* Have we found INDENT ON or INDENT OFF ? */  enum    {      None, Indent_on, Indent_off    } com;  /* indent() may be saving the text between "if (...)" and the following     statement.  To do so, it uses another buffer (`save_com').  Switch     back to the previous buffer here. */  if (bp_save != 0)    {      buf_ptr = bp_save;      buf_end = be_save;      bp_save = be_save = 0;      /* only return if there is really something in this buffer */      if (buf_ptr < buf_end)	return;    }fill_it:  cur_line = in_prog_pos;  buf_ptr = in_prog_pos;  if (*buf_ptr == '\0')    {      had_eof = true;      return;    }  p = buf_ptr;  do    {      c = *p;      p++;    }  while (c != '\0' && c != '\n');  buf_end = p;  p = buf_ptr;  in_prog_pos = buf_end;  while (*p == ' ' || *p == '\t')    p++;  if (*p == '/' && p[1] == '*')    {      p += 2;      if (p[1] == 'I' && strncmp (p, "*INDENT**", 9) == 0)	goto fill_it;      while (*p == ' ' || *p == '\t')	p++;      com = None;      if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E'	  && p[4] == 'N' && p[5] == 'T')	{	  p += 6;	  while (*p == ' ' || *p == '\t')	    p++;	  if (*p == '*')	    com = Indent_on;	  else if (*p == 'O')	    if (*++p == 'N')	      p++, com = Indent_on;	    else if (*p == 'F' && *++p == 'F')	      p++, com = Indent_off;	  while (*p == ' ' || *p == '\t')	    p++;	  if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com)	    {	      if (s_com != e_com || s_lab != e_lab || s_code != e_code)		dump_line ();	      if (!(inhibit_formatting = (int) com - 1))		{		  n_real_blanklines = 0;		  postfix_blankline_requested = 0;		  prefix_blankline_requested = 0;		  suppress_blanklines = 1;		}	    }	}    }  if (inhibit_formatting)    {      p = buf_ptr;      do	putc (*p, output);      while (*p++ != '\n');    }}/* Copyright (C) 1976 by the Board of Trustees of the University of IllinoisAll rights reservedNAME: pad_outputFUNCTION: Writes tabs and spaces to move the current column up to the desired   position.ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf.PARAMETERS: current		integer		The current column target   nteger		The desired columnRETURNS: Integer value of the new column.  (If current >= target, no action   is taken, and current is returned.GLOBALS: NoneCALLS: write (sys)CALLED BY: dump_lineHISTORY: initial coding 	November 1976	D A Willcox of CAC */INLINE intpad_output (current, target)	/* writes tabs and blanks (if necessary) to				   get the current output position up to the				   target column */     int current;		/* the current column value */     int target;		/* position we want it at */{  register int curr;		/* internal column pointer */  register int tcur;  if (troff)    fprintf (output, "\\h'|%dp'", (target - 1) * 7);  else    {      if (current >= target)	return (current);	/* line is already long enough */      curr = current;      while ((tcur = curr + tabsize - (curr - 1) % tabsize) <= target)	{	  putc ('\t', output);	  curr = tcur;	}      while (curr++ < target)	putc (' ', output);	/* pad with final blanks */    }  return (target);}/* Copyright (C) 1976 by the Board of Trustees of the University of IllinoisAll rights reservedNAME: count_spacesFUNCTION: Find out where printing of a given string will leave the current   character position on output.ALGORITHM: Run thru input string and add appropriate values to current   position.RETURNS: Integer value of position after printing "buffer" starting in column   "current".HISTORY: initial coding 	November 1976	D A Willcox of CAC */INLINE intcount_spaces (current, buffer)     /* this routine figures out where the character position will be after        printing the text in buffer starting at column "current" */     int current;     char *buffer;{  register char *buf;		/* used to look thru buffer */  register int cur;		/* current character counter */  cur = current;  for (buf = buffer; *buf != '\0'; ++buf)    {      switch (*buf)	{	case '\n':	case 014:		/* form feed */	  cur = 1;	  break;	case '\t':	  cur = cur + tabsize - (cur - 1) % tabsize;	  break;	case 010:		/* backspace */	  --cur;	  break;	default:	  ++cur;	  break;	}			/* end of switch */    }				/* end of for loop */  return (cur);}/* Nonzero if we have found an error (not a warning).  */int found_err;/* Signal an error.  LEVEL is nonzero if it is an error (as opposed to a   warning.  MSG is a printf-style format string.  Additional arguments are   additional arguments for printf.  *//* VARARGS2 */diag (level, msg, a, b)     int level;     unsigned int a, b;     char *msg;{  if (level)    found_err = 1;  if (output == stdout)    {      fprintf (stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);      fprintf (stdout, msg, a, b);      fprintf (stdout, " */\n");    }  else    {      fprintf (stderr, "%s: %d: ", in_name, line_no);      fprintf (stderr, msg, a, b);      fprintf (stderr, "\n");    }}writefdef (f, nm)     register struct fstate *f;     unsigned int nm;{  fprintf (output, ".ds f%c %s\n.nr s%c %d\n",	   nm, f->font, nm, f->size);}/* Write characters starting at S to change the font from OF to NF.  Return a   pointer to the character after the last character written. For troff mode   only.  */char *chfont (of, nf, s)     register struct fstate *of, *nf;     char *s;{  if (of->font[0] != nf->font[0]      || of->font[1] != nf->font[1])    {      *s++ = '\\';      *s++ = 'f';      if (nf->font[1])	{	  *s++ = '(';	  *s++ = nf->font[0];	  *s++ = nf->font[1];	}      else	*s++ = nf->font[0];    }  if (nf->size != of->size)    {      *s++ = '\\';      *s++ = 's';      if (nf->size < of->size)	{	  *s++ = '-';	  *s++ = '0' + of->size - nf->size;	}      else	{	  *s++ = '+';	  *s++ = '0' + nf->size - of->size;	}    }  return s;}voidparsefont (f, s0)     register struct fstate *f;     char *s0;{  register char *s = s0;  int sizedelta = 0;  int i;  f->size = 0;  f->allcaps = 1;  for (i = 0; i < 4; i++)    f->font[i] = 0;  while (*s)    {      if (isdigit (*s))	f->size = f->size * 10 + *s - '0';      else if (isupper (*s))	if (f->font[0])	  f->font[1] = *s;	else	  f->font[0] = *s;      else if (*s == 'c')	f->allcaps = 1;      else if (*s == '+')	sizedelta++;      else if (*s == '-')	sizedelta--;      else	{	  fprintf (stderr, "indent: bad font specification: %s\n", s0);	  exit (1);	}      s++;    }  if (f->font[0] == 0)    f->font[0] = 'R';  if (bodyf.size == 0)    bodyf.size = 11;  if (f->size == 0)    f->size = bodyf.size + sizedelta;  else if (sizedelta > 0)    f->size += bodyf.size;  else    f->size = bodyf.size - f->size;}#ifdef DEBUGvoiddump_debug_line (){  fprintf (output, "\n*** Debug output marker line ***\n");}#endif

⌨️ 快捷键说明

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