Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,10 @@
|
|||
{{selection|Short Circuit|Console Program Basics}}[[Category:Basic language learning]][[Category:Programming environment operations]]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.
|
||||
{{selection|Short Circuit|Console Program Basics}}[[Category:Basic language learning]] [[Category:Programming environment operations]]
|
||||
{{omit from|Lotus 123 Macro Scripting}}
|
||||
{{omit from|Maxima}}
|
||||
{{omit from|Openscad}}
|
||||
{{omit from|ZX Spectrum Basic|Does not support command line parameters}}
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
program notes;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
Classes,
|
||||
SysUtils,
|
||||
IOUtils;
|
||||
|
||||
const
|
||||
FILENAME = 'NOTES.TXT';
|
||||
TAB = #9;
|
||||
|
||||
var
|
||||
sw: TStreamWriter;
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
if ParamCount = 0 then
|
||||
begin
|
||||
if TFile.Exists(FILENAME) then
|
||||
write(TFile.ReadAllText(FILENAME));
|
||||
end
|
||||
else
|
||||
begin
|
||||
if TFile.Exists(FILENAME) then
|
||||
sw := TFile.AppendText(FILENAME)
|
||||
else
|
||||
sw := TFile.CreateText(FILENAME);
|
||||
|
||||
sw.Write(FormatDateTime('yyyy-mm-dd hh:nn',Now));
|
||||
sw.Write(TAB);
|
||||
for i := 1 to ParamCount do
|
||||
begin
|
||||
sw.Write(ParamStr(i));
|
||||
if i < ParamCount then
|
||||
sw.Write(' ');
|
||||
end;
|
||||
sw.WriteLine;
|
||||
sw.Free;
|
||||
end;
|
||||
end.
|
||||
|
|
@ -1,46 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const fn = "NOTES.TXT"
|
||||
func addNote(fn string, note string) error {
|
||||
f, err := os.OpenFile(fn, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprint(f, time.Now().Format(time.RFC1123), "\n\t", note, "\n")
|
||||
// To be extra careful with errors from Close():
|
||||
if cErr := f.Close(); err == nil {
|
||||
err = cErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func showNotes(w io.Writer, fn string) error {
|
||||
f, err := os.Open(fn)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil // don't report "no such file"
|
||||
}
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(w, f)
|
||||
f.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 1 {
|
||||
f, err := os.Open(fn)
|
||||
if err != nil {
|
||||
// don't report "file does not exist" as an error, but
|
||||
// if it seems to be there but just can't be opened for
|
||||
// some reason, print original error from open attempt.
|
||||
if _, statErr := os.Stat(fn); statErr == nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if _, err = io.Copy(os.Stdout, f); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if cErr := f.Close(); err == nil && cErr != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
f, err := os.OpenFile(fn, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
_, err = fmt.Fprint(f, time.Now().Format(time.RFC1123),
|
||||
"\n\t", strings.Join(os.Args[1:], " "), "\n")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if cErr := f.Close(); err == nil && cErr != nil {
|
||||
fmt.Println(cErr)
|
||||
}
|
||||
const fn = "NOTES.TXT"
|
||||
var err error
|
||||
if len(os.Args) > 1 {
|
||||
err = addNote(fn, strings.Join(os.Args[1:], " "))
|
||||
} else {
|
||||
err = showNotes(os.Stdout, fn)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
NOTES: procedure (text) options (main); /* 8 April 2014 */
|
||||
declare text character (100) varying;
|
||||
declare note_file file;
|
||||
|
||||
on undefinedfile(note_file) go to file_does_not_exist;
|
||||
open file (note_file) title ('/NOTES.TXT,recsize(100),type(text)');
|
||||
revert error;
|
||||
|
||||
if text = '' then
|
||||
do;
|
||||
on endfile (note_file) stop;
|
||||
|
||||
do forever;
|
||||
get file (note_file) edit (text) (L);
|
||||
put skip list (text);
|
||||
end;
|
||||
end;
|
||||
close file (note_file);
|
||||
open file (note_file) output title ('/NOTES.TXT,recsize(100),type(text),append(y)');
|
||||
|
||||
put file (note_file) skip list (DATETIME('DDMmmYYYY'), TIME());
|
||||
put file (note_file) skip list (text);
|
||||
put file (note_file) skip;
|
||||
|
||||
put skip list ('Appended ' || text || ' to file');
|
||||
|
||||
return;
|
||||
|
||||
file_does_not_exist:
|
||||
revert undefinedfile (note_file);
|
||||
close file (note_file);
|
||||
open file (note_file) output title ('/NOTES.TXT,recsize(100),type(text)');
|
||||
put file (note_file) skip list (DATETIME('DDMmmYYYY'), TIME());
|
||||
put file (note_file) skip list (text);
|
||||
put file (note_file) skip;
|
||||
put skip list ('The file, NOTES.TXT, has been created');
|
||||
end NOTES;
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import java.io.{ FileNotFoundException, FileOutputStream, PrintStream }
|
||||
import java.util.Date
|
||||
import java.time.LocalDateTime
|
||||
|
||||
object TakeNotes extends App {
|
||||
val notesFileName = "notes.txt"
|
||||
if (args.length > 0) {
|
||||
val ps = new PrintStream(new FileOutputStream(notesFileName, true))
|
||||
ps.println(new Date() + args.mkString("\n\t", " ", "."))
|
||||
ps.println(LocalDateTime.now() + args.mkString("\n\t", " ", "."))
|
||||
ps.close()
|
||||
} else try {
|
||||
io.Source.fromFile(notesFileName).getLines().foreach { line => println(line) }
|
||||
io.Source.fromFile(notesFileName).getLines().foreach(println)
|
||||
} catch {
|
||||
case e: FileNotFoundException => println(e.getLocalizedMessage())
|
||||
case e: Throwable => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue