// CFUNC.VDM - Show and select 'C' program functions. // // Originally by Kerry E. Wilkinson, Owings Mills, MD. // Modified by Greenview Data, Inc. // Modified by David Kasmar, Cherry Hill, NJ // Finds multiline prototypes, // L-R scroll function list. // Finds C++ member functions. // Clean up window displays. // Modified by Paul Lindgren (PL) // Windows-version, does not update edit window when selecting function // Modified by Ian Binned (IB) // Allow C++ comments after ")" and whitespace at start of line 27-08-2003 // Last change: 23-Feb-2004 // // Requires: VEDIT 5.21 or later. // // Usage: Select {USER, C function show/select}. // // Or select {MISC, More macros, CFUNC}. // // Notes: PFUNC.VDM is a similar macro for Pascal / Delphi. // //////////////// // #103 = 0 // Change to "1" to update edit window on Up/Down #104 = 0 // Change to "1" to include return-type, e.g. "int", "VOID" // Num_Push(70,92) // Save numeric registers used here #75 = #103 // Copy option above to #75 #76 = #104 // Copy option above to #76 #85 = Buf_Num // #85 = original edit buffer #86 = Cur_Pos // #86 = original buffer's file position #87 = Cur_Line // #87 = original buffer's cursor line (PL), + tmp #79 = Config(F_F_TYPE) // #79 = original buffer's file-type #80 = Reg_Free() // #80 = T-Reg to hold occurrence line array Reg_Set(#80,/ /) // Insert something so next "Reg_Free" works #81 = Reg_Free() // #81 = T-Reg to hold file position array Reg_Set(#81,/ /) // Insert something so next "Reg_Free" works #82 = Reg_Free() // #82 = T-Reg to hold search string #83 = Buf_Free(EXTRA) // #83 = Extra Buffer for occurrence line array Buf_Switch(#83,EXTRA) // Open buffer with additional memory if (#79 > 3) { #79 = 1 } // If in record mode, use file-type 1=LF Config(F_F_TYPE,#79,LOCAL) // Show lines in same file-type #84 = Buf_Free(EXTRA) // #84 = Extra Buffer for file position array Buf_Switch(#84,EXTRA) // Open buffer with additional memory Buf_Switch(#85) // Switch back if (#80<=0 || #81<=0 || #83<=0 || #84<=0) { // If no resources... Alert() Get_Key("Insufficient resources for this function!",STATLINE+RAW) Num_Pop(70,92) Return } // // Initialize for processing loop. // Reg_Empty(#80) // Empty @#80 Reg_Empty(#81) // Empty @#81 #88 = 0 // PL: nearest function position #89 = 0 // Init loop counter to zero Message("Processing file. Please wait...",STATLINE) // // Create arrays of occurrence lines and corresponding file position. // Buf_Switch(#85) // Switch to original buffer Begin_Of_File() repeat (ALL) { // Loop until Search() breaks out Search("|041|[|W]|[/*|M*/,/*|M*/|W,//|M|L]|[|L]|[|L]|[|W]|123",ERRBREAK) //Allow C++ comment IB 27/08/03 #91 = CP // Save "end" location IB 28/08/03 Match_Paren(NOERR) // Backup to beginning of function declaration BOL Match("|W",ADVANCE) // Advance over any whitespace at start of line IB 27/08/03 // // Skip this occurrence if 1st char is not alphanumeric. // if ((Cur_Char < 65 || Cur_Char > 122)) { S("|123") Line(1,NOERR) Continue } // #89++ // Increment loop counter if (Cur_Line <= #87) { #88 = #89 } //+ find index closest to current cur pos (PL) // // Optionally (default), skip over the return-type, e.g. "int", "VOID", etc. // if (! #76) { if (!Match("[0-z]+[\s\t]+[A-z]",REGEXP)) { Search("|W",ADVANCE+NOERR) // Return-type not displayed (PL) } } // // T-Reg #81 is file-position array // Out_Reg(#81,APPEND) // T-Reg #81 is file-position array Num_Type(Cur_Pos,LEFT) // Append File-Pos(occurrence) with CRLF Out_Reg(CLEAR) // // T-Reg #80 is occurrence line array // Out_Reg(#80,APPEND) // T-Reg #80 is occurrence line array Reg_Set(#80," ", APPEND) Out_Reg(CLEAR) Reg_Copy(#80,1,APPEND) // Append occurrence line to T-Reg #80 Goto_Pos(#91) // Restore "end" location IB 28/08/03 Search("|123") //+ skip multi-line definition (PL) Match_Paren(NOERR) // Skip to end of function IB 28/08/03 Line(1,NOERR) // Continue search on next line // // End loop prematurely if running out of memory for arrays. // if (Reg_Mem_Free < 500) { Reg_Set(#80,"Too many occurrences...", APPEND) Break } } // End of loop // // If at least 1 occurrence found... // if (#89 > 0) { Goto_Pos(#86) // Goto original position (++) if (Screen_Cols > 50 ) { // If VEDIT > 50 columns... #90 = Screen_Cols*40/100 // Use 40% width window #91 = Screen_Cols-#90-2 } else { if (Screen_Cols > 23 ) { // Else if VEDIT > 23 columns... #90 = 20 // Use 20 column window #91 = Screen_Cols-#90-3 } else { // Else... #90 = Screen_Cols // Use full width window #91 = 1 }} #92 = Screen_Lines-4 if (#89 < #92) { #92 = #89+1 } // Check window height required (PL) if (Win_Status(*) >= 0) { // If window already exists... (PL) Win_Switch(*,ATTACH) Buf_Quit(DELETE+OK) // Quit buffer and delete window } // // Create display window to the right // Win_Create(*,1,#91,#92,#90,MINBORDER) Win_Switch(*) // Switch to the new window if (Is_Mono) { Win_Color(112) } // If monochrome use black chars on white else { Win_Color(32) } // Else use black chars on green Win_Clear() // Clear window with new color // // Setup buffer #83 to process occurrence line array. // Setup buffer #84 to process file position array. // Buf_Switch(#84) Reg_Ins(#81,BEGIN) // Load file position array Buf_Switch(#83) Config(PG_E_SYNTAX,0,LOCAL) // Disable syntax highlighting Reg_Ins(#80,BEGIN) // Load occurrence line array Win_Attach(*) // Attach special window Goto_Line(#88) // Select function closest to current (PL) Key_Purge() // Clear keyboard buffer (PL) #77 = 1 // Column in function name window #78 = 1 // Set "update" flag // // Loop until or // repeat (ALL) { // Loop until or if (#78) { // If update needed... Begin_Of_Line() Block_Begin(Cur_Pos) Block_End(EOL_Pos) Goto_Col(#77) // So we can scroll long function names Update() // Highlight current occurrence line if (#78 > 1 || #75) { // Update only when requested (PL) #88 = Cur_Line // #88 = array index Buf_Switch(#84) Goto_Line(#88) // Index into file_position array #88 = Num_Eval() // #88 = corresponding file position Buf_Switch(#85) // Return to original buffer Goto_Pos(#88) // Goto occurrence location if (#89 < #92) { // If all functions fit... Set_Visual_Line(#89) // make sure all are visible } else { // Else, set current near top of screen Set_Visual_Line(Screen_Lines/3) } Update() // Update buffer Begin_Of_Line() // Goto beginning of line Buf_Switch(#83) Win_Switch(*) // Go back to show/select window } } #78 = 0 // Assume no update needed #88 = Get_Key("Use cursor keys and press to select or to Quit",STATLINE) if (#88=='R'+'T'*256) { // Return #88 = Cur_Line // #88 = array index Buf_Switch(#84) Goto_Line(#88) // Index into file_position array #86 = Num_Eval() // #86 = corresponding file position Buf_Switch(#85) // Return to original buffer Goto_Pos(#86) // Goto occurrence location Update() // Update buffer Begin_Of_Line() // Goto beginning of line Break // Break out of Repeat Loop } if (#88=='E'+'S'*256) { // Escape Break // Break out of Repeat Loop } if (#88=='C'+'D'*256) { // Cursor Down if (Cur_Line<#89) { Line(1,NOERR) #78=1 } } if (#88=='C'+'U'*256) { // Cursor Up if (Cur_Line>1) { Line(-1,NOERR) #78=1 } } if (#88=='C'+'R'*256) { // Cursor Right if (Cur_Col<200) { #77=Cur_Col+40 #78=2 } } if (#88=='C'+'L'*256) { // Cursor Left if (Cur_Col>40) { #77=Cur_Col-40 } else { #77 = 1 } #78=2 } if (#88=='P'+'D'*256) { // Page Down if (Cur_Line < #89) { #78=1 } Line(Win_Lines-1,NOERR) if (At_EOF) { Line(-1,NOERR) } #77 = 1 } if (#88=='P'+'U'*256) { // Page Up if (Cur_Line > 1) { #78=1 } Line(-(Win_Lines-1),NOERR) #77 = 1 } if (#88=='L'+'E'*256) { // End if (Cur_Line < #89) { #78=1 } End_Of_File() Line(-1,NOERR) #77 = 1 } if (#88=='L'+'B'*256) { // Home if (Cur_Line > 1) { #78=1 } Begin_Of_File() #77 = 1 } } Win_Delete(*) } Reg_Empty(#80) // Empty T-Regs Reg_Empty(#81) Reg_Empty(#82) Buf_Switch(#83) Buf_Quit(OK) // Empty extra buffers Buf_Switch(#84) Buf_Quit(OK) Buf_Switch(#85) // Return to original buffer Goto_Pos(#86) // Goto new/original position Update() Num_Pop(70,92) // Restore numeric regs Reg_Empty(Macro_Num,EXTRA) // Empty this T-Reg; should return Return // Just in case