Skip to content

Commit 607c884

Browse files
committed
make proc self contained compilation
1 parent c893c81 commit 607c884

16 files changed

+1532
-34
lines changed

common/chkalloc.c

+164-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,177 @@
1-
# if 0
2-
chk_free(void *p)
1+
/**********************************************************************/
2+
/* */
3+
/* CRiSP - Programmable editor */
4+
/* =========================== */
5+
/* */
6+
/* File: chkalloc2.c */
7+
/* Author: P. D. Fox */
8+
/* Created: 26 Nov 2004 */
9+
/* */
10+
/* Copyright (c) 2004, Foxtrot Systems Ltd */
11+
/* All Rights Reserved. */
12+
/* */
13+
/*--------------------------------------------------------------------*/
14+
/* Description: Lightweight chkalloc replacement. */
15+
/*--------------------------------------------------------------------*/
16+
/* $Header: Last edited: 05-Jan-2005 1.2 $ */
17+
/**********************************************************************/
18+
19+
# include <stdio.h>
20+
# include <stdlib.h>
21+
# include <string.h>
22+
# include <strings.h>
23+
# include <memory.h>
24+
# include <stdarg.h>
25+
26+
#define DLL_EXPORT
27+
#define EXPORT_FUNCTION
28+
#define UNUSED_PARAMETER
29+
30+
void
31+
chk_init()
332
{
4-
free(p);
533
}
6-
chk_free_ptr(void **p)
34+
DLL_EXPORT void *EXPORT_FUNCTION
35+
check_alloc(unsigned int len, char *file)
736
{
8-
if (*p) {
9-
free(*p);
10-
*p = 0;
11-
}
37+
UNUSED_PARAMETER(file);
38+
39+
return malloc(len);
40+
}
41+
DLL_EXPORT void *EXPORT_FUNCTION
42+
chk_alloc(int size)
43+
{ void *ptr;
44+
45+
ptr = malloc(size);
46+
if (ptr == (void *) NULL) {
47+
printf("CHK_ALLOC: Failed to allocate memory. Wanted 0x%x bytes\n", size);
48+
}
49+
return ptr;
50+
}
51+
DLL_EXPORT void *EXPORT_FUNCTION
52+
chk_calloc(int size, int nel)
53+
{
54+
return calloc(size, nel);
55+
}
56+
void *
57+
chk_zalloc(int size)
58+
{ void *ptr;
59+
60+
ptr = calloc(size, 1);
61+
if (ptr == (void *) NULL) {
62+
printf("CHK_ALLOC: Failed to zallocate memory. Wanted 0x%x bytes\n", size);
63+
}
64+
return ptr;
65+
}
66+
/**********************************************************************/
67+
/* Create a new string which is a concatenation. */
68+
/**********************************************************************/
69+
DLL_EXPORT char *
70+
chk_makestr(const char *s1, ...)
71+
{ int len;
72+
char *p, *q, *sn;
73+
va_list ap;
74+
75+
len = strlen(s1);
76+
va_start(ap, s1);
77+
while (1) {
78+
sn = va_arg(ap, char *);
79+
if (!sn)
80+
break;
81+
len += strlen(sn);
82+
}
83+
va_end(ap);
84+
85+
p = check_alloc(len + 1, "chk_makestr");
86+
strcpy(p, s1);
87+
q = p + strlen(p);
88+
89+
va_start(ap, s1);
90+
while (1) {
91+
sn = va_arg(ap, char *);
92+
if (!sn)
93+
break;
94+
strcpy(q, sn);
95+
q += strlen(q);
96+
}
97+
va_end(ap);
98+
99+
return p;
12100
}
13101
void *
14-
chk_strdup(char *str)
102+
chk_realloc(char *ptr, int size)
103+
{
104+
ptr = realloc(ptr, size);
105+
if (ptr == (void *) NULL) {
106+
printf("CHK_ALLOC: Failed to reallocate memory. Wanted 0x%x bytes\n", size);
107+
}
108+
return ptr;
109+
}
110+
void
111+
chk_free(void *ptr)
112+
{
113+
free(ptr);
114+
}
115+
void
116+
chk_free_ptr(void **ptr)
117+
{
118+
if (*ptr) {
119+
chk_free(*ptr);
120+
*ptr = (void *) NULL;
121+
}
122+
}
123+
void
124+
chk_exit()
125+
{
126+
}
127+
void
128+
chk_free_safe(void *ptr)
129+
{
130+
if (ptr)
131+
free(ptr);
132+
}
133+
/**********************************************************************/
134+
/* Checking version of the strdup() function. */
135+
/**********************************************************************/
136+
char *
137+
chk_strdup(char *str)
15138
{
16139
return strdup(str);
17140
}
18-
void *
19-
chk_alloc(void *p)
141+
char *
142+
chk_strndup(char *str, int len)
143+
{ char *cp;
144+
145+
cp = (char *) malloc(len);
146+
memcpy(cp, str, len);
147+
148+
return cp;
149+
}
150+
/**********************************************************************/
151+
/* Called by main.c */
152+
/**********************************************************************/
153+
void
154+
chk_error(func)
155+
void (*func)();
156+
{
157+
UNUSED_PARAMETER(func);
158+
}
159+
/**********************************************************************/
160+
/* Called by crunch/crmain.c */
161+
/**********************************************************************/
162+
void
163+
chk_dump()
20164
{
21-
return malloc(p);
22165
}
166+
23167
void *
24-
chk_realloc(void *p, int s)
168+
vm_alloc(int sz, void **pool)
169+
{
170+
return chk_alloc(sz);
171+
}
172+
173+
void
174+
vm_free(void *m, void **pool)
25175
{
26-
return realloc(p, s);
176+
chk_free(m);
27177
}
28-
# endif

common/coldisp.h

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ void refresh_fp(FILE *fp);
6464
void out_flush(void);
6565
void reinit_screen(void);
6666
void end_screen(void);
67+
void disp_set_batch(int r, int c);
68+
void init_termcap(int r, int c);
69+
void init_screen(void);
70+
int tgetent(char *bp, char *name);
71+
int tnamchk(char *bp, char *name);
72+
6773

6874

6975
extern int dsp_crmode;

common/crc32.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/* This is not a real crc32 - but it is ok for the current purpose.
3+
*/
4+
5+
int
6+
crc32(char *s, int len)
7+
{ int sum = 0;
8+
9+
while (len-- > 0)
10+
sum += *s++;
11+
return sum;
12+
}

0 commit comments

Comments
 (0)