Contents of /trunk/mkinitrd-magellan/klibc/usr/dash/nodes.c.pat
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File size: 3812 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File size: 3812 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /*- |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. |
4 | * Copyright (c) 1997-2005 |
5 | * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved. |
6 | * |
7 | * This code is derived from software contributed to Berkeley by |
8 | * Kenneth Almquist. |
9 | * |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions |
12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of the University nor the names of its contributors |
19 | * may be used to endorse or promote products derived from this software |
20 | * without specific prior written permission. |
21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. |
33 | * |
34 | * @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95 |
35 | */ |
36 | |
37 | #include <stdlib.h> |
38 | /* |
39 | * Routine for dealing with parsed shell commands. |
40 | */ |
41 | |
42 | #include "shell.h" |
43 | #include "nodes.h" |
44 | #include "memalloc.h" |
45 | #include "machdep.h" |
46 | #include "mystring.h" |
47 | #include "system.h" |
48 | |
49 | |
50 | int funcblocksize; /* size of structures in function */ |
51 | int funcstringsize; /* size of strings in node */ |
52 | pointer funcblock; /* block to allocate function from */ |
53 | char *funcstring; /* block to allocate strings from */ |
54 | |
55 | %SIZES |
56 | |
57 | |
58 | STATIC void calcsize(union node *); |
59 | STATIC void sizenodelist(struct nodelist *); |
60 | STATIC union node *copynode(union node *); |
61 | STATIC struct nodelist *copynodelist(struct nodelist *); |
62 | STATIC char *nodesavestr(char *); |
63 | |
64 | |
65 | |
66 | /* |
67 | * Make a copy of a parse tree. |
68 | */ |
69 | |
70 | struct funcnode * |
71 | copyfunc(union node *n) |
72 | { |
73 | struct funcnode *f; |
74 | size_t blocksize; |
75 | |
76 | funcblocksize = offsetof(struct funcnode, n); |
77 | funcstringsize = 0; |
78 | calcsize(n); |
79 | blocksize = funcblocksize; |
80 | f = ckmalloc(blocksize + funcstringsize); |
81 | funcblock = (char *) f + offsetof(struct funcnode, n); |
82 | funcstring = (char *) f + blocksize; |
83 | copynode(n); |
84 | f->count = 0; |
85 | return f; |
86 | } |
87 | |
88 | |
89 | |
90 | STATIC void |
91 | calcsize(n) |
92 | union node *n; |
93 | { |
94 | %CALCSIZE |
95 | } |
96 | |
97 | |
98 | |
99 | STATIC void |
100 | sizenodelist(lp) |
101 | struct nodelist *lp; |
102 | { |
103 | while (lp) { |
104 | funcblocksize += SHELL_ALIGN(sizeof(struct nodelist)); |
105 | calcsize(lp->n); |
106 | lp = lp->next; |
107 | } |
108 | } |
109 | |
110 | |
111 | |
112 | STATIC union node * |
113 | copynode(n) |
114 | union node *n; |
115 | { |
116 | union node *new; |
117 | |
118 | %COPY |
119 | return new; |
120 | } |
121 | |
122 | |
123 | STATIC struct nodelist * |
124 | copynodelist(lp) |
125 | struct nodelist *lp; |
126 | { |
127 | struct nodelist *start; |
128 | struct nodelist **lpp; |
129 | |
130 | lpp = &start; |
131 | while (lp) { |
132 | *lpp = funcblock; |
133 | funcblock = (char *) funcblock + |
134 | SHELL_ALIGN(sizeof(struct nodelist)); |
135 | (*lpp)->n = copynode(lp->n); |
136 | lp = lp->next; |
137 | lpp = &(*lpp)->next; |
138 | } |
139 | *lpp = NULL; |
140 | return start; |
141 | } |
142 | |
143 | |
144 | |
145 | STATIC char * |
146 | nodesavestr(s) |
147 | char *s; |
148 | { |
149 | char *rtn = funcstring; |
150 | |
151 | funcstring = stpcpy(funcstring, s) + 1; |
152 | return rtn; |
153 | } |
154 | |
155 | |
156 | |
157 | /* |
158 | * Free a parse tree. |
159 | */ |
160 | |
161 | void |
162 | freefunc(struct funcnode *f) |
163 | { |
164 | if (f && --f->count < 0) |
165 | ckfree(f); |
166 | } |