aboutsummaryrefslogtreecommitdiffstats
path: root/inc2scm
diff options
context:
space:
mode:
authorJames LewisMoss <dres@debian.org>2000-03-12 09:04:17 -0500
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:26 -0800
commit8cfce36c6a4fc2e0a0ab6ef2db66a23cbe462693 (patch)
tree17427e4f777ca85990a449fe939fbae29770b346 /inc2scm
parenta47af30d2f0e96afcd1f14b1984575c359faa3d6 (diff)
parent3278b75942bdbe706f7a0fba87729bb1e935b68b (diff)
downloadscm-8cfce36c6a4fc2e0a0ab6ef2db66a23cbe462693.tar.gz
scm-8cfce36c6a4fc2e0a0ab6ef2db66a23cbe462693.zip
Import Debian changes 5d2-3debian/5d2-3
scm (5d2-3) unstable frozen; urgency=low * Fix libncurses4-dev -> libncurses5-dev build depend (Closes: #58435) * Fix libreadline2-dev -> libreadline4-dev build depend. * Fix license location in copyright file (lintian warning) * Add tetex-bin as a build depend (needs makeinfo) (Closes: #53197) * Add -isp option to dpkg-gencontrol (lintian error) * Move scm to section interpreters. scm (5d2-2) unstable; urgency=low * Apply patch from upstream for bug in eval.c. (Picked up from comp.lang.scheme) * Add Build-Depends on slib, librx1g-dev, libncurses4-dev, libreadlineg2-dev. * Up standards version. * Correct description: this is an R5RS implementation now * Make sure no optimizations are done on m68k. (Closes: #52434) scm (5d2-1) unstable; urgency=low * New upstream. scm (5d1-2) unstable; urgency=low * Remove TAGS on clean (cut the diff back down to reasonable size). scm (5d1-1) unstable; urgency=low * New upstream. * move stuff to /usr/share. scm (5d0-3) unstable; urgency=low * Change scmlit call to ./scmlit call (missed one) (Fixes bugs #37455 and #35545) * Change man file permissions to 644 (fixes lintian warning) scm (5d0-2) unstable; urgency=low * Removed call to add_final in init_crs. lendwin doesn't do anything and scm was crashing when quit everytime in final_scm. * Changed copyright to reflect new source. scm (5d0-1) unstable; urgency=low * New upstream. * Changed (terms) to access "/usr/doc/copyright/GPL". * Changed regex to use -lrx scm (5c3-6) unstable; urgency=low * New maintainer.
Diffstat (limited to 'inc2scm')
-rwxr-xr-xinc2scm190
1 files changed, 190 insertions, 0 deletions
diff --git a/inc2scm b/inc2scm
new file mode 100755
index 0000000..58a9540
--- /dev/null
+++ b/inc2scm
@@ -0,0 +1,190 @@
+#! /usr/local/bin/scm \ %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
+- !#
+;; Copyright (C) 1991-1999 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, 59 Temple Place, Suite 330, Boston, MA 02111, 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.
+
+;;;; "inc2scm", Convert numeric C #defines to Scheme definitions.
+;;; Author: Aubrey Jaffer.
+
+(define (go-script)
+ (cond ((not *script*))
+ ((< 1 (- (length *argv*) *optind*))
+ (apply inc2scm (list-tail *argv* *optind*)))
+ (else
+ (display "\
+\
+Usage: inc2scm defines.scm [pre:] [/usr/include/] file1.h file2.h ...
+\
+ Appends to DEFINES.SCM the Scheme translations of the numeric
+ #define statements in /USR/INCLUDE/FILE1.H, /USR/INCLUDE/FILE2.H, ...
+
+ PRE: is prepended to those scheme names lacking a prefix.
+
+ /USR/INCLUDE/ defaults to /usr/include/.
+"
+ (current-error-port))
+ (exit #f))))
+
+(require 'string-search)
+(require 'printf)
+(require 'scanf)
+
+(define (StudlyCaps->dashed-name nstr)
+ (do ((idx (+ -1 (string-length nstr)) (+ -1 idx)))
+ ((> 2 idx))
+ (cond ((and (char-upper-case? (string-ref nstr (+ -1 idx)))
+ (char-lower-case? (string-ref nstr idx)))
+ (set! nstr
+ (string-append (substring nstr 0 (+ -1 idx))
+ "-"
+ (substring nstr (+ -1 idx)
+ (string-length nstr)))))
+ ((and (char-lower-case? (string-ref nstr (+ -1 idx)))
+ (char-upper-case? (string-ref nstr idx)))
+ (set! nstr
+ (string-append (substring nstr 0 idx)
+ "-"
+ (substring nstr idx
+ (string-length nstr)))))))
+ nstr)
+
+;; SCHEMEIFY-NAME:
+;; * Changes _ to -
+;; * Changes the first - to : if it is within the first 3 characters.
+;; * inserts dashes between `StudlyCaps'
+
+(define (schemeify-name pre name)
+ (define nstr (string-subst name "_" "-"))
+ (let ((sid (string-index nstr #\-)))
+ (cond ((and sid (< sid 3)) (string-set! nstr sid #\:)
+ nstr)
+ (pre (string-append pre (StudlyCaps->dashed-name nstr)))
+ (else (StudlyCaps->dashed-name nstr)))))
+
+(define (extract-defineds port)
+ (define sharp (string #\newline #\#))
+ (define defineds '())
+ (do ((find? (find-string-from-port? sharp port)
+ (find-string-from-port? sharp port)))
+ ((not find?) (reverse defineds))
+ (do ((chr (read-char port) (read-char port)))
+ ((or (eof-object? chr) (not (char-whitespace? chr)))
+ (and (eqv? chr #\d)
+ (let ((op #f) (va #f))
+ (fscanf port "efine%*[ \t]%s%*[ \t]%s" op va)
+ (if (and op va
+ (not (string-index op #\())
+ (not (eqv? #\_ (string-ref op 0)))
+ (not (equal? "int" va)))
+ (set! defineds (cons op defineds)))))))))
+
+(define (scm<-includes scmname pre non-local? . filenames)
+ (define tmpprog "tmpprog")
+ (call-with-output-file (string-append tmpprog ".c")
+ (lambda (cport)
+ (for-each (lambda (filename)
+ (fprintf cport
+ (if non-local?
+ "#include <%s>\\n"
+ "#include \"%s\"\\n")
+ filename))
+ filenames)
+ (for-each
+ (lambda (args) (apply fprintf cport args))
+ `(("#include <stdio.h>\\n")
+ ("void pSl(sname, value)\\n")
+ (" char sname[];\\n")
+ (" int value;\\n")
+ ("{\\n")
+ ("%s\\n" " printf(\"(define %s %d)\\n\", sname, value);")
+ ("}\\n")
+ ("\\n")
+ ("int main(argc, argv)\\n")
+ (" int argc;\\n")
+ (" char *argv[];\\n")
+ ("{\\n")
+ ))
+ (for-each
+ (lambda (filename)
+ (if non-local?
+ (set! filename (string-append non-local? filename)))
+ (fprintf cport "/* Extract #define values from %s */\\n" filename)
+ (fprintf cport "%s %s%s\\n"
+ " printf(\";;inc2scm extracted #define values from"
+ filename
+ "\\n\");")
+ (for-each
+ (lambda (name) (fprintf cport " pSl(\"%s\", %s);\\n"
+ (schemeify-name pre name) name))
+ (call-with-input-file filename extract-defineds)))
+ filenames)
+ (fprintf cport "}\\n")))
+ (cond
+ ((not (zero? (system (sprintf #f "cc -o %s %s.c" tmpprog tmpprog)))))
+ ((not (zero? (system (sprintf #f "./%s >> %s" tmpprog scmname)))))))
+
+(define (scm<-usr/includes scmname . filenames)
+ (define pre (let ((first (car filenames)))
+ (cond ((substring-ci? ".h" first) #f)
+ (else (set! filenames (cdr filenames)) first))))
+ (define include-path "/usr/include/")
+ (let* ((first (car filenames)))
+ (cond ((memv (string-ref first (+ -1 (string-length first))) '(#\\ #\/))
+ (set! include-path first)
+ (set! filenames (cdr filenames)))))
+ (apply scm<-includes scmname pre include-path filenames)
+ (delete-file "tmpprog.c")
+ (delete-file "tmpprog"))
+(define inc2scm scm<-usr/includes)
+
+(define (scm<-h* scmname . filenames)
+ (define pre (let ((first (car filenames)))
+ (cond ((substring-ci? ".h" first) first)
+ (else (set! filenames (cdr filenames)) #f))))
+ (apply scm<-includes scmname pre #f filenames)
+ (delete-file "tmpprog.c")
+ (delete-file "tmpprog"))
+(define h2scm scm<-h*)
+
+(go-script)
+
+;;; Local Variables:
+;;; mode:scheme
+;;; End: