rbtagger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +21 -0
- data/History.txt +4 -0
- data/LICENSE +21 -0
- data/License.txt +20 -0
- data/Manifest.txt +75 -0
- data/PostInstall.txt +7 -0
- data/README +7 -0
- data/README.txt +53 -0
- data/Rakefile +33 -0
- data/config/hoe.rb +74 -0
- data/config/requirements.rb +15 -0
- data/ext/rule_tagger/bool.h +38 -0
- data/ext/rule_tagger/darray.c +292 -0
- data/ext/rule_tagger/darray.h +125 -0
- data/ext/rule_tagger/darrayP.h +50 -0
- data/ext/rule_tagger/extconf.rb +14 -0
- data/ext/rule_tagger/lex.c +170 -0
- data/ext/rule_tagger/lex.h +49 -0
- data/ext/rule_tagger/memory.c +127 -0
- data/ext/rule_tagger/memory.h +20 -0
- data/ext/rule_tagger/rbtagger.c +252 -0
- data/ext/rule_tagger/registry.c +326 -0
- data/ext/rule_tagger/registry.h +129 -0
- data/ext/rule_tagger/registryP.h +46 -0
- data/ext/rule_tagger/ruby-compat.h +20 -0
- data/ext/rule_tagger/rules.c +525 -0
- data/ext/rule_tagger/rules.h +42 -0
- data/ext/rule_tagger/sysdep.h +20 -0
- data/ext/rule_tagger/tagger.c +110 -0
- data/ext/rule_tagger/tagger.h +46 -0
- data/ext/rule_tagger/useful.c +44 -0
- data/ext/rule_tagger/useful.h +51 -0
- data/ext/word_tagger/extconf.rb +7 -0
- data/ext/word_tagger/porter_stemmer.c +430 -0
- data/ext/word_tagger/porter_stemmer.h +19 -0
- data/ext/word_tagger/rtagger.cc +83 -0
- data/ext/word_tagger/tagger.cc +153 -0
- data/ext/word_tagger/tagger.h +27 -0
- data/ext/word_tagger/tagger.rb +8 -0
- data/ext/word_tagger/test/Makefile +22 -0
- data/ext/word_tagger/test/doc.txt +87 -0
- data/ext/word_tagger/test/test.cc +107 -0
- data/ext/word_tagger/test.rb +31 -0
- data/lib/brill/tagger.rb +225 -0
- data/lib/rbtagger/version.rb +9 -0
- data/lib/rbtagger.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/CONTEXTUALRULEFILE +284 -0
- data/test/LEXICALRULEFILE +148 -0
- data/test/LEXICON +93696 -0
- data/test/docs/doc0.txt +20 -0
- data/test/docs/doc1.txt +11 -0
- data/test/docs/doc2.txt +52 -0
- data/test/docs/doc3.txt +128 -0
- data/test/docs/doc4.txt +337 -0
- data/test/docs/doc5.txt +497 -0
- data/test/docs/doc6.txt +116 -0
- data/test/docs/doc7.txt +101 -0
- data/test/docs/doc8.txt +25 -0
- data/test/docs/doc9.txt +84 -0
- data/test/tagger_test.rb +60 -0
- data/test/test_helper.rb +2 -0
- data/tools/rakehelp.rb +113 -0
- data/website/index.html +113 -0
- data/website/index.txt +53 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +155 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
#ifndef _darray_h_
|
2
|
+
#define _darray_h_
|
3
|
+
|
4
|
+
#include "sysdep.h"
|
5
|
+
#include "bool.h"
|
6
|
+
|
7
|
+
typedef struct st_Darray *Darray;
|
8
|
+
|
9
|
+
#ifdef __STDC__
|
10
|
+
extern Darray Darray_create(NOARGS);
|
11
|
+
extern NORET Darray_destroy(Darray);
|
12
|
+
extern NORET Darray_hint(Darray, unsigned int, unsigned int);
|
13
|
+
extern unsigned int Darray_len(Darray);
|
14
|
+
extern NORET Darray_addh(Darray, VOIDP);
|
15
|
+
extern NORET Darray_addl(Darray, VOIDP);
|
16
|
+
extern VOIDP Darray_remh(Darray);
|
17
|
+
extern VOIDP Darray_reml(Darray);
|
18
|
+
extern Bool Darray_valid_index(Darray, unsigned int);
|
19
|
+
extern NORET Darray_set(Darray, unsigned int, VOIDP);
|
20
|
+
extern VOIDP Darray_get(Darray, unsigned int);
|
21
|
+
extern NORET Darray_values(Darray, VOIDP *);
|
22
|
+
extern Darray Darray_copy(Darray);
|
23
|
+
extern Darray Darray_remove(Darray, int);
|
24
|
+
extern Darray Darray_duplicate(Darray);
|
25
|
+
extern Darray Darray_insert(Darray, int, VOIDP);
|
26
|
+
extern void Darray_clear(Darray);
|
27
|
+
#else
|
28
|
+
extern Darray Darray_create();
|
29
|
+
extern NORET Darray_destroy();
|
30
|
+
extern NORET Darray_hint();
|
31
|
+
extern unsigned int Darray_len();
|
32
|
+
extern NORET Darray_addh();
|
33
|
+
extern NORET Darray_addl();
|
34
|
+
extern VOIDP Darray_remh();
|
35
|
+
extern VOIDP Darray_reml();
|
36
|
+
extern Bool Darray_valid_index();
|
37
|
+
extern NORET Darray_set();
|
38
|
+
extern VOIDP Darray_get();
|
39
|
+
extern NORET Darray_values();
|
40
|
+
extern Darray Darray_copy();
|
41
|
+
extern Darray Darray_remove();
|
42
|
+
extern Darray Darray_duplicate();
|
43
|
+
extern Darray Darray_insert();
|
44
|
+
extern void Darray_clear();
|
45
|
+
#endif /* __STDC__ */
|
46
|
+
|
47
|
+
|
48
|
+
/*
|
49
|
+
* Dynamic arrays are zero-based (0 <= index < length-of-array)
|
50
|
+
*
|
51
|
+
* Darray_create()
|
52
|
+
* Creates and returns an empty dynamic array.
|
53
|
+
*
|
54
|
+
* Darray_destroy(dynamic_array)
|
55
|
+
* Frees all memory used by the dynamic_array. Calling this routine
|
56
|
+
* should be the last use of the dynamic_array. The object held by
|
57
|
+
* the array are not destroyed.
|
58
|
+
*
|
59
|
+
* Darray_hint(dynamic_array, addl_hint, addh_hint)
|
60
|
+
* The hints specify how many additional (occuring after the hint call) addl
|
61
|
+
* and addh operations are expected. Large values may improve performance
|
62
|
+
* at the cost of additional memory usage.
|
63
|
+
*
|
64
|
+
* Darray_len(dynamic_array)
|
65
|
+
* Returns the length of the dynamic array passed.
|
66
|
+
*
|
67
|
+
* Darray_addh(dynamic_array, element)
|
68
|
+
* Adds the element to the "high end" of the dynamic array.
|
69
|
+
*
|
70
|
+
* Darray_addl(dynamic_array, element)
|
71
|
+
* Adds the element to the "low end" of the dynamic array.
|
72
|
+
*
|
73
|
+
* Darray_remh(dynamic_array)
|
74
|
+
* Returns element at the "high end" of the dynamic array,
|
75
|
+
* and removes that element from the array. Darray_len(dynamic_array)
|
76
|
+
* must be > 0.
|
77
|
+
*
|
78
|
+
* Darray_reml(dynamic_array)
|
79
|
+
* Returns element at the "low end" of the dynamic array,
|
80
|
+
* and removes that element from the array. Darray_len(dynamic_array)
|
81
|
+
* must be > 0.
|
82
|
+
*
|
83
|
+
* Darray_valid_index(dynamic_array, index)
|
84
|
+
* Checks if index is valid for use in a call to Darray_set or Darray_get.
|
85
|
+
* Returns Bool_TRUE if index < Darray_len(dynamic_array),
|
86
|
+
* Bool_FALSE otherwise.
|
87
|
+
*
|
88
|
+
* Darray_set(dynamic_array, index, new_value)
|
89
|
+
* Sets the index position in the dynamic array to be
|
90
|
+
* the new value. Darray_valid_index(dynamic_array, index) must be Bool_TRUE.
|
91
|
+
*
|
92
|
+
* Darray_get(dynamic_array, index)
|
93
|
+
* Returns the value at the index position in the dynamic array.
|
94
|
+
* Darray_valid_index(dynamic_array, index) must be Bool_TRUE.
|
95
|
+
*
|
96
|
+
* Darray_values(dynamic_array, pointer to c_array)
|
97
|
+
* Stores all the elements (as void pointers) of the dynamic array into
|
98
|
+
* the c_array. The
|
99
|
+
* c_array must contain at least Darray_len(dynamic_array) slots for
|
100
|
+
* void pointers (note: not object pointers).
|
101
|
+
*
|
102
|
+
* Darray_copy(dynamic_array)
|
103
|
+
* Creates and returns a new dynamic array, with the same contents as
|
104
|
+
* the dynamic array passed. The new dynamic array does not inherit
|
105
|
+
* any hints that may apply to the original dynamic array.
|
106
|
+
*
|
107
|
+
* Darray_remove(dynamic_array, index)
|
108
|
+
* removes the item indexed by index from the array. Index is base 0
|
109
|
+
* (i.e. first item in array is 0, last item is Darray_len()-1)
|
110
|
+
* (added by Rich Pito: this is not efficient code at the moment)
|
111
|
+
*
|
112
|
+
* Darray_insert(dynamic_array, index, data)
|
113
|
+
* inserts the data into the dynamic_array at index. data is inserted
|
114
|
+
* at position index. All items with position values greater than or
|
115
|
+
* equal to index are assigned new position values one greater than
|
116
|
+
* their old ones. If index is greater than the maximum position
|
117
|
+
* value in the dynamic_array, data is added as the topmost element to
|
118
|
+
* the array. If index is less than zero it is inserted as if index
|
119
|
+
* were zero.
|
120
|
+
* (added by Rich Pito: this is not efficient code at the moment)
|
121
|
+
|
122
|
+
|
123
|
+
*/
|
124
|
+
|
125
|
+
#endif /* ifndef _darray_h_ */
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#ifndef _darrayP_h_
|
2
|
+
#define _darrayP_h_
|
3
|
+
|
4
|
+
#include "sysdep.h"
|
5
|
+
#include "memory.h"
|
6
|
+
|
7
|
+
#include "darray.h"
|
8
|
+
|
9
|
+
typedef struct st_Darray {
|
10
|
+
unsigned length;
|
11
|
+
VOIDP *storage;
|
12
|
+
unsigned storage_offset;
|
13
|
+
unsigned storage_length;
|
14
|
+
} Darray_rep;
|
15
|
+
|
16
|
+
#define draise(p_to_rep) ((Darray)p_to_rep)
|
17
|
+
#define dlower(obj) ((Darray_rep *)obj)
|
18
|
+
#define dcreate() ((Darray_rep *)Memory_allocate(sizeof(Darray_rep)))
|
19
|
+
/*#define destroy(p_to_rep) (Memory_free(p_to_rep))*/
|
20
|
+
|
21
|
+
#define MAX_GROW_STEP 100 /* Defines the maximum amount to increase
|
22
|
+
storage_length when storage is full.
|
23
|
+
A call to Darray_hint can cause a larger
|
24
|
+
grow to occur; this only applies to
|
25
|
+
"on-demand grows" */
|
26
|
+
|
27
|
+
enum grow_direction {GROW_HIGH, GROW_LOW};
|
28
|
+
|
29
|
+
#ifdef __STDC__
|
30
|
+
static NORET grow(Darray_rep *, enum grow_direction, unsigned);
|
31
|
+
#else
|
32
|
+
static NORET grow();
|
33
|
+
#endif
|
34
|
+
|
35
|
+
/* Invariant conditions:
|
36
|
+
*
|
37
|
+
* Each array component (object) is stored in a void pointer.
|
38
|
+
*
|
39
|
+
* [storage_length] >= 1
|
40
|
+
*
|
41
|
+
* [storage] is pointer to a a heap object large enough for
|
42
|
+
* [storage_length] pointers to void,
|
43
|
+
*
|
44
|
+
* [storage_length] >= [length]
|
45
|
+
*
|
46
|
+
* The n-th element (index=n-1) of the dynamic array is located at
|
47
|
+
* address [storage]+[storage_offset]+n-1.
|
48
|
+
*
|
49
|
+
*/
|
50
|
+
#endif /* ifndef _darrayP_h_ */
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('rule_tagger')
|
4
|
+
have_header('stdlib.h')
|
5
|
+
have_header('string.h')
|
6
|
+
have_library('c', 'main')
|
7
|
+
|
8
|
+
if !have_func('snprintf', 'stdio.h')
|
9
|
+
raise "You must have snprintf available to compile this library"
|
10
|
+
end
|
11
|
+
|
12
|
+
CFLAGS='-Wall -g'
|
13
|
+
|
14
|
+
create_makefile('rule_tagger')
|
@@ -0,0 +1,170 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include "useful.h"
|
5
|
+
#include "lex.h"
|
6
|
+
|
7
|
+
int numspaces(char *buf);
|
8
|
+
int numchars(char *buf, char achar);
|
9
|
+
|
10
|
+
char *append_with_space(w1,w2)
|
11
|
+
char *w1,*w2;
|
12
|
+
{
|
13
|
+
char *result;
|
14
|
+
|
15
|
+
result = (char *)malloc((strlen(w1) + strlen(w2)+2) * sizeof(char));
|
16
|
+
strcpy(result,w1);
|
17
|
+
strcat(result," ");
|
18
|
+
strcat(result,w2);
|
19
|
+
return(result);
|
20
|
+
}
|
21
|
+
|
22
|
+
char *append_with_char(w1,w2,w3)
|
23
|
+
char *w1,*w2,w3;
|
24
|
+
{
|
25
|
+
char *result;
|
26
|
+
result = (char *)malloc((strlen(w1) + strlen(w2)+2) * sizeof(char));
|
27
|
+
sprintf(result,"%s%c%s",w1,w3,w2);
|
28
|
+
return(result);
|
29
|
+
}
|
30
|
+
|
31
|
+
void perl_split_free( char **split_buf )
|
32
|
+
{
|
33
|
+
int i;
|
34
|
+
for( i = 0; split_buf[i] != NULL; ++i ) {
|
35
|
+
free( split_buf[i] );
|
36
|
+
}
|
37
|
+
free( split_buf );
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
char **perl_split(buf)
|
42
|
+
const char *buf;
|
43
|
+
{
|
44
|
+
char **return_buf;
|
45
|
+
int cntr = 0;
|
46
|
+
char *temp,*temp2;
|
47
|
+
|
48
|
+
temp2 = (char *)malloc(sizeof(char)*(1+strlen(buf)));
|
49
|
+
while(*buf == ' ' || *buf == '\t') ++buf;
|
50
|
+
strcpy(temp2,buf);
|
51
|
+
return_buf = (char **) malloc(sizeof(char *) * ((numspaces(temp2)+1) + 2));
|
52
|
+
return_buf[cntr++] = strdup( (char *)strtok(temp2," \t") );
|
53
|
+
while ( (temp = (char *)strtok(NULL," \t")) )
|
54
|
+
if (temp != NULL) {
|
55
|
+
return_buf[cntr] = strdup(temp);
|
56
|
+
++cntr;}
|
57
|
+
return_buf[cntr] = NULL;
|
58
|
+
free(temp2);
|
59
|
+
return(return_buf);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
char **perl_split_independent(buf_in)
|
65
|
+
const char *buf_in;
|
66
|
+
{
|
67
|
+
char **return_buf;
|
68
|
+
int cntr = 0;
|
69
|
+
char *temp;
|
70
|
+
char *buf = mystrdup(buf_in);
|
71
|
+
|
72
|
+
while(*buf == ' ' || *buf == '\t') ++buf;
|
73
|
+
return_buf = (char **) malloc(sizeof(char *) * (numspaces(buf)+3));
|
74
|
+
return_buf[cntr++] = (char *)mystrdup((char *)strtok(buf," \t"));
|
75
|
+
while ((temp = (char *)strtok(NULL,"\t ")) != NULL) {
|
76
|
+
return_buf[cntr] =(char *)mystrdup(temp);
|
77
|
+
++cntr;
|
78
|
+
}
|
79
|
+
return_buf[cntr] = NULL;
|
80
|
+
return(return_buf); }
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
char **perl_split_on_char(buf,achar)
|
86
|
+
char *buf;
|
87
|
+
char achar;
|
88
|
+
{
|
89
|
+
char **return_buf;
|
90
|
+
int cntr = 0;
|
91
|
+
char *temp,temp2[2],*temp3;
|
92
|
+
|
93
|
+
temp3 = (char *)malloc(sizeof(char)*(1+strlen(buf)));
|
94
|
+
temp2[0] = achar; temp2[1] = '\0';
|
95
|
+
return_buf = (char **) malloc(sizeof(char *) * ((numchars(temp3,achar)+1) + 2));
|
96
|
+
return_buf[cntr++] = (char *)strtok(temp3,temp2);
|
97
|
+
while ( (temp = (char *)strtok(NULL,temp2)) )
|
98
|
+
if (temp != NULL) {
|
99
|
+
return_buf[cntr] = temp;
|
100
|
+
++cntr;}
|
101
|
+
return_buf[cntr] = NULL;
|
102
|
+
return(return_buf); }
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
char **perl_split_on_nothing(buf)
|
108
|
+
char *buf;
|
109
|
+
{
|
110
|
+
char **return_buf;
|
111
|
+
int cntr;
|
112
|
+
char *temp2;
|
113
|
+
|
114
|
+
temp2 = (char *)malloc(sizeof(char)*(1+strlen(buf)));
|
115
|
+
strcpy(temp2,buf);
|
116
|
+
|
117
|
+
return_buf = (char **) malloc(sizeof(char *) * (strlen(buf)+1));
|
118
|
+
for (cntr = 0; cntr < strlen(buf); ++cntr) {
|
119
|
+
return_buf[cntr] = (char *)malloc(sizeof(char)*2);
|
120
|
+
return_buf[cntr][0] = temp2[cntr];
|
121
|
+
return_buf[cntr][1] = '\0'; }
|
122
|
+
return_buf[cntr] = NULL;
|
123
|
+
return(return_buf);
|
124
|
+
}
|
125
|
+
|
126
|
+
int numspaces(buf)
|
127
|
+
char *buf;
|
128
|
+
{
|
129
|
+
int tot,count;
|
130
|
+
tot = 0;
|
131
|
+
for (count = 0; count < strlen(buf); ++count)
|
132
|
+
if (buf[count]==' ')
|
133
|
+
++tot;
|
134
|
+
return(tot); }
|
135
|
+
|
136
|
+
int numchars(buf,achar)
|
137
|
+
char *buf,achar;
|
138
|
+
{
|
139
|
+
int tot,count;
|
140
|
+
tot = 0;
|
141
|
+
for (count = 0; count < strlen(buf); ++count)
|
142
|
+
if (buf[count]== achar)
|
143
|
+
++tot;
|
144
|
+
return(tot); }
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
char *return_tag(theword)
|
149
|
+
char *theword;
|
150
|
+
{
|
151
|
+
char *tempword;
|
152
|
+
tempword = (char *)strchr(theword,'/');
|
153
|
+
if (tempword != NULL) return (tempword+1);
|
154
|
+
else return(NULL); }
|
155
|
+
|
156
|
+
|
157
|
+
char *before_tag(theword)
|
158
|
+
char *theword;
|
159
|
+
{
|
160
|
+
int count = 0;
|
161
|
+
|
162
|
+
while (theword[count] != '\0' &&
|
163
|
+
theword[count] != '/')
|
164
|
+
count++;
|
165
|
+
if (theword[count] == '/')
|
166
|
+
theword[count] = '\0';
|
167
|
+
return(theword); }
|
168
|
+
|
169
|
+
|
170
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#ifndef _LEX_H_
|
2
|
+
#define _LEX_H_
|
3
|
+
|
4
|
+
|
5
|
+
#ifdef __STDC__
|
6
|
+
extern char *append_with_space(char *,char *);
|
7
|
+
/* takes 2 strings, and appends them with a space btwn them */
|
8
|
+
|
9
|
+
extern char *append_with_char(char *,char *,char);
|
10
|
+
/* takes 2 strings, and appends them with character w3 (the */
|
11
|
+
/* third argument) btwn them */
|
12
|
+
|
13
|
+
extern char **perl_split(const char *);
|
14
|
+
/* takes a string with spaces and does a split, returning */
|
15
|
+
/* an array of ptrs to strings. */
|
16
|
+
/* like perl - @temp = split(/\s+/,$buf);
|
17
|
+
Last ptr is a null. */
|
18
|
+
/* x = perl_split(buf); then you are responsible for freeing
|
19
|
+
*x and x */
|
20
|
+
extern void perl_split_free( char **split_buf );
|
21
|
+
|
22
|
+
extern char **perl_split_independent(const char *);
|
23
|
+
/* same as perl_split, but each element in the array is a separate */
|
24
|
+
/* string of memory. */
|
25
|
+
|
26
|
+
extern char **perl_split_on_char(char *,char);
|
27
|
+
/* same as perl_split, but split on the specified character, instead */
|
28
|
+
/* of space */
|
29
|
+
|
30
|
+
extern char **perl_split_on_nothing(char *);
|
31
|
+
/* same as perl_split, but split on nothing instead of space*/
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
extern char *return_tag(char *); /* returns a ptr to the tag
|
36
|
+
in a tagged word (the/dt),
|
37
|
+
or NULL if not tagged.*/
|
38
|
+
#else
|
39
|
+
extern char *append_with_space();
|
40
|
+
extern char *append_with_char();
|
41
|
+
extern char **perl_split();
|
42
|
+
extern char **perl_split_independent();
|
43
|
+
extern char **perl_split_on_char();
|
44
|
+
extern char **perl_split_on_nothing();
|
45
|
+
extern char *return_tag();
|
46
|
+
|
47
|
+
#endif /* __STDC__ */
|
48
|
+
|
49
|
+
#endif /* _LEX_H_ */
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#include <stddef.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <assert.h>
|
4
|
+
|
5
|
+
#include <stdio.h>
|
6
|
+
#include "sysdep.h"
|
7
|
+
|
8
|
+
|
9
|
+
#ifndef MEMORY_LEAK_COUNT
|
10
|
+
long Memory_unfreed_bytes(NOARGS)
|
11
|
+
{
|
12
|
+
return 0;
|
13
|
+
}
|
14
|
+
#else
|
15
|
+
static long bytes_unfreed;
|
16
|
+
long Memory_unfreed_bytes(NOARGS)
|
17
|
+
{
|
18
|
+
return bytes_unfreed;
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifdef MEMORY_CHECK_POINTERS
|
24
|
+
|
25
|
+
#define MEMORY_REGISTRY_HT_SIZE 997
|
26
|
+
|
27
|
+
#include "registry.h"
|
28
|
+
#include "bool.h"
|
29
|
+
static Registry valid_blocks = NULL;
|
30
|
+
static int dont_check = 0;
|
31
|
+
|
32
|
+
static NORET mem_add_to_rgy(temp, bytes)
|
33
|
+
VOIDP temp;
|
34
|
+
size_t bytes;
|
35
|
+
{
|
36
|
+
dont_check = 1;
|
37
|
+
assert(Registry_add(valid_blocks, temp, (VOIDP)bytes)==Bool_TRUE);
|
38
|
+
#ifdef MEMORY_LEAK_COUNT
|
39
|
+
bytes_unfreed += bytes;
|
40
|
+
#endif
|
41
|
+
dont_check = 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
static NORET mem_remove_from_rgy(temp)
|
45
|
+
VOIDP temp;
|
46
|
+
{
|
47
|
+
long num_bytes;
|
48
|
+
|
49
|
+
dont_check = 1;
|
50
|
+
num_bytes = (long)Registry_get(valid_blocks, temp);
|
51
|
+
assert(num_bytes != 0);
|
52
|
+
#ifdef MEMORY_LEAK_COUNT
|
53
|
+
bytes_unfreed -= num_bytes;
|
54
|
+
#endif
|
55
|
+
assert(Registry_remove(valid_blocks, temp));
|
56
|
+
dont_check = 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
static int mem_rgy_initialized(NOARGS)
|
60
|
+
{
|
61
|
+
if (valid_blocks == (Registry)NULL) {
|
62
|
+
dont_check = 1;
|
63
|
+
valid_blocks = Registry_create(Registry_ptrcmp,
|
64
|
+
Registry_ptrhash);
|
65
|
+
Registry_size_hint(valid_blocks, (unsigned int)MEMORY_REGISTRY_HT_SIZE);
|
66
|
+
dont_check = 0;
|
67
|
+
}
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
#endif
|
72
|
+
|
73
|
+
VOIDP Memory_allocate(n)
|
74
|
+
size_t n;
|
75
|
+
{
|
76
|
+
VOIDP temp;
|
77
|
+
|
78
|
+
temp = (VOIDP)malloc(n);
|
79
|
+
|
80
|
+
#ifdef MEMORY_CHECK_POINTERS
|
81
|
+
assert(dont_check ||mem_rgy_initialized());
|
82
|
+
#endif
|
83
|
+
|
84
|
+
|
85
|
+
if (temp == NULL) {
|
86
|
+
fprintf(stderr, "Fatal error allocating %d bytes", (int)n);
|
87
|
+
abort();
|
88
|
+
}
|
89
|
+
#ifdef MEMORY_CHECK_POINTERS
|
90
|
+
assert(dont_check || (mem_add_to_rgy(temp,n),1));
|
91
|
+
#endif
|
92
|
+
return temp;
|
93
|
+
}
|
94
|
+
|
95
|
+
VOIDP Memory_reallocate(ptr, n)
|
96
|
+
VOIDP ptr;
|
97
|
+
size_t n;
|
98
|
+
{
|
99
|
+
VOIDP temp;
|
100
|
+
|
101
|
+
#ifdef MEMORY_CHECK_POINTERS
|
102
|
+
assert(dont_check ||mem_rgy_initialized());
|
103
|
+
assert(dont_check ||(mem_remove_from_rgy(ptr),1));
|
104
|
+
#endif
|
105
|
+
|
106
|
+
temp = (VOIDP)realloc(ptr, n);
|
107
|
+
if (temp == NULL) {
|
108
|
+
fprintf(stderr, "Fatal error allocating %d bytes", (int)n);
|
109
|
+
abort();
|
110
|
+
}
|
111
|
+
#ifdef MEMORY_CHECK_POINTERS
|
112
|
+
assert(dont_check ||(mem_add_to_rgy(temp,n),1));
|
113
|
+
#endif
|
114
|
+
return temp;
|
115
|
+
}
|
116
|
+
|
117
|
+
NORET Memory_free(ptr)
|
118
|
+
VOIDP ptr;
|
119
|
+
{
|
120
|
+
#ifdef MEMORY_CHECK_POINTERS
|
121
|
+
assert(dont_check ||mem_rgy_initialized());
|
122
|
+
assert(dont_check ||(mem_remove_from_rgy(ptr),1));
|
123
|
+
#endif
|
124
|
+
|
125
|
+
if (ptr != NULL)
|
126
|
+
free(ptr);
|
127
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef _Memory_h_
|
2
|
+
#define _Memory_h_
|
3
|
+
|
4
|
+
#include <stddef.h>
|
5
|
+
|
6
|
+
#include "sysdep.h"
|
7
|
+
|
8
|
+
#ifdef __STDC__
|
9
|
+
extern VOIDP Memory_allocate(size_t);
|
10
|
+
extern VOIDP Memory_reallocate(VOIDP, size_t);
|
11
|
+
extern NORET Memory_free(VOIDP);
|
12
|
+
extern long Memory_unfreed_bytes(NOARGS);
|
13
|
+
#else
|
14
|
+
extern VOIDP Memory_allocate();
|
15
|
+
extern VOIDP Memory_reallocate();
|
16
|
+
extern NORET Memory_free();
|
17
|
+
extern long Memory_unfreed_bytes(NOARGS);
|
18
|
+
#endif /* __STDC__ */
|
19
|
+
|
20
|
+
#endif
|