Take notes on the command line is part of Short Circuit's Console Program Basics selection.
Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists.
If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline.
Then all the arguments, joined with spaces, prepended with a tab, and appended with a trailing newline, are written to NOTES.TXT.
If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.

% This program uses the "get_argv" function that is supplied iwth
% PCLU in "useful.lib".
 
NOTEFILE = "notes.txt"
 
% Format the date and time as MM/DD/YYYY HH:MM:SS [AM|PM]
format_date = proc (d: date) returns (string)
    ds: stream := stream$create_output()
    stream$putzero(ds, int$unparse(d.month), 2)
    stream$putc(ds, '/')
    stream$putzero(ds, int$unparse(d.day), 2)
    stream$putc(ds, '/')
    stream$putzero(ds, int$unparse(d.year), 4)
    stream$putc(ds, ' ')
 
    hour: int := d.hour // 12
    if hour=0 then hour:=12 end
    ampm: string := "AM"
    if d.hour>=12 then ampm := "PM" end
 
    stream$putzero(ds, int$unparse(hour), 2)
    stream$putc(ds, ':')
    stream$putzero(ds, int$unparse(d.minute), 2)
    stream$putc(ds, ':')
    stream$putzero(ds, int$unparse(d.second), 2)
    stream$putc(ds, ' ')
    stream$puts(ds, ampm)
    return(stream$get_contents(ds))
end format_date
 
% Add a note to the file
add_note = proc (note: sequence[string])
    fn: file_name := file_name$parse(NOTEFILE)
    out: stream := stream$open(fn, "append")
    stream$putl(out, format_date(now()))
 
    c: char := '\t'
    for part: string in sequence[string]$elements(note) do 
        stream$putc(out, c)
        stream$puts(out, part)
        c := ' '
    end 
    stream$putc(out, '\n')
    stream$close(out)
end add_note
 
% Show the notes file, if it exists
show_notes = proc ()
    po: stream := stream$primary_output()
    fn: file_name := file_name$parse(NOTEFILE)
    begin
        inp: stream := stream$open(fn, "read")
        while true do
            stream$putl(po, stream$getl(inp))
            except when end_of_file: break end
        end
        stream$close(inp)
    end except when not_possible(s: string): end
end show_notes
 
% Add a note if one is given, show the notes otherwise
start_up = proc ()
    note: sequence[string] := get_argv()
    if sequence[string]$empty(note)
        then show_notes()
        else add_note(note)
    end
end start_up