Category : Miscellaneous Language Source Code
Archive   : EC304.ZIP
Filename : CONFIG.CB
Output of file : CONFIG.CB contained in archive : EC304.ZIP
* *
* Template: <^f^> *
* *
* File: config.cb *
* *
* Description: Configuration macro package for the Brief(tm) editor. *
* *
* Created by: Bruce A. Mallett 25-Jan-1989 *
* *
* Copyright (C) 1989 Bruce A. Mallett dba M-Tek *
* All rights reserved *
* *
* ("Brief" is a trademark of UnderWare, Inc). *
* *
* Revision history: *
* *
* 25-Jan-89 Bruce A. Mallett *
* Created this mess. *
* *
* 01-Mar-90 Bruce A. Mallett *
* Reformatted file. *
* *
\****************************************************************************/
#include "ascfind.h"
#include "config.h"
extern string search_path(string, string);
#define CONFIG_FILE "brief.ini" /* Name of configuration file */
#define NONSYSTEM 0 /* Non-system buffer */
#define SYSTEM 1 /* System buffer */
#define SEARCH_BUFFER 0 /* Search entire buffer */
#define SEARCH_BLOCK 1 /* Confine search to marked block */
#define SEARCH_CASE_ANY 0 /* Case insensitive searches */
#define SEARCH_CASE_MATCH 1 /* Case sensitive searches */
#define SEARCH_NOT_RE 0 /* Not regular expression */
#define SEARCH_RE 1 /* Regular expression search */
/****************************************************************************\
* *
* Forward definitions: *
* *
\****************************************************************************/
int _Pos2Inq( string pkg, string query );
int _read_config();
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: _init() *
* *
* Description: Brief calls this macro once, when it is first loaded. THis *
* is used to initialize the configuration subsystem (global *
* variables and the like). *
* *
* Parameters: None *
* *
* Returns: Nothing *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 01-Mar-1990 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
void _init()
{
int _config_bid; /* Buffer Id. of configuration file */
global _config_bid;
autoload("ascfind", "_AscendFind");
_config_bid = 0; /* Null this out */
} /* _init() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: inq_config( package, inquiry, default ) *
* *
* Description: This macro will search the section of the configuration file *
* specific to the given package for the configuration data *
* passed via "inquiry". If found then the string result is *
* returned. If not found then the string given by "default" *
* is returned (if specified). If default is not given then *
* the empty string ("") is returned. *
* *
* Parameters: package - Name of the package that the inquiry is *
* being made on behalf of *
* inquiry - The configuration data desired *
* default - The default value to return if the inquiry *
* is not answered in the configuration file *
* *
* Returns: (string) The result of the inquiry. See the *
* description above for all the details. *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1989 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
string inq_config( string pkg, string query, ~string )
{
int cur_bid; /* Current Buffer Id. */
string
deflt; /* What to return when there is no answer */
if (!get_parm(2, deflt)) /* Find out for nothin' */
deflt = ""; /* If nothin' not present */
cur_bid = inq_buffer(); /* Save current buffer Id. */
if (!_Pos2Inq(pkg, query)) /* Position to the inquiry */
{
set_buffer(cur_bid); /* Restore to entry buffer */
return deflt;
}
returns ( ltrim(trim(read())) ); /* Return answer to the query */
set_buffer(cur_bid); /* Switch back to entry buffer */
} /* inq_config() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: inq_config_int( package, inquiry, default ) *
* *
* Description: This macro will search the section of the configuration file *
* specific to the given package for the configuration data *
* passed via "inquiry". If found the string result is *
* converted to an integer and the result is returned. If not *
* found then the default value (passed) is returned. *
* *
* Parameters: package - Name of the package the inquiry is being *
* made for *
* inquiry - The configuration data desired *
* default - Default value to return should the inquiry *
* not be in the configuration file *
* *
* Returns: (int) The integer result of the inquiry ("default" *
* if the query was not answered by the *
* configuration file). *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1989 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
int inq_config_int(string pkg, string query, ~int)
{
int result; /* Result of the inquiry */
if ( (query = inq_config(pkg, query)) != "" )
result = atoi( query );
else
get_parm( 2, result ); /* Find out for nothin' */
return ( result ); /* Return the result. */
} /* inq_config_int() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: _Pos2Inq( pkg, query ) *
* *
* Description: This routine will attempt to position to the value of the *
* given query field. The caller is cautioned to save the *
* current buffer setting, since this call will modify it. *
* *
* Parameters: pkg - Name of the package the inquiry is made for *
* inquiry - The inquiry string *
* *
* Returns: (int) 0 if the inquiry string could not be found *
* for the given package *
* 1 if the inquiry string was found. The *
* cursor will be positioned to just after *
* the "=" (equals sign) on the inquiry and *
* the buffer will be set to the configuration *
* data file buffer. *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1990 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
int _Pos2Inq( string pkg, string query )
{
if (!_read_config()) /* Make sure config file is resident */
{
beep();
error("No config file!");
return 0;
}
set_buffer(_config_bid); /* Switch to configuration buffer */
move_abs(1, 1); /* Home */
if (search_fwd("[" + (pkg + "]"), SEARCH_NOT_RE, SEARCH_CASE_ANY) <= 0)
return 0; /* No configuration */
move_rel(1); /* Move to next line */
beginning_of_line(); /* To beginning of it to be precise */
drop_anchor(); /* Bound the search */
if (search_fwd("<\\[", SEARCH_RE) <= 0) /* Look for end of block */
end_of_buffer(); /* If not found then end will do */
raise_anchor();
if (search_back("<[ \t]@" + (query + "[ \t]@=\\c"), SEARCH_RE, SEARCH_CASE_ANY, SEARCH_BLOCK) > 0)
return 1; /* Found! */
return 0; /* Not found! */
} /* _Pos2Inq() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: _read_config() *
* *
* Description: This routine will create the configuration buffer and read *
* the configuration file into it. *
* *
* Parameters: None *
* *
* Returns: (int) 0 If the configuration file was not found *
* 1 If the configuration file was read into *
* the _config_bid buffer *
* *
* Notes: *
* *
* Side effects: _config_bid is set by this routine *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1990 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
int _read_config()
{
int cur_bid; /* Entry Buffer Id. */
string path; /* Holds path being examined */
if ( /* If config file already in memory */
_config_bid)
return 1; /* Say so! */
getwd(NULL, path); /* Get where we are now. */
/* Run up the directory tree looking for the config. file: */
path = _AscendFind(path, CONFIG_FILE, inq_environment("BPATH"));
if (path != "") /* If we have a config. file */
/* Create a buffer to store the configuration file and then */
/* read the file into same: */
{
_config_bid = create_buffer("_CONFIG_", path, SYSTEM);
cur_bid = inq_buffer(); /* Save current buffer */
set_buffer(_config_bid); /* Switch to the new one */
set_buffer(cur_bid); /* Switch back to entry buffer */
return 1; /* Show success! */
}
/************************************************************************\
* *
* Here having failed to get the configuration file. Show same *
* by returning a value of zero. *
* *
\************************************************************************/
return 0;
} /* _read_config() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: set_config( pkg, inquiry, value ) *
* *
* Description: This routine will search the section of the configuration *
* file specific to the given package for the configuration *
* data passed via "inquiry". If found then the field is *
* updated to contain the new value passed via "value". *
* *
* Parameters: pkg - Name of the package *
* inquiry - Names the configuration data *
* value - New configuration value *
* *
* Returns: Nothing *
* *
* Notes: This routine will *not* write out the modified configuration *
* file the caller must do this by calling write_config. *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1990 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
void set_config( string pkg, string query, string value )
{
int
cur_bid; /* Current Buffer Id. */
cur_bid = inq_buffer(); /* Save current buffer Id. */
if (_Pos2Inq(pkg, query)) /* Position to the inquiry */
{
delete_to_eol(); /* Delete old value */
insert("\t"); /* Add new value */
insert(value); /* (does this make it a VAR?) */
}
set_buffer(cur_bid); /* Switch back to entry buffer */
} /* set_config() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: config_end() *
* *
* Description: This routine is called by a macro package when it is done *
* making inquiries of the configuration subsystem. This *
* routine will delete the buffer that contains the *
* configuration file. *
* *
* Parameters: None *
* *
* Returns: Nothing *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1989 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
void config_end()
{
if ( /* Protect ourselves! */
_config_bid)
{
delete_buffer(_config_bid); /* Get rid of in memory config. file */
_config_bid = 0; /* Signal that buffer no longer exists */
}
} /* config_end() */
/****************************************************************************\
* *
* Template: <^r^> *
* *
* Name: write_config() *
* *
* Description: This routine will write the configuration buffer out to disk *
* and then call config_end to delete the thing. *
* *
* Parameters: None *
* *
* Returns: Nothing *
* *
* Notes: *
* *
* Side effects: *
* *
* Revision History: *
* Vers Date Author *
* 0.0 25-Jan-1989 Bruce A. Mallett *
* Created Module. *
* *
\****************************************************************************/
void write_config()
{
int
cur_bid; /* Current buffer Id. */
if ( /* Protect ourselves! */
_config_bid)
{
cur_bid = inq_buffer(); /* Save this */
set_buffer(_config_bid); /* Move to configuration data */
write_buffer(); /* Write it to disk */
config_end(); /* Thats all folks! */
}
} /* write_config() */
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/