home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
converters
/
bas2txt_1
/
c
/
bas2txt
Wrap
Text File
|
1995-02-25
|
9KB
|
263 lines
/***
Submitted-by: zenith@dcs.warwick.ac.uk
Here's a little C program I knocked up to convert tokenised BASIC programs to
text files. They are already available for Archies, but this one is machine
independent. It can be quite useful for looking at downloaded files on UNIX
or other networked machines. Basically one HUGE switch construct. Hope
somebody finds it useful.
Liam Corner
csubt@csv.warwick.ac.uk
zenith@dcs.warwick.ac.uk
1.01 - added -n switch
***/
/*****************************************************************************/
/* Basic to Text - Liam Corner March 1992 */
/* */
/* Converts a tokenised BBC BASIC V file into a text file */
/* Does not convert GOTO (or GOSUB) line numbers, but nobody uses those */
/* anymore, do they :-) */
/* Please correct any silly mistakes/omissions */
/*****************************************************************************/
#include <stdio.h>
int line_number();
void keyword();
int display_line_numbers=0;
void main (argc,argv)
int argc;
char *argv[];
{
int c;
if (argc>1)
{
if (strcmp(argv[1],"-n"))
{
fprintf(stderr,"usage: %s [-n]\n",argv[0]);
fprintf(stderr,"(-n prints line numbers)\n");
exit(1);
}
display_line_numbers=1;
}
getchar();
while (line_number()) {
do {
c = getchar();
if (c==13)
printf("\n");
else if (c<32)
printf(" %02x ", c);
else if (c>126)
keyword(c);
else
printf("%c", c);
}
while (c != 13);
}
}
int line_number ()
{
int c, d;
if (((c=getchar()) != EOF) && (c != 255)) {
d=getchar();
getchar();
if (display_line_numbers) printf("%5d ", (c<<8)+d);
return (1);
}
else
return (0);
}
void keyword (key)
int key;
{
int key2;
switch (key) {
case 0x7f : printf("OTHERWISE"); break;
case 0x80 : printf("AND"); break;
case 0x81 : printf("DIV"); break;
case 0x82 : printf("EOR"); break;
case 0x83 : printf("MOD"); break;
case 0x84 : printf("OR"); break;
case 0x85 : printf("ERROR"); break;
case 0x86 : printf("LINE"); break;
case 0x87 : printf("OFF"); break;
case 0x88 : printf("STEP"); break;
case 0x89 : printf("SPC"); break;
case 0x8a : printf("TAB("); break;
case 0x8b : printf("ELSE"); break;
case 0x8d : printf("(LINE NUMBER)"); break;
case 0x8c : printf("THEN"); break;
case 0x8e : printf("OPENIN"); break;
case 0x8f : printf("PTR"); break;
case 0x90 : printf("PAGE"); break;
case 0x91 : printf("TIME"); break;
case 0x92 : printf("LOMEM"); break;
case 0x93 : printf("HIMEM"); break;
case 0x94 : printf("ABS"); break;
case 0x95 : printf("ACS"); break;
case 0x96 : printf("ADVAL"); break;
case 0x97 : printf("ASC"); break;
case 0x98 : printf("ASN"); break;
case 0x99 : printf("ATN"); break;
case 0x9a : printf("BGET"); break;
case 0x9b : printf("COS"); break;
case 0x9c : printf("COUNT"); break;
case 0x9d : printf("DEG"); break;
case 0x9e : printf("ERL"); break;
case 0x9f : printf("ERR"); break;
case 0xa0 : printf("EVAL"); break;
case 0xa1 : printf("EXP"); break;
case 0xa2 : printf("EXT"); break;
case 0xa3 : printf("FALSE"); break;
case 0xa4 : printf("FN"); break;
case 0xa5 : printf("GET"); break;
case 0xa6 : printf("INKEY"); break;
case 0xa7 : printf("INSTR("); break;
case 0xa8 : printf("INT"); break;
case 0xa9 : printf("LEN"); break;
case 0xaa : printf("LN"); break;
case 0xab : printf("LOG"); break;
case 0xac : printf("NOT"); break;
case 0xad : printf("OPENUP"); break;
case 0xae : printf("OPENOUT"); break;
case 0xaf : printf("PI"); break;
case 0xb0 : printf("POINT("); break;
case 0xb1 : printf("POS"); break;
case 0xb2 : printf("RAD"); break;
case 0xb3 : printf("RND"); break;
case 0xb4 : printf("SGN"); break;
case 0xb5 : printf("SIN"); break;
case 0xb6 : printf("SQR"); break;
case 0xb7 : printf("TAN"); break;
case 0xb8 : printf("TO"); break;
case 0xb9 : printf("TRUE"); break;
case 0xba : printf("USR"); break;
case 0xbb : printf("VAL"); break;
case 0xbc : printf("VPOS"); break;
case 0xbd : printf("CHR$"); break;
case 0xbe : printf("GET$"); break;
case 0xbf : printf("INKEY$"); break;
case 0xc0 : printf("LEFT$("); break;
case 0xc1 : printf("MID$("); break;
case 0xc2 : printf("RIGHT$("); break;
case 0xc3 : printf("STR$"); break;
case 0xc4 : printf("STRING$("); break;
case 0xc5 : printf("EOF"); break;
case 0xc6 : switch (key2=getchar()) {
case 0x8e : printf("SUM"); break;
case 0x8f : printf("BEAT"); break;
default : printf("*** AUTO %02x ***", key2);
}; break;
case 0xc7 : switch (key2=getchar()) {
case 0x8e : printf("APPEND"); break;
case 0x8f : printf("AUTO"); break;
case 0x90 : printf("DELETE"); break;
case 0x91 : printf("EDIT"); break;
case 0x92 : printf("HELP"); break;
case 0x93 : printf("LIST"); break;
case 0x94 : printf("LOAD"); break;
case 0x95 : printf("LVAR"); break;
case 0x96 : printf("NEW"); break;
case 0x97 : printf("OLD"); break;
case 0x98 : printf("RENUMBER"); break;
case 0x99 : printf("SAVE"); break;
case 0x9a : printf("TWIN"); break;
case 0x9b : printf("TWINO"); break;
default : printf("*** DELETE %02x ***", key2);
}; break;
case 0xc8 : switch (key2=getchar()) {
case 0x8e : printf("CASE"); break;
case 0x8f : printf("CIRCLE"); break;
case 0x90 : printf("FILL"); break;
case 0x91 : printf("ORIGIN"); break;
case 0x92 : printf("POINT"); break;
case 0x93 : printf("RECTANGLE"); break;
case 0x94 : printf("SWAP"); break;
case 0x95 : printf("WHILE"); break;
case 0x96 : printf("WAIT"); break;
case 0x97 : printf("MOUSE"); break;
case 0x98 : printf("QUIT"); break;
case 0x99 : printf("SYS"); break;
case 0x9a : printf("INSTALL"); break;
case 0x9b : printf("LIBRARY"); break;
case 0x9c : printf("TINT"); break;
case 0x9d : printf("ELLIPSE"); break;
case 0x9e : printf("BEATS"); break;
case 0x9f : printf("TEMPO"); break;
case 0xa0 : printf("VOICES"); break;
case 0xa1 : printf("VOICE"); break;
case 0xa2 : printf("STEREO"); break;
case 0xa3 : printf("OVERLAY"); break;
default : printf (" *** EXTRA %02x *** ", key2);
}; break;
case 0xc9 : printf("WHEN"); break;
case 0xca : printf("OF"); break;
case 0xcb : printf("ENDCASE"); break;
case 0xcc : printf("ELSE"); break;
case 0xcd : printf("ENDIF"); break;
case 0xce : printf("ENDWHILE"); break;
case 0xcf : printf("PTR"); break;
case 0xd0 : printf("PAGE"); break;
case 0xd1 : printf("TIME"); break;
case 0xd2 : printf("LOMEM"); break;
case 0xd3 : printf("HIMEM"); break;
case 0xd4 : printf("SOUND"); break;
case 0xd5 : printf("BPUT"); break;
case 0xd6 : printf("CALL"); break;
case 0xd7 : printf("CHAIN"); break;
case 0xd8 : printf("CLEAR"); break;
case 0xd9 : printf("CLOSE"); break;
case 0xda : printf("CLG"); break;
case 0xdb : printf("CLS"); break;
case 0xdc : printf("DATA"); break;
case 0xdd : printf("DEF"); break;
case 0xde : printf("DIM"); break;
case 0xdf : printf("DRAW"); break;
case 0xe0 : printf("END"); break;
case 0xe1 : printf("ENDPROC"); break;
case 0xe2 : printf("ENVELOPE"); break;
case 0xe3 : printf("FOR"); break;
case 0xe4 : printf("GOSUB"); break;
case 0xe5 : printf("GOTO"); break;
case 0xe6 : printf("GCOL"); break;
case 0xe7 : printf("IF"); break;
case 0xe8 : printf("INPUT"); break;
case 0xe9 : printf("LET"); break;
case 0xea : printf("LOCAL"); break;
case 0xeb : printf("MODE"); break;
case 0xec : printf("MOVE"); break;
case 0xed : printf("NEXT"); break;
case 0xee : printf("ON"); break;
case 0xef : printf("VDU"); break;
case 0xf0 : printf("PLOT"); break;
case 0xf1 : printf("PRINT"); break;
case 0xf2 : printf("PROC"); break;
case 0xf3 : printf("READ"); break;
case 0xf4 : printf("REM"); break;
case 0xf5 : printf("REPEAT"); break;
case 0xf6 : printf("REPORT"); break;
case 0xf7 : printf("RESTORE"); break;
case 0xf8 : printf("RETURN"); break;
case 0xf9 : printf("RUN"); break;
case 0xfa : printf("STOP"); break;
case 0xfb : printf("COLOUR"); break;
case 0xfc : printf("TRACE"); break;
case 0xfd : printf("UNTIL"); break;
case 0xfe : printf("WIDTH"); break;
case 0xff : printf("OSCLI"); break;
default : printf (" *** %02x *** ", key);
}
}