;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Replaced the function a-match with a faster version. 
;;; This speeds up the X server's response to OpenFont requests.
;;; Fixes SPR #11018.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Patch file for X11M version 6.29
;;; Written 06/07/90 14:09:50 by HAGY,
;;; while running on Zwingli from band LOD2
;;; With SYSTEM 6.25, VIRTUAL-MEMORY 6.2, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.7, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.6, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.14, TV 6.19, DATALINK 6.0, CHAOSNET 6.5, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.5, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.8,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.2, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.3, MAIL-READER 6.6, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.4, PROFILE 6.2, VISIDOC 6.5, TI-CLOS 6.26, CLEH 6.5, IP 3.56,
;;;  Experimental CLX 6.11, CLUE 6.104, X11M 6.28, Experimental BUG 11.17, Experimental CLIO 1.0,
;;;   microcode 430, Band Name: REl 6.0 +SLE +CLIO

#!C
; From file FONT-REQUESTS.LISP#> X11M.SERVER; Hotel:
#10R X11#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "X11"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: X11M.SERVER; FONT-REQUESTS.#"


(DEFUN a-match (STRING pattern string-offset pattern-offset)
  "Match a PATTERN with a STRING starting at INDEX.
Returns NIL if no match could be made, otherwise non-NIL."
  (DO (failure (p pattern-offset) (s string-offset))
      (;; Finished if we detected a failure or either string is exhausted...
       (OR failure
	   (= s (LENGTH string))
	   (= p (LENGTH pattern)))
       ;; Success if we've exhausted the PATTERN and either (1) the STRING is also 
       ;; exhausted, or (2) the last character of the PATTERN was a #\*...
       (AND (= p (LENGTH pattern))
	    (OR (= s (LENGTH string))
		(CHAR-EQUAL (CHAR pattern (1- p)) #\*))))

    ;;
    ;;  Look at the next character in the PATTERN to determine what to do...
    ;;
    (SELECTOR (CHAR pattern p) CHAR-EQUAL
      (#\*
       ;;  First, swallow any following asterisks in the pattern, leaving p pointing at the
       ;;  character following the last asterisk found...
       (DO ((pp (1+ p) (1+ pp)))
	   ((OR (= pp (LENGTH pattern))
		(NOT (CHAR-EQUAL (CHAR pattern pp) #\*)))
	    (SETF p pp)))
       ;;  Then swallow the next component of STRING upto the first occurance of the character
       ;;  that follows the asterisk(s) in PATTERN...
       (DO ((ss s (1+ ss))
	    (test-char (IF (= p (LENGTH pattern))
			   (RETURN-FROM a-match t)
			 (CHAR pattern p))))
	   ((OR (= ss (LENGTH string))
		(CHAR-EQUAL (CHAR string ss) test-char))
	    (SETF s (1- ss))
	    (DECF p))))
      
      ((#\? (CHAR string s)))
      ;; Swallow one character of STRING...
      
      (:otherwise
       (SETF failure t)))

    ;;  Move onward by one character in both strings, look again...
    (INCF p)
    (INCF s)))
))
