GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/lex/scanflags.c Lines: 10 12 83.3 %
Date: 2017-11-13 Branches: 2 4 50.0 %

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