[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Aug 13 23:43:34 2003 
Subject:Re: listing directories and chario 
From:ug57dsm 
Volume-ID:1030813.01 

This is a multi-part message in MIME format.
--------------060102030206080000060803
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

david moss wrote:
> [loads of stuff...]

Hi,

I seem to have got over the listing directories problem, i.e. I can get
a listing of files in a directory, however I was wondering if there is a
way of getting a directory name (like sys_fname_name(dirname)) my
problem is that when I want to check the name of a fully qualified path
that ends with a slash, like ~/work/java/todo/ I get nothing back. I can
scan the string and strip the slash at the end, but was wondering if
there was a more elegant way of doing this...

The code is attached for you to look at... I'm getting there, i think...

The relevant section is the procedure listDir()...


-- 
=================================================
   The future of HTML mail is clearly > /dev/null.
=================================================
   Two of the most famous products of Berkeley are
LSD and Unix. I don t think that is a coincidence
=================================================



--------------060102030206080000060803
Content-Type: text/plain;
 name="server.p"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="server.p"

/****************************************************************
 *                                                              *
 *  File:       server.p                                        *
 *  Author:     dsm                                             *
 *  Created:    Mon Aug 11 2003                                 *
 *  Version:    0.0.9                                           *
 *                                                              *
 *  This file contains the instructions necessary to make pop11 *
 *  serve documents like ref, doc, help and teach files.        * 
 *                                                              *
 *  All the stuff is printed to stdout as plain ascii and       * 
 *  collected by the java container, then its prepended the     * 
 *  message string and sent to the client that requested it.    *
 *                                                              *
 ****************************************************************/

/* filter:  Filters a file containing ved control chars. Definition of filter shamelessly stolen 
 *          from REF * VEDPROCS
 * filein:  The file to convert to ASCII
 * fileout: A writable file to which the results will be printed (can be popdevout if is to be sent
 *          to stdout for example).
 * retval:  a string with the file in ascii
 */
define filter(filein, fileout) -> retval;
    lvars repeater, consumer, str;
    
    vedfile_line_repeater(filein) -> repeater;
    vedfile_line_consumer(fileout, 1) -> consumer;
    
    until (repeater() ->> str) == termin do
        consumer(str);
    enduntil;
enddefine;

/* getFileInASCII:  Gets a file and converts all the control chars to ASCII, then returns the
 *                  contents of the file
 * filename:        The name of the file to make ASCII
 * retval:          The resulting ASCII from the contents of file
 */
define getFileInASCII(filename) -> retval;
    ''->retval;
    ;;; open filename
    ;;; make a string device (REF CHARIO)
    ;;; use filter to make file into plain text and store in string
    ;;; return string
enddefine;

/* open:    Opens a file
 * args:    The argument list. Defines the file to open
 * retval:  A list of lines of the file, like [[first line] [second line] [third line]]
 */
define open(args) -> retval;
    if listlength(args) = 1 then
        pr('doing default open');nl(1);
    elseif listlength(args) > 1 then
        pr('doing open with args');nl(1);
    else
        pr('I\'m afraid I can\'t open with no args at all');nl(1);
    endif;
enddefine;

/* listDir: List a directory. It indicates when its gone into a directory by nested lists, for
 *          example, if you have dir/file, dir/sub/file, and dir/sub/file2 you would get 
 *          [[F file] [D sub [F file] [F file2]]]
 * dirname: The directory to list
 * retval:  The dir listing, looks like this, [>] [F fname] ... [D dirname] [>] ... [<] ... [<]
 */
define listDir(dirname) -> retval;
    [] -> retval;
    
    if dirname = "teach"
    or dirname = "doc"
    or dirname = "ref"
    or dirname = "help" then
        return;
    endif;

    [D ^(sys_fname_name(dirname))] -> retval;
    
    lvars allfiles = dirname dir_>< '*';
    lvars filep = sys_file_match(allfiles, '', false, 1);
    lvars filen, dirn, tmp;

    until (filep() ->> filen) == termin do
        if filen then
            dirname dir_>< filen -> dirn;

            if sysisdirectory(dirn) then
                [^^retval [^^(listDir(dirn))]] -> retval;
            else
                [^^retval [F ^filen]] -> retval;
            endif;
        else
            -> tmp; ;;; get rid of the path left over in stack
        endif;
    enduntil;
enddefine;

/* listList:    Lists the dir contents of a list working with listDir()
 * list:        The list to list
 * retval:      The listing of list
 */
define listList(list) -> retval;
    lvars i, o, tmp;
    [L]-> retval;
    
    for i in list do
        if islist(i) then
            listList(i) -> tmp;
        elseif isident(i) then
            listList(idval(i)) -> tmp;
        else
            listDir(i) -> tmp;
        endif;
            
        if tmp /= [] then
            [^^retval [^^tmp]] -> retval;
        endif
    endfor;
enddefine;
    
/* listRef: Lists the contents of REF
 */
define listRef() -> retval;
    listList(vedreflist) -> retval;
enddefine;

/* listTeach: Lists the contents of TEACH
 */
define listTeach() -> retval;
    listList(vedteachlist) -> retval;
enddefine;

/* listHelp: Lists the contents of HELP
 */
define listHelp() -> retval;
    listList(vedhelplist) -> retval;
enddefine;

/* listDoc: Lists the contents of DOC
 */
define listDoc() -> retval;
    listList(veddoclist) -> retval;
enddefine;

/* list:    lists a doc directory
 * args:    The argument lst. Defines the doc directory to list
 * retval:  A list with either an error message or a number of lists containing the listing
 */
define list(args) -> retval;
    if listlength(args) = 1 then        ;;; list from args
        if args matches [REF] then
            listRef() -> retval;
        elseif args matches [HELP] then
            listHelp() -> retval;
        elseif args matches [TEACH] then
            listTeach() -> retval;
        elseif args matches [DOC] then
            listDoc() -> retval;
        else
            [the category ^^args does not exist] -> retval;
        endif;
    elseif listlength(args) > 1 then    ;;; error
        [too many arguments ^^args for list] -> retval;
    else                                ;;; list everything
        listRef()<>listHelp()<>listTeach()<>listDoc()->retval;
    endif;
enddefine;

/* main:    Main procedure. It contains the service loop.
 */ 
define main();
    vars input;
    vars args;

    /* service loop */
    while true do
        readline() -> input;
    
        if input matches [LIST ??args] then
            pr(list(args))nl(1);
        elseif input matches [OPEN ??args] then
            pr(open(args));nl(1);
        else
            pr([I\'m afraid I can\'t deal with that]);nl(1);
        endif;
    endwhile;
enddefine;

;;; now just run it all
main();


--------------060102030206080000060803--