summaryrefslogtreecommitdiffstats
path: root/src/occApplet/createApplet
blob: 784fcaa0483a47f882f0725a469dc9682c70c462 (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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl
#
# Create a new applet source file from a template
#
#
my $template;
my $newfile = 0;
my $typeflag = 0;
my $feature = "";
my $username = $ENV{USER};
# version 2: Added applet id name support.
# version 1: Created this file
my $VERSION = "2";

#template file path
$template = $ENV{SANDBOXBASE} . "/src/occc/405/occApplet/template";

#usage
sub usage() 
{

	print "Usage: $0 -d <short_description_of_file> -f <functionNM> -i <unique applet Id String> <filename> \n";
	print "\n";
	print "-d:   short description for the file\n";
	print "-f:   Entry point function name\n";
	print "-i:   Unique Applet Id string(15 char long and must be unique within applets)\n";
	print "-n:   Applet ID name from the OCC_APLT enumeration for this applet (eg: OCC_APLT_TEST)\n";
	print "-V:   Version\n";
	print "\n\n";

	exit 1;
}

sub createfile(@) 
{
	
	($newfile,$type,$shortDesc,$funcNm,$appIdStr,$appIdNm) = @_;
	
	open TEMPL, "<$template.$type" || die "Unable to open: $template.$type\n";
	open NEWFILE, ">$newfile.$type" || die "Can't open: $newfile.$type\n";

	read TEMPL, $buf, ( -s TEMPL ) || die "Unable to read template $template.$type\n";
	close TEMPL;

	# change the filename,function name, short description, applet id string
	# and applet id
	$upperNewFile = uc($newfile);
	$upperFuncNm = uc($funcNm);
	$buf =~ s/<filename.$type>/$newfile.$type/g;
    $buf =~ s/<FILENAME.$type>/$upperNewFile.$type/g;
    $buf =~ s/<shortDesc>/$shortDesc/g;
    $buf =~ s/<funcNm>/$funcNm/g;
    $buf =~ s/<FUNCNM>/$upperFuncNm/g;
    $buf =~ s/<APPLET_ID_STR>/$appIdStr/g;
    $buf =~ s/<APLT_ID>/$appIdNm/g;
    
	#change creation date
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
	$year = sprintf("%02s", $year % 100);
	$mon  = sprintf("%02s", $mon + 1);
	$mday  = sprintf("%02s", $mday);
	$buf =~ s/MM\/DD\/YY/$mon\/$mday\/$year/;

	#change the userid
	$buf =~ s/USERID/$username/;
	
	#write the file
	print NEWFILE $buf;

	close NEWFILE;

}

while ($ARGV = shift) 
{
   
    if ($ARGV =~ m/-V/) 
    {
        print "$0 version = $VERSION\n\n";
        exit 0;  
    }
    elsif ($ARGV =~ m/-d/i) 
    {
        $desc = shift;
        usage() if  $desc =~ m/(-f|-i)/;
        $shortDesc = $desc;
        $descFound = 1;
   }
   elsif ($ARGV =~ m/-f/i) 
   {
        $func = shift;
        usage() if $func =~ m/(-i)/;
        $funcNm = $func;
   }
   elsif ($ARGV =~ m/-i/i) 
   {
        $appIdStr = shift;
        usage() if ! $appIdStr =~ m/\w+/;
   }
   elsif ($ARGV =~ m/-n/i)
   {
        $appIdNm = shift;
        usage() if ! $appIdNm =~ m/\w+/;
   }
   elsif ($ARGV =~ m/\w+/) 
   {
        $newfile = $ARGV;
   }
}

# check if all the expected inputs are received
if ( ! $newfile || ! $desc || ! $func || ! $appIdStr || !$appIdNm) 
{
	usage();
}

if ( -e "$newfile.c" ) 
{
    print "File $newfile exists, clobber file? (y/n) [n] ";
	$clobber = <STDIN>;
	if ( $clobber !~ m/^y/i ) 
	{
		die "\nFile exists, cannot continue....\n";
	}
	else 
	{
		createfile($newfile,"c",$shortDesc,$funcNm,$appIdStr,$appIdNm);
	}
}
else 
{
	createfile($newfile,"c",$shortDesc,$funcNm,$appIdStr,$appIdNm);
}


OpenPOWER on IntegriCloud