all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
1
Task/Take-notes-on-the-command-line/0DESCRIPTION
Normal file
1
Task/Take-notes-on-the-command-line/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{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.
|
||||
2
Task/Take-notes-on-the-command-line/1META.yaml
Normal file
2
Task/Take-notes-on-the-command-line/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Text processing
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
with Ada.Calendar.Formatting;
|
||||
with Ada.Characters.Latin_1;
|
||||
with Ada.Command_Line;
|
||||
with Ada.IO_Exceptions;
|
||||
with Ada.Text_IO;
|
||||
procedure Notes is
|
||||
Notes_Filename : constant String := "notes.txt";
|
||||
Notes_File : Ada.Text_IO.File_Type;
|
||||
Argument_Count : Natural := Ada.Command_Line.Argument_Count;
|
||||
begin
|
||||
if Argument_Count = 0 then
|
||||
begin
|
||||
Ada.Text_IO.Open
|
||||
(File => Notes_File,
|
||||
Mode => Ada.Text_IO.In_File,
|
||||
Name => Notes_Filename);
|
||||
while not Ada.Text_IO.End_Of_File (File => Notes_File) loop
|
||||
Ada.Text_IO.Put_Line (Ada.Text_IO.Get_Line (File => Notes_File));
|
||||
end loop;
|
||||
exception
|
||||
when Ada.IO_Exceptions.Name_Error =>
|
||||
null;
|
||||
end;
|
||||
else
|
||||
begin
|
||||
Ada.Text_IO.Open
|
||||
(File => Notes_File,
|
||||
Mode => Ada.Text_IO.Append_File,
|
||||
Name => Notes_Filename);
|
||||
exception
|
||||
when Ada.IO_Exceptions.Name_Error =>
|
||||
Ada.Text_IO.Create (File => Notes_File, Name => Notes_Filename);
|
||||
end;
|
||||
Ada.Text_IO.Put_Line
|
||||
(File => Notes_File,
|
||||
Item => Ada.Calendar.Formatting.Image (Date => Ada.Calendar.Clock));
|
||||
Ada.Text_IO.Put (File => Notes_File, Item => Ada.Characters.Latin_1.HT);
|
||||
for I in 1 .. Argument_Count loop
|
||||
Ada.Text_IO.Put
|
||||
(File => Notes_File,
|
||||
Item => Ada.Command_Line.Argument (I));
|
||||
if I /= Argument_Count then
|
||||
Ada.Text_IO.Put (File => Notes_File, Item => ' ');
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.Flush (File => Notes_File);
|
||||
end if;
|
||||
if Ada.Text_IO.Is_Open (File => Notes_File) then
|
||||
Ada.Text_IO.Close (File => Notes_File);
|
||||
end if;
|
||||
end Notes;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
Notes := "Notes.txt"
|
||||
|
||||
If 0 = 0 ; no arguments
|
||||
{
|
||||
If FileExist(Notes) {
|
||||
FileRead, Content, %Notes%
|
||||
MsgBox, %Content%
|
||||
} Else
|
||||
MsgBox, %Notes% does not exist
|
||||
Goto, EOF
|
||||
}
|
||||
|
||||
; date and time, colon, newline (CRLF), tab
|
||||
Date := A_DD "/" A_MM "/" A_YYYY
|
||||
Time := A_Hour ":" A_Min ":" A_Sec "." A_MSec
|
||||
FileAppend, %Date% %Time%:`r`n%A_Tab%, %Notes%
|
||||
|
||||
; command line parameters, trailing newline (CRLF)
|
||||
Loop, %0%
|
||||
FileAppend, % %A_Index% " ", %Notes%
|
||||
FileAppend, `r`n, %Notes%
|
||||
|
||||
EOF:
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
IF LEN(COMMAND$) THEN
|
||||
OPEN "notes.txt" FOR APPEND AS 1
|
||||
PRINT #1, DATE$, TIME$
|
||||
PRINT #1, CHR$(9); COMMAND$
|
||||
CLOSE
|
||||
ELSE
|
||||
d$ = DIR$("notes.txt")
|
||||
IF LEN(d$) THEN
|
||||
OPEN d$ FOR INPUT AS 1
|
||||
WHILE NOT EOF(1)
|
||||
LINE INPUT #1, i$
|
||||
PRINT i$
|
||||
WEND
|
||||
CLOSE
|
||||
END IF
|
||||
END IF
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
REM!Exefile C:\NOTES.EXE, encrypt, console
|
||||
REM!Embed
|
||||
LF = 10
|
||||
|
||||
SYS "GetStdHandle", -10 TO @hfile%(1)
|
||||
SYS "GetStdHandle", -11 TO @hfile%(2)
|
||||
SYS "SetConsoleMode", @hfile%(1), 0
|
||||
*INPUT 13
|
||||
*OUTPUT 14
|
||||
ON ERROR PRINT REPORT$ : QUIT ERR
|
||||
|
||||
notes% = OPENUP(@dir$ + "NOTES.TXT")
|
||||
IF notes% = 0 notes% = OPENOUT(@dir$ + "NOTES.TXT")
|
||||
IF notes% = 0 PRINT "Cannot open or create NOTES.TXT" : QUIT 1
|
||||
|
||||
IF @cmd$ = "" THEN
|
||||
WHILE NOT EOF#notes%
|
||||
INPUT #notes%, text$
|
||||
IF ASC(text$) = LF text$ = MID$(text$,2)
|
||||
PRINT text$
|
||||
ENDWHILE
|
||||
ELSE
|
||||
PTR#notes% = EXT#notes%
|
||||
PRINT #notes%,TIME$ : BPUT#notes%,LF
|
||||
PRINT #notes%,CHR$(9) + @cmd$ : BPUT#notes%,LF
|
||||
ENDIF
|
||||
|
||||
CLOSE #notes%
|
||||
QUIT
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
@echo off
|
||||
if %1@==@ (
|
||||
if exist notes.txt more notes.txt
|
||||
goto :eof
|
||||
)
|
||||
echo %date% %time%:>>notes.txt
|
||||
echo %*>>notes.txt
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
#define note_file "NOTES.TXT"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(argc>1)
|
||||
{
|
||||
ofstream Notes(note_file, ios::app);
|
||||
time_t timer = time(NULL);
|
||||
if(Notes.is_open())
|
||||
{
|
||||
Notes << asctime(localtime(&timer)) << '\t';
|
||||
for(int i=1;i<argc;i++)
|
||||
Notes << argv[i] << ' ';
|
||||
Notes << endl;
|
||||
Notes.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ifstream Notes(note_file, ios::in);
|
||||
string line;
|
||||
if(Notes.is_open())
|
||||
{
|
||||
while(!Notes.eof())
|
||||
{
|
||||
getline(Notes, line);
|
||||
cout << line << endl;
|
||||
}
|
||||
Notes.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define note_file "NOTES.TXT"
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
FILE *note = 0;
|
||||
time_t tm;
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
if (argc < 2) {
|
||||
if ((note = fopen(note_file, "r")))
|
||||
while ((i = fgetc(note)) != EOF)
|
||||
putchar(i);
|
||||
|
||||
} else if ((note = fopen(note_file, "a")))
|
||||
tm = time(0);
|
||||
p = ctime(&tm);
|
||||
|
||||
/* skip the newline */
|
||||
while (*p) fputc(*p != '\n'?*p:'\t', note), p++;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
fprintf(note, "%s%c", argv[i], 1 + i - argc ? ' ' : '\n');
|
||||
}
|
||||
|
||||
if (note) fclose(note);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(ns rosettacode.notes
|
||||
(:use [clojure.string :only [join]]))
|
||||
|
||||
(defn notes [notes]
|
||||
(if (seq notes)
|
||||
(spit
|
||||
"NOTES.txt"
|
||||
(str (java.util.Date.) "\n" "\t"
|
||||
(join " " notes) "\n")
|
||||
:append true)
|
||||
(println (slurp "NOTES.txt"))))
|
||||
|
||||
(notes *command-line-args*)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import std.stdio, std.file, std.string, std.datetime;
|
||||
|
||||
void main(string[] args) {
|
||||
immutable filename = "NOTES.TXT";
|
||||
|
||||
if (args.length == 1) {
|
||||
if (exists(filename) && isFile(filename))
|
||||
writefln("%-(%s\n%)", filename.File.byLine);
|
||||
} else {
|
||||
auto f = File(filename, "a+");
|
||||
f.writefln("%s", cast(DateTime)Clock.currTime);
|
||||
f.writefln("\t%s", args[1 .. $].join(" "));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env rune
|
||||
|
||||
def f := <file:notes.txt>
|
||||
def date := makeCommand("date")
|
||||
|
||||
switch (interp.getArgs()) {
|
||||
match [] {
|
||||
if (f.exists()) {
|
||||
for line in f { print(line) }
|
||||
}
|
||||
}
|
||||
match noteArgs {
|
||||
def w := f.textWriter(true)
|
||||
w.print(date()[0], "\t", " ".rjoin(noteArgs), "\n")
|
||||
w.close()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
constant cmd = command_line()
|
||||
constant filename = "notes.txt"
|
||||
integer fn
|
||||
object line
|
||||
sequence date_time
|
||||
|
||||
if length(cmd) < 3 then
|
||||
fn = open(filename,"r")
|
||||
if fn != -1 then
|
||||
while 1 do
|
||||
line = gets(fn)
|
||||
if atom(line) then
|
||||
exit
|
||||
end if
|
||||
puts(1,line)
|
||||
end while
|
||||
close(fn)
|
||||
end if
|
||||
else
|
||||
fn = open(filename,"a") -- if such file doesn't exist it will be created
|
||||
date_time = date()
|
||||
date_time = date_time[1..6]
|
||||
date_time[1] += 1900
|
||||
printf(fn,"%d-%02d-%02d %d:%02d:%02d\n",date_time)
|
||||
line = "\t"
|
||||
for n = 3 to length(cmd) do
|
||||
line &= cmd[n] & ' '
|
||||
end for
|
||||
line[$] = '\n'
|
||||
puts(fn,line)
|
||||
close(fn)
|
||||
end if
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#! /usr/bin/env factor
|
||||
USING: kernel calendar calendar.format io io.encodings.utf8 io.files
|
||||
sequences command-line namespaces ;
|
||||
|
||||
command-line get [
|
||||
"notes.txt" utf8 file-contents print
|
||||
] [
|
||||
" " join "\t" prepend
|
||||
"notes.txt" utf8 [
|
||||
now timestamp>ymdhms print
|
||||
print flush
|
||||
] with-file-appender
|
||||
] if-empty
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
class Notes
|
||||
{
|
||||
public static Void main (Str[] args)
|
||||
{
|
||||
notesFile := File(`notes.txt`) // the backticks make a URI
|
||||
if (args.isEmpty)
|
||||
{
|
||||
if (notesFile.exists)
|
||||
{
|
||||
notesFile.eachLine |line| { echo (line) }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// notice the following uses a block so the 'printLine/close'
|
||||
// operations are all applied to the same output stream for notesFile
|
||||
notesFile.out(true) // 'true' to append to file
|
||||
{
|
||||
printLine ( DateTime.now.toLocale("DD-MM-YY hh:mm:ss").toStr )
|
||||
printLine ( "\t" + args.join(" ") )
|
||||
close
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
vocabulary note-words
|
||||
get-current also note-words definitions
|
||||
|
||||
\ -- notes.txt
|
||||
variable file
|
||||
: open s" notes.txt" r/w open-file if
|
||||
s" notes.txt" r/w create-file throw then file ! ;
|
||||
: appending file @ file-size throw file @ reposition-file throw ;
|
||||
: write file @ write-file throw ;
|
||||
: close file @ close-file throw ;
|
||||
|
||||
\ -- SwiftForth console workaround
|
||||
9 constant TAB
|
||||
: type ( c-addr u -- )
|
||||
bounds ?do
|
||||
i c@ dup TAB = if drop 8 spaces else emit then
|
||||
loop ;
|
||||
|
||||
\ -- dump notes.txt
|
||||
create buf 4096 allot
|
||||
: dump ( -- )
|
||||
cr begin buf 4096 file @ read-file throw dup while
|
||||
buf swap type
|
||||
repeat drop ;
|
||||
|
||||
\ -- time and date
|
||||
: time @time (time) ;
|
||||
: date @date (date) ;
|
||||
|
||||
\ -- add note
|
||||
: cr s\" \n" write ;
|
||||
: tab s\" \t" write ;
|
||||
: space s" " write ;
|
||||
: add-note ( c-addr u -- ) appending
|
||||
date write space time write cr
|
||||
tab ( note ) write cr ;
|
||||
|
||||
set-current
|
||||
|
||||
\ -- note
|
||||
: note ( "note" -- )
|
||||
open 0 parse dup if add-note
|
||||
else 2drop dump then close ;
|
||||
previous
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
\ -- notes.txt
|
||||
include lib/argopen.4th
|
||||
include lib/ansfacil.4th
|
||||
|
||||
\ -- dump notes.txt
|
||||
4096 buffer: buf
|
||||
: dump ( -- )
|
||||
input 1 arg-open
|
||||
begin buf dup 4096 accept dup while type repeat
|
||||
drop drop close ;
|
||||
|
||||
\ -- time and date
|
||||
: :00 <# # # [char] : hold #> type ;
|
||||
: -00 <# # # [char] - hold #> type ;
|
||||
: .time 0 .r :00 :00 ;
|
||||
: .date 0 .r -00 -00 ;
|
||||
|
||||
\ -- add note
|
||||
: add-note ( c-addr u -- )
|
||||
output append [+] 1 arg-open -rot
|
||||
time&date .date space .time cr
|
||||
9 emit type cr close ;
|
||||
|
||||
\ -- note
|
||||
: note ( "note" -- )
|
||||
argn 2 < abort" Usage: notes filename"
|
||||
refill drop 0 parse dup if add-note else 2drop dump then ;
|
||||
|
||||
note
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const fn = "NOTES.TXT"
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import System.Environment (getArgs)
|
||||
import System.Time (getClockTime)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
if null args
|
||||
then catch (readFile "notes.txt" >>= putStr)
|
||||
(\_ -> return ())
|
||||
else
|
||||
do ct <- getClockTime
|
||||
appendFile "notes.txt" $ show ct ++ "\n\t" ++ unwords args ++ "\n"
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
SYSTEM(RUN) ! start this script in RUN-mode
|
||||
|
||||
CHARACTER notes="Notes.txt", txt*1000
|
||||
|
||||
! Remove file name from the global variable $CMD_LINE:
|
||||
EDIT(Text=$CMD_LINE, Mark1, Right=".hic ", Right=4, Mark2, Delete)
|
||||
|
||||
IF($CMD_LINE == ' ') THEN
|
||||
READ(FIle=notes, LENgth=Lnotes)
|
||||
IF( Lnotes ) THEN
|
||||
WINDOW(WINdowhandle=hdl, TItle=notes)
|
||||
WRITE(Messagebox="?Y") "Finished ?"
|
||||
ENDIF
|
||||
ELSE
|
||||
WRITE(Text=txt, Format="UWWW CCYY-MM-DD HH:mm:SS, A") 0, $CRLF//$TAB//TRIM($CMD_LINE)//$CRLF
|
||||
OPEN(FIle=notes, APPend)
|
||||
WRITE(FIle=notes, CLoSe=1) txt
|
||||
ENDIF
|
||||
|
||||
ALARM(999) ! quit HicEst immediately
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
procedure write_out_notes (filename)
|
||||
file := open (filename, "rt") | stop ("no notes file yet")
|
||||
every write (!file)
|
||||
end
|
||||
|
||||
procedure add_to_notes (filename, strs)
|
||||
file := open (filename, "at") | # append to file if it exists
|
||||
open (filename, "cat") | # create the file if not there
|
||||
stop ("unable to open " || filename)
|
||||
writes (file, ctime(&now) || "\n\t")
|
||||
every writes (file, !strs || " ")
|
||||
write (file, "")
|
||||
end
|
||||
|
||||
procedure main (args)
|
||||
notes_file := "notes.txt"
|
||||
if *args = 0
|
||||
then write_out_notes (notes_file)
|
||||
else add_to_notes (notes_file, args)
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
require 'files strings'
|
||||
|
||||
notes=: monad define
|
||||
if. #y do.
|
||||
now=. LF ,~ 6!:0 'hh:mm:ss DD/MM/YYYY'
|
||||
'notes.txt' fappend~ now, LF ,~ TAB, ' ' joinstring y
|
||||
elseif. -. _1 -: txt=. fread 'notes.txt' do.
|
||||
smoutput txt
|
||||
end.
|
||||
)
|
||||
|
||||
notes 2}.ARGV
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Date;
|
||||
|
||||
public class TakeNotes {
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length > 0) {
|
||||
PrintStream ps = new PrintStream(new FileOutputStream("notes.txt", true));
|
||||
ps.println(new Date());
|
||||
ps.print("\t" + args[0]);
|
||||
for (int i = 1; i < args.length; i++)
|
||||
ps.print(" " + args[i]);
|
||||
ps.println();
|
||||
ps.close();
|
||||
} else {
|
||||
FileChannel fc = new FileInputStream("notes.txt").getChannel();
|
||||
fc.transferTo(0, fc.size(), Channels.newChannel(System.out));
|
||||
fc.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
var notes = 'NOTES.TXT';
|
||||
|
||||
var args = WScript.Arguments;
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
var ForReading = 1, ForWriting = 2, ForAppending = 8;
|
||||
|
||||
if (args.length == 0) {
|
||||
if (fso.FileExists(notes)) {
|
||||
var f = fso.OpenTextFile(notes, ForReading);
|
||||
WScript.Echo(f.ReadAll());
|
||||
f.Close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
var f = fso.OpenTextFile(notes, ForAppending, true);
|
||||
var d = new Date();
|
||||
f.WriteLine(d.toLocaleString());
|
||||
f.Write("\t");
|
||||
// note that WScript.Arguments is not an array, it is a "collection"
|
||||
// it does not have a join() method.
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
f.Write(args(i) + " ");
|
||||
}
|
||||
f.WriteLine();
|
||||
f.Close();
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
filename = "NOTES.TXT"
|
||||
|
||||
if #arg == 0 then
|
||||
fp = io.open( filename, "r" )
|
||||
if fp ~= nil then
|
||||
print( fp:read( "*all*" ) )
|
||||
fp:close()
|
||||
end
|
||||
else
|
||||
fp = io.open( filename, "a+" )
|
||||
|
||||
fp:write( os.date( "%x %X\n" ) )
|
||||
|
||||
fp:write( "\t" )
|
||||
for i = 1, #arg do
|
||||
fp:write( arg[i], " " )
|
||||
end
|
||||
fp:write( "\n" )
|
||||
|
||||
fp:close()
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
function notes(varargin)
|
||||
% NOTES can be used for taking notes
|
||||
% usage:
|
||||
% notes displays the content of the file NOTES.TXT
|
||||
% notes arg1 arg2 ...
|
||||
% add the current date, time and arg# to NOTES.TXT
|
||||
%
|
||||
|
||||
filename = 'NOTES.TXT';
|
||||
if nargin==0
|
||||
fid = fopen(filename,'rt');
|
||||
if fid<0, return; end;
|
||||
while ~feof(fid)
|
||||
fprintf('%s\n',fgetl(fid));
|
||||
end;
|
||||
fclose(fid);
|
||||
else
|
||||
fid = fopen(filename,'a+');
|
||||
if fid<0, error('cannot open %s\n',filename); end;
|
||||
fprintf(fid, '%s\n\t%s', datestr(now),varargin{1});
|
||||
for k=2:length(varargin)
|
||||
fprintf(fid, ', %s', varargin{k});
|
||||
end;
|
||||
fprintf(fid,'\n');
|
||||
fclose(fid);
|
||||
end;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#! /usr/bin/env ocaml
|
||||
#load "unix.cma"
|
||||
|
||||
let notes_file = "notes.txt"
|
||||
|
||||
let take_notes() =
|
||||
let gmt = Unix.gmtime (Unix.time()) in
|
||||
let date =
|
||||
Printf.sprintf "%d-%02d-%02d %02d:%02d:%02d"
|
||||
(1900 + gmt.Unix.tm_year) (1 + gmt.Unix.tm_mon) gmt.Unix.tm_mday
|
||||
gmt.Unix.tm_hour gmt.Unix.tm_min gmt.Unix.tm_sec
|
||||
in
|
||||
let oc = open_out_gen [Open_append; Open_creat; Open_text] 0o644 notes_file in
|
||||
output_string oc (date ^ "\t");
|
||||
output_string oc (String.concat " " (List.tl(Array.to_list Sys.argv)));
|
||||
output_string oc "\n";
|
||||
;;
|
||||
|
||||
let dump_notes() =
|
||||
if not(Sys.file_exists notes_file)
|
||||
then (prerr_endline "no local notes found"; exit 1);
|
||||
let ic = open_in notes_file in
|
||||
try while true do
|
||||
print_endline (input_line ic)
|
||||
done with End_of_file ->
|
||||
close_in ic
|
||||
|
||||
let () =
|
||||
if Array.length Sys.argv = 1
|
||||
then dump_notes()
|
||||
else take_notes()
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
functor
|
||||
import
|
||||
Application
|
||||
Open
|
||||
OS
|
||||
System
|
||||
define
|
||||
fun {TimeStamp}
|
||||
N = {OS.localTime}
|
||||
in
|
||||
(1900+N.year)#"-"#(1+N.mon)#"-"#N.mDay#", "#N.hour#":"#N.min#":"#N.sec
|
||||
end
|
||||
|
||||
fun {Join X|Xr Sep}
|
||||
{FoldL Xr fun {$ Z X} Z#Sep#X end X}
|
||||
end
|
||||
|
||||
case {Application.getArgs plain}
|
||||
of nil then
|
||||
try
|
||||
F = {New Open.file init(name:"notes.txt")}
|
||||
in
|
||||
{System.printInfo {F read(list:$ size:all)}}
|
||||
{F close}
|
||||
catch _ then skip end
|
||||
[] Args then
|
||||
F = {New Open.file init(name:"notes.txt" flags:[write text create append])}
|
||||
in
|
||||
{F write(vs:{TimeStamp}#"\n")}
|
||||
{F write(vs:"\t"#{Join Args " "}#"\n")}
|
||||
{F close}
|
||||
end
|
||||
{Application.exit 0}
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
if ($argc > 1)
|
||||
file_put_contents(
|
||||
'notes.txt',
|
||||
date('r')."\n\t".implode(' ', array_slice($argv, 1))."\n",
|
||||
FILE_APPEND
|
||||
);
|
||||
else
|
||||
@readfile('notes.txt');
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
my $file = 'notes.txt';
|
||||
|
||||
multi MAIN() {
|
||||
print slurp($file);
|
||||
}
|
||||
|
||||
multi MAIN(*@note) {
|
||||
my $fh = open($file, :a);
|
||||
$fh.say: DateTime.now, "\n\t", @note;
|
||||
$fh.close;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
my $file = 'notes.txt';
|
||||
if ( @ARGV ) {
|
||||
open NOTES, '>>', $file or die "Can't append to file $file: $!";
|
||||
print NOTES scalar localtime, "\n\t@ARGV\n";
|
||||
} else {
|
||||
open NOTES, '<', $file or die "Can't read file $file: $!";
|
||||
print <NOTES>;
|
||||
}
|
||||
close NOTES;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
|
||||
|
||||
(load "@lib/misc.l")
|
||||
(if (argv)
|
||||
(out "+notes.txt" (prinl (stamp) "^J^I" (glue " " @)))
|
||||
(and (info "notes.txt") (in "notes.txt" (echo))) )
|
||||
(bye)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
$notes = "notes.txt"
|
||||
if (($args).length -eq 0) {
|
||||
if(Test-Path $notes) {
|
||||
Get-Content $notes
|
||||
}
|
||||
} else {
|
||||
Get-Date | Add-Content $notes
|
||||
"`t" + $args -join " " | Add-Content $notes
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#FileName="notes.txt"
|
||||
Define argc=CountProgramParameters()
|
||||
If OpenConsole()
|
||||
If argc=0
|
||||
If ReadFile(0,#FileName)
|
||||
While Eof(0)=0
|
||||
PrintN(ReadString(0)) ; No new notes, so present the old
|
||||
Wend
|
||||
CloseFile(0)
|
||||
EndIf
|
||||
Else ; e.g. we have some arguments
|
||||
Define d$=FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss",date())
|
||||
If OpenFile(0,#FileName)
|
||||
Define args$=""
|
||||
While argc
|
||||
args$+" "+ProgramParameter() ; Read all arguments
|
||||
argc-1
|
||||
Wend
|
||||
FileSeek(0,Lof(0)) ; Go to the end of this file
|
||||
WriteStringN(0,d$+#CRLF$+#TAB$+args$) ; Append date & note
|
||||
CloseFile(0)
|
||||
EndIf
|
||||
EndIf
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import sys, datetime, shutil
|
||||
|
||||
#sys.argv[1:] = 'go for it'.split()
|
||||
if len(sys.argv) == 1:
|
||||
try:
|
||||
f = open('notes.txt', 'r')
|
||||
shutil.copyfileobj(f, sys.stdout)
|
||||
f.close()
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
f = open('notes.txt', 'a')
|
||||
f.write(datetime.datetime.now().isoformat() + '\n')
|
||||
f.write("\t%s\n" % ' '.join(sys.argv[1:]))
|
||||
f.close()
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env Rscript --default-packages=methods
|
||||
|
||||
args <- commandArgs(trailingOnly=TRUE)
|
||||
|
||||
if (length(args) == 0) {
|
||||
conn <- file("notes.txt", 'r')
|
||||
cat(readLines(conn), sep="\n")
|
||||
} else {
|
||||
conn <- file("notes.txt", 'a')
|
||||
cat(file=conn, date(), "\n\t", paste(args, collapse=" "), "\n", sep="")
|
||||
}
|
||||
close(conn)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
REBOL [
|
||||
Title: "Notes"
|
||||
Author: oofoe
|
||||
Date: 2010-10-04
|
||||
URL: http://rosettacode.org/wiki/Take_notes_on_the_command_line
|
||||
]
|
||||
|
||||
notes: %notes.txt
|
||||
|
||||
either any [none? args: system/script/args empty? args] [
|
||||
if exists? notes [print read notes]
|
||||
] [
|
||||
write/binary/append notes rejoin [now lf tab args lf]
|
||||
]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/*REXX program implements the "NOTES" command (append text to a file).*/
|
||||
timestamp=right(date(),11,0) time() date('W') /*create date/time stamp.*/
|
||||
nFID = 'NOTES.TXT' /*the fileID of the "notes" file.*/
|
||||
|
||||
if 'f0'x==0 then tab='05'x /*this is an EBCDIC system. */
|
||||
else tab='09'x /* " " " ASCII " */
|
||||
|
||||
if arg()==0 then do while lines(nFID) /*No args? Then show the file. */
|
||||
say linein(Nfid) /*show a line of file ──► screen.*/
|
||||
end /*while*/
|
||||
else do
|
||||
call lineout nFID,timestamp /*append the timestamp. */
|
||||
call lineout nFID,tab||arg(1) /*append the "note" text*/
|
||||
end
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
notes = 'NOTES.TXT'
|
||||
if ARGV.empty?
|
||||
File.copy_stream(notes, $stdout) rescue nil
|
||||
else
|
||||
File.open(notes, 'a') {|file| file.puts "%s\n\t%s" % [Time.now, ARGV.join(' ')]}
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#! /usr/local/bin/snobol4 -b
|
||||
a = 2 ;* skip '-b' parameter
|
||||
notefile = "notes.txt"
|
||||
while args = args host(2,a = a + 1) " " :s(while)
|
||||
ident(args) :f(append)
|
||||
noparms input(.notes,io_findunit(),,notefile) :s(display)f(end)
|
||||
display output = notes :s(display)
|
||||
endfile(notes) :(end)
|
||||
append output(.notes,io_findunit(),"A",notefile) :f(end)
|
||||
notes = date()
|
||||
notes = char(9) args
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#lang racket
|
||||
(require racket/date)
|
||||
(define *notes* "NOTES.TXT")
|
||||
|
||||
(let ([a (vector->list (current-command-line-arguments))])
|
||||
(cond
|
||||
[(empty? a)
|
||||
(with-handlers ([exn:fail? void])
|
||||
(call-with-input-file *notes*
|
||||
(lambda (fi)
|
||||
(copy-port fi (current-output-port)))))
|
||||
]
|
||||
[else
|
||||
(call-with-output-file *notes*
|
||||
(lambda (fo)
|
||||
(let ([ln (apply string-append (add-between a " "))]
|
||||
[dt (date->string (current-date))])
|
||||
(fprintf fo "~a~n\t~a~n" dt ln)))
|
||||
#:mode 'text #:exists 'append)
|
||||
]))
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
$ include "seed7_05.s7i";
|
||||
$ include "getf.s7i";
|
||||
$ include "time.s7i";
|
||||
|
||||
const string: noteFileName is "NOTES.TXT";
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var file: note is STD_NULL;
|
||||
begin
|
||||
if length(argv(PROGRAM)) = 0 then
|
||||
# write NOTES.TXT
|
||||
write(getf(noteFileName));
|
||||
else
|
||||
# Write date & time to NOTES.TXT, and then arguments
|
||||
note := open(noteFileName, "a");
|
||||
if note <> STD_NULL then
|
||||
writeln(note, truncToSecond(time(NOW)));
|
||||
writeln(note, "\t" <& join(argv(PROGRAM), " "));
|
||||
close(note);
|
||||
end if;
|
||||
end if;
|
||||
end func;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Make it easier to change the name of the notes file
|
||||
set notefile notes.txt
|
||||
|
||||
if {$argc} {
|
||||
# Write a message to the file
|
||||
set msg [clock format [clock seconds]]\n\t[join $argv " "]
|
||||
set f [open $notefile a]
|
||||
puts $f $msg
|
||||
close $f
|
||||
} else {
|
||||
# Print the contents of the file
|
||||
catch {
|
||||
set f [open $notefile]
|
||||
fcopy $f stdout
|
||||
close $f
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
NOTES=$HOME/notes.txt
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
[[ -r $NOTES ]] && more $NOTES
|
||||
else
|
||||
date >> $NOTES
|
||||
echo " $*" >> $NOTES
|
||||
fi
|
||||
|
|
@ -0,0 +1 @@
|
|||
N=~/notes.txt;[[ $# -gt 0 ]] && { date ; echo " $*"; exit 0; } >> $N || [[ -r $N ]] && cat $N
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
NOTES=$HOME/notes.txt
|
||||
if test "x$*" = "x"
|
||||
then
|
||||
if test -r $NOTES
|
||||
then
|
||||
more $NOTES
|
||||
fi
|
||||
else
|
||||
date >> $NOTES
|
||||
echo " $*" >> $NOTES
|
||||
fi
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
Imports System.IO
|
||||
|
||||
Module Notes
|
||||
Function Main(ByVal cmdArgs() As String) As Integer
|
||||
Try
|
||||
If cmdArgs.Length = 0 Then
|
||||
Using sr As New StreamReader("NOTES.TXT")
|
||||
Console.WriteLine(sr.ReadToEnd)
|
||||
End Using
|
||||
Else
|
||||
Using sw As New StreamWriter("NOTES.TXT", True)
|
||||
sw.WriteLine(Date.Now.ToString())
|
||||
sw.WriteLine("{0}{1}", ControlChars.Tab, String.Join(" ", cmdArgs))
|
||||
End Using
|
||||
End If
|
||||
Catch
|
||||
End Try
|
||||
End Function
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue