Sauvegarde ce qui suit dans un fichier, et lance-le avec `perl ...` dans un terminal.
Si tu fais chmod +x sur le fichier auparavant, tu peux te passer de mettre "perl " devant l'invocation, il faut juste invoquer "./..."]
Peut-être devras-tu enlever les espaces dans "[ 0 ]", j'ai dû les mettre pour que les couleurs du forum ne m'embêtent pas.
#!/usr/bin/perl -W
use strict;
# Trivial program to convert a TI-68k assembly file (.??z) to a TI-BASIC Exec string.
# Copyright (C) 2009 Lionel Debroux.
package main;
my $length;
my $filecontents;
( ($#ARGV == 0) # A single argument...
&& (($ARGV[ 0 ] =~ m#.89z$#) || ($ARGV[ 0 ] =~ m#.9xz$#) || ($ARGV[ 0 ] =~ m#.v2z$#)) # ... which ends with {89z,9xz,v2z} and ...
&& (-f $ARGV[ 0 ]) # ... which is a path representing an actual file.
)
or die "Usage: tifile_to_exe.pl <infile.{89z,9xz,v2z}>\n";
open(INFILE, $ARGV[ 0 ]) or die "Can't open $ARGV[ 0 ]: $!";
read(INFILE, $filecontents, -s INFILE);
close(INFILE);
if ((index ($filecontents, "**TI89**") != 0) && (index ($filecontents, "**TI92P*") != 0)) {
die "$ARGV[ 0 ] doesn't seem to be a file suitable for TI-68k calculators";
}
do {
use bytes;
# Get file size in bytes.
$length = length($filecontents);
print "Input file is $length bytes long (of which 90 header bytes).\n";
if ($length <= 90) { # 86 bytes for the header, 2 size bytes and 2 bytes for the trailing checksum.
die "$ARGV[ 0 ] is too short to be a valid file suitable for TI-68k calculators";
}
$length -= 90;
$filecontents = substr($filecontents, 88, $length);
$length *= 2; # Number of hex digits is twice that of bytes.
print "Exec \"" . unpack ("H[$length]", $filecontents) . "\"\n";
} while (0);
41 lignes, dont 10 lignes blanches. Ce n'est pas en Java, en C ou en C++ qu'on peut faire ça avec une telle compacité (et surtout pas si on se préoccupe de la gestion des erreurs)
