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