-
Notifications
You must be signed in to change notification settings - Fork 17
/
mkflat.pl
111 lines (84 loc) · 2.09 KB
/
mkflat.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
#!/usr/bin/perl -w
# mkflat.pl: Makes a flat, statically linked version of newserv
my @coredirs = ( "core", "parser", "lib" );
my @moduledirs;
my $configfile="newserv.conf";
my $flatdir="flat";
if (defined $ARGV[0]) {
$configfile=$ARGV[0];
}
open CFG, $configfile or die "Unable to open $configfile: $!";
my $insection=0;
while (<CFG>) {
chomp;
if (/\[core\]/) {
$insection=1;
next;
} elsif (/\[\.*\]/) {
$insection=0;
next;
} else {
if ($insection && m/^loadmodule=(.*)$/) {
push @moduledirs, $1;
}
}
}
close CFG;
open NEWSERVH,">", $flatdir."/newserv.h" or die "Unable to open flat header: $!";
open NEWSERVC,">", $flatdir."/newserv.c" or die "Unable to open flat file : $!";
print NEWSERVC '#include "newserv.h"'."\n\n";
foreach (@coredirs) {
my $dir=$_;
opendir DIR, $_;
my @files=readdir DIR;
closedir DIR;
foreach (@files) {
if (/\.[ch]$/) {
dofile($dir, $_, undef);
}
}
}
foreach (@moduledirs) {
my $dir=$_;
opendir DIR, $_;
my @files=readdir DIR;
closedir DIR;
foreach (@files) {
if (/\.[ch]$/) {
dofile($dir, $_, $dir);
}
}
}
sub dofile {
my ($dirname, $filename, $modname) = @_;
open INFILE, $dirname."/".$filename or die "Unable to open file: $!";
if ($filename =~ /h$/) {
# header file
while(<INFILE>) {
print NEWSERVH $_;
}
} else {
# .c file
open OUTFILE, ">", $flatdir."/".$dirname."_".$filename or die "Unable to open file $flatdir/${dirname}_$filename: ";
# print OUTFILE '#include "newserv.h"'."\n\n";
while (<INFILE>) {
# next if (/^#include \"/); # Skip local include files
if (/void _init\(\)/ && defined $modname) {
s/_init/${modname}_init/;
}
if (/void _fini\(\)/ && defined $modname) {
s/_fini/${modname}_fini/;
}
if (/initmodules\(\);/) {
foreach (@moduledirs) {
print OUTFILE $_."_init\(\);";
print NEWSERVC $_."_init\(\);";
}
next;
}
print OUTFILE $_;
print NEWSERVC $_;
}
close OUTFILE;
}
}