Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dstr / token_stack.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  * $XConsortium: token_stack.C /main/5 1996/08/21 15:51:52 drk $
25  *
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
30  * OR DISCLOSURE.
31  * 
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
36  * INTERNATIONAL, LTD.
37  * 
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.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #include "dstr/token_stack.h"
52
53 #ifdef C_API
54 #include "utility/c_stream.h"
55 #else
56 #include <sstream>
57 using namespace std;
58 #endif
59
60 token_stack::token_stack() : curr_token_start(0)
61 {
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);
65 }
66
67 token_stack::~token_stack() 
68 {
69    long ind = chunk_list.first();
70    while (ind) {
71       slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
72       buffer *w = (buffer*)(p -> void_ptr());
73       delete w;
74       chunk_list.next(ind);
75    }
76 }
77
78 void token_stack::clear()
79 {
80    long ind = chunk_list.first();
81    while (ind) {
82       slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
83       buffer *w = (buffer*)(p -> void_ptr());
84       w -> reset();
85       chunk_list.next(ind);
86    }
87
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());
90 }
91
92 void token_stack::new_token()
93 {
94    if ( curr_token_start ) 
95       v_curr_token_buf -> put(char(0));
96
97    curr_token_start = 0;
98 }
99
100 void token_stack::add_partial_token(char* x) 
101 {
102    if ( v_curr_token_buf -> remaining_sz() < (int)(strlen(x) + 1) ) {
103
104       int partial_str_len = curr_token_start ? strlen(curr_token_start) : 0;
105
106       buffer* new_buf = 0;
107
108       slist_void_ptr_cell* next_cell = 
109           (slist_void_ptr_cell*)(v_curr_list_cell -> v_succ); 
110
111       if ( next_cell ) {
112          new_buf = (buffer*)(next_cell -> void_ptr());
113
114       } else {
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);
118       }
119
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())
125                                            );
126       } 
127
128       v_curr_list_cell = next_cell;
129       v_curr_token_buf = new_buf;
130    }
131
132    if ( curr_token_start == 0 ) {
133       curr_token_start = 
134          v_curr_token_buf -> get_base() + v_curr_token_buf -> content_sz();
135    }
136
137    v_curr_token_buf -> put(x, strlen(x));
138 /*
139 MESSAGE(cerr, "add_partial_token():");
140 debug(cerr, last_buf -> content_sz());
141 */
142 }
143
144 ostream& operator <<(ostream& out, token_stack& ts)
145 {
146    long ind = ts.chunk_list.first();
147    while (ind) {
148       slist_void_ptr_cell *p = (slist_void_ptr_cell*)ind;
149       buffer *w = (buffer*)(p -> void_ptr());
150  
151       int offset = 0; 
152       while ( offset < w -> content_sz() ) {
153
154          char* str = (char*)(w -> get_base() + offset);
155          out << str << "\n";
156
157          offset += strlen(str) + 1;
158       }
159
160       ts.chunk_list.next(ind);
161    }
162    return out;
163 }
164