// Copyright 1999-2001 by Lowell Dennis (Cyberclops, LLC) // // $Workfile: tag.vdm $ // // Symbol lookup macros for VEDIT (5.00 or greater) // STACK.VDM, ALLOC.VDM. PICK.VDM, and FILESTCK.VDM must be // loaded into the same text register. // Must be used with tagfile created by Vedit's CTAG macro. // // $Log: X:/bios/lowell/tools/vedit/tag.vdv $ // // Rev 1.0 04 Oct 2001 10:21:50 Lowell // Initial revision. // ///////////////////////////////////////////////////////////////////// // TAG_INIT Initializes TAG. // Call with: // None // Exits with: // RV = 0, if no error // #90 = Tagfile buffer number // #91 = File stack buffer number // RV = 1, if tagfile not found // if tagfile buffer not available // if file stack buffer not available // if INIT_FILE_STACK returned an error :TAG_INIT: Num_Push(80,89) Reg_Push(80,80) #89 = Buf_Num // Save current buffer #90 = 0 // Tagfile buffer not allocated #91 = 0 // File stack not allocated if (File_Exist(".\tags")==0) { // In current directory ? if (File_Exist("..\tags",NOERR)==0) { // Up one level ? if (File_Exist("..\..\tags",NOERR)==0) { // Up two levels ? if (File_Exist("..\..\..\tags",NOERR)==0) { // Up three levels ? Get_Environment(80,"TAGBASE") // From environment ? if (File_Exist("|@(80)\tags")==0) { Get_Key("Tagfile not found!!!",STATLINE) Call(MN,"TAG_CLEANUP") return(1) } } } else { regset(80,"..\..") } } else { regset(80,"..") } } else { regset(80,".") } // Set path to current directory Call(MN,"ALLOC_BUF") // Allocate buffer for tagfile if (RV != 0) { goto TAG_ERROR } // If allocate failed ... #90 = #80 // Set tagfile buffer Buf_Switch(#90,EXTRA) // Switch to Tagfile buffer Reg_Set(80,"\tags",APPEND) // Tagfile name File_Open("|@(80)",BROWSE+NOEVENT) // Load tagfile Call(MN,"ALLOC_BUF") // Allocate buffer for file stack if (RV != 0) { goto TAG_ERROR } // If allocate failed ... #91 = #80 // Set file stack buffer Call(Macro_Num,"INIT_FILE_STACK") // Initialize file stack if (RV != 0) { goto TAG_ERROR } // If failed ... Call(MN,"TAG_CLEANUP") return(0) :TAG_ERROR: if (#90 != 0) { // Free tagfile buffer Buf_Switch(#90,EXTRA) Buf_Quit(OK) } if (#91 != 0) { // Free file stack buffer Buf_Switch(#91) Buf_Quit(OK) } Call(MN,"TAG_CLEANUP") return(1) :TAG_CLEANUP: Buf_Switch(#89) // Switch to original buffer Reg_Pop(80,80) Num_Pop(80,89) return ///////////////////////////////////////////////////////////////////// // GET_SYMBOL Extracts symbol at cursor // Call with: // Nothing // Exits with: // T80 = Symbol // RV = 0, if no error // RV = 1, if no symbol at cursor // :GET_SYMBOL: Num_Push(85,86) Save_Pos() if (S("|s",REVERSE+NOERR)) { // Move to start Char(1) // of symbol } #86 = Cur_Pos // Mark start of symbol Match("|{_,|F}",ALL+ADVANCE) // Move to end of symbol #85 = Cur_Pos // Mark end of symbol Restore_Pos() if (#86 == #85) { // Symbol not found at cursor Num_Pop(85,86) return (1) } else { RCB(80,#86,#85) // Extract symbol return (0) } ///////////////////////////////////////////////////////////////////// // TAG_LOOKUP Looks up TAG symbol // Call with: // #90 = Tagfile buffer number // #91 = File stack buffer number // Exits with: // RV = 0, if no error // RV = 1, if symbol not found in tagfile // if pick list buffer not available // if INIT_PICK returned an error // if ADD_PICK returned an error // if GET_PICK returned an error // if process buffer not available // Definition not found // :TAG_LOOKUP: Num_Push(80,89) Reg_Push(80,81) #89 = Buf_Num // Save current buffer #88 = 0 // Pick list buffer not allocated #87 = 0 // Process buffer not allocated Call(MN, "GET_SYMBOL") if (RV != 0) { // Prompt for symbol ? Get_Input(80,"Symbol to lookup ( to exit): ",STATLINE+NOCR) if(Reg_Compare(80, "") == 0) { goto LOOKUP_CLEANUP } } Buf_Switch(#90,EXTRA) // Switch to tagfile buffer #84 = S("|<|@(80)|Y|W",BEGIN+NOERR+ALL) // Get # of occurances #83 = #84 // Save BOF if (#84 == 0) { // If not found ... Reg_Set(80,": Symbol not found in tagfile!!!",APPEND) Get_Key(@(80),STATLINE) goto LOOKUP_ERROR } Call(MN,"ALLOC_BUF") // Allocate buffer for pick list if (RV != 0) { goto LOOKUP_ERROR } // If allocate failed ... #88 = #80 // Set pick list buffer Call(MN, "INIT_PICK") // Initialize pick list if (RV != 0) { goto LOOKUP_ERROR } // If failed ... for (#81 = 81; #84 > 0; #84--) { // Goto each occuarnce S("|<|@(80)|Y|W",NOERR+ADVANCE) #86 = Cur_Pos // Mark start of filename #85 = Cur_Line // Symbol line if ((S("|W",NOERR)==0) || (Cur_Line != #85)){ Goto_Pos(#86) // Handle case with no definition EOL } #85 = Cur_Pos // Mark end of filename RCB(81,#86,#85) // Extract filename Reg_Set(81,":: ",APPEND) if (CP == EOL_Pos) { // Handle case with no definition Reg_Set(81,@(80),APPEND) } else { Match("|W",ADVANCE) // Advance past whitespace #86 = Cur_Pos+2 // Mark start of definition EOL RCB(81,#86,Cur_Pos-2,APPEND) // Append function definition } Reg_Set(81," ",APPEND) if (#83 > 1) { // More than 1 occurance ? Call(MN, "ADD_PICK") // Add to pick list if (RV != 0) { // If failed ... goto LOOKUP_ERROR } } } if (#83 > 1) { // More than 1 occurance ? Call(MN,"GET_PICK") // Let user pick if (RV != 0) { goto LOOKUP_ERROR } // If failed ... } Call(MN,"ALLOC_BUF") // Allocate process buffer if (RV != 0) { goto LOOKUP_ERROR } // If allocate failed ... #87 = #80 // Set process buffer Buf_Switch(#87) // Switch to process buffer Reg_Ins(81,BEGIN) // Insert selected data RCB(80,0,EOL_Pos-2) // Extract filename Line(1) // Goto definition line RCB(81,BOL_Pos,EOL_Pos) // Extract definition Buf_Switch(#89) // Switch back to original buffer #80 = #91 // Save current filename and Call(MN,"PUSH_FILE") // position (OK if error) File_Open(@(80),ATTACH) // Goto the definition file if (Search("|<|@(81)|>",NOERR+BEGIN)) { // Find definition Search("|<|@(81)|>",CONFIRM+SET) // Highlight it } else { // If not found ... Get_Key(@(81),STATLINE) Get_Key("Definition not found",STATLINE) goto LOOKUP_NOTFOUND } #89 = Buf_Num Call(MN,"LOOKUP_CLEANUP") return(0) :LOOKUP_NOTFOUND: Call(MN,"POP") // Remove file from stack :LOOKUP_ERROR: Call(MN,"LOOKUP_CLEANUP") return(1) :LOOKUP_CLEANUP: if (#88 != 0) { // Free pick list buffer Buf_Switch(#88) Buf_Quit(OK) } if (#87 != 0) { // Free process buffer Buf_Switch(#87) Buf_Quit(OK) } Buf_Switch(#89) Reg_Pop(80,81) Num_Pop(80,89) return