summaryrefslogtreecommitdiff
path: root/scripts/q_add_variable
Unidiff
Diffstat (limited to 'scripts/q_add_variable') (more/less context) (show whitespace changes)
-rwxr-xr-xscripts/q_add_variable70
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
13if [ $# -lt 3 ]
14then
15echo "Usage: q_add_variable AccessModifier: Type ExistingClassName::NewVariableName"
16print_example_usage
17exit
18fi
19
20
21ACCESS_MODIFIER=$1
22TYPE=$2
23EXISTING_CLASS_NAME=`echo $3 | cut -d ":" -f 1`
24NEW_VARIABLE_NAME=`echo $3 | cut -d ":" -f 3`
25
26
27EXISTING_CLASS_NAME_LOWER=`echo $EXISTING_CLASS_NAME | tr "[A-Z]" "[a-z]"`
28EXISTING_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h
29ORIGINAL_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h.orig
30
31
32function print_variable_definition
33{
34cat << END
35$ACCESS_MODIFIER
36 $TYPE $NEW_VARIABLE_NAME;
37END
38}
39
40
41function print_new_header_file
42{
43get_number_of_lines
44get_first_line_of_class_definition
45if [ -z "$LINE" ]
46then
47cat << 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
53END
54print_variable_definition
55echo -e "\n*/"
56cat $ORIGINAL_CLASS_HEADER_FILE
57else
58head -n $LINE $ORIGINAL_CLASS_HEADER_FILE
59print_variable_definition
60tail -n `expr $LINES - $LINE` $ORIGINAL_CLASS_HEADER_FILE
61fi
62}
63
64
65[ -f $EXISTING_CLASS_HEADER_FILE ] || { echo "file $EXISTING_CLASS_HEADER_FILE not found" ; exit ; }
66# Backup file
67mv $EXISTING_CLASS_HEADER_FILE $ORIGINAL_CLASS_HEADER_FILE
68print_new_header_file >> $EXISTING_CLASS_HEADER_FILE
69
70