Skip to content

Commit

Permalink
perl 3.0 patch #32 patch #29, continued
Browse files Browse the repository at this point in the history
See patch #29.
  • Loading branch information
Larry Wall committed Oct 16, 1990
1 parent c2ab57d commit d9d8d8d
Show file tree
Hide file tree
Showing 24 changed files with 974 additions and 71 deletions.
47 changes: 47 additions & 0 deletions eg/sysvipc/ipcmsg
@@ -0,0 +1,47 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0;

require 'sys/ipc.ph';
require 'sys/msg.ph';

$| = 1;

$mode = shift;
die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/;
$send = ($mode eq "s");

$id = msgget(0x1234, ($send ? 0 : &IPC_CREAT) | 0644);
die "Can't get message queue: $!\n" unless defined($id);
print "message queue id: $id\n";

if ($send) {
while (<STDIN>) {
chop;
unless (msgsnd($id, pack("LA*", $., $_), 0)) {
die "Can't send message: $!\n";
}
}
}
else {
$SIG{'INT'} = $SIG{'QUIT'} = "leave";
for (;;) {
unless (msgrcv($id, $_, 512, 0, 0)) {
die "Can't receive message: $!\n";
}
($type, $message) = unpack("La*", $_);
printf "[%d] %s\n", $type, $message;
}
}

&leave;

sub leave {
if (!$send) {
$x = msgctl($id, &IPC_RMID, 0);
if (!defined($x) || $x < 0) {
die "Can't remove message queue: $!\n";
}
}
exit;
}
46 changes: 46 additions & 0 deletions eg/sysvipc/ipcsem
@@ -0,0 +1,46 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0;

require 'sys/ipc.ph';
require 'sys/msg.ph';

$| = 1;

$mode = shift;
die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/;
$signal = ($mode eq "s");

$id = semget(0x1234, 1, ($signal ? 0 : &IPC_CREAT) | 0644);
die "Can't get semaphore: $!\n" unless defined($id);
print "semaphore id: $id\n";

if ($signal) {
while (<STDIN>) {
print "Signalling\n";
unless (semop($id, 0, pack("sss", 0, 1, 0))) {
die "Can't signal semaphore: $!\n";
}
}
}
else {
$SIG{'INT'} = $SIG{'QUIT'} = "leave";
for (;;) {
unless (semop($id, 0, pack("sss", 0, -1, 0))) {
die "Can't wait for semaphore: $!\n";
}
print "Unblocked\n";
}
}

&leave;

sub leave {
if (!$signal) {
$x = semctl($id, 0, &IPC_RMID, 0);
if (!defined($x) || $x < 0) {
die "Can't remove semaphore: $!\n";
}
}
exit;
}
50 changes: 50 additions & 0 deletions eg/sysvipc/ipcshm
@@ -0,0 +1,50 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0;

require 'sys/ipc.ph';
require 'sys/shm.ph';

$| = 1;

$mode = shift;
die "usage: ipcshm {r|s}\n" unless $mode =~ /^[rs]$/;
$send = ($mode eq "s");

$SIZE = 32;
$id = shmget(0x1234, $SIZE, ($send ? 0 : &IPC_CREAT) | 0644);
die "Can't get message queue: $!\n" unless defined($id);
print "message queue id: $id\n";

if ($send) {
while (<STDIN>) {
chop;
unless (shmwrite($id, pack("La*", length($_), $_), 0, $SIZE)) {
die "Can't write to shared memory: $!\n";
}
}
}
else {
$SIG{'INT'} = $SIG{'QUIT'} = "leave";
for (;;) {
$_ = <STDIN>;
unless (shmread($id, $_, 0, $SIZE)) {
die "Can't read shared memory: $!\n";
}
$len = unpack("L", $_);
$message = substr($_, length(pack("L",0)), $len);
printf "[%d] %s\n", $len, $message;
}
}

&leave;

sub leave {
if (!$send) {
$x = shmctl($id, &IPC_RMID, 0);
if (!defined($x) || $x < 0) {
die "Can't remove shared memory: $!\n";
}
}
exit;
}
12 changes: 7 additions & 5 deletions evalargs.xc
Expand Up @@ -2,9 +2,13 @@
* kit sizes from getting too big.
*/

/* $Header: evalargs.xc,v 3.0.1.6 90/08/09 03:37:15 lwall Locked $
/* $Header: evalargs.xc,v 3.0.1.7 90/10/15 16:48:11 lwall Locked $
*
* $Log: evalargs.xc,v $
* Revision 3.0.1.7 90/10/15 16:48:11 lwall
* patch29: non-existent array values no longer cause core dumps
* patch29: added caller
*
* Revision 3.0.1.6 90/08/09 03:37:15 lwall
* patch19: passing *name to subroutine now forces filehandle and array creation
* patch19: `command` in array context now returns array of lines
Expand Down Expand Up @@ -92,8 +96,6 @@
}
st[++sp] = afetch(stab_array(argptr.arg_stab),
arg[argtype].arg_len - arybase, FALSE);
if (!st[sp])
st[sp] = &str_undef;
#ifdef DEBUGGING
if (debug & 8) {
(void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
Expand Down Expand Up @@ -263,7 +265,7 @@
break;
case A_WANTARRAY:
{
if (wantarray == G_ARRAY)
if (curcsv->wantarray == G_ARRAY)
st[++sp] = &str_yes;
else
st[++sp] = &str_no;
Expand Down Expand Up @@ -323,7 +325,7 @@
st = stack->ary_array;
tmpstr = Str_new(55,0);
#ifdef MSDOS
str_set(tmpstr, "glob ");
str_set(tmpstr, "perlglob ");
str_scat(tmpstr,str);
str_cat(tmpstr," |");
#else
Expand Down
30 changes: 29 additions & 1 deletion form.c
@@ -1,11 +1,14 @@
/* $Header: form.c,v 3.0.1.2 90/08/09 03:38:40 lwall Locked $
/* $Header: form.c,v 3.0.1.3 90/10/15 17:26:24 lwall Locked $
*
* Copyright (c) 1989, Larry Wall
*
* You may distribute under the terms of the GNU General Public License
* as specified in the README file that comes with the perl 3.0 kit.
*
* $Log: form.c,v $
* Revision 3.0.1.3 90/10/15 17:26:24 lwall
* patch29: added @###.## fields to format
*
* Revision 3.0.1.2 90/08/09 03:38:40 lwall
* patch19: did preliminary work toward debugging packages and evals
*
Expand Down Expand Up @@ -281,6 +284,31 @@ int sp;
d += size;
linebeg = fcmd->f_next;
break;
case F_DECIMAL: {
double value;

(void)eval(fcmd->f_expr,G_SCALAR,sp);
str = stack->ary_array[sp+1];
/* If the field is marked with ^ and the value is undefined,
blank it out. */
if ((fcmd->f_flags & FC_CHOP) && !str->str_pok && !str->str_nok) {
while (size) {
size--;
*d++ = ' ';
}
break;
}
value = str_gnum(str);
size = fcmd->f_size;
CHKLEN(size);
if (fcmd->f_flags & FC_DP) {
sprintf(d, "%#*.*f", size, fcmd->f_decimals, value);
} else {
sprintf(d, "%*.0f", size, value);
}
d += size;
break;
}
}
}
CHKLEN(1);
Expand Down
8 changes: 7 additions & 1 deletion form.h
@@ -1,11 +1,14 @@
/* $Header: form.h,v 3.0 89/10/18 15:17:39 lwall Locked $
/* $Header: form.h,v 3.0.1.1 90/10/15 17:26:57 lwall Locked $
*
* Copyright (c) 1989, Larry Wall
*
* You may distribute under the terms of the GNU General Public License
* as specified in the README file that comes with the perl 3.0 kit.
*
* $Log: form.h,v $
* Revision 3.0.1.1 90/10/15 17:26:57 lwall
* patch29: added @###.## fields to format
*
* Revision 3.0 89/10/18 15:17:39 lwall
* 3.0 baseline
*
Expand All @@ -16,6 +19,7 @@
#define F_RIGHT 2
#define F_CENTER 3
#define F_LINES 4
#define F_DECIMAL 5

struct formcmd {
struct formcmd *f_next;
Expand All @@ -25,6 +29,7 @@ struct formcmd {
char *f_pre;
short f_presize;
short f_size;
short f_decimals;
char f_type;
char f_flags;
};
Expand All @@ -33,6 +38,7 @@ struct formcmd {
#define FC_NOBLANK 2
#define FC_MORE 4
#define FC_REPEAT 8
#define FC_DP 16

#define Nullfcmd Null(FCMD*)

Expand Down
3 changes: 2 additions & 1 deletion h2ph.SH
Expand Up @@ -102,7 +102,8 @@ foreach $file (@ARGV) {
}
}
elsif (/^include <(.*)>/) {
print OUT $t,"do '$1' || die \"Can't include $1: \$!\";\n";
($incl = $1) =~ s/\.h$/.ph/;
print OUT $t,"require '$incl';\n";
}
elsif (/^ifdef\s+(\w+)/) {
print OUT $t,"if (defined &$1) {\n";
Expand Down

0 comments on commit d9d8d8d

Please sign in to comment.