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