[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon May 13 16:05:08 2001 
Subject:DRAFT Ved utility for editing files whose names have spaces 
From:Aaron Sloman See text for reply address 
Volume-ID:1010513.02 

[To reply replace "Aaron.Sloman.XX" with "A.Sloman"]

I found that the low level procedure vedreadfile (and also some others,
like vedfile_line_repeater) can accept a file name with spaces. So can
the unix utilities readable, sysopen, etc.

This made it fairly easy to define a procedure to read a file whose
name has spaces into a Ved buffer, without altering any VED system
files.

I.e. the file appended to this message should work in all CURRENT
versions of Poplog.

It could be installed in $poplocal/local/auto/ved_spaceved.p

I'll put it (and any future modifications) in
    http://www.cs.bham.ac.uk/research/poplog/auto/ved_spaceved.p

A shorter name may be more appropriate so that you don't
have to type

    ENTER spaceved .....

I worried that any shorter name I could dream up (e.g. ved_sv)
might clash with some user's ved utility. It's easy enough to
change the name or define your own synonym.

The procedure ved_spaceved enables you to read in a file with
commands like:

    ENTER spaceved my silly file from windows

It creates a ved buffer whose name is 'my silly file from windows'

Like wise it will work if a directory name includes a space:

    ENTER spaceved my dir/my file

The new file is writeable by default, though you could change the code
below to make a file non-writeable. Or immediately after reading it in
do
    ENTER pved

to make the file protected.

Minor problem: what you will see on the status line for a file
read in using ved_spaceved has "workbuff" in it. e.g. this sort of
thing:

    (examining: workbuff my dir/my file)

I can't change that without digging deep into the system. But it is
a very minor irritation.


I also tried doing all this a different way: making ved read in the file
but giving the buffer a different name, with hyphens replacing spaces in
the file name part (not the directory part, as Ved will not allow a file
path to refer to a nonexistent directory).

That was not difficult (using vedfile_line_repeater, or vedreadfile)
but it meant that you could not use ordinary commands for writing and
saving the file.

To overcome that I had to define a procedure ved_spacewrite to convert
the hyphens back, and then there's a problem if the original file name
had a mixture of hyphens and spaces!

Anyhow, in the end I decided that conversion to a new filename
was not worth the hassle. You can always change the name after
reading in the file, using the ENTER name command, if you wish.

In other respects a file read in with ved_spaceved will behave slightly
differently from other ved files. E.g. if you give the same command
twice you will get two copies of the file, so to re-edit the file while
it is already in a ved buffer you must use vedfileselect (ESC e)
or ved_rb (ENTER rb) or select with the mouse.

I have tested this only on solaris and linux poplog.

I have a bit of code for tests for a full path name by seeing whether
the file name starts with "/". That will not work on Windows, and
in some cases may not work on VMS.

Aaron
===
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL   A.Sloman@cs.bham.ac.uk
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/
TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
Phone: +44-121-414-4775        Fax:   +44-121-414-4281/2799

DRAFT autoloadable library file follows
=======================================================================

/* --- Copyright University of Birmingham 2001. All rights reserved. ------
 > File:            $poplocal/local/auto/ved_spaceved.p
 > Purpose:			Read in file whose name contains spaces
 > Author:          Aaron Sloman, May 13 2001
 > Documentation: 	Below for now
 > Related Files:
 */


/*

HELP ved_spaceved

    Utility for reading in files whose names include spaces.
    This is needed because ved_ved assumes that if its argument
    includes spaces then it refers to several files, which should
    all be read into Ved.

ENTER spaceved my silly file.p

    This command will look for a file called 'my silly file.p'
    Warning: this will not use vedsearchlist, so explicit path
    names will be needed for files not in the current directory.

	It will also not find the file if it is already being edited,
	so use ESC e (vedfileselect) to return to a file previously
	edited with this command.

	The ENTER spaceved command will make ved read the file into
	a Ved buffer and in many ways it will be like an ordinary ved
    file. However, on the status line ved will show the type "workbuff"
	before the file name as a reminder that this is an unusual file.

*/


section;

define lconstant setupglobals(newfile, string);
	;;; Set up some of the globals for the new file, to make it behave
	;;; more or less like an ordinary file

	dlocal ved_current_file = newfile;

	sysfileok(string) -> string;

	;;; modify this test for windows ???
	if string(1) = `/` then
		;;; it's a full path name
		string ->> vedpathname -> vedcurrent;
		nullstring -> veddirectory;
	else
		;;; it's a relative path
		current_directory dir_>< string -> vedpathname;
		current_directory -> veddirectory;
		string -> vedcurrent;
	endif;

	;;; if not false, it will be "workbuff"!
	false -> vedfileprops;
	false -> vedchanged;
	;;; Maybe the user should have a choice about this:
	true -> vedwriteable;

enddefine;

define ved_spaceved();
	;;; Edit file whose name (or path) has spaces.

	;;; Check that the file exists
	lvars filedev = readable(vedargument);
	unless filedev then
		vederror('FILE NOT FOUND: ' <> vedargument);
	endunless;

	;;; Prepare new ved file structure containing the file
	;;; ignore first result of vedreadfile
	lvars (_, newfile) = vedreadfile(filedev, vedveddefaults, false);

	setupglobals(newfile, vedargument);

	vededit(newfile);

enddefine;


endsection;