-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate
More file actions
114 lines (104 loc) · 3.23 KB
/
create
File metadata and controls
114 lines (104 loc) · 3.23 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
#
# File Name: create
#
# Date: 2013-07-30
# Author: Asis Kumar Patra
# Purpose: C, CPP, JAVA, SH etc. file creator.
#
#
if [ $# -ne 1 ] ; then
# echo "Usage: '$0 file-name'"
# echo "Usage: 'create <file-name>'"
echo "Usage: '`echo $0 | sed 's/.*\///'` <file-name>'"
exit 1
fi
if [ -e $1 ] ; then
echo "Error: '$1' already exists!"
echo -n "Do you want to continue(y/n)? "
read yn
if [ "$yn" != "y" -a "$yn" != "Y" ] ; then
exit 2
fi
fi
# FL_N: File Name
# P : File Path
# F_L : First Line
# L_L : Last Line
# L_S : Line Start
# P_C : Program Code
# F_N : File Name
# D : Date
# A : Author
# P : Purpose
# c_n : Class Name for java
# s_f : Shell Script Flag
# O_F_N : Only File Name
FL_N=`echo $1 | sed 's/.*\///'`
P=`echo $1 | sed 's/\/[^\/]*$//'`
case $FL_N in
*.h) F_L="/*"
L_S=" * "
L_L=" */"
TEMP=`echo $FL_N | tr '.[a-z]' '_[A-Z]'`
O_F_N=${FL_N%.*}
P_C="#ifndef _${TEMP}\n#define _${TEMP}\n\n#include <stdio.h>\n#include <iostream>\n\nusing namespace std;\n\n/*\nclass $O_F_N\n{\nprivate:\npublic:\n};\n*/\n\n#endif"
;;
*.c) F_L="/*"
L_S=" * "
L_L=" */"
O_F_N=${FL_N%.*}
P_C="#include <stdio.h>\n\n/* #include \"$O_F_N.h\" */\n\nint main(int argc, char** argv) {\n\t/* Write your program code here. */\n\t\n\treturn 0;\n}\n"
;;
*.cpp) F_L="//"
L_S="// "
L_L="//"
O_F_N=${FL_N%.*}
P_C="#include <iostream>\n\nusing namespace std;\n\n// #include \"$O_F_N.h\"\n\nint main(int argc, char** argv) {\n\t// Write your program code here. \n\t\n\treturn 0;\n}\n"
;;
*.pc) F_L="//"
L_S="// "
L_L="//"
P_C="#include <iostream>\n#include <cstdlib>\n\nusing namespace std;\n\n#include <sqlca.h>\n\nint main(int argc, char** argv) { \n\t\n\tEXEC SQL BEGIN DECLARE SECTION;\n\t\tchar h_username[]=\"\";//\"H11OraUser5D@unixdb\";\n\t\tchar h_password[]=\"\";//\"tcshyd\";\n\tEXEC SQL END DECLARE SECTION;\n\tEXEC SQL CONNECT :h_username IDENTIFIED BY :h_password;\n\tint l_connectionStatus = sqlca.sqlcode;\n\tif(l_connectionStatus != 0) {\n\t\tcerr<<\"Error \"<<l_connectionStatus<<\": Database connection failed!\"<<endl;\n\t\texit(1);\n\t}\n\t// Write your program code here. \n\t\n\t\n\tEXEC SQL COMMIT WORK RELEASE;\n\treturn 0;\n}\n"
;;
*.java) F_L="/*"
L_S=" * "
L_L=" */"
c_n=$(echo $FL_N | cut -d "." -f1)
P_C="class $c_n {\n\tpublic static void main(String[] args) {\n\t\t// Write your program code here. \n\t\t\n\t}\n}\n"
;;
*.py) F_L="#!/usr/bin/python\n\n#"
L_S="# "
L_L="#"
P_C="# Write your python code here. \n"
s_f="y"
;;
*.pl) F_L="#!/usr/bin/perl\n\n#"
L_S="# "
L_L="#"
P_C="use strict; \nuse warnings; \nuse diagnostics; \n\n# Write your perl script here. \n"
;;
*.sh) F_L="#!/bin/bash\n\n#"
L_S="# "
L_L="#"
P_C="# Write your shell script here. \n"
;;
*) read -p "Is '$1' Shell Script (Y/N)? " s_f
if [ -z "$s_f" -o "$s_f" != "Y" -a "$s_f" != "y" ] ; then
echo "Error: wrong entry!!!" ; exit 2
else
F_L="#!/bin/bash\n\n#"
L_S="# "
L_L="#"
P_C="# Write your shell script here. \n"
fi
esac
F_N="File Name: $FL_N"
#D="Date: $(date +%F)"
D="Date: $(date '+%B %d, %Y')"
A="Author: Asis Kumar Patra"
P="Purpose: "
echo -e "$F_L\n$L_S$F_N\n$L_S\n$L_S$D\n$L_S$A\n$L_S$P\n$L_S\n$L_L\n\n$P_C" > $1
if [ ! -z "$s_f" ] ; then
chmod u+x $1
fi