File: stack_8c-source.html

package info (click to toggle)
discover 2.1.2-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,756 kB
  • sloc: sh: 7,862; ansic: 7,280; xml: 1,809; makefile: 680
file content (123 lines) | stat: -rw-r--r-- 7,113 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>discover: /home/pere/src/debiancvs/pkg-discover/discover/trunk/lib/stack.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<div class="nav">
<a class="el" href="dir_000002.html">lib</a></div>
<h1>stack.c</h1><a href="stack_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/* $Progeny$ */</span>
00002 
00014 <span class="comment">/*</span>
00015 <span class="comment"> * AUTHOR: Josh Bressers &lt;bressers@progeny.com&gt;</span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * Copyright 2002 Progeny Linux Systems, Inc.</span>
00018 <span class="comment"> *</span>
00019 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
00020 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
00021 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
00022 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
00023 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
00024 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
00025 <span class="comment"> *</span>
00026 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
00027 <span class="comment"> * all copies or substantial portions of the Software.</span>
00028 <span class="comment"> *</span>
00029 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
00030 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
00031 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL</span>
00032 <span class="comment"> * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
00033 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
00034 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
00035 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
00036 <span class="comment"> */</span>
00037 
00038 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
00039 <span class="preprocessor">#include &lt;assert.h&gt;</span>
00040 <span class="preprocessor">#include &lt;stdbool.h&gt;</span>
00041 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
00042 
00043 <span class="preprocessor">#include &lt;discover/utils.h&gt;</span>
00044 <span class="preprocessor">#include &lt;discover/stack.h&gt;</span>
00045 
00046 
<a name="l00048"></a><a class="code" href="stack_8c.html#a0">00048</a> discover_xml_stack * <a class="code" href="stack_8c.html#a0">discover_xml_stack_new</a>()
00049 {
00050     discover_xml_stack *stack;
00051     stack = (discover_xml_stack *) _discover_xmalloc(<span class="keyword">sizeof</span>(discover_xml_stack));
00052     assert(stack != NULL);
00053 
00054     stack-&gt;prev = NULL;
00055     stack-&gt;data = NULL;
00056     stack-&gt;depth = 0;
00057 
00058     <span class="keywordflow">return</span> stack;
00059 }
00060 
<a name="l00062"></a><a class="code" href="stack_8c.html#a1">00062</a> <span class="keywordtype">void</span> <a class="code" href="stack_8c.html#a1">discover_xml_stack_destroy</a>(discover_xml_stack *stack)
00063 {
00064     free(stack);
00065 }
00066 
00068 <span class="keywordtype">void</span>
<a name="l00069"></a><a class="code" href="stack_8c.html#a2">00069</a> <a class="code" href="stack_8c.html#a2">discover_xml_stack_push</a>(discover_xml_stack **stack, <span class="keywordtype">void</span> *data)
00070 {
00071     discover_xml_stack *new_stack;
00072 
00073     new_stack = <a class="code" href="stack_8c.html#a0">discover_xml_stack_new</a>();
00074 
00075 
00076     new_stack-&gt;prev = *stack;
00077     new_stack-&gt;data = data;
00078     new_stack-&gt;depth = (*stack)-&gt;depth + 1;
00079     *stack = new_stack;
00080 }
00081 
<a name="l00083"></a><a class="code" href="stack_8c.html#a3">00083</a> <span class="keywordtype">void</span> * <a class="code" href="stack_8c.html#a3">discover_xml_stack_pop</a>(discover_xml_stack **stack)
00084 {
00085     <span class="keywordtype">void</span> *ctx;
00086     discover_xml_stack *oldstack;
00087 
00088     <span class="keywordflow">if</span>((*stack)-&gt;prev == 0) {
00089         <span class="keywordflow">return</span> NULL;
00090     }
00091 
00092     oldstack = *stack;
00093     ctx = (*stack)-&gt;data;
00094 
00095     *stack = (*stack)-&gt;prev;
00096     (*stack)-&gt;depth = oldstack-&gt;depth - 1;
00097     <a class="code" href="stack_8c.html#a1">discover_xml_stack_destroy</a>(oldstack);
00098 
00099     <span class="keywordflow">return</span> ctx;
00100 }
00101 
<a name="l00103"></a><a class="code" href="stack_8c.html#a4">00103</a> <span class="keywordtype">void</span> * <a class="code" href="stack_8c.html#a4">discover_xml_stack_get</a>(discover_xml_stack *stack)
00104 {
00105         <span class="keywordflow">return</span> stack-&gt;data;
00106 }
00107 
<a name="l00109"></a><a class="code" href="stack_8c.html#a5">00109</a> <span class="keywordtype">void</span> * <a class="code" href="stack_8c.html#a5">discover_xml_stack_getbynum</a>(discover_xml_stack *stack, <span class="keywordtype">int</span> i)
00110 {
00111     discover_xml_stack *S;
00112 
00113     S = stack;
00114     <span class="keywordflow">while</span>(S-&gt;depth &lt; i) {
00115         S = stack-&gt;prev;
00116     }
00117     <span class="keywordflow">return</span> S-&gt;data;
00118 }
00119 
00120 <span class="comment">/*</span>
00121 <span class="comment"> * Local variables:</span>
00122 <span class="comment"> * c-file-style: "progeny"</span>
00123 <span class="comment"> * indent-tabs-mode: nil</span>
00124 <span class="comment"> * End:</span>
00125 <span class="comment"> */</span>
00126 <span class="comment">/* vim: set cin fo=tcroq sw=4 et sts=4 tw=75: */</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Jul 28 03:38:00 2005 for discover by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>