mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
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:
@@ -122,7 +122,7 @@ int main(int argc, char **argv)
|
|||||||
goto errout_with_outstream;
|
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;
|
for (ptr = g_line1, nextindent = 0;
|
||||||
*ptr != '\0' && *ptr != '\n' && isspace(*ptr);
|
*ptr != '\0' && *ptr != '\n' && isspace(*ptr);
|
||||||
@@ -149,6 +149,8 @@ int main(int argc, char **argv)
|
|||||||
willbecomment = strncmp(ptr, "//", 2) == 0;
|
willbecomment = strncmp(ptr, "//", 2) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Loop for each line in the file */
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Swap line n and line n + 1 */
|
/* Swap line n and line n + 1 */
|
||||||
@@ -253,7 +255,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
printf("*****************************************************************************\n");
|
printf("*****************************************************************************\n");
|
||||||
printf("* %5lu. %s\n", lineno, g_line0);
|
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);
|
lastindent, indent, nextindent);
|
||||||
printf("* comment: last=%u curr=%u next=%u\n",
|
printf("* comment: last=%u curr=%u next=%u\n",
|
||||||
wascomment, iscomment, willbecomment);
|
wascomment, iscomment, willbecomment);
|
||||||
@@ -266,15 +268,36 @@ int main(int argc, char **argv)
|
|||||||
ptr = g_line0 + indent;
|
ptr = g_line0 + indent;
|
||||||
if (iscomment)
|
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
|
/* Check for a comment only line that is was not preceded by a
|
||||||
* comment.
|
* 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? */
|
/* Did line n - 1 start with a comment? */
|
||||||
|
|||||||
Reference in New Issue
Block a user