James H. Cloos: >->ASC on other computers?
In article <1990Nov19.215615.3165@sol.cs.wmich.edu> dodgson@sol.cs.wmich.edu (Ha
rry Dodgson) writes:
>Does anyone know of a program that I could run under MSDOS or Un*x that
>would let me take some of these binaries that are available and convert
>them to the ->ASC format? I do not yet have the transfer cable and
>this seemed like a way to move some of the smaller binaries like usag
>into my 48.
>
>Kip DeGraaf
Well, I'll take this one. The following is just a hack, but a more
complete version will be included in my rpl compiler distribution.
This only goes from binary to ASC format, but the reverse is trivial.
To compile, "% cc -o asc asc.c" will do. (Where % is the shell
prompt.)
Some small changes may be needed in the MSDOS & Mac worlds, but not
too many.
Sorry about lack of cooents, but as I said, it is jsut a quick hack.
(With all the trouble the rpl compiler is giving me just now, I had to
prove to myself that I still can write working code :-).
=====================CUT HERE===================
#! /bin/sh
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# asc.c
echo x - asc.c
sed -e 's/^X//' > "asc.c" << '//E*O*F asc.c//'
X/* The crc routine is from _KERMIT_-_A_File_Transfer_Protocol_ by *
X * Frank da Cruz, Digital Press, 1987. P. 257. *
X * The rest is public domain; -JimC. */
X#include <stdio.h>
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X FILE *infile, *outfile;
X int count=0, c=0, hi=0, low=0;
X unsigned short value=0, dofx=0;
X
X argc--, argv++;
X if (argc > 0) {
X infile = fopen(*argv, "r");
X argc--, argv++;
X if (argc > 0)
X outfile = fopen(*argv, "w");
X else
X outfile = stdout;
X }
X else infile = stdin;
X
X for (count=8; count>0; count--)
X c=getc(infile);
X
X fprintf(outfile,"%%HP: T(3)A(R)F(.);\n");
X
X while( (c=getc(infile)) != EOF ) {
X value = c;
X count +=1;
X
X dofx = (dofx >> 4) ^ (((value ^ dofx) & 0xf) * 0x1081);
X dofx = (dofx >> 4) ^ ((((value >> 4) ^ dofx) & 0xf) * 0x1081);
X
X fprintf(outfile,"%2.2X",c);
X
X if (! (count % 32))
X fprintf(outfile,"\n");
X }
X dofx &= 0xffff;
X
X for (count = 1; count < 4; count++) {
X fprintf(outfile,"%1.1X",dofx & 0xf);
X dofx >>= 4;
X }
X fprintf(outfile,"\n");
X}
X
X/* @(#)James H. Cloos, Jr. */
//E*O*F asc.c//
echo Possible errors detected by \'wc\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp <<\!!!
51 159 1133 asc.c
!!!
wc asc.c | sed 's=[^ ]*/==' | diff -b $temp -
exit 0
===========================CUT HERE,TOO===============================
-JimC
--
James H. Cloos, Jr. Phone: +1 716 673-1250
cloos@ACSU.Buffalo.EDU Snail: PersonalZipCode: 14048-0772, USA
cloos@ub.UUCP Quote: <>
James H. Cloos: >>->ASC on other computers?
My appologies. I made a rather inane mistake in the asc.c file I
posted. To fix it, make the following two changes:
change the statement fprintf(outfile,"%%HP: T(3)A(R)F(.);\n");
to fprintf(outfile,"%%%%HP: T(3)A(R)F(.);\n\"");
and change the statement fprintf(outfile,"\n");
to fprintf(outfile,"\"\n"0;
These 2 changes will make it work correctly. Sorry for the
inconvienience.
-JimC
--
James H. Cloos, Jr. Phone: +1 716 673-1250
cloos@ACSU.Buffalo.EDU Snail: PersonalZipCode: 14048-0772, USA
cloos@ub.UUCP Quote: <>
James H. Cloos: >>->ASC on other computers?
Ok, here is the final version of the hack asc. Use it as you wish.
-JimC
--
James H. Cloos, Jr. Phone: +1 716 673-1250
cloos@ACSU.Buffalo.EDU Snail: PersonalZipCode: 14048-0772, USA
cloos@ub.UUCP Quote: <>
=============================CUT HERE==============================
#! /bin/sh
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# asc.c
echo x - asc.c
sed -e 's/^X//' > "asc.c" << '//E*O*F asc.c//'
X/* The crc routine is from _KERMIT_-_A_File_Transfer_Protocol_ by *
X * Frank da Cruz, Digital Press, 1987. P. 257. *
X * The rest is public domain; -JimC. *
X * This is the final version; the 3rd to get posted. */
X#include <stdio.h>
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X FILE *infile, *outfile;
X int count=0, c=0, hi=0, low=0;
X unsigned short value=0, dofx=0;
X
X argc--, argv++;
X if (argc > 0)
X infile = fopen(*argv, "r");
X else
X infile = stdin;
X argc--, argv++;
X if (argc > 0)
X outfile = fopen(*argv, "w");
X else
X outfile = stdout;
X
X for (count=8; count>0; count--)
X c=getc(infile);
X
X fprintf(outfile,"%%%%HP: T(3)A(R)F(.);\n\"");
X
X while( (c=getc(infile)) != EOF ) {
X value = c;
X count +=1;
X
X dofx = (dofx >> 4) ^ (((value ^ dofx) & 0xf) * 0x1081);
X dofx = (dofx >> 4) ^ ((((value >> 4) ^ dofx) & 0xf) * 0x1081);
X
X fprintf(outfile,"%2.2X",c);
X
X if (! (count % 32))
X fprintf(outfile,"\n");
X }
X dofx &= 0xffff;
X
X for (count = 1; count < 4; count++) {
X fprintf(outfile,"%1.1X",dofx & 0xf);
X dofx >>= 4;
X }
X fprintf(outfile,"\"\n");
X}
X
X/* @(#)James H. Cloos, Jr. */
//E*O*F asc.c//
echo Possible errors detected by \'wc\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp <<\!!!
52 169 1196 asc.c
!!!
wc asc.c | sed 's=[^ ]*/==' | diff -b $temp -
exit 0