-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro2strings.pl
executable file
·118 lines (90 loc) · 2.54 KB
/
macro2strings.pl
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
#!/usr/bin/perl -w
# @filename : macro2strings.pl
# @author : Copyright (C) drunkwater
# @date : Mon Jan 15 12:43:38 HKT 2018
# @function :
# @see :
# @require :
# require here
#require v5.6.1;
# use standard library/use warnings
use strict;
use warnings;
#use File::Copy;
# use other library/perl modules, writed by drunkwater
my $OS_DATE;
sub getCurrentTime
{
my $time = time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
$sec = ($sec<10)?"0$sec":$sec;
$min = ($min<10)?"0$min":$min;
$hour = ($hour<10)?"0$hour":$hour;
$mday = ($mday<10)?"0$mday":$mday;
$mon = ($mon<9)?"0".($mon+1):$mon;
$year+=1900;
my $weekday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
return { 'second' => $sec,
'minute' => $min,
'hour' => $hour,
'day' => $mday,
'month' => $mon,
'year' => $year,
'weekNo' => $wday,
'wday' => $weekday,
'yday' => $yday,
'date' => "$year$mon$mday"
};
}
sub ltrim { my $s = shift; $s =~ s/^\s+//; return $s };
sub rtrim { my $s = shift; $s =~ s/\s+$//; return $s };
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
sub open_filehandle_for_output
{
my $filename = $_[0];
my $overWriteFilename = ">" . $filename;
local *FH;
open (FH, $overWriteFilename) || die "Could not open $filename";
return *FH;
}
sub open_filehandle_for_input
{
my $filename = $_[0];
local *FH;
open (FH, $filename) || die "Could not open $filename";
return *FH;
}
sub main
{
my $destFileName = "./" . "WinUserHeader_new.cpp";
my $destFileRef = open_filehandle_for_output($destFileName);
my $srcFileName = "./" . "WinUserHeader_old.cpp";
my $srcFileRef = open_filehandle_for_input($srcFileName);
while_label:while (<$srcFileRef>)
{
my $line = $_;
my $quoted = quotemeta( q{// #define WM} );
if (($_ =~ /^$quoted/) and ($_ =~ /0x/))
{
$line =~ /\/\/ \#define(.*)0x/;
my $macro = trim($1);
print $destFileRef "\tcase " . $macro . " :\r\n";
print $destFileRef "\t\tp = (const char *)WM_MACRO_2_STRINGS" . "(" . $macro . ");\r\n";
print $destFileRef "\t\tbreak;\r\n";
}
else
{
print $destFileRef $line;
}
}
close($srcFileRef);
close($destFileRef);
return 0;
}
################################################################################
my $date = &getCurrentTime();
$OS_DATE = $date->{date};
chomp($OS_DATE);
main();
exit 0;
################################################################################