/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ #include "Lists.hpp" #include "Jam.hpp" #include "String.hpp" #include <new> using Jam::List; using Jam::String; /* * lists.c - maintain lists of strings * * This implementation essentially uses a singly linked list, but * guarantees that the head element of every list has a valid pointer * to the tail of the list, so the new elements can efficiently and * properly be appended to the end of a list. * * To avoid massive allocation, list_free() just tacks the whole freed * chain onto freelist and list_new() looks on freelist first for an * available list struct. list_free() does not free the strings in the * chain: it lazily lets list_new() do so. * * 08/23/94 (seiwald) - new list_append() * 09/07/00 (seiwald) - documented lol_*() functions */ namespace Jam { List* List::freelist = 0; /* junkpile for list_free() */ } namespace Jam { /* * list_append() - append a list onto another one, returning total */ List * List::list_append( List *l, List *nl ) { if( !nl ) { /* Just return l */ } else if( !l ) { l = nl; } else { /* Graft two non-empty lists. */ l->tail->next = nl; l->tail = nl->tail; } return l; } /* * list_new() - tack a string onto the end of a list of strings */ List * List::list_new( List *head, const char *string ) { List *l; if( DEBUG_LISTS ) printf( "list > %s <\n", string ); /* Get list struct from freelist, if one available. */ /* Otherwise allocate. */ /* If from freelist, must free string first */ if( freelist ) { l = freelist; freelist = freelist->next; String::freestr( l->string ); new (l) List(head, string); } else { l = new List(head, string); } return head; } /* * list_copy() - copy a whole list of strings (nl) onto end of another (l) */ List * List::list_copy( List *l, const List *nl ) { for( ; nl; nl = list_const_next( nl ) ) l = list_new( l, String::copystr( nl->string ) ); return l; } /* * list_sublist() - copy a subset of a list of strings */ List * List::list_sublist( const List *l, const int start, const int count ) { List *nl = 0; int start_dash = start; int count_dash = count; for( ; l && start_dash--; l = list_const_next( l ) ) ; for( ; l && count_dash--; l = list_const_next( l ) ) nl = list_new( nl, String::copystr( l->string ) ); return nl; } /* * list_free() - free a list of strings */ void List::list_free( List *head ) { /* Just tack onto freelist. */ if( head ) { head->tail->next = freelist; freelist = head; } } /* * list_print() - print a list of strings to stdout */ void List::list_print( const List *l ) { for( ; l; l = list_const_next( l ) ) printf( "%s ", l->string ); } /* * list_length() - return the number of items in the list */ int List::list_length( const List *l ) { int n = 0; for( ; l; l = list_const_next( l ), ++n ) ; return n; } /* * lol_next() - return the next item in a list. */ List* List::list_next(const List* pItem) { return pItem->next; } const List* List::list_const_next(const List* pItem) { return pItem->next; } List::List(List*& head, const char* string) { if( !head ) { head = this; } else { head->tail->next = this; } head->tail = this; this->next = 0; this->string = string; } } /* * lol_init() - initialize a LOL (list of lists) */ void lol_init( LOL *lol ) { lol->count = 0; } /* * lol_add() - append a List onto an LOL */ void lol_add( LOL *lol, Jam::List *l ) { if( lol->count < LOL_MAX ) lol->list[ lol->count++ ] = l; } /* * lol_free() - free the LOL and its LISTs */ void lol_free( LOL *lol ) { int i; for( i = 0; i < lol->count; i++ ) { List::list_free( lol->list[i] ); } lol->count = 0; } /* * lol_get() - return one of the LISTs in the LOL */ List * lol_get( const LOL *lol, const int i ) { return i < lol->count ? lol->list[i] : 0; } /* * lol_print() - debug print LISTS separated by ":" */ void lol_print( const LOL *lol ) { int i; for( i = 0; i < lol->count; i++ ) { if( i ) printf( " : " ); List::list_print( lol->list[i] ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 1163 | bob_summerwill | Added a private constructor to List. | ||
#5 | 1162 | bob_summerwill | Converted LIST into a List class, with all static methods. | ||
#4 | 1153 | bob_summerwill | NewStr has been renamed as String. | ||
#3 | 1146 | bob_summerwill | Moved the NewStr global functions into a static class Jam::String. | ||
#2 | 1138 | bob_summerwill | Removed all extern "C" wrappers, so the program now has C++ linkage throughout, ready for refactoring. | ||
#1 | 1130 | bob_summerwill | More .C to .CPP conversions. | ||
//guest/bob_summerwill/jam/src/lists.c | |||||
#6 | 1129 | bob_summerwill | Some const-correctness fixes. | ||
#5 | 1127 | bob_summerwill | More file renaming. | ||
#4 | 1126 | bob_summerwill | #include dependencies between headers are now modelled explicitly, with #includes as required in header files, rather than it being a client-code responsibility. | ||
#3 | 1120 | bob_summerwill | A fair-size chunk of char* const-correctness modifications. | ||
#2 | 1118 | bob_summerwill | Various const-correctness fixes. | ||
#1 | 1106 | bob_summerwill | Integrated Jam from "public" to "guest/bob_summerwill". | ||
//guest/perforce_software/jam/src/lists.c | |||||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |