(%.tab): Fix previous change.
[m17n/m17n-db.git] / m17n-db.in
1 #!/bin/sh
2 # m17n-db -- print information about the m17n database.
3 # Copyright (C) 2004, 2005
4 #   National Institute of Advanced Industrial Science and Technology (AIST)
5 #   Registration Number H15PRO112
6 # See the end for copying conditions.
7
8 prefix=@prefix@
9 datadir=@datadir@
10
11 help ()
12 {
13     echo "Usage: $0 [ OPTIONS ] [ TAG0 [ TAG1 [ TAG2 [ TAG3 ] ] ] ]"
14     echo "Options:"
15     echo "  -h, --help  Print this information."
16     echo "  -v, --version       Print the version number."
17     echo "  -l, --locate        Print absolute pathnames of database files."
18     echo "      TAG0 through TAG3 specifies the tags of the database."
19     echo "With no options, print the installed directory name."
20 }
21
22 if test $# -gt 0; then
23     case "$1" in
24         -h | --help) help; exit 0;;
25         -v | --version) echo "@VERSION@"; exit 0;;
26         -l | --locate) DIRFILE="$datadir/m17n/mdb.dir"; shift;;
27         *) help; exit 1;;
28     esac
29 fi
30
31 if test -z "$DIRFILE" ; then
32     echo $datadir/m17n
33     exit 0
34 fi
35
36 if test ! -f "$DIRFILE"; then
37     echo "Can't find the m17n database directory file \"$DIRFILE\"!"
38     exit 1
39 fi
40
41 if test -z "$1"; then
42     help
43     exit 1
44 fi
45
46 TAG0=$1
47 TAG1=$2
48 if test -z "$TAG1"; then
49     TAG1="*"
50 fi
51 TAG2=$3
52 if test -z "$TAG2"; then
53     TAG2="*"
54 fi
55 TAG3=$4
56 if test -z "$TAG3"; then
57     TAG3="*"
58 fi
59
60 SPC="[  ]*"
61 ANY="$SPC\([A-Za-z*][^  )]*\)\?"
62
63 TAGS="$SPC\($TAG0\)$SPC$ANY$SPC$ANY$SPC$ANY"
64 FILE="$SPC\"\([^\"]*\)\""
65 ENTRIES=`sed -n "/$TAG0/s|$SPC($TAGS$FILE).*$|/\1/\2/\3/\4/\5|p" $DIRFILE`
66
67 cd $datadir/m17n
68
69 for e in $ENTRIES; do
70     FN=`expr "$e" : "/[^/]*/[^/]*/[^/]*/[^/]*/\(.*\)"`
71     case "$e" in
72         /$TAG0/\*/*/* | /$TAG0/*/\*/* | /$TAG0/*/*/\*)
73             for f in $FN; do
74                 if test -f $f; then
75                     ENTRY=`sed -n "/$TAG0/s|$SPC($TAGS).*$|/\1/\2/\3/\4|p" $f`
76                     if test -n "$ENTRY"; then
77                         LIST="$LIST $ENTRY/$f"
78                     fi
79                 fi
80             done;;
81         *)
82             if test -f $FN; then
83                 LIST="$LIST $e"
84             fi;;
85     esac
86 done
87
88 for l in $LIST; do
89     case "$l" in
90         /$TAG0/$TAG1/$TAG2/$TAG3)
91             FN=`expr "$l" : "/[^/]*/[^/]*/[^/]*/[^/]*/\(.*\)"`
92             echo "`pwd`/$FN"
93     esac
94 done
95
96 exit 0
97
98 cat > /dev/null <<EOF
99 /***en @page m17n-db Print information about the m17n database */
100 /***ja @page m17n-db m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¾ðÊó¤òɽ¼¨ */
101
102 /***
103 @section m17n-db-synopsis SYNOPSIS
104
105 m17n-db  [ OPTIONS ] [ TAG0 [ TAG1 [ TAG2 [ TAG3 ] ] ] ]
106
107 @section m17n-db-description DESCRIPTION
108
109 The shell script m17n-db prints information about the m17n database.
110
111 The arguments OPTIONS has the following meanings.
112
113 - -h, --help\n
114         Print this information.
115 - -v, --version\n
116         Print the version number.
117 - -l, --locate\n
118         Print absolute pathnames of database files.\n
119         TAG0 through TAG3 specifies the tags of the database.
120
121 With no arguments, print where the m17n database is installed.  */ 
122 EOF
123
124 # Copyright (C) 2004
125 #   National Institute of Advanced Industrial Science and Technology (AIST)
126 #   Registration Number H15PRO112
127
128 # This file is part of the m17n database; a sub-part of the m17n
129 # library.
130
131 # The m17n library is free software; you can redistribute it and/or
132 # modify it under the terms of the GNU Lesser General Public License
133 # as published by the Free Software Foundation; either version 2.1 of
134 # the License, or (at your option) any later version.
135
136 # The m17n library is distributed in the hope that it will be useful,
137 # but WITHOUT ANY WARRANTY; without even the implied warranty of
138 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139 # Lesser General Public License for more details.
140
141 # You should have received a copy of the GNU Lesser General Public
142 # License along with the m17n library; if not, write to the Free
143 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
144 # Boston, MA 02110-1301, USA.
145
146 # Local Variables:
147 # coding: euc-japan
148 # End: