xref: /netbsd-src/external/bsd/flex/dist/src/scanflags.c (revision 7977e68669c3b784eb65c933a2bd99785638ae00)
1*7977e686Schristos /*	$NetBSD: scanflags.c,v 1.3 2017/01/02 17:45:27 christos Exp $	*/
2a11deec2Schristos 
330da1778Schristos /* scanflags - flags used by scanning. */
430da1778Schristos 
530da1778Schristos /*  Copyright (c) 1990 The Regents of the University of California. */
630da1778Schristos /*  All rights reserved. */
730da1778Schristos 
830da1778Schristos /*  This code is derived from software contributed to Berkeley by */
930da1778Schristos /*  Vern Paxson. */
1030da1778Schristos 
1130da1778Schristos /*  The United States Government has rights in this work pursuant */
1230da1778Schristos /*  to contract no. DE-AC03-76SF00098 between the United States */
1330da1778Schristos /*  Department of Energy and the University of California. */
1430da1778Schristos 
1530da1778Schristos /*  This file is part of flex. */
1630da1778Schristos 
1730da1778Schristos /*  Redistribution and use in source and binary forms, with or without */
1830da1778Schristos /*  modification, are permitted provided that the following conditions */
1930da1778Schristos /*  are met: */
2030da1778Schristos 
2130da1778Schristos /*  1. Redistributions of source code must retain the above copyright */
2230da1778Schristos /*     notice, this list of conditions and the following disclaimer. */
2330da1778Schristos /*  2. Redistributions in binary form must reproduce the above copyright */
2430da1778Schristos /*     notice, this list of conditions and the following disclaimer in the */
2530da1778Schristos /*     documentation and/or other materials provided with the distribution. */
2630da1778Schristos 
2730da1778Schristos /*  Neither the name of the University nor the names of its contributors */
2830da1778Schristos /*  may be used to endorse or promote products derived from this software */
2930da1778Schristos /*  without specific prior written permission. */
3030da1778Schristos 
3130da1778Schristos /*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
3230da1778Schristos /*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
3330da1778Schristos /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
3430da1778Schristos /*  PURPOSE. */
3530da1778Schristos #include "flexdef.h"
36*7977e686Schristos __RCSID("$NetBSD: scanflags.c,v 1.3 2017/01/02 17:45:27 christos Exp $");
3730da1778Schristos 
3830da1778Schristos scanflags_t* _sf_stk = NULL;
3930da1778Schristos size_t _sf_top_ix=0, _sf_max=0;
4030da1778Schristos 
4130da1778Schristos void
sf_push(void)4230da1778Schristos sf_push (void)
4330da1778Schristos {
44*7977e686Schristos     if (_sf_top_ix + 1 >= _sf_max) {
45*7977e686Schristos         _sf_max += 32;
46*7977e686Schristos         _sf_stk = realloc(_sf_stk, sizeof(scanflags_t) * _sf_max);
47*7977e686Schristos     }
4830da1778Schristos 
4930da1778Schristos     // copy the top element
5030da1778Schristos     _sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix];
5130da1778Schristos     ++_sf_top_ix;
5230da1778Schristos }
5330da1778Schristos 
5430da1778Schristos void
sf_pop(void)5530da1778Schristos sf_pop (void)
5630da1778Schristos {
5730da1778Schristos     assert(_sf_top_ix > 0);
5830da1778Schristos     --_sf_top_ix;
5930da1778Schristos }
6030da1778Schristos 
6130da1778Schristos /* one-time initialization. Should be called before any sf_ functions. */
6230da1778Schristos void
sf_init(void)6330da1778Schristos sf_init (void)
6430da1778Schristos {
6530da1778Schristos     assert(_sf_stk == NULL);
66*7977e686Schristos     _sf_max = 32;
67*7977e686Schristos     _sf_stk = malloc(sizeof(scanflags_t) * _sf_max);
6830da1778Schristos     if (!_sf_stk)
6930da1778Schristos         lerr_fatal(_("Unable to allocate %zu of stack"), sizeof(scanflags_t));
7030da1778Schristos     _sf_stk[_sf_top_ix] = 0;
7130da1778Schristos }
7230da1778Schristos 
7330da1778Schristos /* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */
74