mirror of
https://github.com/holub/mame
synced 2025-10-06 17:08:28 +03:00
if the start of a multi-line comment is indented then following comment lines will be indented with tabs up to that point. [smf]
This commit is contained in:
parent
8b1fca36db
commit
a3c79cb5f0
@ -67,10 +67,22 @@ static UINT8 modified[MAX_FILE_SIZE];
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int removed_tabs = 0, added_tabs = 0, removed_spaces = 0, fixed_mac_style = 0, fixed_nix_style = 0, added_newline = 0, removed_newlines = 0;
|
int removed_tabs = 0;
|
||||||
int src = 0, dst = 0, in_c_comment = FALSE, in_cpp_comment = FALSE, in_c_string = FALSE;
|
int added_tabs = 0;
|
||||||
|
int removed_spaces = 0;
|
||||||
|
int fixed_mac_style = 0;
|
||||||
|
int fixed_nix_style = 0;
|
||||||
|
int added_newline = 0;
|
||||||
|
int removed_newlines = 0;
|
||||||
|
int src = 0;
|
||||||
|
int dst = 0;
|
||||||
|
bool in_c_comment = false;
|
||||||
|
bool in_cpp_comment = false;
|
||||||
|
int indent_c_comment = 0;
|
||||||
|
int in_c_string = FALSE;
|
||||||
int hichars = 0;
|
int hichars = 0;
|
||||||
int is_c_file, is_xml_file;
|
bool is_c_file;
|
||||||
|
bool is_xml_file;
|
||||||
const char *ext;
|
const char *ext;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int bytes;
|
int bytes;
|
||||||
@ -134,13 +146,26 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* track whether or not we are within a C-style comment */
|
/* track whether or not we are within a C-style comment */
|
||||||
if (!in_c_comment && ch == '/' && original[src] == '*')
|
if (!in_c_comment && ch == '/' && original[src] == '*')
|
||||||
in_c_comment = TRUE;
|
{
|
||||||
|
in_c_comment = true;
|
||||||
|
if (col > 0 && modified[dst-1] == 0x09)
|
||||||
|
{
|
||||||
|
indent_c_comment = col;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
indent_c_comment = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (in_c_comment && ch == '*' && original[src] == '/')
|
else if (in_c_comment && ch == '*' && original[src] == '/')
|
||||||
in_c_comment = FALSE;
|
{
|
||||||
|
in_c_comment = false;
|
||||||
|
indent_c_comment = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* track whether or not we are within a C++-style comment */
|
/* track whether or not we are within a C++-style comment */
|
||||||
else if (!in_c_comment && ch == '/' && original[src] == '/')
|
else if (!in_c_comment && ch == '/' && original[src] == '/')
|
||||||
in_cpp_comment = TRUE;
|
in_cpp_comment = true;
|
||||||
else
|
else
|
||||||
consume = FALSE;
|
consume = FALSE;
|
||||||
|
|
||||||
@ -183,7 +208,7 @@ int main(int argc, char *argv[])
|
|||||||
fixed_mac_style = 1;
|
fixed_mac_style = 1;
|
||||||
|
|
||||||
/* we are no longer in a C++-style comment */
|
/* we are no longer in a C++-style comment */
|
||||||
in_cpp_comment = FALSE;
|
in_cpp_comment = false;
|
||||||
|
|
||||||
if (in_c_string)
|
if (in_c_string)
|
||||||
{
|
{
|
||||||
@ -197,22 +222,27 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int spaces = tab_size - (col % tab_size);
|
int spaces = tab_size - (col % tab_size);
|
||||||
|
|
||||||
col += spaces;
|
/* convert tabs to spaces, if not used for indenting */
|
||||||
|
if ((in_c_comment && col >= indent_c_comment) || (col != 0 && modified[dst-1] != 0x09))
|
||||||
/* if inside a comment or in the middle of a line, expand it */
|
|
||||||
if (in_c_comment || in_cpp_comment || (col - spaces > 0 && modified[dst-1] != 0x09))
|
|
||||||
{
|
{
|
||||||
while (spaces--) modified[dst++] = ' ';
|
while (spaces > 0)
|
||||||
|
{
|
||||||
|
modified[dst++] = ' ';
|
||||||
|
col++;
|
||||||
|
spaces--;
|
||||||
|
}
|
||||||
|
|
||||||
removed_tabs++;
|
removed_tabs++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modified[dst++] = ch;
|
modified[dst++] = ch;
|
||||||
|
col += spaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert spaces to tabs at beginning of lines */
|
/* if we hit a space... */
|
||||||
else if (ch == 0x20 && !in_c_comment && !in_cpp_comment && (col == 0 || modified[dst-1] == 0x09))
|
else if (ch == 0x20)
|
||||||
{
|
{
|
||||||
int spaces = 1;
|
int spaces = 1;
|
||||||
|
|
||||||
@ -230,13 +260,21 @@ int main(int argc, char *argv[])
|
|||||||
spaces -= realign;
|
spaces -= realign;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spaces > 0)
|
/* convert spaces to tabs, if used for indenting */
|
||||||
|
while (spaces > 0 && (!in_c_comment || col < indent_c_comment) && (col == 0 || modified[dst-1] == 0x09))
|
||||||
{
|
{
|
||||||
modified[dst++] = 0x09;
|
modified[dst++] = 0x09;
|
||||||
spaces -= tab_size;
|
spaces -= tab_size;
|
||||||
col += tab_size;
|
col += tab_size;
|
||||||
added_tabs++;
|
added_tabs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (spaces > 0)
|
||||||
|
{
|
||||||
|
modified[dst++] = ' ';
|
||||||
|
col++;
|
||||||
|
spaces--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* otherwise, copy the source character */
|
/* otherwise, copy the source character */
|
||||||
|
Loading…
Reference in New Issue
Block a user