home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / beav.1.40.lzh / BEAV140 / osk.c < prev    next >
C/C++ Source or Header  |  1995-06-14  |  2KB  |  79 lines

  1. #include <sys/types.h>
  2. #include <module.h>
  3. #include "def.h"
  4.  
  5. extern char    MSG_crc_upd[];
  6. extern char    MSG_crc_updd[];
  7. extern char    MSG_par_updd[];
  8. extern char    MSG_no_module[];
  9.  
  10. updatecrc()
  11. {
  12.   register WINDOW *wp = curwp;
  13.   register LINE   *lp = wp->w_bufp->b_linep->l_fp;
  14.   register struct modhcom *header = (struct modhcom *) lp->l_text;
  15.   int     accu = -1,i;
  16.   LINE    *save_dotp = wp -> w_dotp;    /* save dot position for later */
  17.   int     save_doto = wp -> w_doto;
  18.   unsigned int   size;
  19.   unsigned char  ch;
  20.   unsigned short parity = MODSYNC;
  21.  
  22.   
  23.   writ_echo (MSG_crc_upd);
  24.  
  25.   /* check for module sync */
  26.   if (((unsigned char)lp->l_text[0] != 0x4A) || ((unsigned char)lp->l_text[1] != 0xFC)) {
  27.     writ_echo (MSG_no_module);
  28.     return (FALSE);
  29.   }
  30.  
  31.   /* buffer must be bigger than header+CRC */
  32.   if (BUF_SIZE(wp) < sizeof(struct modhcom)+4) {
  33.     writ_echo (MSG_no_module);
  34.     return (FALSE);
  35.   }
  36.  
  37.   size = header->_msize = BUF_SIZE(wp);
  38.  
  39.   for (i=sizeof(struct modhcom)/sizeof(parity)-2;i>0;i--)
  40.     parity ^= ((short*)header)[i];
  41.  
  42.   parity = ~parity;
  43.  
  44.   if (header->_mparity != parity) {
  45.     header->_mparity = parity;
  46.     writ_echo (MSG_crc_updd);
  47.   }
  48.  
  49.   while (size - llength(lp) > 4) {
  50.     crc(lp->l_text,llength(lp),&accu);
  51.     size -= llength(lp);
  52.     lp = lforw(lp);
  53.   }
  54.  
  55.   move_ptr (wp, header->_msize-size, TRUE, FALSE, FALSE);
  56.  
  57.   while (size-- > 4) {
  58.      ch = DOT_CHAR(wp);
  59.      crc(&ch,1,&accu);
  60.      move_ptr (wp, 1L, TRUE, FALSE, TRUE);
  61.   }
  62.   crc(0,0,&accu);
  63.   accu = ~accu;
  64.  
  65.   lreplace(1,accu>>24);
  66.   lreplace(1,accu>>16);
  67.   lreplace(1,accu>>8);
  68.   lreplace(1,accu);
  69.  
  70.   wp -> w_dotp = save_dotp;  /* restore dot position */
  71.   wp -> w_doto = save_doto;
  72.  
  73.   wp -> w_flag |= WFHARD;  /* update mode line */
  74.   update ();
  75.  
  76.   writ_echo (MSG_crc_updd);
  77. }
  78.  
  79.