// This script works as follows: // - Type a C keyword like "if", "for", "while" etc. // - Press Alt+G to execute this script. // The script analyzes the word before cursor and inserts the appropriate // braces building a template for this C keyword. #include int Col; void SimpleTemplate() { Text(" ()"); SetMark(10); Cr(); CurCol = Col; Text("{"); Cr(); Cr(); CurCol = Col; Text("}"); GetMark(10); Left(); } void Else() { Cr(); CurCol = Col; Text("{"); Cr(); Cr(); CurCol = Col; Text("}"); Up(); Right(); } void For() { Text(" (;;)"); SetMark(10); Cr(); CurCol = Col; Text("{"); Cr(); Cr(); CurCol = Col; Text("}"); GetMark(10); Left(3); } void DoWhile() { Text(" ()"); SetMark(10); Cr(); CurCol = Col; Text("{"); Cr(); Cr(); CurCol = Col; Text("} while ()"); GetMark(10); Left(); } void Switch() { Text(" ()"); SetMark(10); Cr(); CurCol = Col; Text("{"); Cr(); CurCol = Col + 2; Text("case :"); Cr(); Cr(); CurCol = Col + 2; Text("default:"); Cr(); CurCol = Col; Text("}"); GetMark(10); Left(); } void main() { char keyword[256]; int tmp_ins_mode = InsertMode; InsertMode = TRUE; int col = CurCol; WordLeft(); _GetWord(keyword); Col = CurCol; CurCol = col; if (strcmp(keyword, "if") == 0 || strcmp(keyword, "while") == 0 ) { SimpleTemplate(); goto restore; } if (strcmp(keyword, "else") == 0) { Else(); goto restore; } if (strcmp(keyword, "for") == 0) { For(); goto restore; } if (strcmp(keyword, "do") == 0) { DoWhile(); goto restore; } if (strcmp(keyword, "switch") == 0) { Switch(); goto restore; } MessageBoxEx(MB_OK | MB_ICONINFORMATION, "Script Information", "This key executes a script file that works as follows:\n" " - Type a C keyword like \"if\", \"for\", \"while\" etc.\n" " - Press Alt+G to execute this script.\n" " The script analyzes the word before cursor and inserts the\n" "appropriate braces building a template for this C keyword." ); restore: InsertMode = tmp_ins_mode; }