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

📄 io.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 * HISTORY: initial coding 	November 1976	D A Willcox of CAC 1/7/77 A * Willcox of CAC	Added check for switch back to partly full input * buffer from temporary buffer * */voidfill_buffer(){					/* this routine reads stuff					   from the input */   register char  *p;   register int    i;   register FILE  *f = input;   if (bp_save != 0)   {					/* there is a partly filled					   input buffer left */      buf_ptr = bp_save;		/* dont read anything, just					   switch buffers */      buf_end = be_save;      bp_save = be_save = 0;      if (buf_ptr < buf_end)	 return;			/* only return if there is					   really something in this					   buffer */   }   for (p = buf_ptr = in_buffer;;)   {      if ((i = getc(f)) == EOF)      {	 *p++ = ' ';	 *p++ = '\n';	 had_eof = true;	 break;      }      *p++ = (char)i;      if (i == '\n')	 break;   }   buf_end = p;   if (p[-2] == '/' && p[-3] == '*')   {      if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)	 fill_buffer();			/* flush indent error message */      else      {	 int             com = 0;	 p = in_buffer;	 while (*p == ' ' || *p == '\t')	    p++;	 if (*p == '/' && p[1] == '*')	 {	    p += 2;	    while (*p == ' ' || *p == '\t')	       p++;	    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 = 1;	       else if (*p == 'O')		  if (*++p == 'N')		     p++, com = 1;		  else if (*p == 'F' && *++p == 'F')		     p++, com = 2;	       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 = com - 1))		  {		     n_real_blanklines = 0;		     postfix_blankline_requested = 0;		     prefix_blankline_requested = 0;		     suppress_blanklines = 1;		  }	       }	    }	 }      }   }   if (inhibit_formatting)   {      p = in_buffer;      do	 putc(*p, output);      while (*p++ != '\n');   }   return;}/* * Copyright (C) 1976 by the Board of Trustees of the University of Illinois * * All rights reserved * * * NAME: pad_output * * FUNCTION: 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 column * * RETURNS: Integer value of the new column.  (If current >= target, no action * is taken, and current is returned. * * GLOBALS: None * * CALLS: write (sys) * * CALLED BY: dump_line * * HISTORY: initial coding 	November 1976	D A Willcox of CAC * */int pad_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 - 1) & tabmask) + tabsize + 1) <= 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 Illinois * * All rights reserved * * * NAME: count_spaces * * FUNCTION: 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 * */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 - 1) & tabmask) + tabsize + 1;	 break;      case '':				/* this is a backspace */	 --cur;	 break;      default:	 ++cur;	 break;      }					/* end of switch */   }					/* end of for loop */   return (cur);}int             found_err;void diag(level, msg, a, b)int level;char *msg;int a, b;{   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: ", level == 0 ? "Warning" : "Error", line_no);      fprintf(stderr, msg, a, b);      fprintf(stderr, "\n");   }}void writefdef(f, nm)   register struct fstate *f;   int nm;{   fprintf(output, ".ds f%c %s\n.nr s%c %d\n",	   nm, f->font, nm, f->size);}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++ = (char)'0' + of->size - nf->size;      } else      {	 *s++ = '+';	 *s++ = (char)'0' + nf->size - of->size;      }   }   return s;}void parsefont(f, s0)   register struct fstate *f;   char           *s0;{   register char  *s = s0;   int             sizedelta = 0;   memset(f, '\0', sizeof *f);   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;}

⌨️ 快捷键说明

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