home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / rt11pascal.zip / rtxlod.c < prev   
C/C++ Source or Header  |  1984-05-22  |  2KB  |  156 lines

  1. /*
  2.  * XLOAD 
  3.  * 
  4.  * Create a 'HEX' file from 'SAV' for RT-11 Kermit
  5.  * By Philip Murton - UTCS 
  6.  * (EUNICE Version for VAX/VMS)  
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define LF '\n'
  13. #define CR '\r'
  14. #define TRUE 1
  15. #define FALSE 0
  16.  
  17. #define puteol() fputs("\n",op)
  18. #define RS 036
  19. #define CONTROLX 030
  20. #define BSIZE 64
  21. #define TEXT FALSE
  22. #define BINARY TRUE
  23. #define TEST TRUE
  24.  
  25. FILE *op;            /* output file pointer  */
  26. FILE *ip;            /* input file pointer     */
  27. int mode;             /* mode -- text or binary */
  28.  
  29.  
  30. FILE *fopen();
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.     char *s;
  37.     int fd;
  38.  
  39.     if(argc < 3)
  40.         error("usage: xload <HEX file> <SAV file>");
  41.     mode = BINARY;
  42.     op = NULL;
  43.  
  44.     while(--argc > 0 && (*++argv) [0] == '-')
  45.         for(s = argv[0] + 1; *s != '\0'; s++)
  46.             switch(*s) {
  47.             case 'o':  
  48.                 op = stdout;
  49.                 break;
  50.             default:   
  51.                 error("xload: illegal option");
  52.                 break;
  53.             }
  54.  
  55.     /* VMS Text File for EUNICE */
  56.     if(op == NULL)
  57.     {    
  58.         if((fd = creat(*argv++,0664,"txt")) < 0)
  59.             error("xload: Cannot open output");
  60.         op = fdopen(fd,"w");
  61.         argc--;
  62.     }
  63.  
  64.  
  65.     while(argc-- >0 ) {
  66.  
  67.         if ((ip = fopen(*argv++,"r")) == NULL) 
  68.             error("xload: cannot open input file");
  69.         if(mode == TEXT)
  70.         {
  71.         }
  72.         else
  73.         {
  74.             expand();
  75.             puteof();
  76.         }
  77.  
  78.     }
  79.  
  80. }
  81.  
  82. /*
  83.  * 
  84.  */
  85.  
  86. error(s)
  87. char *s;
  88. {
  89.         fprintf(stderr,"%s\n",s);
  90.         exit(1);
  91.         }
  92.         
  93. /* 
  94.  * E X P A N D  -- for PACKER
  95.  */
  96.  
  97. char hex[] = "0123456789ABCDEF";
  98.  
  99. expand()
  100. {
  101.     char c[2];
  102.     unsigned int t;
  103.     while(fread(c,sizeof(char),2,ip) != 0) 
  104.     {
  105.         t = c[1] & 0xF0;
  106.         t = t >> 4;
  107.         packchar(hex[t]);
  108.         t = c[1] & 0x0F;
  109.         packchar(hex[t]);
  110.  
  111.         t = c[0] & 0xF0;
  112.         t = t >> 4;
  113.         packchar(hex[t]);
  114.         t = c[0] & 0x0F;
  115.         packchar(hex[t]);
  116.     }
  117.     return(TRUE);
  118. }
  119.  
  120. /* 
  121.  * P A C K  
  122.  */
  123.  
  124.  
  125. char buffer[BSIZE + 1];
  126. char *bp = buffer;
  127. char *endbuf = &buffer[BSIZE];
  128.  
  129.  
  130. packchar(c)
  131. char c;
  132. {
  133.     if(bp < endbuf)
  134.         *bp++ = c;
  135.     else
  136.     {
  137.         *bp = '\0';    
  138.         fputs(buffer,op);
  139.         puteol();
  140.         bp = buffer;
  141.         packchar(c);
  142.     }
  143. }
  144.  
  145. puteof()
  146. {
  147.     if(bp > buffer)
  148.     {
  149.     *bp = '\0';    
  150.     fputs(buffer,op);
  151.     puteol();
  152.     }
  153. }
  154.  
  155.  
  156.