Create a file on magnetic tape: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
No edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 2 users not shown)
Line 21:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Save(CHAR ARRAY text)
BYTE dev=[1]
 
Line 58:
PrintE("Rewind the tape and press any key to load previously saved file from tape.")
Load()
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file_on_magnetic_tape.png Screenshot from Atari 8-bit computer]
Line 74:
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang ApplesoftBasic="applesoftbasic">SAVE</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">write "TAPE.FILE" {
This code
should be able to write
a file
to magnetic tape
}</langsyntaxhighlight>
 
=={{header|C}}==
The program is self explanatory. :)
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
 
Line 108:
}
 
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
 
Line 128:
fb.close();
return 0;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(spit "/dev/tape" "Hello, World!")</langsyntaxhighlight>
 
=={{header|COBOL}}==
 
{{works with|OpenCOBOLCOBOL 2002}}
 
<langsyntaxhighlight COBOLlang="cobolfree"> >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. MAKE-TAPE-FILE.
Line 145:
FILE-CONTROL.
SELECT TAPE-FILE
ASSIGN TO "./TAPE.FILE"
ORGANIZATION IS LINE SEQUENTIAL.
ACCESS MODE IS SEQUENTIAL.
 
DATA DIVISION.
FILE SECTION.
FD TAPE-FILE RECORD CONTAINS 51 CHARACTERS.
01 TAPE-FILE-RECORD PICPICTURE IS X(51).
 
PROCEDURE DIVISION.
Line 158 ⟶ 159:
FROM "COBOL treats tape files and text files identically."
END-WRITE
STOPCLOSE RUN.</lang>TAPE-FILE
STOP RUN.
 
END PROGRAM MAKE-TAPE-FILE.</syntaxhighlight>
 
=={{header|Crystal}}==
{{trans|D}}
<langsyntaxhighlight lang="ruby">filename = {% if flag?(:win32) %}
"TAPE.FILE"
{% else %}
"/dev/tape"
{% end %}
File.write filename, "howdy, planet!"</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight Dlang="d">import std.stdio;
 
void main() {
Line 179 ⟶ 183:
}
f.writeln("Hello World!");
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
{{Trans|D}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Create_a_file_on_magnetic_tape;
 
Line 204 ⟶ 208:
close(f);
end.
</syntaxhighlight>
</lang>
 
=={{header|F#}}==
<langsyntaxhighlight lang="fsharp">
open System
open System.IO
Line 217 ⟶ 221:
| PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows | PlatformID.WinCE -> File.WriteAllText("TAPE.FILE", msg)
| _ -> File.WriteAllText("/dev/tape", msg)
</syntaxhighlight>
</lang>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io.encodings.ascii io.files kernel system ;
 
"Hello from Rosetta Code!"
os windows? "tape.file" "/dev/tape" ?
ascii set-file-contents</langsyntaxhighlight>
 
=={{header|Fortran}}==
Line 237 ⟶ 241:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Dim As Integer numarch = Freefile
Open "tape.file" For Output As #numarch
Print #numarch, "Soy un archivo de cinta ahora, o espero serlo pronto."
Close #numarch</langsyntaxhighlight>
 
=={{header|Go}}==
Line 249 ⟶ 253:
The tar archive will contain a single file, called <tt>TAPE.FILE</tt> by default,
with the contents of the command line <tt>-data</tt> option.
<langsyntaxhighlight lang="go">package main
 
import (
Line 301 ⟶ 305:
log.Fatal("writing data:", err)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 309 ⟶ 313:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Line 324 ⟶ 328:
}
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="haskell">module Main (main) where
 
main :: IO ()
main = writeFile "/dev/tape" "Hello from Rosetta Code!"</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
 
This solution mimics the solution used in many other languages here and works in both Icon and Unicon.
<langsyntaxhighlight lang="unicon">procedure main()
write(open("/dev/tape","w"),"Hi")
end</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 OPEN #1:"Tape1:README.TXT" ACCESS OUTPUT
110 PRINT #1:"I am a tape file now, or hope to be soon."
120 CLOSE #1</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Line 363 ⟶ 367:
}
}
}</langsyntaxhighlight>
 
=={{header|JCL}}==
<langsyntaxhighlight JCLlang="jcl">// EXEC PGM=IEBGENER
//* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE"
//* may vary depending on site-specific esoteric name assignment
Line 374 ⟶ 378:
//SYSUT1 DD *
DATA TO BE WRITTEN TO TAPE
/* </langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
open("/dev/tape", "w") do f
write(f, "Hello tape!")
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Scala}}
<langsyntaxhighlight lang="scala">// version 1.1.0 (Linux)
 
import java.io.FileWriter
Line 393 ⟶ 397:
lp0.write("Hello, world!")
lp0.close()
}</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">require "lfs"
 
local out
Line 406 ⟶ 410:
file = io.open(out, 'w')
file:write('Hello world')
io.close(file)</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">var t = open("/dev/tape", fmWrite)
t.writeln "Hi Tape!"
t.close</langsyntaxhighlight>
 
=={{header|Phix}}==
<langsyntaxhighlight Phixlang="phix">include builtins/write_file.e
constant filepath = iff(platform()=WINDOWS?"tape.file":"/dev/tape"),
write_file(file_path,"Hello world!")</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(out "/dev/tape"
(prin "Hello World!") )</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">>>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n')
...
>>> </langsyntaxhighlight>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
(with-output-to-file "/dev/tape" #:exists 'append
(λ() (displayln "I am a cheap imitation of the Perl code for a boring problem")))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my $tape = open "/dev/tape", :w or die "Can't open tape: $!";
$tape.say: "I am a tape file now, or hope to be soon.";
$tape.close;</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 446 ⟶ 450:
<br><br>VM/CMS would use a &nbsp; '''CP ATTACH''' &nbsp; command, coupled with a &nbsp; '''CMS FILEDEF''' &nbsp; command which associates a
<br>DSNAME &nbsp; (dataset name) &nbsp; that will be written to on the attached (and mounted) magnetic tape device.
<langsyntaxhighlight lang="rexx">/*REXX pgm demonstrates writing records to an attached magnetic tape.*/
dsName = 'TAPE.FILE' /*dsName of "file" being written.*/
 
Line 452 ⟶ 456:
call lineout dsName, 'this is record' j || "."
end /*j*/
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Create a file on magnetic tape
 
Line 463 ⟶ 467:
fwrite(fp, str)
fclose(fp)
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
{{trans|C}}
<langsyntaxhighlight lang="ruby">File.open("tape.file", "w") do |fh|
fh.syswrite("This code should be able to write a file to magnetic tape.\n")
end</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight Rustlang="rust">use std::io::Write;
use std::fs::File;
 
fn main() -> std::io::Result<()> {
File::open("/dev/tape")?.write_all(b"Hello from Rosetta Code!")
}</langsyntaxhighlight>
 
=={{header|Scala}}==
===[[Unix]]===
Assuming device is attached to "tape"
<langsyntaxhighlight Scalalang="scala">object LinePrinter extends App {
import java.io.{ FileWriter, IOException }
{
Line 489 ⟶ 493:
lp0.close()
}
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
 
<langsyntaxhighlight Seed7lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 509 ⟶ 513:
writeln(" ***** Cannot open tape file.");
end if;
end func;</langsyntaxhighlight>
 
=={{header|Tcl}}==
Tcl does not have built-in special support for tape devices, so it relies on the OS to handle most of the details for it. Assuming a relatively modern Unix:
{{trans|UNIX Shell}}
<langsyntaxhighlight lang="tcl">cd /tmp
 
# Create the file
Line 526 ⟶ 530:
fcopy $fin $fout
close $fin
close $fout</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
STATUS = CREATE ("tape.file",tape-o,-std-)
PRINT STATUS</langsyntaxhighlight>
{{Out}}
<pre>
Line 538 ⟶ 542:
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">#!/bin/sh
cd # Make our home directory current
echo "Hello World!" > hello.jnk # Create a junk file
# tape rewind # Uncomment this to rewind the tape
tar c hello.jnk # Traditional archivers use magnetic tape by default
# tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">import "os" for Platform
import "io" for File
 
Line 552 ⟶ 556:
File.create(fileName) { |file|
file.writeBytes("Hello World!\n")
}</langsyntaxhighlight>
 
=={{header|ZX Spectrum Basic}}==
Line 559 ⟶ 563:
We can use any start address, depending on where we want the data to come from.
Here we dump the contents of the screen:
<langsyntaxhighlight lang="zxbasic">SAVE "TAPEFILE" CODE 16384,6912</langsyntaxhighlight>
9,476

edits