2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: token_stack.C /main/5 1996/08/21 15:51:52 drk $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "dstr/token_stack.h"
54 #include "utility/c_stream.h"
60 token_stack::token_stack() : curr_token_start(0)
62 v_curr_token_buf = new buffer(LBUFSIZ);
63 v_curr_list_cell = new slist_void_ptr_cell(v_curr_token_buf);
64 chunk_list.insert_as_tail(v_curr_list_cell);
67 token_stack::~token_stack()
69 long ind = chunk_list.first();
71 slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
72 buffer *w = (buffer*)(p -> void_ptr());
78 void token_stack::clear()
80 long ind = chunk_list.first();
82 slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
83 buffer *w = (buffer*)(p -> void_ptr());
88 v_curr_list_cell = (slist_void_ptr_cell*)(chunk_list.get_head());
89 v_curr_token_buf = (buffer*)(v_curr_list_cell -> void_ptr());
92 void token_stack::new_token()
94 if ( curr_token_start )
95 v_curr_token_buf -> put(char(0));
100 void token_stack::add_partial_token(char* x)
102 if ( v_curr_token_buf -> remaining_sz() < (int)(strlen(x) + 1) ) {
104 int partial_str_len = curr_token_start ? strlen(curr_token_start) : 0;
108 slist_void_ptr_cell* next_cell =
109 (slist_void_ptr_cell*)(v_curr_list_cell -> v_succ);
112 new_buf = (buffer*)(next_cell -> void_ptr());
115 new_buf = new buffer(MAX(partial_str_len + 1, LBUFSIZ));
116 next_cell = new slist_void_ptr_cell(new_buf);
117 chunk_list.insert_as_tail(next_cell);
120 if ( curr_token_start ) {
121 v_curr_token_buf -> put(char(0));
122 new_buf -> put(curr_token_start, strlen(curr_token_start));
123 v_curr_token_buf -> set_content_sz(
124 int(curr_token_start - v_curr_token_buf->get_base())
128 v_curr_list_cell = next_cell;
129 v_curr_token_buf = new_buf;
132 if ( curr_token_start == 0 ) {
134 v_curr_token_buf -> get_base() + v_curr_token_buf -> content_sz();
137 v_curr_token_buf -> put(x, strlen(x));
139 MESSAGE(cerr, "add_partial_token():");
140 debug(cerr, last_buf -> content_sz());
144 ostream& operator <<(ostream& out, token_stack& ts)
146 long ind = ts.chunk_list.first();
148 slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
149 buffer *w = (buffer*)(p -> void_ptr());
152 while ( offset < w -> content_sz() ) {
154 char* str = (char*)(w -> get_base() + offset);
157 offset += strlen(str) + 1;
160 ts.chunk_list.next(ind);