1*0a6a1f1dSLionel Sambuc /* $NetBSD: scanflags.c,v 1.3 2014/10/30 18:44:05 christos Exp $ */
2357f1050SThomas Veerman
3357f1050SThomas Veerman /* scanflags - flags used by scanning. */
4357f1050SThomas Veerman
5357f1050SThomas Veerman /* Copyright (c) 1990 The Regents of the University of California. */
6357f1050SThomas Veerman /* All rights reserved. */
7357f1050SThomas Veerman
8357f1050SThomas Veerman /* This code is derived from software contributed to Berkeley by */
9357f1050SThomas Veerman /* Vern Paxson. */
10357f1050SThomas Veerman
11357f1050SThomas Veerman /* The United States Government has rights in this work pursuant */
12357f1050SThomas Veerman /* to contract no. DE-AC03-76SF00098 between the United States */
13357f1050SThomas Veerman /* Department of Energy and the University of California. */
14357f1050SThomas Veerman
15357f1050SThomas Veerman /* This file is part of flex. */
16357f1050SThomas Veerman
17357f1050SThomas Veerman /* Redistribution and use in source and binary forms, with or without */
18357f1050SThomas Veerman /* modification, are permitted provided that the following conditions */
19357f1050SThomas Veerman /* are met: */
20357f1050SThomas Veerman
21357f1050SThomas Veerman /* 1. Redistributions of source code must retain the above copyright */
22357f1050SThomas Veerman /* notice, this list of conditions and the following disclaimer. */
23357f1050SThomas Veerman /* 2. Redistributions in binary form must reproduce the above copyright */
24357f1050SThomas Veerman /* notice, this list of conditions and the following disclaimer in the */
25357f1050SThomas Veerman /* documentation and/or other materials provided with the distribution. */
26357f1050SThomas Veerman
27357f1050SThomas Veerman /* Neither the name of the University nor the names of its contributors */
28357f1050SThomas Veerman /* may be used to endorse or promote products derived from this software */
29357f1050SThomas Veerman /* without specific prior written permission. */
30357f1050SThomas Veerman
31357f1050SThomas Veerman /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32357f1050SThomas Veerman /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33357f1050SThomas Veerman /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
34357f1050SThomas Veerman /* PURPOSE. */
35357f1050SThomas Veerman #include "flexdef.h"
36*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: scanflags.c,v 1.3 2014/10/30 18:44:05 christos Exp $");
37357f1050SThomas Veerman
38357f1050SThomas Veerman scanflags_t* _sf_stk = NULL;
39357f1050SThomas Veerman size_t _sf_top_ix=0, _sf_max=0;
40357f1050SThomas Veerman
41357f1050SThomas Veerman void
sf_push(void)42357f1050SThomas Veerman sf_push (void)
43357f1050SThomas Veerman {
44357f1050SThomas Veerman if (_sf_top_ix + 1 >= _sf_max)
45357f1050SThomas Veerman _sf_stk = (scanflags_t*) flex_realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32));
46357f1050SThomas Veerman
47357f1050SThomas Veerman // copy the top element
48357f1050SThomas Veerman _sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix];
49357f1050SThomas Veerman ++_sf_top_ix;
50357f1050SThomas Veerman }
51357f1050SThomas Veerman
52357f1050SThomas Veerman void
sf_pop(void)53357f1050SThomas Veerman sf_pop (void)
54357f1050SThomas Veerman {
55357f1050SThomas Veerman assert(_sf_top_ix > 0);
56357f1050SThomas Veerman --_sf_top_ix;
57357f1050SThomas Veerman }
58357f1050SThomas Veerman
59357f1050SThomas Veerman /* one-time initialization. Should be called before any sf_ functions. */
60357f1050SThomas Veerman void
sf_init(void)61357f1050SThomas Veerman sf_init (void)
62357f1050SThomas Veerman {
63357f1050SThomas Veerman assert(_sf_stk == NULL);
64357f1050SThomas Veerman _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
6584d9c625SLionel Sambuc if (!_sf_stk)
6684d9c625SLionel Sambuc lerrsf_fatal(_("Unable to allocate %ld of stack"),
6784d9c625SLionel Sambuc (long)sizeof(scanflags_t));
68357f1050SThomas Veerman _sf_stk[_sf_top_ix] = 0;
69357f1050SThomas Veerman }
70357f1050SThomas Veerman
71357f1050SThomas Veerman /* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */
72