author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /scripts/q_add_variable | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
-rwxr-xr-x | scripts/q_add_variable | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/q_add_variable b/scripts/q_add_variable new file mode 100755 index 0000000..e35b8de --- a/dev/null +++ b/scripts/q_add_variable | |||
@@ -0,0 +1,70 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Script to add a new function to an existing class | ||
4 | # | ||
5 | # Copyright 1999-2000 Trolltech AS. All rights reserved. | ||
6 | # | ||
7 | |||
8 | |||
9 | # load the helper functions | ||
10 | . q_functions | ||
11 | |||
12 | |||
13 | if [ $# -lt 3 ] | ||
14 | then | ||
15 | echo "Usage: q_add_variable AccessModifier: Type ExistingClassName::NewVariableName" | ||
16 | print_example_usage | ||
17 | exit | ||
18 | fi | ||
19 | |||
20 | |||
21 | ACCESS_MODIFIER=$1 | ||
22 | TYPE=$2 | ||
23 | EXISTING_CLASS_NAME=`echo $3 | cut -d ":" -f 1` | ||
24 | NEW_VARIABLE_NAME=`echo $3 | cut -d ":" -f 3` | ||
25 | |||
26 | |||
27 | EXISTING_CLASS_NAME_LOWER=`echo $EXISTING_CLASS_NAME | tr "[A-Z]" "[a-z]"` | ||
28 | EXISTING_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h | ||
29 | ORIGINAL_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h.orig | ||
30 | |||
31 | |||
32 | function print_variable_definition | ||
33 | { | ||
34 | cat << END | ||
35 | $ACCESS_MODIFIER | ||
36 | $TYPE $NEW_VARIABLE_NAME; | ||
37 | END | ||
38 | } | ||
39 | |||
40 | |||
41 | function print_new_header_file | ||
42 | { | ||
43 | get_number_of_lines | ||
44 | get_first_line_of_class_definition | ||
45 | if [ -z "$LINE" ] | ||
46 | then | ||
47 | cat << END | ||
48 | /* | ||
49 | No good, can't find $EXISTING_CLASS_NAME class definition anywhere. | ||
50 | You'll have to manually edit the header file to add the | ||
51 | following variable definition to the $EXISTING_CLASS_NAME class: | ||
52 | |||
53 | END | ||
54 | print_variable_definition | ||
55 | echo -e "\n*/" | ||
56 | cat $ORIGINAL_CLASS_HEADER_FILE | ||
57 | else | ||
58 | head -n $LINE $ORIGINAL_CLASS_HEADER_FILE | ||
59 | print_variable_definition | ||
60 | tail -n `expr $LINES - $LINE` $ORIGINAL_CLASS_HEADER_FILE | ||
61 | fi | ||
62 | } | ||
63 | |||
64 | |||
65 | [ -f $EXISTING_CLASS_HEADER_FILE ] || { echo "file $EXISTING_CLASS_HEADER_FILE not found" ; exit ; } | ||
66 | # Backup file | ||
67 | mv $EXISTING_CLASS_HEADER_FILE $ORIGINAL_CLASS_HEADER_FILE | ||
68 | print_new_header_file >> $EXISTING_CLASS_HEADER_FILE | ||
69 | |||
70 | |||