> Would sbase suck less if the program head, which is currently a C 
> program of 77 lines, were replaced with something like 
>   #!/bin/sh
>   sed "$1"q

Here it is in 37 lines of glorious rc shell code.  Note that head.c also 
depends on several functions in libutil, so it is more than 77 lines really.

#!/usr/bin/env rc

fn usage {printf '%s [-n num] [file ...]\n' $0; exit $1}
fn numeric {printf '%s' $1 | grep -Eq '^[0-9]+$'}
fn positive {expr $1 '>' 0 > /dev/null}
lines=10
while (! ~ $#* 0 && ~ $1 -* && ! ~ $1 --) {
        switch($1) {
        case -n
                if (~ $2 ?*) {
                        if (numeric $2 && positive $2) {
                                lines=$2
                                shift
                        }; if not {   # else
                                usage 1
                        }
                }; if not {
                        usage 2
                }
        case -*;  usage 3
        }
        shift
}
if (~ $1 --) {shift}
switch($#*) {
case 0
        echo sed $lines^q
case 1
        echo sed $lines^q $1
case *
        while (! ~ $#* 0) {
                printf '==> %s <==\n' $1
                echo sed $lines^q $1
                shift
        }
}
true  # otherwise script will exit with error

Attachment: head.rc
Description: application/vnd.kde.kxmlguirc

Reply via email to