[BACK]Return to pr_comment.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / indent

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/indent/pr_comment.c between version 1.57 and 1.58

version 1.57, 2021/10/07 21:57:21 version 1.58, 2021/10/07 23:15:15
Line 105  process_comment(void)
Line 105  process_comment(void)
         ps.com_col = 1;          ps.com_col = 1;
   
     } else {      } else {
         if (*buf_ptr == '-' || *buf_ptr == '*' || token.e[-1] == '/' ||          if (*inp.s == '-' || *inp.s == '*' || token.e[-1] == '/' ||
             (*buf_ptr == '\n' && !opt.format_block_comments)) {              (*inp.s == '\n' && !opt.format_block_comments)) {
             ps.box_com = true;  /* A comment with a '-' or '*' immediately              ps.box_com = true;  /* A comment with a '-' or '*' immediately
                                  * after the /+* is assumed to be a boxed                                   * after the /+* is assumed to be a boxed
                                  * comment. A comment with a newline                                   * comment. A comment with a newline
Line 150  process_comment(void)
Line 150  process_comment(void)
          * much will have to be ignored by dump_line(). This is a box comment,           * much will have to be ignored by dump_line(). This is a box comment,
          * so nothing changes -- not even indentation.           * so nothing changes -- not even indentation.
          *           *
          * The comment we're about to read usually comes from in_buffer,           * The comment we're about to read usually comes from inp.buf,
          * unless it has been copied into save_com.           * unless it has been copied into save_com.
          */           */
         const char *start;          const char *start;
Line 159  process_comment(void)
Line 159  process_comment(void)
          * XXX: ordered comparison between pointers from different objects           * XXX: ordered comparison between pointers from different objects
          * invokes undefined behavior (C99 6.5.8).           * invokes undefined behavior (C99 6.5.8).
          */           */
         start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ?          start = inp.s >= save_com && inp.s < save_com + sc_size ?
             sc_buf : in_buffer;              sc_buf : inp.buf;
         ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);          ps.n_comment_delta = -indentation_after_range(0, start, inp.s - 2);
     } else {      } else {
         ps.n_comment_delta = 0;          ps.n_comment_delta = 0;
         while (is_hspace(*buf_ptr))          while (is_hspace(*inp.s))
             buf_ptr++;              inp.s++;
     }      }
   
     ps.comment_delta = 0;      ps.comment_delta = 0;
     *com.e++ = '/';      *com.e++ = '/';
     *com.e++ = token.e[-1];      *com.e++ = token.e[-1];
     if (*buf_ptr != ' ' && !ps.box_com)      if (*inp.s != ' ' && !ps.box_com)
         *com.e++ = ' ';          *com.e++ = ' ';
   
     /* Don't put a break delimiter if this is a one-liner that won't wrap. */      /* Don't put a break delimiter if this is a one-liner that won't wrap. */
     if (break_delim) {      if (break_delim) {
         for (t_ptr = buf_ptr; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {          for (t_ptr = inp.s; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {
             if (t_ptr >= buf_end)              if (t_ptr >= inp.e)
                 fill_buffer();                  fill_buffer();
             if (t_ptr[0] == '*' && t_ptr[1] == '/') {              if (t_ptr[0] == '*' && t_ptr[1] == '/') {
                 /*                  /*
Line 186  process_comment(void)
Line 186  process_comment(void)
                  * out since they are equally long.                   * out since they are equally long.
                  */                   */
                 int right_margin = indentation_after_range(ps.com_col - 1,                  int right_margin = indentation_after_range(ps.com_col - 1,
                     buf_ptr, t_ptr + 2);                      inp.s, t_ptr + 2);
                 if (right_margin < adj_max_line_length)                  if (right_margin < adj_max_line_length)
                     break_delim = false;                      break_delim = false;
                 break;                  break;
Line 210  process_comment(void)
Line 210  process_comment(void)
   
     for (;;) {                  /* this loop will go until the comment is      for (;;) {                  /* this loop will go until the comment is
                                  * copied */                                   * copied */
         switch (*buf_ptr) {     /* this checks for various special cases */          switch (*inp.s) {       /* this checks for various special cases */
         case '\f':          case '\f':
             check_size_comment(3);              check_size_comment(3);
             if (!ps.box_com) {  /* in a text comment, break the line here */              if (!ps.box_com) {  /* in a text comment, break the line here */
Line 219  process_comment(void)
Line 219  process_comment(void)
                 last_blank = -1;                  last_blank = -1;
                 if (!ps.box_com && opt.star_comment_cont)                  if (!ps.box_com && opt.star_comment_cont)
                     *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';                      *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
                 buf_ptr++;                  inp.s++;
                 while (is_hspace(*buf_ptr))                  while (is_hspace(*inp.s))
                     buf_ptr++;                      inp.s++;
             } else {              } else {
                 inbuf_skip();                  inbuf_skip();
                 *com.e++ = '\f';                  *com.e++ = '\f';
Line 267  process_comment(void)
Line 267  process_comment(void)
                 do {            /* flush any blanks and/or tabs at start of                  do {            /* flush any blanks and/or tabs at start of
                                  * next line */                                   * next line */
                     inbuf_skip();                      inbuf_skip();
                     if (*buf_ptr == '*' && --asterisks_to_skip >= 0) {                      if (*inp.s == '*' && --asterisks_to_skip >= 0) {
                         inbuf_skip();                          inbuf_skip();
                         if (*buf_ptr == '/')                          if (*inp.s == '/')
                             goto end_of_comment;                              goto end_of_comment;
                     }                      }
                 } while (is_hspace(*buf_ptr));                  } while (is_hspace(*inp.s));
             } else              } else
                 inbuf_skip();                  inbuf_skip();
             break;              /* end of case for newline */              break;              /* end of case for newline */
Line 280  process_comment(void)
Line 280  process_comment(void)
         case '*':          case '*':
             inbuf_skip();              inbuf_skip();
             check_size_comment(4);              check_size_comment(4);
             if (*buf_ptr == '/') {              if (*inp.s == '/') {
         end_of_comment:          end_of_comment:
                 inbuf_skip();                  inbuf_skip();
   
Line 316  process_comment(void)
Line 316  process_comment(void)
                     last_blank = com.e - com.buf;                      last_blank = com.e - com.buf;
                 *com.e++ = ch;                  *com.e++ = ch;
                 now_len++;                  now_len++;
             } while (memchr("*\n\r\b\t", *buf_ptr, 6) == NULL &&              } while (memchr("*\n\r\b\t", *inp.s, 6) == NULL &&
                 (now_len < adj_max_line_length || last_blank == -1));                  (now_len < adj_max_line_length || last_blank == -1));
   
             ps.last_nl = false;              ps.last_nl = false;

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

CVSweb <webmaster@jp.NetBSD.org>