There was a discussion here : http://www.powerbasic.com/support/pb...913#post322913 and another here: http://www.powerbasic.com/support/pb...ad.php?t=41453
Code:
' ' Experimenting with a function/sub list for a code module ' starting off with a basic function list like the F2 list in the PB compilers ' Each function or sub can be viewed in a seperate window ' Synchronises with the last saved version of the subject file ' ' Chris Holbrook 12-Sep-2009 ' #compile exe #debug display #dim all #if not %def(%WINAPI) #include "WIN32API.INC" #endif #if not %def(%COMMCTRL_INC) #include "COMMCTRL.INC" #endif %IDD_DIALOG1 = 101 %IDC_LV = 1001 %IDD_DIALOG2 = 102 %IDC_TEXTBOX1 = 1003 type tfindex sfname as asciz * 256 start as long finish as long hwnd as dword end type global findex() as tfindex ' global table of functions and subs global sourcecode() as string ' global table of source code '--------------------------------------------------------------------------- function build ( hD as dword, LVid as long, sfile as string) as long local i, n, hfile, nrow, linenum as long local s, sline, s1, s2, s3, slist, swork as string ' dialog set text hd, "F2plus " + sfile + time$ hfile = freefile try open sfile for input as hfile linenum = 1 nrow = 1 while isfalse eof(hfile) line input #hfile, sline SWORK = SLINE + " @@@@@@@@" s1 = ucase$(parse$(ltrim$(swork), " ", 1)) s2 = ucase$(parse$(ltrim$(swork), any " (", 2)) s3 = ucase$(parse$(ltrim$(swork), any " (", 3)) select case s1 case "SUB" gosub addtolist case "FUNCTION" if left$(s2,1) <> "=" then gosub addtolist case "CALLBACK" gosub addtolist case "END" if left$(s2,8) = "FUNCTION" then gosub nudgelist exit select end if if left$(s2,3) = "SUB" then gosub nudgelist end if end select n = ubound(sourcecode()) + 1 redim preserve sourcecode(0 to n) sourcecode(n) = sline incr linenum wend close hfile catch dialog set text hd, "FILE ERROR": beep: sleep 2000 exit function end try exit function ''''''''''''''' addtolist: slist = slist + $crlf + sline if s1 = "CALLBACK" then s = s3 else s = s2 end if listview insert item hD, %IDC_LV, nrow, 0, s redim preserve findex(1 to nrow) findex(nrow).start = linenum findex(nrow).sfname = s if nrow > 1 then if findex(nrow -1).finish = 0 then findex(nrow-1).finish = linenum -1 end if end if listview set text hD, %IDC_LV, nrow, 1, s listview set text hD, %IDC_LV, nrow, 2, sline return ''''''''''''''' nudgelist: slist = slist + $crlf + "############ NUDGE ###############" + s1 + "@" + s2 + "@" + sline findex(nrow).finish = linenum -1 incr nrow return end function '---------------------------------------------------------- callback function CodeDlgProc() local x, y as long select case as long cbmsg case %wm_initdialog ' case %wm_move, %wm_size dialog get client cb.hndl to x, y control set size cb.hndl, %IDC_TEXTBOX1, x, y ' case %wm_ncactivate static hWndSaveFocus as dword if isfalse cbwparam then hWndSaveFocus = GetFocus() elseif hWndSaveFocus then SetFocus(hWndSaveFocus) hWndSaveFocus = 0 end if ' case %wm_destroy ' let the parent dialog know that we have finished dialog post getparent(cb.hndl), %wm_user + 501, cb.hndl, 0 ' case %wm_command select case as long cbctl case %IDC_TEXTBOX1 end select end select end function '-------------------------------------------------- function CodeDlg(byval hParent as dword, fx as long) as long static xoffset, yoffset as long local lRslt as long local hDlg as dword local i, nfrom, nto as long local s as string nfrom = findex(fx).start nto = findex(fx).finish '? str$(nfrom) + str$(nto) xoffset += 5: yoffset += 5 dialog new hParent, "F2+ code viewer", xoffset, yoffset, 201, 121, _ %ws_popup or %ws_border or %ws_dlgframe or %ws_sysmenu or _ %ws_minimizebox or %ws_clipsiblings or %ws_visible or _ %ds_modalframe or %ds_3dlook or %ds_nofailcreate or _ %ds_setfont or %ws_thickframe, _ %ws_ex_controlparent or %ws_ex_left or %ws_ex_ltrreading or %ws_ex_rightscrollbar, to hDlg findex(fx).hWnd = hDlg control add textbox, hDlg, %IDC_TEXTBOX1, "", 0, 0, 192, 110, _ %ws_child or %ws_visible or %ws_tabstop or %ws_hscroll _ or %ws_vscroll or %es_left or %es_multiline or %es_autohscroll or %es_autovscroll or %es_readonly, %ws_ex_clientedge or _ %ws_ex_left or %ws_ex_ltrreading or %ws_ex_rightscrollbar control set color hDlg, %IDC_textbox1, -1, %white ' build the source code table s = "" for i = nfrom - 1 to nto s = s + $crlf + sourcecode(i) next s = mid$(s,2) control set text hDlg, %IDC_TEXTBOX1, s dialog get text hParent to s dialog set text hDlg, findex(fx).sfname + " in " + parse$(s," ", 2) dialog set user hDlg, 1, fx dialog show modeless hDlg, call CodeDlgProc to lRslt function = lRslt end function '-------------------------------------------------------- callback function MainDlgProc() local i, j, l, n, nfrom, nto, nsel, x, y as long local s, soldcode as string local prevfindex() as tfindex static htimer as dword static sourcecodefile as string static dird, dird1 as dirdata ' select case as long cbmsg case %wm_initdialog listview set stylexx cb.hndl, %IDC_LV, _ %LVS_ex_infotip or %LVS_EX_FULLROWSELECT or %LVS_EX_ONECLICKACTIVATE or %LVS_EX_GRIDLINES listview reset cb.hndl, %IDC_LV listview insert column cb.hndl, %IDC_LV, 1, "Name", 100, 0 listview insert column cb.hndl, %IDC_LV, 2, "header", 500, 0 sourcecodefile = inputbox$("enter the source code module name") if trim$(sourcecodefile) = "" then dialog end cb.hndl, 0 end if if isfile(sourcecodefile) = 0 then ? "file " + sourcecodefile + " not found!" dialog end cb.hndl, 0 end if s = dir$ (sourcecodefile to dird) build(cb.hndl, %IDC_LV, sourcecodefile) htimer = settimer ( cb.hndl,%null, 2000, %null) ' case %wm_timer s = dir$ (sourcecodefile to dird1) if dird1.LastWriteTime <> dird.lastwritetime then erase sourcecode() ' get rid of the previous sourcecode array dird = dird1 listview reset cb.hndl, %IDC_LV l = lbound(findex()) dim prevfindex(l to ubound(findex())) poke$ varptr(prevfindex(l)), peek$(varptr(findex(l)),sizeof(findex(l)) * arrayattr(findex(),4)) erase findex() build(cb.hndl, %IDC_LV, sourcecodefile) for i = lbound(findex()) to ubound(findex()) if prevfindex(i).hWnd then ' get the text in the "new" file for the named Function s = trim$(prevfindex(i).sfname) listview find exact cb.hndl, %IDC_LV, 1, s to n ' if the function no longer exists, kill the viewer window and exit if n = 0 then dialog end prevfindex(i).hWnd, 0 exit select end if ' fn is present, get its text s = "" for j = findex(n).start - 1 to findex(n).finish s = s + $crlf + sourcecode(j) next s = mid$(s,2) control get text prevfindex(i).hWnd, %IDC_TEXTBOX1 to soldcode ' compare it with the version in the viewer window ' if different, kill the viewer window and create a new one ' if the same, update the entry in the current findex table for ' the existing code window if s <> soldcode then dialog end prevfindex(i).hWnd, 0 codedlg ( cb.hndl, n ) else findex(i).hWnd = prevfindex(i).hWnd end if end if next end if ' case %wm_destroy killtimer cb.hndl, htimer ' case %wm_user + 501 ' child dialog has ended - clear hWnd in findex table for i = lbound(findex()) to ubound(findex()) if findex(i).hWnd = cb.wparam then findex(i).hWnd = 0 exit for end if next ' case %wm_move, %wm_size dialog get client cb.hndl to x, y control set size cb.hndl, %IDC_LV, x, y ' case %wm_notify select case cb.ctl case %IDC_LV select case cb.nmcode case %nm_click listview get select cb.hndl, %IDC_LV to nsel 'listview get user cb.hndl, %IDC_LV, nsel to n nfrom = findex(nsel).start nto = findex(nsel).finish CodeDlg(cb.hndl, nsel) end select end select ' case %wm_ncactivate static hWndSaveFocus as dword if isfalse cbwparam then hWndSaveFocus = GetFocus() elseif hWndSaveFocus then SetFocus(hWndSaveFocus) hWndSaveFocus = 0 end if end select end function '------------------------------------------------------------------------ function MainDlg(byval hParent as dword) as long local lRslt as long local hDlg as dword dialog new hParent, "F2+", 193, 143, 201, 121, _ %ws_popup or %ws_border or %ws_dlgframe or %ws_sysmenu or %ws_minimizebox or _ %ws_clipsiblings or %ws_visible or %ds_modalframe or %ds_3dlook or _ %ds_nofailcreate or %ds_setfont or %ws_thickframe, _ %ws_ex_controlparent or %ws_ex_left or %ws_ex_ltrreading or %ws_ex_rightscrollbar, _ to hDlg control add "SysListView32", hDlg, %IDC_LV, "SysListView32_1", 0, 0, 192, 100, _ %ws_child or %ws_visible or %ws_tabstop or %lvs_report or %lvs_showselalways, _ %ws_ex_left or %ws_ex_clientedge or %ws_ex_rightscrollbar dialog show modal hDlg, call MainDlgProc to lRslt function = lRslt end function '--------------------------------------------------------------------- function pbmain() initcommoncontrols MainDlg %hwnd_desktop end function
Comment