+/* Jump over a comment, assuming we are at the beginning of one.
+ FROM is the current position.
+ FROM_BYTE is the bytepos corresponding to FROM.
+ Do not move past STOP (a charpos).
+ The comment over which we have to jump is of style STYLE
+ (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
+ NESTING should be positive to indicate the nesting at the beginning
+ for nested comments and should be zero or negative else.
+ ST_COMMENT_STYLE cannot be nested.
+ PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
+ (or 0 If the search cannot start in the middle of a two-character).
+
+ If successful, return 1 and store the charpos of the comment's end
+ into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
+ Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
+ corresponding bytepos into *BYTEPOS_PTR and the current nesting
+ (as defined for state.incomment) in *INCOMMENT_PTR.
+
+ The comment end is the last character of the comment rather than the
+ character just after the comment.
+
+ Global syntax data is assumed to initially be valid for FROM and
+ remains valid for forward search starting at the returned position. */
+
+static int
+forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
+ charpos_ptr, bytepos_ptr, incomment_ptr)
+ int from, from_byte, stop;
+ int nesting, style, prev_syntax;
+ int *charpos_ptr, *bytepos_ptr, *incomment_ptr;
+{
+ register int c, c1;
+ register enum syntaxcode code;
+ register int syntax;
+
+ if (nesting <= 0) nesting = -1;
+
+ /* Enter the loop in the middle so that we find
+ a 2-char comment ender if we start in the middle of it. */
+ syntax = prev_syntax;
+ if (syntax != 0) goto forw_incomment;
+
+ while (1)
+ {
+ if (from == stop)
+ {
+ *incomment_ptr = nesting;
+ *charpos_ptr = from;
+ *bytepos_ptr = from_byte;
+ return 0;
+ }
+ c = FETCH_CHAR (from_byte);
+ syntax = SYNTAX_WITH_FLAGS (c);
+ code = syntax & 0xff;
+ if (code == Sendcomment
+ && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
+ && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
+ (nesting > 0 && --nesting == 0) : nesting < 0))
+ /* we have encountered a comment end of the same style
+ as the comment sequence which began this comment
+ section */
+ break;
+ if (code == Scomment_fence
+ && style == ST_COMMENT_STYLE)
+ /* we have encountered a comment end of the same style
+ as the comment sequence which began this comment
+ section. */
+ break;
+ if (nesting > 0
+ && code == Scomment
+ && SYNTAX_FLAGS_COMMENT_NESTED (syntax)
+ && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style)
+ /* we have encountered a nested comment of the same style
+ as the comment sequence which began this comment section */
+ nesting++;
+ INC_BOTH (from, from_byte);
+ UPDATE_SYNTAX_TABLE_FORWARD (from);
+
+ forw_incomment:
+ if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax)
+ && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
+ && (c1 = FETCH_CHAR (from_byte),
+ SYNTAX_COMEND_SECOND (c1))
+ && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
+ SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0))
+ {
+ if (--nesting <= 0)
+ /* we have encountered a comment end of the same style
+ as the comment sequence which began this comment
+ section */
+ break;
+ else
+ {
+ INC_BOTH (from, from_byte);
+ UPDATE_SYNTAX_TABLE_FORWARD (from);
+ }
+ }
+ if (nesting > 0
+ && from < stop
+ && SYNTAX_FLAGS_COMSTART_FIRST (syntax)
+ && (c1 = FETCH_CHAR (from_byte),
+ SYNTAX_COMMENT_STYLE (c1) == style
+ && SYNTAX_COMSTART_SECOND (c1))
+ && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
+ SYNTAX_COMMENT_NESTED (c1)))
+ /* we have encountered a nested comment of the same style
+ as the comment sequence which began this comment
+ section */
+ {
+ INC_BOTH (from, from_byte);
+ UPDATE_SYNTAX_TABLE_FORWARD (from);
+ nesting++;
+ }
+ }
+ *charpos_ptr = from;
+ *bytepos_ptr = from_byte;
+ return 1;
+}
+