Diff for /freem/src/routine.c between versions 1.7 and 1.10

version 1.7, 2025/04/30 14:41:03 version 1.10, 2025/05/01 03:56:29
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.10  2025/05/01 03:56:29  snw
    *   -m
    *
    *   Revision 1.9  2025/04/30 20:03:09  snw
    *   Work on entryref parser
    *
    *   Revision 1.8  2025/04/30 17:19:16  snw
    *   Improve backtraces in debugger
    *
  *   Revision 1.7  2025/04/30 14:41:03  snw   *   Revision 1.7  2025/04/30 14:41:03  snw
  *   Further debugger work   *   Further debugger work
  *   *
Line 1148  void lineref (char **adrr) Line 1157  void lineref (char **adrr)
     return;      return;
 }                                       /* end of lineref() */  }                                       /* end of lineref() */
   
 #if 0  char *m_text(char *lref, char *buf)
 char *routine_get_line(char *lref, char *buf)  
 {  {
     char tmp[STRLEN];      char *old_codptr;
     char a[STRLEN];      char old_code[STRLEN];
     long l1, rouoldc;  
     short reload = FALSE;  
     int f = 3;  
     register int i;  
     register int j;  
           
     i = 0;      old_codptr = codptr;
                               stcpy (old_code, code);
     if (f > 1) {      
         stcpy (tmp, lref[arg + 1]);      sprintf (code, "$TEXT(%s)\201", lref);
         i = intexpr (tmp);      codptr = code;
     }      
       expr (STRING);
     if (a[0] == EOL) {  
   
         if (i < 0) {  
             return (char *) NULL;  
         }  
   
         /* $T(+0) returns routine name */  
         if (i == 0) {  
   
             if (f != 3) {  
                 stcpy (a, rou_name);  
             }   
             else {  
                 stcpy (a, argstck[arg + 2]);  
             }                                  
   
             goto nxt_operator;  
   
         }  
   
       if (merr () != OK) {
           stcpy (code, old_code);
           codptr = old_codptr;
           return (char *) NULL;
     }      }
   
     if (f == 3) {      stcpy (buf, argptr);
       stcpy (code, old_code);
       codptr = old_codptr;
   
         reload = TRUE;  /* load routine; */      return buf;
         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;  /* routine_get_line()
             }   *  char *entryref:  [cstr/in] M entryref
    *  char *buf:   [cstr/out] buffer to contain resulting line
    *
    *  returns a pointer to buf [cstr] on success; otherwise NULL */
   char *routine_get_line(char *entryref, char *buf)
   {
       FILE *fp;
       char routine_path[PATHLEN];
       
       char *routine_p;
       char *label_p;
       char *offset_p;
   
       short have_label = FALSE;
       short have_offset = FALSE;
       
       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;
   
             return;      register int i;
       register int j;
       char ch;
   
         }      short in_tag = FALSE;
       
       /*
        * entryref can be:
        *  +0 (returns rou_name)
        *  label
        *  ^routine
        *  +offset
        *  +offset^routine
        *  label^routine
        *  label+offset^routine
        */
   
       /* handle +0 */
       if (strcmp (entryref, "+0") == 0) {
           stcpy (buf, rou_name);
           stcnv_m2c (buf);
           return buf;
     }      }
   
     j = 0;      if ((routine_p = strchr (entryref, '^')) != NULL) {
     f = 1;          /* have a routine */
                                   stcpy (r, routine_p);
     if (a[0] != EOL) {  /* 1st arg == label */          stcnv_m2c (r);
           
           if ((entryref[0] != '^') && (isalpha (entryref[0]))) {
               /* we have a label */
               char ch;
               char *src;
               char *dst;
               
               src = entryref;
               dst = l;
   
         for (;;) {              while (((ch = *src++) != '\0') && (ch != '^') && (ch != '+')) {
                                           *dst++ = ch;
             if (j >= (rouend - rouptr)) {  
                 a[0] = EOL;  
                 goto t_end;  
             }              }
               *dst = '\0';
             l1 = j;              have_label = TRUE;
             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 */  
   
         }          }
   
         f = 0;  
   
     }      }
       else {
     if (i > 0) {          /* no routine implies current routine */
           stcpy (r, rou_name);
         while (f < i) {          stcnv_m2c (r);
   
             if ((j = j + (UNSIGN (*(rouptr + j))) + 2) >= (rouend - rouptr)) {  
                 a[0] = EOL;  
                 goto t_end;  
             }  
                                   
             f++;  
   
         }  
   
     }      }
   
     if (i < 0) {      if (r[0] == '^') {
           strcpy (txtbuf, &(r[1]));
         j--;          strcpy (r, txtbuf);
                               
         while (f != i) {  
   
             while (*(rouptr + (--j)) != EOL && j >= 0);  
                                   
             if (--f != i && j < 1) {  
                 a[0] = EOL;  
                 goto t_end;  
             }  
   
         }  
   
         j++;  
   
     }      }
       
     f = (-1);      if (rtn_get_path (r, routine_path) == FALSE) {
     j++;          sprintf (buf, "");
           return NULL;
     while ((a[++f] = (*(rouptr + (j++)))) != EOL) {  
         if (a[f] == TAB || a[f] == SP)  
             break;  
     }      }
   
     if (j >= (rouend - rouptr - 1)) {      if ((fp = fopen (routine_path, "r")) == NULL) {
         a[0] = EOL;          sprintf (buf, "");
     }           return NULL;
       }
           
       if ((offset_p = strchr (entryref, '+')) != NULL) {
           stcpy (o, offset_p + 1);
           os = atoi (o);
           sprintf (o, "%d\0", os);
           have_offset = TRUE;
       }
     else {      else {
           have_offset = FALSE;
           os = 1;
       }
   
         a[f] = SP;      in_tag = FALSE;
                                   cur_offset = 0;
         while ((*(rouptr + j)) == TAB || (*(rouptr + j)) == SP) {      while (fgets (line, sizeof (line) - 1, fp) != NULL) {       
             j++;  
             a[++f] = SP;          if (!have_label && !have_offset) {
               strcpy (buf, line);
               fclose (fp);
               return buf;
         }          }
           
           if (isalpha (line[0]) && !isblank (line[0])) {
               j = 0;
   
         stcpy (&a[++f], rouptr + j);              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++;
   
 t_end:              if (in_tag && (cur_offset == os)) {
     if (reload) {                  strcpy (buf, line);
         zload (rou_name);                  fclose (fp);
         roucur = rouptr + rouoldc;                  return buf;
     }           /* reload routine; */              }
           }        
           
       }
   
       fclose (fp);
       return FALSE;
   
 }  }
 #endif  

Removed from v.1.7  
changed lines
  Added in v.1.10


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