Click here to Skip to main content
15,891,688 members
Articles / Desktop Programming / MFC

Another Enum Viewer

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
22 Oct 20015 min read 83K   1.3K   19  
An article on the usage and design of another Enum Viewer
/*
 * SList.C
 *
 * SOFTWARE RIGHTS
 *
 * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
 * domain.  An individual or company may do whatever they wish with
 * source code distributed with SORCERER or the code generated by
 * SORCERER, including the incorporation of SORCERER, or its output, into
 * commerical software.
 * 
 * We encourage users to develop software with SORCERER.  However, we do
 * ask that credit is given to us for developing SORCERER.  By "credit",
 * we mean that if you incorporate our source code into one of your
 * programs (commercial product, research project, or otherwise) that you
 * acknowledge this fact somewhere in the documentation, research report,
 * etc...  If you like SORCERER and have developed a nice tool with the
 * output, please mention that you developed it using SORCERER.  In
 * addition, we ask that this header remain intact in our source code.
 * As long as these guidelines are kept, we expect to continue enhancing
 * this system and expect to make other tools available as they are
 * completed.
 *
 * PCCTS 1.33
 * Terence Parr
 * Parr Research Corporation
 * with Purdue University and AHPCRC, University of Minnesota
 * 1992-1995
 */

#define ANTLR_SUPPORT_CODE

#include "SList.h"

/* Iterate over a list of elements; returns ptr to a new element
 * in list upon every call and NULL when no more are left.
 * Very useful like this:
 *
 *		cursor = mylist;
 *		while ( (p=mylist->iterate(&cursor)) ) {
 *			// place with element p
 *		}
 *
 * The cursor must be initialized to point to the list to iterate over.
 */
void *SList::
iterate(SListNode **cursor)
{
	void *e;

	if ( cursor == NULL || *cursor==NULL ) return NULL;
	if ( head == *cursor ) { *cursor = (*cursor)->next(); }
	e = (*cursor)->elem();
	(*cursor) = (*cursor)->next();
	return e;
}

/* add an element to end of list. */
void SList::
add(void *e)
{
	SListNode *p, *tail;
	require(e!=NULL, "slist_add: attempting to add NULL list element");

	p = new SListNode;
	require(p!=NULL, "add: cannot alloc new list node");
	p->setElem(e);
	if ( head == NULL )
	{
		head = tail = p;
	}
	else								/* find end of list */
	{
		tail->setNext(p);
		tail = p;
	}
}

void SList::
lfree()
{
	SListNode *p,*q;

	if ( head==NULL ) return;	/* empty list */
	for (p = head; p!=NULL; p=q)
	{
		q = p->next();
		free(p);
	}
}

PCCTS_AST *SList::
to_ast(SList list)
{
	PCCTS_AST *t=NULL, *last=NULL;
	SListNode *p;

	for (p = head; p!=NULL; p=p->next())
	{
		PCCTS_AST *u = (PCCTS_AST *)p->elem();
		if ( last==NULL ) last = t = u;
		else { last->setRight(u); last = u; }
	}
	return t;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions