Exemplo n.º 1
0
Whether the line is visible (if `selective-display' is t) has no effect.")
  ()
{
  Lisp_Object temp;
  XFASTINT (temp) = current_column ();
  return temp;
}
Exemplo n.º 2
0
int SCP_instance::exclude_a_column(int column_id)
{
	column_excluded[column_id] = true;
	set<int> &current_column((*columns)[column_id]);
	for (set<int>::iterator iterator1 = current_column.begin(); iterator1 != current_column.end(); iterator1++)
	{
		((*rows)[*iterator1]).erase(column_id);
	}
	((*columns)[column_id]).clear();
	return 0;
};
Exemplo n.º 3
0
void
print_comment ()
{
  register int column, format;
  enum codes comment_type;

  int start_column, found_column;
  int first_comment_line, right_margin;
  int boxed_comment, stars, blankline_delims, paragraph_break, merge_blank_comment_lines;

  int two_contiguous_comments = 0;
  int save_length = 0;
  char *save_ptr = 0;
  char *text_on_line = 0;
  char *line_break_ptr = 0;
  char *start_delim;

  char *line_preamble;
  int line_preamble_length, visible_preamble;
  int suppress_cdb = 0;

  /* GDB_HOOK_print_comment() */

  /* Increment the parser stack, as we will store some things
     there for dump_line to use. */
  inc_pstack ();

  /* Have to do it this way because this piece of shit program doesn't
     always place the last token code on the stack. */
  if (*(token + 1) == '/')
    comment_type = cplus_comment;
  else
    comment_type = comment;

  /* First, decide what kind of comment this is: C++, C, or boxed C.
     Even if this appears to be a normal C comment, we may change our
     minds if we find a star in the right column of the second line,
     in which case that's a boxed comment too. */
  if (comment_type == cplus_comment)
    {
      start_delim = "//";
      line_preamble = "// ";
      line_preamble_length = 3;
      visible_preamble = 1;
      boxed_comment = 0;
      stars = 0;
      blankline_delims = 0;
    }
  else if (*buf_ptr == '*' || *buf_ptr == '-' || *buf_ptr == '=' || *buf_ptr == '_'
	   || (parser_state_tos->col_1 && !format_col1_comments))
    /* Boxed comment.  This block of code will return. */
    {
      int comment_lines_count = 1;

      found_column = start_column = current_column () - 2;
      parser_state_tos->box_com = 1;
      parser_state_tos->com_col = found_column;

      if (blanklines_before_blockcomments)
	prefix_blankline_requested = 1;

      *e_com++ = '/';
      *e_com++ = '*';
      while (1)
	{
	  do
	    {
	      if (*buf_ptr == EOL)	/* Count line numbers within comment blocks */
		++line_no;
	      *e_com++ = *buf_ptr++;
	      CHECK_COM_SIZE;
	    }
	  while (*buf_ptr != '*' && buf_ptr < buf_end);

	  /* We have reached the end of the comment, and it's all on
	     this line. */
	  if (*buf_ptr == '*' && *(buf_ptr + 1) == '/')
	    {
	      if (buf_ptr == buf_end)
		fill_buffer ();

	      buf_ptr += 2;
	      if (buf_ptr == buf_end)
		fill_buffer ();

	      *e_com++ = '*';
	      *e_com++ = '/';
	      *e_com = '\0';
	      parser_state_tos->tos--;

	      /* If this is the only line of a boxed comment, it may
	         be after some other text (e.g., #if foo <comment>),
	         in which case we want to specify the correct column.
	         In the other cases, the leading spaces account for
	         the columns and we start it in column 1. */

	      if (comment_lines_count > 1)
		parser_state_tos->com_col = 1;
	      else
		parser_state_tos->com_col = found_column;
	      return;
	    }

	  /* End of the line, or end of file. */
	  if (buf_ptr == buf_end)
	    {
	      if (*(buf_ptr - 1) == EOL)
		{
		  *(--e_com) = '\0';
		  dump_line (true);
		  comment_lines_count++;
		  parser_state_tos->com_col = 1;
		}

	      fill_buffer ();
	      if (had_eof)
		{
		  *e_com++ = '\0';
		  parser_state_tos->tos--;
		  parser_state_tos->com_col = start_column;
		  return;
		}
	    }
	}
    }
  else
    {
      start_delim = "/*";
      line_preamble = 0;
      line_preamble_length = 0;
      visible_preamble = 0;
      boxed_comment = 0;
      stars = star_comment_cont;
      blankline_delims = comment_delimiter_on_blankline;
    }

  paragraph_break = 0;
  merge_blank_comment_lines = 0;
  first_comment_line = com_lines;
  right_margin = comment_max_col;

  /* Now, compute the correct indentation for this comment
     and whether or not it should be formatted. */
  found_column = current_column () - 2;

  if ((s_lab == e_lab) && (s_code == e_code))
    /* First handle comments which begin the line. */
    {
      if (parser_state_tos->col_1 && !format_col1_comments)
	{
	  format = format_col1_comments;
	  start_column = 1;
	}
      else if (s_com != e_com)
	/* The fool has a line consisting of two contiguous comments.
	   In this case, we don't try too hard, 'cause nothing will
	   look good. */
	{
	  format = 0;
	  start_column = found_column;
	  two_contiguous_comments = 1;
	}
      else
	{
	  format = format_comments;

	  if (parser_state_tos->ind_level <= 0
	      && (!parser_state_tos->in_stmt || (parser_state_tos->in_decl && parser_state_tos->paren_level == 0)))
	    start_column = found_column;
	  else
	    /* This comment is within a procedure or other code. */
	    {
	      start_column = compute_code_target () - unindent_displace;
	      if (start_column < 0)
		start_column = 1;
	    }
	}
    }
  else
    /* This comment follows code of some sort. */
    {
      int target;

      suppress_cdb = 1;

      /* First, compute where the comment SHOULD go. */
      if (parser_state_tos->decl_on_line)
	target = decl_com_ind;
      else if (else_or_endif)
	target = else_endif_col;
      else
	target = com_ind;

      /* Now determine if the code on the line is short enough
         to allow the comment to begin where it should. */
      if (s_code != e_code)
	start_column = count_columns (compute_code_target (), s_code, NULL_CHAR);
      else
	/* s_lab != e_lab : there is a label here. */
	start_column = count_columns (compute_label_target (), s_lab, NULL_CHAR);

      if (start_column < target)
	start_column = target;
      else
	{
	  /* If the too-long code is a pre-processor command,
	     start the comment 1 space afterwards, otherwise
	     start at the next tab mark. */
	  if (else_or_endif)
	    {
	      start_column++;
	      else_or_endif = false;
	    }
	  else
	    start_column += tabsize - ((start_column - 1) % tabsize);
	}

      format = format_comments;
    }

  if (!line_preamble)
    {
      line_preamble_length = 3;
      if (stars)
	{
	  line_preamble = " * ";
	  visible_preamble = 1;
	}
      else
	{
	  line_preamble = "   ";
	  visible_preamble = 0;
	}
    }

  /* These are the parser stack variables used to communicate
     formatting information to dump_line (). */
  parser_state_tos->com_col = (two_contiguous_comments ? 1 : start_column);
  parser_state_tos->box_com = boxed_comment;

  /* Output the beginning comment delimiter.  They are both two
     characters long. */
  *e_com++ = *start_delim;
  *e_com++ = *(start_delim + 1);
  column = start_column + 2;

  /* If the user specified -cdb, put the delimiter on one line. */
  if (blankline_delims && !suppress_cdb)
    {
      char *p = buf_ptr;

      *e_com = '\0';
      dump_line (true);

      /* Check if the delimiter was already on a line by itself,
         and skip whitespace if formating. */
      while (*p == ' ' || *p == TAB)
	p++;
      if (*p == EOL)
	buf_ptr = p + 1;
      else if (format)
	buf_ptr = p;
      if (buf_ptr >= buf_end)
	fill_buffer ();

      column = start_column;
      goto begin_line;
    }
  else if (format)
    {
      *e_com++ = ' ';
      column = start_column + 3;
      while (*buf_ptr == ' ' || *buf_ptr == TAB)
	if (++buf_ptr >= buf_end)
	  fill_buffer ();
    }

  /* Iterate through the lines of the comment */
  while (!had_eof)
    {
      /* Iterate through the characters on one line */
      while (!had_eof)
	{
	  CHECK_COM_SIZE;

	  switch (*buf_ptr)
	    {
	    case ' ':
	    case TAB:
	      /* If formatting, and previous break marker is
	         nonexistant, or before text on line, reset
	         it to here. */
	      if (format && line_break_ptr < text_on_line)
		line_break_ptr = e_com;

	      if (format)
		{
		  /* Don't write two spaces after another, unless the first space it preceeded by a dot. */
		  if (e_com == s_com || e_com[-1] != ' ' || e_com - 1 == s_com || e_com[-2] == '.')
		    {
		      *e_com++ = ' ';
		      column++;
		    }
		}
	      else if (*buf_ptr == ' ')
		{
		  *e_com++ = ' ';
		  column++;
		}
	      else
		{
		  /* Convert the tab to the appropriate number of spaces,
		     based on the column we found the comment in, not
		     the one we're printing in. */
		  int tab_width = (tabsize - ((column + found_column - start_column - 1) % tabsize));
		  column += tab_width;
		  while (tab_width--)
		    *e_com++ = ' ';
		}
	      break;

	    case EOL:
	      /* We may be at the end of a C++ comment */
	      if (comment_type == cplus_comment)
		{
		cplus_exit:
		  parser_state_tos->tos--;
		  parser_state_tos->com_col = (two_contiguous_comments ? 1 : start_column);
		  parser_state_tos->box_com = boxed_comment;
		  *e_com = 0;
		  return;
		}

	      if (format)
		{
		  /* Newline and null are the two characters which
		     end an input line, so check here if we need to
		     get the next line. */
		  if (*buf_ptr == EOL)
		    ++line_no;
		  buf_ptr++;
		  if (buf_ptr >= buf_end)
		    fill_buffer ();

		  /* If there are any spaces between the text and this
		     newline character, remove them. */
		  if (e_com > line_break_ptr && text_on_line < line_break_ptr)
		    e_com = line_break_ptr;

		  /* If this is "\n\n", or "\n<whitespace>\n",
		     it's a paragraph break. */
		  while (*buf_ptr == TAB || *buf_ptr == ' ')
		    if (++buf_ptr >= buf_end)
		      fill_buffer ();
		  if (*buf_ptr == EOL || !text_on_line)
		    {
		      paragraph_break = 1;
		      goto end_line;
		    }

		  /* Also need to eat the preamble. */
		  if (!boxed_comment && current_column () == found_column + 1 && buf_ptr[0] == '*' && buf_ptr[1] != '/')
		    {
		      if (++buf_ptr >= buf_end)
			fill_buffer ();
		      if (*buf_ptr == ' ' && ++buf_ptr >= buf_end)
			fill_buffer ();
		    }

		  /* This is a single newline.  Transform it (and any
		     following whitespace) into a single blank. */
		  if (e_com[-1] != ' ')
		    {
		      line_break_ptr = e_com;
		      *e_com++ = ' ';
		      column++;
		    }
		  continue;
		}

	      /* We are printing this line "as is", so output it
	         and continue on to the next line. */
	      goto end_line;

	    case '*':
	      /* Check if we've reached the end of the comment. */
	      if (comment_type == comment)
		{
		  if (*(buf_ptr + 1) == '/')
		    {
		      /* If it's not a boxed comment, put some whitespace
		         before the ending delimiter.  Otherwise, simply
		         insert the delimiter. */
		      if (!boxed_comment)
			{
			  if (text_on_line)
			    {
			      if (blankline_delims && !suppress_cdb)
				{
				  *e_com = '\0';
				  dump_line (true);
				  *e_com++ = ' ';
				}
			      else
				/* Insert space before closing delim */
			      if (*(e_com - 1) != ' ' && *(e_com - 1) != TAB)
				*e_com++ = ' ';
			    }
			  /* If no text on line, then line is completely empty
			     or starts with preamble, or is beginning of
			     comment and starts with beginning delimiter. */
			  else if (s_com == e_com || *s_com != '/')
			    {
			      e_com = s_com;
			      *e_com++ = ' ';
			    }
			  else
			    /* This is case of first comment line.  Test
			       with:
			       if (first_comment_line != com_lines)
			       abort (); */
			  if (*(e_com - 1) != ' ' && *(e_com - 1) != TAB)
			    *e_com++ = ' ';
			}

		      /* Now insert the ending delimiter */
		      *e_com++ = '*';
		      *e_com++ = '/';
		      *e_com = '\0';

		      /* Skip any whitespace following the comment.  If
		         there is only whitespace after it, print the line.

		         NOTE:  We're not printing the line: TRY IT! */
		      buf_ptr += 2;
		      while (*buf_ptr == ' ' || *buf_ptr == TAB)
			buf_ptr++;
		      if (buf_ptr >= buf_end)
			fill_buffer ();

		      parser_state_tos->tos--;
		      parser_state_tos->com_col = (two_contiguous_comments ? 1 : start_column);
		      parser_state_tos->box_com = boxed_comment;
		      return;
		    }

		  /* If this star is on the second line of the
		     comment in the same column as the star of the
		     beginning delimiter, then consider it
		     a boxed comment. */
		  if (first_comment_line == com_lines - 1 && e_com == s_com + line_preamble_length
		      && current_column () == found_column + 1)
		    {
		      /* Account for change in line_preamble_length: */
		      column -= line_preamble_length - 1;
		      line_preamble = " ";
		      line_preamble_length = 1;
		      boxed_comment = 1;
		      format = 0;
		      blankline_delims = 0;
		      *s_com = ' ';
		      *(s_com + 1) = '*';
		      text_on_line = e_com = s_com + 2;
		      column++;
		      break;
		    }
		}
	      /* If it was not the end of the comment, drop through
	         and insert the star on the line. */

	    default:
	      /* Some textual character. */
	      text_on_line = e_com;
	      *e_com++ = *buf_ptr;
	      column++;
	      break;
	    }


	  /* If we are formatting, check that we haven't exceeded the
	     line length.  If we haven't set line_break_ptr, keep going. */
	  if (format && column > right_margin && line_break_ptr)
	    {
	      if (line_break_ptr < e_com - 1)
		/* Here if we are really "breaking" the line:  the line
		   break is before some text we've seen. */
		{
		  *line_break_ptr = '\0';
		  save_ptr = line_break_ptr + 1;
		  save_length = e_com - save_ptr;
		  e_com = line_break_ptr;

		  /* If we had to go past `right_margin' to print stuff out,
		     extend `right_margin' out to this point. */
		  if ((column - save_length) > right_margin)
		    right_margin = column - save_length;
		}
	      else
		/* The line break is after the last text;  we're really
		   truncating the line. */
		{
		  if (comment_type == cplus_comment)
		    {
		      while (*buf_ptr == TAB || *buf_ptr == ' ')
			buf_ptr++;
		      buf_ptr--;
		      if (*buf_ptr == EOL)
			goto cplus_exit;
		    }
		  else
		    {
		      while (*buf_ptr == TAB || *buf_ptr == ' ' || *buf_ptr == EOL)
			buf_ptr++;

		      buf_ptr--;
		    }

		  *e_com = '\0';
		}
	      goto end_line;
	    }

	  if (*buf_ptr == EOL)
	    ++line_no;
	  buf_ptr++;
	  if (buf_ptr == buf_end)
	    fill_buffer ();
	}


    end_line:
      /* Compress pure whitespace lines into newlines. */
      if (!text_on_line && !visible_preamble && !(first_comment_line == com_lines))
	e_com = s_com;
      *e_com = '\0';
      dump_line (true);
      /* We're in the middle of a C-comment, don't add blank lines! */
      prefix_blankline_requested = 0;

      /* If formatting (paragraph_break is only used for formatted
         comments) and user wants blank lines merged, kill all white
         space after the "\n\n" indicating a paragraph break. */
      if (paragraph_break)
	{
	  if (merge_blank_comment_lines)
	    while (*buf_ptr == EOL || *buf_ptr == ' ' || *buf_ptr == TAB)
	      {
		if (*buf_ptr == EOL)
		  ++line_no;
		if (++buf_ptr >= buf_end)
		  fill_buffer ();
	      }
	  paragraph_break = 0;
	}
      else
	{
	  /* If it was a paragraph break (`if' clause), we scanned ahead
	     one character.  So, here in the `else' clause, advance buf_ptr. */
	  if (*buf_ptr == EOL)
	    ++line_no;
	  buf_ptr++;
	  if (buf_ptr >= buf_end)
	    fill_buffer ();
	}

    begin_line:
      if (had_eof)
	break;

      /* Indent the line properly.  If it's a boxed comment, align with
         the '*' in the beginning slash-star and start inserting there.
         Otherwise, insert blanks for alignment, or a star if the
         user specified -sc. */
      if (line_preamble)
	{
	  (void) memcpy (e_com, line_preamble, line_preamble_length);
	  e_com += line_preamble_length;
	  column = start_column + line_preamble_length;
	}
      else
	column = start_column;
      line_break_ptr = 0;

      /* If we have broken the line before the end for formatting,
         copy the text after the break onto the beginning of this
         new comment line. */
      if (save_ptr)
	{
	  while ((*save_ptr == ' ' || *save_ptr == TAB) && save_length)
	    {
	      save_ptr++;
	      save_length--;
	    }
	  (void) memcpy (e_com, save_ptr, save_length);
	  text_on_line = e_com;
	  e_com += save_length;
	  /* We only break if formatting, in which cases there
	     are no tabs, only spaces. */
	  column += save_length;
	  save_ptr = 0;
	  save_length = 0;
	}
      else
	{
	  while (*buf_ptr == ' ' || *buf_ptr == TAB)
	    if (++buf_ptr >= buf_end)
	      fill_buffer ();
	  text_on_line = 0;
	}
    }

  parser_state_tos->tos--;
  parser_state_tos->com_col = (two_contiguous_comments ? 1 : start_column);
  parser_state_tos->box_com = boxed_comment;
}
Exemplo n.º 4
0
DEFUN ("current-column", Fcurrent_column, 0, 1, 0, /*
Return the horizontal position of point.  Beginning of line is column 0.
This is calculated by adding together the widths of all the displayed
 representations of the character between the start of the previous line
 and point. (e.g. control characters will have a width of 2 or 4, tabs
 will have a variable width.)
Ignores finite width of frame, which means that this function may return
 values greater than (frame-width).
Whether the line is visible (if `selective-display' is t) has no effect;
 however, ^M is treated as end of line when `selective-display' is t.
If BUFFER is nil, the current buffer is assumed.
*/
       (buffer))
{
  return make_int (current_column (decode_buffer (buffer, 0)));
}


DEFUN ("indent-to", Findent_to, 1, 3, "NIndent to column: ", /*
Indent from point with tabs and spaces until COLUMN is reached.
Optional second argument MINIMUM says always do at least MINIMUM spaces
 even if that goes past COLUMN; by default, MINIMUM is zero.
If BUFFER is nil, the current buffer is assumed.
*/
       (column, minimum, buffer))
{
  /* This function can GC */
  int mincol;
  int fromcol;
  struct buffer *buf = decode_buffer (buffer, 0);
Exemplo n.º 5
0
static BOOLEAN search_brace(
    codes_ty       * type_code,
    BOOLEAN        * force_nl,
    BOOLEAN        * flushed_nl,
    BOOLEAN        * last_else,
    BOOLEAN        * is_procname_definition,
    BOOLEAN        * pbreak_line)
{
    int cur_token;

    while (parser_state_tos->search_brace)
    {
        /* After scanning an if(), while (), etc., it might be necessary to
         * keep track of the text between the if() and the start of the
         * statement which follows.  Use save_com to do so.
         */

        /* The saved buffer has space at the beginning to hold a brace if
         * needed and otherwise collects comments, separating them with newlines
         * if there are more than one.
         *
         * The process stops if we find a left brace or the beginning of a statement.
         *
         * A left brace is moved before any comments in a -br situation.  Otherwise,
         * it comes after comments.
         *
         * At the moment any form feeds before we get to braces or a statement are just
         * dropped.
         */
        cur_token = *type_code;
        switch (cur_token)
        {
        case newline:
            ++line_no;
            *flushed_nl = true;
            break;
        case form_feed:
            break;              /* form feeds and newlines found here will be
                                 * ignored */
        case lbrace:
            /* Ignore buffering if no comment stored. */

            if (save_com.end == save_com.ptr)
            {
                parser_state_tos->search_brace = false;
                return true;                                                            /* RETURN */
            }

            /* We need to put the '{' back into save_com somewhere.  */

            if (settings.btype_2 && (parser_state_tos->last_token != rbrace))
            {
                /* We are asking the brace to jump ahead of the comment.  In 
                 * the event that it was between two comments, the regression
                 * examples want to insert a newline to put the comments on 
                 * separate lines.  If it is followed by something not a 
                 * comment, we don't want to add a newline.
                 *
                 * To make that work, we'll put the brace up front and let the
                 * process continue to pick up another comment or not.
                 */

                save_com.ptr[0] = '{';
                save_com.len = 1;
                save_com.column = current_column ();
            }
            else
            {
                /* Put the brace at the end of the saved buffer, after
                 * a newline character.  The newline char will cause
                 * a `dump_line' call, thus ensuring that the brace
                 * will go into the right column. */

                *save_com.end++ = EOL;
                *save_com.end++ = '{';
                save_com.len += 2;

                /* Go to common code to get out of this loop.  */

                sw_buffer();
            }
            break;
                    
        case comment:
            /* Save this comment in the `save_com' buffer, for
             * possible re-insertion in the output stream later. */

            if (!*flushed_nl || (save_com.end != save_com.ptr))
            {
                need_chars (&save_com, 10);

                if (save_com.end == save_com.ptr)
                {
                    /* if this is the first comment, we must set
                     * up the buffer */

                    save_com.start_column = current_column ();
                    save_com.ptr[0] = save_com.ptr[1] = ' ';
                    save_com.end = save_com.ptr + 2;
                    save_com.len = 2;
                    save_com.column = current_column ();
                }
                else
                {
                    *save_com.end++ = EOL;      /* add newline between
                                                 * comments */
                    *save_com.end++ = ' ';
                    save_com.len += 2;
                    --line_no;
                }

                *save_com.end++ = '/';  /* copy in start of comment */
                *save_com.end++ = '*';

                for (;;)
                {
                    /* loop until we get to the end of the
                     * comment */

                    /* make sure there is room for this character and
                     * (while we're at it) the '/' we might add at the end
                     * of the loop. */
                        
                    need_chars (&save_com, 2);
                    *save_com.end = *buf_ptr++;
                    save_com.len++;

                    if (buf_ptr >= buf_end)
                    {
                        fill_buffer();

                        if (had_eof)
                        {
                            ERROR (_("EOF encountered in comment"), 0, 0);
                            return indent_punt;                               /* RETURN */
                        }
                    }

                    if (*save_com.end++ == '*' && *buf_ptr == '/')
                    {
                        break;  /* we are at end of comment */
                    }
                }

                *save_com.end++ = '/';  /* add ending slash */
                save_com.len++;

                if (++buf_ptr >= buf_end)       /* get past / in buffer */
                {
                    fill_buffer();
                }

                break;
            }

            /* Just some statement. */

        default:
            /* Some statement.  Unless it's special, arrange
             * to break the line. */

            if (((*type_code == sp_paren) && (*token == 'i') &&    /* "if" statement */
                 *last_else) ||
                ((*type_code == sp_else)  &&     /* "else" statement */
                 (e_code != s_code) && (e_code[-1] == '}') &&      /* The "else" follows '}' */
                 (save_com.end == save_com.ptr)))                  /* And we haven't found an 
                                                                    * intervening comment. */
            {
                *force_nl = false;
            }
            else if (*flushed_nl)
            {
                *force_nl = true;
            }
            else
            {
              /* what ? */
            }

            if (save_com.end == save_com.ptr)
            {
                /* ignore buffering if comment wasnt saved up */

                parser_state_tos->search_brace = false;
                return true;                                      /* RETURN */
            }

            if (*force_nl)
            {
                *force_nl = false;
                --line_no;      /* this will be re-increased when the nl is read from the buffer */
                need_chars (&save_com, 2);
                *save_com.end++ = EOL;
                save_com.len++;
                if (settings.verbose && !*flushed_nl)
                {
                    WARNING (_("Line broken"), 0, 0);
                }

                *flushed_nl = false;
            }

            /* Now copy this token we just found into the saved buffer. */

            *save_com.end++ = ' ';
            save_com.len++;
            buf_ptr = token;

            /* A total nightmare is created by trying to get the
             * next token into this save buffer.  Rather than that,
             * I've just backed up the buffer pointer to point
             * at `token'. --jla 9/95 */

            parser_state_tos->procname      = "\0";
            parser_state_tos->procname_end  = "\0";
            parser_state_tos->classname     = "\0";
            parser_state_tos->classname_end = "\0";

            /* Switch input buffers so that calls to lexi() will
             * read from our save buffer. */

            sw_buffer();
            break;
        }                   /* end of switch */

        if (*type_code != code_eof)
        {
            /* Read the next token */
            *type_code = lexi();

            /* Dump the line, if we just saw a newline, and:
             *
             * 1. The current token is a newline. - AND -
             * 2. The comment buffer is empty. - AND -
             * 3. The next token is a newline or comment. - AND -
             * 4. The previous token was a rbrace.
             *
             * This is needed to avoid indent eating newlines between
             * blocks like so:
             *
             * if (...) {
             *
             * }
             *
             * /comment here/
             * if (...)
             *
             * However, if there's a comment in the comment buffer, and the
             * next token is a newline, we'll just append a newline to the end
             * of the comment in the buffer, so that we don't lose it when
             * the comment is written out.
             */
            if (cur_token == newline &&
                (*type_code == newline || *type_code == comment) &&
                parser_state_tos->last_token == rbrace)
            {
                if (!save_com.len) {
                    dump_line(true, &paren_target, pbreak_line);
                    *flushed_nl = true;
                } else if (*type_code == newline) {
                    *save_com.end++ = EOL;
                    save_com.len++;
                }
           }

            *is_procname_definition = ((parser_state_tos->procname[0] != '\0') &&
                                       parser_state_tos->in_parameter_declaration);
        }

        if ((*type_code == ident) && *flushed_nl &&
            !settings.procnames_start_line &&
            parser_state_tos->in_decl &&
            (parser_state_tos->procname[0] != '\0'))
        {
            *flushed_nl = 0;
        }
    }                       /* end of while (search_brace) */

    *last_else = 0;

    return true;
}
Exemplo n.º 6
0
void SCP_instance::consistency_checking()
{
	/*check that the numbers within the rows and the columns are all legitimate*/
	for (int ii = 0; ii < number_of_rows; ii++)
	{
		set<int> &current_row((*rows)[ii]);
		for (set<int>::iterator iterator1= current_row.begin(); iterator1 != current_row.end(); iterator1 ++)
		{
			if (((*iterator1) >= number_of_columns) or ((*iterator1) < 0))
			{
				cout << "EXCEPTION: within SCP_instance::consistency_checking the number is invalid" << endl;
			}
		}
	}
	
	for (int ii = 0; ii < number_of_columns; ii++)
	{
		set<int> &current_column((*columns)[ii]);
		for (set<int>::iterator iterator1= current_column.begin(); iterator1 != current_column.end(); iterator1 ++)
		{
			if (((*iterator1) >= number_of_rows) or ((*iterator1) < 0))
			{
				cout << "EXCEPTION: within SCP_instance::consistency_checking the number is invalid" << endl;
			}
		}
	}
	
	/*check that none of the rows or columns are empty*/
	for (int ii = 0 ; ii < number_of_rows; ii++)
	{
		if (((*rows)[ii]).size() == 0)
		{
			cout << "EXCEPTION within SCP_instance::consistency_checking, an empty row" << endl;
		}
	}
	
	for (int ii = 0 ; ii < number_of_columns; ii++)
	{
		if (((*columns)[ii]).size() == 0 )
		{
			cout << "EXCEPTION within SCP_instance::consistency_checking, an empty column" << endl;
		}		
	}
									
	/*check that the rows and the columns are consistent with one another, and none of them are empty*/
	for (int ii = 0 ; ii < number_of_rows; ii ++)
	{
		set<int> & current_row((*rows)[ii]);
		for (set<int>::iterator iterator1 = current_row.begin(); iterator1 != current_row.end(); iterator1++)
		{
			if (((*columns)[*iterator1]).find(ii) == ((*columns)[*iterator1]).end())
			{
				cout << "ERROR, rows is not consistent with columns" << endl;
			}
		}
	}
	
	for (int ii = 0 ; ii < number_of_columns; ii ++)
	{
		set<int> & current_column((*columns)[ii]);
		for (set<int>::iterator iterator1 = current_column.begin(); iterator1 != current_column.end(); iterator1++)
		{
			if (((*rows)[*iterator1]).find(ii) == ((*rows)[*iterator1]).end())
			{
				cout << "ERROR, rows is not consistent with columns" << endl;
			}
		}
	}
	
};
Exemplo n.º 7
0
int SCP_instance::find_set_cover_best_of_LR_and_greedy_with_preprocessing(int &lower_bound, int &cost, vector<int> &solution, LR_Types lr_type)
{
	execute_exact_heuristic();
	/*construct a new column set*/
	vector<int> new_columns_set;
	for (int ii = 0 ; ii < number_of_columns; ii++)
	{
		if ( (not column_chosen[ii]) and (not column_excluded[ii]) and (not ((*columns)[ii]).size() == 0) )
		{
			new_columns_set.push_back(ii);
		}
	}
	vector<int> new_rows_set;
	for (int ii = 0 ; ii < number_of_rows ; ii ++)
	{
		if ( (not row_covered[ii]) and ( not row_excluded[ii]) and (not (((*rows)[ii]).size()==0)))
		{
			new_rows_set.push_back(ii);
		}
	}
	vector<int> reverse_row_id_mapping(number_of_rows, -1);
	for (int ii = 0 ; ii < new_rows_set.size(); ii ++)
	{
		reverse_row_id_mapping[new_rows_set[ii]] = ii;
	}
	
	vector<set<int> > * tmp_columns = new vector<set<int> >(new_columns_set.size(), set<int>());
	vector<set<int> > * tmp_rows = new vector<set<int> >(new_rows_set.size(), set<int>());
	for (int ii = 0 ; ii < new_columns_set.size(); ii++)
	{
		set<int> &current_column((*columns)[new_columns_set[ii]]);
		for (set<int>::iterator iterator1 = current_column.begin(); iterator1 != current_column.end(); iterator1 ++)
		{
			int jj = reverse_row_id_mapping[*iterator1];
			if (jj == -1)
			{
				cout << "ERROR! in find_set_cover, row_id is not mapped" <<endl;
			}
			(*tmp_columns)[ii].insert(jj);
			(*tmp_rows)[jj].insert(ii);
		}
	}
	
	/*check that each row is covered by at least one column*/
	for (int ii = 0 ; ii < tmp_rows->size(); ii++)
	{
		if (((*tmp_rows)[ii]).size() == 0)
		{
			cout << "ERROR!  some row is not covered by the reduced set" << endl;
		}
	}
	
	/*Call LR to solve this problem*/
	LR_SCP_instance tmp_lr_scp_instance(tmp_rows, tmp_columns);
	tmp_rows = NULL;
	tmp_columns = NULL; //tmp_lr_scp_instance will take care of the two instances
	
	int current_lower_bound = 0 ;
	int current_cost = 0;
	vector<int> current_solution ;
	
	tmp_lr_scp_instance.find_set_cover_LR(current_lower_bound, current_cost, current_solution, lr_type);

	
	/*combine the lr solution for the problem core with the solution obtained by exact heuristic and return the solution to the caller function*/
	lower_bound = this->lower_bound + current_lower_bound;
	cost = 0 ;
	solution.clear();
	for (int ii = 0 ; ii < current_solution.size(); ii ++)
	{
		solution.push_back(new_columns_set[current_solution[ii]]);
		cost = cost + 1;
	}
	
	for (int ii = 0 ; ii < number_of_columns; ii ++)
	{
		if (column_chosen[ii])
		{
			cost = cost + 1;
			solution.push_back(ii);
		}
	}
	
	return 0;
}