HP Forums

Full Version: new program : FctBrowser [beta]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I made a small function browser for prime.
[Image: 10wi820.png] [Image: r04j1h.png]

run the program by FBrowser.
Features :
  • identify function definition, display their names and params (remove comments)
  • display line number
  • visually show function decorators (exported in green, keys assign in orange)
  • user interface : move with up/down key, it scrolls the screen if needed (no mouse yet, sorry)
  • user interface : close with ESC. press ENTER to jump to line nr (well, actually it just display a msgbox because such function does not exist... Tim ? Smile)
  • it exports "fct" variable (list of function names)

Download : [attachment=2650]

Version 0.1 : 8th of Oct 2015.
I may change few things in UI.

Code:
// functions browser v 0.1
// by primer - 8th of Oct 2015

#pragma mode( separator(.,;) integer(h32) )

//frw decl
pickPrg();
Analyse(p);
display();

EXPORT FBrowser() // functions browser entry point.
BEGIN
 local p:=pickPrg();
 if p≠"" then
  Analyse(p);
  display();
 end;
END;

pickPrg() // to pick a prog name
begin
 local prgs:=Programs;
 local p;
 choose(p,"Fct Browse to program",prgs);
 if p==0 then return ""; end;
 return prgs(p);
end;



collectFcts(p); //frw decl

///----------- Analysis ------------

// perform analysis on a program
Analyse(p)
begin
 collectFcts(p);
end;

/////////////////////// public vars
export fct;
export fctn;

analyseline(l,n); //frw decl

collectFcts(p)
begin
 local src:=Programs(p);
 local s:=size(src);
 local n:=1;
 local i,c,l;
 fct:={};
 fctn:={};

 l:="";
 for i from 1 to s do
  c:=mid(src,i,1);
  if c==char(10) then // line feed
   analyseline(l,n); 
   n:=n+1; // inc lin nr
   l:="";
  else
   l:=l+c;
  end;
 end; // for
 analyseline(l,n);
end;

//frw decl
trim(x);
trim_cmt(x);
register_fct(txt,n);

// statics vars
local prev:="";
local nprev:=0;

analyseline(l,n) // analyse la ligne
begin
 local a:=trim(trim_cmt(l));
 if upper(a)=="BEGIN" then
   register_fct(prev,nprev);
   prev:="";
 else
   if a≠"" then prev:=a; nprev:=n; end;
 end; // begin
end;


register_fct(txt,n) // save function information
begin
// print("L"+n+" : "+txt);
 local a:=upper(txt);
 local p:=instring(a,"EXPORT ");
 local export:=0;
 local pars:="";
 local nopar:=0;
 if p==1 then 
  txt:=trim(mid(txt,p+6));
  export:=1;
 end;
 p:=instring(a,"KEY ");
 if p==1 then 
  txt:=trim(mid(txt,p+3));
  export:=2; // it's a key assign
  nopar:=1; // no need for params
 end;

 // check is ends with ";", it should not
 if right(txt,1)==";" then return; end; // fausse alerte
 if nopar==1 then
  pars:="";
 else
  p:=instring(txt,"(");
  if p==0 then return; end; // fausse alerte :^)
  pars:=mid(txt,p);
  txt:=left(txt,p-1);
 end;
 fct:=concat(fct,txt);  
 fctn:=concat(fctn, {{n, export, pars}});
end;

trim_cmt(x) // remove cmt
begin
 local p:=instring(x,"//");
 if p==0 then return x; end;
 if p==1 then return ""; end;
 return mid(x,1,p-1);
end;

trim(x) // l/r trim
begin
 local s:=size(x);
 if s==0 then return ""; end;
 local i,a;
 local ok:=0;
 //debug;
 //left trim
 for i from 1 to s do
  if mid(x,i,1)≠" " then
   if i==1 then a:=x; else  a:=mid(x,i); end;
   ok:=1;
   break;
  end; //if
 end; //for
 if ok==0 then return ""; end;

 //right trim
 s:=size(a);
 if s==0 then return ""; end;
 for i from s downto 1 do
  if mid(a,i,1)≠" " then
   a:=mid(a,1,i);
   break;
  end; //if
 end; //for
 return a;
end;

//#missing hppl fct :  split, trim, mid(x,?,0)->"", mid(x,0)???


///----------- user interface ------------

// frw decl
initdsp();
dsploop();

display()
begin
 initdsp();
 dsploop();
end;

initdsp() // prepare G9 with all fcts from <ftc> + <ftcn> vars
begin
 local h:=SIZE(fct)*12;
 local i,t,x,p;
 DIMGROB_P(G9,300,h);
 for i from 1 to size(fct) do
  t:=fct(i);
  x:=fctn(i,2); // export y/n
  p:=fctn(i,3); // pars
  TEXTOUT_P(t,G9,10,(i-1)*12,2,#0h); // fct name
  TEXTOUT_P(p,G9,100,(i-1)*12,2,#444444h); // params
  if x==1 then RECT_P(G9,1,1+(i-1)*12,8,(i*12)-2,#21AC0Dh,#29D810h); end; // exported
  if x==2 then RECT_P(G9,1,1+(i-1)*12,8,(i*12)-2,#E7B00Eh,#F4CE59h); end; // key
 end;
end;


dsploop()
begin
 local f:=0; // ends the display loop
 local k; // key
 local pos:=1; // position
 local t; // temp txt
 local voffs:=0; // vertical offset
 while f==0 do
  RECT_P(); // clean screen
  BLIT_P(G0,40,1,G9,1,1+voffs);
  RECT_P(G0,1,(pos-1)*12-voffs,320,pos*12-voffs, {#54A7FAh, 127},{#54A7FAh, 127}); // selector
  t:=fctn(pos,1); // line nr
  TEXTOUT_P(t,G0,1,(pos-1)*12-voffs,2,#FFFFFFh,40,#0h); // fct name

  k:=wait();
  if k==30 then  f:=1; msgbox("Jump to line "+fctn(pos,1));  end; // enter
  if k==4 then  f:=1;  end; // esc
  if k==2 then // up
   pos:=max(pos-1,1);
   if pos*12-voffs<1 then    voffs:=voffs-12; end; // move veiwport up
  end;
  if k==12 then // down
   pos:=min(pos+1,size(fct));
   if pos*12-voffs>228 then    voffs:=voffs+12; end; // move veiwport down
  end;

 end; // while
end;
[attachment=2648]

Let me know your feeling...

I've a idea for a feature that may take time to be built... too early to speak about Tongue


Regards,
Hello,

Very nice work...
It would be nice if they was a programmatic way to open the program editor at a given line :-(

Cyrille
(10-08-2015 12:03 PM)primer Wrote: [ -> ]I've a idea for a feature that may take time to be built... too early to speak about Tongue


Regards,

You shall include this in a custom code editor Tongue in conjunction with the virtual keyboard (and a small one for symbols and recent used keywords)... and a live help panel: http://www.hpmuseum.org/forum/attachment.php?aid=2625
Hi,
(10-08-2015 02:43 PM)eried Wrote: [ -> ]You shall include this in a custom code editor...
No, building a new editor is a too big project. I've already thought about, but there are too many things to do, and so few tools in language (literaly, here 13% of my code is only to create a simple "trim()" command that does not exist). It's impossible to reach same level of quality and performance, built-in editor is not made with HPPL.

My dream would be : someone from hp do add a function browser in the built-in editor. Of course, it would be something better than mine where you can navigate from a function to another, jump to function definition...
If not, I hope at least they will add few string commands that would make life better. (picking for ex from popular php trim, split, join, strpad...)

Quote:I've a idea for a feature that may take time to be built... too early to speak about
This idea was to extend FBrowser with a new feature, not trying to recreate the full hp prime programing environment Wink
Thank you for your message, but I'm not able to.
Reference URL's