-
Notifications
You must be signed in to change notification settings - Fork 256
/
scigend
executable file
·86 lines (63 loc) · 1.98 KB
/
scigend
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
#!/usr/bin/perl -w
# This file is part of SCIgen.
#
# SCIgen is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# SCIgen is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SCIgen; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use IO::Socket;
use scigen;
print "about to use port $scigen::SCIGEND_PORT\n";
my $server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $scigen::SCIGEND_PORT,
Listen => 1, Reuse => 1);
die "Cannot start $0 on port $scigen::SCIGEND_PORT" unless $server;
my $client;
my $name_dat = {};
my $name_RE = undef;
my $tex_dat = {};
my $tex_RE = undef;
&initialize();
print "Initialized . . .\n";
while(1) {
while( $client = $server->accept() ) {
while( <$client> ) {
print "Received message: $_\n";
my $fh = select $client;
print &get_system_name() . "\n";
close $client;
select $fh;
last;
}
}
next if $!{EINTR};
last;
}
sub initialize {
my $fh = new IO::File( "<system_names.in" );
&scigen::read_rules( $fh, $name_dat, \$name_RE, 0 );
$fh = new IO::File( "<scirules.in" );
&scigen::read_rules( $fh, $tex_dat, \$tex_RE, 0 );
}
sub get_system_name {
my $name = &scigen::generate ($name_dat, "SYSTEM_NAME", $name_RE, 0, 0);
chomp($name);
# how about some effects?
my $rand = rand;
if( $rand < .1 ) {
$name = "{\\em $name}";
} elsif( length($name) <= 6 and $rand < .4 ) {
$name = uc($name);
}
return $name;
}