rbtagger 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 Todd A. Fisher
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 Todd A. Fisher
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
COPYING
|
2
|
+
History.txt
|
3
|
+
LICENSE
|
4
|
+
License.txt
|
5
|
+
Manifest.txt
|
6
|
+
PostInstall.txt
|
7
|
+
README
|
8
|
+
README.txt
|
9
|
+
Rakefile
|
10
|
+
config/hoe.rb
|
11
|
+
config/requirements.rb
|
12
|
+
ext/rule_tagger/bool.h
|
13
|
+
ext/rule_tagger/darray.c
|
14
|
+
ext/rule_tagger/darray.h
|
15
|
+
ext/rule_tagger/darrayP.h
|
16
|
+
ext/rule_tagger/extconf.rb
|
17
|
+
ext/rule_tagger/lex.c
|
18
|
+
ext/rule_tagger/lex.h
|
19
|
+
ext/rule_tagger/memory.c
|
20
|
+
ext/rule_tagger/memory.h
|
21
|
+
ext/rule_tagger/rbtagger.c
|
22
|
+
ext/rule_tagger/registry.c
|
23
|
+
ext/rule_tagger/registry.h
|
24
|
+
ext/rule_tagger/registryP.h
|
25
|
+
ext/rule_tagger/ruby-compat.h
|
26
|
+
ext/rule_tagger/rules.c
|
27
|
+
ext/rule_tagger/rules.h
|
28
|
+
ext/rule_tagger/sysdep.h
|
29
|
+
ext/rule_tagger/tagger.c
|
30
|
+
ext/rule_tagger/tagger.h
|
31
|
+
ext/rule_tagger/useful.c
|
32
|
+
ext/rule_tagger/useful.h
|
33
|
+
ext/word_tagger/extconf.rb
|
34
|
+
ext/word_tagger/porter_stemmer.c
|
35
|
+
ext/word_tagger/porter_stemmer.h
|
36
|
+
ext/word_tagger/rtagger.cc
|
37
|
+
ext/word_tagger/tagger.cc
|
38
|
+
ext/word_tagger/tagger.h
|
39
|
+
ext/word_tagger/tagger.rb
|
40
|
+
ext/word_tagger/test.rb
|
41
|
+
ext/word_tagger/test/Makefile
|
42
|
+
ext/word_tagger/test/doc.txt
|
43
|
+
ext/word_tagger/test/test.cc
|
44
|
+
lib/brill/tagger.rb
|
45
|
+
lib/rbtagger.rb
|
46
|
+
lib/rbtagger/version.rb
|
47
|
+
script/console
|
48
|
+
script/destroy
|
49
|
+
script/generate
|
50
|
+
script/txt2html
|
51
|
+
setup.rb
|
52
|
+
tasks/deployment.rake
|
53
|
+
tasks/environment.rake
|
54
|
+
tasks/website.rake
|
55
|
+
test/CONTEXTUALRULEFILE
|
56
|
+
test/LEXICALRULEFILE
|
57
|
+
test/LEXICON
|
58
|
+
test/docs/doc0.txt
|
59
|
+
test/docs/doc1.txt
|
60
|
+
test/docs/doc2.txt
|
61
|
+
test/docs/doc3.txt
|
62
|
+
test/docs/doc4.txt
|
63
|
+
test/docs/doc5.txt
|
64
|
+
test/docs/doc6.txt
|
65
|
+
test/docs/doc7.txt
|
66
|
+
test/docs/doc8.txt
|
67
|
+
test/docs/doc9.txt
|
68
|
+
test/tagger_test.rb
|
69
|
+
test/test_helper.rb
|
70
|
+
tools/rakehelp.rb
|
71
|
+
website/index.html
|
72
|
+
website/index.txt
|
73
|
+
website/javascripts/rounded_corners_lite.inc.js
|
74
|
+
website/stylesheets/screen.css
|
75
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
A Simple Ruby Rule-Based Part of Speech Tagger
|
2
|
+
|
3
|
+
This work is based on the work of Eric Brill
|
4
|
+
|
5
|
+
Credit for extracting Eric's work into a reusable library goes to Ken Williams as part of his work in creating the Lingua::BrillTagger perl module
|
6
|
+
|
7
|
+
This software is made available under the MIT License, see LICENSE
|
data/README.txt
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= rbtagger
|
2
|
+
|
3
|
+
* http://github.com/taf2/rb-brill-tagger/tree/master
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A Simple Ruby Rule-Based Part of Speech Tagger
|
8
|
+
|
9
|
+
This work is based on the work of Eric Brill
|
10
|
+
|
11
|
+
Credit for extracting Eric's work into a reusable library goes to Ken Williams as part of his work in creating the Lingua::BrillTagger perl module
|
12
|
+
|
13
|
+
This software is made available under the MIT License, see LICENSE
|
14
|
+
|
15
|
+
== FEATURES/PROBLEMS:
|
16
|
+
|
17
|
+
* Rule based tagger
|
18
|
+
* Word matching tagger
|
19
|
+
|
20
|
+
== SYNOPSIS:
|
21
|
+
|
22
|
+
tagger = Brill::Tagger.new( File.join(File.dirname(__FILE__),"LEXICON"),
|
23
|
+
File.join(File.dirname(__FILE__),"LEXICALRULEFILE"),
|
24
|
+
File.join(File.dirname(__FILE__),"CONTEXTUALRULEFILE") )
|
25
|
+
|
26
|
+
== INSTALL:
|
27
|
+
|
28
|
+
* sudo gem install rbtagger
|
29
|
+
|
30
|
+
== LICENSE:
|
31
|
+
|
32
|
+
(The MIT License)
|
33
|
+
|
34
|
+
Copyright (c) 2008 Todd A. Fisher
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
'Software'), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
50
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
51
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
52
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
53
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'config/requirements'
|
2
|
+
require 'config/hoe' # setup Hoe + all gem configuration
|
3
|
+
|
4
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
5
|
+
|
6
|
+
# redefine release
|
7
|
+
|
8
|
+
desc 'Package and upload the release to rubyforge.'
|
9
|
+
task :release_current => [:clean, :package] do |t|
|
10
|
+
require 'config/hoe'
|
11
|
+
version = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
12
|
+
name = $hoe.name
|
13
|
+
rubyforge_name = $hoe.rubyforge_name
|
14
|
+
description = $hoe.description
|
15
|
+
pkg = "pkg/#{name}-#{version}"
|
16
|
+
abort "Package doesn't exist => #{pkg}" if !File.exist?(pkg)
|
17
|
+
|
18
|
+
rf = RubyForge.new
|
19
|
+
puts "Logging in"
|
20
|
+
rf.login
|
21
|
+
|
22
|
+
c = rf.userconfig
|
23
|
+
c["release_notes"] = description if description
|
24
|
+
c["release_changes"] = $hoe.changes if $hoe.changes
|
25
|
+
c["preformatted"] = true
|
26
|
+
|
27
|
+
files = [(@need_tar ? "#{pkg}.tgz" : nil),
|
28
|
+
(@need_zip ? "#{pkg}.zip" : nil),
|
29
|
+
"#{pkg}.gem"].compact
|
30
|
+
|
31
|
+
puts "Releasing #{rubyforge_name} v. #{version}"
|
32
|
+
rf.add_release 'ruletagger', 'ruletagger', version, *files
|
33
|
+
end
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rbtagger/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Todd A. Fisher' # can also be an array of Authors
|
4
|
+
EMAIL = 'todd.fisher@gmail.com'
|
5
|
+
DESCRIPTION = "A Simple Ruby Rule-Based Part of Speech Tagger"
|
6
|
+
GEM_NAME = 'rbtagger' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'ruletagger' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = RbTagger::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'ruletagger documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
52
|
+
|
53
|
+
# Generate all the Rake tasks
|
54
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
55
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
56
|
+
p.developer(AUTHOR, EMAIL)
|
57
|
+
p.description = DESCRIPTION
|
58
|
+
p.summary = DESCRIPTION
|
59
|
+
p.url = HOMEPATH
|
60
|
+
p.rubyforge_name = PATH #RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
61
|
+
p.test_globs = ["test/**/test_*.rb"]
|
62
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
63
|
+
|
64
|
+
# == Optional
|
65
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
66
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
67
|
+
|
68
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
69
|
+
end
|
70
|
+
|
71
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
72
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
73
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
74
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#ifndef _BOOL_H_
|
2
|
+
#define _BOOL_H_
|
3
|
+
|
4
|
+
/* Note: It is an abstraction violation to use the C "boolean"
|
5
|
+
* operators (&&, ||, etc.) on Bool objects. Those operators
|
6
|
+
* really operate on type "int".
|
7
|
+
*
|
8
|
+
* Note: Bool_and() and Bool_or() do not short circuit.
|
9
|
+
* Bool_cand() and Bool_cor() do.
|
10
|
+
*/
|
11
|
+
|
12
|
+
/* The identifier en_Bool and the values are private */
|
13
|
+
|
14
|
+
#ifdef Bool
|
15
|
+
#undef Bool
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#ifdef __STDC__
|
19
|
+
typedef enum Bool_en {Bool_FALSE=0, Bool_TRUE=1} Bool;
|
20
|
+
#else
|
21
|
+
typedef int Bool;
|
22
|
+
#define Bool_FALSE 0
|
23
|
+
#define Bool_TRUE 1
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/* The macro expansions are private */
|
27
|
+
|
28
|
+
#define Bool_to_int(a) ((int)a)
|
29
|
+
#define Bool_to_char(a) ((char)a)
|
30
|
+
#define Bool_create(integral_value) (((integral_value) != 0)?(Bool_TRUE):(Bool_FALSE))
|
31
|
+
/* Some type conversions are omitted for efficiency (with stupid compilers) */
|
32
|
+
#define Bool_or(a,b) ((a)|(b))
|
33
|
+
#define Bool_and(a,b) ((a)&(b))
|
34
|
+
#define Bool_cor(a,b) ((a)||(b))
|
35
|
+
#define Bool_cand(a,b) ((a)&&(b))
|
36
|
+
#define Bool_not(a) ((a)^(Bool_TRUE))
|
37
|
+
|
38
|
+
#endif
|
@@ -0,0 +1,292 @@
|
|
1
|
+
#include <stddef.h>
|
2
|
+
/*#include <stdlib.h>*/
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <assert.h>
|
5
|
+
|
6
|
+
#include "sysdep.h"
|
7
|
+
#include "memory.h"
|
8
|
+
#include "bool.h"
|
9
|
+
|
10
|
+
#include "useful.h"
|
11
|
+
#include "darrayP.h"
|
12
|
+
|
13
|
+
/* Grow in the specified direction by the specified amount (number of
|
14
|
+
* new array slots). It amount is zero, grow by some default amount.
|
15
|
+
*/
|
16
|
+
static NORET grow(array_rep, direction, amount)
|
17
|
+
Darray_rep *array_rep;
|
18
|
+
enum grow_direction direction;
|
19
|
+
unsigned amount;
|
20
|
+
{
|
21
|
+
int grow_amount;
|
22
|
+
int new_length;
|
23
|
+
VOIDP *temp_new_space;
|
24
|
+
VOIDP *p, *q;
|
25
|
+
|
26
|
+
assert(direction == GROW_HIGH || direction == GROW_LOW);
|
27
|
+
|
28
|
+
if (amount == 0)
|
29
|
+
grow_amount = (MAX_GROW_STEP < array_rep->storage_length) ?
|
30
|
+
MAX_GROW_STEP : array_rep->storage_length;
|
31
|
+
else
|
32
|
+
grow_amount = amount;
|
33
|
+
|
34
|
+
new_length = array_rep->storage_length + grow_amount;
|
35
|
+
|
36
|
+
/* sort of like realloc, but not really */
|
37
|
+
if (direction == GROW_HIGH) {
|
38
|
+
/* Maybe this should not use realloc, since there may be unused
|
39
|
+
slots at the low end of the darray (before storage_offset), and it
|
40
|
+
is a waste to copy them */
|
41
|
+
array_rep->storage = (VOIDP *)Memory_reallocate(array_rep->storage,
|
42
|
+
sizeof(VOIDP) * new_length);
|
43
|
+
array_rep->storage_length = new_length;
|
44
|
+
} else { /* direction == GROW_LOW */
|
45
|
+
temp_new_space = (VOIDP *)Memory_allocate(sizeof(VOIDP) * new_length);
|
46
|
+
for (p=temp_new_space+grow_amount+array_rep->storage_offset,
|
47
|
+
q=array_rep->storage+array_rep->storage_offset;
|
48
|
+
q < array_rep->storage+array_rep->storage_offset+array_rep->length;
|
49
|
+
++p, ++q) {
|
50
|
+
*p = *q;
|
51
|
+
}
|
52
|
+
Memory_free(array_rep->storage);
|
53
|
+
array_rep->storage = temp_new_space;
|
54
|
+
array_rep->storage_length = new_length;
|
55
|
+
array_rep->storage_offset += grow_amount;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
Darray Darray_create(NOARGS)
|
60
|
+
{
|
61
|
+
Darray_rep *temp = dcreate();
|
62
|
+
|
63
|
+
temp->length = 0;
|
64
|
+
temp->storage = (VOIDP *)Memory_allocate(sizeof(VOIDP));
|
65
|
+
temp->storage_length = 1;
|
66
|
+
temp->storage_offset = 0;
|
67
|
+
return draise(temp);
|
68
|
+
}
|
69
|
+
|
70
|
+
NORET Darray_destroy(dyn_ary)
|
71
|
+
Darray dyn_ary;
|
72
|
+
{
|
73
|
+
Darray_rep *temp = dlower(dyn_ary);
|
74
|
+
|
75
|
+
Memory_free((VOIDP)temp->storage);
|
76
|
+
Memory_free((VOIDP)temp);
|
77
|
+
}
|
78
|
+
|
79
|
+
NORET Darray_hint(dyn_ary, addl_hint, addh_hint)
|
80
|
+
Darray dyn_ary;
|
81
|
+
unsigned addl_hint, addh_hint;
|
82
|
+
{
|
83
|
+
Darray_rep *temp = dlower(dyn_ary);
|
84
|
+
int grow_amount;
|
85
|
+
|
86
|
+
grow_amount = addh_hint - (temp->storage_length - temp->storage_offset
|
87
|
+
- temp->length);
|
88
|
+
if (grow_amount > 0)
|
89
|
+
grow(temp, GROW_HIGH, (unsigned)grow_amount);
|
90
|
+
|
91
|
+
grow_amount = addl_hint - temp->storage_offset;
|
92
|
+
if (grow_amount > 0)
|
93
|
+
grow(temp, GROW_LOW, (unsigned)grow_amount);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
NORET Darray_addh(dyn_ary, object)
|
98
|
+
Darray_rep *dyn_ary;
|
99
|
+
VOIDP object;
|
100
|
+
{
|
101
|
+
Darray_rep *temp = dlower(dyn_ary);
|
102
|
+
int add_posn = temp->storage_offset + temp->length;
|
103
|
+
|
104
|
+
if (add_posn >= temp->storage_length)
|
105
|
+
grow(temp, GROW_HIGH, (unsigned)0);
|
106
|
+
|
107
|
+
*(temp->storage + add_posn) = object;
|
108
|
+
++temp->length;
|
109
|
+
}
|
110
|
+
|
111
|
+
NORET Darray_addl(dyn_ary, obj)
|
112
|
+
Darray dyn_ary;
|
113
|
+
VOIDP obj;
|
114
|
+
{
|
115
|
+
Darray_rep *temp = dlower(dyn_ary);
|
116
|
+
|
117
|
+
if (temp->storage_offset == 0)
|
118
|
+
grow(temp, GROW_LOW, (unsigned)0); /* Modifies storage_offset */
|
119
|
+
|
120
|
+
assert(temp->storage_offset > 0);
|
121
|
+
|
122
|
+
/* Note side-effect */
|
123
|
+
*(temp->storage + --temp->storage_offset) = obj;
|
124
|
+
++temp->length;
|
125
|
+
}
|
126
|
+
|
127
|
+
VOIDP Darray_remh(dyn_ary)
|
128
|
+
Darray dyn_ary;
|
129
|
+
{
|
130
|
+
Darray_rep *temp = dlower(dyn_ary);
|
131
|
+
|
132
|
+
assert(temp->length > 0);
|
133
|
+
|
134
|
+
return *(temp->storage + temp->storage_offset + --temp->length);
|
135
|
+
}
|
136
|
+
|
137
|
+
VOIDP Darray_reml(dyn_ary)
|
138
|
+
Darray dyn_ary;
|
139
|
+
{
|
140
|
+
Darray_rep *temp = dlower(dyn_ary);
|
141
|
+
VOIDP return_value;
|
142
|
+
|
143
|
+
assert(temp->length > 0);
|
144
|
+
|
145
|
+
return_value = *(temp->storage + temp->storage_offset++);
|
146
|
+
--temp->length;
|
147
|
+
return return_value;
|
148
|
+
}
|
149
|
+
|
150
|
+
unsigned Darray_len(dyn_ary)
|
151
|
+
Darray dyn_ary;
|
152
|
+
{
|
153
|
+
assert(dyn_ary != (Darray)NULL);
|
154
|
+
|
155
|
+
return dlower(dyn_ary)->length;
|
156
|
+
}
|
157
|
+
|
158
|
+
Bool Darray_valid_index(dyn_ary, index)
|
159
|
+
Darray dyn_ary;
|
160
|
+
unsigned index;
|
161
|
+
{
|
162
|
+
return Bool_create(index < Darray_len(dyn_ary));
|
163
|
+
}
|
164
|
+
|
165
|
+
NORET Darray_set(dyn_ary, index, obj)
|
166
|
+
Darray dyn_ary;
|
167
|
+
unsigned index;
|
168
|
+
VOIDP obj;
|
169
|
+
{
|
170
|
+
Darray_rep *temp = dlower(dyn_ary);
|
171
|
+
|
172
|
+
assert(Darray_valid_index(dyn_ary, index)==Bool_TRUE);
|
173
|
+
|
174
|
+
*(temp->storage + temp->storage_offset + index) = obj;
|
175
|
+
}
|
176
|
+
|
177
|
+
VOIDP Darray_get(dyn_ary, index)
|
178
|
+
Darray dyn_ary;
|
179
|
+
unsigned index;
|
180
|
+
{
|
181
|
+
Darray_rep *temp = dlower(dyn_ary);
|
182
|
+
|
183
|
+
assert(Darray_valid_index(dyn_ary, index)==Bool_TRUE);
|
184
|
+
|
185
|
+
/* You should suppress the saber warning on the following line */
|
186
|
+
return *(temp->storage + temp->storage_offset + index);
|
187
|
+
}
|
188
|
+
|
189
|
+
NORET Darray_values(dyn_ary, c_ary)
|
190
|
+
Darray dyn_ary;
|
191
|
+
VOIDP *c_ary;
|
192
|
+
{
|
193
|
+
Darray_rep *temp = dlower(dyn_ary);
|
194
|
+
VOIDP *p, *q;
|
195
|
+
|
196
|
+
for (p=c_ary, q=temp->storage+temp->storage_offset;
|
197
|
+
q < temp->storage+temp->storage_offset+temp->length;
|
198
|
+
++p, ++q) {
|
199
|
+
*p = *q;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
Darray Darray_copy(dyn_ary)
|
204
|
+
Darray dyn_ary;
|
205
|
+
{
|
206
|
+
Darray temp = Darray_create();
|
207
|
+
unsigned int temp_len = Darray_len(dyn_ary);
|
208
|
+
unsigned int i;
|
209
|
+
|
210
|
+
Darray_hint(temp, (unsigned int)0, temp_len);
|
211
|
+
for (i = 0; i < temp_len; ++i)
|
212
|
+
Darray_addh(temp, Darray_get(dyn_ary, i));
|
213
|
+
return temp;
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/*--------------------------------------------------*/
|
218
|
+
/* code added by Rich Pito */
|
219
|
+
/*--------------------------------------------------*/
|
220
|
+
|
221
|
+
/* Both of thes function has to be rewrutten to use the internal darray data */
|
222
|
+
/* structure. This is this way for ease of writing */
|
223
|
+
|
224
|
+
Darray Darray_remove(dar, index)
|
225
|
+
Darray dar;
|
226
|
+
int index;
|
227
|
+
{
|
228
|
+
int s, d, l;
|
229
|
+
l = Darray_len(dar);
|
230
|
+
if (index == (l - 1)) {
|
231
|
+
Darray_remh(dar);
|
232
|
+
return dar;
|
233
|
+
}
|
234
|
+
if (index == 0) {
|
235
|
+
Darray_reml(dar);
|
236
|
+
return dar;
|
237
|
+
}
|
238
|
+
s = index + 1; d = index;
|
239
|
+
while (s < l) {
|
240
|
+
Darray_set(dar, d, (VOIDP)Darray_get(dar, s));
|
241
|
+
s++; d++;
|
242
|
+
}
|
243
|
+
Darray_remh(dar);
|
244
|
+
return dar;
|
245
|
+
}
|
246
|
+
|
247
|
+
/*--------------------------------------------------*/
|
248
|
+
Darray Darray_insert(dar, index, data)
|
249
|
+
Darray dar;
|
250
|
+
int index;
|
251
|
+
VOIDP data;
|
252
|
+
{
|
253
|
+
int l = Darray_len(dar);
|
254
|
+
int source;
|
255
|
+
if (index <= 0)
|
256
|
+
Darray_addl(dar, data);
|
257
|
+
else if (index >= l)
|
258
|
+
Darray_addh(dar, data);
|
259
|
+
else {
|
260
|
+
Darray_addh(dar, NULL);
|
261
|
+
for (source = l - 1; source >= index; source--)
|
262
|
+
Darray_set(dar, source + 1, Darray_get(dar, source));
|
263
|
+
Darray_set(dar, index, data);
|
264
|
+
}
|
265
|
+
return dar;
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
/*--------------------------------------------------*/
|
270
|
+
Darray Darray_duplicate(a)
|
271
|
+
Darray a;
|
272
|
+
{
|
273
|
+
int i, l;
|
274
|
+
Darray ret;
|
275
|
+
|
276
|
+
l = Darray_len(a);
|
277
|
+
ret = Darray_create();
|
278
|
+
Darray_hint(ret, 0, l);
|
279
|
+
for (i = 0; i < l; i++) {
|
280
|
+
Darray_addh(ret, (char*)Darray_get(a, i));
|
281
|
+
}
|
282
|
+
return ret;
|
283
|
+
}
|
284
|
+
|
285
|
+
void Darray_clear(dyn_ary)
|
286
|
+
Darray dyn_ary;
|
287
|
+
{
|
288
|
+
Darray_rep *temp = dlower(dyn_ary);
|
289
|
+
|
290
|
+
temp->storage_offset = 0;
|
291
|
+
temp->length = 0;
|
292
|
+
}
|