Skip to content

Commit

Permalink
Add the library of Qed programs
Browse files Browse the repository at this point in the history
Add the `q` directory
  • Loading branch information
phonologus authored Jan 31, 2024
1 parent 03eae7a commit 2a4fad1
Show file tree
Hide file tree
Showing 23 changed files with 625 additions and 0 deletions.
19 changes: 19 additions & 0 deletions q/L.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
" Left justify addressed lines (default to (1,$))
" (Terminating blanks are appended to bring all lines out to same width)
zL#=\zM yf'fi
1,$zL#r
"fi
\zL,\zMs/^[ ]*//
\zL,\zMs/[ ]*$//
zW:0
\zL,\zM g/^/ zI#n<\czW yt zW:\czI
zW#>35 yf zW:35
zD: |
zD)\zW
\zL,\zM s/$/\zD/
" Turn spaces into periods
zD+14
\zL,\zM s/^\(\zD\) *$/\1/
zD-14
\zL,\zM s/\zD$//
zL)0 zM)0 zI)0 zD)0 zW)0
18 changes: 18 additions & 0 deletions q/R.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
" Right justify addressed lines (default to (1,$))
zL#=\zM yf'fi
1,$zL#r
"fi
\zL,\zMs/^[ ]*//
\zL,\zMs/[ ]*$//
zW:0
\zL,\zM g/^/ zI#n<\czW yt zW:\czI
zW#>35 yf zW:35
zD: |
zD)\zW
\zL,\zM s/^/\zD/
" Turn spaces into periods
zD+14
\zL,\zM s/^ *\(\zD\)$/\1/
zD-14
\zL,\zM s/^\zD//
zL)0 zM)0 zI)0 zD)0 zW)0
12 changes: 12 additions & 0 deletions q/Run
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
" Run a qed buffer `off line'
z{:\l
z{C
z{s/$/ /
z|'{ z{[/ /
z{)\zC z|(\zC z|C
" z{: command z|: argument string z}: return buffer set by zr
b{ E \zq\z{.q
ovs
b\z} \b{
" Note! ok to ZERO buffer ~ (this buffer); the line will finish executing
b{Z b~Z
50 changes: 50 additions & 0 deletions q/col.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
" Buffer to columnate a buffer of file names, etc.
" takes a range of lines; defaults to 1,$
zB:\B
zL#=\zM yf 1,$zL#r
bZ Z
b\zB
\zL,\zM tZ0
" Calculate the width W of the widest line
zW#:0
g/^/ zM#n>\czW yf zW#:\czM
zW#>35 yf'fi
1,$p
yo
"fi
" L = width of column; C = # of columns
zN#:70 zL#:\zW+1 zN#/\zL
" now make each line have W spaces
zA: |
zA)\zW
1,$s/$/\zA/
" Turn the spaces into periods
zA+14
1,$s/\(\zA.\).*/\1/
" C = number of columns.
" L = 1st line of join
" M = last line of join
$zM#a $zL#a/\zN*\zN+1
zL#=\zM yf'else
zM#-1 zL#-\zN
y'fi
"else
zL#>\zM yf'else
zL#-\zN
y'fi
"else
\zL,\zM j/ /
zM#:\zL-1
zL#-\zN
"fi
"do
zL#>0 yf'od
\zL,\zM j/ /
zL#-\zN
zM#-\zN
y`do
"od
1,$p
b\zB
" Clean up the variables
zA)0 zB)0 zI)0 zL)0 zM)0 zN)0 zW)0
3 changes: 3 additions & 0 deletions q/divby2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"This worked the first time!!
,s/[0-9]+/|&|/g
g/|[0-9]+|/ za/|[0-9]+|/ hf zas/|//g za#/2 s/|[0-9]+|/\ccza/ za//
6 changes: 6 additions & 0 deletions q/grep.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
" Grep for z| (possibly set by caller) in all buffers
z|=
yf'fi
""pattern:" z|:\l
"fi
G/^[a-zA-Z]/ g/\z|/ ""\cB:" P
7 changes: 7 additions & 0 deletions q/grepf.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
" Grep for z| (possibly set by caller) in all buffers
" Prints file name as well as buffer name
z|=
yf'fi
""pattern:" z|:\l
"fi
G/^[a-zA-Z]/ g/\z|/ ""\cB(\cf):" P
173 changes: 173 additions & 0 deletions q/mail.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
" bA contains mail file
" \Fa is uid
" zF is mail file
" zM is current message number
" zN is number of messages
" zX is modified if buffer has been modified
" zY is number of lines in original mail file
" zZ is number of characters in original mail file
zF:/usr/spool/mail/\Fa
bA E \zF
zZ'C
$zY#a
g/^From /zN#+1
zN#=0 yf'}
""No mail
Q
"}
" add an extra From line to make things easy
$a From
zM'N zM#-1
"Loop
""? "
bA
za:\'l
bZZ a \za
bA
za=
yf'Nope
zM#+1>\zN yf'Print
""at end of mailbox
zM:\zN
y`Loop
"Nope
za=d
yf'Nope
zx:0
g/^From /zx#+1=\zM yto
.,/^From /-d
zX:modified
zN#-1=0 yt'Quit
zM#>\zN yf zM'N
y`Loop
"Nope
za=h
yf'Nope
" h command: headers
zx:0
g/^From .+/ ""\cz#+x "p
y`Loop
"Nope
bZ zx/^m .+/ bA yf'Nope
bBZ bA
zx:0
g/^From /zx#+1=\zM yto
.,/^From /-tB0
0a Forwarded by \Fa
zas/m //
>mail \za
y`Loop
"Nope
za=p
yf'Nope
zM#>0 yt zM:1
yt'Print
"Nope
za=q
yf'Nope
"Quit
zX=modified
yt'}
" no changes; just quit
zx{HOME} !touch \zx/.../readmail
Q
"}
bA $d " remove that extra From
bBZ E \zF
zC#=\zZ yf'}
" nobody touched it; ok to put file back
"Write
bA w \zF
zx{HOME} !touch \zx/.../readmail
Q
"}
""new mail arrived
" if the file is shorter this will intentionally crap out and
" drop you into qed
\zY+1,$tA$
y`Write
"Nope
za=r
yf'Nope
zx:0
g/^From /zx#+1=\zM yto
za. zas/From \([^ ]*\) .*/\1/
bBZ
a To: \za
"{
zx:\'l
zx=.
yt'Sendit
zx=.e
yt'Editit
a \zx
y`{
"}
"Nope
za=R
yf'Nope
bBZ bA
zx:0
g/^From /zx#+1=\zM yto
.,/^From /-tB0
1" " za. zas/From \([^ ]*\) .*/\1/
1c To: \za
"Editit
zx#P
w /tmp/m\zx
!qed /tmp/m\zx
E /tmp/m\zx
!rm -f /tmp/m\zx
"Sendit
1" " za. d zas/To: // za=
yf'}
""reply aborted
y`Loop
"}
>mail \za
yf ""reply saved in bB
y`Loop
"Nope
bZ zx/^s.*/ bA yf'Nope
zxs/s \(.*\)/\1/ yt zx{HOME} zx:\zx/mbox
zy:0
g/^From /zy#+1=\zM yto
.,/^From /- W \zx
y`Loop
"Nope
za=x
yf'Nope
zx{HOME} !touch \zx/.../readmail
Q
"Nope
bZ zx/^[0-9]+/ bA yf'Nope
" message chosen by number
za#>\zN yf'}
""only \zN messages
y`Loop
"}
zM'a
y'Print
"Nope
bZ zx/^-[0-9]*/ bA yf'Nope
" back up some number of messages
za#:-\za=0 yf za:1
zx#:\zN-\za<1 yf'}
""beyond beginning of mailbox
y`Loop
"}
zM'x
y'Print
"Nope
bZ zx/^!.*/ bA yf'Nope
\za
y`Loop
"Nope
y`Loop
"Print
zx:0
g/^From /zx#+1=\zM yto
.,/^From /- > cat
y`Loop

14 changes: 14 additions & 0 deletions q/man.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"" Arguments in [] will be prompted for if missing
"" man - print this listing
"" L - pad addressed lines with blanks to same length
"" R - pad addressed lines to same length with leading blanks
"" col - columnate addressed lines
"" grep [RE] - search buffers a-z and A-Z for regular expression
"" grepf [RE] - same as grep, but also gives file name in each buffer
""multiblanks - replace multiple blanks lines by single ones
"" nextfile - load bn with loop to loop through file list in bz
"" parens - show parenthesis nesting in addressed lines
"" pwd - put pwd output into zd
"" qfile - load your qfile into b~ (`qfile -' gets default)
"" split - split a line at a numbered blank
"" writelen - put length of quoted string into C write call
2 changes: 2 additions & 0 deletions q/manual
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
: Shell command to drive manual.qed
qed -i -q -x /usr/qed/q/manual.qed $1 < /dev/tty
66 changes: 66 additions & 0 deletions q/manual.qed
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
" Help to create a manual section
" Prompts which leave cursor on same line expect one line of input;
" others take text up to lone . on a line.
za:\Fa
za=
yf'OK
"Usage
""Usage: manual file.n
q
"OK
a \za
za/\.[0-9]+$/
za=
yt`Usage
bA a
"Getline
za:\cl
za=.
yt'done
a \cza
y`Getline
"done
.
ba
"Create the name from the file name
a \Fa
s/\.[0-9]+$//
za/\//
za=
yt s|.*/||
zn.
s/.*/^/
zN.
s/^/.th /
""Section number (Roman): "
za:\l
""Date: "
zb:\l
a \za \zb
j/ /
a .sh NAME
""Brief description: "
a \zn \*- \l
""Synopsis: \zn"
a .sh SYNOPSIS
a \cfI\zn\cfP\l
""Description:
a .sh DESCRIPTION
\bA
""See Also: "
a .sh "SEE ALSO"
a \l
""Files: "
a .sh "FILES"
a \l
""Diagnostics:
a .sh DIAGNOSTICS
\bA
""Author: "
a .sh AUTHOR
a \l
""Bugs:
a .sh BUGS
\bA
w \Fa
q
11 changes: 11 additions & 0 deletions q/multiblanks.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
" Multiblanks - convert multiple blank lines to single blank lines
" Address defaults to 1,$
zL#=\zM yf'fi
1,$zL#r
"fi
" By adding blank at end, get all trailing blank lines deleted!
\zMa
" Precompile the pattern for efficiency
/^$/"
\zL,\z#+M g// a \cN hf d zP//
zP)0 zL)0 zM)0
Loading

0 comments on commit 2a4fad1

Please sign in to comment.