1#!/usr/bin/perl
2
3#============================================================================
4#
5#   File : gensrc.pl
6#   Creation date : Sun 17 Dec 2006 20:36:07 by Szymon Stefanek
7#
8#   This file is part of the KVIrc IRC Client distribution
9#   Copyright (C) 2000-2009 Szymon Stefanek <pragma at kvirc dot net>
10#
11#   This program is FREE software. You can redistribute it and/or
12#   modify it under the terms of the GNU General Public License
13#   as published by the Free Software Foundation; either version 2
14#   of the License, or (at your option) any later version.
15#
16#   This program is distributed in the HOPE that it will be USEFUL,
17#   but WITHOUT ANY WARRANTY; without even the implied warranty of
18#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19#   See the GNU General Public License for more details.
20#
21#   You should have received a copy of the GNU General Public License
22#   along with this program. If not, write to the Free Software Foundation,
23#   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24#
25#============================================================================
26
27$name = $ARGV[0];
28
29if($name eq "")
30{
31	print "Usage: gensrc <filename>\n";
32	exit;
33}
34
35$bIsHeader = 0;
36$ifdefname = $name;
37$ifdefname =~ tr/a-z/A-Z/;
38$ifdefname =~ s/\./_/;
39$ifdefname = "_$ifdefname\_";
40
41if(open(THEFILE,">$name"))
42{
43	$_ = $name;
44	if(/[A-Za-z_]*.h/)
45	{
46		$bIsHeader = 1;
47	}
48
49
50	if($bIsHeader)
51	{
52		print THEFILE "#ifndef $ifdefname\n";
53		print THEFILE "#define $ifdefname\n";
54	}
55
56	$thetime = gmtime;
57
58	print THEFILE "//\n";
59	print THEFILE "//   File : $name\n";
60	print THEFILE "//   Creation date : $thetime GMT by Szymon Stefanek\n";
61	print THEFILE "//\n";
62	print THEFILE "//   This file is part of the KVIrc IRC client distribution\n";
63	print THEFILE "//   Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net)\n";
64	print THEFILE "//\n";
65	print THEFILE "//   This program is FREE software. You can redistribute it and/or\n";
66	print THEFILE "//   modify it under the terms of the GNU General Public License\n";
67	print THEFILE "//   as published by the Free Software Foundation; either version 2\n";
68	print THEFILE "//   of the License, or (at your option) any later version.\n";
69	print THEFILE "//\n";
70	print THEFILE "//   This program is distributed in the HOPE that it will be USEFUL,\n";
71	print THEFILE "//   but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
72	print THEFILE "//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
73	print THEFILE "//   See the GNU General Public License for more details.\n";
74	print THEFILE "//\n";
75	print THEFILE "//   You should have received a copy of the GNU General Public License\n";
76	print THEFILE "//   along with this program. If not, write to the Free Software Foundation,\n";
77	print THEFILE "//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n";
78	print THEFILE "//\n";
79	print THEFILE "\n";
80
81	if($bIsHeader)
82	{
83		print THEFILE "\n";
84		print THEFILE "#endif //$ifdefname\n";
85	}
86
87	close(THEFILE);
88} else {
89	print "No way to open the file $name\n";
90}
91