Commit d0362562 authored by John P. Willis's avatar John P. Willis
Browse files

Bug fixes

parent e2f4f861
Pipeline #729 passed with stage
in 1 minute and 27 seconds
......@@ -37,9 +37,6 @@
; You should have received a copy of the GNU Affero Public License
; along with FreeM. If not, see <https://www.gnu.org/licenses/>.
;
D ^%ZMAINT
;W " PID: ",$J,!
;W " Principal I/O: ",$PRINCIPAL,!,!
CONST %MATH.PI=3.141592653589793238462
CONST %MATH.E=2.71828182845904523536
CONST %MATH.GAMMA=0.57721566490153286060
......
......@@ -43,7 +43,7 @@
ll_constant *const_head;
short const_define(char *key)
short const_define(char *key, char *data)
{
ll_constant *t;
......@@ -61,8 +61,12 @@ short const_define(char *key)
t->key = (char *) malloc (stlen (key) + 1);
NULLPTRCHK(t->key,"const_define");
t->data = (char *) malloc (stlen (data) + 1);
NULLPTRCHK(t->data,"const_define");
stcpy (t->key, key);
stcpy (t->data, data);
t->next = const_head;
const_head = t;
......@@ -79,3 +83,18 @@ short const_is_defined(char *key)
return 0;
}
void const_restore(void)
{
ll_constant *t;
restoring_consts = TRUE;
for (t = const_head; t != NULL; t = t->next) {
symtab (set_sym, t->key, t->data);
}
restoring_consts = FALSE;
return;
}
......@@ -37,10 +37,13 @@
*
**/
#if !defined(__FREEM_CONSTTBL_H)
# define __FREEM_CONSTTBL_H
typedef struct ll_constant {
char *key;
char *data;
struct ll_constant *next;
......@@ -48,6 +51,10 @@ typedef struct ll_constant {
extern ll_constant *const_head;
extern short const_define(char *key);
extern short const_define(char *key, char *data);
extern short const_is_defined(char *key);
extern void const_restore(void);
extern short restoring_consts;
#endif
......@@ -53,6 +53,7 @@
#include "iniconf.h"
int fma_do_export (FILE *out, char *rtn_name);
char *fma_trim_string(char *str);
int fma_routines_list (int optc, char **opts)
{
......@@ -221,6 +222,25 @@ int fma_routines_restore (int optc, char **opts)
return 0;
}
char *fma_trim_string(char *str)
{
char *end;
while (isspace ((unsigned char) *str)) str++;
if (*str == NULL) return str;
end = str + strlen (str) - 1;
while (end > str && isspace ((unsigned char) *end)) end--;
end[1] = '\0';
return str;
}
int fma_routines_import (int optc, char **opts)
{
int usr_loaded = 0;
......@@ -235,11 +255,14 @@ int fma_routines_import (int optc, char **opts)
char namespace[4096];
char roufile[4096];
char line[STRLEN];
char *trimmed_line;
char filename[4096];
FILE *archive = NULL;
FILE *rtn = NULL;
char *parsed_line;
strncpy (namespace, fma_namespace, 512 - 1);
strncpy (filename, opts[1], 4096 - 1);
......@@ -283,23 +306,25 @@ int fma_routines_import (int optc, char **opts)
printf ("%% Routine Path: %s\n\n", pct_rtn_path);
/* read routine archive line-by-line */
while(fgets(line, STRLEN - 1, archive) != NULL) {
while (fgets(line, STRLEN - 1, archive) != NULL) {
if(line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0';
if (line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0';
ln++;
if((ln == 1) || (ln == 2)) {
if ((ln == 1) || (ln == 2)) {
printf("%s\n", line);
continue;
}
if(ln == 3) {
if (ln == 3) {
next_routine_flag = TRUE;
}
if(strcmp(line, "") == 0) {
trimmed_line = strdup (line);
if (strcmp (fma_trim_string (trimmed_line), "") == 0) {
next_routine_flag = TRUE;
if(rtn_open == TRUE) {
......@@ -310,11 +335,13 @@ int fma_routines_import (int optc, char **opts)
continue;
}
if(next_routine_flag == TRUE) {
next_routine_flag = FALSE;
parsed_line = strtok (line, "^");
if((!isalpha(line[0])) && (line[0] != '%')) {
if(rtn_open == TRUE) {
......@@ -325,20 +352,21 @@ int fma_routines_import (int optc, char **opts)
continue;
}
printf(" %s\n", line);
printf(" %s\n", parsed_line);
switch(line[0]) {
case '%':
pct_loaded++;
snprintf(roufile, PATH_MAX, "%s/%s.m", pct_rtn_path, line);
snprintf(roufile, PATH_MAX, "%s/%s.m", pct_rtn_path, parsed_line);
break;
default:
usr_loaded++;
snprintf(roufile, PATH_MAX, "%s/%s.m", usr_rtn_path, line);
snprintf(roufile, PATH_MAX, "%s/%s.m", usr_rtn_path, parsed_line);
break;
}
......
......@@ -475,6 +475,7 @@ void stcpy0 ();
void stcpy1 ();
short int stcat ();
short int stcmp ();
char *trim (char *s);
void stcnv_m2c (char *mstr);
void stcnv_c2m (char *cstr);
size_t key_to_name (char *buf, const char *key, size_t count);
......
......@@ -180,15 +180,6 @@ void set_namespace(char *ns, int verbose)
jour_end:
/* clear private buffer */
for(i = 0; i < 256; i++) ns_buf[i] = NUL;
if(get_conf("SYSTEM", "hardcopy_file", ns_buf) == TRUE) {
stcnv_c2m(ns_buf);
hcpyfile[stcpy (hcpyfile, ns_buf)] = NUL;
}
/* clear private buffer */
for(i = 0; i < 256; i++) ns_buf[i] = NUL;
......
......@@ -5324,354 +5324,6 @@ try:
} /* end of zsave() */
/* execution of the LOCK command
*
* lockarg:
* lockarg[0] = lockmode
* SP=normal
* '+'=incremental
* '-'=decremental
* &lockarg[1]=name(s) to be (un)locked
*
* type:
* l=LOCK, A=ZALLOCATE, D=ZDEALLOCATE, j=JOB (clear nolocks flag)
*
*/
void lock_OLD (char *lockarg, long time_out, char type)
{
/* nolocks and noallox are TRUE if */
/* the respective table is guaranteed */
/* to contain no entries for the current job */
static short nolocks = TRUE; /* empty flag locks */
static short noallox = TRUE; /* empty flag allocates */
short ltab; /* file descr. for locktab */
int cpid;
short scoop; /* flag to retain entries */
char entry[256];
long int r_pos; /* position to read */
long int w_pos; /* position to write */
int i,
j;
int found;
/* after JOB our table is supposed to be empty of PIDs entries */
if (type == 'j') {
nolocks = TRUE;
noallox = TRUE;
return;
}
/* after SET $JOB the table is possibly not empty of PIDs entries */
if (type == 's') {
nolocks = FALSE;
noallox = FALSE;
return;
}
if (lockarg[1] == EOL) { /* free LOCKs in empty table: nothing to do! */
if (type == 'l') {
if (nolocks) return;
}
else {
if (noallox) return;
}
}
/* if 'locktab' does not exist, create it */
for (;;) {
errno = 0;
if ((ltab = open (type == 'l' ? locktab : zallotab, 2)) != -1) break;
if (errno == EINTR) continue; /* signal interrupt */
if (errno == ENOENT) {
if (lockarg[1] == EOL) return; /* nothing to do */
ltab = creat (type == 'l' ? locktab : zallotab, 0666);
if (errno == EMFILE || errno == ENFILE) {
close_all_globals ();
ltab = creat (type == 'l' ? locktab : zallotab, 0666);
}
if (ltab == -1) {
ierr = PROTECT;
return;
}
}
entry[0] = 0;
entry[1] = 0; /* zero word is terminator of locktab */
lseek (ltab, 0L, 0);
write (ltab, entry, 2);
close (ltab);
if (ierr == INRPT) return;
}
/* request exclusive access to locktab (read & write) */
locking (ltab, 1, 0L);
/* free all of your own locks; we do it by copying the whole stuff */
/* within 'locktab' omitting the old entries under our PID */
j = 0; /* count your old entries */
lseek (ltab, 0L, 0);
w_pos = 0L;
for (;;) {
read (ltab, entry, 2);
cpid = UNSIGN (entry[0]) * 256 + UNSIGN (entry[1]);
if (cpid == 0) {
lseek (ltab, w_pos, 0);
write (ltab, entry, 2);
break;
}
i = 1;
do {
read (ltab, &entry[++i], 1);
} while (entry[i] != EOL);
i++;
scoop = FALSE;
if (cpid != pid) {
scoop = TRUE;
}
else if (entry[2] != type) {
scoop = TRUE;
}
else if (lockarg[0] == '+') {
scoop = TRUE;
}
else if (lockarg[0] == '-') {
int k;
k = 0;
if ((found = find (&lockarg[1], &entry[3]))) {
while (lockarg[found + k] == entry[3 + k]) k++;
}
if (k && (lockarg[found + k] == 1)) {
lockarg[found] = '!';
}
else {
/* unlock only once */
scoop = TRUE;
}
}
else if (type == 'D' && lockarg[1] != EOL && stcmp (&lockarg[1], &entry[3])) {
scoop = TRUE;
}
if (scoop) {
if (j) {
r_pos = tell (ltab);
lseek (ltab, w_pos, 0);
write (ltab, entry, (unsigned) i);
lseek (ltab, r_pos, 0);
}
w_pos += i;
}
if (cpid == pid) j++;
}
locking (ltab, 0, 0L);
close (ltab);
if (lockarg[1] == EOL) { /* it was an argumentless LOCK */
if (type == 'l') {
nolocks = TRUE;
}
else {
noallox = TRUE;
}
return;
}
if (lockarg[0] == '-') { /* it was a decremental LOCK */
if (time_out >= 0L) test = TRUE;
return;
} /* always TRUE */
if (type == 'D') return; /* it was a ZDEALLOCATE */
if (type == 'l') {
nolocks = FALSE; /* reset empty flag */
}
else {
noallox = FALSE;
}
for (;;) { /* request 'locktab' */
while ((ltab = open (type == 'l' ? locktab : zallotab, 2)) == -1) ;
locking (ltab, 1, 0L);
lseek (ltab, 0L, 0);
/* if (requested entries are not in 'locktab') break; */
for (;;) {
if (read (ltab, entry, 2) < 2) break; /* pid */
if ((cpid = UNSIGN (entry[0]) * 256 + UNSIGN (entry[1])) == 0) break;
i = 0;
while (read (ltab, &entry[i], 1) == 1 && entry[i] != EOL) i++;
if (cpid == pid) continue; /* ZALLOCATE !! */
j = 1;
while (lockarg[j] != EOL) {
i = 1;
while (lockarg[j] == entry[i]) {
if (entry[i] == EOL) break;
i++;
j++;
}
/* 01/18/99 rlf Not sure if this is a libc-6 issue or not, but compiler */
/* was throwing a warning about each of the lockarg[j]>DEL */
/* comparisons, saying "warning:comparison is always 0 due */
/* to a limited range of data types". */
#ifdef LINUX_GLIBC
if ((lockarg[j]<2 || UNSIGN(lockarg[j])>DEL) && (entry[i]<2 || UNSIGN(entry[i])>DEL)) goto found;
#else
if ((lockarg[j]<2 || lockarg[j]>DEL) && (entry [i]<2 || entry [i]>DEL)) goto found;
#endif /* LINUX_GLIBC */
while (lockarg[j++] != 1); /* skip to next piece */
}
if (ierr == INRPT) {
locking (ltab, 0, 0L);
close (ltab);
return;
}
}
w_pos = tell (ltab) - 2;
goto notfound;
found: /* release and wait if timeout not expired */
locking (ltab, 0, 0L);
close (ltab);
if (time_out >= 0L) {
if (--time_out < 0L) {
test = FALSE;
return;
}
}
if (ierr == INRPT) return;
sleep (1);
}
notfound: /* enter your own entries and release 'locktab' */
i = w_pos;
i = 1;
lseek (ltab, w_pos, 0);
while (lockarg[i] != EOL) {
entry[0] = pid / 256;
entry[1] = pid % 256;
entry[2] = type == 'l' ? 'l' : 'D';
write (ltab, entry, 3);
j = i;
while (lockarg[++i] != 1);
lockarg[i++] = EOL;
write (ltab, &lockarg[j], (unsigned) (i - j));
}
entry[0] = 0;
entry[1] = 0;
write (ltab, entry, 2); /* zero pid as terminator */
locking (ltab, 0, 0L);
close (ltab);
if (time_out >= 0L) test = TRUE;
return;
} /* end of lock */
/******************************************************************************/
/*
* getraddress(char *a, short lvl):
......
......@@ -115,6 +115,8 @@ void ssvn_job_update(void)
int gid = 0;
#endif
int ierr_sav = ierr;
snprintf (k_buf, 512 - 1, "^$JOB\202%d\202ZCOMMANDS\201", pid);
stcpy (d_buf, zcommds);
global (set_sym, k_buf, d_buf);
......@@ -320,6 +322,8 @@ void ssvn_job_update(void)
#endif
ierr = ierr_sav;
}
......
......@@ -121,6 +121,43 @@ short int stcmp (char *str1, char *str2)
return *str1 - *str2;
}
/* trim whitespace from string 's' */
char *trim (char *s)
{
char *t = strdup (s);
char *end;
char *result;
int final_len;
if (t == NULL) return NULL;
while (isspace ((unsigned char) *t)) t++;
if (*t == NULL) return t;
end = t + strlen (t) - 1;
while (end > t && isspace ((unsigned char) *end)) end--;
end[1] = '\0';
/* recover waste ('t' still occupies the same heap
* as it did before the whitespace was stripped)
*/
final_len = strlen (t);
result = (char *) malloc (final_len * sizeof (char));