📄 asconvrt.c
字号:
{ return ReplaceCount; } /* * Check for translation escape string -- means to ignore * blocks of code while replacing */ SubString2 = strstr (SubBuffer, AS_START_IGNORE); if ((SubString2) && (SubString2 < SubString1)) { /* Find end of the escape block starting at "Substring2" */ SubString2 = strstr (SubString2, AS_STOP_IGNORE); if (!SubString2) { /* Didn't find terminator */ return ReplaceCount; } /* Move buffer to end of escape block and continue */ SubBuffer = SubString2; } /* Do the actual replace if the target was found */ else { if ((Type & REPLACE_MASK) == REPLACE_WHOLE_WORD) { if (!AsMatchExactWord (SubString1, TargetLength)) { SubBuffer = SubString1 + 1; continue; } } SubBuffer = AsReplaceData (SubString1, TargetLength, Replacement, ReplacementLength); if ((Type & EXTRA_INDENT_C) && (!Gbl_StructDefs)) { SubBuffer = AsInsertData (SubBuffer, " ", 8); } ReplaceCount++; } } return ReplaceCount;}/****************************************************************************** * * FUNCTION: AsConvertToLineFeeds * * DESCRIPTION: * ******************************************************************************/voidAsConvertToLineFeeds ( char *Buffer){ char *SubString; char *SubBuffer; SubBuffer = Buffer; SubString = Buffer; while (SubString) { /* Find the target string */ SubString = strstr (SubBuffer, "\r\n"); if (!SubString) { return; } SubBuffer = AsReplaceData (SubString, 1, NULL, 0); } return;}/****************************************************************************** * * FUNCTION: AsInsertCarriageReturns * * DESCRIPTION: * ******************************************************************************/voidAsInsertCarriageReturns ( char *Buffer){ char *SubString; char *SubBuffer; SubBuffer = Buffer; SubString = Buffer; while (SubString) { /* Find the target string */ SubString = strstr (SubBuffer, "\n"); if (!SubString) { return; } SubBuffer = AsInsertData (SubString, "\r", 1); SubBuffer += 1; } return;}/****************************************************************************** * * FUNCTION: AsBracesOnSameLine * * DESCRIPTION: Move opening braces up to the same line as an if, for, else, * or while statement (leave function opening brace on separate * line). * ******************************************************************************/voidAsBracesOnSameLine ( char *Buffer){ UINT32 Length; char *SubBuffer = Buffer; char *Beginning; char *StartOfThisLine; char *Next; BOOLEAN BlockBegin = TRUE; while (*SubBuffer) { /* Ignore comments */ if ((SubBuffer[0] == '/') && (SubBuffer[1] == '*')) { SubBuffer = strstr (SubBuffer, "*/"); if (!SubBuffer) { return; } SubBuffer += 2; continue; } /* Ignore quoted strings */ if (*SubBuffer == '\"') { SubBuffer++; SubBuffer = AsSkipPastChar (SubBuffer, '\"'); if (!SubBuffer) { return; } } if (!strncmp ("\n}", SubBuffer, 2)) { /* * A newline followed by a closing brace closes a function * or struct or initializer block */ BlockBegin = TRUE; } /* * Move every standalone brace up to the previous line * Check for digit will ignore initializer lists surrounded by braces. * This will work until we we need more complex detection. */ if ((*SubBuffer == '{') && !isdigit (SubBuffer[1])) { if (BlockBegin) { BlockBegin = FALSE; } else { /* * Backup to previous non-whitespace */ Beginning = SubBuffer - 1; while ((*Beginning == ' ') || (*Beginning == '\n')) { Beginning--; } StartOfThisLine = Beginning; while (*StartOfThisLine != '\n') { StartOfThisLine--; } /* * Move the brace up to the previous line, UNLESS: * * 1) There is a conditional compile on the line (starts with '#') * 2) Previous line ends with an '=' (Start of initializer block) * 3) Previous line ends with a comma (part of an init list) */ if ((StartOfThisLine[1] != '#') && (*Beginning != '/') && (*Beginning != '{') && (*Beginning != '=') && (*Beginning != ',')) { Beginning++; SubBuffer++; Length = strlen (SubBuffer); Gbl_MadeChanges = TRUE;#ifdef ADD_EXTRA_WHITESPACE AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3);#else /* Find non-whitespace start of next line */ Next = SubBuffer + 1; while ((*Next == ' ') || (*Next == '\t')) { Next++; } /* Find non-whitespace start of this line */ StartOfThisLine++; while ((*StartOfThisLine == ' ') || (*StartOfThisLine == '\t')) { StartOfThisLine++; } /* * Must be a single-line comment to need more whitespace * Even then, we don't need more if the previous statement * is an "else". */ if ((Next[0] == '/') && (Next[1] == '*') && (Next[2] != '\n') && (!strncmp (StartOfThisLine, "else if", 7) || !strncmp (StartOfThisLine, "else while", 10) || strncmp (StartOfThisLine, "else", 4))) { AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3); } else { AsReplaceData (Beginning, SubBuffer - Beginning, " {", 2); }#endif } } } SubBuffer++; }}/****************************************************************************** * * FUNCTION: AsTabify4 * * DESCRIPTION: Convert the text to tabbed text. Alignment of text is * preserved. * ******************************************************************************/voidAsTabify4 ( char *Buffer){ char *SubBuffer = Buffer; char *NewSubBuffer; UINT32 SpaceCount = 0; UINT32 Column = 0; while (*SubBuffer) { if (*SubBuffer == '\n') { Column = 0; } else { Column++; } /* Ignore comments */ if ((SubBuffer[0] == '/') && (SubBuffer[1] == '*')) { SubBuffer = strstr (SubBuffer, "*/"); if (!SubBuffer) { return; } SubBuffer += 2; continue; } /* Ignore quoted strings */ if (*SubBuffer == '\"') { SubBuffer++; SubBuffer = AsSkipPastChar (SubBuffer, '\"'); if (!SubBuffer) { return; } SpaceCount = 0; } if (*SubBuffer == ' ') { SpaceCount++; if (SpaceCount >= 4) { SpaceCount = 0; NewSubBuffer = (SubBuffer + 1) - 4; *NewSubBuffer = '\t'; NewSubBuffer++; /* Remove the spaces */ SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer + 1); } if ((Column % 4) == 0) { SpaceCount = 0; } } else { SpaceCount = 0; } SubBuffer++; }}/****************************************************************************** * * FUNCTION: AsTabify8 * * DESCRIPTION: Convert the text to tabbed text. Alignment of text is * preserved. * ******************************************************************************/voidAsTabify8 ( char *Buffer){ char *SubBuffer = Buffer; char *NewSubBuffer; char *CommentEnd = NULL; UINT32 SpaceCount = 0; UINT32 Column = 0; UINT32 TabCount = 0; UINT32 LastLineTabCount = 0; UINT32 LastLineColumnStart = 0; UINT32 ThisColumnStart = 0; UINT32 ThisTabCount = 0; char *FirstNonBlank = NULL; while (*SubBuffer) { if (*SubBuffer == '\n') { /* This is a standalone blank line */ FirstNonBlank = NULL; Column = 0; SpaceCount = 0; TabCount = 0; SubBuffer++; continue; } if (!FirstNonBlank) { /* Find the first non-blank character on this line */ FirstNonBlank = SubBuffer; while (*FirstNonBlank == ' ') { FirstNonBlank++; } /* * This mechanism limits the difference in tab counts from * line to line. It helps avoid the situation where a second * continuation line (which was indented correctly for tabs=4) would * get indented off the screen if we just blindly converted to tabs. */ ThisColumnStart = FirstNonBlank - SubBuffer; if (LastLineTabCount == 0) { ThisTabCount = 0; } else if (ThisColumnStart == LastLineColumnStart) { ThisTabCount = LastLineTabCount -1; } else { ThisTabCount = LastLineTabCount + 1; } } Column++; /* Check if we are in a comment */ if ((SubBuffer[0] == '*') && (SubBuffer[1] == '/')) { SpaceCount = 0; SubBuffer += 2; if (*SubBuffer == '\n') { if (TabCount > 0) { LastLineTabCount = TabCount; TabCount = 0; } FirstNonBlank = NULL; LastLineColumnStart = ThisColumnStart; SubBuffer++; } continue; } /* Check for comment open */ if ((SubBuffer[0] == '/') && (SubBuffer[1] == '*')) { /* Find the end of the comment, it must exist */ CommentEnd = strstr (SubBuffer, "*/"); if (!CommentEnd) { return; } /* Toss the rest of this line or single-line comment */ while ((SubBuffer < CommentEnd) && (*SubBuffer != '\n')) { SubBuffer++; } if (*SubBuffer == '\n') { if (TabCount > 0) { LastLineTabCount = TabCount;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -