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