From 5ca6e8e6a4e5c022a6fb5d28f30219c22c99eda8 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:23 -0800 Subject: Import Upstream version 4e6 --- sc2.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 sc2.c (limited to 'sc2.c') diff --git a/sc2.c b/sc2.c new file mode 100644 index 0000000..904458a --- /dev/null +++ b/sc2.c @@ -0,0 +1,172 @@ +/* Copyright (C) 1990, 1991, 1992, 1993, 1994, 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 2, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * As a special exception, the Free Software Foundation gives permission + * for additional uses of the text contained in its release of GUILE. + * + * The exception is that, if you link the GUILE library with other files + * to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the GUILE library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the + * Free Software Foundation under the name GUILE. If you copy + * code from other Free Software Foundation releases into a copy of + * GUILE, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for GUILE, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + */ + +/* "sc2.c" R2RS and R3RS procedures not in R4RS. + Author: Aubrey Jaffer */ + +#include "scm.h" + +static char s_last_pair[] = "last-pair"; +SCM last_pair(sx) + SCM sx; +{ + register SCM res = sx; + register SCM x; + ASSERT(NIMP(res) && CONSP(res), res, ARG1, s_last_pair); + while (!0) { + x = CDR(res); + if (IMP(x) || NCONSP(x)) return res; + res = x; + x = CDR(res); + if (IMP(x) || NCONSP(x)) return res; + res = x; + sx = CDR(sx); + ASSERT(x != sx, sx, ARG1, s_last_pair); + } +} + +static char s_subml[] = "substring-move-left!"; +SCM subml(str1, start1, args) + SCM str1, start1, args; +{ + SCM end1, str2, start2; + long i, j, e; + ASSERT(3==ilength(args), args, WNA, s_subml); + end1 = CAR(args); args = CDR(args); + str2 = CAR(args); args = CDR(args); + start2 = CAR(args); + ASSERT(NIMP(str1) && STRINGP(str1), str1, ARG1, s_subml); + ASSERT(INUMP(start1), start1, ARG2, s_subml); + ASSERT(INUMP(end1), end1, ARG3, s_subml); + ASSERT(NIMP(str2) && STRINGP(str2), str2, ARG4, s_subml); + ASSERT(INUMP(start2), start2, ARG5, s_subml); + i = INUM(start1), j = INUM(start2), e = INUM(end1); + ASSERT(i <= LENGTH(str1) && i >= 0, start1, OUTOFRANGE, s_subml); + ASSERT(j <= LENGTH(str2) && j >= 0, start2, OUTOFRANGE, s_subml); + ASSERT(e <= LENGTH(str1) && e >= 0, end1, OUTOFRANGE, s_subml); + ASSERT(e-i+j <= LENGTH(str2), start2, OUTOFRANGE, s_subml); + while(i= 0, start1, OUTOFRANGE, s_submr); + ASSERT(j <= LENGTH(str2) && j >= 0, start2, OUTOFRANGE, s_submr); + ASSERT(e <= LENGTH(str1) && e >= 0, end1, OUTOFRANGE, s_submr); + ASSERT((j = e-i+j) <= LENGTH(str2), start2, OUTOFRANGE, s_submr); + while(i= 0, start, OUTOFRANGE, s_subfl); + ASSERT(e <= LENGTH(str) && e >= 0, end, OUTOFRANGE, s_subfl); + while(i