Category : Miscellaneous Language Source Code
Archive   : EC304.ZIP
Filename : MYTAG.CB
Output of file : MYTAG.CB contained in archive : EC304.ZIP
Module
tag.cb
Revision
$Revision: 1.0 $
$Date: 11 Aug 1989 09:48:06 $
Description
Provides C tag support to BRIEF.
Written by Sky Schulz
(C) Copyright 1988 UnderWare, Inc. All rights reserved.
The tags file format is as follows:
The
of the file containing the
the line defining
The function (tag), if passed a parameter, will pass that parameter
to the function (tag_key) to use. If no parameter is passed to
(tag_key) it will attempt to pull an identifier from the current
buffer.
Table of invocation methods:
This assumes that the function (tag_key) is bound to
that the function (undo_tag) is bound to
****************************************************************************/
/*----------------------------- Include Files ------------------------------*/
#include "dialog.h"
#include "ascfind.h"
/*--------------------------- External Functions ---------------------------*/
extern
display_file_name,
escape_re;
/*--------------------------- External Variables ---------------------------*/
extern _tag_file; /* Name of the tag file */
/*---------------------------- Global Variables ---------------------------*/
global int tag_stack_buf; // Tag stack buffer
global int tag_menu_sel; // User's pick from tags menu
global string tag_cur_file; // Current file being tagged to
global string tag_cur_exp; // Current expression being tagged to
global string tag_cur_id; // Current symbol being tagged to
/*------------------------------- Module Code ------------------------------*/
/* Invoked when the user presses the Tag key. */
int Tag (...)
{
string
tag_id, /* ID to tag on */
tag_exp, /* Expression to find ID */
tagged_file, /* Name of file where ID is */
temp_str, /* Temporary string */
path;
int
cur_buf, /* Current file buffer */
new_buf, /* New file/tags file buffer */
men_buf, /* Menu buffer */
max_id_len, /* Length of longest id */
id_len,
max_fil_len, /* Length of longest filename */
fil_len,
mtch_cnt, /* Count of matching tags found */
i,
j;
/* Get ID to tag from */
if (!get_parm (0, tag_id))
{
error ("No tag specified");
return 0;
}
/* Open tags file for searching */
if (!exist(_tag_file))
{
/********************************************************************\
* *
* Run up the current directory and find a tag file: *
* *
\********************************************************************/
getwd(NULL, path); /* Get where we are now. */
tagged_file = _AscendFind(path, _tag_file);
if (tagged_file == "") /* File not found. */
{
error("No tag file!");
return 0; /* No tag file! */
}
}
else
tagged_file = _tag_file;
cur_buf = inq_buffer (); /* Save the current buffer */
message ("Searching for %s...", tag_id);
new_buf = create_buffer ("Tags", tagged_file, 1);
set_buffer (new_buf);
/* Make tag-line expression */
sprintf (tag_exp, "<%s\t", tag_id);
/* Look for it, case-sensitive, from the top of the buffer */
top_of_buffer ();
if (search_fwd (tag_exp, 1, 1) <= 0)
{
message ("Tag name '%s' not found in tags file.", tag_id);
set_buffer (cur_buf);
delete_buffer (new_buf);
return 0;
}
mtch_cnt = 1; /* We found at least one */
/* See if there are more matches */
save_position (); /* So we can return and get the first */
move_rel (1, 0);
if (search_fwd (tag_exp, 1, 1) > 0)
{
int lx, by, rx; /* Where to place and size menu */
message ("Searching for %s [%d]...", tag_id, mtch_cnt);
/* Create menu buffer */
men_buf = create_buffer ("Tags", NULL, 1);
/* Get first match out of tags file and insert it into the menu */
restore_position ();
temp_str = read ();
move_rel (1, 0);
set_buffer (men_buf);
insert (temp_str); /* Insert matching line */
/* Get length of id and filename for this match */
max_id_len = index (temp_str, "\t");
max_fil_len = index (substr (temp_str, max_id_len + 1), "\t");
/* Look for additional matches in the tags file */
set_buffer (new_buf); /* tags file active */
while (search_fwd (tag_exp, 1, 1) > 0)
/* Get matching line and insert it into the menu */
{
temp_str = read ();
set_buffer (men_buf);
insert (temp_str); /* Insert matching line */
/* Get length of id and filename for this match */
id_len = index (temp_str, "\t");
fil_len = index (substr (temp_str, id_len + 1), "\t");
/* Maintain record of longest id and filename */
max_id_len = id_len > max_id_len ? id_len : max_id_len;
max_fil_len = fil_len > max_fil_len ? fil_len : max_fil_len;
/* Keep track of matches found */
message ("Searching for %s [%d]...", tag_id, ++mtch_cnt);
set_buffer (new_buf); /* tags file active */
move_rel (1, 0);
}
/* Set up menu buffer to be used as a menu */
message ("Creating menu...");
set_buffer (men_buf);
end_of_buffer ();
delete_line (); /* Remove trailing line */
top_of_buffer ();
/* Set the tabs so the filenames are aligned and the pattern */
/* isn't visible */
tabs (max_id_len + 1, 128);
/* Figure out where to position menu on screen */
temp_str = "
/* Top-Y is hardcoded to be 3 */
by = mtch_cnt > 15 ? 19 : 4 + mtch_cnt; /* Bottom-Y */
/* Bigger than screen? */
if (max_id_len + max_fil_len >= 76)
{
lx = 0; /* Yeah, we maxed it */
rx = 78;
}
else
{
/* Not too big, bigger than message? */
if (max_id_len + max_fil_len >= strlen (temp_str) + 4)
{
lx = (80 - (max_id_len + max_fil_len)) / 2;
rx = 1 + (lx + (max_id_len + max_fil_len));
}
else
{
/* Nope, make it at least big enough for message */
lx = (80 - (strlen (temp_str) + 4)) / 2;
rx = 1 + (lx + (strlen (temp_str) + 4));
}
}
/* Start up menu. If tag_menu_sel is non-zero, that line will */
/* be used as the tag line */
tag_menu_sel = 0; /* If zero, cancel operation */
_process_menu (lx, by, rx, 3 /* Position of menu */
, "Tags", /* Title and message */
temp_str, /* No filename, using internal buffer */
NULL, /* Buffer-id of menu */
men_buf, "_tag_menu_action" /* event/action handler */
, /* Don't format menu */
TRUE);
/* User made a choice, get it and go */
if (tag_menu_sel != 0)
{
move_abs (tag_menu_sel, 1);
temp_str = read ();
set_buffer (new_buf); /* tags file */
delete_buffer (men_buf); /* Get rid of menu buffer */
}
else
{
/* User canceled */
set_buffer (cur_buf);
delete_buffer (new_buf);
delete_buffer (men_buf); /* Get rid of menu buffer */
message ("Command cancelled.");
return;
}
}
else
/* Just the one matching tag was found */
{
restore_position ();
temp_str = read ();
}
/* end if (more than one match) */
/* Now, extract symbol, filename and RE off of matched line */
tag_id = substr (temp_str, 1, index (temp_str, "\t") - 1);
i = search_string ("<*\t\\c*\t", temp_str, j, 1, 0);
tagged_file = substr (temp_str, i, j - 1);
i = search_string ("<*\t*\t\\c?", temp_str, NULL, 1, 0);
temp_str = substr (temp_str, i);
/* Remove trailing newline from tag_exp */
/* (= tag_exp (+ "<" (+ (escape_re (substr temp_str 1 (- (strlen temp_str) 1))) ">"))) */
tag_exp = substr (temp_str, 1, strlen (temp_str) - 1);
if (!strlen (tag_exp))
{
beep ();
error ("tag_key: Invalid tag_exp!");
set_buffer (cur_buf);
delete_buffer (new_buf);
return 0;
}
/* Check for tagged file's existence first */
if (!exist (tagged_file))
{
beep ();
error ("File not found: %s", tagged_file);
set_buffer (cur_buf);
delete_buffer (new_buf);
return 0;
}
/* Then open it, but first save the current buffer & position for */
/* use by (undo_tag) */
set_buffer (cur_buf);
save_tag_undo ();
/* Set current tag file and RE */
tag_cur_id = tag_id;
tag_cur_file = tagged_file;
tag_cur_exp = tag_exp;
/* put parms */
put_parm(1, tag_cur_file);
put_parm(2, tag_cur_exp);
/* Get rid of 'tags' buffer */
delete_buffer (new_buf);
return 1;
}
/* end tag_key */
/* _tag_menu_action - Process menu events */
_tag_menu_action (...)
{
int
event_type, /* Type of event in process */
menu_line; /* Line of event */
get_parm (0, event_type);
switch (event_type)
{
case DIALOG_INIT:
message ("Select a tag.");
case DIALOG_PICK_MENU:
{
get_parm (1, menu_line);
tag_menu_sel = menu_line;
push_back (18989); /* Cause menu to terminate */
}
}
return TRUE;
}
/* end _tag_menu_action */
/* Jump back to the previous file, before the last tag was done. */
UndoTag (...)
{
string
filename,
stack_line;
int
line,
col,
cur_buf,
tag_stack_line,
ndx;
/* If there is something in the tag stack, pull it out */
if (tag_stack_buf)
{
cur_buf = inq_buffer (); /* In case we need to get back here */
set_buffer (tag_stack_buf);
end_of_buffer ();
up ();
beginning_of_line ();
/* Extract line of interest */
stack_line = read ();
/* Remove line from tag stack buffer */
delete_line ();
/* Continue normally if there is something here */
if (strlen (stack_line))
{
/* Get filename from line */
filename = substr (stack_line, 1, (ndx = index (stack_line, " ")) - 1);
stack_line = substr (stack_line, ndx + 1);
/* Get line position from line */
line = atoi (substr (stack_line, 1, (ndx = index (stack_line, " ")) - 1));
stack_line = substr (stack_line, ndx + 1);
/* Get col position from line */
col = atoi (substr (stack_line, 1, (ndx = index (stack_line, " ")) - 1));
stack_line = substr (stack_line, ndx + 1);
/* Get current tag filename from line */
tag_cur_file = substr (stack_line, 1, (ndx = index (stack_line, " ")) - 1);
stack_line = substr (stack_line, ndx + 1);
/* Get current tag ID from line */
tag_cur_id = substr (stack_line, 1, (ndx = index (stack_line, " ")) - 1);
stack_line = substr (stack_line, ndx + 1);
/* Get current tag RE from line (remainder of line) */
tag_cur_exp = stack_line;
}
else
{
/* Nothing to undo, if we are at line 1 in the tag stack, */
/* get rid of the tag stack buffer */
set_buffer (cur_buf); /* Back to original buffer */
error ("Tag stack is empty.");
}
/* Remove buffer if it is empty */
inq_position (tag_stack_line, NULL);
if (tag_stack_line == 1)
{
delete_buffer (tag_stack_buf);
tag_stack_buf = 0;
tag_cur_id = tag_cur_exp = tag_cur_file = "";
}
/* Jump to stacked buffer */
if (strlen (filename))
{
edit_file (filename);
display_file_name ();
move_abs (line, col);
}
}
else
error ("Tag stack is empty.");
}
/* end undo_tag */
/* Save the current buffer name & cursor position for later undo */
save_tag_undo (...)
{
string
filename;
int
line,
col,
cur_buf;
/* Create tag stack buffer as a system buffer */
if (!tag_stack_buf)
tag_stack_buf = create_buffer ("Tag Stack", NULL, 1);
/* Get info on current buffer */
cur_buf = inq_buffer ();
inq_names (filename);
inq_position (line, col);
/* Save information at end of tag stack buffer */
set_buffer (tag_stack_buf);
end_of_buffer ();
/* Insert tag stack line into buffer */
insert (filename); /* Name of file to edit */
sprintf (filename, " %d %d ", line, col);
insert (filename); /* Line and column position in file */
/* Insert current tag file & RE if there is one */
if (strlen (tag_cur_file))
{
insert (" ");
insert (tag_cur_file);
insert (" ");
insert (tag_cur_id);
insert (" ");
insert (tag_cur_exp);
insert ("\n");
}
else
insert (" P P P\n");
/* Finish */
set_buffer (cur_buf);
}
/* end save_tag_undo */
/*------------------------------ End of file ------------------------------*/
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/