WeixiangYan/CodeTransOcean huggingface dataset:
Task: Take notes on the command line


C++: #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();
		}
	}
}









Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line

C: #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);

		
		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;
}










Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line





Java: 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();
        }
    }
}






Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line







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:]))




Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line








VB: 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



Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line






PHP: #!/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');





Fortran: program notes
implicit none
integer                      :: i, length, iargs, lun, ios
integer,dimension(8)         :: values
character(len=:),allocatable :: arg
character(len=256)           :: line
character(len=1),parameter   :: tab=char(9)
   iargs = command_argument_count()
   open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
   if(iargs.eq.0)then
      rewind(lun)
      do
         read(lun,'(a)',iostat=ios)line
         if(ios.ne.0)exit
         write(*,'(a)')trim(line)
      enddo
   else
      call date_and_time(VALUES=values)
      write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
      write(lun,'(a)',advance='no')tab
      do i=1,iargs
         call get_command_argument(number=i,length=length)
         arg=repeat(' ',length)
         call get_command_argument(i, arg)
         write(lun,'(a,1x)',advance='no')arg
      enddo
      write(lun,*)
   endif
end program notes
Task: Take notes on the command line

C: #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);

		
		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;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. NOTES.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OPTIONAL notes ASSIGN TO "NOTES.TXT"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS note-status.

       DATA DIVISION.
       FILE SECTION.
       FD  notes.
       01  note-record       PIC X(256).

       LOCAL-STORAGE SECTION.
       01  note-status       PIC 99.
           88  notes-ok      VALUE 0 THRU 9.

       01  date-now.
           03  current-year  PIC 9(4).
           03  current-month PIC 99.
           03  current-day   PIC 99.

       01  time-now.
           03  current-hour  PIC 99.
           03  current-min   PIC 99.
           03  current-sec   PIC 99.

       01  args              PIC X(256).

       PROCEDURE DIVISION.
       DECLARATIVES.
       note-error SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON notes.

           DISPLAY "Error using NOTES.TXT. Error code: " note-status
           .
       END DECLARATIVES.

       main.
           ACCEPT args FROM COMMAND-LINE

*          
           IF args = SPACES
               OPEN INPUT notes

               PERFORM FOREVER
*                  
*                  
                   READ notes 
                       AT END
                           EXIT PERFORM

                       NOT AT END
                           DISPLAY FUNCTION TRIM(note-record)
                   END-READ
               END-PERFORM
           ELSE
               OPEN EXTEND notes

*              
               ACCEPT date-now FROM DATE YYYYMMDD
               ACCEPT time-now FROM TIME
               STRING current-year "-" current-month "-" current-day
                   " " current-hour ":" current-min ":" current-sec
                   INTO note-record
               WRITE note-record
               
*              
               STRING X"09", args INTO note-record
               WRITE note-record
           END-IF

           CLOSE notes

           GOBACK
           .
Task: Take notes on the command line



C#: using System;
using System.IO;
using System.Text;

namespace RosettaCode
{
  internal class Program
  {
    private const string FileName = "NOTES.TXT";

    private static void Main(string[] args)
    {
      if (args.Length==0)
      {
        string txt = File.ReadAllText(FileName);
        Console.WriteLine(txt);
      }
      else
      {
        var sb = new StringBuilder();
        sb.Append(DateTime.Now).Append("\n\t");
        foreach (string s in args)
          sb.Append(s).Append(" ");
        sb.Append("\n");

        if (File.Exists(FileName))
          File.AppendAllText(FileName, sb.ToString());
        else
          File.WriteAllText(FileName, sb.ToString());
      }
    }
  }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. NOTES.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OPTIONAL notes ASSIGN TO "NOTES.TXT"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS note-status.

       DATA DIVISION.
       FILE SECTION.
       FD  notes.
       01  note-record       PIC X(256).

       LOCAL-STORAGE SECTION.
       01  note-status       PIC 99.
           88  notes-ok      VALUE 0 THRU 9.

       01  date-now.
           03  current-year  PIC 9(4).
           03  current-month PIC 99.
           03  current-day   PIC 99.

       01  time-now.
           03  current-hour  PIC 99.
           03  current-min   PIC 99.
           03  current-sec   PIC 99.

       01  args              PIC X(256).

       PROCEDURE DIVISION.
       DECLARATIVES.
       note-error SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON notes.

           DISPLAY "Error using NOTES.TXT. Error code: " note-status
           .
       END DECLARATIVES.

       main.
           ACCEPT args FROM COMMAND-LINE

*          
           IF args = SPACES
               OPEN INPUT notes

               PERFORM FOREVER
*                  
*                  
                   READ notes 
                       AT END
                           EXIT PERFORM

                       NOT AT END
                           DISPLAY FUNCTION TRIM(note-record)
                   END-READ
               END-PERFORM
           ELSE
               OPEN EXTEND notes

*              
               ACCEPT date-now FROM DATE YYYYMMDD
               ACCEPT time-now FROM TIME
               STRING current-year "-" current-month "-" current-day
                   " " current-hour ":" current-min ":" current-sec
                   INTO note-record
               WRITE note-record
               
*              
               STRING X"09", args INTO note-record
               WRITE note-record
           END-IF

           CLOSE notes

           GOBACK
           .
Task: Take notes on the command line


C++: #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();
		}
	}
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. NOTES.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OPTIONAL notes ASSIGN TO "NOTES.TXT"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS note-status.

       DATA DIVISION.
       FILE SECTION.
       FD  notes.
       01  note-record       PIC X(256).

       LOCAL-STORAGE SECTION.
       01  note-status       PIC 99.
           88  notes-ok      VALUE 0 THRU 9.

       01  date-now.
           03  current-year  PIC 9(4).
           03  current-month PIC 99.
           03  current-day   PIC 99.

       01  time-now.
           03  current-hour  PIC 99.
           03  current-min   PIC 99.
           03  current-sec   PIC 99.

       01  args              PIC X(256).

       PROCEDURE DIVISION.
       DECLARATIVES.
       note-error SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON notes.

           DISPLAY "Error using NOTES.TXT. Error code: " note-status
           .
       END DECLARATIVES.

       main.
           ACCEPT args FROM COMMAND-LINE

*          
           IF args = SPACES
               OPEN INPUT notes

               PERFORM FOREVER
*                  
*                  
                   READ notes 
                       AT END
                           EXIT PERFORM

                       NOT AT END
                           DISPLAY FUNCTION TRIM(note-record)
                   END-READ
               END-PERFORM
           ELSE
               OPEN EXTEND notes

*              
               ACCEPT date-now FROM DATE YYYYMMDD
               ACCEPT time-now FROM TIME
               STRING current-year "-" current-month "-" current-day
                   " " current-hour ":" current-min ":" current-sec
                   INTO note-record
               WRITE note-record
               
*              
               STRING X"09", args INTO note-record
               WRITE note-record
           END-IF

           CLOSE notes

           GOBACK
           .
Task: Take notes on the command line





Java: 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();
        }
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. NOTES.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OPTIONAL notes ASSIGN TO "NOTES.TXT"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS note-status.

       DATA DIVISION.
       FILE SECTION.
       FD  notes.
       01  note-record       PIC X(256).

       LOCAL-STORAGE SECTION.
       01  note-status       PIC 99.
           88  notes-ok      VALUE 0 THRU 9.

       01  date-now.
           03  current-year  PIC 9(4).
           03  current-month PIC 99.
           03  current-day   PIC 99.

       01  time-now.
           03  current-hour  PIC 99.
           03  current-min   PIC 99.
           03  current-sec   PIC 99.

       01  args              PIC X(256).

       PROCEDURE DIVISION.
       DECLARATIVES.
       note-error SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON notes.

           DISPLAY "Error using NOTES.TXT. Error code: " note-status
           .
       END DECLARATIVES.

       main.
           ACCEPT args FROM COMMAND-LINE

*          
           IF args = SPACES
               OPEN INPUT notes

               PERFORM FOREVER
*                  
*                  
                   READ notes 
                       AT END
                           EXIT PERFORM

                       NOT AT END
                           DISPLAY FUNCTION TRIM(note-record)
                   END-READ
               END-PERFORM
           ELSE
               OPEN EXTEND notes

*              
               ACCEPT date-now FROM DATE YYYYMMDD
               ACCEPT time-now FROM TIME
               STRING current-year "-" current-month "-" current-day
                   " " current-hour ":" current-min ":" current-sec
                   INTO note-record
               WRITE note-record
               
*              
               STRING X"09", args INTO note-record
               WRITE note-record
           END-IF

           CLOSE notes

           GOBACK
           .
Task: Take notes on the command line







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:]))



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. NOTES.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OPTIONAL notes ASSIGN TO "NOTES.TXT"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS note-status.

       DATA DIVISION.
       FILE SECTION.
       FD  notes.
       01  note-record       PIC X(256).

       LOCAL-STORAGE SECTION.
       01  note-status       PIC 99.
           88  notes-ok      VALUE 0 THRU 9.

       01  date-now.
           03  current-year  PIC 9(4).
           03  current-month PIC 99.
           03  current-day   PIC 99.

       01  time-now.
           03  current-hour  PIC 99.
           03  current-min   PIC 99.
           03  current-sec   PIC 99.

       01  args              PIC X(256).

       PROCEDURE DIVISION.
       DECLARATIVES.
       note-error SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON notes.

           DISPLAY "Error using NOTES.TXT. Error code: " note-status
           .
       END DECLARATIVES.

       main.
           ACCEPT args FROM COMMAND-LINE

*          
           IF args = SPACES
               OPEN INPUT notes

               PERFORM FOREVER
*                  
*                  
                   READ notes 
                       AT END
                           EXIT PERFORM

                       NOT AT END
                           DISPLAY FUNCTION TRIM(note-record)
                   END-READ
               END-PERFORM
           ELSE
               OPEN EXTEND notes

*              
               ACCEPT date-now FROM DATE YYYYMMDD
               ACCEPT time-now FROM TIME
               STRING current-year "-" current-month "-" current-day
                   " " current-hour ":" current-min ":" current-sec
                   INTO note-record
               WRITE note-record
               
*              
               STRING X"09", args INTO note-record
               WRITE note-record
           END-IF

           CLOSE notes

           GOBACK
           .