tools/convert-comments.c: Fix an error in handling of a blank C++ comment before a comment block. For example, this testfile:

1
2  //
3  // Multi-line comment
4  // The second line
5

Was generating this output:

1
2
3   * Multi-line comment
4   * The second line
5   */
6

Now correctly generates:

1
2  /* Multi-line comment
3   * The second line
4   */
5
This commit is contained in:
Gregory Nutt 2019-01-22 10:45:06 -06:00
parent 434cad4d17
commit b4373e21e7
1 changed files with 28 additions and 5 deletions

View File

@ -122,7 +122,7 @@ int main(int argc, char **argv)
goto errout_with_outstream;
}
/* Skip over leading spaces in line1 n + 1 */
/* Skip over leading spaces in line n + 1 */
for (ptr = g_line1, nextindent = 0;
*ptr != '\0' && *ptr != '\n' && isspace(*ptr);
@ -149,6 +149,8 @@ int main(int argc, char **argv)
willbecomment = strncmp(ptr, "//", 2) == 0;
}
/* Loop for each line in the file */
do
{
/* Swap line n and line n + 1 */
@ -253,7 +255,7 @@ int main(int argc, char **argv)
printf("*****************************************************************************\n");
printf("* %5lu. %s\n", lineno, g_line0);
printf("* indent: last=%u curr=%u next=%u\n",
printf("* indent: last=%u curr=%u next=%u\n",
lastindent, indent, nextindent);
printf("* comment: last=%u curr=%u next=%u\n",
wascomment, iscomment, willbecomment);
@ -266,15 +268,36 @@ int main(int argc, char **argv)
ptr = g_line0 + indent;
if (iscomment)
{
char *endptr;
/* Get a pointer for the first non-blank character following the
* comment.
*/
for (endptr = &ptr[2];
*endptr != '\0' && *endptr != '\n' && isspace(*endptr);
endptr++)
{
}
/* Check for a comment only line that is was not preceded by a
* comment.
*/
if (ptr[2] == '\n' && !wascomment)
if ((*endptr == '\n' || *endptr == '\0') && !wascomment)
{
/* Output a blank line */
/* Avoid double spacing */
fputc('\n', outstream);
if (!wasblank)
{
/* Output a blank line */
fputc('\n', outstream);
}
indent = 0;
iscomment = false;
isblank = true;
}
/* Did line n - 1 start with a comment? */