version 1.19, 2025/04/11 16:52:05
|
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 |
* Revision 1.19 2025/04/11 16:52:05 snw |
* Fix indentation in global handler |
* Fix indentation in global handler |
* |
* |
Line 105 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 |
Line 309 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 334 int gbl_write_header(global_handle *g, g
|
Line 304 int gbl_write_header(global_handle *g, g
|
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 499 int gbl_read_block(global_handle *g, uns
|
Line 469 int gbl_read_block(global_handle *g, uns
|
|
|
g->use_count++; |
g->use_count++; |
|
|
fstat (g->fd, &gstat); |
|
if (!g->locked) gbl_lock (g, 1); |
if (!g->locked) gbl_lock (g, 1); |
|
fstat (g->fd, &gstat); |
|
|
if ((g->last_block == blocknum) && |
if ((g->last_block == blocknum) && |
(g->have_cached_block) && |
(g->have_cached_block) && |
Line 509 int gbl_read_block(global_handle *g, uns
|
Line 478 int gbl_read_block(global_handle *g, uns
|
(gstat.st_mtime < g->last_read_time)) { |
(gstat.st_mtime < g->last_read_time)) { |
/* the global has not been modified since the last read; grab from memory */ |
/* the global has not been modified since the last read; grab from memory */ |
g->memory_reads++; |
g->memory_reads++; |
g->last_read_time = time (0L); |
|
memcpy (block, g->last_block_accessed, g->header.block_size); |
memcpy (block, g->last_block_accessed, g->header.block_size); |
} |
} |
else { |
else { |
Line 520 int gbl_read_block(global_handle *g, uns
|
Line 488 int gbl_read_block(global_handle *g, uns
|
/* update cache */ |
/* update cache */ |
memcpy (g->last_block_accessed, block, g->header.block_size); |
memcpy (g->last_block_accessed, block, g->header.block_size); |
g->have_cached_block = TRUE; |
g->have_cached_block = TRUE; |
g->last_read_time = time (0L); |
g->cached_block_num = blocknum; |
g->cached_block_num = blocknum; |
|
|
|
g->last_block = blocknum; |
g->last_block = blocknum; |
g->use_count++; |
|
g->read_ops++; |
g->read_ops++; |
} |
} |
|
|
|
g->last_read_time = time (0L); |
|
g->use_count++; |
|
|
if (g->locked) gbl_unlock (g); |
if (g->locked) gbl_unlock (g); |
|
|
return TRUE; |
return TRUE; |
Line 550 int gbl_write_block(global_handle *g, un
|
Line 518 int gbl_write_block(global_handle *g, un
|
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 748 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 887 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 967 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 1043 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 1127 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 1158 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 1175 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 1184 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 1194 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 1208 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 2604 s10:
|
Line 2513 s10:
|
} |
} |
|
|
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: |
|
|
merr_raise (INVREF); /* accidental call with wrong action code (v22-stuff) */ |
merr_raise (INVREF); /* accidental call with wrong action code (v22-stuff) */ |