annotate keiko/util.c @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 /*
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 * util.c
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 * This file is part of the Oxford Oberon-2 compiler
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 * Copyright (c) 2006--2016 J. M. Spivey
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 * All rights reserved
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions are met:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 * 1. Redistributions of source code must retain the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 * this list of conditions and the following disclaimer.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 * this list of conditions and the following disclaimer in the documentation
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 * and/or other materials provided with the distribution.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 * 3. The name of the author may not be used to endorse or promote products
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 * derived from this software without specific prior written permission.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 #include "config.h"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 #include <stdio.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 #include <stdarg.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 #include <stdlib.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 #include <ctype.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 #include <string.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 #include "obcommon.h"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 #include "util.h"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 #include <assert.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 EXTERN int dflag;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 char *prog_name;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 void error(const char *msg, ...) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 va_list va;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 va_start(va, msg);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 fprintf(stderr, "%s: ", err_file);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 vfprintf(stderr, msg, va);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 va_end(va);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 fprintf(stderr, "\n");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 status = 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 void panic(const char *msg, ...) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 va_list va;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 mybool bug = FALSE;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 if (*msg == '*') {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 bug = TRUE; msg++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 fprintf(stderr, "%s: Fatal error -- ", progname);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 va_start(va, msg);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 vfprintf(stderr, msg, va);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 va_end(va);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 if (err_file != NULL)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 fprintf(stderr, " in %s", err_file);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 fprintf(stderr, "\n");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 if (bug)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 fprintf(stderr, "Please report bugs to %s or %s\n",
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 PACKAGE_TRACKER, PACKAGE_BUGREPORT);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 exit(2);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 /* must_alloc -- malloc or die */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 void *must_alloc(int n, const char *why) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 void *p;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 #ifdef DEBUG
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 if (dflag >= 2) printf("Allocating %s as %d", why, n);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 p = malloc(n);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 #ifdef DEBUG
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 if (dflag >= 2) printf(" at %p\n", p);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 if (p == NULL) panic("couldn't allocate space for %s", why);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 memset(p, 0, n);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 return p;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 /* must_strdup -- strdup or die */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 char *must_strdup(const char *s) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 char *p = (char *) must_alloc(strlen(s)+1, s);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 strcpy(p, s);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 return p;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 /* must_realloc -- realloc or (you guessed it) */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 void *must_realloc(void *p, int n0, int n, const char *msg) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 #ifdef DEBUG
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 if (dflag >= 2) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 printf("Growing %s at %p from %d to %d\n", msg, p, n0, n);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 fflush(stdout);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 p = realloc(p, n);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 if (p == NULL) panic("couldn't expand space for %s", msg);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 memset(((char *) p) + n0, 0, n-n0);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 return p;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 void _buf_init(struct _growbuf *b, int size, int margin,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 int elsize, const char *name) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 b->buf = must_alloc(size * elsize, name);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 b->loc = 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 b->size = size;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 b->margin = margin;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 b->elsize = elsize;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 b->name = name;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 void _buf_grow(struct _growbuf *b) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 if (b == NULL) panic("*uninitialized growbuf");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128 /* Ensure space for margin+1 items */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129 if (b->loc > b->size - b->margin) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 int size1 = max(b->size * GROW, b->loc + b->margin);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 b->buf = must_realloc(b->buf, b->size * b->elsize,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 size1 * b->elsize, b->name);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133 b->size = size1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 #define SIZE 10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138 #define PAGE 40000
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140 void *pool_alloc(mempool *pool, int size) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 void *result;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 assert(size < PAGE);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 if (pool->p_alloc + size > pool->p_pool[pool->p_current] + PAGE) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 pool->p_current++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
147 if (pool->p_current >= pool->p_npools) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
148 if (pool->p_npools >= pool->p_size) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
149 pool->p_pool = (unsigned char **)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
150 must_realloc(pool->p_pool,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
151 pool->p_size * sizeof(void *),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
152 2 * pool->p_size * sizeof(void *),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
153 "pool table");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
154 pool->p_size *= 2;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
155 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
156 pool->p_pool[pool->p_npools++] =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
157 (uchar *) must_alloc(PAGE, "pools");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
158 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
159 pool->p_alloc = pool->p_pool[pool->p_current];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
160 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
161
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
162 result = (void *) pool->p_alloc;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
163 pool->p_alloc += size;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
164 return result;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
165 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
166
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
167 void pool_reset(mempool *pool) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
168 if (pool->p_pool == NULL) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
169 pool->p_pool = (unsigned char **)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
170 must_alloc(SIZE * sizeof(void *), "pool table");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
171 pool->p_pool[0] = (uchar *) must_alloc(PAGE, "pools");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
172 pool->p_npools = 1; pool->p_size = SIZE;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
173 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
174
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
175 pool->p_current = 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
176 pool->p_alloc = pool->p_pool[0];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
177 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
178
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
179
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
180 int split_line(char *line, char **words) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
181 int nwords = 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
182 char *s;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
183
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
184 s = line;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
185 while (*s == ' ' || *s == '\t' || *s == '\r') s++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
186 if (*s == '\n' || *s == '!' || *s == '\0') return 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
187
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
188 /* Set the words array */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
189 while (1) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
190 while (*s == ' ' || *s == '\t' || *s == '\r') s++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
191 if (*s == '\n' || *s == '\0') break;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
192 if (nwords == MAXWORDS) panic("too many words");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
193 words[nwords++] = s;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
194 while (! isspace((int) *s) && *s != '\0') s++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
195 if (*s == '\n' || *s == '\0') { *s = '\0'; break; }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
196 *s++ = '\0';
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
197 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
198
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
199 return nwords;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
200 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
201
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
202 /* squidge -- change Oberon-style name into C identifier */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
203 char *squidge(char *name) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
204 static char buf[128];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
205 char *t = buf;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
206
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
207 for (char *s = name; *s != '\0'; s++)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
208 *t++ = ((*s == '.' || *s == '%') ? '_' : *s);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
209 *t = '\0';
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
210
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
211 return buf;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
212 }