From 66735d9c9e781b348c353efa4a5e4233119e6d59 Mon Sep 17 00:00:00 2001 From: shivers Date: Wed, 26 Feb 1997 20:37:53 +0000 Subject: [PATCH] fdports1.c: hacked in a gross fix for linux bug. The problem is that linux stdio functions retry when interrupted, instead of returning errno=EINTR. regexp: New regexp-substitute function. scsh-interfaces: Fixed a typo in a type decl. --- scsh/fdports1.c | 4 ++++ scsh/re.c | 30 ------------------------------ scsh/re.scm | 37 +++++++++++++++++++------------------ scsh/scsh-interfaces.scm | 6 +++--- 4 files changed, 26 insertions(+), 51 deletions(-) diff --git a/scsh/fdports1.c b/scsh/fdports1.c index b87c869..85d5f65 100644 --- a/scsh/fdports1.c +++ b/scsh/fdports1.c @@ -41,11 +41,15 @@ static FILE *fstar_cache[NUM_FDPORTS] = {NULL}; /* Maps fd's to ports. */ static scheme_value fdports[NUM_FDPORTS] = {SCHFALSE}; +extern void remove_bone_from_head_of_linux_libc (void); + void init_fdports(void) { int i = NUM_FDPORTS; while( i-- ) fdports[i] = SCHFALSE; + remove_bone_from_head_of_linux_libc(); + /* Specially hack stdio. */ fstar_cache[fileno(stdin)] = stdin; fstar_cache[fileno(stdout)] = stdout; diff --git a/scsh/re.c b/scsh/re.c index c32166a..7f297c3 100644 --- a/scsh/re.c +++ b/scsh/re.c @@ -67,36 +67,6 @@ scheme_value df_re_match(long nargs, scheme_value *args) return ret1; } -scheme_value df_re_subst(long nargs, scheme_value *args) -{ - extern char *re_subst(scheme_value , const char *, const char *, int , scheme_value , scheme_value , scheme_value , int *); - scheme_value ret1; - char *r1; - int r2; - - cig_check_nargs(8, nargs, "re_subst"); - r1 = re_subst(args[7], cig_string_body(args[6]), cig_string_body(args[5]), EXTRACT_FIXNUM(args[4]), args[3], args[2], args[1], &r2); - ret1 = VECTOR_REF(*args,0); - {AlienVal(CAR(ret1)) = (long) r1; CDR(ret1) = strlen_or_false(r1);} - VECTOR_REF(*args,1) = ENTER_FIXNUM(r2); - return ret1; - } - -scheme_value df_re_subst_len(long nargs, scheme_value *args) -{ - extern char *re_subst_len(scheme_value , const char *, const char *, int , scheme_value , scheme_value , int *); - scheme_value ret1; - char *r1; - int r2; - - cig_check_nargs(7, nargs, "re_subst_len"); - r1 = re_subst_len(args[6], cig_string_body(args[5]), cig_string_body(args[4]), EXTRACT_FIXNUM(args[3]), args[2], args[1], &r2); - ret1 = VECTOR_REF(*args,0); - {AlienVal(CAR(ret1)) = (long) r1; CDR(ret1) = strlen_or_false(r1);} - VECTOR_REF(*args,1) = ENTER_FIXNUM(r2); - return ret1; - } - scheme_value df_filter_stringvec(long nargs, scheme_value *args) { extern char *filter_stringvec(const char *, char const ** , int *); diff --git a/scsh/re.scm b/scsh/re.scm index 3e1c4de..9fdcee6 100644 --- a/scsh/re.scm +++ b/scsh/re.scm @@ -111,31 +111,33 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (regexp-substitute port match . items) - (let ((str (regexp-match:string match)) - (sv (regexp-match:start match)) - (ev (regexp-match:end match))) + (let* ((str (regexp-match:string match)) + (sv (regexp-match:start match)) + (ev (regexp-match:end match)) + (range (lambda (item) ; Return start & end of + (cond ((integer? item) ; ITEM's range in STR. + (values (vector-ref sv item) + (vector-ref ev item))) + ((eq? 'pre item) (values 0 (vector-ref sv 0))) + ((eq? 'post item) (values (vector-ref ev 0) + (string-length str))) + (else (error "Illegal substitution item." + item + regexp-substitute)))))) (if port ;; Output port case. (for-each (lambda (item) - (cond ((string? item) (write-string item port)) - ((integer? item) (write-string str port - (vector-ref sv item) - (vector-ref ev item))) - (else (error "Illegal substitution item." - item - regexp-substitute)))) + (if (string? item) (write-string item port) + (receive (si ei) (range item) + (write-string str port si ei)))) items) ;; Here's the string case. Make two passes -- one to ;; compute the length of the target string, one to fill it in. (let* ((len (reduce (lambda (i item) - (+ i (cond ((string? item) (string-length item)) - ((integer? (- (vector-ref ev item) - (vector-ref sv item)))) - (else (error "Illegal substitution item." - item - regexp-substitute))))) + (+ i (if (string? item) (string-length item) + (receive (si ei) (range item) (- ei si))))) 0 items)) (ans (make-string len))) @@ -143,8 +145,7 @@ (cond ((string? item) (copy-string! ans index item) (+ index (string-length item))) - (else (let ((si (vector-ref sv item)) - (ei (vector-ref ev item))) + (else (receive (si ei) (range item) (copy-substring! ans index str si ei) (+ index (- ei si)))))) 0 items) diff --git a/scsh/scsh-interfaces.scm b/scsh/scsh-interfaces.scm index 4e70f2c..3f06b7f 100644 --- a/scsh/scsh-interfaces.scm +++ b/scsh/scsh-interfaces.scm @@ -96,8 +96,8 @@ (define-interface scsh-errors-interface (export errno-error error - (with-errno-handler* (proc (proc (:number :value) :values) ; handler - (proc () :values))) ; thunk + (with-errno-handler* (proc ((proc (:number :value) :values)); handler + (proc () :values))) ; thunk (with-errno-handler :syntax))) @@ -424,7 +424,7 @@ make-regexp regexp? regexp-exec - regexp-subst + regexp-substitute regexp-quote))