1/*****************************************************************************/
2/* */
3/* intptrstack.c */
4/* */
5/* Integer+ptr stack used for program settings */
6/* */
7/* */
8/* */
9/* (C) 2017, Mega Cat Studios */
10/* */
11/* */
12/* This software is provided 'as-is', without any expressed or implied */
13/* warranty. In no event will the authors be held liable for any damages */
14/* arising from the use of this software. */
15/* */
16/* Permission is granted to anyone to use this software for any purpose, */
17/* including commercial applications, and to alter it and redistribute it */
18/* freely, subject to the following restrictions: */
19/* */
20/* 1. The origin of this software must not be misrepresented; you must not */
21/* claim that you wrote the original software. If you use this software */
22/* in a product, an acknowledgment in the product documentation would be */
23/* appreciated but is not required. */
24/* 2. Altered source versions must be plainly marked as such, and must not */
25/* be misrepresented as being the original software. */
26/* 3. This notice may not be removed or altered from any source */
27/* distribution. */
28/* */
29/*****************************************************************************/
30
31
32
33/* common */
34#include "check.h"
35#include "intptrstack.h"
36
37
38
39/*****************************************************************************/
40/* Code */
41/*****************************************************************************/
42
43
44
45void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr)
46/* Get the value on top of an int stack */
47{
48 PRECONDITION (S->Count > 0);
49 if (Val) *Val = S->Stack[S->Count-1].val;
50 if (Ptr) *Ptr = S->Stack[S->Count-1].ptr;
51}
52
53
54
55void IPS_Set (IntPtrStack* S, long Val, void *Ptr)
56/* Set the value on top of an int stack */
57{
58 PRECONDITION (S->Count > 0);
59 S->Stack[S->Count-1].val = Val;
60 S->Stack[S->Count-1].ptr = Ptr;
61}
62
63
64
65void IPS_Drop (IntPtrStack* S)
66/* Drop a value from an int stack */
67{
68 PRECONDITION (S->Count > 0);
69 --S->Count;
70}
71
72
73
74void IPS_Push (IntPtrStack* S, long Val, void *Ptr)
75/* Push a value onto an int stack */
76{
77 PRECONDITION (S->Count < sizeof (S->Stack) / sizeof (S->Stack[0]));
78 S->Stack[S->Count].val = Val;
79 S->Stack[S->Count++].ptr = Ptr;
80}
81
82
83
84void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr)
85/* Pop a value from an int stack */
86{
87 PRECONDITION (S->Count > 0);
88 if (Val) *Val = S->Stack[--S->Count].val;
89 if (Ptr) *Ptr = S->Stack[S->Count].ptr;
90}
91