home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
- /******************************************************************/
- /* This module manages a linked list of variable names and values */
- /* XBBS replaces the variable name where encountered with the */
- /* variable's value. Unknown variables return "" (null string) */
- /******************************************************************/
-
- #include "msg.h" /* Function declarations & misc BS */
- #include "xext.h" /* External variables */
-
- /* Error codes for bbserr global variable */
-
-
- #define NOERR 0 /* 's cool, m'man */
- #define NOVARS 1 /* No variables in linked list */
- #define NOTVAR 2 /* Name given isn't a var in list */
- #define NOMEM 3 /* Out of memory */
- #define NOFILE 4 /* Can't read a file */
- #define SYNTAX 5 /* Syntax error */
-
- #define mymalloc mmalloc
- #define myfree ffree
- #define bbserr level /* For XBBS 1.xx; 2.xx uses bbserr */
-
- struct _variable { /* Structure of the variables */
- char *name;
- char *str;
- struct _variable *next; /* Next var in list */
- struct _variable *prior; /* Previous var in list */
- };
-
- struct _variable *head=NULL; /* First var */
- struct _variable *tail=NULL; /* Last var */
-
- struct _variable * pascal find_var (char *name);
-
-
-
- char * pascal lookup_var (char *name) { /* Finds var, returns string */
-
- struct _variable *info;
-
- info=find_var(name);
- if(!info) return "";
- else return info->str;
- }
-
-
-
- static struct _variable * pascal find_var (char *name) { /* Finds var, returns struct ptr */
-
- struct _variable *info;
-
- if(!name) {
- bbserr=NOVARS;
- return NULL;
- }
- bbserr=NOERR;
- if(head==NULL) {
- bbserr=NOVARS;
- return NULL; /* No variables defined */
- }
- info=head;
- while(info) {
- if(!stricmp(info->name,name)) {
- return info;
- }
- info=info->next;
- }
- bbserr=NOTVAR;
- return NULL;
- }
-
-
-
- void pascal delete_var (char *name) { /* Delete named var */
-
- struct _variable *info;
-
- bbserr=NOERR;
- info=find_var(name);
- if(info) { /* It exists; delete it */
- if(info->prior) info->prior->next=info->next; /* Remove from link */
- else {
- head=info->next; /* Next is new first item */
- if(head) info->prior=NULL; /* ...else no vars left */
- }
- if(info->next) info->next->prior=info->prior; /* Remove from link */
- if(info->name) myfree(info->name); /* Release allocated memory */
- if(info->str) myfree(info->str);
- if(info)myfree(info);
- }
- }
-
-
-
- void pascal assign_var (char *name,char *str) { /* Handles new and old vars */
-
- struct _variable *info;
-
- if(!str) {
- bbserr=SYNTAX;
- return;
- }
- info=find_var(name);
- if(!info) { /* New variable */
- info=(struct _variable *)mymalloc(sizeof(struct _variable));
- if(!info) {
- bbserr=NOMEM;
- return;
- }
- info->name=mystrdup(name);
- if(!info->name) {
- bbserr=NOMEM;
- myfree(info);
- return;
- }
- info->str=mystrdup(str);
- if(!info->str) {
- bbserr=NOMEM;
- myfree(info->name);
- myfree(info);
- return;
- }
- if(tail==NULL) { /* First and only element */
- info->next=info->prior=NULL; /* No links */
- head=tail=info; /* All roads lead to Amber */
- }
- else { /* Add to end of list */
- tail->next=info; /* Last points ahead to this */
- info->next=NULL; /* This points ahead to nothing */
- info->prior=tail; /* This points back to last */
- tail=info; /* This is now last */
- }
- }
- else {
- if(info->str)myfree(info->str);
- info->str=mystrdup(str);
- if(!info->str) {
- bbserr=NOMEM;
- myfree(info->name);
- myfree(info);
- return;
- }
- }
- }
-
-
- void pascal free_vars (void) { /* Free the entire linked list */
-
- struct _variable *info,*temp;
-
- info=head;
- while(info) {
- if(info->str)myfree(info->str);
- if(info->name)myfree(info->name);
- temp=info->next;
- myfree(info);
- info=temp;
- }
- }
-