grammar_police 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/c/.DS_Store +0 -0
- data/c/link-grammar.c +65 -0
- data/c/link-grammar.h +60 -0
- data/c/link-grammar.o +0 -0
- data/c/link-grammar.so +0 -0
- data/c/link-grammar/.DS_Store +0 -0
- data/c/link-grammar/.deps/analyze-linkage.Plo +198 -0
- data/c/link-grammar/.deps/and.Plo +202 -0
- data/c/link-grammar/.deps/api.Plo +244 -0
- data/c/link-grammar/.deps/build-disjuncts.Plo +212 -0
- data/c/link-grammar/.deps/command-line.Plo +201 -0
- data/c/link-grammar/.deps/constituents.Plo +201 -0
- data/c/link-grammar/.deps/count.Plo +202 -0
- data/c/link-grammar/.deps/disjunct-utils.Plo +126 -0
- data/c/link-grammar/.deps/disjuncts.Plo +123 -0
- data/c/link-grammar/.deps/error.Plo +121 -0
- data/c/link-grammar/.deps/expand.Plo +133 -0
- data/c/link-grammar/.deps/extract-links.Plo +198 -0
- data/c/link-grammar/.deps/fast-match.Plo +200 -0
- data/c/link-grammar/.deps/idiom.Plo +200 -0
- data/c/link-grammar/.deps/jni-client.Plo +217 -0
- data/c/link-grammar/.deps/link-parser.Po +1 -0
- data/c/link-grammar/.deps/massage.Plo +202 -0
- data/c/link-grammar/.deps/post-process.Plo +202 -0
- data/c/link-grammar/.deps/pp_knowledge.Plo +202 -0
- data/c/link-grammar/.deps/pp_lexer.Plo +201 -0
- data/c/link-grammar/.deps/pp_linkset.Plo +200 -0
- data/c/link-grammar/.deps/prefix.Plo +102 -0
- data/c/link-grammar/.deps/preparation.Plo +202 -0
- data/c/link-grammar/.deps/print-util.Plo +200 -0
- data/c/link-grammar/.deps/print.Plo +201 -0
- data/c/link-grammar/.deps/prune.Plo +202 -0
- data/c/link-grammar/.deps/read-dict.Plo +223 -0
- data/c/link-grammar/.deps/read-regex.Plo +123 -0
- data/c/link-grammar/.deps/regex-morph.Plo +131 -0
- data/c/link-grammar/.deps/resources.Plo +203 -0
- data/c/link-grammar/.deps/spellcheck-aspell.Plo +1 -0
- data/c/link-grammar/.deps/spellcheck-hun.Plo +115 -0
- data/c/link-grammar/.deps/string-set.Plo +198 -0
- data/c/link-grammar/.deps/tokenize.Plo +160 -0
- data/c/link-grammar/.deps/utilities.Plo +222 -0
- data/c/link-grammar/.deps/word-file.Plo +201 -0
- data/c/link-grammar/.deps/word-utils.Plo +212 -0
- data/c/link-grammar/.libs/analyze-linkage.o +0 -0
- data/c/link-grammar/.libs/and.o +0 -0
- data/c/link-grammar/.libs/api.o +0 -0
- data/c/link-grammar/.libs/build-disjuncts.o +0 -0
- data/c/link-grammar/.libs/command-line.o +0 -0
- data/c/link-grammar/.libs/constituents.o +0 -0
- data/c/link-grammar/.libs/count.o +0 -0
- data/c/link-grammar/.libs/disjunct-utils.o +0 -0
- data/c/link-grammar/.libs/disjuncts.o +0 -0
- data/c/link-grammar/.libs/error.o +0 -0
- data/c/link-grammar/.libs/expand.o +0 -0
- data/c/link-grammar/.libs/extract-links.o +0 -0
- data/c/link-grammar/.libs/fast-match.o +0 -0
- data/c/link-grammar/.libs/idiom.o +0 -0
- data/c/link-grammar/.libs/jni-client.o +0 -0
- data/c/link-grammar/.libs/liblink-grammar-java-symbols.expsym +31 -0
- data/c/link-grammar/.libs/liblink-grammar-java.4.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar-java.4.dylib.dSYM/Contents/Info.plist +20 -0
- data/c/link-grammar/.libs/liblink-grammar-java.4.dylib.dSYM/Contents/Resources/DWARF/liblink-grammar-java.4.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar-java.a +0 -0
- data/c/link-grammar/.libs/liblink-grammar-java.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar-symbols.expsym +194 -0
- data/c/link-grammar/.libs/liblink-grammar.4.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar.4.dylib.dSYM/Contents/Info.plist +20 -0
- data/c/link-grammar/.libs/liblink-grammar.4.dylib.dSYM/Contents/Resources/DWARF/liblink-grammar.4.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar.a +0 -0
- data/c/link-grammar/.libs/liblink-grammar.dylib +0 -0
- data/c/link-grammar/.libs/liblink-grammar.la +41 -0
- data/c/link-grammar/.libs/liblink-grammar.lai +41 -0
- data/c/link-grammar/.libs/massage.o +0 -0
- data/c/link-grammar/.libs/post-process.o +0 -0
- data/c/link-grammar/.libs/pp_knowledge.o +0 -0
- data/c/link-grammar/.libs/pp_lexer.o +0 -0
- data/c/link-grammar/.libs/pp_linkset.o +0 -0
- data/c/link-grammar/.libs/prefix.o +0 -0
- data/c/link-grammar/.libs/preparation.o +0 -0
- data/c/link-grammar/.libs/print-util.o +0 -0
- data/c/link-grammar/.libs/print.o +0 -0
- data/c/link-grammar/.libs/prune.o +0 -0
- data/c/link-grammar/.libs/read-dict.o +0 -0
- data/c/link-grammar/.libs/read-regex.o +0 -0
- data/c/link-grammar/.libs/regex-morph.o +0 -0
- data/c/link-grammar/.libs/resources.o +0 -0
- data/c/link-grammar/.libs/spellcheck-aspell.o +0 -0
- data/c/link-grammar/.libs/spellcheck-hun.o +0 -0
- data/c/link-grammar/.libs/string-set.o +0 -0
- data/c/link-grammar/.libs/tokenize.o +0 -0
- data/c/link-grammar/.libs/utilities.o +0 -0
- data/c/link-grammar/.libs/word-file.o +0 -0
- data/c/link-grammar/.libs/word-utils.o +0 -0
- data/c/link-grammar/Makefile +900 -0
- data/c/link-grammar/Makefile.am +202 -0
- data/c/link-grammar/Makefile.in +900 -0
- data/c/link-grammar/analyze-linkage.c +1317 -0
- data/c/link-grammar/analyze-linkage.h +24 -0
- data/c/link-grammar/and.c +1603 -0
- data/c/link-grammar/and.h +27 -0
- data/c/link-grammar/api-structures.h +362 -0
- data/c/link-grammar/api-types.h +72 -0
- data/c/link-grammar/api.c +1887 -0
- data/c/link-grammar/api.h +96 -0
- data/c/link-grammar/autoit/.DS_Store +0 -0
- data/c/link-grammar/autoit/README +10 -0
- data/c/link-grammar/autoit/_LGTest.au3 +22 -0
- data/c/link-grammar/autoit/_LinkGrammar.au3 +545 -0
- data/c/link-grammar/build-disjuncts.c +487 -0
- data/c/link-grammar/build-disjuncts.h +21 -0
- data/c/link-grammar/command-line.c +458 -0
- data/c/link-grammar/command-line.h +15 -0
- data/c/link-grammar/constituents.c +1836 -0
- data/c/link-grammar/constituents.h +26 -0
- data/c/link-grammar/corpus/.DS_Store +0 -0
- data/c/link-grammar/corpus/.deps/cluster.Plo +1 -0
- data/c/link-grammar/corpus/.deps/corpus.Plo +1 -0
- data/c/link-grammar/corpus/Makefile +527 -0
- data/c/link-grammar/corpus/Makefile.am +46 -0
- data/c/link-grammar/corpus/Makefile.in +527 -0
- data/c/link-grammar/corpus/README +17 -0
- data/c/link-grammar/corpus/cluster.c +286 -0
- data/c/link-grammar/corpus/cluster.h +32 -0
- data/c/link-grammar/corpus/corpus.c +483 -0
- data/c/link-grammar/corpus/corpus.h +46 -0
- data/c/link-grammar/count.c +828 -0
- data/c/link-grammar/count.h +25 -0
- data/c/link-grammar/disjunct-utils.c +261 -0
- data/c/link-grammar/disjunct-utils.h +27 -0
- data/c/link-grammar/disjuncts.c +138 -0
- data/c/link-grammar/disjuncts.h +13 -0
- data/c/link-grammar/error.c +92 -0
- data/c/link-grammar/error.h +35 -0
- data/c/link-grammar/expand.c +67 -0
- data/c/link-grammar/expand.h +13 -0
- data/c/link-grammar/externs.h +22 -0
- data/c/link-grammar/extract-links.c +625 -0
- data/c/link-grammar/extract-links.h +16 -0
- data/c/link-grammar/fast-match.c +309 -0
- data/c/link-grammar/fast-match.h +17 -0
- data/c/link-grammar/idiom.c +373 -0
- data/c/link-grammar/idiom.h +15 -0
- data/c/link-grammar/jni-client.c +779 -0
- data/c/link-grammar/jni-client.h +236 -0
- data/c/link-grammar/liblink-grammar-java.la +42 -0
- data/c/link-grammar/liblink-grammar.la +41 -0
- data/c/link-grammar/link-features.h +37 -0
- data/c/link-grammar/link-features.h.in +37 -0
- data/c/link-grammar/link-grammar-java.def +31 -0
- data/c/link-grammar/link-grammar.def +194 -0
- data/c/link-grammar/link-includes.h +465 -0
- data/c/link-grammar/link-parser.c +849 -0
- data/c/link-grammar/massage.c +329 -0
- data/c/link-grammar/massage.h +13 -0
- data/c/link-grammar/post-process.c +1113 -0
- data/c/link-grammar/post-process.h +45 -0
- data/c/link-grammar/pp_knowledge.c +376 -0
- data/c/link-grammar/pp_knowledge.h +14 -0
- data/c/link-grammar/pp_lexer.c +1920 -0
- data/c/link-grammar/pp_lexer.h +19 -0
- data/c/link-grammar/pp_linkset.c +158 -0
- data/c/link-grammar/pp_linkset.h +20 -0
- data/c/link-grammar/prefix.c +482 -0
- data/c/link-grammar/prefix.h +139 -0
- data/c/link-grammar/preparation.c +412 -0
- data/c/link-grammar/preparation.h +20 -0
- data/c/link-grammar/print-util.c +87 -0
- data/c/link-grammar/print-util.h +32 -0
- data/c/link-grammar/print.c +1085 -0
- data/c/link-grammar/print.h +16 -0
- data/c/link-grammar/prune.c +1864 -0
- data/c/link-grammar/prune.h +17 -0
- data/c/link-grammar/read-dict.c +1785 -0
- data/c/link-grammar/read-dict.h +29 -0
- data/c/link-grammar/read-regex.c +161 -0
- data/c/link-grammar/read-regex.h +12 -0
- data/c/link-grammar/regex-morph.c +126 -0
- data/c/link-grammar/regex-morph.h +17 -0
- data/c/link-grammar/resources.c +180 -0
- data/c/link-grammar/resources.h +23 -0
- data/c/link-grammar/sat-solver/.DS_Store +0 -0
- data/c/link-grammar/sat-solver/.deps/fast-sprintf.Plo +1 -0
- data/c/link-grammar/sat-solver/.deps/sat-encoder.Plo +1 -0
- data/c/link-grammar/sat-solver/.deps/util.Plo +1 -0
- data/c/link-grammar/sat-solver/.deps/variables.Plo +1 -0
- data/c/link-grammar/sat-solver/.deps/word-tag.Plo +1 -0
- data/c/link-grammar/sat-solver/Makefile +527 -0
- data/c/link-grammar/sat-solver/Makefile.am +29 -0
- data/c/link-grammar/sat-solver/Makefile.in +527 -0
- data/c/link-grammar/sat-solver/clock.hpp +33 -0
- data/c/link-grammar/sat-solver/fast-sprintf.cpp +26 -0
- data/c/link-grammar/sat-solver/fast-sprintf.hpp +7 -0
- data/c/link-grammar/sat-solver/guiding.hpp +244 -0
- data/c/link-grammar/sat-solver/matrix-ut.hpp +79 -0
- data/c/link-grammar/sat-solver/sat-encoder.cpp +2811 -0
- data/c/link-grammar/sat-solver/sat-encoder.h +11 -0
- data/c/link-grammar/sat-solver/sat-encoder.hpp +381 -0
- data/c/link-grammar/sat-solver/trie.hpp +118 -0
- data/c/link-grammar/sat-solver/util.cpp +23 -0
- data/c/link-grammar/sat-solver/util.hpp +14 -0
- data/c/link-grammar/sat-solver/variables.cpp +5 -0
- data/c/link-grammar/sat-solver/variables.hpp +829 -0
- data/c/link-grammar/sat-solver/word-tag.cpp +159 -0
- data/c/link-grammar/sat-solver/word-tag.hpp +162 -0
- data/c/link-grammar/spellcheck-aspell.c +148 -0
- data/c/link-grammar/spellcheck-hun.c +136 -0
- data/c/link-grammar/spellcheck.h +34 -0
- data/c/link-grammar/string-set.c +169 -0
- data/c/link-grammar/string-set.h +16 -0
- data/c/link-grammar/structures.h +498 -0
- data/c/link-grammar/tokenize.c +1049 -0
- data/c/link-grammar/tokenize.h +15 -0
- data/c/link-grammar/utilities.c +847 -0
- data/c/link-grammar/utilities.h +281 -0
- data/c/link-grammar/word-file.c +124 -0
- data/c/link-grammar/word-file.h +15 -0
- data/c/link-grammar/word-utils.c +526 -0
- data/c/link-grammar/word-utils.h +152 -0
- data/data/.DS_Store +0 -0
- data/data/Makefile +511 -0
- data/data/Makefile.am +4 -0
- data/data/Makefile.in +511 -0
- data/data/de/.DS_Store +0 -0
- data/data/de/4.0.affix +7 -0
- data/data/de/4.0.dict +474 -0
- data/data/de/Makefile +387 -0
- data/data/de/Makefile.am +9 -0
- data/data/de/Makefile.in +387 -0
- data/data/en/.DS_Store +0 -0
- data/data/en/4.0.affix +26 -0
- data/data/en/4.0.batch +1002 -0
- data/data/en/4.0.biolg.batch +411 -0
- data/data/en/4.0.constituent-knowledge +127 -0
- data/data/en/4.0.dict +8759 -0
- data/data/en/4.0.dict.m4 +6928 -0
- data/data/en/4.0.enwiki.batch +14 -0
- data/data/en/4.0.fixes.batch +2776 -0
- data/data/en/4.0.knowledge +306 -0
- data/data/en/4.0.regex +225 -0
- data/data/en/4.0.voa.batch +114 -0
- data/data/en/Makefile +554 -0
- data/data/en/Makefile.am +19 -0
- data/data/en/Makefile.in +554 -0
- data/data/en/README +173 -0
- data/data/en/tiny.dict +157 -0
- data/data/en/words/.DS_Store +0 -0
- data/data/en/words/Makefile +456 -0
- data/data/en/words/Makefile.am +78 -0
- data/data/en/words/Makefile.in +456 -0
- data/data/en/words/currency +205 -0
- data/data/en/words/currency.p +28 -0
- data/data/en/words/entities.given-bisex.sing +39 -0
- data/data/en/words/entities.given-female.sing +4141 -0
- data/data/en/words/entities.given-male.sing +1633 -0
- data/data/en/words/entities.locations.sing +68 -0
- data/data/en/words/entities.national.sing +253 -0
- data/data/en/words/entities.organizations.sing +7 -0
- data/data/en/words/entities.us-states.sing +11 -0
- data/data/en/words/units.1 +45 -0
- data/data/en/words/units.1.dot +4 -0
- data/data/en/words/units.3 +2 -0
- data/data/en/words/units.4 +5 -0
- data/data/en/words/units.4.dot +1 -0
- data/data/en/words/words-medical.adv.1 +1191 -0
- data/data/en/words/words-medical.prep.1 +67 -0
- data/data/en/words/words-medical.v.4.1 +2835 -0
- data/data/en/words/words-medical.v.4.2 +2848 -0
- data/data/en/words/words-medical.v.4.3 +3011 -0
- data/data/en/words/words-medical.v.4.4 +3036 -0
- data/data/en/words/words-medical.v.4.5 +3050 -0
- data/data/en/words/words.adj.1 +6794 -0
- data/data/en/words/words.adj.2 +638 -0
- data/data/en/words/words.adj.3 +667 -0
- data/data/en/words/words.adv.1 +1573 -0
- data/data/en/words/words.adv.2 +67 -0
- data/data/en/words/words.adv.3 +157 -0
- data/data/en/words/words.adv.4 +80 -0
- data/data/en/words/words.n.1 +11464 -0
- data/data/en/words/words.n.1.wiki +264 -0
- data/data/en/words/words.n.2.s +2017 -0
- data/data/en/words/words.n.2.s.biolg +1 -0
- data/data/en/words/words.n.2.s.wiki +298 -0
- data/data/en/words/words.n.2.x +65 -0
- data/data/en/words/words.n.2.x.wiki +10 -0
- data/data/en/words/words.n.3 +5717 -0
- data/data/en/words/words.n.t +23 -0
- data/data/en/words/words.v.1.1 +1038 -0
- data/data/en/words/words.v.1.2 +1043 -0
- data/data/en/words/words.v.1.3 +1052 -0
- data/data/en/words/words.v.1.4 +1023 -0
- data/data/en/words/words.v.1.p +17 -0
- data/data/en/words/words.v.10.1 +14 -0
- data/data/en/words/words.v.10.2 +15 -0
- data/data/en/words/words.v.10.3 +88 -0
- data/data/en/words/words.v.10.4 +17 -0
- data/data/en/words/words.v.2.1 +1253 -0
- data/data/en/words/words.v.2.2 +1304 -0
- data/data/en/words/words.v.2.3 +1280 -0
- data/data/en/words/words.v.2.4 +1285 -0
- data/data/en/words/words.v.2.5 +1287 -0
- data/data/en/words/words.v.4.1 +2472 -0
- data/data/en/words/words.v.4.2 +2487 -0
- data/data/en/words/words.v.4.3 +2441 -0
- data/data/en/words/words.v.4.4 +2478 -0
- data/data/en/words/words.v.4.5 +2483 -0
- data/data/en/words/words.v.5.1 +98 -0
- data/data/en/words/words.v.5.2 +98 -0
- data/data/en/words/words.v.5.3 +103 -0
- data/data/en/words/words.v.5.4 +102 -0
- data/data/en/words/words.v.6.1 +388 -0
- data/data/en/words/words.v.6.2 +401 -0
- data/data/en/words/words.v.6.3 +397 -0
- data/data/en/words/words.v.6.4 +405 -0
- data/data/en/words/words.v.6.5 +401 -0
- data/data/en/words/words.v.8.1 +117 -0
- data/data/en/words/words.v.8.2 +118 -0
- data/data/en/words/words.v.8.3 +118 -0
- data/data/en/words/words.v.8.4 +119 -0
- data/data/en/words/words.v.8.5 +119 -0
- data/data/en/words/words.y +104 -0
- data/data/lt/.DS_Store +0 -0
- data/data/lt/4.0.affix +6 -0
- data/data/lt/4.0.constituent-knowledge +24 -0
- data/data/lt/4.0.dict +135 -0
- data/data/lt/4.0.knowledge +38 -0
- data/data/lt/Makefile +389 -0
- data/data/lt/Makefile.am +11 -0
- data/data/lt/Makefile.in +389 -0
- data/grammar_police.gemspec +23 -0
- data/lib/.DS_Store +0 -0
- data/lib/grammar_police.rb +11 -0
- data/lib/grammar_police/.DS_Store +0 -0
- data/lib/grammar_police/dictionary.rb +30 -0
- data/lib/grammar_police/linkage.rb +26 -0
- data/lib/grammar_police/parse_options.rb +32 -0
- data/lib/grammar_police/sentence.rb +44 -0
- data/lib/grammar_police/version.rb +3 -0
- data/tests/.DS_Store +0 -0
- data/tests/count_linkages.rb +29 -0
- data/tests/sentences.txt +86 -0
- metadata +408 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
/*************************************************************************/
|
2
|
+
/* Copyright (c) 2004 */
|
3
|
+
/* Daniel Sleator, David Temperley, and John Lafferty */
|
4
|
+
/* All rights reserved */
|
5
|
+
/* */
|
6
|
+
/* Use of the link grammar parsing system is subject to the terms of the */
|
7
|
+
/* license set forth in the LICENSE file included with this software, */
|
8
|
+
/* and also available at http://www.link.cs.cmu.edu/link/license.html */
|
9
|
+
/* This license allows free redistribution and use in source and binary */
|
10
|
+
/* forms, with or without modification, subject to certain conditions. */
|
11
|
+
/* */
|
12
|
+
/*************************************************************************/
|
13
|
+
PPLexTable *pp_lexer_open(FILE *f);
|
14
|
+
void pp_lexer_close (PPLexTable *lt);
|
15
|
+
int pp_lexer_set_label (PPLexTable *lt, const char *label);
|
16
|
+
int pp_lexer_count_tokens_of_label (PPLexTable *lt);
|
17
|
+
const char *pp_lexer_get_next_token_of_label(PPLexTable *lt);
|
18
|
+
int pp_lexer_count_commas_of_label (PPLexTable *lt);
|
19
|
+
const char **pp_lexer_get_next_group_of_tokens_of_label(PPLexTable *lt,int *n_toks);
|
@@ -0,0 +1,158 @@
|
|
1
|
+
/*************************************************************************/
|
2
|
+
/* Copyright (c) 2004 */
|
3
|
+
/* Daniel Sleator, David Temperley, and John Lafferty */
|
4
|
+
/* All rights reserved */
|
5
|
+
/* */
|
6
|
+
/* Use of the link grammar parsing system is subject to the terms of the */
|
7
|
+
/* license set forth in the LICENSE file included with this software, */
|
8
|
+
/* and also available at http://www.link.cs.cmu.edu/link/license.html */
|
9
|
+
/* This license allows free redistribution and use in source and binary */
|
10
|
+
/* forms, with or without modification, subject to certain conditions. */
|
11
|
+
/* */
|
12
|
+
/*************************************************************************/
|
13
|
+
|
14
|
+
/***********************************************************************
|
15
|
+
pp_linkset.c
|
16
|
+
maintains sets of pointers to link names
|
17
|
+
Similar to string-set, except that the comparison and hashing functions are
|
18
|
+
tailored for links. More importantly, all we store here is pointers. It's up
|
19
|
+
to the caller to ensure that the pointers always point to something useful.
|
20
|
+
**********************************************************************/
|
21
|
+
|
22
|
+
#include <memory.h>
|
23
|
+
|
24
|
+
#include "api.h"
|
25
|
+
|
26
|
+
#define LINKSET_SPARSENESS 2
|
27
|
+
#define LINKSET_SEED_VALUE 37
|
28
|
+
|
29
|
+
static void clear_hash_table(pp_linkset *ls)
|
30
|
+
{
|
31
|
+
memset(ls->hash_table,0,ls->hash_table_size*sizeof(pp_linkset_node *));
|
32
|
+
}
|
33
|
+
|
34
|
+
static void initialize(pp_linkset *ls, int size)
|
35
|
+
{
|
36
|
+
ls->hash_table_size = size*LINKSET_SPARSENESS;
|
37
|
+
ls->population = 0;
|
38
|
+
ls->hash_table =
|
39
|
+
(pp_linkset_node**) xalloc (ls->hash_table_size*sizeof(pp_linkset_node *));
|
40
|
+
clear_hash_table(ls);
|
41
|
+
}
|
42
|
+
|
43
|
+
static int compute_hash(pp_linkset *ls, const char *str)
|
44
|
+
{
|
45
|
+
/* hash is computed from capitalized prefix only */
|
46
|
+
int i, hashval;
|
47
|
+
hashval=LINKSET_SEED_VALUE;
|
48
|
+
for (i=0; isupper((int)str[i]); i++)
|
49
|
+
hashval = str[i] + 31*hashval;
|
50
|
+
hashval = hashval % ls->hash_table_size;
|
51
|
+
if (hashval<0) hashval*=-1;
|
52
|
+
return hashval;
|
53
|
+
}
|
54
|
+
|
55
|
+
static pp_linkset_node *add_internal(pp_linkset *ls, const char *str)
|
56
|
+
{
|
57
|
+
pp_linkset_node *p, *n;
|
58
|
+
int hashval;
|
59
|
+
|
60
|
+
/* look for str (exactly) in linkset */
|
61
|
+
hashval = compute_hash(ls, str);
|
62
|
+
for (p=ls->hash_table[hashval]; p!=0; p=p->next)
|
63
|
+
if (!strcmp(p->str,str)) return NULL; /* already present */
|
64
|
+
|
65
|
+
/* create a new node for u; stick it at head of linked list */
|
66
|
+
n = (pp_linkset_node *) xalloc (sizeof(pp_linkset_node));
|
67
|
+
n->next = ls->hash_table[hashval];
|
68
|
+
n->str = str;
|
69
|
+
ls->hash_table[hashval] = n;
|
70
|
+
return n;
|
71
|
+
}
|
72
|
+
|
73
|
+
pp_linkset *pp_linkset_open(int size)
|
74
|
+
{
|
75
|
+
pp_linkset *ls;
|
76
|
+
if (size==0) return NULL;
|
77
|
+
ls = (pp_linkset *) xalloc (sizeof(pp_linkset));
|
78
|
+
initialize(ls, size);
|
79
|
+
return ls;
|
80
|
+
}
|
81
|
+
|
82
|
+
void pp_linkset_close(pp_linkset *ls)
|
83
|
+
{
|
84
|
+
if (ls==NULL) return;
|
85
|
+
pp_linkset_clear(ls); /* free memory taken by linked lists */
|
86
|
+
xfree((void*) ls->hash_table, ls->hash_table_size*sizeof(pp_linkset_node*));
|
87
|
+
xfree((void*) ls, sizeof(pp_linkset));
|
88
|
+
}
|
89
|
+
|
90
|
+
void pp_linkset_clear(pp_linkset *ls)
|
91
|
+
{
|
92
|
+
/* clear dangling linked lists, but retain hash table itself */
|
93
|
+
int i;
|
94
|
+
pp_linkset_node *p;
|
95
|
+
if (ls==NULL) return;
|
96
|
+
for (i=0; i<ls->hash_table_size; i++) {
|
97
|
+
p=ls->hash_table[i];
|
98
|
+
while (p) {
|
99
|
+
pp_linkset_node *q = p;
|
100
|
+
p=p->next;
|
101
|
+
xfree((void*) q, sizeof(pp_linkset_node));
|
102
|
+
}
|
103
|
+
}
|
104
|
+
clear_hash_table(ls);
|
105
|
+
ls->population=0;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* returns 0 if already there, 1 if new. Stores only the pointer
|
110
|
+
*/
|
111
|
+
int pp_linkset_add(pp_linkset *ls, const char *str)
|
112
|
+
{
|
113
|
+
if (ls==NULL)
|
114
|
+
{
|
115
|
+
prt_error("Fatal Error: pp_linkset internal error: Trying to add to a null set");
|
116
|
+
exit(1);
|
117
|
+
}
|
118
|
+
if (add_internal(ls, str) == NULL) return 0;
|
119
|
+
ls->population++;
|
120
|
+
return 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Set query. Returns 1 if str pp-matches something in the set, 0 otherwise
|
125
|
+
*/
|
126
|
+
int pp_linkset_match(pp_linkset *ls, const char *str)
|
127
|
+
{
|
128
|
+
int hashval;
|
129
|
+
pp_linkset_node *p;
|
130
|
+
if (ls==NULL) return 0;
|
131
|
+
hashval = compute_hash(ls, str);
|
132
|
+
p = ls->hash_table[hashval];
|
133
|
+
while(p!=0) {
|
134
|
+
if (post_process_match(p->str,str)) return 1;
|
135
|
+
p=p->next;
|
136
|
+
}
|
137
|
+
return 0;
|
138
|
+
}
|
139
|
+
|
140
|
+
int pp_linkset_match_bw(pp_linkset *ls, const char *str)
|
141
|
+
{
|
142
|
+
int hashval;
|
143
|
+
pp_linkset_node *p;
|
144
|
+
if (ls==NULL) return 0;
|
145
|
+
hashval = compute_hash(ls, str);
|
146
|
+
p = ls->hash_table[hashval];
|
147
|
+
while(p!=0) {
|
148
|
+
if (post_process_match(str,p->str)) return 1;
|
149
|
+
p=p->next;
|
150
|
+
}
|
151
|
+
return 0;
|
152
|
+
}
|
153
|
+
|
154
|
+
int pp_linkset_population(pp_linkset *ls)
|
155
|
+
{
|
156
|
+
return (ls==NULL)? 0 : ls->population;
|
157
|
+
}
|
158
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/********************************************************************************/
|
2
|
+
/* Copyright (c) 2004 */
|
3
|
+
/* Daniel Sleator, David Temperley, and John Lafferty */
|
4
|
+
/* All rights reserved */
|
5
|
+
/* */
|
6
|
+
/* Use of the link grammar parsing system is subject to the terms of the */
|
7
|
+
/* license set forth in the LICENSE file included with this software, */
|
8
|
+
/* and also available at http://www.link.cs.cmu.edu/link/license.html */
|
9
|
+
/* This license allows free redistribution and use in source and binary */
|
10
|
+
/* forms, with or without modification, subject to certain conditions. */
|
11
|
+
/* */
|
12
|
+
/********************************************************************************/
|
13
|
+
pp_linkset *pp_linkset_open(int size);
|
14
|
+
void pp_linkset_close (pp_linkset *ls);
|
15
|
+
void pp_linkset_clear (pp_linkset *ls);
|
16
|
+
int pp_linkset_add (pp_linkset *ls, const char *str);
|
17
|
+
int pp_linkset_match (pp_linkset *ls, const char *str);
|
18
|
+
int pp_linkset_match_bw (pp_linkset *ls, const char *str);
|
19
|
+
int pp_linkset_population(pp_linkset *ls);
|
20
|
+
|
@@ -0,0 +1,482 @@
|
|
1
|
+
/*
|
2
|
+
* BinReloc - a library for creating relocatable executables
|
3
|
+
* Written by: Mike Hearn <mike@theoretic.com>
|
4
|
+
* Hongli Lai <h.lai@chello.nl>
|
5
|
+
* http://autopackage.org/
|
6
|
+
*
|
7
|
+
* This source code is public domain. You can relicense this code
|
8
|
+
* under whatever license you want.
|
9
|
+
*
|
10
|
+
* NOTE: if you're using C++ and are getting "undefined reference
|
11
|
+
* to br_*", try renaming prefix.c to prefix.cpp
|
12
|
+
*/
|
13
|
+
|
14
|
+
/* WARNING, BEFORE YOU MODIFY PREFIX.C:
|
15
|
+
*
|
16
|
+
* If you make changes to any of the functions in prefix.c, you MUST
|
17
|
+
* change the BR_NAMESPACE macro (in prefix.h).
|
18
|
+
* This way you can avoid symbol table conflicts with other libraries
|
19
|
+
* that also happen to use BinReloc.
|
20
|
+
*
|
21
|
+
* Example:
|
22
|
+
* #define BR_NAMESPACE(funcName) foobar_ ## funcName
|
23
|
+
* --> expands br_locate to foobar_br_locate
|
24
|
+
*/
|
25
|
+
|
26
|
+
#ifndef _PREFIX_C_
|
27
|
+
#define _PREFIX_C_
|
28
|
+
|
29
|
+
#ifdef HAVE_CONFIG_H
|
30
|
+
#include "config.h"
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#ifndef BR_PTHREADS
|
34
|
+
/* Change 1 to 0 if you don't want pthread support */
|
35
|
+
#define BR_PTHREADS 1
|
36
|
+
#endif /* BR_PTHREADS */
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include <stdio.h>
|
40
|
+
#include <limits.h>
|
41
|
+
#include <string.h>
|
42
|
+
#include "prefix.h"
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
extern "C" {
|
46
|
+
#endif /* __cplusplus */
|
47
|
+
|
48
|
+
|
49
|
+
#undef NULL
|
50
|
+
#define NULL ((void *) 0)
|
51
|
+
|
52
|
+
#ifdef __GNUC__
|
53
|
+
#define br_return_val_if_fail(expr,val) if (!(expr)) {fprintf (stderr, "** BinReloc (%s): assertion %s failed\n", __PRETTY_FUNCTION__, #expr); return val;}
|
54
|
+
#else
|
55
|
+
#define br_return_val_if_fail(expr,val) if (!(expr)) return val
|
56
|
+
#endif /* __GNUC__ */
|
57
|
+
|
58
|
+
|
59
|
+
static br_locate_fallback_func fallback_func = (br_locate_fallback_func) NULL;
|
60
|
+
static void *fallback_data = NULL;
|
61
|
+
|
62
|
+
|
63
|
+
#ifdef ENABLE_BINRELOC
|
64
|
+
#include <sys/types.h>
|
65
|
+
#include <sys/stat.h>
|
66
|
+
#include <sys/param.h>
|
67
|
+
#include <unistd.h>
|
68
|
+
|
69
|
+
|
70
|
+
/**
|
71
|
+
* br_locate:
|
72
|
+
* symbol: A symbol that belongs to the app/library you want to locate.
|
73
|
+
* Returns: A newly allocated string containing the full path of the
|
74
|
+
* app/library that func belongs to, or NULL on error. This
|
75
|
+
* string should be freed when not when no longer needed.
|
76
|
+
*
|
77
|
+
* Finds out to which application or library symbol belongs, then locate
|
78
|
+
* the full path of that application or library.
|
79
|
+
* Note that symbol cannot be a pointer to a function. That will not work.
|
80
|
+
*
|
81
|
+
* Example:
|
82
|
+
* --> main.c
|
83
|
+
* #include "prefix.h"
|
84
|
+
* #include "libfoo.h"
|
85
|
+
*
|
86
|
+
* int main (int argc, char *argv[]) {
|
87
|
+
* printf ("Full path of this app: %s\n", br_locate (&argc));
|
88
|
+
* libfoo_start ();
|
89
|
+
* return 0;
|
90
|
+
* }
|
91
|
+
*
|
92
|
+
* --> libfoo.c starts here
|
93
|
+
* #include "prefix.h"
|
94
|
+
*
|
95
|
+
* void libfoo_start () {
|
96
|
+
* --> "" is a symbol that belongs to libfoo (because it's called
|
97
|
+
* --> from libfoo_start()); that's why this works.
|
98
|
+
* printf ("libfoo is located in: %s\n", br_locate (""));
|
99
|
+
* }
|
100
|
+
*/
|
101
|
+
char *
|
102
|
+
br_locate (void *symbol)
|
103
|
+
{
|
104
|
+
char line[5000];
|
105
|
+
FILE *f;
|
106
|
+
char *path;
|
107
|
+
|
108
|
+
br_return_val_if_fail (symbol != NULL, NULL);
|
109
|
+
|
110
|
+
f = fopen ("/proc/self/maps", "r");
|
111
|
+
if (!f) {
|
112
|
+
if (fallback_func)
|
113
|
+
return fallback_func(symbol, fallback_data);
|
114
|
+
else
|
115
|
+
return NULL;
|
116
|
+
}
|
117
|
+
|
118
|
+
while (!feof (f))
|
119
|
+
{
|
120
|
+
unsigned long start, end;
|
121
|
+
|
122
|
+
if (!fgets (line, sizeof (line), f))
|
123
|
+
continue;
|
124
|
+
if (!strstr (line, " r-xp ") || !strchr (line, '/'))
|
125
|
+
continue;
|
126
|
+
|
127
|
+
sscanf (line, "%lx-%lx ", &start, &end);
|
128
|
+
if (symbol >= (void *) start && symbol < (void *) end)
|
129
|
+
{
|
130
|
+
char *tmp;
|
131
|
+
size_t len;
|
132
|
+
|
133
|
+
/* Extract the filename; it is always an absolute path */
|
134
|
+
path = strchr (line, '/');
|
135
|
+
|
136
|
+
/* Get rid of the newline */
|
137
|
+
tmp = strrchr (path, '\n');
|
138
|
+
if (tmp) *tmp = 0;
|
139
|
+
|
140
|
+
/* Get rid of "(deleted)" */
|
141
|
+
len = strlen (path);
|
142
|
+
if (len > 10 && strcmp (path + len - 10, " (deleted)") == 0)
|
143
|
+
{
|
144
|
+
tmp = path + len - 10;
|
145
|
+
*tmp = 0;
|
146
|
+
}
|
147
|
+
|
148
|
+
fclose(f);
|
149
|
+
return strdup (path);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
fclose (f);
|
154
|
+
return NULL;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
/**
|
159
|
+
* br_locate_prefix:
|
160
|
+
* symbol: A symbol that belongs to the app/library you want to locate.
|
161
|
+
* Returns: A prefix. This string should be freed when no longer needed.
|
162
|
+
*
|
163
|
+
* Locates the full path of the app/library that symbol belongs to, and return
|
164
|
+
* the prefix of that path, or NULL on error.
|
165
|
+
* Note that symbol cannot be a pointer to a function. That will not work.
|
166
|
+
*
|
167
|
+
* Example:
|
168
|
+
* --> This application is located in /usr/bin/foo
|
169
|
+
* br_locate_prefix (&argc); --> returns: "/usr"
|
170
|
+
*/
|
171
|
+
char *
|
172
|
+
br_locate_prefix (void *symbol)
|
173
|
+
{
|
174
|
+
char *path, *prefix;
|
175
|
+
|
176
|
+
br_return_val_if_fail (symbol != NULL, NULL);
|
177
|
+
|
178
|
+
path = br_locate (symbol);
|
179
|
+
if (!path) return NULL;
|
180
|
+
|
181
|
+
prefix = br_extract_prefix (path);
|
182
|
+
free (path);
|
183
|
+
return prefix;
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
/**
|
188
|
+
* br_prepend_prefix:
|
189
|
+
* symbol: A symbol that belongs to the app/library you want to locate.
|
190
|
+
* path: The path that you want to prepend the prefix to.
|
191
|
+
* Returns: The new path, or NULL on error. This string should be freed when no
|
192
|
+
* longer needed.
|
193
|
+
*
|
194
|
+
* Gets the prefix of the app/library that symbol belongs to. Prepend that prefix to path.
|
195
|
+
* Note that symbol cannot be a pointer to a function. That will not work.
|
196
|
+
*
|
197
|
+
* Example:
|
198
|
+
* --> The application is /usr/bin/foo
|
199
|
+
* br_prepend_prefix (&argc, "/share/foo/data.png"); --> Returns "/usr/share/foo/data.png"
|
200
|
+
*/
|
201
|
+
char *
|
202
|
+
br_prepend_prefix (void *symbol, char *path)
|
203
|
+
{
|
204
|
+
char *tmp, *newpath;
|
205
|
+
|
206
|
+
br_return_val_if_fail (symbol != NULL, NULL);
|
207
|
+
br_return_val_if_fail (path != NULL, NULL);
|
208
|
+
|
209
|
+
tmp = br_locate_prefix (symbol);
|
210
|
+
if (!tmp) return NULL;
|
211
|
+
|
212
|
+
if (strcmp (tmp, "/") == 0)
|
213
|
+
newpath = strdup (path);
|
214
|
+
else
|
215
|
+
newpath = br_strcat (tmp, path);
|
216
|
+
|
217
|
+
/* Get rid of compiler warning ("br_prepend_prefix never used") */
|
218
|
+
if (0) br_prepend_prefix (NULL, NULL);
|
219
|
+
|
220
|
+
free (tmp);
|
221
|
+
return newpath;
|
222
|
+
}
|
223
|
+
|
224
|
+
#endif /* ENABLE_BINRELOC */
|
225
|
+
|
226
|
+
|
227
|
+
/* Pthread stuff for thread safetiness */
|
228
|
+
#if BR_PTHREADS && defined(ENABLE_BINRELOC)
|
229
|
+
|
230
|
+
#include <pthread.h>
|
231
|
+
|
232
|
+
static pthread_key_t br_thread_key;
|
233
|
+
static pthread_once_t br_thread_key_once = PTHREAD_ONCE_INIT;
|
234
|
+
|
235
|
+
|
236
|
+
static void
|
237
|
+
br_thread_local_store_fini ()
|
238
|
+
{
|
239
|
+
char *specific;
|
240
|
+
|
241
|
+
specific = (char *) pthread_getspecific (br_thread_key);
|
242
|
+
if (specific)
|
243
|
+
{
|
244
|
+
free (specific);
|
245
|
+
pthread_setspecific (br_thread_key, NULL);
|
246
|
+
}
|
247
|
+
pthread_key_delete (br_thread_key);
|
248
|
+
br_thread_key = 0;
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
static void
|
253
|
+
br_str_free (void *str)
|
254
|
+
{
|
255
|
+
if (str)
|
256
|
+
free (str);
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
static void
|
261
|
+
br_thread_local_store_init ()
|
262
|
+
{
|
263
|
+
if (pthread_key_create (&br_thread_key, br_str_free) == 0)
|
264
|
+
atexit (br_thread_local_store_fini);
|
265
|
+
}
|
266
|
+
|
267
|
+
#else /* BR_PTHREADS */
|
268
|
+
#ifdef ENABLE_BINRELOC
|
269
|
+
|
270
|
+
static char *br_last_value = (char *) NULL;
|
271
|
+
|
272
|
+
static void
|
273
|
+
br_free_last_value ()
|
274
|
+
{
|
275
|
+
if (br_last_value)
|
276
|
+
free (br_last_value);
|
277
|
+
}
|
278
|
+
|
279
|
+
#endif /* ENABLE_BINRELOC */
|
280
|
+
#endif /* BR_PTHREADS */
|
281
|
+
|
282
|
+
|
283
|
+
#ifdef ENABLE_BINRELOC
|
284
|
+
|
285
|
+
/**
|
286
|
+
* br_thread_local_store:
|
287
|
+
* str: A dynamically allocated string.
|
288
|
+
* Returns: str. This return value must not be freed.
|
289
|
+
*
|
290
|
+
* Store str in a thread-local variable and return str. The next
|
291
|
+
* you run this function, that variable is freed too.
|
292
|
+
* This function is created so you don't have to worry about freeing
|
293
|
+
* strings. Just be careful about doing this sort of thing:
|
294
|
+
*
|
295
|
+
* some_function( BR_DATADIR("/one.png"), BR_DATADIR("/two.png") )
|
296
|
+
*
|
297
|
+
* Examples:
|
298
|
+
* char *foo;
|
299
|
+
* foo = br_thread_local_store (strdup ("hello")); --> foo == "hello"
|
300
|
+
* foo = br_thread_local_store (strdup ("world")); --> foo == "world"; "hello" is now freed.
|
301
|
+
*/
|
302
|
+
const char *
|
303
|
+
br_thread_local_store (char *str)
|
304
|
+
{
|
305
|
+
#if BR_PTHREADS
|
306
|
+
char *specific;
|
307
|
+
|
308
|
+
pthread_once (&br_thread_key_once, br_thread_local_store_init);
|
309
|
+
|
310
|
+
specific = (char *) pthread_getspecific (br_thread_key);
|
311
|
+
br_str_free (specific);
|
312
|
+
pthread_setspecific (br_thread_key, str);
|
313
|
+
|
314
|
+
#else /* BR_PTHREADS */
|
315
|
+
static int initialized = 0;
|
316
|
+
|
317
|
+
if (!initialized)
|
318
|
+
{
|
319
|
+
atexit (br_free_last_value);
|
320
|
+
initialized = 1;
|
321
|
+
}
|
322
|
+
|
323
|
+
if (br_last_value)
|
324
|
+
free (br_last_value);
|
325
|
+
br_last_value = str;
|
326
|
+
#endif /* BR_PTHREADS */
|
327
|
+
|
328
|
+
return (const char *) str;
|
329
|
+
}
|
330
|
+
|
331
|
+
#endif /* ENABLE_BINRELOC */
|
332
|
+
|
333
|
+
|
334
|
+
/**
|
335
|
+
* br_strcat:
|
336
|
+
* str1: A string.
|
337
|
+
* str2: Another string.
|
338
|
+
* Returns: A newly-allocated string. This string should be freed when no longer needed.
|
339
|
+
*
|
340
|
+
* Concatenate str1 and str2 to a newly allocated string.
|
341
|
+
*/
|
342
|
+
char *
|
343
|
+
br_strcat (const char *str1, const char *str2)
|
344
|
+
{
|
345
|
+
char *result;
|
346
|
+
size_t len1, len2;
|
347
|
+
|
348
|
+
if (!str1) str1 = "";
|
349
|
+
if (!str2) str2 = "";
|
350
|
+
|
351
|
+
len1 = strlen (str1);
|
352
|
+
len2 = strlen (str2);
|
353
|
+
|
354
|
+
result = (char *) malloc (len1 + len2 + 1);
|
355
|
+
memcpy (result, str1, len1);
|
356
|
+
memcpy (result + len1, str2, len2);
|
357
|
+
result[len1 + len2] = '\0';
|
358
|
+
|
359
|
+
return result;
|
360
|
+
}
|
361
|
+
|
362
|
+
|
363
|
+
/* Emulates glibc's strndup() */
|
364
|
+
static char *
|
365
|
+
br_strndup (char *str, size_t size)
|
366
|
+
{
|
367
|
+
char *result = (char *) NULL;
|
368
|
+
size_t len;
|
369
|
+
|
370
|
+
br_return_val_if_fail (str != (char *) NULL, (char *) NULL);
|
371
|
+
|
372
|
+
len = strlen (str);
|
373
|
+
if (!len) return strdup ("");
|
374
|
+
if (size > len) size = len;
|
375
|
+
|
376
|
+
result = (char *) calloc (sizeof (char), len + 1);
|
377
|
+
memcpy (result, str, size);
|
378
|
+
return result;
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
/**
|
383
|
+
* br_extract_dir:
|
384
|
+
* path: A path.
|
385
|
+
* Returns: A directory name. This string should be freed when no longer needed.
|
386
|
+
*
|
387
|
+
* Extracts the directory component of path. Similar to g_dirname() or the dirname
|
388
|
+
* commandline application.
|
389
|
+
*
|
390
|
+
* Example:
|
391
|
+
* br_extract_dir ("/usr/local/foobar"); --> Returns: "/usr/local"
|
392
|
+
*/
|
393
|
+
char *
|
394
|
+
br_extract_dir (const char *path)
|
395
|
+
{
|
396
|
+
char *end, *result;
|
397
|
+
|
398
|
+
br_return_val_if_fail (path != (char *) NULL, (char *) NULL);
|
399
|
+
|
400
|
+
end = strrchr (path, '/');
|
401
|
+
if (!end) return strdup (".");
|
402
|
+
|
403
|
+
while (end > path && *end == '/')
|
404
|
+
end--;
|
405
|
+
result = br_strndup ((char *) path, end - path + 1);
|
406
|
+
if (!*result)
|
407
|
+
{
|
408
|
+
free (result);
|
409
|
+
return strdup ("/");
|
410
|
+
} else
|
411
|
+
return result;
|
412
|
+
}
|
413
|
+
|
414
|
+
|
415
|
+
/**
|
416
|
+
* br_extract_prefix:
|
417
|
+
* path: The full path of an executable or library.
|
418
|
+
* Returns: The prefix, or NULL on error. This string should be freed when no longer needed.
|
419
|
+
*
|
420
|
+
* Extracts the prefix from path. This function assumes that your executable
|
421
|
+
* or library is installed in an LSB-compatible directory structure.
|
422
|
+
*
|
423
|
+
* Example:
|
424
|
+
* br_extract_prefix ("/usr/bin/gnome-panel"); --> Returns "/usr"
|
425
|
+
* br_extract_prefix ("/usr/local/lib/libfoo.so"); --> Returns "/usr/local"
|
426
|
+
* br_extract_prefix ("/usr/local/libfoo.so"); --> Returns "/usr"
|
427
|
+
*/
|
428
|
+
char *
|
429
|
+
br_extract_prefix (const char *path)
|
430
|
+
{
|
431
|
+
char *end, *tmp, *result;
|
432
|
+
|
433
|
+
br_return_val_if_fail (path != (char *) NULL, (char *) NULL);
|
434
|
+
|
435
|
+
if (!*path) return strdup ("/");
|
436
|
+
end = strrchr (path, '/');
|
437
|
+
if (!end) return strdup (path);
|
438
|
+
|
439
|
+
tmp = br_strndup ((char *) path, end - path);
|
440
|
+
if (!*tmp)
|
441
|
+
{
|
442
|
+
free (tmp);
|
443
|
+
return strdup ("/");
|
444
|
+
}
|
445
|
+
end = strrchr (tmp, '/');
|
446
|
+
if (!end) return tmp;
|
447
|
+
|
448
|
+
result = br_strndup (tmp, end - tmp);
|
449
|
+
free (tmp);
|
450
|
+
|
451
|
+
if (!*result)
|
452
|
+
{
|
453
|
+
free (result);
|
454
|
+
result = strdup ("/");
|
455
|
+
}
|
456
|
+
|
457
|
+
return result;
|
458
|
+
}
|
459
|
+
|
460
|
+
|
461
|
+
/**
|
462
|
+
* br_set_fallback_function:
|
463
|
+
* func: A function to call to find the binary.
|
464
|
+
* data: User data to pass to func.
|
465
|
+
*
|
466
|
+
* Sets a function to call to find the path to the binary, in
|
467
|
+
* case "/proc/self/maps" can't be opened. The function set should
|
468
|
+
* return a string that is safe to free with free().
|
469
|
+
*/
|
470
|
+
void
|
471
|
+
br_set_locate_fallback_func (br_locate_fallback_func func, void *data)
|
472
|
+
{
|
473
|
+
fallback_func = func;
|
474
|
+
fallback_data = data;
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
#ifdef __cplusplus
|
479
|
+
}
|
480
|
+
#endif /* __cplusplus */
|
481
|
+
|
482
|
+
#endif /* _PREFIX_C */
|