|
|
| version 1.17, 2025/04/11 14:21:03 | version 1.22, 2025/04/13 04:22:43 |
|---|---|
| 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.22 2025/04/13 04:22:43 snw | |
| * Fix snprintf calls | |
| * | |
| * Revision 1.21 2025/04/11 20:55:49 snw | |
| * Disable -Wunused-result where possible | |
| * | |
| * Revision 1.20 2025/04/11 18:24:32 snw | |
| * Fix bug in memory cache | |
| * | |
| * Revision 1.19 2025/04/11 16:52:05 snw | |
| * Fix indentation in global handler | |
| * | |
| * Revision 1.18 2025/04/11 16:23:18 snw | |
| * Avoid re-reading the same block consecutively when possible | |
| * | |
| * Revision 1.17 2025/04/11 14:21:03 snw | * Revision 1.17 2025/04/11 14:21:03 snw |
| * Make all but one of the read/write calls in global_bltin use gbl_read_block or gbl_write_block | * Make all but one of the read/write calls in global_bltin use gbl_read_block or gbl_write_block |
| * | * |
| Line 99 short g_numeric (char *str); | Line 114 short g_numeric (char *str); |
| void close_all_globals(void); | void close_all_globals(void); |
| static void panic (void); | static void panic (void); |
| #define ROOT 0L | |
| /* end of line symbol in global module is 30, which is a code not */ | |
| /* otherwise used in subscripts */ | |
| #define g_EOL 30 | |
| #define EOL1 EOL | |
| /* numerics (('.'<<1)&037)==28 ; (('-'<<1)&037)==26; */ | |
| #define POINT 28 | |
| #define MINUS 26 | |
| /* ALPHA and OMEGA are dummy subscripts in $order processing */ | |
| /* ALPHA sorts before all other subscripts */ | |
| /* OMEGA sorts after all other subscripts */ | |
| /* e.g. ("abc") -> "abc",OMEGA ; ("abc","") -> "abc",ALPHA */ | |
| #define OMEGA 29 | |
| #define ALPHA 31 | |
| /* length of blocks. status bytes defined as offset to blocklength */ | |
| /* BLOCKLEN 1024 is defined in mpsdef0 include file */ | |
| #define DATALIM (BLOCKLEN-11) | |
| #define LLPTR (BLOCKLEN-10) | |
| #define NRBLK LLPTR | |
| #define COLLA (BLOCKLEN- 7) | |
| #define RLPTR (BLOCKLEN- 6) | |
| #define FREE RLPTR | |
| #define BTYP (BLOCKLEN- 3) | |
| #define OFFS (BLOCKLEN- 2) | |
| /* length of blockpointers in bytes */ | |
| #define PLEN 3 | |
| #define EMPTY 0 | |
| #define FBLK 1 | |
| #define POINTER 2 | |
| #define BOTTOM 6 | |
| #define DATA 8 | |
| #if !defined(__OpenBSD__) && !defined(_AIX) && !defined(__osf__) && !defined(MSDOS) && !defined(__vax__) && !defined(__OS2__) | #if !defined(__OpenBSD__) && !defined(_AIX) && !defined(__osf__) && !defined(MSDOS) && !defined(__vax__) && !defined(__OS2__) |
| long time (); | long time (); |
| #endif | #endif |
| inline long gbl_path(char *key, char *buf) | inline long gbl_path(char *key, char *buf) |
| Line 303 int gbl_write_initial_header(global_hand | Line 279 int gbl_write_initial_header(global_hand |
| lseek (g->fd, 0, SEEK_SET); | lseek (g->fd, 0, SEEK_SET); |
| if (write (g->fd, &hdr, sizeof (global_header)) == -1) { | if (write (g->fd, &hdr, sizeof (global_header)) == -1) { |
| snprintf (msg, sizeof (msg), "error %d writing global header for %s", errno, g->global_name); | snprintf (msg, sizeof (msg) - 1, "error %d writing global header for %s", errno, g->global_name); |
| m_fatal (msg); | m_fatal (msg); |
| } | } |
| Line 323 int gbl_write_header(global_handle *g, g | Line 299 int gbl_write_header(global_handle *g, g |
| return FALSE; | return FALSE; |
| } | } |
| if (g->locked == FALSE) gbl_lock (g, 1); | gbl_lock (g, 1); |
| old_position = lseek (g->fd, 0, SEEK_CUR); | old_position = lseek (g->fd, 0, SEEK_CUR); |
| lseek (g->fd, 0, SEEK_SET); | lseek (g->fd, 0, SEEK_SET); |
| if (write (g->fd, hdr, sizeof (global_header)) == -1) { | if (write (g->fd, hdr, sizeof (global_header)) == -1) { |
| snprintf (msg, sizeof (msg), "error %d writing global header for %s", errno, g->global_name); | snprintf (msg, sizeof (msg) - 1, "error %d writing global header for %s", errno, g->global_name); |
| m_fatal (msg); | m_fatal (msg); |
| } | } |
| lseek (g->fd, old_position, SEEK_SET); | lseek (g->fd, old_position, SEEK_SET); |
| if (g->locked == TRUE) gbl_unlock (g); | gbl_unlock (g); |
| gbl_read_header (g, &g->header); | gbl_read_header (g, &g->header); |
| Line 445 short gbl_open(global_handle *g, short a | Line 421 short gbl_open(global_handle *g, short a |
| } | } |
| else { | else { |
| g->opened = TRUE; | g->opened = TRUE; |
| result = gbl_read_header (g, &g->header); | result = gbl_read_header (g, &g->header); |
| if (result == GBL_HDR_OK) { | if (result == GBL_HDR_OK) { |
| /* initialize last_block_accessed cache */ | |
| g->last_block_accessed = (char *) calloc (g->header.block_size, sizeof (char)); | |
| NULLPTRCHK(g->last_block_accessed,"gbl_open"); | |
| g->opened = TRUE; | g->opened = TRUE; |
| } | } |
| else { | else { |
| Line 479 short gbl_open(global_handle *g, short a | Line 459 short gbl_open(global_handle *g, short a |
| int gbl_read_block(global_handle *g, unsigned long blocknum, char *block) | int gbl_read_block(global_handle *g, unsigned long blocknum, char *block) |
| { | { |
| struct stat gstat; | |
| unsigned long hdr_offset; | unsigned long hdr_offset; |
| hdr_offset = sizeof (global_header); | hdr_offset = sizeof (global_header); |
| Line 486 int gbl_read_block(global_handle *g, uns | Line 467 int gbl_read_block(global_handle *g, uns |
| return 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->use_count++; |
| g->read_ops++; | |
| gbl_unlock (g); | if (!g->locked) gbl_lock (g, 1); |
| fstat (g->fd, &gstat); | |
| if ((g->last_block == blocknum) && | |
| (g->have_cached_block) && | |
| (g->cached_block_num == blocknum) && | |
| (gstat.st_mtime < g->last_read_time)) { | |
| /* the global has not been modified since the last read; grab from memory */ | |
| g->memory_reads++; | |
| memcpy (block, g->last_block_accessed, g->header.block_size); | |
| } | |
| else { | |
| /* have to go out to disk */ | |
| lseek (g->fd, hdr_offset + ((long) blocknum * (long) (g->header.block_size)), SEEK_SET); | |
| read (g->fd, block, g->header.block_size); | |
| /* update cache */ | |
| memcpy (g->last_block_accessed, block, g->header.block_size); | |
| g->have_cached_block = TRUE; | |
| g->cached_block_num = blocknum; | |
| g->last_block = blocknum; | |
| g->read_ops++; | |
| } | |
| g->last_read_time = time (0L); | |
| g->use_count++; | |
| if (g->locked) gbl_unlock (g); | |
| return TRUE; | return TRUE; |
| } /* gbl_read_block() */ | } /* gbl_read_block() */ |
| Line 507 int gbl_write_block(global_handle *g, un | Line 511 int gbl_write_block(global_handle *g, un |
| return FALSE; | return FALSE; |
| } | } |
| if (!g->locked) { | gbl_lock (g, 1); |
| gbl_lock (g, 1); | |
| } | |
| for (;;) { | for (;;) { |
| errno = 0; | errno = 0; |
| lseek (g->fd, hdr_offset + (blocknum * g->header.block_size), SEEK_SET); | lseek (g->fd, hdr_offset + (blocknum * g->header.block_size), SEEK_SET); |
| write (g->fd, block, BLOCKLEN); | write (g->fd, block, g->header.block_size); |
| errsav = errno; | errsav = errno; |
| g->last_block = blocknum; | g->last_block = blocknum; |
| g->use_count++; | g->use_count++; |
| Line 528 int gbl_write_block(global_handle *g, un | Line 530 int gbl_write_block(global_handle *g, un |
| } | } |
| gbl_update_tid (g); | gbl_update_tid (g); |
| gbl_unlock (g); | |
| if (g->locked) { | |
| gbl_unlock (g); | |
| } | |
| return TRUE; | return TRUE; |
| } | } |
| Line 578 global_handle *gbl_handle(char *key) | Line 577 global_handle *gbl_handle(char *key) |
| g->use_count = 1; | g->use_count = 1; |
| g->locked = FALSE; | g->locked = FALSE; |
| g->age = time (0L); | g->age = time (0L); |
| g->last_read_time = 0; | |
| g->last_block = 0; | g->last_block = 0; |
| g->opened = FALSE; | g->opened = FALSE; |
| g->fd = 0; | g->fd = 0; |
| Line 586 global_handle *gbl_handle(char *key) | Line 586 global_handle *gbl_handle(char *key) |
| g->cache_hits = 0; | g->cache_hits = 0; |
| g->read_ops = 0; | g->read_ops = 0; |
| g->write_ops = 0; | g->write_ops = 0; |
| g->memory_reads = 0; | |
| g->have_cached_block = FALSE; | |
| g->last_block_accessed = NULL; | |
| 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 704 void global_bltin (short action, char *k | Line 707 void global_bltin (short action, char *k |
| static char block[BLOCKLEN]; | static char block[BLOCKLEN]; |
| static int getnflag; /* flag 1=$ZO-variable 0=$Q-function */ | static int getnflag; /* flag 1=$ZO-variable 0=$Q-function */ |
| static int tryfast; /* try fast access if get_sym on */ | static int tryfast; /* try fast access if get_sym on */ |
| /* previous global */ | /* previous global */ |
| int iresult; | int iresult; |
| Line 713 void global_bltin (short action, char *k | Line 716 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; | j = 0; |
| hdr_offset = sizeof (global_header); | hdr_offset = sizeof (global_header); |
| /* process optional limitations */ | /* process optional limitations */ |
| if (glvnflag.all && key[0] >= '%' && key[0] <= 'z') { | if (glvnflag.all && key[0] >= '%' && key[0] <= 'z') { |
| if ((i = glvnflag.one[0])) { /* number of significant chars */ | if ((i = glvnflag.one[0])) { /* number of significant chars */ |
| j = 0; | j = 0; |
| while ((k = key[j]) != DELIM && k != EOL) { | while ((k = key[j]) != DELIM && k != EOL) { |
| if (j >= i) { | if (j >= i) { |
| while ((k = key[++j]) != DELIM && k != EOL); | while ((k = key[++j]) != DELIM && k != EOL); |
| stcpy (&key[i], &key[j]); | stcpy (&key[i], &key[j]); |
| break; | break; |
| } | } |
| j++; | j++; |
| } | } |
| } | } |
| if (glvnflag.one[1]) { /* upper/lower sensitivity */ | if (glvnflag.one[1]) { /* upper/lower sensitivity */ |
| j = 0; | j = 0; |
| while ((k = key[j]) != DELIM && k != EOL) { | while ((k = key[j]) != DELIM && k != EOL) { |
| if (k >= 'a' && k <= 'z') key[j] = k - 32; | if (k >= 'a' && k <= 'z') key[j] = k - 32; |
| j++; | j++; |
| } | } |
| } | } |
| if ((i = glvnflag.one[2])) { | if ((i = glvnflag.one[2])) { |
| if (stlen (key) > i) { | if (stlen (key) > i) { |
| merr_raise (M75); | merr_raise (M75); |
| return; | return; |
| } /* key length limit */ | } /* key length limit */ |
| } | } |
| if ((i = glvnflag.one[3])) { /* subscript length limit */ | if ((i = glvnflag.one[3])) { /* subscript length limit */ |
| j = 0; | j = 0; |
| while ((k = key[j++]) != DELIM && k != EOL); | while ((k = key[j++]) != DELIM && k != EOL); |
| if (k == DELIM) { | if (k == DELIM) { |
| k = 0; | k = 0; |
| for (;;) { | for (;;) { |
| k = key[j++]; | k = key[j++]; |
| if (k == DELIM || k == EOL) { | if (k == DELIM || k == EOL) { |
| if (k > i) { | if (k > i) { |
| merr_raise (M75); | merr_raise (M75); |
| return; | return; |
| } | } |
| k = 0; | k = 0; |
| } | } |
| if (k == EOL) break; | if (k == EOL) break; |
| k++; | k++; |
| } | } |
| } | } |
| } | } |
| } | } |
| Line 852 void global_bltin (short action, char *k | Line 834 void global_bltin (short action, char *k |
| } | } |
| } | } |
| if (v22ptr) { | |
| procv22 (key); | |
| if (key[0] != '^') { | |
| char losav[256]; | |
| stcpy (losav, l_o_val); | |
| symtab (action, key, data); | |
| stcpy (g_o_val, l_o_val); | |
| stcpy (l_o_val, losav); | |
| return; | |
| } | |
| } | |
| g = gbl_handle (key); | g = gbl_handle (key); |
| i = gbl_path (key, filnam); | i = gbl_path (key, filnam); |
| Line 932 void global_bltin (short action, char *k | Line 898 void global_bltin (short action, char *k |
| compactkey[k++] = ch << 1; | compactkey[k++] = ch << 1; |
| } | } |
| else if (ch < SP || ch >= DEL) { | else if (ch < SP || ch >= DEL) { |
| /* no CTRLs */ | |
| /*no CTRLs */ | |
| merr_raise (SBSCR); | merr_raise (SBSCR); |
| return; | return; |
| } | } |
| Line 1008 void global_bltin (short action, char *k | Line 972 void global_bltin (short action, char *k |
| reopen: | reopen: |
| gbl_open (g, action); | if (!gbl_open (g, action)) { |
| if (g->fd == -1) { | |
| /* file not found */ | /* file not found */ |
| if (action != set_sym) { | if (action != set_sym) { |
| Line 1092 reopen: | Line 1055 reopen: |
| block[BTYP] = DATA; /* type */ | block[BTYP] = DATA; /* type */ |
| block[OFFS] = i / 256; | block[OFFS] = i / 256; |
| block[OFFS + 1] = i % 256; | block[OFFS + 1] = i % 256; |
| for (;;) { | |
| errno = 0; | |
| write (g->fd, block, BLOCKLEN); | |
| if (errno == 0) break; | |
| lseek (g->fd, hdr_offset + ((ROOT + 1L) * BLOCKLEN), SEEK_SET); | |
| panic (); | |
| } | |
| gbl_write_block (g, ROOT + 1, block); | |
| gbl_close (g); | gbl_close (g); |
| gbl_unlock (g); | gbl_unlock (g); |
| gbl_open (g, action); | gbl_open (g, action); |
| Line 1123 reopen: | Line 1076 reopen: |
| if (action == get_sym) { | if (action == get_sym) { |
| tfast0: | tfast0: |
| gbl_lock (g, 3); | gbl_lock (g, 3); |
| if (g->fast_path > 0) goto tfast1; /* try again last block */ | if (g->fast_path > 0) { |
| goto tfast1; /* try again last block */ | |
| } | |
| blknbr = g->last_block = ROOT; /* start with ROOT block */ | blknbr = g->last_block = ROOT; /* start with ROOT block */ |
| for (;;) { | for (;;) { |
| tfast1: | tfast1: |
| gbl_read_block (g, blknbr, block); | gbl_read_block (g, blknbr, block); |
| Line 1140 reopen: | Line 1093 reopen: |
| tfast2: | tfast2: |
| */ | */ |
| if ((typ = block[BTYP]) == DATA) { /* scan data block: here we test for equality only */ | if ((typ = block[BTYP]) == DATA) { /* scan data block: here we test for equality only */ |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| j = UNSIGN (block[0]); | j = UNSIGN (block[0]); |
| Line 1149 reopen: | Line 1101 reopen: |
| stcpy0 (key1, &block[2], j); /* get first key */ | stcpy0 (key1, &block[2], j); /* get first key */ |
| ch = keyl; /* ch is a register! */ | ch = keyl; /* ch is a register! */ |
| while (i < offset) { | |
| while (i < offset) { | |
| j = UNSIGN (block[i++]); /* length of key - offset */ | j = UNSIGN (block[i++]); /* length of key - offset */ |
| k = UNSIGN (block[i++]); /* offset into previous entry */ | k = UNSIGN (block[i++]); /* offset into previous entry */ |
| Line 1159 reopen: | Line 1109 reopen: |
| while (k < j) key1[k++] = block[i++]; /* get key */ | while (k < j) key1[k++] = block[i++]; /* get key */ |
| if (j != ch) { /* keys have different length */ | if (j != ch) { /* keys have different length */ |
| i += UNSIGN (block[i]); | i += UNSIGN (block[i]); |
| i++; | i++; |
| continue; | continue; |
| } | } |
| j = ch; | j = ch; |
| Line 1173 reopen: | Line 1121 reopen: |
| do { | do { |
| j--; | j--; |
| } while (compactkey[j] == key1[j]); /* compare keys */ | } while (compactkey[j] == key1[j]); /* compare keys */ |
| if (j < 0) { | |
| if (j < 0) { | |
| k = UNSIGN (block[i++]); | k = UNSIGN (block[i++]); |
| stcpy0 (data, &block[i], k); /* get value */ | stcpy0 (data, &block[i], k); /* get value */ |
| data[k] = EOL1; /* append EOL */ | data[k] = EOL1; /* append EOL */ |
| goto quit; | goto quit; |
| } | } |
| i += UNSIGN (block[i]); | i += UNSIGN (block[i]); |
| i++; /* skip data */ | i++; /* skip data */ |
| } | } |
| /* fast access failed. try normal path */ | /* fast access failed. try normal path */ |
| Line 1227 reopen: | Line 1171 reopen: |
| addr += UNSIGN (block[addr]) + 2; /* skip key */ | addr += UNSIGN (block[addr]) + 2; /* skip key */ |
| if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == g->last_block) { | if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == g->last_block) { |
| merr_raise (DBDGD); | merr_raise (DBDGD); |
| goto quit; | goto quit; |
| } | } |
| addr += PLEN; /* skip data */ | addr += PLEN; /* skip data */ |
| g->last_block = blknbr; | g->last_block = blknbr; |
| g->fast_path = 1; | g->fast_path = 1; |
| if (merr () == INRPT) goto quit; | if (merr () == INRPT) goto quit; |
| } | } |
| } /* end of get_sym */ | } /* end of get_sym */ |
| Line 1319 k_again: /* entry point for repeated | Line 1263 k_again: /* entry point for repeated |
| datal = stlen (data); | datal = stlen (data); |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| if (found != 2) { /* new entry */ | if (found != 2) { /* new entry */ |
| Line 1345 k_again: /* entry point for repeated | Line 1289 k_again: /* entry point for repeated |
| } | } |
| s10: { | s10: |
| { | |
| long len; /* insert key */ | long len; /* insert key */ |
| char key0[256]; | char key0[256]; |
| Line 1496 s10: { | Line 1441 s10: { |
| goto splitd; | goto splitd; |
| } | } |
| s20: | s20: |
| i = offset; | i = offset; |
| k = addr + olddatal; | k = addr + olddatal; |
| Line 1556 s20: | Line 1501 s20: |
| /* get following entry, eventually in the next blk */ | /* get following entry, eventually in the next blk */ |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| if (addr >= offset) { | if (addr >= offset) { |
| Line 1691 s20: | Line 1636 s20: |
| while (i < keyl) if (compactkey[i++] & 01) | while (i < keyl) if (compactkey[i++] & 01) |
| j1++; | j1++; |
| i = 0; | i = 0; |
| j = 0; | j = 0; |
| k = 0; | k = 0; |
| Line 1724 s20: | Line 1669 s20: |
| while ((ch = UNSIGN (scratch[i++])) != g_EOL) { | while ((ch = UNSIGN (scratch[i++])) != g_EOL) { |
| ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ | ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ |
| (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ | (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ |
| (ch >> 1) + SP)); /* '.' or '-' */ | (ch >> 1) + SP)); /* '.' or '-' */ |
| if (ch0 == DEL) { | if (ch0 == DEL) { |
| Line 1804 s20: | Line 1749 s20: |
| addr = 0; | addr = 0; |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| } | } |
| } | } |
| Line 1871 s20: | Line 1816 s20: |
| while ((ch = UNSIGN (key0[i++])) != g_EOL) { | while ((ch = UNSIGN (key0[i++])) != g_EOL) { |
| ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ | ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ |
| (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ | (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ |
| (ch >> 1) + SP)); /* '.' or '-' */ | (ch >> 1) + SP)); /* '.' or '-' */ |
| if (ch0 == DEL) { | if (ch0 == DEL) { |
| Line 1948 s20: | Line 1893 s20: |
| } | } |
| ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ | ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ |
| (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ | (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ |
| (ch >> 1) + SP)); /* '.' or '-' */ | (ch >> 1) + SP)); /* '.' or '-' */ |
| if (ch0 == DEL) { | if (ch0 == DEL) { |
| Line 1993 s20: | Line 1938 s20: |
| case kill_sym: /* search and destroy */ | case kill_sym: /* search and destroy */ |
| killo: /* entry from killone section */ | killo: /* entry from killone section */ |
| offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); | offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); |
| i = 0; | i = 0; |
| Line 2038 killo: /* entry from killone section | Line 1983 killo: /* entry from killone section |
| addr += UNSIGN (block[addr]); | addr += UNSIGN (block[addr]); |
| addr += (2 + PLEN); /* skip previous entry */ | addr += (2 + PLEN); /* skip previous entry */ |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| traceadr[trx] = addr; | traceadr[trx] = addr; |
| if (addr < offset) break; | if (addr < offset) break; |
| traceadr[trx] = 0; | traceadr[trx] = 0; |
| traceblk[trx] = UNSIGN (block[RLPTR]) * 65536 + | traceblk[trx] = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| } | } |
| Line 2055 killo: /* entry from killone section | Line 2000 killo: /* entry from killone section |
| gbl_read_block (g, blknbr, block); | gbl_read_block (g, blknbr, block); |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| addr = 0; | addr = 0; |
| k = UNSIGN (block[0]); | k = UNSIGN (block[0]); |
| stcpy0 (key0, &block[2], k); | stcpy0 (key0, &block[2], k); |
| Line 2144 killo: /* entry from killone section | Line 2089 killo: /* entry from killone section |
| if ((begadr == 0) && (endadr == offset)) { /* block becomes empty */ | if ((begadr == 0) && (endadr == offset)) { /* block becomes empty */ |
| long left, | long left, |
| right; | right; |
| char block0[BLOCKLEN]; | char block0[BLOCKLEN]; |
| p_empty: /* entry if pointer block goes empty */ | p_empty: /* entry if pointer block goes empty */ |
| left = UNSIGN (block[LLPTR]) * 65536 + | left = UNSIGN (block[LLPTR]) * 65536 + |
| UNSIGN (block[LLPTR + 1]) * 256 + | UNSIGN (block[LLPTR + 1]) * 256 + |
| UNSIGN (block[LLPTR + 2]); | UNSIGN (block[LLPTR + 2]); |
| right = UNSIGN (block[RLPTR]) * 65536 + | right = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| if (left) { | if (left) { |
| Line 2195 p_empty: /* entry if pointer block goes | Line 2140 p_empty: /* entry if pointer block goes |
| gbl_read_block (g, blknbr, block); | gbl_read_block (g, blknbr, block); |
| 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; |
| /* delete key */ | /* delete key */ |
| Line 2268 p_empty: /* entry if pointer block goes | Line 2213 p_empty: /* entry if pointer block goes |
| j = block[begadr + 1]; | j = block[begadr + 1]; |
| k = 0; | k = 0; |
| if (begadr) | if (begadr) |
| while (key0[k] == key1[k]) | while (key0[k] == key1[k]) |
| k++; /* new key_offset */ | k++; /* new key_offset */ |
| if (k < j) { | if (k < j) { |
| ch = j - k; /* space requirement */ | ch = j - k; /* space requirement */ |
| block[begadr] = i + ch; /* new key_length */ | block[begadr] = i + ch; /* new key_length */ |
| block[begadr + 1] = k; /* new key_offset */ | block[begadr + 1] = k; /* new key_offset */ |
| i = offset; | i = offset; |
| j = i + ch; | j = i + ch; |
| offset = j; | offset = j; |
| begadr++; | begadr++; |
| while (i > begadr) | while (i > begadr) |
| block[j--] = block[i--]; | block[j--] = block[i--]; |
| stcpy0 (&block[begadr + 1], &key0[k], ch); | stcpy0 (&block[begadr + 1], &key0[k], ch); |
| } | } |
| } | } |
| block[OFFS] = offset / 256; | block[OFFS] = offset / 256; |
| Line 2298 p_empty: /* entry if pointer block goes | Line 2243 p_empty: /* entry if pointer block goes |
| break; | break; |
| zinv: | zinv: |
| { | { |
| long len; | long len; |
| Line 2316 zinv: | Line 2261 zinv: |
| gbl_read_block (g, blknbr, block); | gbl_read_block (g, blknbr, block); |
| addr = UNSIGN (block[OFFS]) * 256 + | addr = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| } | } |
| Line 2391 zinv: | Line 2336 zinv: |
| while ((ch = UNSIGN (scratch[i++])) != g_EOL) { | while ((ch = UNSIGN (scratch[i++])) != g_EOL) { |
| ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ | ch0 = (ch >= SP ? (ch >> 1) : /* 'string' chars */ |
| (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ | (ch < 20 ? (ch >> 1) + '0' : /* 0...9 */ |
| (ch >> 1) + SP)); /* '.' or '-' */ | (ch >> 1) + SP)); /* '.' or '-' */ |
| if (ch0 == DEL) { | if (ch0 == DEL) { |
| Line 2437 zinv: | Line 2382 zinv: |
| case zdata: /* nonstandard data function */ | case zdata: /* nonstandard data function */ |
| { | { |
| long counties[128]; | long counties[128]; |
| char key0[256]; | char key0[256]; |
| int icnt, icnt0, len; | int icnt, icnt0, len; |
| i = 0; | i = 0; |
| while (i < 128) counties[i++] = 0L; /* init count; */ | while (i < 128) counties[i++] = 0L; /* init count; */ |
| if (found == 2) { /* ... advance to next entry */ | if (found == 2) { /* ... advance to next entry */ |
| addr += UNSIGN (block[addr]); | addr += UNSIGN (block[addr]); |
| addr += 2; /* skip key */ | addr += 2; /* skip key */ |
| addr += UNSIGN (block[addr]); | addr += UNSIGN (block[addr]); |
| addr++; /* skip data */ | addr++; /* skip data */ |
| counties[0] = 1L; | counties[0] = 1L; |
| } | } |
| offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); | offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); |
| icnt = 0; | icnt = 0; |
| i = 0; | i = 0; |
| while ((ch = compactkey[i++]) != g_EOL) { | while ((ch = compactkey[i++]) != g_EOL) { |
| if (ch & 01) { | |
| icnt++; | |
| } | |
| if (ch & 01) { | |
| icnt++; | |
| } | } |
| len = i - 1; | } |
| i = 0; | |
| while (i < addr) { /* compute offset complete key */ | len = i - 1; |
| i = 0; | |
| while (i < addr) { /* compute offset complete key */ | |
| icnt0 = UNSIGN (block[i++]); | icnt0 = UNSIGN (block[i++]); |
| icnt0 += (j = UNSIGN (block[i++])); | icnt0 += (j = UNSIGN (block[i++])); |
| while (j < icnt0) key0[j++] = block[i++]; | while (j < icnt0) key0[j++] = block[i++]; |
| key0[j] = g_EOL; | key0[j] = g_EOL; |
| i += UNSIGN (block[i]); | i += UNSIGN (block[i]); |
| i++; /* skip data */ | i++; /* skip data */ |
| } | } |
| for (;;) { /* is it still a descendant ??? */ | for (;;) { /* is it still a descendant ??? */ |
| if (addr >= offset) { /* look in next block */ | if (addr >= offset) { /* look in next block */ |
| if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2])) == 0) { | if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2])) == 0) { |
| break; /* no next block */ | break; /* no next block */ |
| } | } |
| gbl_read_block (g, blknbr, block); | gbl_read_block (g, blknbr, block); |
| addr = 0; | addr = 0; |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| } | } |
| i = UNSIGN (block[addr++]); | i = UNSIGN (block[addr++]); |
| i += (j = UNSIGN (block[addr++])); | i += (j = UNSIGN (block[addr++])); |
| while (j < i) key0[j++] = block[addr++]; | while (j < i) key0[j++] = block[addr++]; |
| addr += UNSIGN (block[addr]); | addr += UNSIGN (block[addr]); |
| addr++; /* skip data */ | addr++; /* skip data */ |
| icnt0 = 0; | icnt0 = 0; |
| i = 0; | i = 0; |
| while (i < j) if (key0[i++] & 01) | while (i < j) if (key0[i++] & 01) |
| icnt0++; | icnt0++; |
| if (icnt0 <= icnt) break; | if (icnt0 <= icnt) break; |
| i = 0; | i = 0; |
| while (i < len) { | while (i < len) { |
| if (key0[i] != compactkey[i]) break; | if (key0[i] != compactkey[i]) break; |
| i++; | i++; |
| } | } |
| if (i < len) break; | if (i < len) break; |
| counties[icnt0 - icnt]++; | counties[icnt0 - icnt]++; |
| } | } |
| i = 128; | i = 128; |
| while (counties[--i] == 0L); | while (counties[--i] == 0L); |
| lintstr (data, counties[0]); | lintstr (data, counties[0]); |
| j = 1; | j = 1; |
| tmp1[0] = ','; | tmp1[0] = ','; |
| while (j <= i) { | while (j <= i) { |
| lintstr (&tmp1[1], counties[j++]); | lintstr (&tmp1[1], counties[j++]); |
| stcat (data, tmp1); | stcat (data, tmp1); |
| } | |
| } | } |
| } | |
| break; | break; |
| case getinc: | case getinc: |
| { | { |
| int setopsav; | int setopsav; |
| setopsav = setop; | setopsav = setop; |
| setop = '+'; | setop = '+'; |
| data[0] = '1'; | data[0] = '1'; |
| data[1] = EOL; | data[1] = EOL; |
| global (set_sym, key, data); | global (set_sym, key, data); |
| setop = setopsav; | setop = setopsav; |
| return; | return; |
| } | } |
| case killone: | case killone: |
| { | |
| { | if (found == 2) goto killo; /* entry found use normal kill routine */ |
| if (found == 2) goto killo; /* entry found use normal kill routine */ | |
| goto quit; | goto quit; |
| } | } |
| case merge_sym: | |
| printf("MERGE NOT IMPLEMENTED FOR GLOBALS\n"); | |
| #ifdef DEBUG_GBL | |
| int loop; | |
| printf ("DEBUG MERGE: "); | |
| printf ("[key] is ["); | |
| for (loop = 0; key[loop] != EOL; loop++) printf ("%c", (key[loop] == DELIM) ? '!' : key[loop]); | |
| printf ("]\r\n"); | |
| printf ("[data] is ["); | |
| for(loop = 0; data[loop] != EOL; loop++) printf ("%c", (data[loop] == DELIM) ? '!' : data[loop]); | |
| printf("]\r\n"); | |
| #endif | |
| return; | |
| default: | default: |
| Line 2628 splitd: /* split data block in two se | Line 2549 splitd: /* split data block in two se |
| if (addr >= offset) { | if (addr >= offset) { |
| long right, | long right, |
| right1, | right1, |
| right2; | right2; |
| right = UNSIGN (block[RLPTR]); | right = UNSIGN (block[RLPTR]); |
| right1 = UNSIGN (block[RLPTR + 1]); | right1 = UNSIGN (block[RLPTR + 1]); |
| Line 2702 splitd: /* split data block in two se | Line 2623 splitd: /* split data block in two se |
| } | } |
| /* other is ***always*** zero !!! | /* other is ***always*** zero !!! |
| * if (other=left*65536+left1*256+left2) up-date RL-PTR of LL-block | * if (other=left*65536+left1*256+left2) up-date RL-PTR of LL-block |
| * { char block0[BLOCKLEN]; | * { char block0[BLOCKLEN]; |
| * lseek(filedes,(long)other*(long)(BLOCKLEN),0); | * lseek(filedes,(long)other*(long)(BLOCKLEN),0); |
| * read(filedes,block0,BLOCKLEN); | * read(filedes,block0,BLOCKLEN); |
| * block0[RLPTR ]=blknbr/65536; | * block0[RLPTR ]=blknbr/65536; |
| * block0[RLPTR+1]=blknbr%65536/256; | * block0[RLPTR+1]=blknbr%65536/256; |
| * block0[RLPTR+2]=blknbr%256; | * block0[RLPTR+2]=blknbr%256; |
| * lseek(filedes,(long)other*(long)(BLOCKLEN),0); | * lseek(filedes,(long)other*(long)(BLOCKLEN),0); |
| * write(filedes,block0,BLOCKLEN); | * write(filedes,block0,BLOCKLEN); |
| * } | * } |
| */ | */ |
| goto spltex; | goto spltex; |
| Line 2794 splitd: /* split data block in two se | Line 2715 splitd: /* split data block in two se |
| /* update rightlink and leftlink pointers */ | /* update rightlink and leftlink pointers */ |
| other = UNSIGN (block[RLPTR]) * 65536 + | other = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| block0[RLPTR] = block[RLPTR]; | block0[RLPTR] = block[RLPTR]; |
| block0[RLPTR + 1] = block[RLPTR + 1]; | block0[RLPTR + 1] = block[RLPTR + 1]; |
| block0[RLPTR + 2] = block[RLPTR + 2]; | block0[RLPTR + 2] = block[RLPTR + 2]; |
| Line 2831 splitd: /* split data block in two se | Line 2752 splitd: /* split data block in two se |
| /* save old block away and make new block the current block */ | /* save old block away and make new block the current block */ |
| /* update rightlink and leftlink pointers */ | /* update rightlink and leftlink pointers */ |
| other = UNSIGN (block[RLPTR]) * 65536 + | other = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| block0[RLPTR] = block[RLPTR]; | block0[RLPTR] = block[RLPTR]; |
| block0[RLPTR + 1] = block[RLPTR + 1]; | block0[RLPTR + 1] = block[RLPTR + 1]; |
| block0[RLPTR + 2] = block[RLPTR + 2]; | block0[RLPTR + 2] = block[RLPTR + 2]; |
| Line 2925 static void splitp (global_handle *g, ch | Line 2846 static void splitp (global_handle *g, ch |
| /* update number of blocks ! */ | /* update number of blocks ! */ |
| i = UNSIGN (block0[NRBLK]) * 65536 + | i = UNSIGN (block0[NRBLK]) * 65536 + |
| UNSIGN (block0[NRBLK + 1]) * 256 + | UNSIGN (block0[NRBLK + 1]) * 256 + |
| UNSIGN (block0[NRBLK + 2]) + 1; | UNSIGN (block0[NRBLK + 2]) + 1; |
| block0[NRBLK] = i / 65536; | block0[NRBLK] = i / 65536; |
| block0[NRBLK + 1] = i % 65536 / 256; | block0[NRBLK + 1] = i % 65536 / 256; |
| Line 2992 static void splitp (global_handle *g, ch | Line 2913 static void splitp (global_handle *g, ch |
| /* update rightlink and leftlink pointers */ | /* update rightlink and leftlink pointers */ |
| other = UNSIGN (block[RLPTR]) * 65536 + | other = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| block0[RLPTR] = block[RLPTR]; | block0[RLPTR] = block[RLPTR]; |
| block0[RLPTR + 1] = block[RLPTR + 1]; | block0[RLPTR + 1] = block[RLPTR + 1]; |
| block0[RLPTR + 2] = block[RLPTR + 2]; | block0[RLPTR + 2] = block[RLPTR + 2]; |
| Line 3028 static void splitp (global_handle *g, ch | Line 2949 static void splitp (global_handle *g, ch |
| /* update rightlink and leftlink pointers */ | /* update rightlink and leftlink pointers */ |
| other = UNSIGN (block[RLPTR]) * 65536 + | other = UNSIGN (block[RLPTR]) * 65536 + |
| UNSIGN (block[RLPTR + 1]) * 256 + | UNSIGN (block[RLPTR + 1]) * 256 + |
| UNSIGN (block[RLPTR + 2]); | UNSIGN (block[RLPTR + 2]); |
| block0[RLPTR] = block[RLPTR]; | block0[RLPTR] = block[RLPTR]; |
| block0[RLPTR + 1] = block[RLPTR + 1]; | block0[RLPTR + 1] = block[RLPTR + 1]; |
| Line 3102 static void update (global_handle *g, ch | Line 3023 static void update (global_handle *g, ch |
| j = oldkeyl - keyl; | j = oldkeyl - keyl; |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| if (j > 0) { /* surplus space */ | if (j > 0) { /* surplus space */ |
| Line 3176 static void insert (global_handle *g, ch | Line 3097 static void insert (global_handle *g, ch |
| gbl_read_block (g, blk, block); | gbl_read_block (g, blk, block); |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| if (traceadr[trx + 1] != (-1)) { | if (traceadr[trx + 1] != (-1)) { |
| addr += UNSIGN (block[addr]); | addr += UNSIGN (block[addr]); |
| Line 3246 static void b_free (global_handle *g, un | Line 3167 static void b_free (global_handle *g, un |
| gbl_read_block (g, free, block0); | gbl_read_block (g, free, block0); |
| other = UNSIGN (block0[RLPTR]) * 65536 + | other = UNSIGN (block0[RLPTR]) * 65536 + |
| UNSIGN (block0[RLPTR + 1]) * 256 + | UNSIGN (block0[RLPTR + 1]) * 256 + |
| UNSIGN (block0[RLPTR + 2]); | UNSIGN (block0[RLPTR + 2]); |
| if (other == 0) break; | if (other == 0) break; |
| Line 3263 static void b_free (global_handle *g, un | Line 3184 static void b_free (global_handle *g, un |
| offset -= PLEN; | offset -= PLEN; |
| other = UNSIGN (block0[offset]) * 65536 + | other = UNSIGN (block0[offset]) * 65536 + |
| UNSIGN (block0[offset + 1]) * 256 + | UNSIGN (block0[offset + 1]) * 256 + |
| UNSIGN (block0[offset + 2]); | UNSIGN (block0[offset + 2]); |
| block0[offset] = 0; | block0[offset] = 0; |
| block0[offset + 1] = 0; | block0[offset + 1] = 0; |
| Line 3388 static void scandblk (char *block, long | Line 3309 static void scandblk (char *block, long |
| char key0[256]; | char key0[256]; |
| offset = UNSIGN (block[OFFS]) * 256 + | offset = UNSIGN (block[OFFS]) * 256 + |
| UNSIGN (block[OFFS + 1]); | UNSIGN (block[OFFS + 1]); |
| while (i < offset) { | while (i < offset) { |
| Line 3716 void gbl_dump_stat(void) | Line 3637 void gbl_dump_stat(void) |
| int hit_pct; | int hit_pct; |
| unsigned long access_total; | unsigned long access_total; |
| unsigned long hit_total; | unsigned long hit_total; |
| unsigned long mem_reads_total; | |
| mem_reads_total = 0; | |
| printf ("\r\nFreeM Global Statistics [PID %d]\r\n\r\n", pid); | printf ("\r\nFreeM Global Statistics [PID %d]\r\n\r\n", pid); |
| printf ("%-20s%-10s%-10s%-10s%-12s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "READS", "WRITES", "SLOW PTHCT", "AGE", "LAST BLK", "FILE"); | printf ("%-20s%-10s%-10s%-10s%-10s%-12s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "READS", "WRITES", "MEMREADS", "SLOW PTHCT", "AGE", "LAST BLK", "FILE"); |
| printf ("%-20s%-10s%-10s%-10s%-12s%-20s%-10s%s\r\n", "======", "=====", "=====", "======", "==========", "===", "========", "===="); | printf ("%-20s%-10s%-10s%-10s%-10s%-12s%-20s%-10s%s\r\n", "======", "=====", "=====", "======", "========", "==========", "===", "========", "===="); |
| access_total = 0; | access_total = 0; |
| ct = 0; | ct = 0; |
| for (g = global_handles_head; g != NULL; g = g->next) { | for (g = global_handles_head; g != NULL; g = g->next) { |
| printf ("%-20s%-10ld%-10ld%-10ld%-12ld%-20ld%-10ld%s\r\n", | printf ("%-20s%-10ld%-10ld%-10ld%-10ld%-12ld%-20ld%-10ld%s\r\n", |
| g->global_name, | g->global_name, |
| g->use_count, | g->use_count, |
| g->read_ops, | g->read_ops, |
| g->write_ops, | g->write_ops, |
| g->memory_reads, | |
| g->cache_misses, | g->cache_misses, |
| g->age, | g->age, |
| g->last_block, | g->last_block, |
| g->global_path); | g->global_path); |
| ct++; | ct++; |
| mem_reads_total += g->memory_reads; | |
| access_total += g->use_count; | access_total += g->use_count; |
| } | } |
| if (!ct) printf ("<no globals opened in this pid>\r\n"); | if (!ct) printf ("<no globals opened in this pid>\r\n"); |
| Line 3745 void gbl_dump_stat(void) | Line 3670 void gbl_dump_stat(void) |
| printf ("\r\nTotal accesses: %ld\r\n", access_total); | printf ("\r\nTotal accesses: %ld\r\n", access_total); |
| printf ("Fast path hits %ld\t(%d%%)\r\n", hit_total, hit_pct); | printf ("Fast path hits %ld\t(%d%%)\r\n", hit_total, hit_pct); |
| printf ("Fast path misses: %ld\t(%d%%)\r\n", gbl_cache_misses, miss_pct); | printf ("Fast path misses: %ld\t(%d%%)\r\n", gbl_cache_misses, miss_pct); |
| printf ("Disk reads avoided: %ld\r\n", mem_reads_total); | |
| } | } |