Post Reply 
Program to search inside programs
09-29-2015, 05:44 PM (This post was last modified: 09-29-2015 07:02 PM by xset.)
Post: #1
Program to search inside programs
Hello. As far as Programs sorted chronologically, first program text is text of current program. So u press SHIFT+[User] then S and enter text to search, it will print line number and text in the line. Unfortunately we can't control position of cursor inside program editor, and can't call editor to edit some program (i wish developers will think about it). U also can run

Look code in text and same in attachment.
Find all posts by this user
Quote this message in a reply
09-29-2015, 06:52 PM (This post was last modified: 09-29-2015 07:01 PM by xset.)
Post: #2
Global search and local search
U press SHIFT+[User] and G (Sin key) to call global search on program texts
then enter text (currently case sensitive) and it will print results in form:
Program name:Line Number: Text

SHIFT+[User]+S (9 key) gives local search (search inside current program).

Code:

EXPORT ProgSrch(str)
BEGIN
    LOCAL CurProg:=Programs(1);
    LOCAL L:=DIM(CurProg);
    LOCAL LineNo:=1;
    LOCAL SLine:=1;
    LOCAL i;
    PRINT();
    FOR i FROM 1 TO L DO
        LOCAL cCH:=CurProg(i);
        IF cCH==10 THEN
           LOCAL s:=MID(CurProg,SLine,i-SLine+1);
           IF INSTRING(s,str) THEN
              PRINT(LineNo+": "+s);
           END;
           SLine:=i+1;
           LineNo:=LineNo+1;
        END;   
    END;
END;

CONCATSTRS(lst)
BEGIN
    LOCAL res:="";
    FOR I FROM 1 TO SIZE(lst) DO
       res:=res+lst(I);
    END;
    RETURN res;
END;

EXPORT ProgGlobSrch(str)
BEGIN
    LOCAL Name:=head(Programs);
    LOCAL PrgList:=Programs;
    LOCAL CurProg:=CONCATSTRS(MAKELIST(CHAR(10)+PrgList(X)+CHAR(13)+Programs(X),X,1,S​IZE(Programs)));
    LOCAL L:=DIM(CurProg);
    LOCAL LineNo:=1;
    LOCAL SLine:=1;
    LOCAL i;
    PRINT();
    FOR i FROM 1 TO L DO
        LOCAL cCH:=CurProg(i);
        IF cCH==13 THEN 
           Name:=MID(CurProg,SLine,i-SLine+1); // Program name
           SLine:=i+1;
           LineNo:=1;
        END;
        IF cCH==10 THEN
           LOCAL s:=MID(CurProg,SLine,i-SLine+1);
           IF INSTRING(s,str) THEN
              PRINT(Name+":"+LineNo+": "+s);
           END;
           SLine:=i+1;
           LineNo:=LineNo+1;
        END;   
    END;
END;

KEY K_Sin()
BEGIN
    LOCAL str:="";
    INPUT(str,"Search in program","string=","Enter string:","");
    IF str<>"" THEN       
        ProgGlobSrch(str);
    END;
    RETURN "";
END;


KEY K_9()
BEGIN
    LOCAL str:="";
    INPUT(str,"Search in program","string=","Enter string:","");
    IF str<>"" THEN       
        ProgSrch(str);
    END;
    RETURN "";
END;

Next task is case insensitive search and "Search and replace" in current program.


Attached File(s)
.hpprgm  ProgSrch.hpprgm (Size: 3.4 KB / Downloads: 6)
Find all posts by this user
Quote this message in a reply
09-29-2015, 07:45 PM (This post was last modified: 09-29-2015 07:45 PM by xset.)
Post: #3
RE: Program to search inside programs
Case insensitive version (only English letters of course)

Code:

EXPORT ReplToUpper(Str)
BEGIN
 FOR I FROM 1 TO DIM(Str) DO
    IF Str(I)≥97 AND Str(I)<123 THEN
       Str(I):=Str(I)-32;
    END;
 END;
 RETURN Str;
END;

EXPORT ProgSrch(str)
BEGIN
    str:=ReplToUpper(str);
    LOCAL CurProg:=Programs(1);
    LOCAL L:=DIM(CurProg);
    LOCAL LineNo:=1;
    LOCAL SLine:=1;
    LOCAL i;
    PRINT();
    FOR i FROM 1 TO L DO
        LOCAL cCH:=CurProg(i);
        IF cCH==10 THEN
           LOCAL s:=MID(CurProg,SLine,i-SLine+1);
           IF INSTRING(ReplToUpper(s),str) THEN
              PRINT(LineNo+": "+s);
           END;
           SLine:=i+1;
           LineNo:=LineNo+1;
        END;   
    END;
    PRINT("SEARCH FINISHED.");
END;

CONCATSTRS(lst)
BEGIN
    LOCAL res:="";
    FOR I FROM 1 TO SIZE(lst) DO
       res:=res+lst(I);
    END;
    RETURN res;
END;

EXPORT ProgGlobSrch(str)
BEGIN
    str:=ReplToUpper(str);
    LOCAL Name:=head(Programs);
    LOCAL PrgList:=Programs;
    LOCAL CurProg:=CONCATSTRS(MAKELIST(CHAR(10)+PrgList(X)+CHAR(13)+Programs(X),X,1,S​IZE(Programs)));
    LOCAL L:=DIM(CurProg);
    LOCAL LineNo:=1;
    LOCAL SLine:=1;
    LOCAL i;
    PRINT();
    FOR i FROM 1 TO L DO
        LOCAL cCH:=CurProg(i);
        IF cCH==13 THEN 
           Name:=MID(CurProg,SLine,i-SLine+1); // Program name
           SLine:=i+1;
           LineNo:=1;
        END;
        IF cCH==10 THEN
           LOCAL s:=MID(CurProg,SLine,i-SLine+1);
           IF INSTRING(ReplToUpper(s),str) THEN
              PRINT(Name+":"+LineNo+": "+s);
           END;
           SLine:=i+1;
           LineNo:=LineNo+1;
        END;   
    END;
    PRINT("SEARCH FINISHED.");
END;

KEY K_Sin()
BEGIN
    LOCAL str:="";
    INPUT(str,"Search in program","string=","Enter string:","");
    IF str<>"" THEN       
        ProgGlobSrch(str);
    END;
    RETURN "";
END;


KEY K_9()
BEGIN
    LOCAL str:="";
    INPUT(str,"Search in program","string=","Enter string:","");
    IF str<>"" THEN       
        ProgSrch(str);
    END;
    RETURN "";
END;


Attached File(s)
.hpprgm  ProgSrch.hpprgm (Size: 4.01 KB / Downloads: 10)
Find all posts by this user
Quote this message in a reply
09-30-2015, 05:40 AM
Post: #4
RE: Program to search inside programs
Hello,

Nice work!

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
09-30-2015, 06:24 AM (This post was last modified: 09-30-2015 06:25 AM by xset.)
Post: #5
RE: Program to search inside programs
(09-30-2015 05:40 AM)cyrille de brébisson Wrote:  Nice work!

Thanks! I think this is only begining. We need fully functional editor. Currently i am investigating how to calculate exact size of text drawed TEXTOUT_P, so we could find there to put cursor and how much to shift because of scrolling.

I think new editor should support:
1) Undo
2) Selecting of whole word by touching it (often used to copy variable name).
3) Fast shortcuts for selection of whole line or number of lines for copy-paste (current SHIFT-COPY SHIFT-PASTE is awful).
4) Some kind of autocompleting and hints
5) Fast gestures to call Search and Global Search with jumping on results. Also Search and Replace !
6) Fast jumping between functions in current module (selecting from list).
7) Screen keyboard (because my eyes crying looking at orange letters on gray), useful with capacitive stylus.

Any help would be appreciated. There many tasks for doing GUI things like listboxes, screen menus, dialogs for searching, etc.

Best regards
XSet
Find all posts by this user
Quote this message in a reply
09-30-2015, 07:55 AM (This post was last modified: 09-30-2015 08:22 AM by StephenG1CMZ.)
Post: #6
RE: Program to search inside programs
I had thought my Z EDITOR was a useful way of searching Notes and Programs, until I saw your approach. Very impressive.

Both our programs seem to have an issue parsing strings like "WAIT(", because INPUT returns a pair of brackets instead.

Could you add searching of Notes too?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-30-2015, 08:04 AM
Post: #7
RE: Program to search inside programs
(09-30-2015 06:24 AM)xset Wrote:  7) Screen keyboard (because my eyes crying looking at orange letters on gray), useful with capacitive stylus.

YES !
We need a virtual keyboard that we can popup quickly.
Thank you xset.

Alpha keys are not readable on physical keyboard, I don't konw if hp fixed that on later hardware revision, or plan to do it...
Find all posts by this user
Quote this message in a reply
09-30-2015, 08:35 AM
Post: #8
RE: Program to search inside programs
(09-30-2015 08:04 AM)hpfx Wrote:  
(09-30-2015 06:24 AM)xset Wrote:  7) Screen keyboard (because my eyes crying looking at orange letters on gray), useful with capacitive stylus.

YES !
We need a virtual keyboard that we can popup quickly.
Thank you xset.

Alpha keys are not readable on physical keyboard, I don't konw if hp fixed that on later hardware revision, or plan to do it...

As well as improving visibility, a QWERTY pop-up would be useful.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-30-2015, 09:41 AM
Post: #9
RE: Program to search inside programs
(09-30-2015 07:55 AM)StephenG1CMZ Wrote:  Could you add searching of Notes too?

Not a problem, it's time to extract functions which actually does parsing, searching and use them on anything including Notes. Need to find some modular OOP-like technology for development, that is sad HPPL is not Lua :-(
Find all posts by this user
Quote this message in a reply
09-30-2015, 03:13 PM (This post was last modified: 09-30-2015 04:37 PM by StephenG1CMZ.)
Post: #10
RE: Program to search inside programs
On the Android emulator I find that when I cut and paste the code, there appears to be a space within one SIZE. Deleting that one space, it compiles OK.

The User S Search sequence works great, but the User G Globalsearch is ineffective:
After entering the search text, it drops back to the edited text inserting SIN() into the text.

If I attempt to Run the Globalsearch from your code, instead of from a file one is editing, I get an insufficient memory error. I suspect it's just that the code being searched is too big.
Update: Instead of using MAKELIST to make one big list, looping through each file in turn would reduce the memory required.

But that User S search within program is a great feature.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-30-2015, 04:30 PM
Post: #11
RE: Program to search inside programs
(09-30-2015 03:13 PM)StephenG1CMZ Wrote:  On the Android emulator I find that when I cut and paste the code, there appears to be a space within one SIZE. Deleting that one space, it compiles OK.

Better use attached hpprgm, i also have found some bugs with copied text.

(09-30-2015 03:13 PM)StephenG1CMZ Wrote:  If I attempt to Run the Globalsearch from your code, instead of from a file one is editing, I get an insufficient memory error. I suspect it's just that the code being searched is too big.

You can change K_Sin() with K_8() OR KA_9() to move shortcut to appropriate keys.

I am currently working on universal search (current program, all programs, notes). I though new cool feature for the editor, which also will be implemented there. I killed many hours trying to construct fast function calls "by pointer" but they still costs at least triple of direct call :-( Why HP banned "program" concept from RPL, you could pass symbol and eval it fast. EXPR is too slow. I am missing pointers to functions to write clean extendable code. :-( Looks like we can not avoid text code generation in some language higher than HPPL, but I can't figure how to implement "function as value" conception in absence of "program as value" mechanisms :-(
Find all posts by this user
Quote this message in a reply
09-30-2015, 05:02 PM
Post: #12
RE: Program to search inside programs
On the Android emulator I don't think you can use hpprgm - it has to be cut and paste AFAIK.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-30-2015, 05:09 PM (This post was last modified: 09-30-2015 08:51 PM by xset.)
Post: #13
Version 0.3
This version includes:

1) Searching in current program (or in last edited) Shift-USER S (S is button [9])
2) Searching in all programs Shift-USER Shift-S (S is button [9])
3) Searching in current note (or in last edited Note if u are not in editor)
Shift-USER Note (Note is button [0])
4) Searching in all notes
Shift-USER Shift-Note (Note is button [0])

The program now contains semi-unversal function GlobSearch with arguments: str, IType, BCaseSense

str - string to search.
IType: 1 - Local searching in program, 2- Global searching in programs, 3-Local searching in note, 4-Global searching in notes.
BCaseSense: 1 - Case insensitive, other values - Case sensitive

Currently I hardcoded case insensitive search everywhere, so one need to change searching dialog to add check box
for sensitive searching (just in case).

Text of program, but better use attached file:
Code:

ReplToUpper(Str)
BEGIN
 FOR I FROM 1 TO DIM(Str) DO
    IF Str(I)≥97 AND Str(I)<123 THEN
       Str(I):=Str(I)-32;
    END;
 END;
 RETURN Str;
END;

CONCATSTRS(lst)
BEGIN
    LOCAL res:="";
    FOR I FROM 1 TO SIZE(lst) DO
       res:=res+lst(I);
    END;
    RETURN res;
END;

EXPORT GlobSearch(str,IType,BCaseSense)
BEGIN
   IF BCaseSense==1 THEN
      str:=ReplToUpper(str);
   END;
    LOCAL AText:="";

    CASE
      IF IType==1 THEN AText:=Programs(1); END; // Current program
      IF IType==2 THEN  // Search in all programs
        LOCAL TitleList:=Programs; 
        AText:=CONCATSTRS(MAKELIST(CHAR(10)+TitleList(X)+CHAR(13)+Programs(X),
                    X,1,SIZE(TitleList))); 
      END;
      IF IType==3 THEN  // Search in current Note
         AText:= Notes(1);
      END;
      IF IType==4 THEN  // Search in all notes
         LOCAL TitleList:=Notes; 
         AText:=CONCATSTRS(MAKELIST(CHAR(10)+TitleList(X)+CHAR(13)+Notes(X),
                 X,1,SIZE(TitleList))); 
      END;
    DEFAULT
         PRINT("IType argument can be 1-4");
         RETURN 0;
    END;
    LOCAL Name:="";
    LOCAL L:=DIM(AText);
    LOCAL LineNo:=1;
    LOCAL SLine:=1;
    LOCAL i;
    PRINT();
    FOR i FROM 1 TO L DO
        LOCAL cCH:=AText(i);
        IF cCH==13 THEN 
           Name:=MID(AText,SLine,i-SLine+1); // Program or Note title
           SLine:=i+1;
           LineNo:=1;
        END;
        IF cCH==10 OR i==L THEN
           LOCAL s:=MID(AText,SLine,i-SLine+1);
           IF BCaseSense==1 THEN
              s:=ReplToUpper(s);
           END;
           IF INSTRING(s,str) THEN
              PRINT(Name+":"+LineNo+": "+s);
           END;
           SLine:=i+1;
           LineNo:=LineNo+1;
        END;   
    END;
    PRINT("SEARCH FINISHED.");
    RETURN 1;
END;

KEY KS_9() // Shift-USER Shift-S
BEGIN
    LOCAL str:="";
    INPUT(str,"Global search in programs","string=","Enter string:","");
    IF str<>"" THEN       
        GlobSearch(str,2,1);
    END;
    RETURN "";
END;


KEY K_9() // Shift-USER S
BEGIN
    LOCAL str:="";
    INPUT(str,"Local search in program","string=","Enter string:","");
    IF str<>"" THEN       
        GlobSearch(str,1,1);
    END;
    RETURN "";
END;

KEY K_0() // Shift-USER [Notes] (0 button)
BEGIN
    LOCAL str:="";
    INPUT(str,"Search in current Note","string=","Enter string:","");
    IF str<>"" THEN       
        GlobSearch(str,3,1);
    END;
    RETURN "";
END;

KEY KS_0() // Shift-USER Shift-[Notes] (0 button)
BEGIN
    LOCAL str:="";
    INPUT(str,"Global search in Notes","string=","Enter string:","");
    IF str<>"" THEN       
        GlobSearch(str,4,1);
    END;
    RETURN "";
END;

Best regards
XSet


Attached File(s)
.hpprgm  ProgSrch.hpprgm (Size: 5.37 KB / Downloads: 5)
Find all posts by this user
Quote this message in a reply
09-30-2015, 05:18 PM
Post: #14
RE: Program to search inside programs
(09-30-2015 05:02 PM)StephenG1CMZ Wrote:  On the Android emulator I don't think you can use hpprgm - it has to be cut and paste AFAIK.

Life is life. But I also publish texts copied from Connectivity Kit window, so I hope it will be useful on Android as well.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)