/**************************************************************** * Module name : conv.c * * Purpose : Converts any base to all bases * * Created : ??-??-89 * * Last edited : 24-08-89 Version 1.0 * * Copyright : G R Buckeridge * ****************************************************************/ #include stdio.h main(argc,argv) int argc; char *argv[]; { FAST char argv_buffer[MAXARGS * 2 +132]; char ln[20],asc; int dec,hex,oct,h; h=0; cpm_cmd_line (&argc,&argv,argv_buffer); /* for reading command line */ if (argc==1) strcpy(ln,"X"); else if (argc==2) strcpy(ln,argv[1]); else if(argc==3) { ln[0]=*argv[1]; strcpy(ln+1,argv[2]); } else { error(); } while (strlen(ln)>0) { switch(toupper(ln[0])) { case 'D': dec=atoi(ln+1); conv(dec); break; case 'H': sscanf(ln+1," %x",&hex); conv(hex); break; case 'O': sscanf(ln+1," %o",&oct); conv(oct); break; case 'A': if(strlen(ln)>2 && ln[1]==' ') asc=ln[2]; else asc=ln[1]; conv(asc); break; default : help(); break; } printf("Enter Command "); gets(ln); printf("\33A\15"); } } void conv(n) int n; { printf("DEC=%6u\tHEX=%5x\tOCT=%6o\tASC= '",n,n,n); if(n<32) printf("^%c'\n",n+64); else if (n>255) printf("'\n"); else printf("%c'\n",n); } void error() { printf("\nBad Command Line"); exit(0); } void help() { printf("\n\nCONV.COM is a utility which converts an integer from one base to another.\n"); printf("Commands should start with D, H, O, or A, which denotes the original base.\n"); printf("For example. D213, H 7D5C, O 123, A @, are all valid parameters.\n\n"); } #include ?stdio.lib #include ?cpm.lib #include ?gb.lib 3, H 7D5C, O 123, A @, are all valid parameters.\n\n"); } #include ?stdio.lib #include ?cpm.lib #includ