Category : Miscellaneous Language Source Code
Archive   : EDITFIL3.ZIP
Filename : EDITFIL3.CB

 
Output of file : EDITFIL3.CB contained in archive : EDITFIL3.ZIP
/*
Brief 3.0 replacement macro for edit_file.
By Steven Polsky
5011 Dalton Rd.
Chevy Chase, MD. 20815
12/89

Modifies built in edit_file as follows:

- Prompt default to *.* or the last filename entered.

- [Tab] still expands incomplete filespecs just as it used to

- [Enter] expands incomplete filespecs like [Tab], but with the
following enhancements:

- keep the wildcard filespec in the command stack.

- Fully expand filespecs containing wildcards
(eg. make p?o expand p?o*.*)

- Allow user to use .xxx format to mean *.xxx

- Allows user to edit all files listed in a list file:

- If the first or last character in the filename that the
user specifies is FLIST_MARKER ("@") then all files listed
in the user specified file are edited (loaded into buffers).

- If the user enters FLIST_MARKER ("@") alone (without a
filespec), then files listed in the current buffer are
loaded.

- Each line of the list file is processed as follows:
- Lines with leading white space are skipped
- Filenames start in column 1.
- Filenames are terminated by any of the following:
- white space ("[ \t\n]")
- ":" where ":" is in a position > col 2 (NOT A:)
- "("
This facilitates use with grep and with Microsoft C
(cl -Zs).

Ideas for future enhancement:
- if FLIST_MARKER is in Fname then display popup window of
files listed in Fname and allow the user to _multifile_edit_file
instead of just loading all files listed in Fname.

Known Bugs: If the user selects a set of files from the file list window,
the highlighted file is edited even if it is not selected.
(Bring up the file list window with Tab, then press * to
select all files, then press Space bar to un-select one,
but leave the highlight on the un-selected file. The
un-selected file is still edited)
THIS BUG ALSO OCCURS IN NATIVE BRIEF.
To get around this bug, I would need to modify PROMPT.CB
somewhere around line 446 to set a global flag as follows:
if (read (1) == ">") {
_highlighted_file_is_marked = TRUE;
}
else {
_highlighted_file_is_marked = FALSE;
}
and check the flag before doing the final edit_file below.
I prefer not to modify PROMPT.CB and can live with the fact
that the highlighted file is always edited. In practice,
make sure that when you are done selecting files, the
cursor is on a file that you want edited.
*/


#define TRUE 1
#define FALSE 0
#define FIRST_CHAR 1
#define FLIST_MARKER "@"

extern display_file_name();

string Fname; /* save the filename to use next time we are called */

void _init ()
{
Fname = "*.*";
}


replacement int edit_file (~string)
{
int ret_val, /* return value */
expand, /* flag indicating need to expand filespec */
last_char, /* last character in filespec (len of filespec) */
dot, /* location of the last "." in the filespec */
slash, /* location of the last "/" in the filespec */
bslash, /* location of the last "\" in the filespec */
asterisk, /* location of the last "*" in the filespec */
qmark, /* location of the last "?" in the filespec */
fattr, /* file attribute assigned by find_file */
flist, /* location of the FLIST_MARKER in the filespec */
flist_buf, /* buffer containing file list */
num_edited, /* number of files edited from file list */
old_msg_level; /* save of old message level before we change it */

string fname_from_list, /* filename read from file list */
last_edited, /* last file edited from file list */
tmp_str; /* used as a temporary string holder */

/* if called from another macro then just call the original edit_file */
if (inq_called () != "") { /* not called from keyboard */
ret_val = edit_file ();
}

else { /* called from keyboard */

/* let edit_file messages flow through, but save old message level */
old_msg_level = set_msg_level (0);

do {
expand = FALSE; /* start off assuming that we will not expand */

if (ret_val = get_parm(NULL, Fname, "File: ", NULL, Fname)) {

last_char = strlen(Fname);
dot = rindex (Fname, ".");
slash = rindex (Fname, "/");
bslash = rindex (Fname, "\\");
asterisk = rindex (Fname, "*");
qmark = rindex (Fname, "?");

if ( asterisk /* if Fname contains "*" */
|| qmark /* or Fname contains "?" */
|| (last_char == 0) /* or Fname empty */
|| (FIRST_CHAR == dot) /* or Fname starts with "." */
|| (last_char == dot) /* or Fname ends with "." */
|| (last_char == slash) /* or Fname ends with "/" */
|| (last_char == bslash)) { /* or Fname ends with "\" */
/* then expand it */

expand = TRUE;
push_back (key_to_int (""));

if (last_char == 0) {
Fname = "*.*";
}

else {

if ( (last_char != asterisk)
&& (last_char != qmark)) {

Fname += "*";
}

if (!dot) {
Fname += ".*";
}
else if (FIRST_CHAR == dot) {
Fname = "*" + Fname;
}
}

message ("File: %s ... ", Fname);
}
}
} while (expand);

/* Now the filespec is expanded or the user pressed Esc */

if (ret_val) { /* then they did not press Esc */

/* if the user wants to edit files from a file list then do so */
flist = index (Fname, FLIST_MARKER);

if ((flist == FIRST_CHAR) || (flist == last_char)) {

if (Fname == FLIST_MARKER) {
inq_names(Fname);
}
else {
Fname = trim(ltrim(substr (Fname,
(flist == FIRST_CHAR) ? 2 : 1,
last_char - 1)));
}

if (exist (Fname)) {

if ((ret_val = edit_file (Fname)) > 0) {

flist_buf = inq_buffer();
num_edited = 0;
save_position();
top_of_buffer();

/*
load files from a list using the rules listed in
the comment at the top of this file.
*/

last_edited = ""; /* we havent edited any files yet */

while (!inq_position ()) {

/* get the filename from the list */
fname_from_list = compress (trim (read ()));

if (index (fname_from_list, ":") == 2) {
tmp_str = substr (fname_from_list, 3);
}
else {
tmp_str = fname_from_list;
}

/*
There will always be a " " at the end of
tmp_str from the \n converted to " " in
the convert() call above.
If there is a blank at the beginning of the
line, then the filename_from_list will be "".
*/

fname_from_list = substr(tmp_str, 1,
search_string ("[ :(]",
tmp_str,
NULL,
TRUE) - 1);

down ();

/*
Only edit the file if it exists and was not
edited in the last pass through the loop (grep
and cl -Zs list files many times in a row).

Note that exist(""),
exist(" "), and
exist(" filename") return FALSE
*/

if (exist (fname_from_list)
&& (fname_from_list != last_edited)) {

if ((edit_file (fname_from_list)) == 2) {
/* file not already in memory */
num_edited++;
message (fname_from_list);
}

last_edited = fname_from_list;

set_buffer (flist_buf);
}
}

set_buffer (flist_buf);
attach_buffer (flist_buf);

message ("%d files loaded from %s", num_edited, Fname);

restore_position();
}
else {
error ("Could not edit %s.", Fname);
}
}
else {
error ("%s not found.", Fname);
}
}
else if ((ret_val = edit_file (Fname)) > 0) {
display_file_name();
}
}

set_msg_level (old_msg_level);
}

return (ret_val);
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : EDITFIL3.ZIP
Filename : EDITFIL3.CB

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/