]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/str-stk.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 // file: .../c++-lib/src/str-stk.C
22 // Copyright (C) 1992 Michael Sample and the University of British Columbia
24 // This library is free software; you can redistribute it and/or
25 // modify it provided that this copyright/license information is retained
28 // If you modify this file, you must clearly indicate your changes.
30 // This source code is distributed in the hope that it will be
31 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
32 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 // $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/c++-lib/c++/str-stk.cpp,v 1.2 2002/02/07 04:30:04 mb Exp $
35 // $Log: str-stk.cpp,v $
36 // Revision 1.2 2002/02/07 04:30:04 mb
37 // Fixes required to build with gcc3.
38 // Merged from branch PR-2848996
41 // Reviewed by: Turly O'Connor <turly@apple.com>
43 // Revision 1.1.1.1.12.1 2002/02/06 23:45:03 mb
44 // Changes to allow building with gcc3
46 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
47 // Move from private repository to open source repository
49 // Revision 1.3 2001/05/05 00:59:17 rmurphy
50 // Adding darwin license headers
52 // Revision 1.2 2000/12/07 22:16:57 dmitch
53 // Thread-safe mods: removed global StrStk strStkG.
57 // #ifdef'd out strStkG for thread safety
59 // Revision 1.1 2000/06/15 18:44:58 dmitch
60 // These snacc-generated source files are now checked in to allow cross-platform build.
62 // Revision 1.2 2000/06/08 20:05:37 dmitch
63 // Mods for X port. These files are actually machine generated and probably don't need to be in CVS....
65 // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy
66 // Base Fortissimo Tree
68 // Revision 1.2 1999/06/04 21:43:21 mb
69 // Fixed several memory leaks.
71 // Revision 1.1 1999/02/25 05:21:57 mb
72 // Added snacc c++ library
74 // Revision 1.5 1997/02/16 20:26:11 rj
75 // check-in of a few cosmetic changes
77 // Revision 1.4 1995/07/24 20:34:57 rj
78 // changed `_' to `-' in file names.
80 // Revision 1.3 1994/10/08 04:15:22 rj
81 // fixed both Copy()'s name and implementation to CopyOut() that always returns the number of bytes copied out instead of 0 in case less than the requested amount is available.
83 // several `unsigned long int' turned into `size_t'.
85 // Revision 1.2 1994/08/28 10:01:24 rj
86 // comment leader fixed.
88 // Revision 1.1 1994/08/28 09:21:13 rj
89 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
91 #include "asn-config.h"
95 /* clients each have their own for OS X */
96 // global for use by AsnBits and AsnOcts
98 StrStk
strStkG ( 128 , 64 );
101 StrStk :: StrStk ( int stkSize
, int growIncrement
)
103 stk
= new struct Elmt
[ stkSize
];
105 growSize
= growIncrement
;
119 void StrStk :: Push ( char * str
, size_t strLen
)
121 if ( nextFreeElmt
>= size
)
124 // alloc bigger stack and copy old elmts to it
125 tmpStk
= new struct Elmt
[ size
+ growSize
];
126 for ( size_t i
= 0 ; i
< size
; i
++)
132 totalByteLen
+= strLen
;
133 stk
[ nextFreeElmt
]. str
= str
;
134 stk
[ nextFreeElmt
++]. len
= strLen
;
138 * copy string pieces (buffer refs) into single block.
139 * assumes that the buf is at least totalByteLen byte long.
141 void StrStk :: CopyOut ( char * buf
)
143 unsigned long int curr
;
147 for ( curr
= 0 ; curr
< nextFreeElmt
; curr
++)
149 memcpy ( bufCurr
, stk
[ curr
]. str
, stk
[ curr
]. len
);
150 bufCurr
+= stk
[ curr
]. len
;