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

📄 indent.c

📁 GNU 系统开发优化 C 语言程序的应用程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	  parser_state_tos->in_stmt = false;	/* dont indent the {} */	  if (!parser_state_tos->block_init)	    force_nl = true;	/* force other stuff on same line as '{' onto				   new line */	  else if (parser_state_tos->block_init_level <= 0)	    parser_state_tos->block_init_level = 1;	  else	    parser_state_tos->block_init_level++;	  if (s_code != e_code && !parser_state_tos->block_init)	    {	      if (!btype_2)		{		  dump_line ();		  parser_state_tos->want_blank = false;		}	      else		{		  if (parser_state_tos->in_parameter_declaration		      && !parser_state_tos->in_or_st)		    {		      parser_state_tos->i_l_follow = 0;		      dump_line ();		      parser_state_tos->want_blank = false;		    }		  else		    parser_state_tos->want_blank = true;		}	    }	  if (parser_state_tos->in_parameter_declaration)	    prefix_blankline_requested = 0;#if 0	/* Changed to allow "{}" inside parens, as when	   passed to a macro.  -jla */	  if (parser_state_tos->p_l_follow > 0)	    {			/* check for preceeding unbalanced parens */	      diag (1, "Unbalanced parens", 0, 0);	      parser_state_tos->p_l_follow = 0;	      if (sp_sw)		{		/* check for unclosed if, for, etc. */		  sp_sw = false;		  parse (hd_type);		  parser_state_tos->ind_level = parser_state_tos->i_l_follow;		}	    }#endif	  if (s_code == e_code)	    parser_state_tos->ind_stmt = false;	/* dont put extra indentation						   on line with '{' */	  if (parser_state_tos->in_decl && parser_state_tos->in_or_st)	    {	      /* This is a structure declaration.  */	      if (parser_state_tos->dec_nest >= di_stack_alloc)		{		  di_stack_alloc *= 2;		  di_stack = (int *)		    xrealloc ((char *) di_stack,			      di_stack_alloc * sizeof (*di_stack));		}	      di_stack[parser_state_tos->dec_nest++] = dec_ind;	      /* ?		dec_ind = 0; */	    }	  else	    {	      parser_state_tos->in_decl = false;	      parser_state_tos->decl_on_line = false;	/* we cant be in the							   middle of a							   declaration, so dont							   do special							   indentation of							   comments */#if 0				/* Doesn't work currently. */	      if (blanklines_after_declarations_at_proctop		  && parser_state_tos->in_parameter_declaration)		postfix_blankline_requested = 1;#endif	      parser_state_tos->in_parameter_declaration = 0;	    }	  dec_ind = 0;	  /* We are no longer looking for an initializer or structure. Needed	     so that the '=' in "enum bar {a = 1" does not get interpreted as	     the start of an initializer.  */	  parser_state_tos->in_or_st = false;	  parse (lbrace);	/* let parser know about this */	  if (parser_state_tos->want_blank)	/* put a blank before '{' if						   '{' is not at start of						   line */	    *e_code++ = ' ';	  parser_state_tos->want_blank = false;	  *e_code++ = '{';	  parser_state_tos->just_saw_decl = 0;	  break;	case rbrace:		/* got a '}' */	  /* semicolons can be omitted in declarations */	  if (parser_state_tos->p_stack[parser_state_tos->tos] == decl	      && !parser_state_tos->block_init)	    parse (semicolon);#if 0	/* Changed to allow "{}" inside parens, as when	   passed to a macro.  -jla */	  if (parser_state_tos->p_l_follow)	    {			/* check for unclosed if, for, else. */	      diag (1, "Unbalanced parens", 0, 0);	      parser_state_tos->p_l_follow = 0;	      sp_sw = false;	    }#endif	  parser_state_tos->just_saw_decl = 0;	  parser_state_tos->block_init_level--;	  if (s_code != e_code && !parser_state_tos->block_init)	    {			/* '}' must be first on line */	      if (verbose)		diag (0, "Line broken", 0, 0);	      dump_line ();	    }	  *e_code++ = '}';	  parser_state_tos->want_blank = true;	  parser_state_tos->in_stmt = parser_state_tos->ind_stmt = false;	  if (parser_state_tos->dec_nest > 0)	    {			/* we are in multi-level structure				   declaration */	      dec_ind = di_stack[--parser_state_tos->dec_nest];	      if (parser_state_tos->dec_nest == 0		  && !parser_state_tos->in_parameter_declaration)		parser_state_tos->just_saw_decl = 2;	      parser_state_tos->in_decl = true;	    }	  prefix_blankline_requested = 0;	  parse (rbrace);	/* let parser know about this */	  parser_state_tos->search_brace	    = (cuddle_else	     && parser_state_tos->p_stack[parser_state_tos->tos] == ifhead);	  if ((parser_state_tos->p_stack[parser_state_tos->tos] == stmtl	       && ((parser_state_tos->last_rw != rw_struct_like		    && parser_state_tos->last_rw != rw_decl)		   || ! btype_2))	      || (parser_state_tos->p_stack[parser_state_tos->tos] == ifhead)	      || (parser_state_tos->p_stack[parser_state_tos->tos] == dohead		  && !btype_2))	    force_nl = true;	  else if (parser_state_tos->tos <= 1		   && blanklines_after_procs		   && parser_state_tos->dec_nest <= 0)	    postfix_blankline_requested = 1;#if 0	  parser_state_tos->search_brace	    = (cuddle_else	       && parser_state_tos->p_stack[parser_state_tos->tos] == ifhead	       && (parser_state_tos->il[parser_state_tos->tos]		   >= parser_state_tos->ind_level));#endif	  break;	case swstmt:		/* got keyword "switch" */	  sp_sw = true;	  hd_type = swstmt;	/* keep this for when we have seen the				   expression */	  parser_state_tos->in_decl = false;	  goto copy_id;		/* go move the token into buffer */	case sp_paren:		/* token is if, while, for */	  sp_sw = true;		/* the interesting stuff is done after the				   expression is scanned */	  hd_type = (*token == 'i' ? ifstmt :		     (*token == 'w' ? whilestmt : forstmt));	  /* remember the type of header for later use by parser */	  goto copy_id;		/* copy the token into line */	case sp_nparen:	/* got else, do */	  parser_state_tos->in_stmt = false;	  if (*token == 'e')	    {	      if (e_code != s_code && (!cuddle_else || e_code[-1] != '}'))		{		  if (verbose)		    diag (0, "Line broken", 0, 0);		  dump_line ();	/* make sure this starts a line */		  parser_state_tos->want_blank = false;		}	      force_nl = true;	/* also, following stuff must go onto new				   line */	      last_else = 1;	      parse (elselit);	    }	  else	    {	      if (e_code != s_code)		{		/* make sure this starts a line */		  if (verbose)		    diag (0, "Line broken", 0, 0);		  dump_line ();		  parser_state_tos->want_blank = false;		}	      force_nl = true;	/* also, following stuff must go onto new				   line */	      last_else = 0;	      parse (dolit);	    }	  goto copy_id;		/* move the token into line */	case decl:		/* we have a declaration type (int, register,				   etc.) */	  if (! parser_state_tos->sizeof_mask)	    parse (decl);	  if (parser_state_tos->last_token == rparen	      && parser_state_tos->tos <= 1)	    {	      parser_state_tos->in_parameter_declaration = 1;	      if (s_code != e_code)		{		  dump_line ();		  parser_state_tos->want_blank = false;		}	    }	  if (parser_state_tos->in_parameter_declaration	      && indent_parameters	      && parser_state_tos->dec_nest == 0	      && parser_state_tos->p_l_follow == 0)	    {	      parser_state_tos->ind_level		= parser_state_tos->i_l_follow = indent_parameters;	      parser_state_tos->ind_stmt = 0;	    }	  /* in_or_st set for struct or initialization decl. Don't set it if	     we're in ansi prototype */	  if (!parser_state_tos->paren_depth)	    parser_state_tos->in_or_st = true;	  parser_state_tos->in_decl = parser_state_tos->decl_on_line = true;#if 0	  if (!parser_state_tos->in_or_st && parser_state_tos->dec_nest <= 0)#endif	    if (parser_state_tos->dec_nest <= 0)	      parser_state_tos->just_saw_decl = 2;	  if (prefix_blankline_requested	      && (parser_state_tos->block_init != 0		  || parser_state_tos->block_init_level != -1		  || parser_state_tos->last_token != rbrace		  || e_code != s_code		  || e_lab != s_lab		  || e_com != s_com))	    prefix_blankline_requested = 0;	  i = token_end - token + 1;	/* get length of token plus 1 */	  /* dec_ind = e_code - s_code + (parser_state_tos->decl_indent>i ?	     parser_state_tos->decl_indent : i); */	  dec_ind = decl_indent > 0 ? decl_indent : i;	  goto copy_id;	case ident:		/* got an identifier or constant */	  /* If we are in a declaration, we must indent identifier. But not	     inside the parentheses of an ANSI function declaration.  */	  if (parser_state_tos->in_decl	      && parser_state_tos->p_l_follow == 0	      && parser_state_tos->last_token != rbrace)	    {	      if (parser_state_tos->want_blank)		*e_code++ = ' ';	      parser_state_tos->want_blank = false;	      if (is_procname == 0 || !procnames_start_line)		{		  if (!parser_state_tos->block_init)		    if (troff && !parser_state_tos->dumped_decl_indent)		      {			sprintf (e_code, "\n.De %dp+\200p\n",				 (int) (dec_ind * 7));			parser_state_tos->dumped_decl_indent = 1;			e_code += strlen (e_code);		      }		    else		      while ((e_code - s_code) < dec_ind)			{			  CHECK_CODE_SIZE;			  *e_code++ = ' ';			}		}	      else		{		  if (dec_ind && s_code != e_code)		    dump_line ();		  dec_ind = 0;		  parser_state_tos->want_blank = false;		}	    }	  else if (sp_sw && parser_state_tos->p_l_follow == 0)	    {	      sp_sw = false;	      force_nl = true;	      parser_state_tos->last_u_d = true;	      parser_state_tos->in_stmt = false;	      parse (hd_type);	    }	copy_id:	  if (parser_state_tos->want_blank)	    *e_code++ = ' ';	  if (troff && parser_state_tos->its_a_keyword)	    {	      e_code = chfont (&bodyf, &keywordf, e_code);	      for (t_ptr = token; t_ptr < token_end; ++t_ptr)		{		  CHECK_CODE_SIZE;		  *e_code++ = keywordf.allcaps && islower (*t_ptr)		    ? toupper (*t_ptr) : *t_ptr;		}	      e_code = chfont (&keywordf, &bodyf, e_code);	    }	  else	    {	      /* Troff mode requires that strings be processed specially.  */	      if (troff && (*token == '"' || *token == '\''))		{		  char qchar;		  qchar = *token;		  *e_code++ = '`';		  if (qchar == '"')		    *e_code++ = '`';		  e_code = chfont (&bodyf, &stringf, e_code);		  t_ptr = token + 1;		  while (t_ptr < token_end)		    {		      *e_code = *t_ptr++;		      if (*e_code == '\\')			{			  *++e_code = '\\';			  if (*t_ptr == '\\')			    *++e_code = '\\';			  /* Copy char after backslash.  */			  *++e_code = *t_ptr++;			  /* Point after the last char we copied.  */			  e_code++;			}		    }		  e_code = chfont (&stringf, &bodyf, e_code - 1);		  if (qchar == '"')		    *e_code++ = '\'';		}	      else		for (t_ptr = token; t_ptr < token_end; ++t_ptr)		  {		    CHECK_CODE_SIZE;		    *e_code++ = *t_ptr;		  }	    }	  parser_state_tos->want_blank = true;	  /* If the token is va_dcl, it appears without a semicolon, so we	     need to pretend that one was there.  */	  if ((token_end - token) == 6	      && strncmp (token, "va_dcl", 6) == 0)	    {	      parser_state_tos->in_or_st = false;	      parser_state_tos->just_saw_decl--;	      parser_state_tos->in_decl = 0;	      parse (semicolon);	      force_nl = true;	    }	  break;	case period:		/* treat a period kind of like a binary				   operation */	  *e_code++ = '.';	/* move the period into line */	  parser_state_tos->want_blank = false;	/* dont put a blank after a						   period */	  break;	case comma:	  /* only put blank after comma if comma does not start the line */	  parser_state_tos->want_blank = (s_code != e_code);	  if (parser_state_tos->paren_depth == 0	      && parser_state_tos->in_decl	      && is_procname == 0	      && !parser_state_tos->block_init)	    while ((e_code - s_code) < (dec_ind - 1))	      {		CHECK_CODE_SIZE;		*e_code++ = ' ';	      }	  *e_code++ = ',';	  if (parser_state_tos->p_l_follow == 0)	    {	      if (parser_state_tos->block_init_level <= 0)		parser_state_tos->block_init = 0;	      /* If we are in a declaration, and either the user wants all	         comma'd declarations broken, or the line is getting too	         long, break the line.  */	      if (break_comma &&		  (!leave_comma		   || (compute_code_target () + (e_code - s_code)		       > max_col - tabsize)))		force_nl = true;	    }	  break;	case preesc:		/* got the character '#' */	  if ((s_com != e_com) ||	      (s_lab != e_lab) ||	      (s_code != e_code))	    dump_line ();	  {	    int in_comment = 0;	    int in_cplus_comment = 0;	    int com_start = 0;	    char quote = 0;	    int com_end = 0;	    /* ANSI allows spaces between '#' and preprocessor directives.	       Remove such spaces unless user has specified "-lps", in	       which case also leave any space preceeding the '#'. */	    if (leave_preproc_space)	      {		char *p = cur_line;		while (p < buf_ptr)		  *e_lab++ = *p++;		while (*buf_ptr == ' ' || *buf_ptr == TAB)		  {		    *e_lab++ = *buf_ptr++;		    if (buf_ptr >= buf_end)		      fill_buffer ();		  }	      }	    else	      {		*e_lab++ = '#';		while (*buf_ptr == ' ' || *buf_ptr == TAB)		  if (++buf_ptr >= buf_end)		    fill_buffer ();	      }	    while (*buf_ptr != EOL || (in_comment && !had_eof))	      {		CHECK_LAB_SIZE;		*e_lab = *buf_ptr++;		if (buf_ptr >= buf_end)		  fill_buffer ();		switch (*e_lab++)		  {		  case BACKSLASH:		    if (troff)		      *e_lab++ = BACKSLASH;

⌨️ 快捷键说明

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