Take notes on the command line: Difference between revisions
m
syntax highlighting fixup automation
(Added XPL0 example.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 12:
=={{header|11l}}==
<
I :argv.len == 1
print(File(‘notes.txt’).read(), end' ‘’)
Line 18:
V f = File(‘notes.txt’, ‘a’)
f.write(Time().format("YYYY-MM-DD hh:mm:ss\n"))
f.write("\t"(:argv[1..].join(‘ ’))"\n")</
=={{header|8086 Assembly}}==
Line 24:
This code assembles into a .COM file that runs under MS-DOS.
<
cpu 8086
;;; MS-DOS PSP locations
Line 186:
filnam: db 'NOTES.TXT',0 ; File name to use
section .bss
filebuf: resb BUFSZ ; 4K file buffer</
{{out}}
Line 213:
{{works with|Ada 2005}}
<
with Ada.Characters.Latin_1;
with Ada.Command_Line;
Line 263:
Ada.Text_IO.Close (File => Notes_File);
end if;
end Notes;</
=={{header|Aime}}==
<
if (argc() == 1) {
Line 293:
f.byte('\n');
}</
=={{header|APL}}==
{{works with|GNU APL}}
<
∇r←ch Join ls ⍝ Join list of strings with character
Line 334:
Notes
)OFF</
{{out}}
Line 360:
=={{header|AppleScript}}==
Requires a modernish version of OS X (Lion or later) on which osascript works as a shebang interpreter.
<
-- format a number as a string with leading zero if needed
Line 442:
end try
end if
end run</
=={{header|Arturo}}==
<
if? empty? arg [
if exists? notes -> print read notes
Line 454:
"\t" ++ (join.with:" " to [:string] arg) ++ "\n"
write.append notes output
]</
{{out}}
Line 465:
=={{header|AutoHotkey}}==
<
If 0 = 0 ; no arguments
Line 487:
FileAppend, `r`n, %Notes%
EOF:</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f TAKE_NOTES.AWK [notes ... ]
# examples:
Line 515:
printf("\n") >>log_name
}
</syntaxhighlight>
{{out}} from the three example commands:
<pre>
Line 530:
for this to work with older versions of QB.
<
OPEN "notes.txt" FOR APPEND AS 1
PRINT #1, DATE$, TIME$
Line 545:
CLOSE
END IF
END IF</
=={{header|Batch File}}==
{{works with|Windows NT|4}}
<
if %1@==@ (
if exist notes.txt more notes.txt
Line 555:
)
echo %date% %time%:>>notes.txt
echo %*>>notes.txt</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
This must be compiled to an EXE and run from the command prompt.
<
REM!Embed
LF = 10
Line 588:
CLOSE #notes%
QUIT</
=={{header|C}}==
<
#include <time.h>
Line 621:
if (note) fclose(note);
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.IO;
using System.Text;
Line 656:
}
}
}</
=={{header|C++}}==
<
#include <iostream>
#include <ctime>
Line 695:
}
}
}</
=={{header|Clojure}}==
<
(:use [clojure.string :only [join]]))
Line 710:
(println (slurp "NOTES.txt"))))
(notes *command-line-args*)</
{{out}}
Line 730:
=={{header|CLU}}==
<
% PCLU in "useful.lib".
Line 797:
else add_note(note)
end
end start_up</
{{out}}
<pre>$ ls
Line 819:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. NOTES.
Line 896:
GOBACK
.</
=={{header|Common Lisp}}==
<
(defun format-date-time (stream)
Line 920:
(defun main ()
(notes (uiop:command-line-arguments)))</
=={{header|D}}==
<
import std.stdio, std.file, std.datetime, std.range;
Line 936:
f.writefln("\t%-(%s %)", args.dropOne);
}
}</
{{out}}
<pre>C:\>notes Permission to speak, sir!
Line 950:
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 991:
sw.Free;
end;
end.</
=={{header|E}}==
<
def f := <file:notes.txt>
Line 1,011:
w.close()
}
}</
=={{header|Elixir}}==
{{trans|Erlang}}
<
@filename "NOTES.TXT"
Line 1,029:
end
Take_notes.main(System.argv)</
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
#! /usr/bin/env escript
Line 1,057:
Existing_contents = file_contents(),
file:write_file( file(), [Existing_contents, Notes, "\n"] ).
</syntaxhighlight>
=={{header|Euphoria}}==
<
constant filename = "notes.txt"
integer fn
Line 1,091:
puts(fn,line)
close(fn)
end if</
=={{header|F Sharp|F#}}==
<
open System.IO;;
Line 1,116:
| 0 -> show_notes()
| _ -> take_note <| String.concat " " args;
0;;</
Usage:
Line 1,133:
=={{header|Factor}}==
<
USING: kernel calendar calendar.format io io.encodings.utf8 io.files
sequences command-line namespaces ;
Line 1,145:
print flush
] with-file-appender
] if-empty</
=={{header|Fantom}}==
<
class Notes
{
Line 1,175:
}
}
</syntaxhighlight>
Sample:
Line 1,195:
The following is SwiftForth-specific, and runs in the Forth environment rather than as a standalone terminal application. Win32Forth only needs simple replacements of DATE and TIME . A Unix Forth would come closer to the 'commandline' requirement, as Windows Forths for whatever reason very eagerly discard the Windows console. Because this runs in the Forth environment, the otherwise acceptable application words are stuffed in a wordlist. Standard Forth doesn't have the notion of create-it-if-it-doesn't-exist, so OPEN just tries again with CREATE-FILE if OPEN-FILE fails.
<
get-current also note-words definitions
Line 1,238:
open 0 parse dup if add-note
else 2drop dump then close ;
previous</
The following is exactly the same program, but written in 4tH. 4tH has an I/O system which is different from ANS-Forth. The notes file is specified on the commandline.
<
include lib/argopen.4th
include lib/ansfacil.4th
Line 1,268:
refill drop 0 parse dup if add-note else 2drop dump then ;
note</
=={{header|Fortran}}==
<
program notes
implicit none
Line 1,301:
endif
end program notes
</syntaxhighlight>
{{out}}<pre>
2022-2-20T18:40:13
Line 1,310:
=={{header|FreeBASIC}}==
<
Open "notes.txt" For Append As #1
Print #1, Date, Time
Line 1,329:
End If
Close #1
Sleep</
=={{header|Gambas}}==
<
Public Sub Main()
Line 1,355:
Endif
End</
Output:
<pre>
Line 1,365:
=={{header|Go}}==
<
import (
Line 1,413:
os.Exit(1)
}
}</
=={{header|Groovy}}==
<
if (args) {
notes << "${new Date().format('YYYY-MM-dd HH:mm:ss')}\t${args.join(' ')}\n"
Line 1,422:
println notes.text
}
</syntaxhighlight>
=={{header|Haskell}}==
<
import System.Time (getClockTime)
Line 1,436:
else
do ct <- getClockTime
appendFile "notes.txt" $ show ct ++ "\n\t" ++ unwords args ++ "\n"</
{{out}} after a few runs:
Line 1,447:
=={{header|HicEst}}==
<
CHARACTER notes="Notes.txt", txt*1000
Line 1,466:
ENDIF
ALARM(999) ! quit HicEst immediately</
<pre>Thu 2010-09-16 18:42:15
This is line 1
Line 1,475:
=={{header|Icon}} and {{header|Unicon}}==
<syntaxhighlight lang="icon">
procedure write_out_notes (filename)
file := open (filename, "rt") | stop ("no notes file yet")
Line 1,496:
else add_to_notes (notes_file, args)
end
</syntaxhighlight>
{{out}}
Line 1,516:
=={{header|J}}==
'''Solution''':<br>
<
notes=: monad define
Line 1,528:
notes 2}.ARGV
exit 0</
Create a Shortcut called <tt>Notes</tt> that calls the script above using the Target:<br>
Line 1,551:
=={{header|Java}}==
<
import java.nio.channels.*;
import java.util.Date;
Line 1,571:
}
}
}</
=={{header|JavaScript}}==
{{works with|JScript}}
<
var args = WScript.Arguments;
Line 1,600:
f.WriteLine();
f.Close();
}</
<pre>> del NOTES.TXT
> cscript /nologo notes.js
Line 1,609:
=={{header|Julia}}==
<
const filename = "NOTES.TXT"
Line 1,621:
end
close(fp)
</syntaxhighlight>
=={{header|Kotlin}}==
<
import java.io.File
Line 1,643:
f.appendText(notes)
}
}</
Sample output:
Line 1,655:
=={{header|Lasso}}==
<
local(
Line 1,676:
else
#notesfile -> exists ? stdout(#notesfile -> readstring)
}</
Called with:
<
./notes First Second Last
./notes
</syntaxhighlight>
<pre>2013-11-15 11:43:08
Rosetta was here, Räksmörgås
Line 1,690:
=={{header|Lua}}==
<
if #arg == 0 then
Line 1,710:
fp:close()
end</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="text">If[Length[$CommandLine < 11], str = OpenRead["NOTES.TXT"];
Print[ReadString[str, EndOfFile]]; Close[str],
str = OpenAppend["NOTES.TXT"]; WriteLine[str, DateString[]];
WriteLine[str, "\t" <> StringRiffle[$CommandLine[[11 ;;]]]];
Close[str]]</
=={{header|MATLAB}} / {{header|Octave}}==
<
% NOTES can be used for taking notes
% usage:
Line 1,746:
fprintf(fid,'\n');
fclose(fid);
end; </
=={{header|Mercury}}==
<
:- interface.
Line 1,809:
notes_filename = "NOTES.TXT".
:- end_module notes.</
=={{header|Nim}}==
<
if paramCount() == 0:
Line 1,821:
f.writeLine getTime()
f.writeLine "\t", commandLineParams().join(" ")
f.close()</
Sample format.txt:
<pre>2021-04-21T15:49:00+02:00
Line 1,829:
=={{header|OCaml}}==
<
#load "unix.cma"
Line 1,859:
if Array.length Sys.argv = 1
then dump_notes()
else take_notes()</
=={{header|Oz}}==
<
import
Application
Line 1,895:
end
{Application.exit 0}
end</
=={{header|Pascal}}==
Free Pascal in Delphi mode or Delphi in console mode.
<syntaxhighlight lang="pascal">
{$mode delphi}
PROGRAM notes;
Line 1,939:
END;
END.
</syntaxhighlight>
{{out|Program usage and output}}
Line 1,954:
=={{header|Perl}}==
<
if ( @ARGV ) {
open NOTES, '>>', $file or die "Can't append to file $file: $!";
Line 1,962:
print <NOTES>;
}
close NOTES;</
{{out}} after a few runs:
Line 1,973:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cmd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">(),</span>
Line 1,986:
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PHP}}==
<
#!/usr/bin/php
<?php
Line 2,000:
else
@readfile('notes.txt');
</syntaxhighlight>
Note that the error suppression operator (@) is considered bad coding practice.
Line 2,016:
=={{header|PicoLisp}}==
<
(load "@lib/misc.l")
Line 2,022:
(out "+notes.txt" (prinl (stamp) "^J^I" (glue " " @)))
(and (info "notes.txt") (in "notes.txt" (echo))) )
(bye)</
=={{header|PL/I}}==
<
declare text character (100) varying;
declare note_file file;
Line 2,061:
put file (note_file) skip;
put skip list ('The file, NOTES.TXT, has been created');
end NOTES;</
=={{header|PowerShell}}==
<
if (($args).length -eq 0) {
if(Test-Path $notes) {
Line 2,072:
Get-Date | Add-Content $notes
"`t" + $args -join " " | Add-Content $notes
}</
=={{header|PureBasic}}==
<
Define argc=CountProgramParameters()
If OpenConsole()
Line 2,098:
EndIf
EndIf
EndIf</
=={{header|Python}}==
<
if len(sys.argv) == 1:
Line 2,112:
with open('notes.txt', 'a') as f:
f.write(datetime.datetime.now().isoformat() + '\n')
f.write("\t%s\n" % ' '.join(sys.argv[1:]))</
'''Sample notes.txt file'''
Line 2,123:
=={{header|R}}==
<
args <- commandArgs(trailingOnly=TRUE)
Line 2,134:
cat(file=conn, date(), "\n\t", paste(args, collapse=" "), "\n", sep="")
}
close(conn)</
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#!/usr/bin/env racket
#lang racket
Line 2,153:
(date->string (current-date) #t)
(string-join notes))))))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
multi MAIN() {
Line 2,168:
$fh.say: DateTime.now, "\n\t", @note;
$fh.close;
}</
=={{header|REBOL}}==
<
Title: "Notes"
URL: http://rosettacode.org/wiki/Take_notes_on_the_command_line
Line 2,182:
] [
write/binary/append notes rejoin [now lf tab args lf]
]</
{{out|Sample session}}
Line 2,199:
=={{header|REXX}}==
<
timestamp=right(date(),11,0) time() date('W') /*create a (current) date & time stamp.*/
nFID = 'NOTES.TXT' /*the fileID of the "notes" file. */
Line 2,213:
call lineout nFID,tab||arg(1) /* " " text " " " */
end
/*stick a fork in it, we're all done. */</
=={{header|Ruby}}==
<
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</
=={{header|Rust}}==
This uses version 0.4 of the <code>chrono</code> crate
<
use std::fs::OpenOptions;
Line 2,268:
add_to_notes(¬e.join(" ")).expect("failed to write to NOTES.TXT");
}
}</
=={{header|Scala}}==
{{libheader|Scala}}
<
import java.time.LocalDateTime
Line 2,290:
}
}
}</
=={{header|Scheme}}==
(moved from Racket)
{{works with|Racket}}
<
(require racket/date)
(define *notes* "NOTES.TXT")
Line 2,314:
(fprintf fo "~a~n\t~a~n" dt ln)))
#:mode 'text #:exists 'append)
]))</
=={{header|Seed7}}==
<
$ include "getf.s7i";
$ include "time.s7i";
Line 2,339:
end if;
end if;
end func;</
=={{header|Sidef}}==
<
if (ARGV.len > 0) {
Line 2,351:
var fh = file.open_r
fh && fh.each { .say }
}</
{{out}}
<pre>
Line 2,365:
=={{header|SNOBOL4}}==
{{works with|Macro SNOBOL4 in C}}
<
a = 2 ;* skip '-b' parameter
notefile = "notes.txt"
Line 2,376:
notes = date()
notes = char(9) args
end</
=={{header|Swift}}==
<
let args = Process.arguments
Line 2,419:
let strData = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
handler?.writeData(strData!)</
{{out}}
Example output
Line 2,430:
=={{header|Tcl}}==
<
set notefile notes.txt
Line 2,446:
close $f
}
}</
{{out}} after a few runs:
<pre>
Line 2,458:
{{works with|R3}}
The lack of built-in high level time and date functions makes it more difficult than necessary, since they have to be implemented by user defined functions.
<syntaxhighlight lang="text">If Cmd (0) > 1 Then ' if there are commandline arguments
If Set (a, Open ("notes.txt", "a")) < 0 Then
Print "Cannot write \qnotes.txt\q" ' open the file in "append" mode
Line 2,517:
_Format Param (2) : Return (Join (Iif (a@<10, Join(b@, "0"), b@), Str (a@)))
_Monthdays Param (2) : Return (((a@ + (a@<7)) % 2) + 30 - ((2 - b@) * (a@=1)))
</syntaxhighlight>
{{out}}
<pre>2022-04-02 14:58:57
Line 2,528:
=={{header|UNIX Shell}}==
Bash version
<
NOTES=$HOME/notes.txt
if [[ $# -eq 0 ]] ; then
Line 2,535:
date >> $NOTES
echo " $*" >> $NOTES
fi</
"Spoiled Bash kid" version
<
Portable version
<
if test "x$*" = "x"
then
Line 2,552:
date >> $NOTES
echo " $*" >> $NOTES
fi</
{{omit from|Retro}}
=={{header|Visual Basic .NET}}==
<
Module Notes
Line 2,575:
End Try
End Function
End Module</
=={{header|Wren}}==
Line 2,582:
An awkward task for Wren-cli which currently has no way of determining the current date and time.
We therefore have to ask the user to input it plus the note(s).
<
import "/ioutil" for File, FileUtil
import "/date" for Date
Line 2,597:
var note = "\t" + args[1..-1].join(" ") + "\n"
FileUtil.append("NOTES.TXT", dateTime.format(dateFormatOut) + "\n" + note)
}</
{{out}}
Line 2,613:
=={{header|XPL0}}==
Checks for unlikely array overflows have been omitted for simplicity.
<
int I, NotesSize, Ch, CmdArgSize;
char Notes(1_000_000), CmdArg(1000);
Line 2,647:
Close(3);
];
]</
{{out}}
Line 2,661:
=={{header|zkl}}==
File notes.zkl:
<
args:=vm.arglist;
if (not args)
Line 2,669:
f.writeln(Time.Date.ctime(),"\n\t",args.concat(" "));
f.close();
}</
{{out}}
<pre>
|