summaryrefslogtreecommitdiff
path: root/scripts/q_add_function
blob: cc14db70dd0625b766632adebac4f0fd9b9cb00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# Script to add a new function to an existing class
#
# Copyright 1999-2000 Trolltech AS.  All rights reserved.
#


# load the helper functions
. q_functions


if [ $# -lt 4 ]
then
echo "Usage: q_add_function AccessModifier RetType ExistingClassName NewFunctionName ArgList"
print_example_usage
exit
fi


ACCESS_MODIFIER=$1
RET_TYPE=$2
EXISTING_CLASS_NAME=`echo $3 | cut -d ":" -f 1`
NEW_FUNCTION_NAME=`echo $3 | cut -d ":" -f 3`
ARG_LIST=$4


EXISTING_CLASS_NAME_LOWER=`echo $EXISTING_CLASS_NAME | tr "[A-Z]" "[a-z]"`
EXISTING_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h
EXISTING_CLASS_SOURCE_FILE="$EXISTING_CLASS_NAME_LOWER".cpp
ORIGINAL_CLASS_HEADER_FILE="$EXISTING_CLASS_NAME_LOWER".h.orig


function print_source_file
{
cat << END


$RET_TYPE $EXISTING_CLASS_NAME::$NEW_FUNCTION_NAME$ARG_LIST
{
}
END
}


function print_function_definition
{
cat << END
$ACCESS_MODIFIER
    $RET_TYPE $NEW_FUNCTION_NAME$ARG_LIST;
END
}


function print_new_header_file
{
get_number_of_lines
get_first_line_of_class_definition
if [ -z "$LINE" ]
then
cat << END
/*
    No good, can't find $EXISTING_CLASS_NAME class definition anywhere.
    You'll have to manually edit the header file to add the
    following function definition to the $EXISTING_CLASS_NAME class:

END
print_function_definition
echo -e "\n*/"
cat $ORIGINAL_CLASS_HEADER_FILE
else
head -n $LINE $ORIGINAL_CLASS_HEADER_FILE
print_function_definition
tail -n `expr $LINES - $LINE` $ORIGINAL_CLASS_HEADER_FILE
fi
}


[ -f $EXISTING_CLASS_HEADER_FILE ] || { echo "file $EXISTING_CLASS_HEADER_FILE not found" ; exit ; }

# Backup file
mv $EXISTING_CLASS_HEADER_FILE $ORIGINAL_CLASS_HEADER_FILE


print_source_file     >> $EXISTING_CLASS_SOURCE_FILE
print_new_header_file >> $EXISTING_CLASS_HEADER_FILE