Take notes on the command line: Difference between revisions

Add SETL
(Added uBasic/4tH version)
(Add SETL)
 
(18 intermediate revisions by 15 users not shown)
Line 1:
{{task|Text processing}} {{selection|Short Circuit|Console Program Basics}}[[Category:Basic language learning]] [[Category:Programming environment operations]]
{{omit from|EasyLang}}
{{omit from|Lotus 123 Macro Scripting}}
{{omit from|Maxima}}
Line 12 ⟶ 13:
=={{header|11l}}==
 
<langsyntaxhighlight lang="11l">:start:
I :argv.len == 1
print(File(‘notes.txt’).read(), end' ‘’)
E
V f = File(‘notes.txt’, ‘a’APPEND)
f.write(Time().format("YYYY-MM-DD hh:mm:ss\n"))
f.write("\t"(:argv[1..].join(‘ ’))"\n")</langsyntaxhighlight>
 
=={{header|8086 Assembly}}==
Line 24 ⟶ 25:
This code assembles into a .COM file that runs under MS-DOS.
 
<langsyntaxhighlight lang="asm"> bits 16
cpu 8086
;;; MS-DOS PSP locations
Line 186 ⟶ 187:
filnam: db 'NOTES.TXT',0 ; File name to use
section .bss
filebuf: resb BUFSZ ; 4K file buffer</langsyntaxhighlight>
 
{{out}}
Line 209 ⟶ 210:
 
A:\></pre>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program notes64.s */
 
/************************************/
/* Constantes */
/************************************/
.include "../includeConstantesARM64.inc"
.equ BUFFERSIZE, 10000
.equ O_APPEND, 0x400
.equ GETTIME, 0xa9 // call system linux gettimeofday
 
/*******************************************/
/* Structures */
/********************************************/
/* example structure time */
.struct 0
timeval_sec: //
.struct timeval_sec + 8
timeval_usec: //
.struct timeval_usec + 8
timeval_end:
.struct 0
timezone_min: //
.struct timezone_min + 8
timezone_dsttime: //
.struct timezone_dsttime + 8
timezone_end:
/*********************************/
/* Initialized data */
/*********************************/
.data
szCarriageReturn: .asciz "\n"
szSpace: .asciz " "
szLibNoFile: .asciz "no file notes.txt in this directory\n"
szFileName: .asciz "notes.txt"
szMessAnoRead: .asciz "Error read file \n"
szMessAnoTime: .asciz "Error call time \n"
szMessAnoWrite: .asciz "Error file write \n"
szMessDate: .asciz " @/@/@ @:@:@ \n" // message time
.align 8
tbDayMonthYear: .quad 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
.quad 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
.quad 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
.quad 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
stTVal: .skip timeval_end
stTZone: .skip timezone_end
sBuffer: .skip BUFFERSIZE
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
mov fp,sp // stack address
ldr x20,[fp] // load number of parameters command line
cmp x20,#1 // >1 insertion text
bgt 10f
mov x0,AT_FDCWD
ldr x1,qAdrszFileName // file name
mov x2,#O_RDONLY // flags
mov x3,#0 // mode in octal
mov x8,#OPEN // open file, create if not exist
svc 0
cmp x0,#0 // error open
ble 99f // file no exists ?
mov x19,x0 // save FD and if file exist display text
ldr x1,qAdrsBuffer // buffer address
ldr x2,#iBufferSize // buffersize
mov x8,READ
svc 0
cmp x0,#0 // error read ?
blt 98f
ldr x0,qAdrsBuffer // buffer address
bl affichageMess // and display
b 50f
10: // multiple parameters in command line
mov x0,AT_FDCWD
ldr x1,qAdrszFileName // file name
ldr x2,iFlag // flags
mov x3,#0644 // mode in octal
mov x8,#OPEN // open file, create if not exist
svc 0
cmp x0,#0 // error open
ble 96f
mov x19,x0 // save FD
ldr x0,qAdrstTVal
ldr x1,qAdrstTZone
mov x8,#GETTIME // call system function time
svc 0
cmp x0,#-1 // error ?
beq 97f
ldr x1,qAdrstTVal
ldr x0,[x1,timeval_sec] // timestamp in second
bl formatTime // format date and hour
mov x1,x0
mov x2,#0
11: // compute length of time message
ldrb w3,[x1,x2]
cmp w3,#0
beq 12f
add x2,x2,#1
b 11b
12:
mov x0,x19 // write time message
mov x8,#WRITE
svc 0
cmp x0,#0 // error ?
ble 96f
mov x5,#2 // start parameters command line
13:
mov x0,x19 // file FD
ldr x1,[fp,x5,lsl #3] // load parameter address
mov x2,#0
14: // compute parameter length
ldrb w3,[x1,x2]
cmp w3,#0
beq 15f
add x2,x2,#1
b 14b
15: // write parameter
mov x8,#WRITE
svc 0
cmp x0,#0 // error ?
ble 96f
mov x0,x19 // file FD
ldr x1,iadrszSpace // write a space betwin parameters
mov x2,#1
mov x8,#WRITE
svc 0
add x5,x5,#1 // increment indixe
cmp x5,x20 // parameters maxi ?
ble 13b // no -> loop
mov x0,x19
ldr x1,qAdrszCarriageReturn // write line end
mov x2,#1
mov x7,#WRITE
svc 0
 
50: // close the file
mov x0,x19
mov x8,CLOSE
svc 0
b 100f
 
96: // error write
ldr x0,qAdrszMessAnoWrite
bl affichageMess
b 100f
97: // error function time
ldr x0,qAdrszMessAnoTime
bl affichageMess
b 100f
98: // error read
ldr x0,qAdrszMessAnoRead
bl affichageMess
b 100f
99: // display message no file in this directory
ldr x0,qAdrszLibNoFile
bl affichageMess
100: // standard end of the program
mov x0, #0 // return code
mov x8,EXIT
svc #0 // perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsZoneConv: .quad sZoneConv
qAdrszFileName: .quad szFileName
qAdrszLibNoFile: .quad szLibNoFile
qAdrsBuffer: .quad sBuffer
iBufferSize: .quad BUFFERSIZE
qAdrszMessAnoRead: .quad szMessAnoRead
qAdrszMessAnoTime: .quad szMessAnoTime
qAdrszMessAnoWrite: .quad szMessAnoWrite
iFlag: .quad O_RDWR|O_APPEND|O_CREAT
qAdrstTVal: .quad stTVal
qAdrstTZone: .quad stTZone
iadrszSpace: .quad szSpace
/***************************************************/
/* formatting time area */
/***************************************************/
// x0 contains time area
// x0 return address result string
formatTime:
stp x2,lr,[sp,-16]! // save registers
ldr x2,qSecJan2020
sub x3,x0,x2 // total secondes to 01/01/2020
mov x4,60
udiv x5,x3,x4
msub x6,x5,x4,x3 // compute secondes
udiv x3,x5,x4
msub x7,x3,x4,x5 // compute minutes
mov x4,24
udiv x5,x3,x4
msub x8,x5,x4,x3 // compute hours
mov x4,(365 * 4 + 1)
udiv x9,x5,x4
lsl x9,x9,2 // multiply by 4 = year1
udiv x12,x5,x4
msub x10,x12,x4,x5
ldr x11,qAdrtbDayMonthYear
mov x12,3
mov x13,12
1:
mul x14,x13,x12
ldr x15,[x11,x14,lsl 3] // load days by year
cmp x10,x15
bge 2f
sub x12,x12,1
cmp x12,0
cbnz x12,1b
2: // x12 = year2
mov x16,11
mul x15,x13,x12
lsl x15,x15,3 // * par 8
add x14,x15,x11
3:
ldr x15,[x14,x16,lsl 3] // load days by month
cmp x10,x15
bge 4f
sub x16,x16,1
cmp x16,0
cbnz x16,3b
4: // x16 = month - 1
mul x15,x13,x12
add x15,x15,x16
ldr x1,qAdrtbDayMonthYear
ldr x3,[x1,x15,lsl 3]
sub x0,x10,x3
add x0,x0,1 // final compute day
ldr x1,qAdrsZoneConv
bl conversion10
ldr x0,qAdrszMessDate
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at first @ character
mov x2,x0
add x0,x16,1 // final compute month
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x2
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next @ character
mov x2,x0
add x0,x9,2020
add x0,x0,x12 // final compute year = 2020 + year1 + year2
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x2
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next @ character
mov x2,x0
mov x0,x8 // hours
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x2
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next @ character
mov x2,x0
mov x0,x7 // minutes
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x2
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next @ character
mov x2,x0
mov x0,x6 // secondes
ldr x1,qAdrsZoneConv
bl conversion10
mov x4,#0 // store zero final
strb w4,[x1,x0]
mov x0,x2
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next // character
100:
ldp x2,lr,[sp],16 // restaur registers
ret
qAdrszMessDate: .quad szMessDate
qSecJan2020: .quad 1577836800
qAdrtbDayMonthYear: .quad tbDayMonthYear
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../includeARM64.inc"
</syntaxhighlight>
{{output}}
<pre>
~/.../rosetta/asm3 $ notes64
11/4/2023 15:16:29
initialisation
11/4/2023 15:16:45
verification
11/4/2023 15:17:15
suite modification revoir le cas
 
</pre>
=={{header|Ada}}==
{{works with|Ada 2005}}
 
<langsyntaxhighlight Adalang="ada">with Ada.Calendar.Formatting;
with Ada.Characters.Latin_1;
with Ada.Command_Line;
Line 263 ⟶ 567:
Ada.Text_IO.Close (File => Notes_File);
end if;
end Notes;</langsyntaxhighlight>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">#! /usr/local/bin/aime -a
 
if (argc() == 1) {
Line 293 ⟶ 597:
 
f.byte('\n');
}</langsyntaxhighlight>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
/*
Take notes on the command line. Rosettacode.org
*/
#include <basico.h>
 
algoritmo
cuando ' no existe el archivo ("NOTES.txt") ' {
sys = `touch NOTES.txt`; luego limpiar 'sys'
}
si ' total argumentos es (1) '
cargar cadena desde ("NOTES.txt"); luego imprime
sino
msg=""; obtener todos los parámetros, guardar en 'msg'
#( msg = strtran("@","\n\t",msg) )
fijar separador 'NULO'
fecha y hora, "\n\t", msg, "\n\n", unir esto;
añadir al final de ("NOTES.txt")
fin si
terminar
</syntaxhighlight>
{{out}}
<pre>
:
:
$ hopper3 basica/notes.bas otra y otra y otra...@y otra
$ hopper3 basica/notes.bas
27/11/2023,23:38:28:74
iniciando estas notas con un mensaje
de prueba
 
27/11/2023,23:40:57:41
nota 2:
establecer parámetro
 
27/11/2023,23:52:22:82
nueva nota de prueba
ta es medianoche
 
27/11/2023,23:55:07:20
otra nueva nota
 
27/11/2023,23:56:21:15
otra y otra y otra...
y otra
 
$ hopper3 basica/notes.bas borrar todo de este directorio@sin asco
$ hopper3 basica/notes.bas
27/11/2023,23:38:28:74
iniciando estas notas con un mensaje
de prueba
 
27/11/2023,23:40:57:41
nota 2:
establecer parámetro
 
27/11/2023,23:52:22:82
nueva nota de prueba
ta es medianoche
 
27/11/2023,23:55:07:20
otra nueva nota
 
27/11/2023,23:56:21:15
otra y otra y otra...
y otra
 
28/11/2023,00:04:04:62
borrar todo de este directorio
sin asco
 
$
</pre>
 
=={{header|APL}}==
{{works with|GNU APL}}
 
<langsyntaxhighlight APLlang="apl">#!/usr/local/bin/apl -s --
 
∇r←ch Join ls ⍝ Join list of strings with character
Line 334 ⟶ 715:
 
Notes
)OFF</langsyntaxhighlight>
 
{{out}}
Line 360 ⟶ 741:
=={{header|AppleScript}}==
Requires a modernish version of OS X (Lion or later) on which osascript works as a shebang interpreter.
<langsyntaxhighlight lang="applescript">#!/usr/bin/osascript
 
-- format a number as a string with leading zero if needed
Line 442 ⟶ 823:
end try
end if
end run</langsyntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI or android 32 bits */
/* program notes.s */
 
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
.equ BUFFERSIZE, 10000
.equ READ, 3 @ system call
.equ WRITE, 4 @ Linux syscall
.equ OPEN, 5 @ system call
.equ CLOSE, 6 @ system call
.equ O_RDONLY, 0
.equ O_RDWR, 0x0002 @ open for reading and writing
.equ O_APPEND, 0x400
.equ O_CREAT, 0x40
.equ GETTIME, 0x4e @ call system linux gettimeofday
 
 
/*******************************************/
/* Structures */
/********************************************/
/* example structure time */
.struct 0
timeval_sec: @
.struct timeval_sec + 4
timeval_usec: @
.struct timeval_usec + 4
timeval_end:
.struct 0
timezone_min: @
.struct timezone_min + 4
timezone_dsttime: @
.struct timezone_dsttime + 4
timezone_end:
/*********************************/
/* Initialized data */
/*********************************/
.data
szCarriageReturn: .asciz "\n"
szSpace: .asciz " "
szLibNoFile: .asciz "no file notes.txt in this directory\n"
szFileName: .asciz "notes.txt"
szMessAnoRead: .asciz "Error read file \n"
szMessAnoTime: .asciz "Error call time \n"
szMessAnoWrite: .asciz "Error file write \n"
szMessDate: .asciz " @/@/@ @:@:@ \n" @ message time
.align 4
tbDayMonthYear: .int 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
.int 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
.int 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
.int 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
stTVal: .skip timeval_end
stTZone: .skip timezone_end
sBuffer: .skip BUFFERSIZE
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
mov fp,sp @ stack address
ldr r4,[fp] @ load number of parameters command line
cmp r4,#1 @ >1 insertion text
bgt 10f
ldr r0,iAdrszFileName @ file name
mov r1,#O_RDONLY @ flags
mov r2,#0 @ mode in octal
mov r7,#OPEN @ oen file, create if not exist
svc 0
cmp r0,#0 @ error open
ble 99f @ file no exists ?
mov r8,r0 @ save FD @ if exist display text
ldr r1,iAdrsBuffer @ buffer address
ldr r2,#iBufferSize @ buffersize
mov r7, #READ @ read file
svc 0
cmp r0,#0 @ error read ?
blt 98f
ldr r0,iAdrsBuffer @ buffer address
bl affichageMess @ and display
b 50f
10: @ multiple parameters in command line
ldr r0,iAdrszFileName @ file name
ldr r1,iFlag @ flags
mov r2,#0644 @ mode in octal
mov r7,#OPEN @ open file, create if not exist
svc 0
cmp r0,#0 @ error open
ble 96f
mov r8,r0 @ save FD
ldr r0,iAdrstTVal
ldr r1,iAdrstTZone
mov r7,#GETTIME @ call system function time
svc 0
cmp r0,#-1 @ error ?
beq 97f
ldr r0,iAdrstTVal
bl formatTime @ format date and hour
mov r1,r0
mov r2,#0
11: @ compute length of time message
ldrb r3,[r1,r2]
cmp r3,#0
beq 12f
add r2,#1
b 11b
12:
mov r0,r8 @ write time message
mov r7,#WRITE
svc 0
cmp r0,#0 @ error ?
ble 96f
mov r5,#2 @ start parameters command line
13:
mov r0,r8 @ file FD
ldr r1,[fp,r5,lsl #2] @ load parameter address
mov r2,#0
14: @ compute parameter length
ldrb r3,[r1,r2]
cmp r3,#0
beq 15f
add r2,#1
b 14b
15: @ write parameter
mov r7,#WRITE
svc 0
cmp r0,#0 @ error ?
ble 96f
mov r0,r8 @ file FD
ldr r1,iadrszSpace @ write a space betwin parameters
mov r2,#1
mov r7,#WRITE
svc 0
add r5,#1 @ increment indixe
cmp r5,r4 @ parameters maxi ?
ble 13b @ no -> loop
mov r0,r8
ldr r1,iAdrszCarriageReturn @ write line end
mov r2,#1
mov r7,#WRITE
svc 0
 
50: @ close the file
mov r0,r8
mov r7, #CLOSE
svc 0
b 100f
 
96: @ error write
ldr r0,iAdrszMessAnoWrite
bl affichageMess
b 100f
97: @ error function time
ldr r0,iAdrszMessAnoTime
bl affichageMess
b 100f
98: @ error read
ldr r0,iAdrszMessAnoRead
bl affichageMess
b 100f
99: @ display message no file in this directory
ldr r0,iAdrszLibNoFile
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsZoneConv: .int sZoneConv
iAdrszFileName: .int szFileName
iAdrszLibNoFile: .int szLibNoFile
iAdrsBuffer: .int sBuffer
iBufferSize: .int BUFFERSIZE
iAdrszMessAnoRead: .int szMessAnoRead
iAdrszMessAnoTime: .int szMessAnoTime
iAdrszMessAnoWrite: .int szMessAnoWrite
iFlag: .int O_RDWR|O_APPEND|O_CREAT
iAdrstTVal: .int stTVal
iAdrstTZone: .int stTZone
iadrszSpace: .int szSpace
/***************************************************/
/* formatting time area */
/***************************************************/
// r0 contains time area
// r0 return address result string
formatTime:
push {r2-r12,lr} @ save registers
ldr r1,[r0,#timeval_sec] @ timestemp in second
ldr r2,iSecJan2020
sub r0,r1,r2 @ total secondes to 01/01/2020
mov r1,#60
bl division
mov r0,r2
mov r6,r3 @ compute secondes
mov r1,#60
bl division
mov r7,r3 @ compute minutes
mov r0,r2
mov r1,#24
bl division
mov r8,r3 @ compute hours
mov r0,r2
mov r11,r0
mov r1,#(365 * 4 + 1)
bl division
lsl r9,r2,#2 @ multiply by 4 = year1
mov r1,#(365 * 4 + 1)
mov r0,r11
bl division
mov r10,r3
ldr r1,iAdrtbDayMonthYear
mov r2,#3
mov r3,#12
1:
mul r11,r3,r2
ldr r12,[r1,r11,lsl #2] @ load days by year
cmp r10,r12
bge 2f
sub r2,r2,#1
cmp r2,#0
bne 1b
2: @ r2 = year2
mov r5,#11
mul r4,r3,r2
lsl r4,#2
add r4,r1
3:
ldr r12,[r4,r5,lsl #2] @ load days by month
cmp r10,r12
bge 4f
subs r5,r5,#1
bne 3b
4: @ r5 = month - 1
mul r11,r3,r2
add r11,r5
ldr r1,iAdrtbDayMonthYear
ldr r3,[r1,r11,lsl #2]
sub r0,r10,r3
 
add r0,r0,#1 @ final compute day
ldr r1,iAdrsZoneConv
bl conversion10 @ this function do not zero final
mov r4,#0 @ store zero final
strb r4,[r1,r0]
ldr r0,iAdrszMessDate
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at first @ character
mov r3,r0
add r0,r5,#1 @ final compute month
ldr r1,iAdrsZoneConv
bl conversion10
mov r4,#0 @ store zero final
strb r4,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
ldr r11,iYearStart
add r0,r9,r11
add r0,r0,r2 @ final compute year = 2020 + year1 + year2
ldr r1,iAdrsZoneConv
bl conversion10
mov r4,#0 @ store zero final
strb r4,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
mov r0,r8 @ hours
ldr r1,iAdrsZoneConv
bl conversion10
mov r4,#0 @ store zero final
strb r4,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
mov r0,r7 @ minutes
ldr r1,iAdrsZoneConv
bl conversion10
mov r4,#0 @ store zero final
strb r4,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
mov r0,r6 @ secondes
ldr r1,iAdrsZoneConv
bl conversion10
mov r4,#0 @ store zero final
strb r4,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
 
100:
pop {r2-r12,pc} @ restaur registers
iAdrszMessDate: .int szMessDate
iSecJan2020: .int 1577836800
iAdrtbDayMonthYear: .int tbDayMonthYear
iYearStart: .int 2020
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
<pre>
~/.../rosetta/asm3 $ notes
10/4/2023 19:32:34
creation fichier notes
10/4/2023 19:32:53
affichage fichier
~/.../rosetta/asm3 $ notes saisie des exemples
~/.../rosetta/asm3 $ notes
10/4/2023 19:32:34
creation fichier notes
10/4/2023 19:32:53
affichage fichier
10/4/2023 19:37:58
saisie des exemples
</pre>
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">notes: "notes.txt"
if? empty? arg [
if exists? notes -> print read notes
Line 454 ⟶ 1,172:
"\t" ++ (join.with:" " to [:string] arg) ++ "\n"
write.append notes output
]</langsyntaxhighlight>
 
{{out}}
Line 465 ⟶ 1,183:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">Notes := "Notes.txt"
 
If 0 = 0 ; no arguments
Line 487 ⟶ 1,205:
FileAppend, `r`n, %Notes%
 
EOF:</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TAKE_NOTES.AWK [notes ... ]
# examples:
Line 515 ⟶ 1,233:
printf("\n") >>log_name
}
</syntaxhighlight>
</lang>
{{out}} from the three example commands:
<pre>
Line 530 ⟶ 1,248:
for this to work with older versions of QB.
 
<langsyntaxhighlight lang="qbasic">IF LEN(COMMAND$) THEN
OPEN "notes.txt" FOR APPEND AS 1
PRINT #1, DATE$, TIME$
Line 545 ⟶ 1,263:
CLOSE
END IF
END IF</langsyntaxhighlight>
 
=={{header|Batch File}}==
{{works with|Windows NT|4}}
<langsyntaxhighlight lang="dos">@echo off
if %1@==@ (
if exist notes.txt more notes.txt
Line 555 ⟶ 1,273:
)
echo %date% %time%:>>notes.txt
echo %*>>notes.txt</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
This must be compiled to an EXE and run from the command prompt.
<langsyntaxhighlight lang="bbcbasic"> REM!Exefile C:\NOTES.EXE, encrypt, console
REM!Embed
LF = 10
Line 588 ⟶ 1,306:
CLOSE #notes%
QUIT</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <time.h>
 
Line 621 ⟶ 1,339:
if (note) fclose(note);
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.IO;
using System.Text;
Line 656 ⟶ 1,374:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <ctime>
Line 695 ⟶ 1,413:
}
}
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(ns rosettacode.notes
(:use [clojure.string :only [join]]))
 
Line 710 ⟶ 1,428:
(println (slurp "NOTES.txt"))))
 
(notes *command-line-args*)</langsyntaxhighlight>
 
{{out}}
Line 730 ⟶ 1,448:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">% This program uses the "get_argv" function that is supplied iwth
% PCLU in "useful.lib".
 
Line 797 ⟶ 1,515:
else add_note(note)
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>$ ls
Line 819 ⟶ 1,537:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. NOTES.
 
Line 896 ⟶ 1,614:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defparameter *notes* "NOTES.TXT")
 
(defun format-date-time (stream)
Line 920 ⟶ 1,638:
 
(defun main ()
(notes (uiop:command-line-arguments)))</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main(in string[] args) {
import std.stdio, std.file, std.datetime, std.range;
 
Line 936 ⟶ 1,654:
f.writefln("\t%-(%s %)", args.dropOne);
}
}</langsyntaxhighlight>
{{out}}
<pre>C:\>notes Permission to speak, sir!
Line 950 ⟶ 1,668:
 
=={{header|Delphi}}==
<langsyntaxhighlight lang="delphi">program notes;
 
{$APPTYPE CONSOLE}
Line 991 ⟶ 1,709:
sw.Free;
end;
end.</langsyntaxhighlight>
 
=={{header|E}}==
 
<langsyntaxhighlight lang="e">#!/usr/bin/env rune
 
def f := <file:notes.txt>
Line 1,011 ⟶ 1,729:
w.close()
}
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Erlang}}
<langsyntaxhighlight lang="elixir">defmodule Take_notes do
@filename "NOTES.TXT"
Line 1,029 ⟶ 1,747:
end
 
Take_notes.main(System.argv)</langsyntaxhighlight>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
#! /usr/bin/env escript
 
Line 1,057 ⟶ 1,775:
Existing_contents = file_contents(),
file:write_file( file(), [Existing_contents, Notes, "\n"] ).
</syntaxhighlight>
</lang>
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">constant cmd = command_line()
constant filename = "notes.txt"
integer fn
Line 1,091 ⟶ 1,809:
puts(fn,line)
close(fn)
end if</langsyntaxhighlight>
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System;;
open System.IO;;
 
Line 1,116 ⟶ 1,834:
| 0 -> show_notes()
| _ -> take_note <| String.concat " " args;
0;;</langsyntaxhighlight>
 
Usage:
Line 1,133 ⟶ 1,851:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">#! /usr/bin/env factor
USING: kernel calendar calendar.format io io.encodings.utf8 io.files
sequences command-line namespaces ;
Line 1,145 ⟶ 1,863:
print flush
] with-file-appender
] if-empty</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
class Notes
{
Line 1,175 ⟶ 1,893:
}
}
</syntaxhighlight>
</lang>
 
Sample:
Line 1,195 ⟶ 1,913:
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.
 
<langsyntaxhighlight lang="forth">vocabulary note-words
get-current also note-words definitions
 
Line 1,238 ⟶ 1,956:
open 0 parse dup if add-note
else 2drop dump then close ;
previous</langsyntaxhighlight>
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.
<langsyntaxhighlight lang="forth">\ -- notes.txt
include lib/argopen.4th
include lib/ansfacil.4th
Line 1,268 ⟶ 1,986:
refill drop 0 parse dup if add-note else 2drop dump then ;
 
note</langsyntaxhighlight>
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">
program notes
implicit none
Line 1,301 ⟶ 2,019:
endif
end program notes
</syntaxhighlight>
</lang>
{{out}}<pre>
2022-2-20T18:40:13
Line 1,310 ⟶ 2,028:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">If Len(Command) Then
Open "notes.txt" For Append As #1
Print #1, Date, Time
Line 1,329 ⟶ 2,047:
End If
Close #1
Sleep</langsyntaxhighlight>
 
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">'Note that the 1st item in 'Args' is the file name as on the command line './CLIOnly.gambas'
 
Public Sub Main()
Line 1,355 ⟶ 2,073:
Endif
 
End</langsyntaxhighlight>
Output:
<pre>
Line 1,365 ⟶ 2,083:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,413 ⟶ 2,131:
os.Exit(1)
}
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">def notes = new File('./notes.txt')
if (args) {
notes << "${new Date().format('YYYY-MM-dd HH:mm:ss')}\t${args.join(' ')}\n"
Line 1,422 ⟶ 2,140:
println notes.text
}
</syntaxhighlight>
</lang>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import System.Environment (getArgs)
import System.Time (getClockTime)
 
Line 1,436 ⟶ 2,154:
else
do ct <- getClockTime
appendFile "notes.txt" $ show ct ++ "\n\t" ++ unwords args ++ "\n"</langsyntaxhighlight>
 
{{out}} after a few runs:
Line 1,447 ⟶ 2,165:
 
=={{header|HicEst}}==
<langsyntaxhighlight HicEstlang="hicest">SYSTEM(RUN) ! start this script in RUN-mode
 
CHARACTER notes="Notes.txt", txt*1000
Line 1,466 ⟶ 2,184:
ENDIF
 
ALARM(999) ! quit HicEst immediately</langsyntaxhighlight>
<pre>Thu 2010-09-16 18:42:15
This is line 1
Line 1,475 ⟶ 2,193:
=={{header|Icon}} and {{header|Unicon}}==
 
<syntaxhighlight lang="icon">
<lang Icon>
procedure write_out_notes (filename)
file := open (filename, "rt") | stop ("no notes file yet")
Line 1,496 ⟶ 2,214:
else add_to_notes (notes_file, args)
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,516 ⟶ 2,234:
=={{header|J}}==
'''Solution''':<br>
<syntaxhighlight lang="j">#!/usr/bin/ijconsole
<lang j>require 'files strings'
require 'files strings'
 
notes=: monad define
Line 1,528 ⟶ 2,247:
 
notes 2}.ARGV
exit 0</langsyntaxhighlight>
 
Under OSX, replace <tt>/usr/bin/ijconsole</tt> with a version specific path such at /Applications/j602/bin/jconsole
Create a Shortcut called <tt>Notes</tt> that calls the script above using the Target:<br>
 
Under Windows (where the #! line is irrelevant), create a Shortcut called <tt>Notes</tt> that calls the script above using the Target:<br>
<tt>"c:\program files\j602\bin\jconsole.exe" path\to\script\notes.ijs</tt><br>
and Start in: <tt>.\</tt>
Line 1,551 ⟶ 2,272:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.io.*;
import java.nio.channels.*;
import java.util.Date;
Line 1,571 ⟶ 2,292:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|JScript}}
<langsyntaxhighlight lang="javascript">var notes = 'NOTES.TXT';
 
var args = WScript.Arguments;
Line 1,600 ⟶ 2,321:
f.WriteLine();
f.Close();
}</langsyntaxhighlight>
<pre>> del NOTES.TXT
> cscript /nologo notes.js
Line 1,609 ⟶ 2,330:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Dates
 
const filename = "NOTES.TXT"
Line 1,621 ⟶ 2,342:
end
close(fp)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.2.10
 
import java.io.File
Line 1,643 ⟶ 2,364:
f.appendText(notes)
}
}</langsyntaxhighlight>
 
Sample output:
Line 1,655 ⟶ 2,376:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
 
local(
Line 1,676 ⟶ 2,397:
else
#notesfile -> exists ? stdout(#notesfile -> readstring)
}</langsyntaxhighlight>
 
Called with:
<langsyntaxhighlight Lassolang="lasso">./notes "Rosetta was here" Räksmörgås
./notes First Second Last
./notes
</syntaxhighlight>
</lang>
<pre>2013-11-15 11:43:08
Rosetta was here, Räksmörgås
Line 1,690 ⟶ 2,411:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">filename = "NOTES.TXT"
 
if #arg == 0 then
Line 1,710 ⟶ 2,431:
 
fp:close()
end</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
M2000 Interpreter run M2000 environment, which is a Windows program (written in VB6). So for using console we have to use Kernel32 AttachConsole. When we start M2000.exe with a gsb file, the console of M2000 not opened until we execute a Show command or we use an input statement. So we can run this code without opening M2000 console. There is a tiny lag (observable) when start the environment (can open many times at the same time), there is a stack capacity check, and the M2000.exe make about 30MByte stack (from 1Mbyte the default for VB6).
 
 
How to run this example:
 
Write the code on a UTF-8 text file as notes.gsb
 
Assign gsb files to open with M2000.exe (the M2000 environment)
 
Open the folder where exist notes.gsb in a cmd window and execute it writing notes.gsb to get the notes.bat. Now you can write notes your note here.
 
 
<syntaxhighlight lang="m2000 interpreter">
MODULE GLOBAL interpret {
global filename$="notes.txt"
declare FreeConsole lib "Kernel32.FreeConsole"
declare GetStdHandle lib "Kernel32.GetStdHandle" {long a}
declare AttachConsole lib "Kernel32.AttachConsole" {long a}
declare CloseHandle lib "Kernel32.CloseHandle" {long a}
declare global WriteCons Lib "Kernel32.WriteConsoleW" {long cons, a$, long n, Long p, long u}
long STD_OUTPUT_HANDLE=-11
global retvalue
buffer clear retvalue as long
ret=AttachConsole(-1)
if ret=0 then beep: exit
global m=GetStdHandle(STD_OUTPUT_HANDLE)
if not islet then
try {
open "notes.bat" for output as #f
print #f, {@}+appdir$+{m2000.exe data {%*}: dir %cd%:load notes
}
close #f
}
PrintConsoleLn("")
dos "notes.bat"
else
read cmd$
cmd$=trim$(cmd$)
if cmd$="" then
if exist(filename$) then
open filename$ for wide input exclusive as #f
while not eof(#f)
line input #f, line$
PrintConsoleLn(line$)
end while
close#
end if
else
if exist(filename$) then
try ok {
open filename$ for wide append exclusive as #f
}
else
try ok {
open filename$ for wide output exclusive as #f
}
end if
if ok then
print #f, str$(now+today,"YYYY-MM-DD hh:mm:ss")
print #f, chr$(9);@RemoveSpaces$(cmd$)
close#f
end if
end if
end if
call void closehandle(m)
call void freeconsole()
Sub PrintConsole(a$)
Call Void WriteCons(m, a$, Len(a$), retvalue(0), 0)
End Sub
Sub PrintConsoleLn(a$)
a$+={
}
Call Void WriteCons(m, a$, Len(a$), retvalue(0), 0)
End Sub
Function RemoveSpaces$(a$)
local b$,c$,i, sk
for i=1 to len(a$)
b$=mid$(a$,i,1)
if sk then
c$+=b$
if b$=""""then
sk=false
b$=mid$(a$,i+1,1)
if b$<>"" and b$<>" " then c$+=" "
end if
else.if mid$(a$,i,2)<>" "then
c$+=b$:if b$=""""then sk=true
end if
next
=c$
End Function
}
module interpret1 {
try {interpret}
}
interpret1: end
</syntaxhighlight>
{{out}}
<pre>
>notes this is "a b" a note.
>notes this is another note.
>notes
2022-11-29 19:32:26
this is "a b" a note
2022-11-29 19:32:45
this is another note.
</pre>
 
 
 
=={{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]]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> function notes(varargin)
% NOTES can be used for taking notes
% usage:
Line 1,746 ⟶ 2,579:
fprintf(fid,'\n');
fclose(fid);
end; </langsyntaxhighlight>
 
=={{header|Mercury}}==
<langsyntaxhighlight lang="mercury">:- module notes.
:- interface.
 
Line 1,809 ⟶ 2,642:
notes_filename = "NOTES.TXT".
 
:- end_module notes.</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import os, times, strutils
 
if paramCount() == 0:
Line 1,821 ⟶ 2,654:
f.writeLine getTime()
f.writeLine "\t", commandLineParams().join(" ")
f.close()</langsyntaxhighlight>
Sample format.txt:
<pre>2021-04-21T15:49:00+02:00
Line 1,829 ⟶ 2,662:
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">#! /usr/bin/env ocaml
#load "unix.cma"
 
Line 1,859 ⟶ 2,692:
if Array.length Sys.argv = 1
then dump_notes()
else take_notes()</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">functor
import
Application
Line 1,895 ⟶ 2,728:
end
{Application.exit 0}
end</langsyntaxhighlight>
 
=={{header|Pascal}}==
Free Pascal in Delphi mode or Delphi in console mode.
 
<syntaxhighlight lang="pascal">
<lang Pascal>
{$mode delphi}
PROGRAM notes;
Line 1,939 ⟶ 2,772:
END;
END.
</syntaxhighlight>
</lang>
 
{{out|Program usage and output}}
Line 1,954 ⟶ 2,787:
 
=={{header|Perl}}==
<langsyntaxhighlight Perllang="perl">my $file = 'notes.txt';
if ( @ARGV ) {
open NOTES, '>>', $file or die "Can't append to file $file: $!";
Line 1,962 ⟶ 2,795:
print <NOTES>;
}
close NOTES;</langsyntaxhighlight>
 
{{out}} after a few runs:
Line 1,973 ⟶ 2,806:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
Copy of [[Take_notes_on_the_command_line#Euphoria|Euphoria]]
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<lang Phix>constant cmd = command_line()
<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>
constant filename = "notes.txt"
<span style="color: #000000;">filename</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"notes.txt"</span>
integer fn
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cmd</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">3</span> <span style="color: #008080;">then</span>
object line
<span style="color: #004080;">object</span> <span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span>
if length(cmd)<3 then
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)?</span><span style="color: #000000;">text</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"&lt;empty&gt;"</span><span style="color: #0000FF;">))</span>
fn = open(filename,"r")
<span style="color: #008080;">else</span>
if fn!=-1 then
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a"</span><span style="color: #0000FF;">)</span>
while 1 do
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d-%02d-%02d %d:%02d:%02d\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">())</span>
line = gets(fn)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\t%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cmd</span><span style="color: #0000FF;">[</span><span style="color: #000000;">3</span><span style="color: #0000FF;">..$]))</span>
if atom(line) then exit end if
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
puts(1,line)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while
<!--</syntaxhighlight>-->
close(fn)
end if
else
fn = open(filename,"a") -- if such file doesn't exist it will be created
printf(fn,"%d-%02d-%02d %d:%02d:%02d\n",date())
printf(fn,"\t%s\n",join(cmd[3..$]))
close(fn)
end if</lang>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">
#!/usr/bin/php
<?php
Line 2,007 ⟶ 2,833:
else
@readfile('notes.txt');
</syntaxhighlight>
</lang>
Note that the error suppression operator (@) is considered bad coding practice.
 
Line 2,023 ⟶ 2,849:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(load "@lib/misc.l")
Line 2,029 ⟶ 2,855:
(out "+notes.txt" (prinl (stamp) "^J^I" (glue " " @)))
(and (info "notes.txt") (in "notes.txt" (echo))) )
(bye)</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">NOTES: procedure (text) options (main); /* 8 April 2014 */
declare text character (100) varying;
declare note_file file;
Line 2,068 ⟶ 2,894:
put file (note_file) skip;
put skip list ('The file, NOTES.TXT, has been created');
end NOTES;</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">$notes = "notes.txt"
if (($args).length -eq 0) {
if(Test-Path $notes) {
Line 2,079 ⟶ 2,905:
Get-Date | Add-Content $notes
"`t" + $args -join " " | Add-Content $notes
}</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">#FileName="notes.txt"
Define argc=CountProgramParameters()
If OpenConsole()
Line 2,105 ⟶ 2,931:
EndIf
EndIf
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import sys, datetime, shutil
 
if len(sys.argv) == 1:
try:
with open('"notes.txt'", '"r'") as f:
shutil.copyfileobj(f, sys.stdout)
except IOError:
pass
else:
with open('"notes.txt'", '"a'") as f:
f.write(datetime.datetime.now().isoformat() + '"\n'")
f.write("\t%s\n" % ' '.join(sys.argv[1:]))</langsyntaxhighlight>
 
'''Sample notes.txt file'''
Line 2,130 ⟶ 2,956:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">#!/usr/bin/env Rscript --default-packages=methods
 
args <- commandArgs(trailingOnly=TRUE)
Line 2,141 ⟶ 2,967:
cat(file=conn, date(), "\n\t", paste(args, collapse=" "), "\n", sep="")
}
close(conn)</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#!/usr/bin/env racket
#lang racket
Line 2,160 ⟶ 2,986:
(date->string (current-date) #t)
(string-join notes))))))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
 
<syntaxhighlight lang="raku" perl6line>my $file = 'notes.txt';
 
multi MAIN() {
Line 2,175 ⟶ 3,001:
$fh.say: DateTime.now, "\n\t", @note;
$fh.close;
}</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Notes"
URL: http://rosettacode.org/wiki/Take_notes_on_the_command_line
Line 2,189 ⟶ 3,015:
] [
write/binary/append notes rejoin [now lf tab args lf]
]</langsyntaxhighlight>
 
{{out|Sample session}}
Line 2,204 ⟶ 3,030:
Test line 3
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, <ArgList>: {
= <PrintNotes>;
e.Args = <WriteNote e.Args>;
};
};
 
ArgList {
= <ArgList 1>;
s.N, <Arg s.N>: {
= ;
e.Arg = (e.Arg) <ArgList <+ s.N 1>>;
};
};
 
PrintNotes {
, <ExistFile 'notes.txt'>: {
False = ;
True = <PrintFile 1 'notes.txt'>;
};
};
 
PrintFile {
s.Chan e.File = <Open 'r' s.Chan e.File> <PrintFile (s.Chan)>;
(s.Chan), <Get s.Chan>: {
0 = <Close s.Chan>;
e.Line = <Prout e.Line> <PrintFile (s.Chan)>;
};
};
 
WriteNote {
e.Args, <Time> '\n\t' <Join (' ') e.Args> '\n': e.Note =
<Open 'a' 2 'notes.txt'>
<Put 2 e.Note>
<Close 2>;
};
 
Join {
(e.X) = ;
(e.X) (e.1) = e.1;
(e.X) (e.1) e.2 = e.1 e.X <Join (e.X) e.2>;
};</syntaxhighlight>
{{out}}
<pre>$ ls notes.*
notes.ref notes.rsl
$ refgo notes
$ refgo notes This is a note
$ refgo notes This is another note
$ refgo notes Note that this is a note
$ refgo notes
Mon Apr 8 13:57:34 2024
This is a note
 
Mon Apr 8 13:57:38 2024
This is another note
 
Mon Apr 8 13:57:42 2024
Note that this is a note
 
$ ls notes.*
notes.ref notes.rsl notes.txt
$</pre>
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program implements the "NOTES" command (append text to a file from the C.L.). */
notes = 'notes.txt' /*the fileID of the 'notes' file. */
timestamp=right(date(),11,0) time() date('W') /*create a (current) date & time stamp.*/
Select
nFID = 'NOTES.TXT' /*the fileID of the "notes" file. */
When arg(1)='?' Then Do
Say "'rexx notes text' appends text to file" notes
Say "'rexx notes' displays file" notes
End
When arg()==0 Then Do /*No arguments? Then display the file.*/
Do while lines(notes)>0
Say linein(notes) /* display a line of file --> screen. */
End
End
Otherwise Do
timestamp=right(date(),11,0) time() date('W') /*create current date & time stamp */
If 'f2'x==2 Then tab='05'x /* this is an EBCDIC system. */
Else tab='09'x /* " " " ASCII " */
Call lineout notes,timestamp /*append the timestamp to "notes" file.*/
Call lineout notes,tab||arg(1) /* " " text " " " */
End
End /*stick a fork in it, we're all Done. */</syntaxhighlight>
{{out}}
<pre>
K:\>rexx notes ?
'rexx notes text' appends text to file notes.txt
'rexx notes' displays file notes.txt
 
K:\>rexx notes starting work
 
07 Aug 2023 19:39:41 Monday
if 'f2'x==2 then tab="05"x /*this is an EBCDIC system. */
starting work</pre>
else tab="09"x /* " " " ASCII " */
 
=={{header|RPL}}==
if arg()==0 then do while lines(nFID) /*No arguments? Then display the file.*/
The file is idiomatically named <code>Logbook</code> rather than <code>NOTES.TXT</code>.
say linein(Nfid) /*display a line of file ──► screen. */
« '''IFERR''' Logbook '''THEN''' "" '''END'''
end /*while*/
'''IF''' DEPTH 1 > '''THEN''' "\n" + DATE TIME TSTR else+ do'''END'''
'''WHILE''' DEPTH 1 > '''REPEAT''' "\n" + DEPTH ROLL + '''END'''
call lineout nFID,timestamp /*append the timestamp to "notes" file.*/
DUP 'Logbook' STO
call lineout nFID,tab||arg(1) /* " " text " " " */
1 DISP 7 endFREEZE
» '<span style="color:blue">NOTES</span>' STO
/*stick a fork in it, we're all done. */</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">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</langsyntaxhighlight>
 
=={{header|Rust}}==
This uses version 0.4 of the <code>chrono</code> crate
<langsyntaxhighlight Rustlang="rust">extern crate chrono;
 
use std::fs::OpenOptions;
Line 2,275 ⟶ 3,189:
add_to_notes(&note.join(" ")).expect("failed to write to NOTES.TXT");
}
}</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import java.io.{ FileNotFoundException, FileOutputStream, PrintStream }
import java.time.LocalDateTime
 
Line 2,297 ⟶ 3,211:
}
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
(moved from Racket)
{{works with|Racket}}
<langsyntaxhighlight lang="scheme">#lang racket
(require racket/date)
(define *notes* "NOTES.TXT")
Line 2,321 ⟶ 3,235:
(fprintf fo "~a~n\t~a~n" dt ln)))
#:mode 'text #:exists 'append)
]))</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
$ include "getf.s7i";
$ include "time.s7i";
Line 2,346 ⟶ 3,260:
end if;
end if;
end func;</langsyntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program notes;
if #command_line = 0 then
show_notes;
else
write_note;
end if;
 
show_notes::
if (notefile := open('notes.txt', 'r')) = om then
stop;
end if;
 
loop for line in [getline notefile : until eof(notefile)] do
print(line);
end loop;
 
close(notefile);
 
write_note::
notefile := open('notes.txt', 'a');
note := (+/[' ' + a : a in command_line])(2..);
puta(notefile, date + '\n\t' + note + '\n');
close(notefile);
end program;</syntaxhighlight>
{{out}}
<pre>$ ls notes.*
notes.setl
$ setl notes.setl
$ setl notes.setl This is a note
$ setl notes.setl This is another note
$ setl notes.setl
Mon Apr 8 14:27:07 2024
This is a note
 
Mon Apr 8 14:27:11 2024
This is another note
 
$ ls notes.*
notes.setl notes.txt</pre>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var file = %f'notes.txt'
 
if (ARGV.len > 0) {
Line 2,358 ⟶ 3,313:
var fh = file.open_r
fh && fh.each { .say }
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,372 ⟶ 3,327:
=={{header|SNOBOL4}}==
{{works with|Macro SNOBOL4 in C}}
<langsyntaxhighlight lang="snobol">#! /usr/local/bin/snobol4 -b
a = 2 ;* skip '-b' parameter
notefile = "notes.txt"
Line 2,383 ⟶ 3,338:
notes = date()
notes = char(9) args
end</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
let args = Process.arguments
Line 2,426 ⟶ 3,381:
 
let strData = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
handler?.writeData(strData!)</langsyntaxhighlight>
{{out}}
Example output
Line 2,437 ⟶ 3,392:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl"># Make it easier to change the name of the notes file
set notefile notes.txt
 
Line 2,453 ⟶ 3,408:
close $f
}
}</langsyntaxhighlight>
{{out}} after a few runs:
<pre>
Line 2,463 ⟶ 3,418:
 
=={{header|uBasic/4tH}}==
{{works with|R3R4}}
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,516 ⟶ 3,471:
g@ = g@ - FUNC(_Monthdays (c@-1, f@))
' Print a@, d@, e@, f@
Return (Join (Str(b@), FUNC(_Format (c@, Dup("-"))), FUNC(_Format (e@ - g@, Dup("-")))))
 
_TimeStr ' convert epoch to time string
Param (1)
Return (Join(Str((a@%86400)/3600), FUNC(_Format ((a@%3600)/60, Dup(":"))), FUNC(_Format (a@%60, Dup(":")))))
 
_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>
</lang>
{{out}}
<pre>2022-04-02 14:58:57
Line 2,533 ⟶ 3,488:
Anyways, it seems this task is DONE!
</pre>
 
=={{header|UNIX Shell}}==
Bash version
<langsyntaxhighlight lang="bash">#
NOTES=$HOME/notes.txt
if [[ $# -eq 0 ]] ; then
Line 2,542 ⟶ 3,498:
date >> $NOTES
echo " $*" >> $NOTES
fi</langsyntaxhighlight>
 
"Spoiled Bash kid" version
<langsyntaxhighlight lang="bash">N=~/notes.txt;[[ $# -gt 0 ]] && { date ; echo " $*"; exit 0; } >> $N || [[ -r $N ]] && cat $N</langsyntaxhighlight>
 
 
Portable version
<langsyntaxhighlight lang="bash">NOTES=$HOME/notes.txt
if test "x$*" = "x"
then
Line 2,559 ⟶ 3,515:
date >> $NOTES
echo " $*" >> $NOTES
fi</langsyntaxhighlight>
 
{{omit from|Retro}}
 
=={{header|Visual Basic .NET}}==
<langsyntaxhighlight lang="vbnet">Imports System.IO
 
Module Notes
Line 2,582 ⟶ 3,538:
End Try
End Function
End Module</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 2,589 ⟶ 3,545:
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).
<langsyntaxhighlight ecmascriptlang="wren">import "os" for Process
import "./ioutil" for File, FileUtil
import "./date" for Date
 
var dateFormatIn = "yyyy|-|mm|-|dd|+|hh|:|MM"
Line 2,604 ⟶ 3,560:
var note = "\t" + args[1..-1].join(" ") + "\n"
FileUtil.append("NOTES.TXT", dateTime.format(dateFormatOut) + "\n" + note)
}</langsyntaxhighlight>
 
{{out}}
Line 2,616 ⟶ 3,572:
2021-09-29 16:51
my second note
</pre>
 
=={{header|XPL0}}==
Checks for unlikely array overflows have been omitted for simplicity.
<syntaxhighlight lang="xpl0">include xpllib; \Date and Time routines
int I, NotesSize, Ch, CmdArgSize;
char Notes(1_000_000), CmdArg(1000);
[\Read in notes.txt, if it exists
Trap(false); \disable abort on errors
FSet(FOpen("notes.txt", 0), ^i);
OpenI(3);
if GetErr = 0 then \file exists
[I:= 0;
while GetErr = 0 do \GetErr detects end-of-file
[Notes(I):= ChIn(3);
I:= I+1;
];
NotesSize:= I-2; \remove 2 EOFs
];
\Get command-line argument, if any, from command line
I:= 0;
loop [Ch:= ChIn(8);
if Ch = CR then quit;
CmdArg(I):= Ch;
I:= I+1;
];
CmdArg(I):= 0; \terminate string
if I = 0 then \no args, just display notes.txt
for I:= 0 to NotesSize-1 do ChOut(0, Notes(I))
else \open notes.txt for output and append CmdArg
[FSet(FOpen("notes.txt", 1), ^o);
OpenO(3);
for I:= 0 to NotesSize-1 do ChOut(3, Notes(I));
DateOut(3, GetDosDate); ChOut(3, ^ );
TimeOut(3, GetDosTime); CrLf(3);
ChOut(3, Tab); Text(3, CmdArg); CrLf(3);
Close(3);
];
]</syntaxhighlight>
 
{{out}}
<pre>
18-Apr-2022 1:27:14p
first line
18-Apr-2022 1:27:30p
another line
18-Apr-2022 1:42:02p
final test
</pre>
 
=={{header|zkl}}==
File notes.zkl:
<langsyntaxhighlight lang="zkl">const notesName="NOTES.TXT";
args:=vm.arglist;
if (not args)
Line 2,628 ⟶ 3,632:
f.writeln(Time.Date.ctime(),"\n\t",args.concat(" "));
f.close();
}</langsyntaxhighlight>
{{out}}
<pre>
2,093

edits