1. Updated File Search & Select PGM

Oct. 11, 1996
To all,

I have modified my "filesrch.e" program. This program makes it easy
to find and select a file on your computer, network, or CD-ROM drive
and then returns the file name and path to your program.  Version 1.
1
now allows the default, or startup directory, to be either the
current
directory or a user defined directory.  Also new, on EXIT the
program
returns the directory path displayed on the first line, or the
current
directory when you EXIT from the "Select Drive" screen.
"filesrch.e" uses graphics text Mode 3 with 25 lines of text.

One example where I find it very useful is the Euphoria Editor, ed.ex;

no longer do you have to remember the file name and type it in, but
you
can search on all drives and subdirectories for the desired file and
then click on the mouse left button to select the file and return it
to
the editor.  If you want to create a new file, just move with the
mouse
to the drive and directory you want the file to be in, and then
click
on EXIT.  The desired path will be displayed on line one of the
editor
and it will be waiting for you to type in the new file name.

To check out the program to see how it works on your system you can
type in this short program:

    include filesrch.e   -- Name of the include file routine
    sequence fs
    fs = file_select("") -- "" selects the current directory on
                         -- startup or type "c:\\euphoria\\" for
                         -- example, for a user defined startup
                         -- directory.
    puts(1,fs)           -- Prints to screen the selected path
                         -- and file name selected.

If this short program works fine, you may want to use this feature
in the Euphoria Editor or your own program.

Following are instructions to modify the Euphoria Editor.  Don't
forget to make a backup copy of the editor prior to making changes.
At the beginning of the ed.ex program the nine (9) new lines are
added as shown below, several of them being comments for future
reference:

        ----------------------------------------------------------
        --       This Euphoria Editor was developed by          --
        --            Rapid Deployment Software.                --
        --                                                      --
        -- Permission is freely granted to anyone to modify     --
        -- and/or redistribute this editor (ed.ex, syncolor.e). --
        -- You may even sell it as it is, or with your          --
        -- modifications.                                       --
        --                                                      -- --new
        -- Revision History:                                    -- --new
        -- 10/11/96  Ver 1.1 filesrch.e include function added  -- --new
        ----------------------------------------------------------

without type_check -- makes it a bit faster
include graphics.e
include get.e
include file.e
include filesrch.e -- Returns path & file name; Exit returns path  --
new
sequence startup_path, file_path                                   --
new
startup_path = ""                                                  --
new
        -- "" selects the current directory on startup.            --new
        -- Type "c:\\euphoria\\demo\\", for example,               --new
        -- for a user defined startup directory.                   --new


To find the next section of the program that is changed use the find
feature of the editor.  Press the "Esc" key, then f, then type in
the
words, file name:, and press the enter key twice. It will take you
to
the section listed below.  Nine (9) new lines are added, and one (1)
modified.  The modified code should look like the following:

elsif command[1] = 'n' then
    if modified and last_use() then
        set_top_line("")
        printf(SCREEN, "save changes to %s? ", {file_name})
        if find('y', key_gets("yn")) then
            save_file(file_name)
        end if
    end if
    save_state()
    temp_name = lower(file_select(startup_path))              --new
    if temp_name[length(temp_name)] = 92 then                 --new
        file_path = temp_name                                 --new
        set_top_line("new file name: " & file_path)        --modify
        temp_name = delete_trailing_white(key_gets(""))
        if length(temp_name) != 0 then                        --new
            temp_name = file_path & temp_name                 --new
            else                                              --new
                set_top_line("file name:  " & file_name)      --new
        end if                                                --new
    end if                                                    --new
    if length(temp_name) != 0 then
        file_name = temp_name
        stop = TRUE
    end if


The next section is also found with the find feature.  Press the
"Esc" key, then f, then press the Enter key (find defaults to, file
name:). It will take you to the section listed below.  Six (6)new
lines are added, two (2) are modified, and two (2) are deleted.
The modified code will look like the following, minus the two
deleted
lines:

if length(file_name) = 0 then
     -- we still don't know the file name - so ask user
    file_name = lower(file_select(startup_path))             --new
    if file_name[length(file_name)] = 92 then                --new
        file_path = file_name                                --new
        puts(SCREEN, "new file name: " & file_path)       --modify
        cursor(ED_CURSOR)
        file_name = delete_trailing_white(key_gets(""))   --modify
        puts(SCREEN, '\n')
     end if                                               --delete
     file_name = delete_trailing_white(file_name)         --delete
        if length(file_name) = 0 then
            abort(1) -- file_name was just whitespace - quit
        end if
        file_name = file_path & file_name                    --new
    end if                                                   --new
end if                                                       --new
file_no = open(file_name, "r")


That completes all the changes necessary for the Euphoria Editor.

I am providing this include file program to the Euphoria Public
Domain.  This program is supplied "AS IS" and without warranty.
If there are changes needed to this program for your application,
feel free to modify to suit your needs.

Comments and/or improvement suggestion feedback is welcome.

Enjoy!!

Fred Cole      (facole at prodigy.com)

***************************  filesrch.e
********************************

              --------------------------------------------------
              ---            File Search & Select            ---
              ---                  Ver 1.1                   ---
              ---            Written by: Fred Cole           ---
              ---             facole at prodigy.com             ---
              ---       Free to Euphoria Public Domain       ---
              ---            Provided "AS IS" and            ---
              ---              Without Warranty              ---
              ---         Permission given to Modify         ---
              ---                                            ---
              --- Revision History:                          ---
              --- 10/11/96 Ver 1.1 Startup path added;       ---
              ---          returns last path on EXIT         ---
              ---  9/26/96 Ver 1.0 Original                  ---
              --------------------------------------------------

-- Search sub-directories and drives using a mouse to search for
-- a file.  When the desired file is found and the mouse pointer
-- is moved to that line, the mouse left button is clicked to
-- return the directory path and file name of the selected file.
-- The startup directory is the current directory when a {} is
-- passed to this include file, or the startup directory can be
-- user defined when the path is passed to this include file, for
-- example, "c:\\euphoria\\".  When EXIT is clicked the directory
-- path shown on the first line is returned.  When EXIT is clicked
-- on the "Select Drive" screen the current directory is returned.
-- Use in Graphics Mode (3) with 25 lines text.

include file.e
include get.e
include graphics.e
include image.e
include machine.e
include mouse.e
include sort.e

function mouse()
    object y
    mouse_events(LEFT_DOWN)
    mouse_pointer(1)
    while 1 do
        y = get_mouse()
        if atom(y) then
            else
                exit
        end if
    end while
    mouse_pointer(0)
    return y
end function

procedure first_line(sequence b)
    text_color(6)
    position(1,15)
    puts(1,"Directory Path is:")
    position(1,35)
    text_color(9)
    puts(1,b)
end procedure

function file_path(sequence b)
    object x,y,p
    integer a,c
    sequence x1,x2
    x = dir(b)
    p = 0
    if not atom(x) and length(b)>3 then
        for t=1 to length(x) by 1 do
            if find("..",x[t]) = 0 then
                else
                    p = 1
                    exit
            end if
        end for
        if p=0 then
            p = {{46,46},{100},0,0,0,0,0,0,0}
            x = prepend(x,p)
        end if
    elsif atom(x) and length(b)>3 then
        x = {{{46,46},{100},0,0,0,0,0,0,0}}
    elsif atom(x) then
        clear_screen()
        while atom(x) do
            first_line(b)
            position(3,15)
            text_color(15)
            puts(1,"NO FILES FOUND")
            text_color(3)
            position(25,37)
            puts(1,"<CHANGE DRIVE>")
            text_color(4)
            puts(1,"         <EXIT>")
            y = mouse()
            if y[3]/8 = 24 and y[2] < 288 or y[2] > 392 and y[2]<472
                or y[2]>512 then
            elsif y[3]/8 = 24 and y[2] <= 392 and y[2] >= 288 then
                return("CHANGE DRIVE")
            elsif y[3]/8 = 24 and y[2] <= 512 and y[2] >= 472 then
                return({b} & {"EXIT"})
            end if
        end while
    end if
    x = sort(x)
    a = 0
    x1 = {}
    x2 = {}
    while a < length(x) do
        a = a+1
        if compare(x[a][2],"d") = 0  then
            x1 = append(x1,x[a])
            else x2 = append(x2,x[a])
        end if
    end while
    clear_screen()
    first_line(b)
    a = 0
    c = 0
    x = x1 & x2
    while a < length(x) do
        a = a+1
        if compare(x[a][2],"d") = 0  then
            text_color(14)
            else text_color(15)
        end if
        position(c+2,8)
        printf(1,"%12s",{x[a][1]})
        printf(1,"  %4s",{x[a][2]})
        printf(1,"   %7d",x[a][3])
        printf(1,"  %02d",x[a][5])
        printf(1,"/%02d",x[a][6])
        printf(1,"/%04d",x[a][4])
        printf(1,"  %02d",x[a][7])
        printf(1,":%02d",x[a][8])
        printf(1,":%02d\n",x[a][9])
        c = c+1
        if a > 23 and a = length(x) then
            position(25,21)
            text_color(10)
            puts(1,"<RETURN>")
            text_color(3)
            position(25,37)
            puts(1,"<CHANGE DRIVE>")
            text_color(4)
            puts(1,"         <EXIT>")
            y = mouse()
            if y[3]/8 > c and y[3]/8 < 24 or y[3] = 0 or (y[3]/8 = 24
                and y[2] < 160 or y[2] > 216 and y[2] < 288 or
                y[2] > 392 and y[2]<472 or y[2]>512) then
                first_line(b)
                a = a - c
                c = 0
            elsif y[3]/8 = 24 and y[2] <= 216 and y[2] >= 160 then
                clear_screen()
                first_line(b)
                a = 0
                c = 0
            elsif y[3]/8 = 24 and y[2] <= 392 and y[2] >= 288 then
                return("CHANGE DRIVE")
            elsif y[3]/8 = 24 and y[2] <= 512 and y[2] >= 472 then
                return({b} & {"EXIT"})
            elsif (y[3]/8)-c <= 0 and y[3] != 0 then
                return (x[y[3]/8+a-c])
            end if
        elsif a <= 23 and a = length(x) then
            text_color(3)
            position(25,37)
            puts(1,"<CHANGE DRIVE>")
            text_color(4)
            puts(1,"         <EXIT>")
            y = mouse()
            if (y[3]/8)-c <= 0 and y[3] != 0 then
                return (x[y[3]/8+a-c])
            elsif y[3]/8 > c and y[3]/8 < 24 or y[3] = 0 or (y[3]/8 = 24
                and y[2] < 288 or y[2] >392 and y[2]<472 or y[2]>512) then
                first_line(b)
                a = 0
                c = 0
            elsif y[3]/8 = 24 and y[2] <= 392 and y[2] >= 288 then
                return("CHANGE DRIVE")
            elsif y[3]/8 = 24 and y[2] <= 512 and y[2] >= 472 then
                return({b} & {"EXIT"})
            end if
        elsif c = 23 and a != length(x) then
            position(25,22)
            text_color(10)
            puts(1,"<MORE>")
            text_color(3)
            position(25,37)
            puts(1,"<CHANGE DRIVE>")
            text_color(4)
            puts(1,"         <EXIT>")
            y = mouse()
            if y[3]=8*24 and y[2]<=208 and y[2]>=168 then
                clear_screen()
                first_line(b)
                c = 0
            elsif y[3] != 0 and y[3] != 8*24 then
                return (x[y[3]/8+a-c])
            elsif y[3] = 0 or (y[3]=8*24 and y[2]<168 or y[2]>208 and
                y[2]<288 or y[2]>392 and y[2]<472 or y[2]>512) then
                first_line(b)
                c = 0
                a = a - 23
            elsif y[3]/8 = 24 and y[2] <= 392 and y[2] >= 288 then
                return("CHANGE DRIVE")
            elsif y[3]/8 = 24 and y[2] <= 512 and y[2] >= 472 then
                return({b} & {"EXIT"})
            end if
        end if
    end while
end function

function select_drive()
    sequence rv -- list of register values
    object b, bl, br, cntr, drives, xy
    bk_color(0)
    clear_screen()
    drives = {}
    for h=1 to 26 by 1 do
        rv = repeat(0, 10)  -- zero register
        rv[REG_AX] = #4409  -- Function: Check if Block Device is Remote
        rv[REG_BX] = 0000 + h     -- Drive Number
        rv = dos_interrupt(#21, rv) -- Call DOS interrupt #21
        if rv[5] != 0 then
            drives = drives & 64+h & "  "
        end if
    end for
    position(2,34)
    text_color(10)
    puts(1,"Select Drive\n\n")
    text_color(15)
    cntr = 40 - floor((length(drives))/2)-- Center available Drive
Choices
    puts(1,repeat(32,cntr) & drives)
    br = 24*((length(drives))/3-1)+8*cntr
    bl = 8*cntr
    text_color(4)
    position(25,60)
    puts(1,"<EXIT>")
    position(5,1)
    mouse_events(LEFT_DOWN)
    while 1 do
        xy = mouse()
        if xy[2]<bl or xy[2]>br or xy[3]<24 or xy[3]>24 then
            if xy[3]/8 = 24 and xy[2] <= 512 and xy[2] >= 472 then
                return("EXIT")
            end if
        elsif remainder((xy[2]-bl),24)=0 then
            b = drives[((xy[2]-bl)/8)+1]
            return (b)
        end if
    end while
end function

procedure closing()
    cursor(UNDERLINE_CURSOR)
    text_color(15)
    set_active_page(0)
    set_display_page(0)
end procedure

global function file_select(sequence path)
    sequence t
    object b
    integer i
    set_active_page(1)
    set_display_page(1)
    bk_color(0)
    clear_screen()
    text_color(4)
    cursor(NO_CURSOR)
    b = current_dir()
    if compare(path,{}) != 0 and compare(b,path) != 0 then
        b = path[1..length(path)-1]
    end if
    t = file_path(b)
    if compare(t[2],"EXIT") = 0 then
        if length(t[1]) = 3 then
            t[1] = t[1][1..2]
        end if
        closing()
        return(t[1] & {92})
    elsif length(b) = 3 then
        b = b[1..2]
    end if
    b = b & "\\"
    while compare(t[2],"d") = 0  do
        if compare(t[1],"..") = 0 then
            i = length(b)-1
            while compare(b[i],92) != 0 do
                i = i-1
            end while
            b = b[1..i]
        elsif compare(t[1],".") = 0 then
        else
            b = b & t[1] & "\\"
        end if
        if length(b) > 3 then
            t = file_path(b[1..length(b)-1])
            else
                t = file_path(b)
        end if
        if compare(t[2],"EXIT") = 0 then
            if length(t[1]) = 3 then
                t[1] = t[1][1..2]
            end if
            closing()
            return(t[1] & {92})
        end if
    end while
    while compare(t,"CHANGE DRIVE") = 0 do
        b = select_drive()
        if compare(b,"EXIT") = 0 then
            t = current_dir()
            if length(t) = 3 then
                t = t[1..2]
            end if
            closing()
            return(t & {92})
        end if
        b = b & ":\\"
        t = file_path(b)
        puts(1,"Next is value of t\n")
        if compare(t[2],"EXIT") = 0 then
            if length(t[1]) = 3 then
                t[1] = t[1][1..2]
            end if
            closing()
            return(t[1] & {92})
        end if
        while compare(t[2],"d") = 0  do
            if compare(t[1],"..") = 0 then
                i = length(b)-1
                while compare(b[i],92) != 0 do
                    i = i-1
                end while
                b = b[1..i]
            elsif compare(t[1],".") = 0 then
            else
                b = b & t[1] & "\\"
            end if
            if length(b) > 3 then
                t = file_path(b[1..length(b)-1])
                else
                    t = file_path(b)
            end if
            if compare(t[2],"EXIT") = 0 then
                if length(t[1]) = 3 then
                    t[1] = t[1][1..2]
                end if
                closing()
                return(t[1] & {92})
            end if
        end while
    end while
    closing()
    return (b & t[1])
end function

new topic     » topic index » view message » categorize

2. Re: Updated File Search & Select PGM

Dear Frederick
     below is the header of the copy of the "new" filesearch.e that you
distributed via email on the 11th

Below that.....

>        ----------------------------------------------------------
>        --       This Euphoria Editor was developed by          --
>        --            Rapid Deployment Software.                --
>        --                                                      --
>        -- Permission is freely granted to anyone to modify     --
>        -- and/or redistribute this editor (ed.ex, syncolor.e). --
>        -- You may even sell it as it is, or with your          --
>        -- modifications.                                       --
>        --                                                      -- --new
>        -- Revision History:                                    -- --new
>        -- 10/11/96  Ver 1.1 filesrch.e include function added  -- --new
>        ----------------------------------------------------------
>


Is the copy I have.
              ---         Permission given to Modify         ---
              ---                                            ---
              --- Revision History:                          ---
              --- 10/11/96 Ver 1.1 Startup path added;       ---
              ---          returns last path on EXIT         ---
              ---  9/26/96 Ver 1.0 Original                  ---
              --------------------------------------------------
Are both these your's?  Is it possible (maybe) I got a changed copy that
isn't compatible?  I will be checking this out tomorrow.

l8tr
Monty King

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu