--- freem/src/routine.c 2025/04/30 20:03:09 1.9 +++ freem/src/routine.c 2025/05/06 15:18:55 1.11 @@ -1,5 +1,5 @@ /* - * $Id: routine.c,v 1.9 2025/04/30 20:03:09 snw Exp $ + * $Id: routine.c,v 1.11 2025/05/06 15:18:55 snw Exp $ * Routine buffer management * * @@ -24,6 +24,12 @@ * along with FreeM. If not, see . * * $Log: routine.c,v $ + * Revision 1.11 2025/05/06 15:18:55 snw + * Remove isblank call from routine.c to fix broken Solaris 8 build + * + * Revision 1.10 2025/05/01 03:56:29 snw + * -m + * * Revision 1.9 2025/04/30 20:03:09 snw * Work on entryref parser * @@ -1189,15 +1195,9 @@ char *m_text(char *lref, char *buf) * returns a pointer to buf [cstr] on success; otherwise NULL */ char *routine_get_line(char *entryref, char *buf) { - char tmp[STRLEN]; - char a[STRLEN]; - long l1, rouoldc; - short reload = FALSE; - char f; - - register int i; - register int j; - + FILE *fp; + char routine_path[PATHLEN]; + char *routine_p; char *label_p; char *offset_p; @@ -1208,7 +1208,18 @@ char *routine_get_line(char *entryref, c char r[256]; char l[256]; char o[256]; + char txtbuf[256]; + char line[2048]; + int curline; + char curtag[256]; + int cur_offset; int os; + + register int i; + register int j; + char ch; + + short in_tag = FALSE; /* * entryref can be: @@ -1231,161 +1242,107 @@ char *routine_get_line(char *entryref, c if ((routine_p = strchr (entryref, '^')) != NULL) { /* have a routine */ stcpy (r, routine_p); - printf ("routine = %s\r\n", r); + stcnv_m2c (r); + + if ((entryref[0] != '^') && (isalpha (entryref[0]))) { + /* we have a label */ + char ch; + char *src; + char *dst; + + src = entryref; + dst = l; + + while (((ch = *src++) != '\0') && (ch != '^') && (ch != '+')) { + *dst++ = ch; + } + *dst = '\0'; + have_label = TRUE; + } } else { /* no routine implies current routine */ - stcpy (r, rou_name); + stcpy (r, rou_name); + stcnv_m2c (r); + } + + if (r[0] == '^') { + strcpy (txtbuf, &(r[1])); + strcpy (r, txtbuf); + } + + if (rtn_get_path (r, routine_path) == FALSE) { + sprintf (buf, ""); + return NULL; } + if ((fp = fopen (routine_path, "r")) == NULL) { + sprintf (buf, ""); + return NULL; + } + if ((offset_p = strchr (entryref, '+')) != NULL) { stcpy (o, offset_p + 1); os = atoi (o); - sprintf (o, "%d\201\0", os); - printf ("offset = %s\r\n", o); + sprintf (o, "%d\0", os); have_offset = TRUE; } else { have_offset = FALSE; + os = 1; } - return NULL; - i = 0; - - if (f > 1) { - stcpy (tmp, entryref); - i = intexpr (tmp); - } - - if (i < 0) return (char *) NULL; - - /* $T(+0) returns routine name */ - if (i == 0) { - stcpy (buf, rou_name); - } - - if (f == 3) { - - reload = TRUE; /* load routine; */ - f = mcmnd; - mcmnd = 'd'; /* make load use standard-path */ - - stcpy (tmp, argstck[arg + 2]); - - rouoldc = roucur - rouptr; - - zload (tmp); - - mcmnd = f; - - if (merr () > OK) { - - zload (rou_name); - - if (merr () == NOPGM) { - ierr -= NOPGM; /* smw 15 nov 2023 TODO HUH?? */ - *a = EOL; - - /*goto nxt_operator;*/ - } - - return NULL; - - } - - } - - j = 0; - f = 1; - - if (a[0] != EOL) { /* 1st arg == label */ - - for (;;) { - - if (j >= (rouend - rouptr)) { - a[0] = EOL; - goto t_end; - } - - l1 = j; - f = 0; - - while (*(rouptr + (++l1)) == a[f++]); - - if (a[--f] == EOL && (*(rouptr + l1) == TAB || *(rouptr + l1) == SP || *(rouptr + l1) == '(')) break; - - j += (UNSIGN (*(rouptr + j)) + 2); /* skip line */ + in_tag = FALSE; + cur_offset = 0; + while (fgets (line, sizeof (line) - 1, fp) != NULL) { + if (!have_label && !have_offset) { + strcpy (buf, line); + fclose (fp); + return buf; } + + if ((isalpha (line[0])) && (line[0] != ' ') && (line[0] != '\t')) { + j = 0; - f = 0; - - } - - if (i > 0) { - - while (f < i) { - - if ((j = j + (UNSIGN (*(rouptr + j))) + 2) >= (rouend - rouptr)) { - a[0] = EOL; - goto t_end; - } - - f++; + for (i = 0; i < strlen (line); i++) { + ch = line[i]; + if ((!isalpha (ch)) && (!isdigit (ch))) { + curtag[j] = '\0'; + cur_offset = 0; + if (have_label && (strcmp (curtag, l) == 0)) { + in_tag = TRUE; + if (!have_offset) { + strcpy (buf, line); + fclose (fp); + return buf; + } + } + else { + in_tag = FALSE; + } + break; + } + else { + curtag[j++] = ch; + } + } } + else { + cur_offset++; - } - - if (i < 0) { - - j--; - - while (f != i) { - - while (*(rouptr + (--j)) != EOL && j >= 0); - - if (--f != i && j < 1) { - a[0] = EOL; - goto t_end; + if (in_tag && (cur_offset == os)) { + strcpy (buf, line); + fclose (fp); + return buf; } - - } - - j++; - - } - - f = (-1); - j++; - - while ((a[++f] = (*(rouptr + (j++)))) != EOL) { - if (a[f] == TAB || a[f] == SP) - break; - } - - if (j >= (rouend - rouptr - 1)) { - a[0] = EOL; - } - else { - - a[f] = SP; - - while ((*(rouptr + j)) == TAB || (*(rouptr + j)) == SP) { - j++; - a[++f] = SP; - } - - stcpy (&a[++f], rouptr + j); - + } + } -t_end: - if (reload) { - zload (rou_name); - roucur = rouptr + rouoldc; - } /* reload routine; */ - + fclose (fp); + return FALSE; }