Diff for /freem/src/routine.c between versions 1.6 and 1.9

version 1.6, 2025/04/13 04:22:43 version 1.9, 2025/04/30 20:03:09
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.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
    *   Further debugger work
    *
  *   Revision 1.6  2025/04/13 04:22:43  snw   *   Revision 1.6  2025/04/13 04:22:43  snw
  *   Fix snprintf calls   *   Fix snprintf calls
  *   *
Line 1144  void lineref (char **adrr) Line 1153  void lineref (char **adrr)
           
     return;      return;
 }                                       /* end of lineref() */  }                                       /* end of lineref() */
   
   char *m_text(char *lref, char *buf)
   {
       char *old_codptr;
       char old_code[STRLEN];
       
       old_codptr = codptr;
       stcpy (old_code, code);
       
       sprintf (code, "$TEXT(%s)\201", lref);
       codptr = code;
       
       expr (STRING);
   
       if (merr () != OK) {
           stcpy (code, old_code);
           codptr = old_codptr;
           return (char *) NULL;
       }
   
       stcpy (buf, argptr);
       stcpy (code, old_code);
       codptr = old_codptr;
   
       return buf;
   }
       
   
   
   /* 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)
   {
       char tmp[STRLEN];
       char a[STRLEN];
       long l1, rouoldc;
       short reload = FALSE;
       char f;
   
       register int i;
       register int j;
   
       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];
       int os;
       
       /*
        * 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;
       }
   
       if ((routine_p = strchr (entryref, '^')) != NULL) {
           /* have a routine */
           stcpy (r, routine_p);
           printf ("routine = %s\r\n", r);
       }
       else {
           /* no routine implies current routine */
           stcpy (r, rou_name);        
       }
   
       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);
           have_offset = TRUE;
       }
       else {
           have_offset = FALSE;
       }
   
       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 */
   
           }
   
           f = 0;
   
       }
   
       if (i > 0) {
   
           while (f < i) {
   
               if ((j = j + (UNSIGN (*(rouptr + j))) + 2) >= (rouend - rouptr)) {
                   a[0] = EOL;
                   goto t_end;
               }
                                   
               f++;
   
           }
   
       }
   
       if (i < 0) {
   
           j--;
                               
           while (f != i) {
   
               while (*(rouptr + (--j)) != EOL && j >= 0);
                                   
               if (--f != i && j < 1) {
                   a[0] = EOL;
                   goto t_end;
               }
   
           }
   
           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; */
   
   
   }
   

Removed from v.1.6  
changed lines
  Added in v.1.9


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