// ifdef.e // // Mon, 11/19/1992 18:00:00 // // Purpose: // // This extension searches your current buffer for #ifdef-relevant // C-preprocessor lines, and displays the ones that would be in effect // for the current line in a popup window. // // Usage: // // Load this module and save your state file. // // // Notes: // // The extension searches backwards from the current position // backwards looking for: // // [white-space(s)]#[white-space(s)]if|el|end // // This is the MS C/C++ 7.00 definition of preprocessor command syntax. // // This search string assumes that // #if, #ifdef, #ifndef, and alike start with "if", // #else, #elif, and alike start with "el", // #end, #endif, and alike start with "end", and // no other preprocessor command uses these prefixes. // // The whole command is bound to the A-i key. // // Example: // // If you have the following text: // // text #0 // #ifdef COMPILE // text #1; // #elif FOO // text #2; // #else // #ifndef DEBUG // text #3; // #else // text #4; // #endif // text #5; // #endif // text #6; // // and hit A-i while the cursor is on text: // // TEXT # OUTPUT // ------ ------ // 0 Not in a #if/#else/#endif block. // // 1 #ifdef COMPILE // // 2 #ifdef COMPILE // #elif FOO // // 3 #ifdef COMPILE // #elif FOO // #else // #ifndef DEBUG // // 4 #ifdef COMPILE // #elif FOO // #else // #ifndef DEBUG // #else // // 5 #ifdef COMPILE // #elif FOO // #else // // 6 Not in a #if/#else/#endif block. // // // The modifications to this code are dedicated to the public domain // with the caveat that Lugaru is welcome to use this within their // distribution source code which is supplied with Epsilon. Use it // any way you want for whatever purposes. The catch is that this header // has to be included in any file using this extension, and any changes // made to this extension should be sent to me as well. // // // Tuna Ertemalp // // INTERNET: tunae@microsoft.com // ertem@cs.stanford.edu // // // Modification History: // // Mon, 11/19/1992 18:00:00 V1.0 initial release. // // Thanks to: // // John Kercheval, since I based most of these comments on his // standard comment header. Couldn't have done // a better job myself... :-) // #include #define bool int #define true 1 #define false 0 #define IFELSEENDIFBUFFER "*#if/#else/#endif*" #define SEARCHIFELSEENDIF "^([ \t]*#[ \t]*(if|el|end))" command show_preprocessor_if_then_else_structure() on reg_tab[ALT('i')] { int oldPoint = point; int origbufnum = bufnum; int origbeginline = give_begin_line(); int bNum = zap(IFELSEENDIFBUFFER); int nest = 0; bool found = false; iter = 0; say("Searching..."); nl_forward(); while (re_search(-1,SEARCHIFELSEENDIF)) { if (character(matchstart-1) == 'd' && point < origbeginline) { // #end nest++; } else if (nest == 0) { found = true; buf_xfer(bNum,give_begin_line(),give_end_line()+1); bufnum = bNum; point = 0; bufnum = origbufnum; } else if (character(matchstart-1) == 'f') { // #if nest--; } } point = oldPoint; if (found) { say("Search completed."); view_buf(bNum,0); } else { say("Not in a #if/#else/#endif block."); } buf_delete(bNum); }