scm-5f4/ 0000775 0001750 0001750 00000000000 14560303536 007244 5 0000000 0000000 scm-5f4/xevent.h 0000755 0001750 0001750 00000041474 14560204227 010656 0000000 0000000 /* xgen.scm extracted typedef structs from /usr/include/X11/Xlib.h */
#ifdef SCM_EVENT_FIELDS
case (KeyPress<<8)+0x10: case (KeyRelease<<8)+0x10: return MAKINUM(((XKeyEvent *) x)->type);
case (KeyPress<<8)+0x11: case (KeyRelease<<8)+0x11: return MAKINUM(((XKeyEvent *) x)->serial);
case (KeyPress<<8)+0x12: case (KeyRelease<<8)+0x12: return x_make_bool(((XKeyEvent *) x)->send_event);
case (KeyPress<<8)+0x13: case (KeyRelease<<8)+0x13: return ulong2num(((XKeyEvent *) x)->time);
case (KeyPress<<8)+0x14: case (KeyRelease<<8)+0x14: return MAKINUM(((XKeyEvent *) x)->x);
case (KeyPress<<8)+0x15: case (KeyRelease<<8)+0x15: return MAKINUM(((XKeyEvent *) x)->y);
case (KeyPress<<8)+0x16: case (KeyRelease<<8)+0x16: return MAKINUM(((XKeyEvent *) x)->x_root);
case (KeyPress<<8)+0x17: case (KeyRelease<<8)+0x17: return MAKINUM(((XKeyEvent *) x)->y_root);
case (KeyPress<<8)+0x18: case (KeyRelease<<8)+0x18: return MAKINUM(((XKeyEvent *) x)->state);
case (KeyPress<<8)+0x19: case (KeyRelease<<8)+0x19: return MAKINUM(((XKeyEvent *) x)->keycode);
case (KeyPress<<8)+0x1a: case (KeyRelease<<8)+0x1a: return x_make_bool(((XKeyEvent *) x)->same_screen);
case (ButtonPress<<8)+0x10: case (ButtonRelease<<8)+0x10: return MAKINUM(((XButtonEvent *) x)->type);
case (ButtonPress<<8)+0x11: case (ButtonRelease<<8)+0x11: return MAKINUM(((XButtonEvent *) x)->serial);
case (ButtonPress<<8)+0x12: case (ButtonRelease<<8)+0x12: return x_make_bool(((XButtonEvent *) x)->send_event);
case (ButtonPress<<8)+0x13: case (ButtonRelease<<8)+0x13: return ulong2num(((XButtonEvent *) x)->time);
case (ButtonPress<<8)+0x14: case (ButtonRelease<<8)+0x14: return MAKINUM(((XButtonEvent *) x)->x);
case (ButtonPress<<8)+0x15: case (ButtonRelease<<8)+0x15: return MAKINUM(((XButtonEvent *) x)->y);
case (ButtonPress<<8)+0x16: case (ButtonRelease<<8)+0x16: return MAKINUM(((XButtonEvent *) x)->x_root);
case (ButtonPress<<8)+0x17: case (ButtonRelease<<8)+0x17: return MAKINUM(((XButtonEvent *) x)->y_root);
case (ButtonPress<<8)+0x18: case (ButtonRelease<<8)+0x18: return MAKINUM(((XButtonEvent *) x)->state);
case (ButtonPress<<8)+0x1b: case (ButtonRelease<<8)+0x1b: return MAKINUM(((XButtonEvent *) x)->button);
case (ButtonPress<<8)+0x1a: case (ButtonRelease<<8)+0x1a: return x_make_bool(((XButtonEvent *) x)->same_screen);
case (MotionNotify<<8)+0x10: return MAKINUM(((XMotionEvent *) x)->type);
case (MotionNotify<<8)+0x11: return MAKINUM(((XMotionEvent *) x)->serial);
case (MotionNotify<<8)+0x12: return x_make_bool(((XMotionEvent *) x)->send_event);
case (MotionNotify<<8)+0x13: return ulong2num(((XMotionEvent *) x)->time);
case (MotionNotify<<8)+0x14: return MAKINUM(((XMotionEvent *) x)->x);
case (MotionNotify<<8)+0x15: return MAKINUM(((XMotionEvent *) x)->y);
case (MotionNotify<<8)+0x16: return MAKINUM(((XMotionEvent *) x)->x_root);
case (MotionNotify<<8)+0x17: return MAKINUM(((XMotionEvent *) x)->y_root);
case (MotionNotify<<8)+0x18: return MAKINUM(((XMotionEvent *) x)->state);
case (MotionNotify<<8)+0x1c: return MAKINUM(((XMotionEvent *) x)->is_hint);
case (MotionNotify<<8)+0x1a: return x_make_bool(((XMotionEvent *) x)->same_screen);
case (EnterNotify<<8)+0x10: case (LeaveNotify<<8)+0x10: return MAKINUM(((XCrossingEvent *) x)->type);
case (EnterNotify<<8)+0x11: case (LeaveNotify<<8)+0x11: return MAKINUM(((XCrossingEvent *) x)->serial);
case (EnterNotify<<8)+0x12: case (LeaveNotify<<8)+0x12: return x_make_bool(((XCrossingEvent *) x)->send_event);
case (EnterNotify<<8)+0x13: case (LeaveNotify<<8)+0x13: return ulong2num(((XCrossingEvent *) x)->time);
case (EnterNotify<<8)+0x14: case (LeaveNotify<<8)+0x14: return MAKINUM(((XCrossingEvent *) x)->x);
case (EnterNotify<<8)+0x15: case (LeaveNotify<<8)+0x15: return MAKINUM(((XCrossingEvent *) x)->y);
case (EnterNotify<<8)+0x16: case (LeaveNotify<<8)+0x16: return MAKINUM(((XCrossingEvent *) x)->x_root);
case (EnterNotify<<8)+0x17: case (LeaveNotify<<8)+0x17: return MAKINUM(((XCrossingEvent *) x)->y_root);
case (EnterNotify<<8)+0x1d: case (LeaveNotify<<8)+0x1d: return MAKINUM(((XCrossingEvent *) x)->mode);
case (EnterNotify<<8)+0x1e: case (LeaveNotify<<8)+0x1e: return MAKINUM(((XCrossingEvent *) x)->detail);
case (EnterNotify<<8)+0x1a: case (LeaveNotify<<8)+0x1a: return x_make_bool(((XCrossingEvent *) x)->same_screen);
case (EnterNotify<<8)+0x1f: case (LeaveNotify<<8)+0x1f: return x_make_bool(((XCrossingEvent *) x)->focus);
case (EnterNotify<<8)+0x18: case (LeaveNotify<<8)+0x18: return MAKINUM(((XCrossingEvent *) x)->state);
case (FocusIn<<8)+0x10: case (FocusOut<<8)+0x10: return MAKINUM(((XFocusChangeEvent *) x)->type);
case (FocusIn<<8)+0x11: case (FocusOut<<8)+0x11: return MAKINUM(((XFocusChangeEvent *) x)->serial);
case (FocusIn<<8)+0x12: case (FocusOut<<8)+0x12: return x_make_bool(((XFocusChangeEvent *) x)->send_event);
case (FocusIn<<8)+0x1d: case (FocusOut<<8)+0x1d: return MAKINUM(((XFocusChangeEvent *) x)->mode);
case (FocusIn<<8)+0x1e: case (FocusOut<<8)+0x1e: return MAKINUM(((XFocusChangeEvent *) x)->detail);
case (KeymapNotify<<8)+0x10: return MAKINUM(((XKeymapEvent *) x)->type);
case (KeymapNotify<<8)+0x11: return MAKINUM(((XKeymapEvent *) x)->serial);
case (KeymapNotify<<8)+0x12: return x_make_bool(((XKeymapEvent *) x)->send_event);
case (Expose<<8)+0x10: return MAKINUM(((XExposeEvent *) x)->type);
case (Expose<<8)+0x11: return MAKINUM(((XExposeEvent *) x)->serial);
case (Expose<<8)+0x12: return x_make_bool(((XExposeEvent *) x)->send_event);
case (Expose<<8)+0x14: return MAKINUM(((XExposeEvent *) x)->x);
case (Expose<<8)+0x15: return MAKINUM(((XExposeEvent *) x)->y);
case (Expose<<8)+0x20: return MAKINUM(((XExposeEvent *) x)->width);
case (Expose<<8)+0x21: return MAKINUM(((XExposeEvent *) x)->height);
case (Expose<<8)+0x22: return MAKINUM(((XExposeEvent *) x)->count);
case (GraphicsExpose<<8)+0x10: return MAKINUM(((XGraphicsExposeEvent *) x)->type);
case (GraphicsExpose<<8)+0x11: return MAKINUM(((XGraphicsExposeEvent *) x)->serial);
case (GraphicsExpose<<8)+0x12: return x_make_bool(((XGraphicsExposeEvent *) x)->send_event);
case (GraphicsExpose<<8)+0x14: return MAKINUM(((XGraphicsExposeEvent *) x)->x);
case (GraphicsExpose<<8)+0x15: return MAKINUM(((XGraphicsExposeEvent *) x)->y);
case (GraphicsExpose<<8)+0x20: return MAKINUM(((XGraphicsExposeEvent *) x)->width);
case (GraphicsExpose<<8)+0x21: return MAKINUM(((XGraphicsExposeEvent *) x)->height);
case (GraphicsExpose<<8)+0x22: return MAKINUM(((XGraphicsExposeEvent *) x)->count);
case (GraphicsExpose<<8)+0x23: return MAKINUM(((XGraphicsExposeEvent *) x)->major_code);
case (GraphicsExpose<<8)+0x24: return MAKINUM(((XGraphicsExposeEvent *) x)->minor_code);
case (NoExpose<<8)+0x10: return MAKINUM(((XNoExposeEvent *) x)->type);
case (NoExpose<<8)+0x11: return MAKINUM(((XNoExposeEvent *) x)->serial);
case (NoExpose<<8)+0x12: return x_make_bool(((XNoExposeEvent *) x)->send_event);
case (NoExpose<<8)+0x23: return MAKINUM(((XNoExposeEvent *) x)->major_code);
case (NoExpose<<8)+0x24: return MAKINUM(((XNoExposeEvent *) x)->minor_code);
case (VisibilityNotify<<8)+0x10: return MAKINUM(((XVisibilityEvent *) x)->type);
case (VisibilityNotify<<8)+0x11: return MAKINUM(((XVisibilityEvent *) x)->serial);
case (VisibilityNotify<<8)+0x12: return x_make_bool(((XVisibilityEvent *) x)->send_event);
case (VisibilityNotify<<8)+0x18: return MAKINUM(((XVisibilityEvent *) x)->state);
case (CreateNotify<<8)+0x10: return MAKINUM(((XCreateWindowEvent *) x)->type);
case (CreateNotify<<8)+0x11: return MAKINUM(((XCreateWindowEvent *) x)->serial);
case (CreateNotify<<8)+0x12: return x_make_bool(((XCreateWindowEvent *) x)->send_event);
case (CreateNotify<<8)+0x14: return MAKINUM(((XCreateWindowEvent *) x)->x);
case (CreateNotify<<8)+0x15: return MAKINUM(((XCreateWindowEvent *) x)->y);
case (CreateNotify<<8)+0x20: return MAKINUM(((XCreateWindowEvent *) x)->width);
case (CreateNotify<<8)+0x21: return MAKINUM(((XCreateWindowEvent *) x)->height);
case (CreateNotify<<8)+0x25: return MAKINUM(((XCreateWindowEvent *) x)->border_width);
case (CreateNotify<<8)+0x26: return x_make_bool(((XCreateWindowEvent *) x)->override_redirect);
case (DestroyNotify<<8)+0x10: return MAKINUM(((XDestroyWindowEvent *) x)->type);
case (DestroyNotify<<8)+0x11: return MAKINUM(((XDestroyWindowEvent *) x)->serial);
case (DestroyNotify<<8)+0x12: return x_make_bool(((XDestroyWindowEvent *) x)->send_event);
case (UnmapNotify<<8)+0x10: return MAKINUM(((XUnmapEvent *) x)->type);
case (UnmapNotify<<8)+0x11: return MAKINUM(((XUnmapEvent *) x)->serial);
case (UnmapNotify<<8)+0x12: return x_make_bool(((XUnmapEvent *) x)->send_event);
case (UnmapNotify<<8)+0x27: return x_make_bool(((XUnmapEvent *) x)->from_configure);
case (MapNotify<<8)+0x10: return MAKINUM(((XMapEvent *) x)->type);
case (MapNotify<<8)+0x11: return MAKINUM(((XMapEvent *) x)->serial);
case (MapNotify<<8)+0x12: return x_make_bool(((XMapEvent *) x)->send_event);
case (MapNotify<<8)+0x26: return x_make_bool(((XMapEvent *) x)->override_redirect);
case (MapRequest<<8)+0x10: return MAKINUM(((XMapRequestEvent *) x)->type);
case (MapRequest<<8)+0x11: return MAKINUM(((XMapRequestEvent *) x)->serial);
case (MapRequest<<8)+0x12: return x_make_bool(((XMapRequestEvent *) x)->send_event);
case (ReparentNotify<<8)+0x10: return MAKINUM(((XReparentEvent *) x)->type);
case (ReparentNotify<<8)+0x11: return MAKINUM(((XReparentEvent *) x)->serial);
case (ReparentNotify<<8)+0x12: return x_make_bool(((XReparentEvent *) x)->send_event);
case (ReparentNotify<<8)+0x14: return MAKINUM(((XReparentEvent *) x)->x);
case (ReparentNotify<<8)+0x15: return MAKINUM(((XReparentEvent *) x)->y);
case (ReparentNotify<<8)+0x26: return x_make_bool(((XReparentEvent *) x)->override_redirect);
case (ConfigureNotify<<8)+0x10: return MAKINUM(((XConfigureEvent *) x)->type);
case (ConfigureNotify<<8)+0x11: return MAKINUM(((XConfigureEvent *) x)->serial);
case (ConfigureNotify<<8)+0x12: return x_make_bool(((XConfigureEvent *) x)->send_event);
case (ConfigureNotify<<8)+0x14: return MAKINUM(((XConfigureEvent *) x)->x);
case (ConfigureNotify<<8)+0x15: return MAKINUM(((XConfigureEvent *) x)->y);
case (ConfigureNotify<<8)+0x20: return MAKINUM(((XConfigureEvent *) x)->width);
case (ConfigureNotify<<8)+0x21: return MAKINUM(((XConfigureEvent *) x)->height);
case (ConfigureNotify<<8)+0x25: return MAKINUM(((XConfigureEvent *) x)->border_width);
case (ConfigureNotify<<8)+0x26: return x_make_bool(((XConfigureEvent *) x)->override_redirect);
case (GravityNotify<<8)+0x10: return MAKINUM(((XGravityEvent *) x)->type);
case (GravityNotify<<8)+0x11: return MAKINUM(((XGravityEvent *) x)->serial);
case (GravityNotify<<8)+0x12: return x_make_bool(((XGravityEvent *) x)->send_event);
case (GravityNotify<<8)+0x14: return MAKINUM(((XGravityEvent *) x)->x);
case (GravityNotify<<8)+0x15: return MAKINUM(((XGravityEvent *) x)->y);
case (ResizeRequest<<8)+0x10: return MAKINUM(((XResizeRequestEvent *) x)->type);
case (ResizeRequest<<8)+0x11: return MAKINUM(((XResizeRequestEvent *) x)->serial);
case (ResizeRequest<<8)+0x12: return x_make_bool(((XResizeRequestEvent *) x)->send_event);
case (ResizeRequest<<8)+0x20: return MAKINUM(((XResizeRequestEvent *) x)->width);
case (ResizeRequest<<8)+0x21: return MAKINUM(((XResizeRequestEvent *) x)->height);
case (ConfigureRequest<<8)+0x10: return MAKINUM(((XConfigureRequestEvent *) x)->type);
case (ConfigureRequest<<8)+0x11: return MAKINUM(((XConfigureRequestEvent *) x)->serial);
case (ConfigureRequest<<8)+0x12: return x_make_bool(((XConfigureRequestEvent *) x)->send_event);
case (ConfigureRequest<<8)+0x14: return MAKINUM(((XConfigureRequestEvent *) x)->x);
case (ConfigureRequest<<8)+0x15: return MAKINUM(((XConfigureRequestEvent *) x)->y);
case (ConfigureRequest<<8)+0x20: return MAKINUM(((XConfigureRequestEvent *) x)->width);
case (ConfigureRequest<<8)+0x21: return MAKINUM(((XConfigureRequestEvent *) x)->height);
case (ConfigureRequest<<8)+0x25: return MAKINUM(((XConfigureRequestEvent *) x)->border_width);
case (ConfigureRequest<<8)+0x1e: return MAKINUM(((XConfigureRequestEvent *) x)->detail);
case (ConfigureRequest<<8)+0x28: return MAKINUM(((XConfigureRequestEvent *) x)->value_mask);
case (CirculateNotify<<8)+0x10: return MAKINUM(((XCirculateEvent *) x)->type);
case (CirculateNotify<<8)+0x11: return MAKINUM(((XCirculateEvent *) x)->serial);
case (CirculateNotify<<8)+0x12: return x_make_bool(((XCirculateEvent *) x)->send_event);
case (CirculateNotify<<8)+0x29: return MAKINUM(((XCirculateEvent *) x)->place);
case (CirculateRequest<<8)+0x10: return MAKINUM(((XCirculateRequestEvent *) x)->type);
case (CirculateRequest<<8)+0x11: return MAKINUM(((XCirculateRequestEvent *) x)->serial);
case (CirculateRequest<<8)+0x12: return x_make_bool(((XCirculateRequestEvent *) x)->send_event);
case (CirculateRequest<<8)+0x29: return MAKINUM(((XCirculateRequestEvent *) x)->place);
case (PropertyNotify<<8)+0x10: return MAKINUM(((XPropertyEvent *) x)->type);
case (PropertyNotify<<8)+0x11: return MAKINUM(((XPropertyEvent *) x)->serial);
case (PropertyNotify<<8)+0x12: return x_make_bool(((XPropertyEvent *) x)->send_event);
case (PropertyNotify<<8)+0x13: return ulong2num(((XPropertyEvent *) x)->time);
case (PropertyNotify<<8)+0x18: return MAKINUM(((XPropertyEvent *) x)->state);
case (SelectionClear<<8)+0x10: return MAKINUM(((XSelectionClearEvent *) x)->type);
case (SelectionClear<<8)+0x11: return MAKINUM(((XSelectionClearEvent *) x)->serial);
case (SelectionClear<<8)+0x12: return x_make_bool(((XSelectionClearEvent *) x)->send_event);
case (SelectionClear<<8)+0x13: return ulong2num(((XSelectionClearEvent *) x)->time);
case (SelectionRequest<<8)+0x10: return MAKINUM(((XSelectionRequestEvent *) x)->type);
case (SelectionRequest<<8)+0x11: return MAKINUM(((XSelectionRequestEvent *) x)->serial);
case (SelectionRequest<<8)+0x12: return x_make_bool(((XSelectionRequestEvent *) x)->send_event);
case (SelectionRequest<<8)+0x13: return ulong2num(((XSelectionRequestEvent *) x)->time);
case (SelectionNotify<<8)+0x10: return MAKINUM(((XSelectionEvent *) x)->type);
case (SelectionNotify<<8)+0x11: return MAKINUM(((XSelectionEvent *) x)->serial);
case (SelectionNotify<<8)+0x12: return x_make_bool(((XSelectionEvent *) x)->send_event);
case (SelectionNotify<<8)+0x13: return ulong2num(((XSelectionEvent *) x)->time);
case (ColormapNotify<<8)+0x10: return MAKINUM(((XColormapEvent *) x)->type);
case (ColormapNotify<<8)+0x11: return MAKINUM(((XColormapEvent *) x)->serial);
case (ColormapNotify<<8)+0x12: return x_make_bool(((XColormapEvent *) x)->send_event);
case (ColormapNotify<<8)+0x2a: return x_make_bool(((XColormapEvent *) x)->new);
case (ColormapNotify<<8)+0x18: return MAKINUM(((XColormapEvent *) x)->state);
case (ClientMessage<<8)+0x10: return MAKINUM(((XClientMessageEvent *) x)->type);
case (ClientMessage<<8)+0x11: return MAKINUM(((XClientMessageEvent *) x)->serial);
case (ClientMessage<<8)+0x12: return x_make_bool(((XClientMessageEvent *) x)->send_event);
case (ClientMessage<<8)+0x2b: return MAKINUM(((XClientMessageEvent *) x)->format);
case (MappingNotify<<8)+0x10: return MAKINUM(((XMappingEvent *) x)->type);
case (MappingNotify<<8)+0x11: return MAKINUM(((XMappingEvent *) x)->serial);
case (MappingNotify<<8)+0x12: return x_make_bool(((XMappingEvent *) x)->send_event);
case (MappingNotify<<8)+0x2c: return MAKINUM(((XMappingEvent *) x)->request);
case (MappingNotify<<8)+0x2d: return MAKINUM(((XMappingEvent *) x)->first_keycode);
case (MappingNotify<<8)+0x22: return MAKINUM(((XMappingEvent *) x)->count);
#else
{MotionNotify, "MotionNotify"},
{KeyPress, "KeyPress"},
{KeyRelease, "KeyRelease"},
{ButtonPress, "ButtonPress"},
{ButtonRelease, "ButtonRelease"},
{MotionNotify, "MotionNotify"},
{EnterNotify, "EnterNotify"},
{LeaveNotify, "LeaveNotify"},
{FocusIn, "FocusIn"},
{FocusOut, "FocusOut"},
{KeymapNotify, "KeymapNotify"},
{Expose, "Expose"},
{GraphicsExpose, "GraphicsExpose"},
{NoExpose, "NoExpose"},
{VisibilityNotify, "VisibilityNotify"},
{CreateNotify, "CreateNotify"},
{DestroyNotify, "DestroyNotify"},
{UnmapNotify, "UnmapNotify"},
{MapNotify, "MapNotify"},
{MapRequest, "MapRequest"},
{ReparentNotify, "ReparentNotify"},
{ConfigureNotify, "ConfigureNotify"},
{ConfigureRequest, "ConfigureRequest"},
{GravityNotify, "GravityNotify"},
{ResizeRequest, "ResizeRequest"},
{CirculateNotify, "CirculateNotify"},
{CirculateRequest, "CirculateRequest"},
{PropertyNotify, "PropertyNotify"},
{SelectionClear, "SelectionClear"},
{SelectionRequest, "SelectionRequest"},
{SelectionNotify, "SelectionNotify"},
{ColormapNotify, "ColormapNotify"},
{ClientMessage, "ClientMessage"},
{MappingNotify, "MappingNotify"},
#endif
scm-5f4/subr.c 0000644 0001750 0001750 00000167157 14505673610 010324 0000000 0000000 /* "subr.c" integer and other Scheme procedures
* Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2013 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* .
*/
/* Author: Aubrey Jaffer */
#include
#include "scm.h"
#define s_length (s_st_length+7)
#define s_append (s_st_append+7)
char s_make_string[] = "make-string";
char s_list[] = "list";
static char s_setcar[] = "set-car!", s_setcdr[] = "set-cdr!",
s_reverse[] = "reverse", s_list_ref[] = "list-ref";
static char s_memq[] = "memq", s_member[] = "member",
s_assq[] = "assq", s_assoc[] = "assoc";
static char s_symbol2string[] = "symbol->string",
s_str2symbol[] = "string->symbol";
extern char s_inexactp[];
#define s_exactp (s_inexactp+2)
static char s_oddp[] = "odd?", s_evenp[] = "even?";
static char s_rquotient[] = "round-quotient",
s_remainder[] = "remainder", s_modulo[] = "modulo";
static char s_gcd[] = "gcd";
#define s_quotient (s_rquotient+6)
static char s_ci_eq[] = "char-ci=?",
s_ch_lessp[] = "char", s_ch_leqp[] = "char<=?",
s_ci_lessp[] = "char-ci", s_ci_leqp[] = "char-ci<=?",
s_ch_grp[] = "char>?", s_ch_geqp[] = "char>=?",
s_ci_grp[] = "char-ci>?", s_ci_geqp[] = "char-ci>=?";
static char s_ch_alphap[] = "char-alphabetic?",
s_ch_nump[] = "char-numeric?",
s_ch_whitep[] = "char-whitespace?",
s_ch_upperp[] = "char-upper-case?",
s_ch_lowerp[] = "char-lower-case?";
static char s_char2int[] = "char->integer", s_int2char[] = "integer->char",
s_ch_upcase[] = "char-upcase", s_ch_downcase[] = "char-downcase";
static char s_st_length[] = "string-length",
s_st_ref[] = "string-ref", s_st_set[] = "string-set!";
static char s_st_equal[] = "string=?", s_stci_equal[] = "string-ci=?",
s_st_lessp[] = "string", s_stci_lessp[] = "string-ci";
static char s_substring[] = "substring", s_st_append[] = "string-append";
static char s_ve_length[] = "vector-length",
s_ve_ref[] = "vector-ref", s_ve_set[] = "vector-set!";
SCM lnot(x)
SCM x;
{
return FALSEP(x) ? BOOL_T : BOOL_F;
}
SCM booleanp(obj)
SCM obj;
{
if (BOOL_F==obj) return BOOL_T;
if (BOOL_T==obj) return BOOL_T;
return BOOL_F;
}
SCM eq(x, y)
SCM x, y;
{
if (x==y) return BOOL_T;
else return BOOL_F;
}
SCM consp(x)
SCM x;
{
if (IMP(x)) return BOOL_F;
return CONSP(x) ? BOOL_T : BOOL_F;
}
SCM setcar(pair, value)
SCM pair, value;
{
ASRTER(NIMP(pair) && CONSP(pair), pair, ARG1, s_setcar);
CAR(pair) = value;
return UNSPECIFIED;
}
SCM setcdr(pair, value)
SCM pair, value;
{
ASRTER(NIMP(pair) && CONSP(pair), pair, ARG1, s_setcdr);
CDR(pair) = value;
return UNSPECIFIED;
}
SCM nullp(x)
SCM x;
{
return NULLP(x) ? BOOL_T : BOOL_F;
}
long ilength(sx)
SCM sx;
{
register long i = 0;
register SCM x = sx;
do {
if (IMP(x)) return NULLP(x) ? i : -1;
if (NCONSP(x)) return -2;
x = CDR(x);
i++;
if (IMP(x)) return NULLP(x) ? i : -1;
if (NCONSP(x)) return -2;
x = CDR(x);
i++;
sx = CDR(sx);
}
while (x != sx);
return -1;
}
SCM listp(x)
SCM x;
{
if (ilength(x)<0) return BOOL_F;
else return BOOL_T;
}
SCM list(objs)
SCM objs;
{
return objs;
}
SCM length(x)
SCM x;
{
SCM i = MAKINUM(ilength(x));
ASRTER(i >= INUM0, x, ARG1, s_length);
return i;
}
SCM append(args)
SCM args;
{
SCM res = EOL;
SCM *lloc = &res, arg;
if (IMP(args)) {
ASRTER(NULLP(args), args, ARGn, s_append);
return res;
}
ASRTER(CONSP(args), args, ARGn, s_append);
while (1) {
arg = CAR(args);
args = CDR(args);
if (IMP(args)) {
*lloc = arg;
ASRTER(NULLP(args), args, ARGn, s_append);
return res;
}
ASRTER(CONSP(args), args, ARGn, s_append);
for (;NIMP(arg);arg = CDR(arg)) {
ASRTER(CONSP(arg), arg, ARGn, s_append);
*lloc = cons(CAR(arg), EOL);
lloc = &CDR(*lloc);
}
ASRTER(NULLP(arg), arg, ARGn, s_append);
}
}
SCM reverse(lst)
SCM lst;
{
SCM res = EOL;
SCM p = lst;
for (;NIMP(p);p = CDR(p)) {
ASRTER(CONSP(p), lst, ARG1, s_reverse);
res = cons(CAR(p), res);
}
ASRTER(NULLP(p), lst, ARG1, s_reverse);
return res;
}
SCM list_ref(lst, k)
SCM lst, k;
{
register long i;
ASRTER(INUMP(k), k, ARG2, s_list_ref);
i = INUM(k);
ASRTER(i >= 0, k, ARG2, s_list_ref);
while (i-- > 0) {
ASRTGO(NIMP(lst) && CONSP(lst), erout);
lst = CDR(lst);
}
erout: ASRTER(NIMP(lst) && CONSP(lst),
NULLP(lst)?k:lst, NULLP(lst)?OUTOFRANGE:ARG1, s_list_ref);
return CAR(lst);
}
SCM memq(x, lst)
SCM x, lst;
{
for (;NIMP(lst);lst = CDR(lst)) {
ASRTER(CONSP(lst), lst, ARG2, s_memq);
if (CAR(lst)==x) return lst;
}
ASRTER(NULLP(lst), lst, ARG2, s_memq);
return BOOL_F;
}
SCM member(x, lst)
SCM x, lst;
{
for (;NIMP(lst);lst = CDR(lst)) {
ASRTER(CONSP(lst), lst, ARG2, s_member);
if (NFALSEP(equal(CAR(lst), x))) return lst;
}
ASRTER(NULLP(lst), lst, ARG2, s_member);
return BOOL_F;
}
SCM assq(x, alist)
SCM x, alist;
{
SCM tmp;
for (;NIMP(alist);alist = CDR(alist)) {
ASRTER(CONSP(alist), alist, ARG2, s_assq);
tmp = CAR(alist);
ASRTER(NIMP(tmp) && CONSP(tmp), alist, ARG2, s_assq);
if (CAR(tmp)==x) return tmp;
}
ASRTER(NULLP(alist), alist, ARG2, s_assq);
return BOOL_F;
}
SCM assoc(x, alist)
SCM x, alist;
{
SCM tmp;
for (;NIMP(alist);alist = CDR(alist)) {
ASRTER(CONSP(alist), alist, ARG2, s_assoc);
tmp = CAR(alist);
ASRTER(NIMP(tmp) && CONSP(tmp), alist, ARG2, s_assoc);
if (NFALSEP(equal(CAR(tmp), x))) return tmp;
}
ASRTER(NULLP(alist), alist, ARG2, s_assoc);
return BOOL_F;
}
extern long tc16_promise;
SCM promisep(x)
SCM x;
{
return NIMP(x) && (TYP16(x)==tc16_promise) ? BOOL_T : BOOL_F;
}
SCM symbolp(x)
SCM x;
{
if (IMP(x)) return BOOL_F;
return SYMBOLP(x) ? BOOL_T : BOOL_F;
}
SCM symbol2string(s)
SCM s;
{
ASRTER(NIMP(s) && SYMBOLP(s), s, ARG1, s_symbol2string);
return makfromstr(CHARS(s), (sizet)LENGTH(s));
}
SCM string2symbol(s)
SCM s;
{
ASRTER(NIMP(s) && STRINGP(s), s, ARG1, s_str2symbol);
s = intern(CHARS(s), (sizet)LENGTH(s));
return CAR(s);
}
SCM exactp(x)
SCM x;
{
if (INUMP(x)) return BOOL_T;
#ifdef BIGDIG
if (NIMP(x) && BIGP(x)) return BOOL_T;
#endif
return BOOL_F;
}
SCM oddp(n)
SCM n;
{
#ifdef BIGDIG
if (NINUMP(n)) {
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_oddp);
return (1 & BDIGITS(n)[0]) ? BOOL_T : BOOL_F;
}
#else
ASRTER(INUMP(n), n, ARG1, s_oddp);
#endif
return (4 & (int)n) ? BOOL_T : BOOL_F;
}
SCM evenp(n)
SCM n;
{
#ifdef BIGDIG
if (NINUMP(n)) {
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_evenp);
return (1 & BDIGITS(n)[0]) ? BOOL_F : BOOL_T;
}
#else
ASRTER(INUMP(n), n, ARG1, s_evenp);
#endif
return (4 & (int)n) ? BOOL_F : BOOL_T;
}
SCM scm_round_quotient(num, den)
SCM num, den;
{
register long quo, rem;
/* if (scm_verbose > 1) */
/* printf("%s / %s\n", */
/* CHARS(number2string(num, MAKINUM(10))), */
/* CHARS(number2string(den, MAKINUM(10)))); */
#ifdef BIGDIG
if (NINUMP(num)) {
long w;
ASRTER(NIMP(num) && BIGP(num), num, ARG1, s_rquotient);
if (NINUMP(den)) {
ASRTGO(NIMP(den) && BIGP(den), badden);
return divbigbig(BDIGITS(num), NUMDIGS(num), BDIGITS(den), NUMDIGS(den),
BIGSIGN(num) ^ BIGSIGN(den), 3);
}
if (!(quo = INUM(den))) goto ov;
if (1==quo) return num;
/* divbigdig() hasn't been extended to perform rounding */
/* if (quo < 0) quo = -quo; */
/* if (quo < BIGRAD) { */
/* w = copybig(num, BIGSIGN(num) ? (den>0) : (den<0)); */
/* divbigdig(BDIGITS(w), NUMDIGS(w), (BIGDIG)quo); */
/* return normbig(w); */
/* } */
# ifndef DIGSTOOBIG
w = pseudolong(quo);
return divbigbig(BDIGITS(num), NUMDIGS(num), (BIGDIG *)&w, DIGSPERLONG,
BIGSIGN(num) ? (den>0) : (den<0), 3);
# else
{ BIGDIG quodigs[DIGSPERLONG];
longdigs(quo, quodigs);
return divbigbig(BDIGITS(num), NUMDIGS(num), quodigs, DIGSPERLONG,
BIGSIGN(num) ? (den>0) : (den<0), 3);
}
# endif
}
if (NINUMP(den)) {
# ifndef RECKLESS
if (!(NIMP(den) && BIGP(den)))
badden: wta(den, (char *)ARG2, s_rquotient);
# endif
if (NUMDIGS(den) > DIGSPERLONG ||
(NUMDIGS(den)==DIGSPERLONG && BDIGITS(den)[DIGSPERLONG-1] >= BIGRAD/2))
return INUM0;
quo = num2long(den, (char *)ARG2, s_rquotient);
rem = INUM(num)%quo;
if (labs(2*rem) > labs(quo))
return MAKINUM(((INUM(num) < 0)==(quo < 0)) ? 1 : -1);
else return INUM0;
}
#else
ASRTER(INUMP(num), num, ARG1, s_rquotient);
ASRTER(INUMP(den), den, ARG2, s_rquotient);
#endif
if ((quo = INUM(den))==0)
ov: wta(den, (char *)OVFLOW, s_rquotient);
quo = INUM(num)/quo;
{
# if (__TURBOC__==1)
rem = ((den<0) ? -INUM(num) : INUM(num))%INUM(den);
# else
rem = INUM(num)%INUM(den);
# endif
#ifdef BADIVSGNS
if (rem==0) ;
else if (rem < 0) {
if (num < 0) ;
else quo--;
} else if (num < 0) quo++;
#endif
if ((1 & quo)
? labs(2*rem) >= labs(INUM(den))
: labs(2*rem) > labs(INUM(den)))
quo = quo + (((INUM(num) < 0)==(INUM(den) < 0)) ? 1 : -1);
}
if (!FIXABLE(quo))
#ifdef BIGDIG
return long2big(quo);
#else
wta(num, (char *)OVFLOW, s_rquotient);
#endif
return MAKINUM(quo);
}
/* SCM scm_round_quotient(num, den) */
/* SCM num, den; */
/* { */
/* SCM quo = lquotient(num, den); */
/* SCM rem = lremainder(num, den); */
/* if (BOOL_T==((BOOL_T==evenp(quo) ? greaterp : greqp) */
/* (scm_ash(scm_iabs(rem), MAKINUM(1L)), scm_iabs(den)))) */
/* quo = sum(quo, MAKINUM(negativep(num)==negativep(den) ? 1L : -1L)); */
/* return quo; */
/* } */
SCM lquotient(x, y)
SCM x, y;
{
register long z;
#ifdef BIGDIG
if (NINUMP(x)) {
long w;
ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_quotient);
if (NINUMP(y)) {
ASRTGO(NIMP(y) && BIGP(y), bady);
return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y),
BIGSIGN(x) ^ BIGSIGN(y), 2);
}
if (!(z = INUM(y))) goto ov;
if (1==z) return x;
if (z < 0) z = -z;
if (z < BIGRAD) {
w = copybig(x, BIGSIGN(x) ? (y>0) : (y<0));
divbigdig(BDIGITS(w), NUMDIGS(w), (BIGDIG)z);
return normbig(w);
}
# ifndef DIGSTOOBIG
w = pseudolong(z);
return divbigbig(BDIGITS(x), NUMDIGS(x), (BIGDIG *)&w, DIGSPERLONG,
BIGSIGN(x) ? (y>0) : (y<0), 2);
# else
{ BIGDIG zdigs[DIGSPERLONG];
longdigs(z, zdigs);
return divbigbig(BDIGITS(x), NUMDIGS(x), zdigs, DIGSPERLONG,
BIGSIGN(x) ? (y>0) : (y<0), 2);
}
# endif
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_quotient);
# endif
return INUM0;
}
#else
ASRTER(INUMP(x), x, ARG1, s_quotient);
ASRTER(INUMP(y), y, ARG2, s_quotient);
#endif
if ((z = INUM(y))==0)
ov: wta(y, (char *)OVFLOW, s_quotient);
z = INUM(x)/z;
#ifdef BADIVSGNS
{
# if (__TURBOC__==1)
long t = ((y<0) ? -INUM(x) : INUM(x))%INUM(y);
# else
long t = INUM(x)%INUM(y);
# endif
if (t==0) ;
else if (t < 0)
if (x < 0) ;
else z--;
else if (x < 0) z++;
}
#endif
if (!FIXABLE(z))
#ifdef BIGDIG
return long2big(z);
#else
wta(x, (char *)OVFLOW, s_quotient);
#endif
return MAKINUM(z);
}
SCM lremainder(x, y)
SCM x, y;
{
register long z;
#ifdef BIGDIG
if (NINUMP(x)) {
ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_remainder);
if (NINUMP(y)) {
ASRTGO(NIMP(y) && BIGP(y), bady);
return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y),
BIGSIGN(x), 0);
}
if (!(z = INUM(y))) goto ov;
return divbigint(x, z, BIGSIGN(x), 0);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_remainder);
# endif
return x;
}
#else
ASRTER(INUMP(x), x, ARG1, s_remainder);
ASRTER(INUMP(y), y, ARG2, s_remainder);
#endif
if (!(z = INUM(y)))
ov: wta(y, (char *)OVFLOW, s_remainder);
#if (__TURBOC__==1)
if (z < 0) z = -z;
#endif
z = INUM(x)%z;
#ifdef BADIVSGNS
if (!z) ;
else if (z < 0)
if (x < 0) ;
else z += INUM(y);
else if (x < 0) z -= INUM(y);
#endif
return MAKINUM(z);
}
SCM modulo(x, y)
SCM x, y;
{
register long yy, z;
#ifdef BIGDIG
if (NINUMP(x)) {
ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_modulo);
if (NINUMP(y)) {
ASRTGO(NIMP(y) && BIGP(y), bady);
return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y),
BIGSIGN(y), (BIGSIGN(x) ^ BIGSIGN(y)) ? 1 : 0);
}
if (!(z = INUM(y))) goto ov;
return divbigint(x, z, z < 0, (BIGSIGN(x) ? (z > 0) : (z < 0)) ? 1 : 0);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_modulo);
# endif
return (BIGSIGN(y) ? (INUM(x)>0) : (INUM(x)<0)) ? sum(x, y) : x;
}
#else
ASRTER(INUMP(x), x, ARG1, s_modulo);
ASRTER(INUMP(y), y, ARG2, s_modulo);
#endif
if (!(yy = INUM(y)))
ov: wta(y, (char *)OVFLOW, s_modulo);
#if (__TURBOC__==1)
z = INUM(x);
z = ((yy<0) ? -z : z)%yy;
#else
z = INUM(x)%yy;
#endif
return MAKINUM(((yy<0) ? (z>0) : (z<0)) ? z+yy : z);
}
SCM lgcd(x, y)
SCM x, y;
{
register long u, v, k, t;
if (UNBNDP(y)) return UNBNDP(x) ? INUM0 : x;
#ifdef BIGDIG
tailrec:
if (NINUMP(x)) {
big_gcd:
ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_gcd);
if (BIGSIGN(x)) x = copybig(x, 0);
newy:
if (NINUMP(y)) {
ASRTER(NIMP(y) && BIGP(y), y, ARG2, s_gcd);
if (BIGSIGN(y)) y = copybig(y, 0);
switch (bigcomp(x, y)) {
case -1:
swaprec: t = lremainder(x, y); x = y; y = t; goto tailrec;
case 0: return x;
case 1: y = lremainder(y, x); goto newy;
}
/* instead of the switch, we could just return lgcd(y, modulo(x, y)); */
}
if (INUM0==y) return x; goto swaprec;
}
if (NINUMP(y)) { t=x; x=y; y=t; goto big_gcd;}
#else
ASRTER(INUMP(x), x, ARG1, s_gcd);
ASRTER(INUMP(y), y, ARG2, s_gcd);
#endif
u = INUM(x);
if (u<0) u = -u;
v = INUM(y);
if (v<0) v = -v;
else if (0==v) goto getout;
if (0==u) {u = v; goto getout;}
for (k = 1;!(1 & ((int)u|(int)v));k <<= 1, u >>= 1, v >>= 1);
if (1 & (int)u) t = -v;
else {
t = u;
b3:
t = SRS(t, 1);
}
if (!(1 & (int)t)) goto b3;
if (t>0) u = t;
else v = -t;
t = u-v;
if (t) goto b3;
u = u*k;
getout:
if (!POSFIXABLE(u))
#ifdef BIGDIG
return long2big(u);
#else
wta(x, (char *)OVFLOW, s_gcd);
#endif
return MAKINUM(u);
}
SCM llcm(n1, n2)
SCM n1, n2;
{
SCM d;
if (UNBNDP(n2)) {
n2 = MAKINUM(1L);
if (UNBNDP(n1)) return n2;
}
d = lgcd(n1, n2);
if (INUM0==d) return d;
return scm_iabs(product(n1, lquotient(n2, d)));
}
/* Emulating 2's complement bignums with sign magnitude arithmetic:
Logand:
X Y Result Method:
(len)
+ + + x (map digit:logand X Y)
+ - + x (map digit:logand X (lognot (+ -1 Y)))
- + + y (map digit:logand (lognot (+ -1 X)) Y)
- - - (+ 1 (map digit:logior (+ -1 X) (+ -1 Y)))
Logior:
X Y Result Method:
+ + + (map digit:logior X Y)
+ - - y (+ 1 (map digit:logand (lognot X) (+ -1 Y)))
- + - x (+ 1 (map digit:logand (+ -1 X) (lognot Y)))
- - - x (+ 1 (map digit:logand (+ -1 X) (+ -1 Y)))
Logxor:
X Y Result Method:
+ + + (map digit:logxor X Y)
+ - - (+ 1 (map digit:logxor X (+ -1 Y)))
- + - (+ 1 (map digit:logxor (+ -1 X) Y))
- - + (map digit:logxor (+ -1 X) (+ -1 Y))
Logtest:
X Y Result
+ + (any digit:logand X Y)
+ - (any digit:logand X (lognot (+ -1 Y)))
- + (any digit:logand (lognot (+ -1 X)) Y)
- - #t
*/
#ifdef BIGDIG
SCM scm_big_ior P((BIGDIG *x, sizet nx, int xsgn, SCM bigy));
SCM scm_big_and P((BIGDIG *x, sizet nx, int xsgn, SCM bigy, int zsgn));
SCM scm_big_xor P((BIGDIG *x, sizet nx, int xsgn, SCM bigy));
SCM scm_big_test P((BIGDIG *x, sizet nx, int xsgn, SCM bigy));
SCM scm_big_ash P((SCM x, int cnt));
SCM scm_copy_big_dec(b, sign)
SCM b;
int sign;
{
long num = -1;
sizet nx = NUMDIGS(b);
sizet i = 0;
SCM ans = mkbig(nx, sign);
BIGDIG *src = BDIGITS(b), *dst = BDIGITS(ans);
if (BIGSIGN(b)) do {
num += src[i];
if (num < 0) {dst[i] = num + BIGRAD; num = -1;}
else {dst[i] = BIGLO(num); num = 0;}
} while (++i < nx);
else
while (nx--) dst[nx] = src[nx];
return ans;
}
SCM scm_copy_smaller(x, nx, zsgn)
BIGDIG *x;
sizet nx;
int zsgn;
{
long num = -1;
sizet i = 0;
SCM z = mkbig(nx, zsgn);
BIGDIG *zds = BDIGITS(z);
if (zsgn) do {
num += x[i];
if (num < 0) {zds[i] = num + BIGRAD; num = -1;}
else {zds[i] = BIGLO(num); num = 0;}
} while (++i < nx);
else do zds[i] = x[i]; while (++i < nx);
return z;
}
SCM scm_big_ior(x, nx, xsgn, bigy)
BIGDIG *x;
SCM bigy;
sizet nx; /* Assumes nx <= NUMDIGS(bigy) */
int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */
{
long num = -1;
sizet i = 0, ny = NUMDIGS(bigy);
SCM z = scm_copy_big_dec(bigy, xsgn & BIGSIGN(bigy));
BIGDIG *zds = BDIGITS(z);
if (xsgn) {
do {
num += x[i];
if (num < 0) {zds[i] |= num + BIGRAD; num = -1;}
else {zds[i] |= BIGLO(num); num = 0;}
} while (++i < nx);
/* ========= Need to increment zds now =========== */
i = 0; num = 1;
while (i < ny) {
num += zds[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
if (!num) return z;
}
adjbig(z, 1 + ny); /* OOPS, overflowed into next digit. */
BDIGITS(z)[ny] = 1;
return z;
}
else do zds[i] = zds[i] | x[i]; while (++i < nx);
return z;
}
SCM scm_big_xor(x, nx, xsgn, bigy)
BIGDIG *x;
SCM bigy;
sizet nx; /* Assumes nx <= NUMDIGS(bigy) */
int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */
{
long num = -1;
sizet i = 0, ny = NUMDIGS(bigy);
SCM z = scm_copy_big_dec(bigy, xsgn ^ BIGSIGN(bigy));
BIGDIG *zds = BDIGITS(z);
if (xsgn) do {
num += x[i];
if (num < 0) {zds[i] ^= num + BIGRAD; num = -1;}
else {zds[i] ^= BIGLO(num); num = 0;}
} while (++i < nx);
else do {
zds[i] = zds[i] ^ x[i];
} while (++i < nx);
if (xsgn ^ BIGSIGN(bigy)) {
/* ========= Need to increment zds now =========== */
i = 0; num = 1;
while (i < ny) {
num += zds[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
if (!num) return normbig(z);
}
}
return normbig(z);
}
SCM scm_big_and(x, nx, xsgn, bigy, zsgn)
BIGDIG *x;
SCM bigy;
sizet nx; /* Assumes nx <= NUMDIGS(bigy) */
int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */
int zsgn; /* return sign equals either 0 or 0x0100 */
{
long num = -1;
sizet i = 0;
SCM z;
BIGDIG *zds;
if (xsgn==zsgn) {
z = scm_copy_smaller(x, nx, zsgn);
x = BDIGITS(bigy);
xsgn = BIGSIGN(bigy);
}
else z = scm_copy_big_dec(bigy, zsgn);
zds = BDIGITS(z);
if (zsgn) {
if (xsgn) do {
num += x[i];
if (num < 0) {zds[i] &= num + BIGRAD; num = -1;}
else {zds[i] &= BIGLO(num); num = 0;}
} while (++i < nx);
else do zds[i] = zds[i] & ~x[i]; while (++i < nx);
/* ========= need to increment zds now =========== */
i = 0; num = 1;
nx = NUMDIGS(z);
while (i < nx) {
num += zds[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
if (!num) return normbig(z);
}
}
else if (xsgn) do {
num += x[i];
if (num < 0) {zds[i] &= ~(num + BIGRAD); num = -1;}
else {zds[i] &= ~BIGLO(num); num = 0;}
} while (++i < nx);
else do zds[i] = zds[i] & x[i]; while (++i < nx);
return normbig(z);
}
SCM scm_big_test(x, nx, xsgn, bigy)
BIGDIG *x;
SCM bigy;
sizet nx; /* Assumes nx <= NUMDIGS(bigy) */
int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */
{
BIGDIG *y;
sizet i = 0;
long num = -1;
if (BIGSIGN(bigy) & xsgn) return BOOL_T;
if (NUMDIGS(bigy) != nx && xsgn) return BOOL_T;
y = BDIGITS(bigy);
if (xsgn)
do {
num += x[i];
if (num < 0) {
if (y[i] & ~(num + BIGRAD)) return BOOL_T;
num = -1;
}
else {
if (y[i] & ~BIGLO(num)) return BOOL_T;
num = 0;
}
} while (++i < nx);
else if (BIGSIGN(bigy))
do {
num += y[i];
if (num < 0) {
if (x[i] & ~(num + BIGRAD)) return BOOL_T;
num = -1;
}
else {
if (x[i] & ~BIGLO(num)) return BOOL_T;
num = 0;
}
} while (++i < nx);
else
do if (x[i] & y[i]) return BOOL_T;
while (++i < nx);
return BOOL_F;
}
static SCM scm_copy_big_2scomp P((SCM x, sizet blen, int sign));
static void scm_2scomp1 P((SCM b));
static SCM scm_copy_big_2scomp(x, blen, sign)
SCM x;
sizet blen;
int sign;
{
sizet nres = (blen + BITSPERDIG - 1)/BITSPERDIG;
SCM res;
BIGDIG *rds;
long num = 0;
sizet i;
if (INUMP(x)) {
long lx = INUM(x);
res = mkbig(nres, sign);
rds = BDIGITS(res);
if (lx < 0) {
lx = -lx;
for (i = 0; i < nres; i++) {
num -= BIGLO(lx);
lx = BIGDN(lx);
if (num < 0) {
rds[i] = num + BIGRAD;
num = -1;
}
else {
rds[i] = num;
num = 0;
}
}
}
else {
for (i = 0; i < nres; i++) {
rds[i] = BIGLO(lx);
lx = BIGDN(lx);
}
}
}
else {
BIGDIG *xds = BDIGITS(x);
sizet nx = NUMDIGS(x);
if (nres < nx)
nres = nx;
res = mkbig(nres, sign);
rds = BDIGITS(res);
if (BIGSIGN(x)) {
for (i = 0; i < nx; i++) {
num -= xds[i];
if (num < 0) {
rds[i] = num + BIGRAD;
num = -1;
}
else {
rds[i] = num;
num = 0;
}
}
for (; i < nres; i++)
rds[i] = BIGRAD - 1;
}
else {
for (i = 0; i < nx; i++)
rds[i] = xds[i];
for (; i < nres; i++)
rds[i] = 0;
}
}
return res;
}
static void scm_2scomp1(b)
SCM b;
{
long num = 0;
sizet i, n = NUMDIGS(b);
BIGDIG *bds = BDIGITS(b);
for (i = 0; i < n; i++) {
num -= bds[i];
if (num < 0) {
bds[i] = num + BIGRAD;
num = -1;
}
else {
bds[i] = num;
num = 0;
}
}
}
SCM scm_big_ash(x, cnt)
SCM x;
int cnt;
{
SCM res;
BIGDIG *resds, d;
int sign, i, ishf, fshf, blen, n;
if (INUMP(x)) {
blen = INUM(scm_intlength(x));
if (0==blen) { /* blen zero and fshf zero would lead to an array
index of -1 in resds[i - ishf] below. */
if (INUM0==x) return x;
else blen = 1;
}
sign = INUM(x) < 0 ? 0x0100 : 0;
}
else {
blen = NUMDIGS(x)*BITSPERDIG;
sign = BIGSIGN(x);
}
if (cnt < 0) {
if (blen <= -cnt) return sign ? MAKINUM(-1) : INUM0;
ishf = (-cnt) / BITSPERDIG;
fshf = (-cnt) % BITSPERDIG;
res = scm_copy_big_2scomp(x, blen, sign);
resds = BDIGITS(res);
n = NUMDIGS(res) - ishf - 1;
for (i = 0; i < n; i++) {
d = (resds[i + ishf]>>fshf);
if (fshf)
d |= ((resds[i + ishf + 1])<<(BITSPERDIG - fshf) & (BIGRAD - 1));
resds[i] = d;
}
d = (resds[i + ishf]>>fshf);
if (sign && fshf) d |= ((BIGRAD - 1)<<(BITSPERDIG - fshf) & (BIGRAD - 1));
resds[i] = d;
n = NUMDIGS(res);
d = sign ? BIGRAD - 1 : 0;
for (i++; i < n; i++)
resds[i] = d;
}
else {
ishf = cnt / BITSPERDIG;
fshf = cnt % BITSPERDIG;
res = scm_copy_big_2scomp(x, blen + cnt, sign);
resds = BDIGITS(res);
/* if (scm_verbose>1){for (i=NUMDIGS(res); i--;) printf(" %08x",resds[i]); printf("\n");} */
for (i = NUMDIGS(res) - 1; i > ishf; i--)
if (fshf) {
d = (((resds[i - ishf])<>(BITSPERDIG - fshf));
resds[i] = d;
} else resds[i] = resds[i - ishf];
d = fshf ? (((resds[i - ishf])<= 0; i--) resds[i] = 0;
}
/* if (scm_verbose>1){for (i=NUMDIGS(res); i--;) printf(" %08x",resds[i]); printf("\n");} */
if (sign) scm_2scomp1(res);
return normbig(res);
}
#endif
static char s_logand[] = "logand", s_lognot[] = "lognot",
s_logior[] = "logior", s_logxor[] = "logxor",
s_logtest[] = "logtest", s_logbitp[] = "logbit?",
s_copybit[] = "copy-bit",
s_copybitfield[] = "copy-bit-field",
s_ash[] = "ash", s_logcount[] = "logcount",
s_bitwise_bit_count[] = "bitwise-bit-count",
s_intlength[] = "integer-length",
s_bitfield[] = "bit-field",
s_bitif[] = "bitwise-if";
SCM scm_logior(x, y)
SCM x, y;
{
if (UNBNDP(y)) {
if (UNBNDP(x)) return INUM0;
#ifndef RECKLESS
if (!(NUMBERP(x)))
badx: wta(x, (char *)ARG1, s_logior);
#endif
return x;
}
#ifdef BIGDIG
if (NINUMP(x)) {
SCM t;
ASRTGO(NIMP(x) && BIGP(x), badx);
if (INUMP(y)) {t = x; x = y; y = t; goto intbig;}
ASRTGO(NIMP(y) && BIGP(y), bady);
if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;}
if ((!BIGSIGN(x)) && !BIGSIGN(y))
return scm_big_ior(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y);
return scm_big_and(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y, 0x0100);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_logior);
# endif
intbig: {
# ifndef DIGSTOOBIG
long z = pseudolong(INUM(x));
if ((!(x < 0)) && !BIGSIGN(y))
return scm_big_ior((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
return scm_big_and((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y,
0x0100);
# else
BIGDIG zdigs[DIGSPERLONG];
longdigs(INUM(x), zdigs);
if ((!(x < 0)) && !BIGSIGN(y))
return scm_big_ior(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
return scm_big_and(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0x0100);
# endif
}}
#else
ASRTGO(INUMP(x), badx);
ASRTER(INUMP(y), y, ARG2, s_logior);
#endif
return MAKINUM(INUM(x) | INUM(y));
}
SCM scm_logand(x, y)
SCM x, y;
{
if (UNBNDP(y)) {
if (UNBNDP(x)) return MAKINUM(-1);
#ifndef RECKLESS
if (!(NUMBERP(x)))
badx: wta(x, (char *)ARG1, s_logand);
#endif
return x;
}
#ifdef BIGDIG
if (NINUMP(x)) {
SCM t;
ASRTGO(NIMP(x) && BIGP(x), badx);
if (INUMP(y)) {t = x; x = y; y = t; goto intbig;}
ASRTGO(NIMP(y) && BIGP(y), bady);
if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;}
if ((BIGSIGN(x)) && BIGSIGN(y))
return scm_big_ior(BDIGITS(x), NUMDIGS(x), 0x0100, y);
return scm_big_and(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y, 0);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_logand);
# endif
intbig: {
# ifndef DIGSTOOBIG
long z = pseudolong(INUM(x));
if ((x < 0) && BIGSIGN(y))
return scm_big_ior((BIGDIG *)&z, DIGSPERLONG, 0x0100, y);
return scm_big_and((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y,
0);
# else
BIGDIG zdigs[DIGSPERLONG];
longdigs(INUM(x), zdigs);
if ((x < 0) && BIGSIGN(y))
return scm_big_ior(zdigs, DIGSPERLONG, 0x0100, y);
return scm_big_and(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0);
# endif
}}
#else
ASRTGO(INUMP(x), badx);
ASRTER(INUMP(y), y, ARG2, s_logand);
#endif
return MAKINUM(INUM(x) & INUM(y));
}
SCM scm_logxor(x, y)
SCM x, y;
{
if (UNBNDP(y)) {
if (UNBNDP(x)) return INUM0;
#ifndef RECKLESS
if (!(NUMBERP(x)))
badx: wta(x, (char *)ARG1, s_logxor);
#endif
return x;
}
#ifdef BIGDIG
if (NINUMP(x)) {
SCM t;
ASRTGO(NIMP(x) && BIGP(x), badx);
if (INUMP(y)) {t = x; x = y; y = t; goto intbig;}
ASRTGO(NIMP(y) && BIGP(y), bady);
if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;}
return scm_big_xor(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_logxor);
# endif
intbig: {
# ifndef DIGSTOOBIG
long z = pseudolong(INUM(x));
return scm_big_xor((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
# else
BIGDIG zdigs[DIGSPERLONG];
longdigs(INUM(x), zdigs);
return scm_big_xor(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
# endif
}}
#else
ASRTGO(INUMP(x), badx);
ASRTER(INUMP(y), y, ARG2, s_logxor);
#endif
return (x ^ y) + INUM0;
}
SCM scm_logtest(x, y)
SCM x, y;
{
#ifndef RECKLESS
if (!(NUMBERP(x)))
badx: wta(x, (char *)ARG1, s_logtest);
#endif
#ifdef BIGDIG
if (NINUMP(x)) {
SCM t;
ASRTGO(NIMP(x) && BIGP(x), badx);
if (INUMP(y)) {t = x; x = y; y = t; goto intbig;}
ASRTGO(NIMP(y) && BIGP(y), bady);
if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;}
return scm_big_test(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y);
}
if (NINUMP(y)) {
# ifndef RECKLESS
if (!(NIMP(y) && BIGP(y)))
bady: wta(y, (char *)ARG2, s_logtest);
# endif
intbig: {
# ifndef DIGSTOOBIG
long z = pseudolong(INUM(x));
return scm_big_test((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
# else
BIGDIG zdigs[DIGSPERLONG];
longdigs(INUM(x), zdigs);
return scm_big_test(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y);
# endif
}}
#else
ASRTGO(INUMP(x), badx);
ASRTER(INUMP(y), y, ARG2, s_logtest);
#endif
return (INUM(x) & INUM(y)) ? BOOL_T : BOOL_F;
}
SCM scm_logbitp(index, j1)
SCM index, j1;
{
ASRTER(INUMP(index) && INUM(index) >= 0, index, ARG1, s_logbitp);
#ifdef BIGDIG
if (NINUMP(j1)) {
ASRTER(NIMP(j1) && BIGP(j1), j1, ARG2, s_logbitp);
if (NUMDIGS(j1) * BITSPERDIG < INUM(index)) return BOOL_F;
else if (BIGSIGN(j1)) {
long num = -1;
sizet i = 0;
BIGDIG *x = BDIGITS(j1);
sizet nx = INUM(index)/BITSPERDIG;
while (!0) {
num += x[i];
if (nx==i++)
return ((1L << (INUM(index)%BITSPERDIG)) & num) ? BOOL_F : BOOL_T;
if (num < 0) num = -1;
else num = 0;
}
}
else return (BDIGITS(j1)[INUM(index)/BITSPERDIG] &
(1L << (INUM(index)%BITSPERDIG))) ? BOOL_T : BOOL_F;
}
#else
ASRTER(INUMP(j1), j1, ARG2, s_logbitp);
#endif
if (INUM(index) >= LONG_BIT) return j1 < 0 ? BOOL_T : BOOL_F;
return ((1L << INUM(index)) & INUM(j1)) ? BOOL_T : BOOL_F;
}
SCM scm_copybit(index, j1, bit)
SCM index, j1, bit;
{
ASRTER(INUMP(index) && INUM(index) >= 0, index, ARG1, s_copybit);
#ifdef BIGDIG
{
SCM res;
BIGDIG *rds;
sizet i = INUM(index);
int sign;
if (!INUMP(j1)) {
ASRTER(NIMP(j1) && BIGP(j1), j1, ARG2, s_copybit);
sign = BIGSIGN(j1);
ovflow:
res = scm_copy_big_2scomp(j1, i + 1, sign);
rds = BDIGITS(res);
if (NFALSEP(bit))
rds[i / BITSPERDIG] |= 1 << (i % BITSPERDIG);
else
rds[i / BITSPERDIG] &= ~(1 << (i % BITSPERDIG));
if (sign) scm_2scomp1(res);
return normbig(res);
}
if (i >= LONG_BIT - 3) {
sign = INUM(j1) < 0 ? 0x0100 : 0;
goto ovflow;
}
}
#else
ASRTER(INUMP(j1), j1, ARG2, s_copybit);
ASRTER(INUM(index) < LONG_BIT - 3, index, OUTOFRANGE, s_copybit);
#endif
if (NFALSEP(bit))
return MAKINUM(INUM(j1) | (1L << INUM(index)));
else
return MAKINUM(INUM(j1) & (~(1L << INUM(index))));
}
SCM scm_lognot(n)
SCM n;
{
return difference(MAKINUM(-1L), n);
}
SCM scm_ash(n, cnt)
SCM n, cnt;
{
SCM res;
long ni = INUM(n);
int icnt = INUM(cnt);
ASRTER(INUMP(cnt), cnt, ARG2, s_ash);
if (INUMP(n)) {
if (icnt < 0) {
if (-icnt >= LONG_BIT) return ni<0 ? MAKINUM(-1L) : INUM0;
return MAKINUM(SRS(ni, -icnt));
}
if (icnt >= LONG_BIT) goto ovflow;
res = MAKINUM(ni<>icnt != INUM(n))
goto ovflow;
else
return res;
}
#ifdef BIGDIG
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_ash);
ovflow:
if (0==icnt) return n;
return scm_big_ash(n, icnt);
#else
ovflow:
wta(n, INUMP(n) ? (char *)OVFLOW : (char *)ARG1, s_ash);
return UNSPECIFIED; /* kill warning */
#endif
}
SCM scm_bitfield(n, start, end)
SCM n, start, end;
{
int sign;
int istart = INUM(start);
int iend = INUM(end);
ASRTER(INUMP(start), start, ARG2, s_bitfield);
ASRTER(INUMP(end), end, ARG3, s_bitfield);
ASRTER(iend >= istart, MAKINUM(iend), OUTOFRANGE, s_bitfield);
#ifdef BIGDIG
if (NINUMP(n)) {
BIGDIG *ds;
sizet i, nd;
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_bitfield);
sign = BIGSIGN(n);
big:
if (sign) n = scm_copy_big_2scomp(n, (sizet)iend, 0);
n = scm_big_ash(n, -istart);
if (INUMP(n)) {
if (iend - istart >= LONG_BIT - 2) return n;
return MAKINUM(INUM(n) & ((1L<<(iend - istart)) - 1));
}
nd = NUMDIGS(n);
ds = BDIGITS(n);
i = (iend - istart) / BITSPERDIG;
if (i >= nd) return n;
ds[i] &= ((1 << ((iend - istart) % BITSPERDIG)) - 1);
for (++i; i < nd; i++) ds[i] = 0;
return normbig(n);
}
if (iend >= LONG_BIT - 2) {
sign = INUM(n) < 0;
goto big;
}
#else
ASRTER(INUMP(n), n, ARG1, s_bitfield);
ASRTER(iend < LONG_BIT - 2, MAKINUM(iend), OUTOFRANGE, s_bitfield);
#endif
return MAKINUM((INUM(n)>>istart) & ((1L<<(iend - istart)) - 1));
}
SCM scm_bitif(mask, n0, n1)
SCM mask, n0, n1;
{
#ifdef BIGDIG
if (NINUMP(mask) || NINUMP(n0) || NINUMP(n1))
return scm_logior(scm_logand(mask, n0),
scm_logand(scm_lognot(mask), n1));
#else
ASRTER(INUMP(mask), mask, ARG1, s_bitif);
ASRTER(INUMP(n0), n0, ARG2, s_bitif);
ASRTER(INUMP(n1), n1, ARG3, s_bitif);
#endif
return MAKINUM((INUM(mask) & INUM(n0)) | (~(INUM(mask)) & INUM(n1)));
}
SCM scm_copybitfield(to, from, rest)
SCM to, from, rest;
{
long len;
SCM start, end;
#ifndef RECKLESS
if (!(NIMP(rest) && CONSP(rest)))
wna: wta(UNDEFINED, (char *)WNA, s_copybitfield);
#endif
start = CAR(rest);
rest = CDR(rest);
ASRTGO(NIMP(rest) && CONSP(rest), wna);
end = CAR(rest);
ASRTGO(NULLP(CDR(rest)), wna);
ASRTER(INUMP(start) && INUM(start)>=0, start, ARG2, s_copybitfield);
len = INUM(end) - INUM(start);
ASRTER(INUMP(end), end, ARG3, s_copybitfield);
ASRTER(len >= 0, MAKINUM(len), OUTOFRANGE, s_copybitfield);
#ifdef BIGDIG
if (NINUMP(from) || NINUMP(to) || (INUM(end) >= LONG_BIT - 2)) {
SCM mask = difference(scm_ash(MAKINUM(1L), MAKINUM(len)), MAKINUM(1L));
mask = scm_ash(mask, start);
return scm_logior(scm_logand(mask, scm_ash(from, start)),
scm_logand(scm_lognot(mask), to));
}
#else
ASRTER(INUMP(to), to, ARG1, s_copybitfield);
ASRTER(INUMP(from), from, ARG4, s_copybitfield);
ASRTER(INUM(end) < LONG_BIT - 2, end, OUTOFRANGE, s_copybitfield);
#endif
{
long mask = ((1L<>= 4) c += logtab[15 & d];
if (BIGSIGN(n))
return MAKINUM(-1 - c);
return MAKINUM(c);
}
#else
ASRTER(INUMP(n), n, ARG1, s_bitwise_bit_count);
#endif
if ((nn = INUM(n)) < 0) nn = -1 - nn;
for (; nn; nn >>= 4) c += logtab[15 & nn];
if (n < 0)
return MAKINUM(-1 - c);
return MAKINUM(c);
}
SCM scm_logcount(n)
SCM n;
{
register unsigned long c = 0;
register long nn;
#ifdef BIGDIG
if (NINUMP(n)) {
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_logcount);
if (BIGSIGN(n)) {
SCM df = difference(MAKINUM(-1L), n);
SCM bc = scm_bitwise_bit_count(df);
bigrecy(df);
return bc;
}
return scm_bitwise_bit_count(n);
}
#else
ASRTER(INUMP(n), n, ARG1, s_logcount);
#endif
if ((nn = INUM(n)) < 0) nn = -1 - nn;
for (; nn; nn >>= 4) c += logtab[15 & nn];
return MAKINUM(c);
}
char ilentab[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
SCM scm_intlength(n)
SCM n;
{
register unsigned long c = 0;
register long nn;
unsigned int l = 4;
#ifdef BIGDIG
if (NINUMP(n)) {
BIGDIG *ds, d;
ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_intlength);
if (BIGSIGN(n)) {
SCM df = difference(MAKINUM(-1L), n);
SCM si = scm_intlength(df);
bigrecy(df);
return si;
}
ds = BDIGITS(n);
d = ds[c = NUMDIGS(n)-1];
for (c *= BITSPERDIG; d; d >>= 4) {c += 4; l = ilentab[15 & d];}
return MAKINUM(c - 4 + l);
}
#else
ASRTER(INUMP(n), n, ARG1, s_intlength);
#endif
if ((nn = INUM(n)) < 0) nn = -1 - nn;
for (;nn; nn >>= 4) {c += 4; l = ilentab[15 & nn];}
return MAKINUM(c - 4 + l);
}
SCM charp(x)
SCM x;
{
return ICHRP(x) ? BOOL_T : BOOL_F;
}
SCM char_lessp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ch_lessp);
ASRTER(ICHRP(y), y, ARG2, s_ch_lessp);
return (ICHR(x) < ICHR(y)) ? BOOL_T : BOOL_F;
}
SCM char_leqp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ch_leqp);
ASRTER(ICHRP(y), y, ARG2, s_ch_leqp);
return (ICHR(x) <= ICHR(y)) ? BOOL_T : BOOL_F;
}
SCM char_grp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ch_grp);
ASRTER(ICHRP(y), y, ARG2, s_ch_grp);
return (ICHR(x) > ICHR(y)) ? BOOL_T : BOOL_F;
}
SCM char_geqp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ch_geqp);
ASRTER(ICHRP(y), y, ARG2, s_ch_geqp);
return (ICHR(x) >= ICHR(y)) ? BOOL_T : BOOL_F;
}
SCM chci_eq(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ci_eq);
ASRTER(ICHRP(y), y, ARG2, s_ci_eq);
return (upcase[ICHR(x)]==upcase[ICHR(y)]) ? BOOL_T : BOOL_F;
}
SCM chci_lessp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ci_lessp);
ASRTER(ICHRP(y), y, ARG2, s_ci_lessp);
return (upcase[ICHR(x)] < upcase[ICHR(y)]) ? BOOL_T : BOOL_F;
}
SCM chci_leqp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ci_leqp);
ASRTER(ICHRP(y), y, ARG2, s_ci_leqp);
return (upcase[ICHR(x)] <= upcase[ICHR(y)]) ? BOOL_T : BOOL_F;
}
SCM chci_grp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ci_grp);
ASRTER(ICHRP(y), y, ARG2, s_ci_grp);
return (upcase[ICHR(x)] > upcase[ICHR(y)]) ? BOOL_T : BOOL_F;
}
SCM chci_geqp(x, y)
SCM x, y;
{
ASRTER(ICHRP(x), x, ARG1, s_ci_geqp);
ASRTER(ICHRP(y), y, ARG2, s_ci_geqp);
return (upcase[ICHR(x)] >= upcase[ICHR(y)]) ? BOOL_T : BOOL_F;
}
SCM char_alphap(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_alphap);
return (isascii(ICHR(chr)) && isalpha(ICHR(chr))) ? BOOL_T : BOOL_F;
}
SCM char_nump(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_nump);
return (isascii(ICHR(chr)) && isdigit(ICHR(chr))) ? BOOL_T : BOOL_F;
}
SCM char_whitep(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_whitep);
return (isascii(ICHR(chr)) && isspace(ICHR(chr))) ? BOOL_T : BOOL_F;
}
SCM char_upperp(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_upperp);
return (isascii(ICHR(chr)) && isupper(ICHR(chr))) ? BOOL_T : BOOL_F;
}
SCM char_lowerp(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_lowerp);
return (isascii(ICHR(chr)) && islower(ICHR(chr))) ? BOOL_T : BOOL_F;
}
SCM char2int(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_char2int);
return MAKINUM(ICHR(chr));
}
SCM int2char(n)
SCM n;
{
ASRTER(INUMP(n), n, ARG1, s_int2char);
ASRTER((n >= INUM0) && (n < MAKINUM(CHAR_CODE_LIMIT)),
n, OUTOFRANGE, s_int2char);
return MAKICHR(INUM(n));
}
SCM char_upcase(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_upcase);
return MAKICHR(upcase[ICHR(chr)]);
}
SCM char_downcase(chr)
SCM chr;
{
ASRTER(ICHRP(chr), chr, ARG1, s_ch_downcase);
return MAKICHR(downcase[ICHR(chr)]);
}
SCM stringp(x)
SCM x;
{
if (IMP(x)) return BOOL_F;
return STRINGP(x) ? BOOL_T : BOOL_F;
}
SCM string(chrs)
SCM chrs;
{
SCM res;
register unsigned char *data;
long i = ilength(chrs);
ASRTER(i >= 0, chrs, ARG1, s_string);
res = makstr(i);
data = UCHARS(res);
for (;NNULLP(chrs);chrs = CDR(chrs)) {
ASRTER(ICHRP(CAR(chrs)), chrs, ARG1, s_string);
*data++ = ICHR(CAR(chrs));
}
return res;
}
SCM make_string(k, chr)
SCM k, chr;
{
SCM res;
register unsigned char *dst;
register long i;
ASRTER(INUMP(k) && (k >= 0), k, ARG1, s_make_string);
i = INUM(k);
res = makstr(i);
dst = UCHARS(res);
if (!UNBNDP(chr)) {
ASRTER(ICHRP(chr), chr, ARG2, s_make_string);
for (i--;i >= 0;i--) dst[i] = ICHR(chr);
}
return res;
}
SCM st_length(str)
SCM str;
{
ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_length);
return MAKINUM(LENGTH(str));
}
SCM st_ref(str, k)
SCM str, k;
{
ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_ref);
ASRTER(INUMP(k), k, ARG2, s_st_ref);
ASRTER(INUM(k) < LENGTH(str) && INUM(k) >= 0, k, OUTOFRANGE, s_st_ref);
return MAKICHR(UCHARS(str)[INUM(k)]);
}
SCM st_set(str, k, chr)
SCM str, k, chr;
{
ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_set);
ASRTER(INUMP(k), k, ARG2, s_st_set);
ASRTER(ICHRP(chr), chr, ARG3, s_st_set);
ASRTER(INUM(k) < LENGTH(str) && INUM(k) >= 0, k, OUTOFRANGE, s_st_set);
UCHARS(str)[INUM(k)] = ICHR(chr);
return UNSPECIFIED;
}
SCM st_equal(s1, s2)
SCM s1, s2;
{
register sizet i;
register unsigned char *c1, *c2;
ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_st_equal);
ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_st_equal);
i = LENGTH(s2);
if (LENGTH(s1) != i) return BOOL_F;
c1 = UCHARS(s1);
c2 = UCHARS(s2);
while(0 != i--) if (*c1++ != *c2++) return BOOL_F;
return BOOL_T;
}
SCM stci_equal(s1, s2)
SCM s1, s2;
{
register sizet i;
register unsigned char *c1, *c2;
ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_stci_equal);
ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_stci_equal);
i = LENGTH(s2);
if (LENGTH(s1) != i) return BOOL_F;
c1 = UCHARS(s1);
c2 = UCHARS(s2);
while(0 != i--) if (upcase[*c1++] != upcase[*c2++]) return BOOL_F;
return BOOL_T;
}
SCM st_lessp(s1, s2)
SCM s1, s2;
{
register sizet i, len;
register unsigned char *c1, *c2;
register int c;
ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_st_lessp);
ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_st_lessp);
len = LENGTH(s1);
i = LENGTH(s2);
if (len>i) i = len;
c1 = UCHARS(s1);
c2 = UCHARS(s2);
for (i = 0;i0) return BOOL_F;
if (c<0) return BOOL_T;
}
return (LENGTH(s2) != len) ? BOOL_T : BOOL_F;
}
SCM st_leqp(s1, s2)
SCM s1, s2;
{
return BOOL_NOT(st_lessp(s2, s1));
}
SCM st_grp(s1, s2)
SCM s1, s2;
{
return st_lessp(s2, s1);
}
SCM st_geqp(s1, s2)
SCM s1, s2;
{
return BOOL_NOT(st_lessp(s1, s2));
}
SCM stci_lessp(s1, s2)
SCM s1, s2;
{
register sizet i, len;
register unsigned char *c1, *c2;
register int c;
ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_stci_lessp);
ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_stci_lessp);
len = LENGTH(s1);
i = LENGTH(s2);
if (len>i) i=len;
c1 = UCHARS(s1);
c2 = UCHARS(s2);
for (i = 0;i0) return BOOL_F;
if (c<0) return BOOL_T;
}
return (LENGTH(s2) != len) ? BOOL_T : BOOL_F;
}
SCM stci_leqp(s1, s2)
SCM s1, s2;
{
return BOOL_NOT(stci_lessp(s2, s1));
}
SCM stci_grp(s1, s2)
SCM s1, s2;
{
return stci_lessp(s2, s1);
}
SCM stci_geqp(s1, s2)
SCM s1, s2;
{
return BOOL_NOT(stci_lessp(s1, s2));
}
SCM substring(str, start, end)
SCM str, start, end;
{
long l;
ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_substring);
ASRTER(INUMP(start), start, ARG2, s_substring);
ASRTER(INUMP(end), end, ARG3, s_substring);
ASRTER(INUM(start) <= LENGTH(str), start, OUTOFRANGE, s_substring);
ASRTER(INUM(end) <= LENGTH(str), end, OUTOFRANGE, s_substring);
l = INUM(end)-INUM(start);
ASRTER(l >= 0, MAKINUM(l), OUTOFRANGE, s_substring);
return makfromstr(&CHARS(str)[INUM(start)], (sizet)l);
}
SCM st_append(args)
SCM args;
{
SCM res;
register long i = 0;
register SCM l, s;
register unsigned char *data;
for (l = args;NIMP(l);) {
ASRTER(CONSP(l), l, ARGn, s_st_append);
s = CAR(l);
ASRTER(NIMP(s) && STRINGP(s), s, ARGn, s_st_append);
i += LENGTH(s);
l = CDR(l);
}
ASRTER(NULLP(l), args, ARGn, s_st_append);
res = makstr(i);
data = UCHARS(res);
for (l = args;NIMP(l);l = CDR(l)) {
s = CAR(l);
for (i = 0;i= 0, l, ARG1, s_vector);
res = make_vector(MAKINUM(i), UNSPECIFIED);
data = VELTS(res);
for (;NIMP(l);l = CDR(l)) *data++ = CAR(l);
return res;
}
SCM vector_ref(v, k)
SCM v, k;
{
ASRTER(NIMP(v) && VECTORP(v), v, ARG1, s_ve_ref);
ASRTER(INUMP(k), k, ARG2, s_ve_ref);
ASRTER((INUM(k) < LENGTH(v)) && (INUM(k) >= 0), k, OUTOFRANGE, s_ve_ref);
return VELTS(v)[((long) INUM(k))];
}
SCM vector_set(v, k, obj)
SCM v, k, obj;
{
ASRTER(NIMP(v) && VECTORP(v), v, ARG1, s_ve_set);
ASRTER(INUMP(k), k, ARG2, s_ve_set);
ASRTER((INUM(k) < LENGTH(v)) && (INUM(k) >= 0), k, OUTOFRANGE, s_ve_set);
VELTS(v)[((long) INUM(k))] = obj;
return UNSPECIFIED;
}
char s_make_vector[] = "make-vector";
SCM make_vector(k, fill)
SCM k, fill;
{
SCM v;
register long i;
register SCM *velts;
#ifdef SHORT_SIZET
ASRTER(INUMP(k), k, ARG1, s_make_vector);
#else
ASRTER(INUMP(k) && (!(~LENGTH_MAX & INUM(k))), k, ARG1, s_make_vector);
#endif
if (UNBNDP(fill)) fill = UNSPECIFIED;
i = INUM(k);
DEFER_INTS;
v = must_malloc_cell(i ? i*sizeof(SCM) : 1L,
MAKE_LENGTH(i, tc7_vector), s_vector);
velts = VELTS(v);
while(--i >= 0) (velts)[i] = fill;
ALLOW_INTS;
return v;
}
#ifdef BIGDIG
char s_big_OVFLOW[] = "numerical overflow; NUMDIGS_MAX <";
char s_bignum[] = "bignum";
SCM mkbig(nlen, sign)
sizet nlen;
int sign;
{
SCM v;
if (NUMDIGS_MAX <= nlen) wta(MAKINUM(nlen), s_big_OVFLOW, s_bignum);
DEFER_INTS;
v = must_malloc_cell((0L+nlen)*sizeof(BIGDIG),
MAKE_NUMDIGS(nlen, sign ? tc16_bigneg : tc16_bigpos),
s_bignum);
ALLOW_INTS;
return v;
}
/* big2inum() frees bignum b when it returns an INUM */
SCM big2inum(b, l)
SCM b;
sizet l;
{
unsigned long num = 0;
BIGDIG *tmp = BDIGITS(b);
while (l--) num = BIGUP(num) + tmp[l];
if (TYP16(b)==tc16_bigpos) {
if (POSFIXABLE(num)) {
bigrecy(b);
return MAKINUM(num);
}}
else if (UNEGFIXABLE(num)) {
bigrecy(b);
return MAKINUM(-(long)num);
}
return b;
}
char s_adjbig[] = "adjbig";
SCM adjbig(b, nlen)
SCM b;
sizet nlen;
{
long nsiz = nlen;
if (((nsiz << 16) >> 16) != nlen)
wta(MAKINUM(nsiz), s_big_OVFLOW, s_adjbig);
DEFER_INTS;
must_realloc_cell(b, (long)(NUMDIGS(b)*sizeof(BIGDIG)),
(long)(nsiz*sizeof(BIGDIG)), s_adjbig);
SETNUMDIGS(b, nsiz, TYP16(b));
ALLOW_INTS;
return b;
}
SCM normbig(b)
SCM b;
{
# ifndef _UNICOS
sizet nlen = NUMDIGS(b);
# else
int nlen = NUMDIGS(b); /* unsigned nlen breaks on Cray when nlen => 0 */
# endif
BIGDIG *zds = BDIGITS(b);
while (nlen-- && !zds[nlen]); nlen++;
if (nlen * BITSPERDIG/CHAR_BIT <= sizeof(SCM))
if (INUMP(b = big2inum(b, (sizet)nlen))) return b;
if (NUMDIGS(b)==nlen) return b;
return adjbig(b, (sizet)nlen);
}
SCM copybig(b, sign)
SCM b;
int sign;
{
sizet i = NUMDIGS(b);
SCM ans = mkbig(i, sign);
BIGDIG *src = BDIGITS(b), *dst = BDIGITS(ans);
while (i--) dst[i] = src[i];
return ans;
}
SCM long2big(n)
long n;
{
sizet i = 0;
BIGDIG *digits;
SCM ans = mkbig(DIGSPERLONG, n<0);
digits = BDIGITS(ans);
if (n < 0) n = -n;
while (i < DIGSPERLONG) {
digits[i++] = BIGLO(n);
n = BIGDN(n);
}
return ans;
}
SCM ulong2big(n)
unsigned long n;
{
sizet i = 0;
BIGDIG *digits;
SCM ans = mkbig(DIGSPERLONG, 0);
digits = BDIGITS(ans);
while (i < DIGSPERLONG) {
digits[i++] = BIGLO(n);
n = BIGDN(n);
}
return ans;
}
int bigcomp(x, y)
SCM x, y;
{
int xsign = BIGSIGN(x);
int ysign = BIGSIGN(y);
long xlen;
sizet ylen;
if (ysign < xsign) return 1;
if (ysign > xsign) return -1;
if ((ylen = NUMDIGS(y)) > (xlen = NUMDIGS(x))) return (xsign) ? -1 : 1;
if (ylen < xlen) return (xsign) ? 1 : -1;
while (xlen-- && (BDIGITS(y)[xlen]==BDIGITS(x)[xlen]));
if (-1==xlen) return 0;
return (BDIGITS(y)[xlen] > BDIGITS(x)[xlen]) ?
(xsign ? -1 : 1) : (xsign ? 1 : -1);
}
# ifndef DIGSTOOBIG
long pseudolong(x)
long x;
{
union {
long l;
BIGDIG bd[DIGSPERLONG];
} p;
sizet i = 0;
if (x < 0) x = -x;
while (i < DIGSPERLONG) {p.bd[i++] = BIGLO(x); x = BIGDN(x);}
/* p.bd[0] = BIGLO(x); p.bd[1] = BIGDN(x); */
return p.l;
}
# else
void longdigs(x, digs)
long x;
BIGDIG digs[DIGSPERLONG];
{
sizet i = 0;
if (x < 0) x = -x;
while (i < DIGSPERLONG) {digs[i++] = BIGLO(x); x = BIGDN(x);}
}
# endif
SCM addbig(x, nx, xsgn, bigy, sgny)
BIGDIG *x;
SCM bigy;
sizet nx; /* Assumes nx <= NUMDIGS(bigy) */
int xsgn, sgny; /* Assumes xsgn and sgny equal either 0 or 0x0100 */
{
SBIGLONG num = 0;
sizet i = 0, ny = NUMDIGS(bigy);
SCM z = copybig(bigy, BIGSIGN(bigy) ^ sgny);
BIGDIG *zds = BDIGITS(z);
if (xsgn ^ BIGSIGN(z)) {
do {
num += (long) zds[i] - x[i];
if (num < 0) {zds[i] = num + BIGRAD; num = -1;}
else {zds[i] = BIGLO(num); num = 0;}
} while (++i < nx);
if (num && nx==ny) {
num = 1; i = 0;
CAR(z) ^= 0x0100;
do {
num += (BIGRAD-1) - zds[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < ny);
}
else while (i < ny) {
num += zds[i];
if (num < 0) {zds[i++] = num + BIGRAD; num = -1;}
else {zds[i++] = BIGLO(num); num = 0;}
}
} else {
do {
num += (long) zds[i] + x[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < nx);
if (!num) return z;
while (i < ny) {
num += zds[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
if (!num) return z;
}
if (num) {z = adjbig(z, ny+1); BDIGITS(z)[ny] = num; return z;}
}
return normbig(z);
}
SCM mulbig(x, nx, y, ny, sgn)
BIGDIG *x, *y;
sizet nx, ny;
int sgn;
{
sizet i = 0, j = nx + ny;
UBIGLONG n = 0;
SCM z = mkbig(j, sgn);
BIGDIG *zds = BDIGITS(z);
while (j--) zds[j] = 0;
do {
j = 0;
if (x[i]) {
do {
n += zds[i + j] + ((UBIGLONG) x[i] * y[j]);
zds[i + j++] = BIGLO(n);
n = BIGDN(n);
} while (j < ny);
if (n) {zds[i + j] = n; n = 0;}
}
} while (++i < nx);
return normbig(z);
}
UBIGLONG divbigdig(ds, h, div)
BIGDIG *ds;
sizet h;
BIGDIG div;
{
register UBIGLONG t2 = 0L;
while(h--) {
t2 = BIGUP(t2) + ds[h];
ds[h] = t2 / div;
t2 %= div;
}
return t2;
}
SCM divbigint(x, z, sgn, mode)
SCM x;
long z;
int sgn, mode;
{
if (z < 0) z = -z;
if (z < BIGRAD) {
register UBIGLONG t2 = 0;
register BIGDIG *ds = BDIGITS(x);
sizet nd = NUMDIGS(x);
while(nd--) t2 = (BIGUP(t2) + ds[nd]) % z;
if (mode && t2) t2 = z - t2;
return MAKINUM(sgn ? -(long)t2 : t2);
}
{
# ifndef DIGSTOOBIG
UBIGLONG t2 = pseudolong(z);
return divbigbig(BDIGITS(x), NUMDIGS(x), (BIGDIG *)&t2,
DIGSPERLONG, sgn, mode);
# else
BIGDIG t2[DIGSPERLONG];
longdigs(z, t2);
return divbigbig(BDIGITS(x), NUMDIGS(x), t2, DIGSPERLONG, sgn, mode);
# endif
}
}
static SCM scm_copy_big_ash1 P((BIGDIG *xds, sizet xlen, BIGDIG dscl));
/* Make a copy of 2*xds and divide by dscl if dscl > 0 */
SCM scm_copy_big_ash1 (xds, xlen, dscl)
BIGDIG *xds;
sizet xlen;
BIGDIG dscl;
{
sizet rlen = xlen + 1, i;
SCM dencell = mkbig(rlen, 0);
BIGDIG *dends = BDIGITS(dencell);
dends[xlen] = xds[xlen-1]>>(BITSPERDIG - 1);
for (i = xlen - 1; i > 0; i--)
dends[i] = (((xds[i])<<1) & (BIGRAD - 1))
| ((xds[i-1])>>(BITSPERDIG - 1));
dends[0] = (((xds[0])<<1) & (BIGRAD - 1));
while(rlen && !dends[rlen-1]) rlen--;
if (dscl) {
divbigdig(dends, rlen, dscl);
while(rlen && !dends[rlen-1]) rlen--;
}
SETNUMDIGS(dencell, rlen, TYP16(dencell));
return dencell;
}
SCM divbigbig(x, xlen, y, ylen, sgn, mode)
BIGDIG *x, *y;
sizet xlen, ylen;
int sgn, mode;
/* mode description
0 remainder
1 modulo
2 quotient
3 quotient with round-toward-even
4 quotient but returns NULL if division is not exact. */
{
int roundup = 0; /* used for round-quotient */
sizet i = 0, j = 0; /* loop indexes */
SBIGLONG dds = 0; /* double-digit signed */
UBIGLONG ddu = 0; /* double-digit unsigned */
SCM quocell, dencell;
volatile SCM gcpr[2];
sizet rlen;
BIGDIG *quods, /* quotient digits */
*dends, /* scaled denominator digits */
dscl = 0, /* unscale quotient from scaled divisor */
qhat;
while(!y[ylen-1]) ylen--; /* in case y came in as a psuedolong */
if (xlen < ylen)
switch (mode) {
case 0: /* remainder -- just return x */
quocell = gcpr[0] = mkbig(xlen, sgn); quods = BDIGITS(quocell);
do {quods[i] = x[i];} while (++i < xlen);
return quocell;
case 1: /* modulo -- return y-x */
quocell = gcpr[0] = mkbig(ylen, sgn); quods = BDIGITS(quocell);
do {
dds += (long) y[i] - x[i];
if (dds < 0) {quods[i] = dds + BIGRAD; dds = -1;}
else {quods[i] = dds; dds = 0;}
} while (++i < xlen);
while (i < ylen) {
dds += y[i];
if (dds < 0) {quods[i++] = dds + BIGRAD; dds = -1;}
else {quods[i++] = dds; dds = 0;}
}
goto doadj;
case 2: return INUM0; /* quotient is zero */
case 3: /* round-toward-even */
/* Use dencell and dends variables to double the numerator */
dencell = gcpr[1] = scm_copy_big_ash1(x, xlen, dscl);
dends = BDIGITS(dencell);
rlen = NUMDIGS(dencell);
if (rlen < ylen) return INUM0;;
if (rlen > ylen) goto retone;
i = rlen;
while (i-- && (y[i]==dends[i]));
if (-1==i || (y[i] > dends[i])) return INUM0;
retone:
return MAKINUM(sgn ? -1 : 1);
case 4: return 0; /* the division is not exact */
}
/* main algorithm requires xlen >= ylen */
quocell = gcpr[0] = mkbig(xlen==ylen ? xlen+2 : xlen+1, sgn); quods = BDIGITS(quocell);
if (xlen==ylen) quods[xlen+1] = 0;
if (y[ylen-1] < (BIGRAD>>1)) { /* normalize operands */
dscl = BIGRAD/(y[ylen-1]+1);
dencell = gcpr[1] = mkbig(ylen, 0); dends = BDIGITS(dencell);
while(j < ylen) {
ddu += (UBIGLONG) y[j]*dscl;
dends[j++] = BIGLO(ddu); ddu = BIGDN(ddu);
}
j = 0; ddu = 0; /* y = dends; */
while(j < xlen) {
ddu += (UBIGLONG) x[j]*dscl;
quods[j++] = BIGLO(ddu); ddu = BIGDN(ddu);
}
quods[j] = ddu;
} else {
dends = y;
quods[j = xlen] = 0;
while (j--) quods[j] = x[j];
}
j = xlen==ylen ? xlen+1 : xlen; /* dividend needs more digits than divisor */
do { /* loop over digits of quotient */
if (quods[j]==dends[ylen-1]) qhat = BIGRAD-1;
else qhat = (BIGUP(quods[j]) + quods[j-1])/dends[ylen-1];
if (!qhat) continue;
i = 0; dds = 0; ddu = 0;
do { /* multiply and subtract */
ddu += (UBIGLONG) dends[i] * qhat;
dds += quods[j - ylen + i] - BIGLO(ddu);
if (dds < 0) {quods[j - ylen + i] = dds + BIGRAD; dds = -1;}
else {quods[j - ylen + i] = dds; dds = 0;}
ddu = BIGDN(ddu);
} while (++i < ylen);
dds += quods[j - ylen + i] - ddu; /* borrow from high digit; don't update */
while (dds) { /* "add back" required */
i = 0; dds = 0; qhat--;
do {
dds += (long) quods[j - ylen + i] + dends[i];
quods[j - ylen + i] = BIGLO(dds);
dds = BIGDN(dds);
} while (++i < ylen);
dds--;
}
if (mode >= 2) quods[j] = qhat; /* returning quotient */
} while (--j >= ylen);
switch (mode) {
case 4: /* check that remainder==0 */
for (j = ylen;j && !quods[j-1];--j) ; if (j) return 0;
case 3: /* round toward even */
/* Reuse dencell and dends variables to double the remainder */
dencell = gcpr[1] = scm_copy_big_ash1(quods, ylen, dscl);
dends = BDIGITS(dencell);
rlen = NUMDIGS(dencell);
if (rlen > ylen) roundup = 1;
else if (rlen < ylen) ;
else {
i = rlen;
while (i-- && (y[i]==dends[i]));
if (-1==i) {
if (0==roundup && quods[ylen] & 1) roundup = 1;
} else if (y[i] < dends[i]) roundup = 1;
}
case 2: /* move quotient down in quocell */
j = (xlen==ylen ? xlen+2 : xlen+1) - ylen;
for (i = 0;i < j;i++) quods[i] = quods[i+ylen];
ylen = i;
if (roundup) {
i = 0; dds = 1;
while (i < ylen) {
dds += quods[i];
quods[i++] = BIGLO(dds);
dds = BIGDN(dds);
if (!dds) break;
}
}
break;
case 1: /* subtract for modulo */
i = 0; dds = 0; j = 0;
do {dds += dends[i] - quods[i];
j = j | quods[i];
if (dds < 0) {quods[i] = dds + BIGRAD; dds = -1;}
else {quods[i] = dds; dds = 0;}
} while (++i < ylen);
if (!j) return INUM0;
case 0: /* just normalize remainder */
if (dscl) divbigdig(quods, ylen, dscl);
}
doadj:
for (j = ylen;j && !quods[j-1];--j) ;
if (j * BITSPERDIG <= sizeof(SCM)*CHAR_BIT)
if (INUMP(quocell = big2inum(quocell, j))) return quocell;
return adjbig(quocell, j);
}
#endif
static iproc cxrs[] = {
{"cr", 0},
{"car", 0}, {"cdr", 0},
{"caar", 0}, {"cadr", 0}, {"cdar", 0}, {"cddr", 0},
{"caaar", 0}, {"caadr", 0}, {"cadar", 0}, {"caddr", 0},
{"cdaar", 0}, {"cdadr", 0}, {"cddar", 0}, {"cdddr", 0},
{"caaaar", 0}, {"caaadr", 0}, {"caadar", 0}, {"caaddr", 0},
{"cadaar", 0}, {"cadadr", 0}, {"caddar", 0}, {"cadddr", 0},
{"cdaaar", 0}, {"cdaadr", 0}, {"cdadar", 0}, {"cdaddr", 0},
{"cddaar", 0}, {"cddadr", 0}, {"cdddar", 0}, {"cddddr", 0},
{0, 0}};
static iproc subr1s[] = {
{"not", lnot},
{"boolean?", booleanp},
{"pair?", consp},
{"null?", nullp},
{"list?", listp},
{s_length, length},
{s_reverse, reverse},
{"symbol?", symbolp},
{s_symbol2string, symbol2string},
{s_str2symbol, string2symbol},
{s_exactp, exactp},
{s_oddp, oddp},
{s_evenp, evenp},
{s_lognot, scm_lognot},
{s_logcount, scm_logcount},
{s_bitwise_bit_count, scm_bitwise_bit_count},
{s_intlength, scm_intlength},
{"char?", charp},
{s_ch_alphap, char_alphap},
{s_ch_nump, char_nump},
{s_ch_whitep, char_whitep},
{s_ch_upperp, char_upperp},
{s_ch_lowerp, char_lowerp},
{s_char2int, char2int},
{s_int2char, int2char},
{s_ch_upcase, char_upcase},
{s_ch_downcase, char_downcase},
{"string?", stringp},
{s_st_length, st_length},
{"vector?", vectorp},
{s_ve_length, vector_length},
{"procedure?", procedurep},
{"promise?", promisep},
{0, 0}};
static char s_acons[] = "acons";
static iproc subr2s[] = {
{&s_acons[1], cons},
{s_setcar, setcar},
{s_setcdr, setcdr},
{s_list_ref, list_ref},
{s_memq, memq},
{s_member, member},
{s_assq, assq},
{s_assoc, assoc},
{s_quotient, lquotient},
/* {"rq", rq}, */
{s_rquotient, scm_round_quotient},
{s_remainder, lremainder},
{s_modulo, modulo},
{s_logtest, scm_logtest},
{s_logbitp, scm_logbitp},
{s_ash, scm_ash},
{s_st_ref, st_ref},
{"string<=?", st_leqp},
{"string-ci<=?", stci_leqp},
{s_ve_ref, vector_ref},
{0, 0}};
static iproc lsubrs[] = {
{s_list, list},
{s_append, append},
{s_string, string},
{s_st_append, st_append},
{s_vector, vector},
{0, 0}};
static iproc subr2os[] = {
{s_make_string, make_string},
{s_make_vector, make_vector},
{0, 0}};
static iproc asubrs[] = {
{s_gcd, lgcd},
{"lcm", llcm},
{s_logand, scm_logand},
{s_logior, scm_logior},
{s_logxor, scm_logxor},
{0, 0}};
static iproc rpsubrs[] = {
{"eq?", eq},
{"equal?", equal},
{"char=?", eq},
{s_ch_lessp, char_lessp},
{s_ci_eq, chci_eq},
{s_ci_lessp, chci_lessp},
{s_ch_leqp, char_leqp},
{s_ci_leqp, chci_leqp},
{s_ch_grp, char_grp},
{s_ci_grp, chci_grp},
{s_ch_geqp, char_geqp},
{s_ci_geqp, chci_geqp},
{s_st_equal, st_equal},
{s_stci_equal, stci_equal},
{s_st_lessp, st_lessp},
{s_stci_lessp, stci_lessp},
{"string>?", st_grp},
{"string-ci>?", stci_grp},
{"string>=?", st_geqp},
{"string-ci>=?", stci_geqp},
{0, 0}};
static iproc subr3s[] = {
{s_bitfield, scm_bitfield},
{s_bitif, scm_bitif},
{s_copybit, scm_copybit},
{s_substring, substring},
{s_acons, acons},
{s_st_set, st_set},
{s_ve_set, vector_set},
{0, 0}};
void init_iprocs(subra, type)
iproc *subra;
int type;
{
for (;subra->string; subra++)
make_subr(subra->string,
type,
subra->cproc);
}
void init_subrs()
{
init_iprocs(cxrs, tc7_cxr);
init_iprocs(subr1s, tc7_subr_1);
init_iprocs(subr2s, tc7_subr_2);
init_iprocs(subr2os, tc7_subr_2o);
init_iprocs(rpsubrs, tc7_rpsubr);
init_iprocs(lsubrs, tc7_lsubr);
init_iprocs(asubrs, tc7_asubr);
init_iprocs(subr3s, tc7_subr_3);
make_subr(s_copybitfield, tc7_lsubr_2, scm_copybitfield);
}
scm-5f4/unexec.c 0000755 0001750 0001750 00000103665 10750242011 010616 0000000 0000000 /* Copyright (C) 1985,86,87,88,92,93,94 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs 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 3 of the
License, or (at your option) any later version.
GNU Emacs 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 GNU Emacs. If not, see
. */
/*
* unexec.c - Convert a running program into an a.out file.
*
* Author: Spencer W. Thomas
* Computer Science Dept.
* University of Utah
* Date: Tue Mar 2 1982
* Modified heavily since then.
*
* Synopsis:
* unexec (new_name, a_name, data_start, bss_start, entry_address)
* char *new_name, *a_name;
* unsigned data_start, bss_start, entry_address;
*
* Takes a snapshot of the program and makes an a.out format file in the
* file named by the string argument new_name.
* If a_name is non-NULL, the symbol table will be taken from the given file.
* On some machines, an existing a_name file is required.
*
* The boundaries within the a.out file may be adjusted with the data_start
* and bss_start arguments. Either or both may be given as 0 for defaults.
*
* Data_start gives the boundary between the text segment and the data
* segment of the program. The text segment can contain shared, read-only
* program code and literal data, while the data segment is always unshared
* and unprotected. Data_start gives the lowest unprotected address.
* The value you specify may be rounded down to a suitable boundary
* as required by the machine you are using.
*
* Specifying zero for data_start means the boundary between text and data
* should not be the same as when the program was loaded.
* If NO_REMAP is defined, the argument data_start is ignored and the
* segment boundaries are never changed.
*
* Bss_start indicates how much of the data segment is to be saved in the
* a.out file and restored when the program is executed. It gives the lowest
* unsaved address, and is rounded up to a page boundary. The default when 0
* is given assumes that the entire data segment is to be stored, including
* the previous data and bss as well as any additional storage allocated with
* break (2).
*
* The new file is set up to start at entry_address.
*
* If you make improvements I'd like to get them too.
* harpo!utah-cs!thomas, thomas@Utah-20
*
*/
/* Modified to support SysVr3 shared libraries by James Van Artsdalen
* of Dell Computer Corporation. james@bigtex.cactus.org.
*/
/* There are several compilation parameters affecting unexec:
* COFF
Define this if your system uses COFF for executables.
* COFF_ENCAPSULATE
Define this if you are using the GNU coff encapsulated a.out format.
This is closer to a.out than COFF. You should *not* define COFF if
you define COFF_ENCAPSULATE
Otherwise we assume you use Berkeley format.
* NO_REMAP
Define this if you do not want to try to save Emacs's pure data areas
as part of the text segment.
Saving them as text is good because it allows users to share more.
However, on machines that locate the text area far from the data area,
the boundary cannot feasibly be moved. Such machines require
NO_REMAP.
Also, remapping can cause trouble with the built-in startup routine
/lib/crt0.o, which defines `environ' as an initialized variable.
Dumping `environ' as pure does not work! So, to use remapping,
you must write a startup routine for your machine in Emacs's crt0.c.
If NO_REMAP is defined, Emacs uses the system's crt0.o.
* SECTION_ALIGNMENT
Some machines that use COFF executables require that each section
start on a certain boundary *in the COFF file*. Such machines should
define SECTION_ALIGNMENT to a mask of the low-order bits that must be
zero on such a boundary. This mask is used to control padding between
segments in the COFF file.
If SECTION_ALIGNMENT is not defined, the segments are written
consecutively with no attempt at alignment. This is right for
unmodified system V.
* SEGMENT_MASK
Some machines require that the beginnings and ends of segments
*in core* be on certain boundaries. For most machines, a page
boundary is sufficient. That is the default. When a larger
boundary is needed, define SEGMENT_MASK to a mask of
the bits that must be zero on such a boundary.
* A_TEXT_OFFSET(HDR)
Some machines count the a.out header as part of the size of the text
segment (a_text); they may actually load the header into core as the
first data in the text segment. Some have additional padding between
the header and the real text of the program that is counted in a_text.
For these machines, define A_TEXT_OFFSET(HDR) to examine the header
structure HDR and return the number of bytes to add to `a_text'
before writing it (above and beyond the number of bytes of actual
program text). HDR's standard fields are already correct, except that
this adjustment to the `a_text' field has not yet been made;
thus, the amount of offset can depend on the data in the file.
* A_TEXT_SEEK(HDR)
If defined, this macro specifies the number of bytes to seek into the
a.out file before starting to write the text segment.
* EXEC_MAGIC
For machines using COFF, this macro, if defined, is a value stored
into the magic number field of the output file.
* ADJUST_EXEC_HEADER
This macro can be used to generate statements to adjust or
initialize nonstandard fields in the file header
* ADDR_CORRECT(ADDR)
Macro to correct an int which is the bit pattern of a pointer to a byte
into an int which is the number of a byte.
This macro has a default definition which is usually right.
This default definition is a no-op on most machines (where a
pointer looks like an int) but not on all machines.
*/
#ifndef emacs
#define PERROR(arg) perror (arg); return -1
#else
#define IN_UNEXEC
#include
#define PERROR(file) report_error (file, new)
#endif
#ifndef CANNOT_DUMP /* all rest of file! */
#ifdef COFF_ENCAPSULATE
int need_coff_header = 1;
#include /* The location might be a poor assumption */
#else
#ifdef MSDOS
#if __DJGPP__ > 1
#include /* for O_RDONLY, O_RDWR */
#include /* for _crt0_startup_flags and its bits */
static int save_djgpp_startup_flags;
#endif
#include
#define filehdr external_filehdr
#define scnhdr external_scnhdr
#define syment external_syment
#define auxent external_auxent
#define n_numaux e_numaux
#define n_type e_type
struct aouthdr
{
unsigned short magic; /* type of file */
unsigned short vstamp; /* version stamp */
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
unsigned long dsize; /* initialized data " " */
unsigned long bsize; /* uninitialized data " " */
unsigned long entry; /* entry pt. */
unsigned long text_start;/* base of text used for this file */
unsigned long data_start;/* base of data used for this file */
};
#else /* not MSDOS */
#include
#endif /* not MSDOS */
#endif
/* Define getpagesize if the system does not.
Note that this may depend on symbols defined in a.out.h. */
#include "getpagesize.h"
#ifndef makedev /* Try to detect types.h already loaded */
#include
#endif /* makedev */
#include
#include
#include
#include /* Must be after sys/types.h for USG and BSD4_1*/
#ifdef USG5
#include
#endif
#ifndef O_RDONLY
#define O_RDONLY 0
#endif
#ifndef O_RDWR
#define O_RDWR 2
#endif
extern char *start_of_text (); /* Start of text */
extern char *start_of_data (); /* Start of initialized data */
#ifdef COFF
static long block_copy_start; /* Old executable start point */
static struct filehdr f_hdr; /* File header */
static struct aouthdr f_ohdr; /* Optional file header (a.out) */
long bias; /* Bias to add for growth */
long lnnoptr; /* Pointer to line-number info within file */
#define SYMS_START block_copy_start
static long text_scnptr;
static long data_scnptr;
#else /* not COFF */
#ifdef HPUX
extern void *sbrk ();
#else
#if 0
/* Some systems with __STDC__ compilers still declare this `char *' in some
header file, and our declaration conflicts. The return value is always
cast, so it should be harmless to leave it undefined. Hopefully
machines with different size pointers and ints declare sbrk in a header
file. */
#ifdef __STDC__
extern void *sbrk ();
#else
extern char *sbrk ();
#endif /* __STDC__ */
#endif
#endif /* HPUX */
#define SYMS_START ((long) N_SYMOFF (ohdr))
/* Some machines override the structure name for an a.out header. */
#ifndef EXEC_HDR_TYPE
#define EXEC_HDR_TYPE struct exec
#endif
#ifdef HPUX
#ifdef HP9000S200_ID
#define MY_ID HP9000S200_ID
#else
#include
#define MY_ID MYSYS
#endif /* no HP9000S200_ID */
static MAGIC OLDMAGIC = {MY_ID, SHARE_MAGIC};
static MAGIC NEWMAGIC = {MY_ID, DEMAND_MAGIC};
#define N_TXTOFF(x) TEXT_OFFSET(x)
#define N_SYMOFF(x) LESYM_OFFSET(x)
static EXEC_HDR_TYPE hdr, ohdr;
#else /* not HPUX */
#if defined (USG) && !defined (IBMAIX) && !defined (IRIS) && !defined (COFF_ENCAPSULATE) && !defined (LINUX)
static struct bhdr hdr, ohdr;
#define a_magic fmagic
#define a_text tsize
#define a_data dsize
#define a_bss bsize
#define a_syms ssize
#define a_trsize rtsize
#define a_drsize rdsize
#define a_entry entry
#define N_BADMAG(x) \
(((x).fmagic)!=OMAGIC && ((x).fmagic)!=NMAGIC &&\
((x).fmagic)!=FMAGIC && ((x).fmagic)!=IMAGIC)
#define NEWMAGIC FMAGIC
#else /* IRIS or IBMAIX or not USG */
static EXEC_HDR_TYPE hdr, ohdr;
#define NEWMAGIC ZMAGIC
#endif /* IRIS or IBMAIX not USG */
#endif /* not HPUX */
static int unexec_text_start;
static int unexec_data_start;
#ifdef COFF_ENCAPSULATE
/* coffheader is defined in the GNU a.out.encap.h file. */
struct coffheader coffheader;
#endif
#endif /* not COFF */
static int pagemask;
/* Correct an int which is the bit pattern of a pointer to a byte
into an int which is the number of a byte.
This is a no-op on ordinary machines, but not on all. */
#ifndef ADDR_CORRECT /* Let m-*.h files override this definition */
#define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
#endif
#ifdef emacs
#include "lisp.h"
static
report_error (file, fd)
char *file;
int fd;
{
if (fd)
close (fd);
report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
}
#endif /* emacs */
#define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
#define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1
#define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
static
report_error_1 (fd, msg, a1, a2)
int fd;
char *msg;
int a1, a2;
{
close (fd);
#ifdef emacs
error (msg, a1, a2);
#else
fprintf (stderr, msg, a1, a2);
fprintf (stderr, "\n");
#endif
}
static int make_hdr ();
static int copy_text_and_data ();
static int copy_sym ();
static void mark_x ();
/* ****************************************************************
* unexec
*
* driving logic.
*/
unexec (new_name, a_name, data_start, bss_start, entry_address)
char *new_name, *a_name;
unsigned data_start, bss_start, entry_address;
{
int new, a_out = -1;
if (a_name && (a_out = open (a_name, O_RDONLY)) < 0)
{
PERROR (a_name);
}
if ((new = creat (new_name, 0666)) < 0)
{
PERROR (new_name);
}
if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0
|| copy_text_and_data (new, a_out) < 0
|| copy_sym (new, a_out, a_name, new_name) < 0
#ifdef COFF
#ifndef COFF_BSD_SYMBOLS
|| adjust_lnnoptrs (new, a_out, new_name) < 0
#endif
#endif
)
{
close (new);
/* unlink (new_name); /* Failed, unlink new a.out */
return -1;
}
close (new);
if (a_out >= 0)
close (a_out);
mark_x (new_name);
return 0;
}
/* ****************************************************************
* make_hdr
*
* Make the header in the new a.out from the header in core.
* Modify the text and data sizes.
*/
static int
make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
int new, a_out;
unsigned data_start, bss_start, entry_address;
char *a_name;
char *new_name;
{
int tem;
#ifdef COFF
auto struct scnhdr f_thdr; /* Text section header */
auto struct scnhdr f_dhdr; /* Data section header */
auto struct scnhdr f_bhdr; /* Bss section header */
auto struct scnhdr scntemp; /* Temporary section header */
register int scns;
#endif /* COFF */
#ifdef USG_SHARED_LIBRARIES
extern unsigned int bss_end;
#else
unsigned int bss_end;
#endif
pagemask = getpagesize () - 1;
/* Adjust text/data boundary. */
#ifdef NO_REMAP
data_start = (int) start_of_data ();
#else /* not NO_REMAP */
if (!data_start)
data_start = (int) start_of_data ();
#endif /* not NO_REMAP */
data_start = ADDR_CORRECT (data_start);
#ifdef SEGMENT_MASK
data_start = data_start & ~SEGMENT_MASK; /* (Down) to segment boundary. */
#else
data_start = data_start & ~pagemask; /* (Down) to page boundary. */
#endif
bss_end = ADDR_CORRECT (sbrk (0)) + pagemask;
bss_end &= ~ pagemask;
/* Adjust data/bss boundary. */
if (bss_start != 0)
{
bss_start = (ADDR_CORRECT (bss_start) + pagemask);
/* (Up) to page bdry. */
bss_start &= ~ pagemask;
if (bss_start > bss_end)
{
ERROR1 ("unexec: Specified bss_start (%u) is past end of program",
bss_start);
}
}
else
bss_start = bss_end;
if (data_start > bss_start) /* Can't have negative data size. */
{
ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)",
data_start, bss_start);
}
#ifdef COFF
/* Salvage as much info from the existing file as possible */
if (a_out >= 0)
{
if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
{
PERROR (a_name);
}
block_copy_start += sizeof (f_hdr);
if (f_hdr.f_opthdr > 0)
{
if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
{
PERROR (a_name);
}
block_copy_start += sizeof (f_ohdr);
}
/* Loop through section headers, copying them in */
lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0);
for (scns = f_hdr.f_nscns; scns > 0; scns--) {
if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp))
{
PERROR (a_name);
}
if (scntemp.s_scnptr > 0L)
{
if (block_copy_start < scntemp.s_scnptr + scntemp.s_size)
block_copy_start = scntemp.s_scnptr + scntemp.s_size;
}
if (strcmp (scntemp.s_name, ".text") == 0)
{
f_thdr = scntemp;
}
else if (strcmp (scntemp.s_name, ".data") == 0)
{
f_dhdr = scntemp;
}
else if (strcmp (scntemp.s_name, ".bss") == 0)
{
f_bhdr = scntemp;
}
}
}
else
{
ERROR0 ("can't build a COFF file from scratch yet");
}
/* Now we alter the contents of all the f_*hdr variables
to correspond to what we want to dump. */
#ifdef USG_SHARED_LIBRARIES
/* The amount of data we're adding to the file is distance from the
* end of the original .data space to the current end of the .data
* space.
*/
bias = bss_start - (f_ohdr.data_start + f_dhdr.s_size);
#endif
f_hdr.f_flags |= (F_RELFLG | F_EXEC);
#ifdef TPIX
f_hdr.f_nscns = 3;
#endif
#ifdef EXEC_MAGIC
f_ohdr.magic = EXEC_MAGIC;
#endif
#ifndef NO_REMAP
f_ohdr.text_start = (long) start_of_text ();
f_ohdr.tsize = data_start - f_ohdr.text_start;
f_ohdr.data_start = data_start;
#endif /* NO_REMAP */
f_ohdr.dsize = bss_start - f_ohdr.data_start;
f_ohdr.bsize = bss_end - bss_start;
#ifndef KEEP_OLD_TEXT_SCNPTR
/* On some machines, the old values are right.
??? Maybe on all machines with NO_REMAP. */
f_thdr.s_size = f_ohdr.tsize;
f_thdr.s_scnptr = sizeof (f_hdr) + sizeof (f_ohdr);
f_thdr.s_scnptr += (f_hdr.f_nscns) * (sizeof (f_thdr));
#endif /* KEEP_OLD_TEXT_SCNPTR */
#ifdef ADJUST_TEXT_SCNHDR_SIZE
/* On some machines, `text size' includes all headers. */
f_thdr.s_size -= f_thdr.s_scnptr;
#endif /* ADJUST_TEST_SCNHDR_SIZE */
lnnoptr = f_thdr.s_lnnoptr;
#ifdef SECTION_ALIGNMENT
/* Some systems require special alignment
of the sections in the file itself. */
f_thdr.s_scnptr
= (f_thdr.s_scnptr + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT;
#endif /* SECTION_ALIGNMENT */
#ifdef TPIX
f_thdr.s_scnptr = 0xd0;
#endif
text_scnptr = f_thdr.s_scnptr;
#ifdef ADJUST_TEXTBASE
text_scnptr = sizeof (f_hdr) + sizeof (f_ohdr) + (f_hdr.f_nscns) * (sizeof (f_thdr));
#endif
#ifndef KEEP_OLD_PADDR
f_dhdr.s_paddr = f_ohdr.data_start;
#endif /* KEEP_OLD_PADDR */
f_dhdr.s_vaddr = f_ohdr.data_start;
f_dhdr.s_size = f_ohdr.dsize;
f_dhdr.s_scnptr = f_thdr.s_scnptr + f_thdr.s_size;
#ifdef SECTION_ALIGNMENT
/* Some systems require special alignment
of the sections in the file itself. */
f_dhdr.s_scnptr
= (f_dhdr.s_scnptr + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT;
#endif /* SECTION_ALIGNMENT */
#ifdef DATA_SECTION_ALIGNMENT
/* Some systems require special alignment
of the data section only. */
f_dhdr.s_scnptr
= (f_dhdr.s_scnptr + DATA_SECTION_ALIGNMENT) & ~DATA_SECTION_ALIGNMENT;
#endif /* DATA_SECTION_ALIGNMENT */
data_scnptr = f_dhdr.s_scnptr;
#ifndef KEEP_OLD_PADDR
f_bhdr.s_paddr = f_ohdr.data_start + f_ohdr.dsize;
#endif /* KEEP_OLD_PADDR */
f_bhdr.s_vaddr = f_ohdr.data_start + f_ohdr.dsize;
f_bhdr.s_size = f_ohdr.bsize;
f_bhdr.s_scnptr = 0L;
#ifndef USG_SHARED_LIBRARIES
bias = f_dhdr.s_scnptr + f_dhdr.s_size - block_copy_start;
#endif
if (f_hdr.f_symptr > 0L)
{
f_hdr.f_symptr += bias;
}
if (f_thdr.s_lnnoptr > 0L)
{
f_thdr.s_lnnoptr += bias;
}
#ifdef ADJUST_EXEC_HEADER
ADJUST_EXEC_HEADER;
#endif /* ADJUST_EXEC_HEADER */
if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
{
PERROR (new_name);
}
if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
{
PERROR (new_name);
}
#ifndef USG_SHARED_LIBRARIES
if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr))
{
PERROR (new_name);
}
if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr))
{
PERROR (new_name);
}
if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr))
{
PERROR (new_name);
}
#else /* USG_SHARED_LIBRARIES */
/* The purpose of this code is to write out the new file's section
* header table.
*
* Scan through the original file's sections. If the encountered
* section is one we know (.text, .data or .bss), write out the
* correct header. If it is a section we do not know (such as
* .lib), adjust the address of where the section data is in the
* file, and write out the header.
*
* If any section precedes .text or .data in the file, this code
* will not adjust the file pointer for that section correctly.
*/
/* This used to use sizeof (f_ohdr) instead of .f_opthdr.
.f_opthdr is said to be right when there is no optional header. */
lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0);
for (scns = f_hdr.f_nscns; scns > 0; scns--)
{
if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp))
PERROR (a_name);
if (!strcmp (scntemp.s_name, f_thdr.s_name)) /* .text */
{
if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr))
PERROR (new_name);
}
else if (!strcmp (scntemp.s_name, f_dhdr.s_name)) /* .data */
{
if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr))
PERROR (new_name);
}
else if (!strcmp (scntemp.s_name, f_bhdr.s_name)) /* .bss */
{
if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr))
PERROR (new_name);
}
else
{
if (scntemp.s_scnptr)
scntemp.s_scnptr += bias;
if (write (new, &scntemp, sizeof (scntemp)) != sizeof (scntemp))
PERROR (new_name);
}
}
#endif /* USG_SHARED_LIBRARIES */
return (0);
#else /* if not COFF */
/* Get symbol table info from header of a.out file if given one. */
if (a_out >= 0)
{
#ifdef COFF_ENCAPSULATE
if (read (a_out, &coffheader, sizeof coffheader) != sizeof coffheader)
{
PERROR(a_name);
}
if (coffheader.f_magic != COFF_MAGIC)
{
ERROR1("%s doesn't have legal coff magic number\n", a_name);
}
#endif
if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr)
{
PERROR (a_name);
}
if (N_BADMAG (ohdr))
{
ERROR1 ("invalid magic number in %s", a_name);
}
hdr = ohdr;
}
else
{
#ifdef COFF_ENCAPSULATE
/* We probably could without too much trouble. The code is in gld
* but I don't have that much time or incentive.
*/
ERROR0 ("can't build a COFF file from scratch yet");
#else
#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
bzero ((void *)&hdr, sizeof hdr);
#else
bzero (&hdr, sizeof hdr);
#endif
#endif
}
unexec_text_start = (long) start_of_text ();
unexec_data_start = data_start;
/* Machine-dependent fixup for header, or maybe for unexec_text_start */
#ifdef ADJUST_EXEC_HEADER
ADJUST_EXEC_HEADER;
#endif /* ADJUST_EXEC_HEADER */
hdr.a_trsize = 0;
hdr.a_drsize = 0;
if (entry_address != 0)
hdr.a_entry = entry_address;
hdr.a_bss = bss_end - bss_start;
hdr.a_data = bss_start - data_start;
#ifdef NO_REMAP
hdr.a_text = ohdr.a_text;
#else /* not NO_REMAP */
hdr.a_text = data_start - unexec_text_start;
#ifdef A_TEXT_OFFSET
hdr.a_text += A_TEXT_OFFSET (ohdr);
#endif
#endif /* not NO_REMAP */
#ifdef COFF_ENCAPSULATE
/* We are encapsulating BSD format within COFF format. */
{
struct coffscn *tp, *dp, *bp;
tp = &coffheader.scns[0];
dp = &coffheader.scns[1];
bp = &coffheader.scns[2];
tp->s_size = hdr.a_text + sizeof(struct exec);
dp->s_paddr = data_start;
dp->s_vaddr = data_start;
dp->s_size = hdr.a_data;
bp->s_paddr = dp->s_vaddr + dp->s_size;
bp->s_vaddr = bp->s_paddr;
bp->s_size = hdr.a_bss;
coffheader.tsize = tp->s_size;
coffheader.dsize = dp->s_size;
coffheader.bsize = bp->s_size;
coffheader.text_start = tp->s_vaddr;
coffheader.data_start = dp->s_vaddr;
}
if (write (new, &coffheader, sizeof coffheader) != sizeof coffheader)
{
PERROR(new_name);
}
#endif /* COFF_ENCAPSULATE */
if (write (new, &hdr, sizeof hdr) != sizeof hdr)
{
PERROR (new_name);
}
#if 0 /* This #ifndef caused a bug on Linux when using QMAGIC. */
/* This adjustment was done above only #ifndef NO_REMAP,
so only undo it now #ifndef NO_REMAP. */
/* #ifndef NO_REMAP */
#endif
#ifdef A_TEXT_OFFSET
hdr.a_text -= A_TEXT_OFFSET (ohdr);
#endif
return 0;
#endif /* not COFF */
}
/* ****************************************************************
* copy_text_and_data
*
* Copy the text and data segments from memory to the new a.out
*/
static int
copy_text_and_data (new, a_out)
int new, a_out;
{
register char *end;
register char *ptr;
#ifdef COFF
#ifdef USG_SHARED_LIBRARIES
int scns;
struct scnhdr scntemp; /* Temporary section header */
/* The purpose of this code is to write out the new file's section
* contents.
*
* Step through the section table. If we know the section (.text,
* .data) do the appropriate thing. Otherwise, if the section has
* no allocated space in the file (.bss), do nothing. Otherwise,
* the section has space allocated in the file, and is not a section
* we know. So just copy it.
*/
lseek (a_out, sizeof (struct filehdr) + sizeof (struct aouthdr), 0);
for (scns = f_hdr.f_nscns; scns > 0; scns--)
{
if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp))
PERROR ("temacs");
if (!strcmp (scntemp.s_name, ".text"))
{
lseek (new, (long) text_scnptr, 0);
ptr = (char *) f_ohdr.text_start;
end = ptr + f_ohdr.tsize;
write_segment (new, ptr, end);
}
else if (!strcmp (scntemp.s_name, ".data"))
{
lseek (new, (long) data_scnptr, 0);
ptr = (char *) f_ohdr.data_start;
end = ptr + f_ohdr.dsize;
write_segment (new, ptr, end);
}
else if (!scntemp.s_scnptr)
; /* do nothing - no data for this section */
else
{
char page[BUFSIZ];
int size, n;
long old_a_out_ptr = lseek (a_out, 0, 1);
lseek (a_out, scntemp.s_scnptr, 0);
for (size = scntemp.s_size; size > 0; size -= sizeof (page))
{
n = size > sizeof (page) ? sizeof (page) : size;
if (read (a_out, page, n) != n || write (new, page, n) != n)
PERROR ("emacs");
}
lseek (a_out, old_a_out_ptr, 0);
}
}
#else /* COFF, but not USG_SHARED_LIBRARIES */
#ifdef MSDOS
#if __DJGPP__ >= 2
/* Dump the original table of exception handlers, not the one
where our exception hooks are registered. */
__djgpp_exception_toggle ();
/* Switch off startup flags that might have been set at runtime
and which might change the way that dumped Emacs works. */
save_djgpp_startup_flags = _crt0_startup_flags;
_crt0_startup_flags &= ~(_CRT0_FLAG_NO_LFN | _CRT0_FLAG_NEARPTR);
#endif
#endif
lseek (new, (long) text_scnptr, 0);
ptr = (char *) f_ohdr.text_start;
#ifdef HEADER_INCL_IN_TEXT
/* For Gould UTX/32, text starts after headers */
ptr = (char *) (ptr + text_scnptr);
#endif /* HEADER_INCL_IN_TEXT */
end = ptr + f_ohdr.tsize;
write_segment (new, ptr, end);
lseek (new, (long) data_scnptr, 0);
ptr = (char *) f_ohdr.data_start;
end = ptr + f_ohdr.dsize;
write_segment (new, ptr, end);
#ifdef MSDOS
#if __DJGPP__ >= 2
/* Restore our exception hooks. */
__djgpp_exception_toggle ();
/* Restore the startup flags. */
_crt0_startup_flags = save_djgpp_startup_flags;
#endif
#endif
#endif /* USG_SHARED_LIBRARIES */
#else /* if not COFF */
/* Some machines count the header as part of the text segment.
That is to say, the header appears in core
just before the address that start_of_text returns.
For them, N_TXTOFF is the place where the header goes.
We must adjust the seek to the place after the header.
Note that at this point hdr.a_text does *not* count
the extra A_TEXT_OFFSET bytes, only the actual bytes of code. */
#ifdef A_TEXT_SEEK
lseek (new, (long) A_TEXT_SEEK (hdr), 0);
#else
lseek (new, (long) N_TXTOFF (hdr), 0);
#endif /* no A_TEXT_SEEK */
#ifdef RISCiX
/* Acorn's RISC-iX has a wacky way of initialising the position of the heap.
* There is a little table in crt0.o that is filled at link time with
* the min and current brk positions, among other things. When start
* runs, it copies the table to where these parameters live during
* execution. This data is in text space, so it cannot be modified here
* before saving the executable, so the data is written manually. In
* addition, the table does not have a label, and the nearest accessible
* label (mcount) is not prefixed with a '_', thus making it inaccessible
* from within C programs. To overcome this, emacs's executable is passed
* through the command 'nm %s | fgrep mcount' into a pipe, and the
* resultant output is then used to find the address of 'mcount'. As far as
* is possible to determine, in RISC-iX releases prior to 1.2, the negative
* offset of the table from mcount is 0x2c, whereas from 1.2 onwards it is
* 0x30. bss_end has been rounded up to page boundary. This solution is
* based on suggestions made by Kevin Welton and Steve Hunt of Acorn, and
* avoids the need for a custom version of crt0.o for emacs which has its
* table in data space.
*/
{
char command[1024];
char errbuf[1024];
char address_text[32];
int proforma[4];
FILE *pfile;
char *temp_ptr;
char c;
int mcount_address, mcount_offset, count;
extern char *_execname;
/* The use of _execname is incompatible with RISCiX 1.1 */
sprintf (command, "nm %s | fgrep mcount", _execname);
if ( (pfile = popen(command, "r")) == NULL)
{
sprintf (errbuf, "Could not open pipe");
PERROR (errbuf);
}
count=0;
while ( ((c=getc(pfile)) != EOF) && (c != ' ') && (count < 31))
address_text[count++]=c;
address_text[count]=0;
if ((count == 0) || pclose(pfile) != NULL)
{
sprintf (errbuf, "Failed to execute the command '%s'\n", command);
PERROR (errbuf);
}
sscanf(address_text, "%x", &mcount_address);
ptr = (char *) unexec_text_start;
mcount_offset = (char *)mcount_address - ptr;
#ifdef RISCiX_1_1
#define EDATA_OFFSET 0x2c
#else
#define EDATA_OFFSET 0x30
#endif
end = ptr + mcount_offset - EDATA_OFFSET;
write_segment (new, ptr, end);
proforma[0] = bss_end; /* becomes _edata */
proforma[1] = bss_end; /* becomes _end */
proforma[2] = bss_end; /* becomes _minbrk */
proforma[3] = bss_end; /* becomes _curbrk */
write (new, proforma, 16);
temp_ptr = ptr;
ptr = end + 16;
end = temp_ptr + hdr.a_text;
write_segment (new, ptr, end);
}
#else /* !RISCiX */
ptr = (char *) unexec_text_start;
end = ptr + hdr.a_text;
write_segment (new, ptr, end);
#endif /* RISCiX */
ptr = (char *) unexec_data_start;
end = ptr + hdr.a_data;
/* This lseek is certainly incorrect when A_TEXT_OFFSET
and I believe it is a no-op otherwise.
Let's see if its absence ever fails. */
/* lseek (new, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */
write_segment (new, ptr, end);
#endif /* not COFF */
return 0;
}
write_segment (new, ptr, end)
int new;
register char *ptr, *end;
{
register int i, nwrite, ret;
char buf[80];
extern int errno;
/* This is the normal amount to write at once.
It is the size of block that NFS uses. */
int writesize = 1 << 13;
int pagesize = getpagesize ();
char zeros[1 << 13];
bzero (zeros, sizeof (zeros));
for (i = 0; ptr < end;)
{
/* Distance to next multiple of writesize. */
nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr;
/* But not beyond specified end. */
if (nwrite > end - ptr) nwrite = end - ptr;
ret = write (new, ptr, nwrite);
/* If write gets a page fault, it means we reached
a gap between the old text segment and the old data segment.
This gap has probably been remapped into part of the text segment.
So write zeros for it. */
if (ret == -1
#ifdef EFAULT
&& errno == EFAULT
#endif
)
{
/* Write only a page of zeros at once,
so that we we don't overshoot the start
of the valid memory in the old data segment. */
if (nwrite > pagesize)
nwrite = pagesize;
write (new, zeros, nwrite);
}
#if 0 /* Now that we have can ask `write' to write more than a page,
it is legit for write do less than the whole amount specified. */
else if (nwrite != ret)
{
sprintf (buf,
"unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d",
ptr, new, nwrite, ret, errno);
PERROR (buf);
}
#endif
i += nwrite;
ptr += nwrite;
}
}
/* ****************************************************************
* copy_sym
*
* Copy the relocation information and symbol table from the a.out to the new
*/
static int
copy_sym (new, a_out, a_name, new_name)
int new, a_out;
char *a_name, *new_name;
{
char page[1024];
int n;
if (a_out < 0)
return 0;
#ifdef COFF
if (SYMS_START == 0L)
return 0;
#endif /* COFF */
#ifdef COFF
if (lnnoptr) /* if there is line number info */
lseek (a_out, lnnoptr, 0); /* start copying from there */
else
#endif /* COFF */
lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */
while ((n = read (a_out, page, sizeof page)) > 0)
{
if (write (new, page, n) != n)
{
PERROR (new_name);
}
}
if (n < 0)
{
PERROR (a_name);
}
return 0;
}
/* ****************************************************************
* mark_x
*
* After successfully building the new a.out, mark it executable
*/
static void
mark_x (name)
char *name;
{
struct stat sbuf;
int um;
int new = 0; /* for PERROR */
um = umask (777);
umask (um);
if (stat (name, &sbuf) == -1)
{
PERROR (name);
}
sbuf.st_mode |= 0111 & ~um;
if (chmod (name, sbuf.st_mode) == -1)
PERROR (name);
}
#ifdef COFF
#ifndef COFF_BSD_SYMBOLS
/*
* If the COFF file contains a symbol table and a line number section,
* then any auxiliary entries that have values for x_lnnoptr must
* be adjusted by the amount that the line number section has moved
* in the file (bias computed in make_hdr). The #@$%&* designers of
* the auxiliary entry structures used the absolute file offsets for
* the line number entry rather than an offset from the start of the
* line number section!
*
* When I figure out how to scan through the symbol table and pick out
* the auxiliary entries that need adjustment, this routine will
* be fixed. As it is now, all such entries are wrong and sdb
* will complain. Fred Fish, UniSoft Systems Inc.
*/
/* This function is probably very slow. Instead of reopening the new
file for input and output it should copy from the old to the new
using the two descriptors already open (WRITEDESC and READDESC).
Instead of reading one small structure at a time it should use
a reasonable size buffer. But I don't have time to work on such
things, so I am installing it as submitted to me. -- RMS. */
adjust_lnnoptrs (writedesc, readdesc, new_name)
int writedesc;
int readdesc;
char *new_name;
{
register int nsyms;
register int new;
#if defined (amdahl_uts) || defined (pfa)
SYMENT symentry;
AUXENT auxentry;
#else
struct syment symentry;
union auxent auxentry;
#endif
if (!lnnoptr || !f_hdr.f_symptr)
return 0;
#ifdef MSDOS
if ((new = writedesc) < 0)
#else
if ((new = open (new_name, O_RDWR)) < 0)
#endif
{
PERROR (new_name);
return -1;
}
lseek (new, f_hdr.f_symptr, 0);
for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++)
{
read (new, &symentry, SYMESZ);
if (symentry.n_numaux)
{
read (new, &auxentry, AUXESZ);
nsyms++;
if (ISFCN (symentry.n_type) || symentry.n_type == 0x2400)
{
auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias;
lseek (new, -AUXESZ, 1);
write (new, &auxentry, AUXESZ);
}
}
}
#ifndef MSDOS
close (new);
#endif
return 0;
}
#endif /* COFF_BSD_SYMBOLS */
#endif /* COFF */
#endif /* not CANNOT_DUMP */
scm-5f4/COPYING 0000755 0001750 0001750 00000104513 11675010371 010220 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
scm-5f4/README 0000664 0001750 0001750 00000012541 14551621663 010053 0000000 0000000 This directory contains the distribution of scm. SCM conforms to
Revised^5 Report on the Algorithmic Language Scheme and the IEEE P1178
specification. SCM runs under Amiga, Atari-ST, MacOS, MS-DOS, OS/2,
NOS/VE, Unicos, VMS, Unix and similar systems. SCM supports the SLIB
Scheme library; both SCM and SLIB are GNU packages.
1 Manifest
==========
'.gdbinit' provides commands for debugging SCM with GDB
'COPYING' GNU GENERAL PUBLIC LICENSE
'COPYING.LESSER' GNU LESSER GENERAL PUBLIC LICENSE
'ChangeLog' changes to SCM.
'Idiffer.scm' Linear-space O(PN) sequence comparison.
'Iedline.scm' Gnu readline input editing.
'Init.scm' Scheme initialization.
'Link.scm' Dynamic link/loading.
'Macro.scm' Supports Syntax-Rules Macros.
'Makefile' builds SCMLIT using the 'make' program.
'QUICKREF' Quick Reference card for R4RS and IEEE Scheme.
'README' contains a MANIFEST, INSTALLATION INSTRUCTIONS, hints
for EDITING SCHEME CODE, and a TROUBLE SHOOTING GUIDE.
'Transcen.scm' inexact builtin procedures.
'bench.scm' computes and records performance statistics of pi.scm.
'build.bat' invokes build.scm for MS-DOS
'build.scm' database for compiling and linking new SCM programs.
'byte.c' strings as bytes.
'bytenumb.c' Byte-number conversions.
'compile.scm' Hobbit compilation to C.
'continue-ia64.S'replaces make_root_continuation(),
make_continuation(), and dynthrow() in continue.c
'continue.c' continuations.
'continue.h' continuations.
'crs.c' interactive terminal control.
'debug.c' debugging, printing code.
'differ.c' Linear-space O(PN) sequence comparison.
'dynl.c' dynamically load object files.
'ecrt0.c' discover the start of initialized data space
dynamically at runtime.
'edline.c' Gnu readline input editing (get
ftp.sys.toronto.edu:/pub/rc/editline.shar).
'eval.c' evaluator, apply, map, and foreach.
'example.scm' example from R4RS which uses inexact numbers.
'fdl.texi' GNU Free Documentation License.
'findexec.c' find the executable file function.
'get-contoffset-ia64.c'makes contoffset-ia64.S for inclusion by
continue-ia64.S
'gmalloc.c' Gnu malloc(); used for unexec.
'gsubr.c' make_gsubr for arbitrary (< 11) arguments to C
functions.
'ioext.c' system calls in common between PC compilers and unix.
'lastfile.c' find the point in data space between data and
libraries.
'macosx-config.h'Included by unexmacosx.c and lastfile.c.
'mkimpcat.scm' build SCM-specific catalog for SLIB.
'patchlvl.h' patchlevel of this release.
'pi.c' computes digits of pi [cc -o pi pi.c;time pi 100 5].
'pi.scm' computes digits of pi [type (pi 100 5)]. Test
performance against pi.c.
'posix.c' posix library interface.
'pre-crt0.c' loaded before crt0.o on machines which do not remap
part of the data space into text space in unexec.
'r4rstest.scm' tests conformance with Scheme specifications.
'ramap.c' array mapping
'record.c' proposed 'Record' user definable datatypes.
'repl.c' error, read-eval-print loop, read, write and load.
'rgx.c' string regular expression match.
'rope.c' C interface functions.
'sc2.c' procedures from R2RS and R3RS not in R4RS.
'scl.c' inexact arithmetic
'scm.1' unix style man page.
'scm.c' initialization, interrupts, and non-IEEE utility
functions.
'scm.doc' man page generated from scm.1.
'scm.h' data type and external definitions of SCM.
'scm.texi' SCM installation and use.
'scmfig.h' contains system dependent definitions.
'scmmain.c' initialization, interrupts, and non-IEEE utility
functions.
'script.c' utilities for running as '#!' script.
'setjump.h' continuations, stacks, and memory allocation.
'setjump.mar' provides setjump and longjump which do not use $unwind
utility on VMS.
'setjump.s' provides setjump and longjump for the Cray YMP.
'socket.c' BSD socket interface.
'split.scm' example use of crs.c. Input, output, and diagnostic
output directed to separate windows.
'subr.c' the rest of IEEE functions.
'sys.c' call-with-current-continuation, opening and closing
files, storage allocation and garbage collection.
'time.c' functions dealing with time.
'ugsetjump.s' provides setjump and longjump which work on Ultrix
VAX.
'unexalpha.c' Convert a running program into an Alpha executable
file.
'unexec.c' Convert a running program into an executable file.
'unexelf.c' Convert a running ELF program into an executable file.
'unexhp9k800.c' Convert a running HP-UX program into an executable
file.
'unexmacosx.c' Convert a running program into an executable file
under MacOS X.
'unexsgi.c' Convert a running program into an IRIX executable
file.
'unexsunos4.c' Convert a running program into an executable file.
'unif.c' uniform vectors.
'unix.c' non-posix system calls on unix systems.
scm-5f4/scmfig.h 0000644 0001750 0001750 00000054037 14512635512 010613 0000000 0000000 /* "scmfig.h" system-dependent configuration.
* Copyright (C) 1990-2006 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* .
*/
/* Author: Aubrey Jaffer */
#ifdef sequent
# include
# define strchr index
# define strrchr rindex
#else
# ifndef PLAN9
# include
# endif
#endif
/* MS Windows signal handling hack added by Rainer Urian */
/*
SCM crashes on WindowsNT after hitting control-c.
This is because signal handling in windows console applications is
rather different from unix apps. If control-c is hit on a console
application Windows creates a new thread which executes the
control-c signal handler. Now, if the SCM handler does the longjmp
back to the repl loop it does it via the stack of the signal
handler thread which results always ever is an access violation.
The solution to this problem is to let the signal handler thread
raise a software interrupt in the main thread.
This is done with the following steps:
1. contol-c is hit
2. Windows creates the signal handler thread which in turn executes
the routine win32_sigint as its signal handler.
3. The handler suspends the main thread and gets the main threads
register context.
4. The handler simulates an interrupt call on the main thread by
pointing Eip to the sigintstub stub function and also simulates a
pushad , pushf of the main threads registers
5. The handler resumes the main thread which when scheduled will
execute sigintstub, which in turn calls the proper signal interupt
(scamble_signal)
*/
#ifdef _WIN32
/* POCKETCONSOLE has the signal handler implemented in the runtime */
# ifndef POCKETCONSOLE
# define WINSIGNALS
# endif
#endif
#include "scmflags.h" /* user specified, system independent flags */
/* IMPLINIT is the full pathname (surrounded by double quotes) of
Init.scm, the Scheme initialization code. This is best defined in
the makefile. If available, SCM uses the value of environment
variable SCM_INIT_PATH instead of IMPLINIT. */
/* #define IMPLINIT "/usr/jaffer/scm/Init.scm" */
/* INITS is calls to initialization routines for any compiled
libraries being linked into scm. This is best done in the makefile.
File: INITS line: functions defined:
sc2.c init_sc2(); substring-move-left!, substring-move-right!,
substring-fill!, append!, and last-pair
rgx.c init_rgx(); regcomp and regexec. */
/* #define INITS init_sc2(); */
/* #define SICP */
/* setbuf(0) needs to be done for tty ports in order for CHAR-READY?
to work. This can cause problems under MSDOS and other systems. */
/* #define NOSETBUF */
/* #define RECKLESS */
/* #define CAUTIOUS */
/* #define BIGNUMS */
/* #define ARRAYS */
/* #define FLOATS */
/* Define SINGLES if you want single precision floats and
(sizeof(float)==sizeof(long)) */
#ifdef FLOATS
# ifndef _MSC_VER
# define SINGLES
# endif
#endif
/* #define SINGLESONLY */
/* Define CDR_DOUBLES if (sizeof(double)==sizeof(long)), i.e.
a `single' is really a double. */
#ifdef FLOATS
# ifdef __alpha
# define CDR_DOUBLES
# endif
# ifdef _UNICOS /* doubles are no better than singles on Cray. */
# define SINGLESONLY
# endif
# ifdef CDR_DOUBLES
# define SINGLES
# define SINGLESONLY
# endif
#endif
/* #define ENGNOT */
/* Define SUN_DL to configure code in "dynl.c" so that dynamic linking
is done using the SUN dynamic linking library "dl". */
/* #define SUN_DL */
/* Define DLD to configure code in "dynl.c" so that dynamic linking is
done using the "dld" library. DLD is ported to Linux, VAX
(Ultrix), Sun 3 (SunOS 3.4 and 4.0), SPARCstation (SunOS 4.0),
Sequent Symmetry (Dynix), and Atari ST. See scm/README or
scm/ANNOUNCE for ftp sites offering dld. */
/* #define DLD */
/* Define HAVE_DYNL if dynamic linking is available */
#ifdef DLD
# define HAVE_DYNL
#endif
#ifdef SUN_DL
# define HAVE_DYNL
#endif
#ifdef HP_SHL
# define HAVE_DYNL
#endif
#ifdef SCM_WIN_DLL
# define HAVE_DYNL
#endif
#ifdef HAVE_DYNL
# define CCLO
#endif
/* Define GC_FREE_SEGMENTS if you want segments of unused heap to
be freed up after garbage collection. Don't define it if you
never want the heap to shrink. */
#ifndef DONT_GC_FREE_SEGMENTS
# define GC_FREE_SEGMENTS
#endif
/* MEMOIZE_LOCALS means to convert references to local variables to ILOCs,
(relative lexical addresses into the environment). This memoization
makes evaluated Scheme code harder to read, so you may want to undefine
this flag for debugging -- but SCM will run 3 to 6 times slower */
#ifndef DONT_MEMOIZE_LOCALS
# define MEMOIZE_LOCALS
#endif
/* #define CHEAP_CONTINUATIONS */
/* #define TICKS */
/* PROT386 should be defined on the compilation command line if the
program is to be run on an intel 386 in protected mode. `Huge'
pointers common on MSDOS compilers do not work in protected mode.
PROT386 is required if scm is to run as part of a Microsoft Windows
application. Added by Stephen Adams 8 May 92 */
/* #define PROT386 */
/* #define NON_PREEMPTIVE if you are using an non-preemptive operating
system in which periodic polling for interrupts is necessary.
Provide your own main procedure (e.g., WinMain, in Windows) or
modify "scmmain.c". Define and initialize unsigned int poll_count,
and provide a procedure named poll_routine(), which POLL calls each
time poll_count reaches zero. poll_routine() must reinitialize
poll_count. It may also check for external actions, such as
Windows messages. The value assigned to poll_count can be quite
large, e.g., 1000, while still maintaining good response time. */
/* #define CAREFUL_INTS */
/* Define MACRO if you want C level support for hygienic and referentially
transparent macros. */
/* #define MACRO */
/* STDC_HEADERS indicates that the include file names are the same as
ANSI C. For most modern systems this is the case. */
/* added by Yasuaki Honda */
#ifdef THINK_C
# define __STDC__
# ifndef macintosh
# define macintosh
# endif
#endif
/* added by Bob Schumaker, cobblers@netcom.com */
#ifdef __MWERKS__
# ifndef macintosh
# define macintosh
# endif
# define bzero(p, n) memset(p, 0, n)
# define bcopy memcpy
#endif
/* added by Denys Duchier */
#ifndef SVR4
# ifdef __SVR4
# define SVR4
# endif
#endif
#ifdef __STDC__
# ifndef __HIGHC__ /* overly fussy compiler */
# define USE_ANSI_PROTOTYPES
# endif
# ifndef __GNUC__
# define STDC_HEADERS
# else
# ifdef sparc
# ifdef SVR4
# define STDC_HEADERS
# endif
# else
# ifndef tahoe
# ifndef sun
# define STDC_HEADERS
# endif
# endif
# endif
# endif
#endif
#ifdef __aarch64__
# define SHORT_INT
# define CDR_DOUBLES
#endif
#ifdef __alpha
# define SHORT_INT
#endif
#ifdef __ia64__
# define SHORT_INT
# define CDR_DOUBLES
#endif
#ifdef __x86_64
# define SHORT_INT
# define CDR_DOUBLES
# ifdef __GNUC__ /* Includes gcc, clang, and llvm-gcc */
# define SCM_LLONG __int128
# endif
#endif
#ifdef _X86_ /* Includes at least gcc on 32-bit platforms */
# ifdef __STDC_VERSION__
# if (__STDC_VERSION__ >= 199901L) /* ISO C99, has long long */
# define SCM_LLONG long long
# endif
# endif
#endif
#ifdef MSDOS /* Microsoft C 5.10 and 6.00A */
# ifndef GO32
# define SHORT_INT
# define SHORT_SIZET
# endif
#endif
#ifdef _QC
# define SHORT_INT
# define SHORT_SIZET
#endif
#ifdef __TURBOC__
# define SHORT_INT
# define SHORT_SIZET
# define LACK_SBRK
# ifndef __TOS__
# define MSDOS
# endif
#endif
#ifdef __HIGHC__
# define LACK_SBRK
#endif
#ifdef _WIN32
# define MSDOS
# define LACK_SBRK
# define LACK_TIMES
#endif
#ifdef _MSDOS
# define MSDOS
#endif
#ifdef MSDOS
# define STDC_HEADERS
#endif
#ifdef POCKETCONSOLE
# define NOSETBUF
# define LACK_FTIME
#endif
#ifdef vms
# define STDC_HEADERS
#endif
#ifdef nosve
# define STDC_HEADERS
#endif
#ifdef linux
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# define STDC_HEADERS
#endif
#ifdef _UNICOS
# define STDC_HEADERS
#endif
#ifdef _AIX
# define _POSIX_SOURCE
# define LACK_FTIME
#endif
#ifdef __sgi__
# define LACK_FTIME
# define STDC_HEADERS
# define USE_ANSI_PROTOTYPES
# define HAVE_SYS_TIME_H
# define __SVR4
#endif
#ifdef __SVR4
# define HAVE_SELECT
#endif
#ifdef PLAN9
# define STDC_HEADERS
#endif
#ifdef hpux
# define LACK_E_IDs
#endif
/* C-Set++ for OS/2 */
#ifdef __IBMC__
# define STDC_HEADERS
# define LACK_TIMES
# define LACK_SBRK
#endif
#ifdef __CYGWIN__
/* # define LACK_FTIME */
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# undef MSDOS
#endif
#ifdef __amigaos__
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# define LACK_SBRK
#endif
/* PROMPT is the prompt string printed at top level */
#ifndef PROMPT
# ifdef SICP
# define PROMPT "==> "
# else
# define PROMPT "> "
# endif
#endif
/* #define BRACKETS_AS_PARENS to have [ and ] be read as ( and ) in forms. */
/* #define BRACKETS_AS_PARENS */
/* LINE_INCREMENTORS are the characters which cause the line count to
be incremented for the purposes of error reporting. This feature
is only used for scheme code loaded from files.
WHITE_SPACES are other characters which should be treated like spaces
in programs. in both cases sparate characters with ":case " */
#define LINE_INCREMENTORS '\n'
#ifdef MSDOS
# define WHITE_SPACES ' ':case '\t':case '\r':case '\f':case 26
#else
# define WHITE_SPACES ' ':case '\t':case '\r':case '\f'
#endif
#ifdef __ia64__
# define PTR2INT(x) ((long)(x))
#else
# ifdef __x86_64
# define PTR2INT(x) ((long)(x))
# else
# define PTR2INT(x) ((int)(x))
# endif
#endif
#ifndef __builtin_expect
# ifndef __GNUC__
# define __builtin_expect(expr, expected) (expr)
# else
# if (__GNUC__ < 3)
# define __builtin_expect(expr, expected) (expr)
# endif
# endif
#endif
#define SCM_EXPECT_TRUE(expr) (__builtin_expect(expr, !0))
#define SCM_EXPECT_FALSE(expr) (__builtin_expect(expr, 0))
#ifdef __GNUC__
# define FENCE asm volatile ("")
#else
# define FENCE /**/
#endif
#ifdef NON_PREEMPTIVE
# define VERIFY_INTS(s1, s2) /**/
# define DEFER_INTS /**/
# ifdef TICKS
# define POLL {if (0==poll_count--) poll_routine(); \
if (0==tick_count--) tick_signal();}
# else
# define POLL {if (0==poll_count--) poll_routine();}
# endif
# define CHECK_INTS POLL
# define ALLOW_INTS POLL
# define DEFER_INTS_EGC /**/
# define ALLOW_INTS_EGC /**/
#else
# ifdef CAREFUL_INTS
typedef struct {char *fname; int linum;} ints_infot;
extern ints_infot *ints_info;
# define VERIFY_INTS(s1, s2) {if (!ints_disabled)\
ints_warn(s1, s2, __FILE__, __LINE__); }
# define DEFER_INTS \
{static ints_infot info = {__FILE__, __LINE__};\
FENCE;if (1==ints_disabled) ints_viol(&info, 1);\
else {ints_info = &info; ints_disabled = 1;FENCE;}}
# define ALLOW_INTS \
{static ints_infot info = {__FILE__, __LINE__};\
FENCE;if (1!=ints_disabled) ints_viol(&info, 0);\
else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}}
# define DEFER_INTS_EGC \
{static ints_infot info = {__FILE__, __LINE__};\
FENCE;if (1==ints_disabled) ints_viol(&info, 1);\
else {ints_info = &info; ints_disabled = 2;FENCE;}}
# define ALLOW_INTS_EGC \
{static ints_infot info = {__FILE__, __LINE__};\
FENCE;if (1==ints_disabled) ints_viol(&info, 0);\
else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}}
# else
# define VERIFY_INTS(s1, s2) /**/
# define DEFER_INTS {FENCE;ints_disabled = 1;FENCE;}
# define ALLOW_INTS {FENCE;ints_disabled = 0;FENCE;CHECK_INTS}
# define DEFER_INTS_EGC {FENCE;ints_disabled = 2;FENCE;}
# define ALLOW_INTS_EGC {FENCE;ints_disabled = 0;FENCE;CHECK_INTS}
# endif
# ifdef TICKS
# define CHECK_INTS {if (deferred_proc) (*deferred_proc)(); POLL;}
# define POLL {if (0==tick_count--) tick_signal();}
# else
# define CHECK_INTS {if (deferred_proc) (*deferred_proc)();}
# define POLL /**/
# endif
#endif
#ifndef STACK_LIMIT
# define STACK_LIMIT (HEAP_SEG_SIZE)
#endif
#define CHECK_STACK {if (2 < scm_verbose) stack_check();}
/* Cray machines have pointers that are incremented once for each word,
rather than each byte, the 3 most significant bits encode the byte
within the word. The following macros deal with this by storing the
native Cray pointers like the ones that looks like scm expects. This
is done for any pointers that might appear in the car of a cell, pointers
to vector elts, functions, &c are not munged. */
#ifdef _UNICOS
# define SCM2PTR(x) ((int)(x) >> 3)
# define PTR2SCM(x) (((SCM)(x)) << 3)
# define POINTERS_MUNGED
#else
# ifdef TEST_SCM2PTR
# define SCM2PTR(x) ((x) ^ 0xf0L)
# define PTR2SCM(x) (((SCM)(x)) ^ 0xf0L)
# define POINTERS_MUNGED
# else
# define SCM2PTR(x) (x)
# define PTR2SCM(x) ((SCM)(x))
# endif
#endif
/* FIXABLE is non-null if its long argument can be encoded in an INUM. */
#define POSFIXABLE(n) SCM_EXPECT_TRUE((n) <= MOST_POSITIVE_FIXNUM)
#define NEGFIXABLE(n) SCM_EXPECT_TRUE((n) >= MOST_NEGATIVE_FIXNUM)
#define UNEGFIXABLE(n) SCM_EXPECT_TRUE((n) <= -MOST_NEGATIVE_FIXNUM)
#define FIXABLE(n) (POSFIXABLE(n) && NEGFIXABLE(n))
/* The following 8 definitions are defined automatically by the C
pre-processor. You will need to override these if you are
cross-compiling or if the C pre-processor has different properties
than the compiler. */
#if (((-1)%2==-1) && ((-1)%(-2)==-1) && (1%2==1) && (1%(-2)==1))
#else
# define BADIVSGNS
#endif
/* SRS is signed right shift */
/*--- Turbo C++ v1.0 has a bug with right shifts of signed longs!
It is believed to be fixed in Turbo C++ v1.01 ---*/
#if (-1==(((-1)<<2)+2)>>2) && (__TURBOC__ != 0x295)
# define SRS(x, y) ((x)>>y)
# ifdef __TURBOC__
# define INUM(x) (((x)>>1)>>1)
# else
# define INUM(x) SRS(x, 2)
# endif
#else
# define SRS(x, y) (((x)<0) ? ~((~(x))>>y) : (x)>>y)
# define INUM(x) SRS(x, 2)
#endif
#ifdef __TURBOC__
/* shifts of more than one are done by a library call, single shifts are
performed in registers */
# define MAKINUM(x) ((((x)<<1)<<1)+2L)
#else
# define MAKINUM(x) (((x)<<2)+2L)
#endif
#ifdef _DCC
# define ASCII
#else
# if (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301'))
# define EBCDIC
# endif
# if (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101'))
# define ASCII
# endif
#endif
/* CHAR_CODE_LIMIT is the number of distinct characters represented by
the unsigned char datatype. */
/* MOST_POSITIVE_FIXNUM is the INUM closest to positive infinity. */
/* MOST_NEGATIVE_FIXNUM is the INUM closest to negative infinity. */
#ifdef __STDC__
# define HAVE_LIMITSH
#endif
#ifdef MWC
# define HAVE_LIMITSH
#endif
#ifdef HAVE_LIMITSH
# include
# ifdef UCHAR_MAX
# define CHAR_CODE_LIMIT (UCHAR_MAX+1L)
# else
# define CHAR_CODE_LIMIT 256L
# endif
# define MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
# ifdef _UNICOS /* Stupid cray bug */
# define MOST_NEGATIVE_FIXNUM ((long)LONG_MIN/4)
# else
# define MOST_NEGATIVE_FIXNUM SRS((long)LONG_MIN, 2)
# endif /* UNICOS */
#else
# define CHAR_CODE_LIMIT 256L
# define MOST_POSITIVE_FIXNUM ((long)((unsigned long)~0L>>3))
# if (0 != ~0)
# define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM-1)
# else
# define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM)
# endif
#endif
/* INTBUFLEN is the maximum number of characters neccessary for the
printed or string representation of an exact number. */
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
#ifndef LONG_BIT
# define LONG_BIT (CHAR_BIT*sizeof(long)/sizeof(char))
#endif
#define INTBUFLEN (5+LONG_BIT)
/* Define BIGDIG to an integer type whose size is smaller than long if
you want bignums. BIGRAD is one greater than the biggest BIGDIG. */
/* Define DIGSTOOBIG if the digits equivalent to a long won't fit in a long. */
#ifdef BIGNUMS
# define SBIGLONG long
# define UBIGLONG unsigned SBIGLONG
# ifdef _UNICOS
# define DIGSTOOBIG
# if (1L << 31) <= USHRT_MAX
# define BIGDIG unsigned short
# else
# define BIGDIG unsigned int
# endif
# define BITSPERDIG 32
# else
# if INT_MAX < LONG_MAX
# define BIGDIG unsigned int
# else
# define BIGDIG unsigned short
# endif
# endif
# define BITSPERDIG (sizeof(BIGDIG)*CHAR_BIT)
# define BIGRAD (1L << BITSPERDIG)
# define DIGSPERLONG ((sizet)((sizeof(UBIGLONG))/sizeof(BIGDIG)))
# define BIGUP(x) (((UBIGLONG)(x)) << BITSPERDIG)
# define BIGDN(x) (((UBIGLONG)(x)) >> BITSPERDIG)
# define BIGLO(x) ((x) & (BIGRAD-1L))
/* NUMDIGS_MAX is the maximum number of digits for BIGNUMS */
# ifndef NUMDIGS_MAX
# define NUMDIGS_MAX 1000
# endif
#endif
#ifndef BIGDIG
# ifndef FLOATS
# define INUMS_ONLY
# endif
#endif
/* FLOBUFLEN is the maximum number of characters neccessary for the
printed or string representation of an inexact number. */
#ifdef FLOATS
# define FLOBUFLEN (10+2*(sizeof(double)/sizeof(char)*CHAR_BIT*3+9)/10)
#endif /* FLOATS */
/* MAXEXP is the maximum double precision exponent */
/* FLTMAX is less than or equal the largest single precision float */
#ifdef FLOATS
# ifdef STDC_HEADERS
# ifndef macintosh
# ifndef PLAN9
# include
# endif
# endif
# endif
# ifdef DBL_MAX_10_EXP
# define MAXEXP DBL_MAX_10_EXP
# else
# define MAXEXP 308 /* IEEE doubles */
# endif
# ifndef DBL_DIG
# define DBL_DIG 15
# endif
# ifndef DBL_MAX_EXP
# define DBL_MAX_EXP 1024
# endif
# ifdef FLT_MAX
# define FLTMAX FLT_MAX
# else
# define FLTMAX 1e+23
# endif
#endif
#ifdef FLOATS
# ifndef __MINGW32__
/* Also asinh and acosh */
# define HAVE_ATANH
# endif
#endif
/*
SCM_LLONG, if defined, must be a signed integer type wide enough to hold the
product of SCM_LONG * SCM_LONG.
*/
#ifdef SCM_LLONG
# define SCM_ULLONG unsigned SCM_LLONG
#endif
#ifdef unix
# define HAVE_UNIX
#endif
#ifdef __unix__
# define HAVE_UNIX
#endif
#ifdef _IBMR2
# define HAVE_UNIX
# define STDC_HEADERS
#endif
/* Only some machines have pipes */
#ifdef HAVE_UNIX
/* DJGPP (gcc for i386) defines unix! */
# define HAVE_PIPE
#endif
#ifndef macintosh
# ifndef _M_ARM
# ifndef _M_ARMT
# ifdef __WINDOWS__ /* there should be a better flag for this. */
# define PROT386
# endif
# endif
# endif
#endif
/* PTR_LT defines how to compare two CELLPTRs (which may not be in the
same array). CELLPTR is a pointer to a cons cell which may be
compared or differenced. SCMPTR is used for stack bounds. */
#if defined(__TURBOC__) && !defined(__TOS__)
# ifdef PROT386
typedef cell *CELLPTR;
typedef SCM *SCMPTR;
# define PTR_LT(x, y) (((long)(x)) < ((long)(y)))
# else
typedef cell huge *CELLPTR;
typedef SCM huge *SCMPTR;
# define PTR_LT(x, y) ((x) < (y))
# endif
#else /* not __TURBOC__ */
typedef cell *CELLPTR;
typedef SCM *SCMPTR;
# ifdef nosve
# define PTR_MASK 0xffffffffffff
# define PTR_LT(x, y) (((int)(x)&PTR_MASK) < ((int)(y)&PTR_MASK))
# else
# define PTR_LT(x, y) ((x) < (y))
# endif
#endif
#define PTR_GT(x, y) PTR_LT(y, x)
#define PTR_LE(x, y) (!PTR_GT(x, y))
#define PTR_GE(x, y) (!PTR_LT(x, y))
#ifdef STDC_HEADERS
# ifdef PLAN9
# define sizet long
# else
# include
# ifdef AMIGA
# include
# endif
# define sizet size_t
# endif
#else
# ifdef _SIZE_T
# define sizet size_t
# else
# define sizet unsigned int
# endif
#endif
#ifdef __APPLE__
# include
#endif
#ifdef macintosh
# include
#endif
#ifdef __FreeBSD__
# include
#endif
#ifdef linux
# include
#endif
/* On VMS, GNU C's errno.h contains a special hack to get link attributes
for errno correct for linking with libc. */
#ifndef PLAN9
# include
#endif
/* SYSCALL retries system calls that have been interrupted (EINTR) */
#ifdef vms
# ifndef __GNUC__
# include
# define SCM_INTERRUPTED(errno) (EVMSERR==errno && \
(vaxc$errno>>3)==(SS$_CONTROLC>>3))
# endif
#endif
#ifndef SCM_INTERRUPTED
# ifdef EINTR
# if (EINTR > 0)
# define SCM_INTERRUPTED(errno) (EINTR==errno)
# endif
# endif
#endif
#ifndef SCM_INTERRUPTED
# define SCM_INTERRUPTED(errno) (0)
#endif
#ifdef _WIN32
// Windows doesn't set errno = EINTR
# define SYSCALL(line) do{line;while(GetLastError() == ERROR_OPERATION_ABORTED){SetLastError(0);Sleep(10);line};}while(0)
#else
# define SYSCALL(line) do{errno = 0;line}while(SCM_INTERRUPTED(errno))
#endif
#ifdef EMFILE
# ifdef ENFILE
# define SCM_NEED_FDS(errno) (EMFILE==errno || ENFILE==errno)
# else
# define SCM_NEED_FDS(errno) (EMFILE==errno)
# endif
#else
# define SCM_NEED_FDS(errno) (0)
#endif
#define SCM_OPENCALL(line) {int gcs = 0;\
while (!0) {errno = 0; if ((line)) break;\
if (0==gcs++ && SCM_NEED_FDS(errno)) \
gc_for_open_files();\
else if (!SCM_INTERRUPTED(errno)) break;}}
#ifndef MSDOS
# ifdef ARM_ULIB
extern volatile int errno;
# else
extern int errno;
# endif
#endif
#ifdef __TURBOC__
# if (__TURBOC__==1)
/* Needed for TURBOC V1.0 */
extern int errno;
# endif
#endif
/* EXIT_SUCCESS is the default code to return from SCM if no errors
were encountered. EXIT_FAILURE is the default code to return from
SCM if errors were encountered. The return code can be explicitly
specified in a SCM program with (quit ). */
#ifndef EXIT_SUCCESS
# ifdef vms
# define EXIT_SUCCESS 1
# else
# define EXIT_SUCCESS 0
# endif
#endif
#ifndef EXIT_FAILURE
# ifdef vms
# define EXIT_FAILURE 2
# else
# define EXIT_FAILURE 1
# endif
#endif
/* Yasuaki Honda, Bob Schumaker */
/* Think C and Metrowerks lack isascii macro */
#ifdef macintosh
# define isascii(c) ((unsigned)(c) <= 0x7f)
#endif
#ifdef _DCC
# define isascii(c) ((unsigned)(c) <= 0x7f)
#endif
#ifdef __STDC__
# define VOLATILE volatile
#else
# define VOLATILE /**/
#endif
#ifdef _MSC_VER
// Disable annoying warnings for:
# pragma warning (disable: 4102) // unreferenced label
# pragma warning (disable: 4018) // signed/unsigned mismatch
# pragma warning (disable: 4101) // unreferenced variables
# pragma warning (disable: 4244) // conversion from unsigned long to unsigned short
#endif
/* end of automatic C pre-processor definitions */
scm-5f4/unexhp9k800.c 0000755 0001750 0001750 00000022667 06467700740 011356 0000000 0000000 /* Unexec for HP 9000 Series 800 machines.
Bob Desinger
Note that the GNU project considers support for HP operation a
peripheral activity which should not be allowed to divert effort
from development of the GNU system. Changes in this code will be
installed when users send them in, but aside from that we don't
plan to think about it, or about whether other Emacs maintenance
might break it.
Unexec creates a copy of the old a.out file, and replaces the old data
area with the current data area. When the new file is executed, the
process will see the same data structures and data values that the
original process had when unexec was called.
Unlike other versions of unexec, this one copies symbol table and
debug information to the new a.out file. Thus, the new a.out file
may be debugged with symbolic debuggers.
If you fix any bugs in this, I'd like to incorporate your fixes.
Send them to uunet!hpda!hpsemc!jmorris or jmorris%hpsemc@hplabs.HP.COM.
CAVEATS:
This routine saves the current value of all static and external
variables. This means that any data structure that needs to be
initialized must be explicitly reset. Variables will not have their
expected default values.
Unfortunately, the HP-UX signal handler has internal initialization
flags which are not explicitly reset. Thus, for signals to work in
conjunction with this routine, the following code must executed when
the new process starts up.
void _sigreturn ();
...
sigsetreturn (_sigreturn);
*/
#include
#include
#include
#include
#ifdef emacs
#include
#endif
#ifdef HPUX_USE_SHLIBS
#include
#endif
/* brk value to restore, stored as a global.
This is really used only if we used shared libraries. */
static long brk_on_dump = 0;
/* Called from main, if we use shared libraries. */
int
run_time_remap (ignored)
char *ignored;
{
brk ((char *) brk_on_dump);
}
#undef roundup
#define roundup(x,n) (((x) + ((n) - 1)) & ~((n) - 1)) /* n is power of 2 */
#define min(x,y) (((x) < (y)) ? (x) : (y))
/* Create a new a.out file, same as old but with current data space */
unexec (new_name, old_name, new_end_of_text, dummy1, dummy2)
char new_name[]; /* name of the new a.out file to be created */
char old_name[]; /* name of the old a.out file */
char *new_end_of_text; /* ptr to new edata/etext; NOT USED YET */
int dummy1, dummy2; /* not used by emacs */
{
int old, new;
int old_size, new_size;
struct header hdr;
struct som_exec_auxhdr auxhdr;
long i;
/* For the greatest flexibility, should create a temporary file in
the same directory as the new file. When everything is complete,
rename the temp file to the new name.
This way, a program could update its own a.out file even while
it is still executing. If problems occur, everything is still
intact. NOT implemented. */
/* Open the input and output a.out files */
old = open (old_name, O_RDONLY);
if (old < 0)
{ perror (old_name); exit (1); }
new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777);
if (new < 0)
{ perror (new_name); exit (1); }
/* Read the old headers */
read_header (old, &hdr, &auxhdr);
brk_on_dump = (long) sbrk (0);
/* Decide how large the new and old data areas are */
old_size = auxhdr.exec_dsize;
/* I suspect these two statements are separate
to avoid a compiler bug in hpux version 8. */
i = (long) sbrk (0);
new_size = i - auxhdr.exec_dmem;
/* Copy the old file to the new, up to the data space */
lseek (old, 0, 0);
copy_file (old, new, auxhdr.exec_dfile);
/* Skip the old data segment and write a new one */
lseek (old, old_size, 1);
save_data_space (new, &hdr, &auxhdr, new_size);
/* Copy the rest of the file */
copy_rest (old, new);
/* Update file pointers since we probably changed size of data area */
update_file_ptrs (new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size);
/* Save the modified header */
write_header (new, &hdr, &auxhdr);
/* Close the binary file */
close (old);
close (new);
return 0;
}
/* Save current data space in the file, update header. */
save_data_space (file, hdr, auxhdr, size)
int file;
struct header *hdr;
struct som_exec_auxhdr *auxhdr;
int size;
{
/* Write the entire data space out to the file */
if (write (file, auxhdr->exec_dmem, size) != size)
{ perror ("Can't save new data space"); exit (1); }
/* Update the header to reflect the new data size */
auxhdr->exec_dsize = size;
auxhdr->exec_bsize = 0;
}
/* Update the values of file pointers when something is inserted. */
update_file_ptrs (file, hdr, auxhdr, location, offset)
int file;
struct header *hdr;
struct som_exec_auxhdr *auxhdr;
unsigned int location;
int offset;
{
struct subspace_dictionary_record subspace;
int i;
/* Increase the overall size of the module */
hdr->som_length += offset;
/* Update the various file pointers in the header */
#define update(ptr) if (ptr > location) ptr = ptr + offset
update (hdr->aux_header_location);
update (hdr->space_strings_location);
update (hdr->init_array_location);
update (hdr->compiler_location);
update (hdr->symbol_location);
update (hdr->fixup_request_location);
update (hdr->symbol_strings_location);
update (hdr->unloadable_sp_location);
update (auxhdr->exec_tfile);
update (auxhdr->exec_dfile);
/* Do for each subspace dictionary entry */
lseek (file, hdr->subspace_location, 0);
for (i = 0; i < hdr->subspace_total; i++)
{
if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace))
{ perror ("Can't read subspace record"); exit (1); }
/* If subspace has a file location, update it */
if (subspace.initialization_length > 0
&& subspace.file_loc_init_value > location)
{
subspace.file_loc_init_value += offset;
lseek (file, -sizeof (subspace), 1);
if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace))
{ perror ("Can't update subspace record"); exit (1); }
}
}
/* Do for each initialization pointer record */
/* (I don't think it applies to executable files, only relocatables) */
#undef update
}
/* Read in the header records from an a.out file. */
read_header (file, hdr, auxhdr)
int file;
struct header *hdr;
struct som_exec_auxhdr *auxhdr;
{
/* Read the header in */
lseek (file, 0, 0);
if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
{ perror ("Couldn't read header from a.out file"); exit (1); }
if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC
&& hdr->a_magic != DEMAND_MAGIC)
{
fprintf (stderr, "a.out file doesn't have legal magic number\n");
exit (1);
}
lseek (file, hdr->aux_header_location, 0);
if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr))
{
perror ("Couldn't read auxiliary header from a.out file");
exit (1);
}
}
/* Write out the header records into an a.out file. */
write_header (file, hdr, auxhdr)
int file;
struct header *hdr;
struct som_exec_auxhdr *auxhdr;
{
/* Update the checksum */
hdr->checksum = calculate_checksum (hdr);
/* Write the header back into the a.out file */
lseek (file, 0, 0);
if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
{ perror ("Couldn't write header to a.out file"); exit (1); }
lseek (file, hdr->aux_header_location, 0);
if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr))
{ perror ("Couldn't write auxiliary header to a.out file"); exit (1); }
}
/* Calculate the checksum of a SOM header record. */
calculate_checksum (hdr)
struct header *hdr;
{
int checksum, i, *ptr;
checksum = 0; ptr = (int *) hdr;
for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++)
checksum ^= ptr[i];
return (checksum);
}
/* Copy size bytes from the old file to the new one. */
copy_file (old, new, size)
int new, old;
int size;
{
int len;
int buffer[8192]; /* word aligned will be faster */
for (; size > 0; size -= len)
{
len = min (size, sizeof (buffer));
if (read (old, buffer, len) != len)
{ perror ("Read failure on a.out file"); exit (1); }
if (write (new, buffer, len) != len)
{ perror ("Write failure in a.out file"); exit (1); }
}
}
/* Copy the rest of the file, up to EOF. */
copy_rest (old, new)
int new, old;
{
int buffer[4096];
int len;
/* Copy bytes until end of file or error */
while ((len = read (old, buffer, sizeof (buffer))) > 0)
if (write (new, buffer, len) != len) break;
if (len != 0)
{ perror ("Unable to copy the rest of the file"); exit (1); }
}
#ifdef DEBUG
display_header (hdr, auxhdr)
struct header *hdr;
struct som_exec_auxhdr *auxhdr;
{
/* Display the header information (debug) */
printf ("\n\nFILE HEADER\n");
printf ("magic number %d \n", hdr->a_magic);
printf ("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize);
printf ("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize);
printf ("entry %x \n", auxhdr->exec_entry);
printf ("Bss segment size %u\n", auxhdr->exec_bsize);
printf ("\n");
printf ("data file loc %d size %d\n",
auxhdr->exec_dfile, auxhdr->exec_dsize);
printf ("som_length %d\n", hdr->som_length);
printf ("unloadable sploc %d size %d\n",
hdr->unloadable_sp_location, hdr->unloadable_sp_size);
}
#endif /* DEBUG */
scm-5f4/indexes.texi 0000755 0001750 0001750 00000002066 10601246054 011514 0000000 0000000
@ifhtml
@node Index, Procedure and Macro Index, The Implementation, Top
@unnumbered Index
@end ifhtml
@ifnotinfo
@menu
* Procedure and Macro Index::
* Variable Index::
* Type Index::
* Concept Index::
@end menu
@end ifnotinfo
@ifnotinfo
@node Procedure and Macro Index, Variable Index, Index, Index
@end ifnotinfo
@unnumbered Procedure and Macro Index
@c This is an alphabetical list of all the procedures and macros in SCM.
@printindex fn
@ifnotinfo
@node Variable Index, Type Index, Procedure and Macro Index, Index
@end ifnotinfo
@unnumbered Variable Index
@c This is an alphabetical list of all the global variables in SCM.
@printindex vr
@ifnotinfo
@node Type Index, Concept Index, Variable Index, Index
@end ifnotinfo
@unnumbered Type Index
@c This is an alphabetical list of data types and feature names in SCM.
@printindex tp
@ifnotinfo
@node Concept Index, , Type Index, Index
@end ifnotinfo
@unnumbered Concept Index
@c This is an alphabetical list of concepts introduced in this manual.
@printindex cp
scm-5f4/scm.1 0000755 0001750 0001750 00000021052 11650443477 010037 0000000 0000000 .\" dummy line
.TH SCM 1 "February 2008"
.UC 4
.SH NAME
scm \- a Scheme Language Interpreter
.SH SYNOPSIS
.B scm
[-a
.I kbytes
]
[-muvqib]
[--version]
[--help]
.br
[[-]-no-init-file] [--no-symbol-case-fold]
.br
[-p
.I int
] [-r
.I feature
] [-h
.I feature
]
.br
[-d
.I filename
] [-f
.I filename
] [-l
.I filename
]
.br
[-c
.I expression
] [-e
.I expression
]
[-o
.I dumpname
]
.br
[-- | - | -s] [
.I filename
] [
.I arguments ...
]
.br
.sp 0.3
.SH DESCRIPTION
.I Scm
is a Scheme interpreter.
.PP
Upon startup
.I scm
loads the file specified by by the environment variable SCM_INIT_PATH
or by the parameter IMPLINIT in the makefile (or scmfig.h) if
SCM_INIT_PATH is not defined. The makefiles attempt to set IMPLINIT
to "Init.scm" in the source directory.
Unless the option
.I -no-init-file
or
.I --no-init-file
occurs in the command line or if
.I scm
is being invoked as a script, "Init.scm" checks to see if there is
file "ScmInit.scm" in the path specified by the environment variable
HOME (or in the current directory if HOME is undefined). If it finds
such a file, then it is loaded.
"Init.scm" then looks for command input from one of three sources:
From an option on the command line, from a file named on the command
line, or from standard input.
.SH OPTIONS
The options are processed in the order specified on the command line.
.TP 5
.BI -a kbytes
specifies that
.I scm
should allocate an initial heapsize of
.I kbytes.
This option, if present, must be the first on the command line.
.TP
.BI --no-init-file
Inhibits the loading of "ScmInit.scm" as described above.
.TP
.BI --no-symbol-case-fold
Symbol (and identifier) names are case-sensitive.
.TP
.BI -e expression
.TP
.BI -c expression
specifies that the scheme expression
.I expression
is to be evaluated. These options are inspired by
.I perl
and
.I sh
respectively.
On Amiga systems the entire option and argument need to be enclosed in
quotes. For instance "-e(newline)".
.TP
.BI -r feature
requires
.I feature.
This will load a file from SLIB if that
.I feature
is not already supported. If
.I feature
is 2, 3, 4, or 5
.I scm
will require the features necessary to support R2RS, R3RS, R4RS, or
R5RS, respectively.
.TP
.BI -h feature
provides
.I feature.
.TP
.BI -l filename
.TP
.BI -f filename
loads
.I filename.
.I Scm
will load the first (unoptioned) file named on the command line if no
-c, -e, -f, -l, or -s option precedes it.
.TP
.BI -d filename
opens (read-only) the extended relational database
.I filename.
If
.I filename
contains initialization code, it will be run when the database is
opened.
.TP
.BI -o dumpname
saves the current SCM session as the executable program
.I dumpname.
This option works only in SCM builds supporting
.BI dump.
If options appear on the command line after
.I -o dumpname,
then the saved session will continue with processing those options
when it is invoked. Otherwise the (new) command line is processed as
usual when the saved image is invoked.
.TP
.BI -p level
sets the prolixity (verboseness) to
.I level.
This is the same as the
.I scm
command (verbose
.I level
).
.TP
.B -v
(verbose mode) specifies that
.I scm
will print prompts, evaluation times, notice of loading files, and
garbage collection statistics. This is the same as
.I -p3.
.TP
.B -q
(quiet mode) specifies that
.I scm
will print no extra information. This is the same as
.I -p0.
.TP
.B -m
specifies that subsequent loads, evaluations, and user interactions
will be with R4RS macro capability. To use a specific R4RS macro
implementation from SLIB (instead of SLIB's default) put
.I -r macropackage
before
.I -m
on the command line.
.TP
.B -u
specifies that subsequent loads, evaluations, and user interactions
will be without R4RS macro capability. R4RS macro capability can be
restored by a subsequent
.I -m
on the command line or from Scheme code.
.TP
.B -i
specifies that
.I scm
should run interactively. That means that
.I scm
will not terminate until the
.I (quit)
or
.I (exit)
command is given, even if there are errors. It also sets the
prolixity level to 2 if it is less than 2. This will print
prompts, evaluation times, and notice of loading files. The prolixity
level can be set by subsequent options. If
.I scm
is started from a tty, it will assume that it should be interactive
unless given a subsequent
.I -b
option.
.TP
.B -b
specifies that
.I scm
should run non-interactively. That means that
.I scm
will terminate after processing the command line or if there are
errors.
.TP
.B -s
specifies, by analogy with
.I sh,
that further options are to be treated as program arguments.
.TP
.BI -
.BI --
specifies that there are no more options on the command line.
.SH ENVIRONMENT VARIABLES
.TP 5
.B SCM_INIT_PATH
is the pathname where
.I scm
will look for its initialization code. The default is the file
"Init.scm" in the source directory.
.TP
.B SCHEME_LIBRARY_PATH
is the SLIB Scheme library directory.
.TP
.B HOME
is the directory where "Init.scm" will look for the user
initialization file "ScmInit.scm".
.SH SCHEME VARIABLES
.TP 5
.B *argv*
contains the list of arguments to the program.
.I *argv*
can change during argument processing. This list is
suitable for use as an argument to SLIB
.I getopt.
.TP
.B *R4RS-macro*
controls whether loading and interaction support R4RS macros. Define
this in "ScmInit.scm" or files specified on the command line. This
can be overridden by subsequent -m and -u options.
.TP
.B *interactive*
controls interactivity as explained for the -i and -b options. Define
this in "ScmInit.scm" or files specified on the command line. This
can be overridden by subsequent -i and -b options.
.SH EXAMPLES
.ne 5
.TP 5
% scm foo.scm arg1 arg2 arg3
.br
Load and execute the contents of foo.scm. Parameters
arg1 arg2 and arg3 are stored in the global list *argv*.
.TP
% scm -f foo.scm arg1 arg2 arg3
.br
The same.
.TP
% scm -s foo.scm arg1 arg2
.br
Set *argv* to ("foo.scm" "arg1" "arg2") and enter interactive session.
.TP
% scm -e '(display (list-ref *argv* *optind*))' bar
.br
Print ``bar''
.TP
% scm -rpretty-print -r format -i
.br
Load pretty-print and format and enter interactive mode.
.TP
% scm -r5
.br
Load dynamic-wind, values, and R4RS macros and enter interactive (with
macros) mode.
.TP
% scm -r5 -r4
.br
Like above but rev4-optional-procedures are also loaded.
.SH FEATURES
.PP
Runs under Amiga, Atari-ST, MacOS, MS-DOS, OS/2, NOS/VE, Unicos, VMS,
Unix and similar systems. Support for ASCII and EBCDIC character
sets.
.PP
Conforms to Revised^5 Report on the Algorithmic Language Scheme
and the IEEE P1178 specification.
.PP
Support for SICP, R2RS, R3RS, and R4RS scheme code.
.PP
Many Common Lisp functions:
logand, logor, logxor, lognot, ash, logcount, integer-length,
bit-extract, defmacro, macroexpand, macroexpand1, gentemp,
defvar, force-output, software-type, get-decoded-time,
get-internal-run-time, get-internal-real-time, delete-file,
rename-file, copy-tree, acons, and eval.
.PP
Char-code-limit, most-positive-fixnum, most-negative-fixnum,
and internal-time-units-per-second constants. *Features* and
*load-pathname* variables.
.PP
Arrays and bit-vectors. String ports and software emulation ports.
I/O extensions providing most of ANSI C and POSIX.1 facilities.
.PP
User definable responses to interrupts and errors,
Process-synchronization primitives, String regular expression matching,
and the CURSES screen management package.
.PP
Available add-on packages including an interactive debugger, database,
X-window graphics, BGI graphics, Motif, and Open-Windows packages.
.PP
A compiler (HOBBIT, available separately) and dynamic linking of
compiled modules.
.PP
Setable levels of monitoring and timing information printed
interactively (the `verbose' function). Restart, quit, and exec.
.SH FILES
.TP
scm.texi
.br
Texinfo documentation of
.I scm
enhancements, internal representations, and how to extend or include
.I scm
in other programs.
.SH AUTHORS
Aubrey Jaffer (agj@alum.mit.edu)
.br
Radey Shouman
.SH BUGS
.SH SEE ALSO
The SCM home-page:
.br
http://people.csail.mit.edu/jaffer/SCM.html
.PP
The Scheme specifications for details on specific procedures
(http://groups.csail.mit.edu/mac/ftpdir/scheme-reports) or
.PP
IEEE Std 1178-1990,
.br
IEEE Standard for the Scheme Programming Language,
.br
Institute of Electrical and Electronic Engineers, Inc.,
.br
New York, NY, 1991
.PP
Brian Harvey and Matthew Wright
.br
Simply Scheme: Introducing Computer Science_
.br
MIT Press, 1994 ISBN 0-262-08226-8
.PP
R. Kent Dybvig, The Scheme Programming Language,
.br
Prentice-Hall Inc, Englewood Cliffs, New Jersey 07632, USA
.PP
H. Abelson, G. J. Sussman, and J. Sussman,
.br
Structure and Interpretation of Computer Programs,
.br
The MIT Press, Cambridge, Massachusetts, USA
scm-5f4/pi.c 0000755 0001750 0001750 00000003207 10750240510 007730 0000000 0000000 /* "pi.c", program for computing digits of numerical value of PI.
* Copyright (C) 1991 1995 Free Software Foundation, Inc.
*
* This program 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 3 of the
* License, or (at your option) any later version.
*
* This program 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 this program. If not, see
* .
*/
/* Author: Aubrey Jaffer
pi prints out digits of pi in groups of digits.
'Spigot' algorithm origionally due to Stanly Rabinowitz.
This algorithm takes time proportional to the square of /.
This fact can make comparisons of computational speed between systems
of vastly differring performances quicker and more accurate.
Try: pi 100 5
The digit size will have to be reduced for larger or an
error due to overflow will occur. */
short *calloc();
main(c,v)
int c;char **v;{
int n=200,j=0,m,b=2,k=0,t,r=1,d=5;
long q;
short *a;
if(c>1)n=atoi(v[1]);
if(c>2)d=atoi(v[2]);
while(k++