Diff for /freem/src/global_bltin.c between versions 1.14 and 1.16

version 1.14, 2025/04/09 19:52:02 version 1.16, 2025/04/11 00:52:40
Line 24 Line 24
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
  *   $Log$   *   $Log$
    *   Revision 1.16  2025/04/11 00:52:40  snw
    *   Replace all lseek/read calls in global handler to use gbl_read_block function
    *
    *   Revision 1.15  2025/04/10 01:24:38  snw
    *   Remove C++ style comments
    *
  *   Revision 1.14  2025/04/09 19:52:02  snw   *   Revision 1.14  2025/04/09 19:52:02  snw
  *   Eliminate as many warnings as possible while building with -Wall   *   Eliminate as many warnings as possible while building with -Wall
  *   *
Line 86  static void scanpblk (char *block, long Line 92  static void scanpblk (char *block, long
 static void scandblk (char *block, long *adr, long *fnd);  static void scandblk (char *block, long *adr, long *fnd);
 static void getnewblk (int filedes, unsigned long *blknbr);  static void getnewblk (int filedes, unsigned long *blknbr);
 static short int g_collate (char *t);  static short int g_collate (char *t);
 //static short int g_numeric (char *str);  
 short g_numeric (char *str);  short g_numeric (char *str);
 void close_all_globals(void);  void close_all_globals(void);
 static void panic (void);  static void panic (void);
Line 469  short gbl_open(global_handle *g, short a Line 474  short gbl_open(global_handle *g, short a
           
 } /* gbl_open() */  } /* gbl_open() */
   
   int gbl_read_block(global_handle *g, unsigned long blocknum, char *block)
   {
       unsigned long hdr_offset;
       hdr_offset = sizeof (global_header);
       
       if (g->opened == FALSE) {
           return FALSE;
       }
   
       gbl_lock (g, 1);
       lseek (g->fd, hdr_offset + ((long) blocknum * (long) (g->header.block_size)), SEEK_SET);
       read (g->fd, block, g->header.block_size);
       g->last_block = blocknum;
       g->use_count++;
       g->read_ops++;
       gbl_unlock (g);
   
       return TRUE;    
   }
   
 global_handle *gbl_handle(char *key)  global_handle *gbl_handle(char *key)
 {  {
     global_handle *g;      global_handle *g;
Line 516  global_handle *gbl_handle(char *key) Line 541  global_handle *gbl_handle(char *key)
     g->fast_path = -1;      g->fast_path = -1;
     g->cache_misses = 0;      g->cache_misses = 0;
     g->cache_hits = 0;      g->cache_hits = 0;
       g->read_ops = 0;
       g->write_ops = 0;
           
     strcpy (g->global_name, global_name);          strcpy (g->global_name, global_name);    
     gbl_path (key, g->global_path);      gbl_path (key, g->global_path);
Line 643  void global_bltin (short action, char *k Line 670  void global_bltin (short action, char *k
     register long int k;      register long int k;
     register long int ch;      register long int ch;
   
       j = 0;
       
     hdr_offset = sizeof (global_header);      hdr_offset = sizeof (global_header);
           
     /* process optional limitations */      /* process optional limitations */
Line 1072  tfast0: Line 1101  tfast0:
   
   
 tfast1:  tfast1:
               gbl_read_block (g, blknbr, block);
             lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);  
             read (g->fd, block, BLOCKLEN);  
   
 /* temporarily disabled  /* temporarily disabled
 tfast2:  tfast2:
Line 1151  tfast2: Line 1178  tfast2:
             if (typ == EMPTY) {              if (typ == EMPTY) {
                                   
                 if (blknbr == ROOT) {                  if (blknbr == ROOT) {
                     //close (filedes);  
                     gbl_close (g);                      gbl_close (g);
                     goto reopen;                      goto reopen;
                 }                  }
Line 1218  k_again:    /* entry point for repeated Line 1244  k_again:    /* entry point for repeated
   
         traceblk[trx] = blknbr;          traceblk[trx] = blknbr;
         traceadr[trx] = 0;          traceadr[trx] = 0;
           
         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          gbl_read_block (g, blknbr, block);
         read (g->fd, block, BLOCKLEN);  
           
         typ = block[BTYP];          typ = block[BTYP];
                   
         if (typ == DATA) {          if (typ == DATA) {
Line 1509  s20: Line 1533  s20:
                 if (addr >= offset) {                  if (addr >= offset) {
   
                     if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2]))) {                      if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2]))) {
                       
                         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, blknbr, block);
                         read (g->fd, block, BLOCKLEN);  
                         j1 = UNSIGN (block[0]);                          j1 = UNSIGN (block[0]);
                                           
                         i = 0;                          i = 0;
Line 1592  s20: Line 1615  s20:
                                   
                     goto quit;                      goto quit;
                 }       /* no next block */                  }       /* no next block */
                   
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  gbl_read_block (g, blknbr, block);
                 read (g->fd, block, BLOCKLEN);  
                 scandblk (block, &addr, &found);                  scandblk (block, &addr, &found);
   
             }               } 
Line 1750  s20: Line 1772  s20:
                         goto quit;              /* no next block */                          goto quit;              /* no next block */
                     }                      }
   
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      gbl_read_block (g, blknbr, block);
                     read (g->fd, block, BLOCKLEN);  
   
                     addr = 0;                      addr = 0;
                     offset = UNSIGN (block[OFFS]) * 256 +                      offset = UNSIGN (block[OFFS]) * 256 +
Line 1774  s20: Line 1795  s20:
                     goto quit;          /* no next block */                      goto quit;          /* no next block */
                 }                  }
   
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  gbl_read_block (g, blknbr, block);
                 read (g->fd, block, BLOCKLEN);  
                                   
                 addr = 0;                  addr = 0;
             }               } 
Line 1984  killo:    /* entry from killone section Line 2004  killo:    /* entry from killone section
   
                         other = traceblk[--trx];                          other = traceblk[--trx];
                         addr = traceadr[trx];                          addr = traceadr[trx];
                           
                         lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, other, block);
                         read (g->fd, block, BLOCKLEN);  
                                                   
                         addr += UNSIGN (block[addr]);                          addr += UNSIGN (block[addr]);
                         addr += (2 + PLEN);     /* skip previous entry */                          addr += (2 + PLEN);     /* skip previous entry */
Line 2005  killo:    /* entry from killone section Line 2024  killo:    /* entry from killone section
   
                     trx = trxsav;                      trx = trxsav;
   
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      gbl_read_block (g, blknbr, block);
                     read (g->fd, block, BLOCKLEN);  
   
                     offset = UNSIGN (block[OFFS]) * 256 +                      offset = UNSIGN (block[OFFS]) * 256 +
                     UNSIGN (block[OFFS + 1]);                      UNSIGN (block[OFFS + 1]);
Line 2112  p_empty:  /* entry if pointer block goes Line 2130  p_empty:  /* entry if pointer block goes
   
                     if (left) {                      if (left) {
   
                         lseek (g->fd, hdr_offset + ((long) left * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, left, block0);
                         read (g->fd, block0, BLOCKLEN);  
                                                   
                         block0[RLPTR] = block[RLPTR];                          block0[RLPTR] = block[RLPTR];
                         block0[RLPTR + 1] = block[RLPTR + 1];                          block0[RLPTR + 1] = block[RLPTR + 1];
Line 2125  p_empty:  /* entry if pointer block goes Line 2142  p_empty:  /* entry if pointer block goes
                     }                      }
   
                     if (right) {                      if (right) {
                           
                         lseek (g->fd, hdr_offset + ((long) right * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, right, block0);
                         read (g->fd, block0, BLOCKLEN);  
                                                   
                         block0[LLPTR] = block[LLPTR];                          block0[LLPTR] = block[LLPTR];
                         block0[LLPTR + 1] = block[LLPTR + 1];                          block0[LLPTR + 1] = block[LLPTR + 1];
Line 2151  p_empty:  /* entry if pointer block goes Line 2167  p_empty:  /* entry if pointer block goes
                         blknbr = traceblk[--trx];                          blknbr = traceblk[--trx];
                         addr = traceadr[trx];                          addr = traceadr[trx];
   
                         lseek (g->fd, hdr_offset + ((long) (blknbr) * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, blknbr, block);
                         read (g->fd, block, BLOCKLEN);  
                         offset = UNSIGN (block[OFFS]) * 256 +                          offset = UNSIGN (block[OFFS]) * 256 +
                         UNSIGN (block[OFFS + 1]);                          UNSIGN (block[OFFS + 1]);
                         freecnt = UNSIGN (block[addr]) + 2 + PLEN;                          freecnt = UNSIGN (block[addr]) + 2 + PLEN;
Line 2270  zinv: Line 2285  zinv:
                         data[0] = EOL1;                          data[0] = EOL1;
                         goto quit;                          goto quit;
                     }                   /* no previous block */                      }                   /* no previous block */
                       
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      gbl_read_block (g, blknbr, block);
                     read (g->fd, block, BLOCKLEN);  
                                           
                     addr = UNSIGN (block[OFFS]) * 256 +                      addr = UNSIGN (block[OFFS]) * 256 +
                     UNSIGN (block[OFFS + 1]);                      UNSIGN (block[OFFS + 1]);
Line 2451  zinv: Line 2465  zinv:
                             break;              /* no next block */                              break;              /* no next block */
                         }                          }
   
                         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                          gbl_read_block (g, blknbr, block);
                         read (g->fd, block, BLOCKLEN);  
                                                   
                         addr = 0;                          addr = 0;
                         offset = UNSIGN (block[OFFS]) * 256 +                          offset = UNSIGN (block[OFFS]) * 256 +
Line 2618  splitd:    /* split data block in two se Line 2631  splitd:    /* split data block in two se
                   
             char    block0[BLOCKLEN];              char    block0[BLOCKLEN];
   
             lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              gbl_read_block (g, other, block0);
             read (g->fd, block0, BLOCKLEN);  
                   
             block0[LLPTR] = blknbr / 65536;              block0[LLPTR] = blknbr / 65536;
             block0[LLPTR + 1] = blknbr % 65536 / 256;              block0[LLPTR + 1] = blknbr % 65536 / 256;
Line 2781  splitd:    /* split data block in two se Line 2793  splitd:    /* split data block in two se
             /* up-date LL-PTR of RL-block */              /* up-date LL-PTR of RL-block */
             if (other != 0) {              if (other != 0) {
   
                 lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  gbl_read_block (g, other, block0);
                 read (g->fd, block0, BLOCKLEN);  
   
                 block0[LLPTR] = newblk / 65536;                  block0[LLPTR] = newblk / 65536;
                 block0[LLPTR + 1] = newblk % 65536 / 256;                  block0[LLPTR + 1] = newblk % 65536 / 256;
Line 2823  splitd:    /* split data block in two se Line 2834  splitd:    /* split data block in two se
             /* up-date LL-PTR of RL-block */              /* up-date LL-PTR of RL-block */
             if (other != 0) {              if (other != 0) {
   
                 lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  gbl_read_block (g, other, block0);
                 read (g->fd, block0, BLOCKLEN);  
                                   
                 block0[LLPTR] = newblk / 65536;                  block0[LLPTR] = newblk / 65536;
                 block0[LLPTR + 1] = newblk % 65536 / 256;                  block0[LLPTR + 1] = newblk % 65536 / 256;
Line 3661  static short int g_collate (char *t) Line 3671  static short int g_collate (char *t)
 /*  /*
  * test whether 'str' is canonical   * test whether 'str' is canonical
  */   */
 //static short int g_numeric (char *str)  
 short g_numeric (char *str)  short g_numeric (char *str)
 {  {
     register int ptr = 0, ch;      register int ptr = 0, ch;

Removed from v.1.14  
changed lines
  Added in v.1.16


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>