• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D19-May-20159 21

MakefileH A D19-May-20152.8 KiB7560

READMEH A D19-May-20153.7 KiB12292

README.cfgH A D19-May-20157.1 KiB206168

README.fpuH A D19-May-20156.9 KiB163132

README.gtkH A D19-May-20151.3 KiB2621

config.cH A D19-May-20153.6 KiB161128

config.shH A D03-May-202218.6 KiB562475

cygyor.defH A D19-May-201556 43

dir.cH A D19-May-20153.2 KiB158127

files.cH A D19-May-20156.3 KiB276224

fpuset.cH A D19-May-201512.7 KiB454292

fputest.cH A D19-May-20152.7 KiB130103

handler.cH A D19-May-20152.2 KiB9973

pathnm.cH A D19-May-20152.3 KiB10484

playu.hH A D19-May-20152.1 KiB6020

pmain.cH A D19-May-2015574 2411

slinks.cH A D19-May-20153.8 KiB144114

stdinit.cH A D19-May-20152.1 KiB9669

timeu.cH A D19-May-20151.7 KiB7249

timew.cH A D19-May-20151.2 KiB5333

udl.cH A D19-May-20154.7 KiB216149

udltest.cH A D19-May-20153.5 KiB176122

uevent.cH A D19-May-20154.5 KiB183139

ugetc.cH A D19-May-20151.8 KiB10375

ugetc.hH A D19-May-20151.5 KiB4111

uinbg.cH A D19-May-20151.8 KiB6639

umain.cH A D19-May-20152.7 KiB11693

upoll.cH A D19-May-20153.4 KiB12884

upoll.hH A D19-May-20151.1 KiB3312

usernm.cH A D19-May-2015930 5438

usock.cH A D19-May-20158.5 KiB335250

uspawn.cH A D19-May-20156.8 KiB298239

README

1
2dir.c (plib.h plibu.h pstdlib.h) <unistd.h sys/types.h sys/stat.h>
3  DIRENT_HEADER undef, <sys/dir.h>, <sys/ndir.h>, <ndir.h>
4    set only if <dirent.h> not present
5  USE_GETWD
6    set to use getwd instead of getcwd
7
8files.c (pstdio.h pstdlib.h plibu.h) <string.h unistd.h>
9
10fpuset.c (plibu.h)
11  see README.fpu for list of FPU_* macros
12
13fputest.c is related to fpuset.c
14
15getpath.c (plib.h pstdlib.h)
16
17handler.c (plib.h) <signal.h>
18
19main.c (plib.h pstdlib.h plibu.h) <setjmp.h>
20
21pathnm.c (plib.h pstdlib.h) <string.h>
22  NO_PASSWD -- define to skip ~user expansion, otherwise
23    <sys/types.h unistd.h pwd.h>
24
25pgrp.c
26  HDR_WITH_TIOCGPGRP -- if undef, <sgtty.h>
27  - pgrp.c only necessary for systems missing tcgetpgrp
28
29stdinit.c (plib.h pstdlib.h pstdio.h plibu.h) <string.h>
30
31timeu.c (plib.h)
32  USE_GETRUSAGE -- (preferred if present) <sys/time.h sys/resource.h>
33  USE_TIMES -- (POSIX standard) <time.h sys/times.h>
34  else      -- (ANSI C standard) <time.h>
35
36timew.c (plib.h)
37  USE_GETTIMEOFDAY -- (X11 uses this) <sys/time.h>
38  else             -- (ANSI C standard) <time.h>
39
40uevent.c (plibu.h pstdlib.h) <errno.h>
41  USE_SELECT -- use upoll.c implementation of poll (upoll.h)
42  else       -- use system poll (preferred)
43    USE_SYS_POLL_H <sys/poll.h>
44    else           <poll.h>
45
46ugetc.c (pstdio.h plibu.h ugetc.h)
47
48uinbg.c (plibu.h) <sys/types.h>
49
50upoll.c (upoll.h pstdlib.h)
51  HAVE_SYS_SELECT_H <sys/select.h>
52  else
53    NO_SYS_TIME_H <time.h> else <sys/time.h>
54    NEED_SELECT_PROTO <sys/types.h>
55
56usernm.c (plib.h pstdlib.h)
57  NO_PASSWD -- use cuserid function
58  else      -- <sys/types.h unistd.h pwd.h>
59
60waiter.c (plib.h plibu.h)
61
62
63
64
65
66Notes on UNIX variants
67----------------------
68
69Required headers not part of ANSI C standard:
70
71<unistd.h>      dir.c usernm.c
72  chdir rmdir getcwd (in dir.c)
73  getlogin getuid (to implement cuserid in usernm.c)
74<sys/types.h>   dir.c usernm.c
75<sys/stat.h>
76  stat S_IFDIR (in dir.c)
77<dirent.h>      dir.c
78  or one of: <sys/dir.h>, <sys/ndir.h>, or <ndir.h>
79  opendir readdir closedir (in dir.c)
80<pwd.h>         usernm.c, pathnm.c (unused if NO_PASSWD set)
81  getpwnam (to expand ~user/* pathnames)
82  getpwuid (to implement cuserid in usernm.c)
83
84pathname expansion: (pathnm.c)
85-------------------
86  $ENVVAR $(ENVVAR) ${ENVVAR}
87  $ENVVAR/path $(ENVVAR)/path ${ENVVAR}/path
88  ~ ~/path
89  ~user ~user/path
90    are all expanded by u_pathname, which is used in every plib
91      function requiring a pathname
92    ~ is the same as $HOME, but if no such environment variable exists
93      and NO_PASSWD is not set, tries to get the home directory for
94      the current real user
95    ~user will not work if NO_PASSWD is set
96
97dirent.h (dir.c)
98--------
99   Old style is struct direct instead of struct dirent; directory
100     functions may be in <sys/dir.h>, <sys/ndir.h>, or <ndir.h>
101   Autoconf manual notes that d_namlen member may be missing from
102     struct dirent (present in struct direct); that raises the
103     possibility that d_name is not a 0-terminated string
104     -- xfig source assumes that it is, so I do too
105  DIRENT_HEADER - if no dirent.h, set to <sys/dir.h> etc
106
107getcwd (dir.c)
108------
109   SunOS deprecates use of getcwd in favor of getwd,
110     but apparently getcwd is more portable (getwd is non-POSIX)...
111   Comments in HPUX unistd.h indicate that original POSIX.1 1988
112     definition had second parameter of type int; POSIX now size_t
113   NextOS has no getwd, at least in some old versions
114  USE_GETWD - define to use getwd instead of getcwd
115
116cuserid (usernm.c)
117-------
118   cuserid was removed from POSIX due to a religious war over
119     whether it should return the real or effective username
120   I call getlogin(), then getpwuid(getuid())
121  NO_PASSWD - define to use cuserid (requires no headers)
122

README.cfg

1Notes on play configuration
2---------------------------
3
4There are two configuration files:
5
6config.h       - #defines for source code in play/*/*.[ch]
7../../Make.cfg - Makefile definitions required to compile or load
8                 (common to all packages)
9
10Both of these can hopefully be computed by the config.sh script; if
11not, you may be able to do the job by hand.
12
13------------------------------------------------------------------------
14_POSIX_SOURCE, _XOPEN_SOURCE_EXTENDED, _HPUX_SOURCE macros:
15
16I want to try to use the POSIX standard whenever possible and
17applicable.  System header files known to be affected on some systems
18include:
19<signal.h>, <dirent.h>, <sys/types.h>, <unistd.h>, <pwd.h>, <time.h>
20
21The files files.c and ugetc.c need _POSIX_SOURCE before <stdio.h> in
22order to get the fileno macro declared.  The dir.c, pathnm.c,
23usernm.c, and uinbg.c files use explicitly POSIX functions and also
24declare the macro.
25
26A few play features are implemented using non-POSIX functions.  At
27these places in the source code, I undef _POSIX_SOURCE.  The timers
28gettimeofday (timew.c) and getrusage (timeu.c) are the only examples
29so far; HPUX additionally needs _HPUX_SOURCE in the former case.
30
31The poll/select functions in uevent.c and upoll.c are the other
32non-POSIX routines and have caused some problems.  HPUX wants
33_HPUX_SOURCE defined, and Digital UNIX wants _XOPEN_SOURCE_EXTENDED
34defined in order to pick up the poll.h header correctly.
35
36A yorick package using a specifically POSIX feature should declare
37_POSIX_SOURCE before any other includes.  If a specifically non-ANSI
38feature is used, _POSIX_SOURCE should be undef'd after config.h but
39before any system headers are included (note that pstdio.h and
40pstdlib.h indirectly include system headers).
41------------------------------------------------------------------------
42
43#define USE_GETRUSAGE
44-or-
45#define USE_TIMES
46-or-
47neither
48
49------------------------------------------------------------------------
50On systems which have the BSD getrusage function, it generally provides
51the most accurate CPU timer (much better than the POSIX times often).
52The POSIX times function is an alternative; if neither is defined, the
53timeu.c source falls back to the ANSI clock function.
54------------------------------------------------------------------------
55
56/* play/unix/timew.c- specify which wall timing function to use
57 *   - gettimeofday needs <sys/time.h>
58 *   - if undefined, will use ANSI C time and difftime functions */
59#define USE_GETTIMEOFDAY
60-or-
61nothing
62
63------------------------------------------------------------------------
64The BSD gettimeofday routine is the preferred wall clock timer; it is
65the one used universally by the X11 library, so you ought to get
66agreement between X server times and p_wall_secs with it.  The
67fallback in timew.c if USE_GETTIMEOFDAY is not defined is the ANSI C
68time and difftime functions.
69------------------------------------------------------------------------
70
71nothing
72-or-
73#define NO_PASSWD
74
75------------------------------------------------------------------------
76The POSIX getlogin, getpwuid, and getuid functions permit expansion of
77~user/... pathnames (pathnm.c).  If these functions are not present,
78define NO_PASSWD and that functionality will be disabled.  This also
79affects the p_getuser function (usernm.c), which falls back to the
80deprecated cuserid function if NO_PASSWD is defined.
81------------------------------------------------------------------------
82
83nothing
84-or-
85#define USE_TIOCGPGRP_IOCTL <sys/termios.h>
86-or-
87#define USE_TIOCGPGRP_IOCTL <sgtty.h>
88
89------------------------------------------------------------------------
90If the POSIX tcgetpgrp function is missing (used to determine whether
91the program is running as a background task in uinbg.c), define
92USE_TIOCGPGRP_IOCTL as the name of the system header file which
93defines the TIOCGPGRP ioctl.
94------------------------------------------------------------------------
95
96nothing
97-or-
98/* play/unix/dir.c- use getwd instead of POSIX getcwd */
99#define USE_GETWD
100
101------------------------------------------------------------------------
102If the POSIX getcwd function is missing (used to find current working
103directory in dir.c), define USE_GETWD to use getwd instead.
104------------------------------------------------------------------------
105
106nothing
107-or-
108#define DIRENT_HEADER <sys/dir.h>
109-or-
110#define DIRENT_HEADER <sys/ndir.h>
111-or-
112#define DIRENT_HEADER <ndir.h>
113
114------------------------------------------------------------------------
115If the POSIX dirent.h header is missing or broken, define DIRENT_HEADER
116as the name of the system header file containing the directory handling
117functions.  See dir.c more more.
118------------------------------------------------------------------------
119
120nothing
121-or-
122#define USE_SYS_POLL_H
123
124-or-
125
126#define USE_SELECT
127-and-
128nothing
129-or-
130#define HAVE_SYS_SELECT_H
131-or none, one, or both of-
132#define NO_SYS_TIME_H
133#define NEED_SELECT_PROTO
134
135------------------------------------------------------------------------
136To handle multiple input sources, you need either the poll function or
137the select function.  I prefer the poll interface (and select was
138apparently broken on at least one IRIX system).  If <poll.h> exists,
139you don't need any defines; if <sys/poll.h> exists, define
140USE_SYS_POLL_H.
141
142If poll is missing or you need to use select instead (upoll.c implements
143a barebones poll in terms of select), define USE_SELECT.  In that case,
144define HAVE_SYS_SELECT_H if <sys/select.h> is present; otherwise you
145may need to define NO_SYS_TIME_H (you will need either <sys/time.h> or
146<time.h>).  You may also need to define NEED_SELECT_PROTO.
147
148See uevent.c and upoll.c for more.
149------------------------------------------------------------------------
150
151in config.h:
152-exactly one of-
153#define FPU_DIGITAL
154#define FPU_AIX
155#define FPU_HPUX
156#define FPU_IRIX
157#define FPU_SUN4
158#define FPU_SOLARIS
159#define FPU_UNICOS
160#define FPU_ALPHA_LINUX
161#define FPU_GCC_I86
162#define FPU_GCC_POWERPC
163#define FPU_GCC_SPARC
164#define FPU_GCC_M68K
165#define FPU_GCC_ARM
166#define FPU_IGNORE
167
168in config.mak:
169FPELIB =
170-or-
171FPELIB = -lsunmath
172-or-
173FPELIB = -lfpe
174
175------------------------------------------------------------------------
176UNIX systems usually do not deliver SIGFPE (floating point exception
177signals) by default.  The code to turn on SIGFPE delivery is highly
178system dependent.  You must define exactly one of the above symbols
179in order to compile fpuset.c.  The fputest.c program will tell you if
180you have succeeded in turning on SIGFPE delivery (config.sh runs it).
181
182FPU_HPUX, FPU_SUN4, and FPU_UNICOS require routines in libm (-lm).
183
184FPU_SUN4 may require libsunmath (-lsunmath), and FPU_IRIX requires
185libfpe (-lfpe).  In these two cases, the config.mak file will set the
186FPELIB flag to the required loader option.  Otherwise, FPELIB will be
187set to nil.
188------------------------------------------------------------------------
189
190in config.mak:
191
192XINC =
193-or-
194XINC = -Ipath_to_X11/Xlib.h
195
196-and-
197
198XLIB =
199-or-
200XLIB = -Lpath_to_libX11
201
202------------------------------------------------------------------------
203The X11 headers and libraries may be hidden from the compiler without
204appropriate -I and -L options, which are written into config.mak.
205------------------------------------------------------------------------
206

README.fpu

1
2All interactive numerical programs benefit from prompt delivery of
3SIGFPE signals.  The processor should trap on zero divide, overflow,
4or invalid operations, and give the process a chance to abort the
5operation cleanly.  Testing for these conditions (which is supported
6in a portable fashion by the C9X standard) is at best a poor
7substitute for prompt interrupt, since it must be done in a very large
8number of places in the code.  Testing on an operation by operation
9basis (as would be necessary before C9X) will obviously ruin
10performance of any numerically demanding program (you'd need to take
11logarithms to check for overflow, for example).  Allowing huge arrays
12of numbers to slowly fill wil NaN and Inf wastes computer time, and
13makes debugging nearly impossible.
14
15Every UNIX operating system and machine requires a different procedure
16for setting up the hardware to trap and deliver this interrupt; the
17universal default is to ignore all floating point errors.  I know how
18to set up the FPU for the following platforms:
19
20FPU_DIGITAL     DEC Alpha / Digital UNIX (FPU_ALPHA_LINUX also works?)
21FPU_AIX         IBM RS6000 / AIX
22FPU_HPUX        HP PA-RISC / HPUX
23FPU_IRIX        SGI MIPS / IRIX
24FPU_SUN4        Sun SPARC / SunOS 4
25FPU_SOLARIS     Sun SPARC / Solaris (SunOS 5)
26FPU_UNICOS      Cray X/YMP, J90 / UNICOS
27FPU_ALPHA_LINUX DEC Alpha / Linux
28FPU_GCC_I86     Intel x86 / gcc (Linux)
29FPU_GCC_POWERPC IBM Power PC (RS6000?) / gcc (Linux)
30FPU_GCC_SPARC   Sun SPARC / gcc (Linux or SunOS)
31FPU_GCC_M68K    Motorola 680x0 / gcc (Linux or NextStep)
32FPU_GCC_ARM     ARM / gcc (Linux)
33FPU_IGNORE      dummy, for those few platforms with proper default
34                  (NetBSD?  FreeBSD?)
35
36If none of these works for your machine, and you can figure out what
37does, please contact me at munro@icf.llnl.gov.  (I've never been able
38to make Ultrix trap SIGFPE, for example.)  You can use the fputest.c
39program (and Make.fpu) to test your ideas.
40
41SIGFPE PROBLEMS
42---------------
43
44On SGI/IRIX machines, you must be extremely careful *not* to set the
45TRAP_FPE environment variable, which will override anything your code
46does.  The best policy there is to undefine TRAP_FPE before running
47your code (do this by starting with a shell script).
48
49If you are using gcc on a SunOS 4 machine, you may not have the
50required routines for FPU_SUN4 (look in /usr/lib/libm.a; otherwise,
51they are in /usr/lang/SC*/lib/libsunmath.a, which comes with Sun's
52compilers).  In that case, try FPU_GCC_SPARC.
53
54Pentium (and other x86) machines do not always deliver SIGFPE
55promptly, so the signal may be delivered on a (non-faulting)
56subsequent floating point instruction.  This is aggravating, but
57apparently not much can be done about it.
58
59
60MacOS X 10.3 (2/Feb/04)
61------------
62
63MacOS X 10.3.0, 10.3.1, and 10.3.2 (at least) shipped with a broken
64libm (/usr/lib/libm.dylib).  The system functions sqrt and tanh cause
65SIGFPE for every argument.  The errors are in Libm-47 in the files
66sqrt.c, shchth.c, and ashachath.c (the latter is inverse hyperbolic
67functions not used by yorick), which perform operations involving
68infinity (FPR_inf) before they switch to a non-trapping floating point
69environment.  The sqrt function in sqrt.c is unused on G5 hardware,
70which selects a hardware fsqrt instruction instead of the sqrt.c code.
71However, on G4 and earlier hardware, the software sqrt in sqrt.c does
72generate incorrect SIGFPEs.  The only easy fix is to use FPU_IGNORE
73instead of FPU_MACOSX, but that will ignore all floating point
74exceptions, which is dangerous in any numerical program.
75
76Earlier versions of setfpu.c did not reset the vx_sqrt bit in the
77fp_scr register, which caused a fault loop on sqrt(any negative
78value); see the comment in fpuset.c.
79
80
81SIGFPE on Linux (18/May/99)
82---------------
83
84The __setfpucw function used to be available for general use; here is
85its generic implementation.  Sometime in early 1999, GNU libc6
86switched to making __setfpucw only available internally, forcing the
87use of assembler macros in application code (see fpuset.c).
88
89#include <fpu_control.h>
90
91void
92__setfpucw (fpu_control_t set)
93{
94  fpu_control_t cw;
95
96  /* Fetch the current control word.  */
97  _FPU_GETCW (cw);
98
99  /* Preserve the reserved bits, and set the rest as the user
100     specified (or the default, if the user gave zero).  */
101  cw &= _FPU_RESERVED;
102  cw |= set & ~_FPU_RESERVED;
103
104  _FPU_SETCW (cw);
105}
106
107Note that the macros are not always defined -- the alpha has its own
108__setfpucw which translates i386 bits.  In all other cases, when they
109are defined, the bit macros are all different.
110
111More recently, Linux 2.6 kernels apparently cause fputest.c to fail,
112although yorick itself still works.  If you figure out why, please
113contact me at munro1 at llnl.gov.
114
115Alpha Linux
116-----------
117
118Alpha Linux implements the Digital UNIX (now Tru64)
119ieee_set_fp_control() function, although it puts the fpu.h header in a
120different place than Digital (now Compaq now HP).
121
122The alpha hardware cannot handle denormals, infinity, or other IEEE
123constructs.  In particular, denormals cause the hardware to trap.  You
124can let the Linux kernel (or Tru64 kernel) handle these exceptions and
125fill in the IEEE-compliant value by compiling every module with the
126-mieee option to GCC.  This is obviously slow if you have lots of
127underflows (as with many FFTs).  Furthermore, -mieee inhibits some
128types of optimizations which would interfere with the kernel math
129emulator's ability to compute the IEEE-compliant result.
130
131Unfortunately, the Linux libc and libm libraries produce denormals,
132for example exp(-720), which are not numbers unless you have compiled
133with -mieee.  Hence, by default, the C expressions exp(-700)+0.0 and
134exp(-800)+0.0 work fine, but exp(-720)+0.0 causes a SIGFPE.  The
135problem is that the alpha hardware does not support denormals, but
136exp() returns them.  The best workaround is to use the Compaq math
137library if you can get it.  The libc also contains routines like scanf
138which will return denormals (hence the yorick read() function can
139produce them).  These are rare enough that you probably don't care
140about trying to replace libc.
141
142If you don't have access to a correct libm, you can put
143       CC=gcc -mieee
144in the top level Make.cfg file.  This will cause a significant
145performance penalty, but at least exp() won't randomly trigger SIGFPE.
146If you do have a good libm, put it in the MATHLIB= line in Make.cfg.
147
148IRIX
149----
150
151Apparently handle_sigfpes (see manpage), as loaded from the libfpe
152library, is the preferred way to get control after SIGFPE.  The
153fpsetmask function can masquerade as a FPU_SOLARIS, but that code
154fails for some reason in full yorick, despite passing the fputest.c
155suite.  When floating point exceptions are masked, IRIX delivers
156SIGTRAP (causing a core dump) on integer divide by zero (gag me with a
157spoon).  When floating point exceptions are being delivered, integer
158divide by zero generates SIGFPE, but only on 32-bit platforms.
159
160An additional headache is that libm does not generate SIGFPE on
161overflow.  An alternative library libmx is available, but requires a
162matherr function.
163

README.gtk

1
2Notes on how to implement plib over gtk
3---------------------------------------
4
5(1) gtk_timeout_add (gtkmain.c) uses g_timeout_add (glib gmain.c),
6which gets the time as of the call and adds the specified interval as
7the first select timeout.  Hence, p_timer/p_idler can be implemented
8neatly like this:
9
10As far as gtk is concerned, the application has a single routine that
11alternates between being called as an idler: Its data context tells
12whether it has been invoked as a timeout or an idler.  If it is a
13timeout, then services the timeout; if it is an idler, it calls the
14application on_idle (and remembers if it wants to be called again).
15In either case, before returning, it calls the application on_poll
16function.  If app_on_poll returns >=0, it calls gtk_timeout_add to add
17itself as a timeout with the specified interval, then returns 0 to
18remove its previous incarnation (as either a timeout or idler).
19Otherwise, it returns 0 unless app_on_idle was called and returned 0.
20
21Unclear: need to know whether gtk calls its idler over and over
22without waiting for new input between idler calls (seems most likely),
23or whether it calls an idler only once and waits for new input before
24calling it again.  In the former case, really just want a sequence of
25timeouts with 0 for immediate recall, or HUGE to wait forever.
26