Home page of Scawk

Scawk is a port of awk to scheme. The implementation of scheme used is siod, but it is planned to extend scawk to other scheme implementations. The interressant point with siod is that a scheme file can be compiled into an executable one. So I use scawk as an exec file for WinNT (scawk.exe).

I tied to give to scawk all the features of awk. It is not completed actually, but I think scawk has enough functions to be used. Actually I use scawk instead of awk for a very large number of applications. The point is that I have not actually a CWEB-like application to use with scawk, but I work on it. The use of awkweb is the only point that makes me prefer awk to scawk sometimes.

You can download the full version 1.0 of scawk here (including binaries for WinNT). You can read the documentation (pdf format) here.

Links :

  • awk FAQ
  • siod
  • scheme

Here is an example of scawk file :

; contants :
(define *example* 0)
(define *classic* 1)
(define *paragra* 2)
(define *section* 3)
(define *nothing* 4)

(define section-s '( "\n\\section{"      "}\n"))
(define paragra-s '( ""                  "\\\\\n"))
(define example-s '( "\\begin{verbatim}" "\\end{verbatim}\n"))

(define replace-strings '( ("$" "\\$") ("#" "\\#")))
(define *nbsp* "~")

; I cut this line for HTML pretty printing reasons :
(define head-and-foot '( "\\documentclass[a4paper,12pt]{article}
   \n\\usepackage{makeidx}\n\\makeindex\n\\title{SCAWK DOC}\n\\
   author{Charles-Albert Lehalle}\n\\date{printed the \\today}

; global variables :
(define current-type *nothing*)
(define special-end  #f)

(define (*begin* )
  (display (car head-and-foot))

(define (*end* )
  ; do not forget to close current env type :
  (if (not (equal? current-type *nothing*))
      (display (cadr current-type))) 
  ; and write the foot
  (display (cadr head-and-foot))

(define (*main* )
  (if (index ($ 0) ";@")
      (let ((t (comment-type ($ 0))))

	 ((= t *section*)
	  (if (not (equal? current-type *nothing*))
	      (display (cadr current-type)))
	  (display (form (car section-s) (uncomment ($ 0)) 
	                 (cadr section-s)))
	  (set! current-type *nothing*)

	 ((= t *paragra*)
	  ; 1. first I close the current env type  :
	  (if (not (equal? current-type *nothing*))
		(display (cadr current-type))
		(if special-end
		      (display (form *nbsp* special-end))
		      (set! special-end #f)))
	  ; 2. them I put the begining of this one :
	  (display (car paragra-s))
	  ; 3. I put the line
	  (display (uncomment-first ($ 0)))
	  ; 4. and I declare the current env type  :
	  (set! current-type paragra-s))

	 ((= t *example*)
	  (if (and (not (equal? current-type *nothing*)) 
	           (not (equal? current-type example-s)))
		;(display (cadr current-type))
		(display (car example-s))
		(set! special-end (cadr current-type))
	  (display (uncomment ($ 0)))
	  (set! current-type example-s))

	 ((= t *classic*)
	  (display (uncomment ($ 0))))


; return the type of the line
(define (comment-type str)
  (if (equal? (substring str 0 2) ";@")
      (let ((t (substring str 2 3)))
	 ((equal? t "x") *example*)
	 ((equal? t " ") *classic*)
	 ((equal? t "p") *paragra*)
	 ((equal? t "*") *section*)
	 (#t             *nothing*)

; uncomment a line
(define (uncomment str)
  (let ((uc (substring+ str " "))
	(rs replace-strings)
    (while (pair? rs)
	   (set! uc (sub uc (caar rs) (cadar rs)))
	   (set! rs (cdr rs)))
; uncomment a line for the first line of a *paragra* section
(define (uncomment-first str)
  (let* ((uc (uncomment str))
	 (fd  (between uc "(" ")")) ; function definition
	 (b   (substring- uc "("))  ; before function definition
	 (a   (substring+ uc ")"))  ; after  function definition
	 (uct (if fd (substring- fd " ") #f))
    (if (and a b fd)
	(string-append "$\\bullet$~" b "\\verb#(" fd ")#" a 
	               "\\index{" uct "@\\verb#" uct "#}")

Author Charles-Albert Lehalle