This Text file is old! In a 🏛️Museum, an unsorted archive of (user-)pages. (Saved from Geocities in Oct-2009. The archival story: oocities.org)
--------------------------------------- (To 🚫report any bad content: archivehelp @ gmail.com)
>

; awk2.scm - adding line numbers to the left margin of a file
; (with proper line number formatting (using string-pad))

;;; Prefix line numbers to the input stream.
;;; note this needs to be changed so that the numbers always take up the same 
;;; amount of space, the following is unsightly: 1: 2:.....10: 11: everything
;;; is pushed over one character starting with 10.
       
(require-library "awk.ss")
(current-input-port (open-input-file "awk2.scm"))
(current-output-port (open-output-file "awk2_linenos.txt" 'replace))

(define (string-pad s len)
   (let* ((str-len (string-length s))
         (excess (- len str-len)))
            (cond
               ((> excess 0) (string-append (make-string excess #\space) s))
	       ((< excess 0) (substring s (- excess) (string-length s)))
	       (else s))))

(define (digits-in-integer n)
   (string-length (number->string n)))

(digits-in-integer 1)         ; 1
(digits-in-integer 10)        ; 2
(digits-in-integer 1000)      ; 4 
(max 3 (digits-in-integer 1)) ; 3

(define (format-line-number n)  
   (format "~A:" (string-pad (number->string n)(max 3 (digits-in-integer n)))))

(format-line-number 1)     ; "  1:"
(format-line-number 10)    ; " 10:"
(format-line-number 100)   ; "100:"
(format-line-number 1000)  ; "1000"
(format-line-number 10000) ; "10000:"

(awk (read-line) (line) lineno ()
   (#t (display (format "~a ~a~%" (format-line-number lineno) line))))




Text file Source (historic): geocities.com/soho/square/3472

geocities.com/soho/square
geocities.com/soho

(to report bad content: archivehelp @ gmail)