flex: Add local modifications and DragonFly READMEs
[dragonfly.git] / contrib / flex / scanflags.c
1 /* scanflags - flags used by scanning. */
2
3 /*  Copyright (c) 1990 The Regents of the University of California. */
4 /*  All rights reserved. */
5
6 /*  This code is derived from software contributed to Berkeley by */
7 /*  Vern Paxson. */
8
9 /*  The United States Government has rights in this work pursuant */
10 /*  to contract no. DE-AC03-76SF00098 between the United States */
11 /*  Department of Energy and the University of California. */
12
13 /*  This file is part of flex. */
14
15 /*  Redistribution and use in source and binary forms, with or without */
16 /*  modification, are permitted provided that the following conditions */
17 /*  are met: */
18
19 /*  1. Redistributions of source code must retain the above copyright */
20 /*     notice, this list of conditions and the following disclaimer. */
21 /*  2. Redistributions in binary form must reproduce the above copyright */
22 /*     notice, this list of conditions and the following disclaimer in the */
23 /*     documentation and/or other materials provided with the distribution. */
24
25 /*  Neither the name of the University nor the names of its contributors */
26 /*  may be used to endorse or promote products derived from this software */
27 /*  without specific prior written permission. */
28
29 /*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
32 /*  PURPOSE. */
33
34 #include "flexdef.h"
35
36 scanflags_t* _sf_stk = NULL;
37 size_t _sf_top_ix=0, _sf_max=0;
38
39 void
40 sf_push (void)
41 {
42     if (_sf_top_ix + 1 >= _sf_max)
43         _sf_stk = (scanflags_t*) flex_realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32));
44
45     // copy the top element
46     _sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix];
47     ++_sf_top_ix;
48 }
49
50 void
51 sf_pop (void)
52 {
53     assert(_sf_top_ix > 0);
54     --_sf_top_ix;
55 }
56
57 /* one-time initialization. Should be called before any sf_ functions. */
58 void
59 sf_init (void)
60 {
61     char membytes[21];
62     assert(_sf_stk == NULL);
63     _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
64     if (!_sf_stk) {
65         snprintf(membytes, 20, "%ld", (long)sizeof(scanflags_t));
66         lerrsf_fatal(_("Unable to allocate %s of stack"), membytes);
67     }
68     _sf_stk[_sf_top_ix] = 0;
69 }
70
71 /* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */