home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / amiga / amigati85prog.lha / src / hex-bin.c next >
Encoding:
C/C++ Source or Header  |  1997-06-14  |  1.1 KB  |  59 lines

  1. /* 
  2.  * Hex-bin.c - converts intel hex records to binary files 
  3.  * I found this on the net somewhere with no notices and assume it is 
  4.  * public domain.  If not please let me know.
  5.  *
  6.  * I improved it by adding the ch-toupper(ch) as otherwise it doesn't 
  7.  * work if your assembler generates hex records with lower case letters
  8.  * (mine does)
  9.  */
  10.  
  11. #include <stdio.h>
  12.  
  13. int aton(unsigned char);
  14. main()
  15. {
  16.   unsigned char fnami[14],fnamo[14],ch,ch1,ch2,a1,a2,a3,a4;
  17.   int count=0,u,t;
  18.   
  19.   while(1)
  20.     {
  21.       while(fgetc(stdin)!=':');
  22.       if((t=16*aton(fgetc(stdin))+aton(fgetc(stdin)))==0)
  23.     {
  24.       fclose(stdin);
  25.       fclose(stdout);
  26.       exit(0);
  27.     }
  28.       u=16*16*16*aton(fgetc(stdin))+16*16*aton(fgetc(stdin))+16*aton(fgetc(stdin))+aton(fgetc(stdin));
  29.       fgetc(stdin);
  30.       fgetc(stdin);
  31.       while(u>count)
  32.         {
  33.       fputc(0,stdout);
  34.       count++;
  35.         }
  36.       while(t>0)
  37.     {
  38.       char ch;
  39.       ch=16*aton(fgetc(stdin))+aton(fgetc(stdin));
  40.       fputc(ch,stdout);
  41.       t--;
  42.       count++;
  43.         }
  44.     }
  45.   
  46. }
  47.  
  48. int aton(ch)
  49.      unsigned char ch;
  50. {
  51.   int n;
  52.   ch=toupper(ch);
  53.   if(ch<0x3A)n=ch-0x30;
  54.   else n=ch-0x37;
  55.   return n;
  56. }
  57.  
  58.  
  59.