Fix up some more svn properties.
[metze/wireshark/wip.git] / tools / idl2wrs
1 #!/bin/sh
2 #
3 #  $Id$
4 #
5 #  File : idl2wrs          
6 #
7 #  Author : Frank Singleton (frank.singleton@ericsson.com)
8 #
9 #  Copyright (C) 2001 Frank Singleton, Ericsson Inc.
10 #
11 #  This file is a simple shell script wrapper for the IDL to 
12 #  Wireshark dissector code.
13 #
14 #  ie: wireshark_be.py and wireshark_gen.py
15 #
16 #  This file is used to generate "Wireshark" dissectors from IDL descriptions. 
17 #  The output language generated is "C". It will generate code to use the 
18 #  GIOP/IIOP get_CDR_XXX API.
19 #
20 #  Please see packet-giop.h in Wireshark distro for API description.
21 #  Wireshark is available at http://www.wireshark.org/
22 #
23 #  Omniidl is part of the OmniOrb distribution, and is available at
24 #  http://omniorb.sourceforge.net/
25 #
26 #  This program is free software; you can redistribute it and/or modify it
27 #  under the terms of the GNU General Public License as published by
28 #  the Free Software Foundation; either version 2 of the License, or
29 #  (at your option) any later version.
30 #
31 #  This program is distributed in the hope that it will be useful,
32 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
33 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34 #  General Public License for more details.
35 #
36 #  You should have received a copy of the GNU General Public License
37 #  along with this program; if not, write to the Free Software
38 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
39 #  02111-1307, USA.
40 #
41
42
43 #  Must at least supply an IDL file
44
45 if [ $# -lt 1 ]; then
46     echo "idl2wrs Error: no IDL file specified."
47     echo "Usage: idl2wrs idl_file_name"
48     exit 1;
49 fi
50
51 # Check the file name for valid characters.
52 # Implementation based on Dave Taylor's validalnum shell script from his book,
53 # "Wicked Cool Shell Scripts", as well as Mark Rushakoff's answer he provided
54 # to the question posted at stackoverflow.com entitled, "How can I use the
55 # UNIX shell to count the number of times a letter appears in a text file?"
56 file=$(basename $1)
57 compressed="$(echo $file | sed 's/[^[:alnum:]._]//g')"
58 if [ "$compressed" != "$file" ]; then
59     echo "idl2wrs Error: Invalid file name: $file"
60     exit 1;
61 fi
62
63 # Only allow one '.' at most.
64 count=$(echo $compressed | awk -F. '{c += NF - 1} END {print c}')
65 if [ $count -gt 1 ] ; then
66     echo "idl2wrs Error: Invalid file name: $file"
67     exit 1;
68 fi
69
70 #
71 # Run wireshark backend, looking for wireshark_be.py and wireshark_gen.py
72 # in pythons's "site-packages" directory. If cannot find that, then
73 # try looking in current directory. If still cannot, then exit with
74 # error.
75
76 if [ -f $PYTHONPATH/site-packages/wireshark_be.py ] && [ -f $PYTHONPATH/site-packages/wireshark_gen.py ]; then
77     exec omniidl  -p $PYTHONPATH/site-packages -b wireshark_be $@
78     /* not reached */
79 fi
80
81 # Try current directory.
82
83 if [ -f ./wireshark_be.py ] && [ -f ./wireshark_gen.py ]; then
84     exec omniidl  -p ./ -b wireshark_be $@
85     /* not reached */
86 fi
87
88 # Could not find both wireshark_be.py AND wireshark_gen.py
89 # So let's just try to run it without -p, hoping that the installation
90 # set up a valid path.
91
92 exec omniidl -b wireshark_be $@
93
94 old code: not reached
95
96 echo "idl2wrs Error: Could not find both wireshark_be.py AND wireshark_gen.py."
97 echo "Please ensure you have the PYTHONPATH variable set, or that wireshark_be.py "
98 echo "and wireshark_gen.py exist in the current directory. "
99 echo
100 echo "On this system, PYTHONPATH is : $PYTHONPATH"
101 echo
102
103 exit 2
104
105
106