summaryrefslogtreecommitdiff
path: root/scripts/q_add_function
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /scripts/q_add_function
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'scripts/q_add_function') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/q_add_function88
1 files changed, 88 insertions, 0 deletions
diff --git a/scripts/q_add_function b/scripts/q_add_function
new file mode 100755
index 0000000..cc14db7
--- a/dev/null
+++ b/scripts/q_add_function
@@ -0,0 +1,88 @@
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 4 ]
14then
15echo "Usage: q_add_function AccessModifier RetType ExistingClassName NewFunctionName ArgList"
16print_example_usage
17exit
18fi
19
20
21ACCESS_MODIFIER=$1
22RET_TYPE=$2
23EXISTING_CLASS_NAME=`echo $3 | cut -d ":" -f 1`
24NEW_FUNCTION_NAME=`echo $3 | cut -d ":" -f 3`
25ARG_LIST=$4
26
27
28EXISTING_CLASS_NAME_LOWER=`echo $EXISTING_CLASS_NAME | tr "[A-Z]" "[a-z]"`
29EXISTING_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h
30EXISTING_CLASS_SOURCE_FILE="$EXISTING_CLASS_NAME_LOWER".cpp
31ORIGINAL_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h.orig
32
33
34function print_source_file
35{
36cat << END
37
38
39$RET_TYPE $EXISTING_CLASS_NAME::$NEW_FUNCTION_NAME$ARG_LIST
40{
41}
42END
43}
44
45
46function print_function_definition
47{
48cat << END
49$ACCESS_MODIFIER
50 $RET_TYPE $NEW_FUNCTION_NAME$ARG_LIST;
51END
52}
53
54
55function print_new_header_file
56{
57get_number_of_lines
58get_first_line_of_class_definition
59if [ -z "$LINE" ]
60then
61cat << END
62/*
63 No good, can't find $EXISTING_CLASS_NAME class definition anywhere.
64 You'll have to manually edit the header file to add the
65 following function definition to the $EXISTING_CLASS_NAME class:
66
67END
68print_function_definition
69echo -e "\n*/"
70cat $ORIGINAL_CLASS_HEADER_FILE
71else
72head -n $LINE $ORIGINAL_CLASS_HEADER_FILE
73print_function_definition
74tail -n `expr $LINES - $LINE` $ORIGINAL_CLASS_HEADER_FILE
75fi
76}
77
78
79[ -f $EXISTING_CLASS_HEADER_FILE ] || { echo "file $EXISTING_CLASS_HEADER_FILE not found" ; exit ; }
80
81# Backup file
82mv $EXISTING_CLASS_HEADER_FILE $ORIGINAL_CLASS_HEADER_FILE
83
84
85print_source_file >> $EXISTING_CLASS_SOURCE_FILE
86print_new_header_file >> $EXISTING_CLASS_HEADER_FILE
87
88