⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ovview.c

📁 汇编语言编的关于ov143b.asm的小程序
💻 C
📖 第 1 页 / 共 2 页
字号:
      going forward) or bottom of screen (if going backward) - otherwise,
      start 1 character offset from the last find so we don't find the same
      string again. */

   if (findloc < 0L || findloc < tos || findloc >= vtell())
      findloc = forward ? tos : vtell();

   else        /* its on the screen - try to offset by 1 */

      if (forward && findloc < files[cw.curidx].size)  /* going forward */
         findloc++;
      else
         if (!forward && findloc > 0L)                 /* going backward */
            findloc--;

   view_seek(findloc);                 /* move to 1st/last find location */

   /* try to find users string in file */

   fch = *findstr;                     /* first char in find string */

   while ((ch = forward ? Vnextch(inf) : Vprevch(inf)) != EOF)

      /* is this the first char of the search string? */

      if (ch == fch || igncase && tolower(ch) == tolower(fch)) {

         temploc = vtell();    /* could be it, remember where we are */

         /* does the rest of the string match? */

         if (!forward)         /* adjust if we are searching backward */
            vnextch(inf);

         for (fcp = findstr+1; *fcp; fcp++)    /* check rest of string */
            if ((ch = vnextch(inf)) != *fcp)
               if (!igncase || tolower(ch) != tolower(*fcp))
                  break;;

         if (*fcp == '\0')             /* ***** FOUND IT ***** */
            break;

         view_seek(temploc);           /* not yet, back to where we were */
      }

   if (ch == EOF) {                    /* EOF if wasn't found       */

      findloc = hiline = -1L;          /* don't highlight any lines */
      strcpy(nfmsg,"Not found: ");     /* tell user it wasn't found */
      strcat(nfmsg,findstr);
      show_error(QUIET,0,1,nfmsg);
      view_current();                  /* make sure no highlighted line */

   } else {                    /* ******* F O U N D   I T ******** */

      tos = findloc = temploc - forward;/* remember where string is */
      align();                          /* goto start of that line  */
      hiline = vtell();                 /* highlight this line      */
      backup(VIEW_ROWS >> 1);           /* try to center line w/str */
      view_down();                      /* view screen              */
   }
}

/***************************************************************************
                            V I E W _ F S T R
 ***************************************************************************/

static int
view_fstr() {          /* pick the string to find */

   char *str;

   str = prompt("Select Find String","Enter string to find: ",findstr,0,FSTR_LEN);
   if (strlen(str) == 0)
      return;

   if (findstr)                /* release old find string */
      free(findstr);

   findstr = Strdup(str);      /* make local copy of string */

}


/*****************************************************************************
                           V I E W _ L I N E
 *****************************************************************************/

static int ALTCALL
view_line() {          /* display a single line of the file */

   int col, ch, hl = 0;
   char line[SCREEN_COLS+1];

   if (hl = (hiline == vtell()))       /* highlight this line if desired */
      setvattrib(DIS_HIGH);

   if (ascmode)                        /* format line as ascii or hex data */
      ch = fmt_asc_line(line,&col);
   else
      ch = fmt_hex_line(line,&col);

   disp_str(line);                     /* make one call to display line */

   if (col < margin+SCREEN_COLS)       /* clear if < full line displayed */
      clr_eol();

   if (hl)                             /* alwasy go back to normal */
      setvattrib(DIS_NORM);

   return(ch != EOF || col);   /* return true if something displayed */
}


/*****************************************************************************
                         F M T _ A S C _ L I N E
 ****************************************************************************/

static int ALTCALL
fmt_asc_line(op,colp)  /* format an ascii line for display */
char *op;
int *colp;
{
   register int ch, col = 0;
   int i, endcol = margin + SCREEN_COLS;

   while ((ch = Vnextch(inf)) != EOF && (ch = ch & bitmask) != '\n')
      if (ch == '\t') {
         for (i = 8 - (col & 7); i; i--, col++)
            if (col >= margin && col < endcol)
               *op++ = ' ';
       } else
          if (ch != '\r' && ch != '\0') {
              if (col >= margin && col < endcol)
                  *op++ = ch;
             col++;
          }

   *op = '\0';                 /* null terminate it for disp_str */

   *colp = col;                /* tell caller the # cloumns */
   return(ch);                 /* and if EOF was reached */
}


/******************************************************************************
                          F M T _ H E X _L I N E
 *****************************************************************************/

static int ALTCALL
fmt_hex_line(op,colp)  /* format a hex line for later display */
register char *op;
int *colp;
{
   int ch, ach, j;
   register int i;
   char offstr[9], *ap;
   static char bin2hex[] = "0123456789ABCDEF";

   /* test if there is anything to format */

   if (vnextch(inf) == EOF) {
      *colp = 0;
      *op = '\0';
      return(EOF);
   } else
      vprevch(inf);

   /* format data offset into buffer */

   ultoa(vtell(),offstr,16);           /* offset to hex */
   j = strlen(offstr);
   for (i = 6 - j; i > 0; i--)         /* zero fill */
      *op++ = '0';
   if (j <= 6)                         /* don't use more than 6 digits */
     strcpy(op,offstr);
   else
     strcpy(op,offstr+j-6);

   strupr(op);                         /* ultoa leaves A-F in lower case */

   strcat(op,"  ");                    /* go beyond the offset */
   op += strlen(op);

   ap = op + 53;                       /* where ascii data starts */
   *ap++ = V_bar;                      /* might as well do it now */

   /* setup data in hex (and ascii) */

   for (i = 16; i; i--) {              /* at most 16 bytes to fmt */

      ch = Vnextch(inf);               /* next char from file */
      if (ch == EOF)                   /* done? */
         break;

      *op++ = bin2hex[(ch >> 4) & 0x0f];       /* hexalate it */
      *op++ = bin2hex[ch & 0x0f];
      *op++ = ' ';

      if (((i+3) & 3) == 0)            /* extra spacer every 4 bytes */
         *op++ = ' ';

      if ((ach = ch & bitmask) < ' ')  /* do the ascii char, '.' if ctrl ch */
         *ap++ = '.';
      else
         *ap++ = ach;
   }

   /* blank fill if EOF was reached */

   for ( ; i; i--) {           /* i is # chars to blank fill */
      strncpy(op,"   ",3);
      op += 3;
      if (((i+3) & 3) == 0)
         *op++ = ' ';
      *ap++ = ' ';
   }

   *op++ = ' ';                /* up to ascii data */

   *ap++ = V_bar;              /* closing bar at end */
   *ap = '\0';                 /* The Terminator */

   *colp = 74;                 /* tell call how many columns */
   return(ch);                 /* and if EOF was reached */
}


/*****************************************************************************
                      V I E W _ R I G H T / L E F T
 *****************************************************************************/

static int
view_right() {         /* scroll right 8 characters */

   margin += 8;
   view_current();
   disp_margin();
}

static int
view_left() {          /* scroll left 8 characters */

   if (margin >= 8) {
      margin -= 8;
      view_current();
      disp_margin();
   }
}

static int
disp_margin() {        /* display the viewing margins */

   char marstr[11];

   if (margin) {

      itoa(margin,marstr,10);
      disp_msg(2,"COL: ",marstr);

   } else              /* must have just gone to 0 */

      clr_msg();
}


/*****************************************************************************
                            V I E W _ n B I T
 *****************************************************************************/

static int
view_7bit() {          /* display data using low order 7 bits */

   if (bitmask != 0x7f) {
      bitmask = 0x7f;
      view_current();
   }
}

static int
view_8bit() {          /* display data using all 8 bits per char */

   if (bitmask != 0xff) {
      bitmask = 0xff;
      view_current();
   }
}

static int
view_current() {       /* redisplay the current screen */

      view_seek(tos);
      view_down();
}


/*****************************************************************************
                           V I E W _ A S C
 *****************************************************************************/

static int
view_asc() {           /* set ascii mode display */

   if (!ascmode) {                    /* only need to change if in hex mode */
      ascmode = TRUE;                 /* set ascii mode */
      align();                        /* make sure were at begining of line */
      view_down();                       /* redisplay in ascii format */
   }
}


/*****************************************************************************
                          V I E W _ H E X
 *****************************************************************************/

static int
view_hex() {           /* set hex mode display */

   if (ascmode) {                     /* only need to change if in ascii mode */
      ascmode = FALSE;                /* set hex mode */
      align();                        /* make sure were at begining of line */
      view_down();                    /* redisplay in ascii format */
   }
}


/*****************************************************************************
                                A L I G N
 *****************************************************************************/

static int ALTCALL
align() {              /* align tos to be at the start of a line */

   if (ascmode) {              /* ascii mode? */

      view_seek(tos);                 /* backup to current top of screen */
      if (backup(1))                  /* make sure were at the start of */
         nsol();                      /*   the current line */

   } else {                    /* hex mode */

      tos &= ~((long) 0x0f);          /* force a paragraph boundry */
      view_seek(tos);                 /* backup to current top of screen */
   }
}

/*****************************************************************************
                                B A C K U P
 *****************************************************************************/

static int ALTCALL
backup(todo)           /* backup todo lines from current position */
int todo;
{
   register int i;
   int part, bytes;
   unsigned long off, lines;

    /* backup in hex mode */

    if (!ascmode) {                    /* different if in hex mode */
       off = vtell();                  /* current loc in file */
       lines = off >> 4;               /* # full hex display lines above */
       part = (bytes = off & (long) 0x0f) > 0; /* may be partial line if at eof */
       if (todo > lines + part) {              /* more todo than are? */
          view_seek(0L);                       /* just goto tof */
          return(lines + part);                /* went back this # lines */
       } else {
          view_seek(off - (((todo - part) << 4)+bytes)); /* backup todo lines */
          return(todo);
       }
    }

    /* backup in ascii mode */

    /* special case backing up from EOF - there may or may not be a \n
       at the end of the last line */

    if (vnextch(inf) == EOF) {         /* at end of file? */
       vprevch(inf);                   /*   always backup at least one char */
       i = 1;                          /*   we will backup 1 line here      */
       if (peol() == '\n')             /*   goto start of prev line         */
          vnextch(inf);
    } else {           /* not at EOF, setup for loop down below */
       i = 0;
       vprevch(inf);
    }

    /* backup todo ascii lines, 1 line may have been done above */

    for ( ; i < todo; i++) {
      if (peol() == EOF)               /* goto end of prev line */
         break;
      if (peol() == '\n')              /* end of prev prev line */
         vnextch(inf);                 /* start of prev line    */
   }

   return(i);          /* tell caller how many ascii lines backed up */
}

static int ALTCALL
peol() {       /* move to end of prev line */

   register int ch;

   while ((ch = Vprevch(inf)) != '\n' && ch != EOF) ;  /* end of prev line */
   return(ch);
}

static int ALTCALL
nsol() {       /* move to start of next line */

   register int ch;

   while ((ch = Vnextch(inf)) != '\n' && ch != EOF) ;  /* start of next line */
   return(ch);
}


/*****************************************************************************
                            M O R E 2 V I E W
 *****************************************************************************/

static int ALTCALL
more2view() {          /* return true if more data to view */

   return(vtell() < files[cw.curidx].size);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -