Beispiel #1
0
char    *scr_single_func_e( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;

    end   = end;

    pchar = scan_sym( in + 3 + (*(in + 3) == '&'), &symvar_entry, &var_ind );

    if( symvar_entry.flags & local_var ) {  // lookup var in dict
        rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                            var_ind, &symsubval );
    } else {
        rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                          &symsubval );
    }
    if( rc == 2 ) {
        **result = '1';                 // exists
    } else {
        **result = '0';                 // does not exist
    }
    *result  += 1;
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Beispiel #2
0
static char * subst_1var( char * pout, char * pvar, size_t len )
{
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    char            *   pchar;

    ProcFlags.suppress_msg = true;
    scan_err = false;

    pchar = scan_sym( pvar, &symvar_entry, &var_ind );
    ProcFlags.suppress_msg = false;
    if( !scan_err ) {
        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                              var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            pchar = symsubval->value;
            while( *pchar ) {
                *pout++ = *pchar++;
            }
        }
    }
    *pout = '\0';
    return( pout );
}
Beispiel #3
0
char    *scr_single_func_w( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    int                 len;
    uint32_t            width;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            width = cop_text_width( symsubval->value, strlen( symsubval->value ), g_curr_font);
        } else {

        /*******************************************************************/
        /* for undefined variable calc length of name, & and perhaps *     */
        /*******************************************************************/
            width = cop_text_width( symvar_entry.name, strlen( symvar_entry.name ), g_curr_font )
                    + wgml_fonts[g_curr_font].width_table['&'];

            if( symvar_entry.flags & local_var ) {  // add width of *
                width += wgml_fonts[g_curr_font].width_table['*'];
            }
        }
    } else {                            // string
        pchar = in + 3;
        len = 0;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            len++;
            pchar++;
        }
        width = cop_text_width( in + 3, len, g_curr_font );
    }
    len = width;
    width = (width * CPI + g_resh / 2) / g_resh;
    sprintf( *result, "%d", width );
#if 0                                   // perhaps as debug output
    sprintf( *result + strlen( *result ), " %d", len );
#endif
    *result  += strlen( *result );
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Beispiel #4
0
char    *scr_single_func_sS( char * in, char * end, char * * result, char fun )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    char            *   pval;


    **result = function_escape;         // insert function code in buffer
    *result += 1;
    **result = fun;
    *result += 1;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            pval = symsubval->value;    // variable  found
        } else {
            pval =  symvar_entry.name;  // not found use variable name
        }
        while( *pval ) {
            **result = *pval++;
            *result += 1;
        }
    } else {                            // string
        pchar = in + 3;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            **result = *pchar++;
            *result += 1;
        }
    }
    **result = function_escape;         // insert function code in buffer
    *result += 1;
    **result = fun | 0x01;              // function end
    *result += 1;
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Beispiel #5
0
char    *scr_single_func_l( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    int                 len;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            sprintf( *result, "%d", strlen( symsubval->value ) );
        } else {
            sprintf( *result, "%d", strlen( symvar_entry.name ) );
        }
    } else {                            // string
        pchar = in + 3;
        len = 0;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            len++;
            pchar++;
        }
        sprintf( *result, "%d", len );
    }
    *result  += strlen( *result );
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Beispiel #6
0
static  condcode    scr_veclp( parm parms[MAX_FUN_PARMS], size_t parmcount,
                               char * * result, int32_t ressize )
{
    char            *   pneedle;
    char            *   pneedlend;
    char            *   phay;
    char            *   phayend;
    int                 rc;
    int                 index;
    int                 hay_len;
    int                 needle_len;
    char                c;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    symvar          *   psymvar;
    bool                suppress_msg;

    ressize = ressize;
    if( parmcount != 2 ) {
        return( neg );
    }

    pneedle = parms[0].a;
    pneedlend = parms[0].e;

    unquote_if_quoted( &pneedle, &pneedlend );
    needle_len = pneedlend - pneedle + 1;   // needle length

    phay = parms[1].a;
    phayend = parms[1].e;

    unquote_if_quoted( &phay, &phayend );
    hay_len = phayend - phay + 1;       // haystack length

    rc = 0;
    scan_err = false;
    index = 0;

    if( (hay_len > 0) ||                // not null string
        (needle_len > 0) ) {            // needle not null


        suppress_msg = ProcFlags.suppress_msg;
        ProcFlags.suppress_msg = true;
        scan_err = false;
        c = *(phayend + 1);
        *(phayend + 1) = '\0';

        scan_sym( phay, &symvar_entry, &var_ind );

        *(phayend + 1) = c;
        ProcFlags.suppress_msg = suppress_msg;;

        if( !scan_err ) {

            if( symvar_entry.flags & local_var ) {  // lookup var in dict
                rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                    var_ind, &symsubval );
            } else {
                rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                                  &symsubval );
            }
            if( rc > 0 ) {              // variable found
                psymvar = symsubval->base;
                if( psymvar->flags & subscripted ) {
                    c = *(pneedlend + 1);
                    *(pneedlend + 1) = '\0';   // make nul delimited
                    for( symsubval = psymvar->subscripts;
                         symsubval != NULL;
                         symsubval = symsubval->next ) {

                        if( !strcmp( symsubval->value, pneedle ) ) {
                           index = symsubval->subscript;
                           if( vec_pos ) {
                               break;// finished for vec_pos, go for veclastpos
                           }
                        }
                    }
                    *(pneedlend + 1) = c;
                }
            }
        }
    }

    *result += sprintf( *result, "%d", index );

    return( pos );
}
Beispiel #7
0
   int thxscan(FILE *fp, cnxt_ent *cnxt_tab, proc_ent *proc_tab,
		       label_ent *label_tab, char file_name[10],
                        int *label_cp, int* proc_cp, int* cnxt_cp)
    {
       char *o_ptr;
       char out_str[255];
       char fname[256];
       char out_num[5];
       int i, IIPlen, ret_code;
       int proc_cnt;
       int proc_start = 0;
       int proc_hold, proc_last;
       int label_count, proc_count, cnxt_count;
       proc_ent *curr_proc;
       cnxt_ent *curr_cnxt;
       int label_ct;
       unsigned cnxt_open, eq_arrow;
       IIP *IIP_ptr;
       FILE *fp2;


       label_count = *label_cp;
       proc_count = *proc_cp;
       cnxt_count = *cnxt_cp;
       proc_hold = proc_count;
       ret_code = 0;
       do {curr_char = getc(fp);} while (curr_char == '\n');

 netloop:
       cnxt_open = FALSE;

       o_ptr = out_str;
       scan_blanks(fp);
       TCO(nEOF,EOF);  
       printf("End of Network Definition\n");
       goto exit;
 nEOF: TCO(NQ,'\'');
       strcpy(label_tab[label_count].label," ");
       strcpy(label_tab[label_count].file, file_name);
       label_tab[label_count].cnxt_ptr = &cnxt_tab[cnxt_count];
       label_tab[label_count].proc_ptr = &proc_tab[proc_count];
       label_tab[label_count].ent_type = 'L';
       printf("Scanning Main Network\n");
       proc_start = proc_count;
       proc_tab[proc_count].proc_name[0] = '\0';
       label_count++;
       label_tab[label_count].label[0] = '\0';
       goto TQ;
 NQ:   if (scan_sym(fp, o_ptr) != 0) {
	  printf("Name error\n");
	  ret_code = 4;
          goto exit;  }
       scan_blanks(fp);
       TCO(ncol,':');
       strcpy(label_tab[label_count].label,out_str);
       strcpy(label_tab[label_count].file, file_name);
       label_tab[label_count].cnxt_ptr = &cnxt_tab[cnxt_count];
       label_tab[label_count].proc_ptr = &proc_tab[proc_count];
       label_tab[label_count].ent_type = 'L';
       printf("Scanning Network: %s\n",out_str);
       proc_start = proc_count;
       label_count++;
       label_tab[label_count].label[0] = '\0';

       scan_blanks(fp);

loop:
       o_ptr = out_str;
       scan_blanks(fp);
       TCO(X1,'\'');
TQ:    
       TCO(tbsl,EOF);  
       printf("EOF encountered within quoted string\n");
       ret_code = 4;
       goto exit;
tbsl:  TCO(copy,'\'');
       TC(NQ2,'\'');
       goto TQ;
copy:  CC;
       goto TQ;
NQ2:   IIPlen = o_ptr - out_str;
       strcpy(cnxt_tab[cnxt_count].upstream_name,"!");
       IIP_ptr = (IIP *)malloc(IIPlen + sizeof(IIP_ptr -> IIP_len));
       IIP_ptr -> IIP_len = IIPlen;
       memcpy(IIP_ptr -> datapart, out_str, IIPlen);
       cnxt_tab[cnxt_count].gen.IIPptr = IIP_ptr;
       scan_blanks(fp);
       goto tArrow;

X1:    if (scan_sym(fp, o_ptr) != 0) {
	  printf("Name error\n");
	  ret_code = 4;
          goto exit;  }
       scan_blanks(fp);
       goto topen;

ncol:   strcpy(label_tab[label_count].label," ");
       strcpy(label_tab[label_count].file, file_name);
       label_tab[label_count].cnxt_ptr = &cnxt_tab[cnxt_count];
       label_tab[label_count].proc_ptr = &proc_tab[proc_count];
       label_tab[label_count].ent_type = 'L';
       proc_start = proc_count;
       label_count++;
       label_tab[label_count].label[0] = '\0';

topen:  if (cnxt_open) {
	  strcpy(cnxt_tab[cnxt_count].downstream_name,out_str);
	  cnxt_open = FALSE;
	  curr_cnxt = &cnxt_tab[cnxt_count];
	  if (curr_cnxt -> upstream_name[0] != '!')
             printf(" Connection: %s %s[%d] -> %s[%d] %s\n",
	     curr_cnxt -> upstream_name,
	     curr_cnxt -> upstream_port_name,
	     curr_cnxt -> upstream_elem_no,
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
	   else {
             printf(" IIP: -> %s[%d] %s\n",
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
             IIP_ptr = curr_cnxt -> gen.IIPptr;
             printf("    \'");
             for (i = 0; i < IIP_ptr -> IIP_len; i++)
	          printf("%c",IIP_ptr -> datapart[i]);
             printf("\'\n");
             }
	  cnxt_count++;
	  }
        else {
	TCO(NIP,'=');
	TCO(NIP,'>');
	scan_blanks(fp);

        strcpy(cnxt_tab[cnxt_count].upstream_name, "*");
	strcpy(cnxt_tab[cnxt_count].upstream_port_name,out_str);
        cnxt_tab[cnxt_count].upstream_elem_no = 0;
        goto ncap;
       }
	/* look up in proc list for subnet */
 NIP:  i = proc_start;
       while (proc_tab[i].proc_name[0] != '\0') {
         if (strcmp(proc_tab[i].proc_name,out_str) == 0) break;
	 i++;
         }
       proc_cnt = i;
       if (proc_tab[proc_cnt].proc_name[0] == '\0')  {
	 strcpy(proc_tab[proc_cnt].proc_name,out_str);
	 proc_tab[proc_cnt].trace = 0;
	 proc_tab[proc_cnt + 1].proc_name[0] = '\0';
	 proc_count = proc_cnt;
	 }

       TCO(NB1,'(');
       scan_blanks(fp);
       o_ptr = proc_tab[proc_cnt].comp_name;
Y1:    TA(NA2);
       goto Y1;
NA2:   TN(NN2);
       goto Y1;
NN2:   *o_ptr = '\0';
       scan_blanks(fp);
       TCO(NB1,')');
       curr_proc = &proc_tab[proc_cnt];
       printf(" Process: %s (%s)\n",curr_proc -> proc_name,
	  curr_proc -> comp_name);
NB1:   scan_blanks(fp);
       TCO(NQ1,'?');
       proc_tab[proc_cnt].trace = 1;

NQ1:   scan_blanks(fp);
       TCO(NSC1,';');
       cnxt_tab[cnxt_count].upstream_name[0] = '\0';
       cnxt_count++;
       proc_count++;
       proc_count++;
       label_count++;
       goto netloop;
NSC1:  TCO(NC1,',');
       goto loop;

NC1:   strcpy(cnxt_tab[cnxt_count].upstream_name,out_str);
       o_ptr = out_str;
X2:    TC(X2a,'*');     /* automatic port */
       *o_ptr = '\0';
       goto is_inport;
X2a:   if (scan_sym(fp, o_ptr) != 0) {
	  printf("Upstream port name error for %s\n",
	    cnxt_tab[cnxt_count].upstream_name);
	  ret_code = 4;
          goto exit;  }
is_inport:
       strcpy(cnxt_tab[cnxt_count].upstream_port_name,out_str);


       scan_blanks(fp);
       cnxt_tab[cnxt_count].upstream_elem_no = 0;
       TCO(tArrow,'[');
       o_ptr = out_num;
GNx:   TN(NNx);
       goto GNx;
NNx:   TCO(elemerr,']');
       *o_ptr = '\0';
       cnxt_tab[cnxt_count].upstream_elem_no = atoi(out_num);
       scan_blanks(fp);

tArrow: eq_arrow = FALSE;
       TCO(tEq,'-');
       goto tGr;
tEq:   TCO(nArrow,'=');
       eq_arrow = TRUE;
tGr:   TCO(nArrow,'>');

       cnxt_tab[cnxt_count].capacity = -1;
       scan_blanks(fp);
       TCO(ncap,'(');
       o_ptr = out_num;
GNz:   TN(NNz);
       goto GNz;
NNz:   TCO(caperr,')');
       *o_ptr = '\0';
       cnxt_tab[cnxt_count].capacity = atoi(out_num);
       scan_blanks(fp);
       goto ncap;
caperr: printf("Capacity error\n");
       ret_code = 4;
       goto exit;
ncap:  cnxt_tab[cnxt_count].downstream_elem_no = 0;

/* Scan off downstream port name */
       o_ptr = out_str;
       TC(Y2a,'*');       /* automatic port */
       *o_ptr = '\0';
       goto is_outport;
Y2a:   if (scan_sym(fp, o_ptr) != 0) {
	  printf("Downstream port name error for %s %s\n",
	  cnxt_tab[cnxt_count].upstream_name,
	  cnxt_tab[cnxt_count].upstream_port_name);
	  ret_code = 4;
          goto exit;  }
is_outport:
       strcpy(cnxt_tab[cnxt_count].downstream_port_name,out_str);
       strcpy(cnxt_tab[cnxt_count].downstream_name, "*");  /* ext. conn */
       cnxt_open = TRUE;

       scan_blanks(fp);
       TCO(CSC2,'[');
       o_ptr = out_num;
GNy:   TN(NNy);
       goto GNy;
NNy:   TCO(elemerr,']');
       *o_ptr = '\0';
       cnxt_tab[cnxt_count].downstream_elem_no = atoi(out_num);

CSC2:  scan_blanks(fp);
       TCO(NSC2,';');
       if (!eq_arrow)
	  printf("Port name %s not an external port\n", out_str);
       curr_cnxt = &cnxt_tab[cnxt_count];
       if (curr_cnxt -> upstream_name[0] != '!')
             printf(" Connection: %s %s[%d] -> %s[%d] %s\n",
	     curr_cnxt -> upstream_name,
	     curr_cnxt -> upstream_port_name,
	     curr_cnxt -> upstream_elem_no,
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
	   else {
             printf(" IIP: -> %s[%d] %s\n",
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
             IIP_ptr = curr_cnxt -> gen.IIPptr;
             printf("    \'");
             for (i = 0; i < IIP_ptr -> IIP_len; i++)
	          printf("%c",IIP_ptr -> datapart[i]);
             printf("\'\n");
             }


       cnxt_count++;
       cnxt_tab[cnxt_count].upstream_name[0] = '\0';
       cnxt_count++;
       proc_count++;
       proc_count++;
       label_count++;
       goto netloop;

NSC2:  TCO(loop,',');

       if (!eq_arrow)
	  printf("Port name %s not an external port\n", out_str);
       curr_cnxt = &cnxt_tab[cnxt_count];
       if (curr_cnxt -> upstream_name[0] != '!')
             printf(" Connection: %s %s[%d] -> %s[%d] %s\n",
	     curr_cnxt -> upstream_name,
	     curr_cnxt -> upstream_port_name,
	     curr_cnxt -> upstream_elem_no,
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
	   else {
             printf(" IIP: -> %s[%d] %s\n",
	     curr_cnxt -> downstream_port_name,
	     curr_cnxt -> downstream_elem_no,
	     curr_cnxt -> downstream_name);
             IIP_ptr = curr_cnxt -> gen.IIPptr;
             printf("    \'");
             for (i = 0; i < IIP_ptr -> IIP_len; i++)
	          printf("%c",IIP_ptr -> datapart[i]);
             printf("\'\n");
             }


       cnxt_count++;
       cnxt_open = FALSE;
       goto loop;

elemerr: printf("Port element error\n");
       ret_code = 4;
       goto exit;

nArrow: printf("No arrow found\n");
       ret_code = 4;
exit:
   if (fclose(fp) != 0) {
         printf("Close error\n");
         if (ret_code == 0)
            ret_code = 2;
	 }
       if (ret_code > 0) {
          printf("Scan error\n");
          return(ret_code);
          }

         proc_last = proc_count;
         for (i = proc_hold; i < proc_last; i++) {
	  curr_proc = &proc_tab[i];
	  if (curr_proc -> proc_name[0] == '\0') continue;
         label_ct = find_label(label_tab, curr_proc -> comp_name, file_name, label_count);
          curr_proc -> composite = (label_ct > 0);
          if (curr_proc -> composite)
             curr_proc -> label_count = label_ct;
           else {
            strcpy(fname, curr_proc -> comp_name);
            if ((fp2 = fopen(strcat(fname, ".net"),"r"))
                   != NULL) {
                 label_ct = label_count;
                 strcpy(fname, curr_proc -> comp_name);
	         thxscan(fp2, cnxt_tab, proc_tab, label_tab, fname,
                    &label_count, &proc_count, &cnxt_count);
                 fclose(fp2);
                 curr_proc -> composite = TRUE;
                 curr_proc -> label_count = label_ct;
                 }
                else {
                   curr_proc -> must_run =
                        (thxgatrs(curr_proc -> comp_name) > 0);
                   curr_proc -> composite = FALSE;
		   curr_proc -> faddr = 0;
                 }
	    }
          }
       *label_cp = label_count;
       *proc_cp = proc_count;
       *cnxt_cp = cnxt_count;
       printf("Scan finished\n");
       return (ret_code);
    }
Beispiel #8
0
bool    resolve_symvar_functions( char * buf )
{
    static const char   ampchar = '&';
    inp_line        *   in_wk;
    char            *   workb;
    char            *   pw;
    char            *   pwend;
    char            *   p2;
    char            *   pchar;
    char            *   varstart;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    size_t              buf_lg;
    int                 rc;
    bool                functions_found;
    bool                anything_substituted;

    char            *   var_unresolved; // ptr for resume search
    char            *   var_unresolved2;// ptr for resume search

    ProcFlags.substituted = false;
    ProcFlags.unresolved  = false;

    if( NULL == strchr( buf, ampchar ) ) {  // look for & in buffer
        return( false );              // no ampchar found, nothing to resolve
    }

    anything_substituted = false;
    var_unresolved = NULL;
    var_unresolved2 = NULL;
    functions_found = false;

    in_wk = mem_alloc( sizeof( inp_line ) + buf_size );// allocate workbuffer
    in_wk->next = NULL;
    workb = in_wk->value;               // allocate workbuffer

    do {                                // until no more substitutions
        strcpy( workb, buf );   // copy input buffer
        buf_lg = strlen( buf );
        pwend = workb + buf_lg - 1;
        if( var_unresolved == NULL ) {
            pw = workb;
            p2 = buf;
        } else {
            pw = workb + (var_unresolved2 - buf);
            p2 = var_unresolved2;
        }
        varstart = NULL;

        anything_substituted |= ProcFlags.substituted;
        ProcFlags.substituted = false;

        pchar = strchr( workb, ampchar ); // look for & in buffer
        while( pchar != NULL ) {        // & found
            if( *(pchar + 1) == ' ' ) { // not a symbol substition or function
                pchar = strchr( pchar + 1, ampchar );  // look for next & in buffer
                continue;
            }
            while( pw < pchar ) {       // copy all data preceding &
                *p2++ = *pw++;
            }
            buf_lg = strlen( buf );

            if( isalpha( *(pchar + 1) ) && *(pchar + 2) == '\''
                && *(pchar + 3) > ' ' ) {
                                        // not for .if '&*' eq '' .th ...
                                        // only    .if '&x'foo' eq '' .th
                char * * ppval = &p2;

                /***********************************************************/
                /*  Some single letter functions are resolved here:        */
                /*                                                         */
                /*  functions used within the OW doc build system:         */
                /*   &e'  existance of variable 0 or 1                     */
                /*   &l'  length of variable content                       */
                /*        or if undefined variable length of name          */
                /*   &u'  upper                                            */
                /*                                                         */
                /*   &s'  subscript                                        */
                /*   &S'  superscript                                      */
                /*                                                         */
                /*   other single letter functions are not used AFAIK      */
                /*                                                         */
                /***********************************************************/

                if( GlobalFlags.firstpass && input_cbs->fmflags & II_research ) {
                    add_single_func_research( pchar + 1 );
                }

                pw = scr_single_funcs( pchar, pwend, ppval );

                pchar = strchr( pw, ampchar );  // look for next & in buffer

                continue;
            }

            if( *(pchar + 1) == '\'' ) {// perhaps a multi letter function
                char   * pf;
                char * * ppval = &p2;
                int32_t  valsize = buf_size - (p2 - buf);

                pf = pchar + 2;
                while( is_function_char( *pf ) ) {
                    pf++;
                }
                if( *pf == '(' ) {// &'xyz( is start of multi char function

                /***********************************************************/
                /*  Some multi  letter functions are resolved here:        */
                /*                                                         */
                /*  functions used within the OW doc build system:         */
                /*                                                         */
                /*   &'delstr(          &'d2c(              &'index(       */
                /*   &'insert(          &'left(             &'length(      */
                /*   &'lower(           &'min(              &'pos(         */
                /*   &'right(           &'strip(            &'substr(      */
                /*   &'subword(         &'translate(        &'upper(       */
                /*   &'veclastpos(      &'vecpos(           &'word(        */
                /*   &'wordpos(         &'words(                           */
                /*                                                         */
                /*   Others are recognized but not processed               */
                /*   &'c2x(    is used for test output                     */
                /***********************************************************/

                    pw = scr_multi_funcs( pchar, pwend, ppval, valsize );

                    pchar = strchr( pw, ampchar );// look for next & in buffer
                    continue;
                }

                *p2++ = *pw++;          // copy &
                pchar = strchr( pw, ampchar );  // look for next & in buffer
                continue;               // and ignore this &... for now
            }

            /***************************************************************/
            /* & is neither start of single char function                  */
            /*   nor start of multi char function                          */
            /*                                                             */
            /* &  is probably start of a variable                          */
            /***************************************************************/

            varstart = pw;              // remember start of var
            pw++;                       // over &
            ProcFlags.suppress_msg = true;
            scan_err = false;

            pchar = scan_sym( pw, &symvar_entry, &var_ind );
            if( scan_err && *pchar == '(' ) {   // problem with subscript

                if( var_unresolved == NULL ) {
                    ProcFlags.unresolved  = true;
                    var_unresolved = varstart;
                    var_unresolved2 = p2;
                } else {
                    if( var_unresolved != varstart ) {
                        ProcFlags.unresolved  = true;
                    }
                }
                p2 += pchar - varstart;
                pw = pchar;
                pchar = strchr( pw, ampchar );  // look for next & in buffer

                continue;
            }

            ProcFlags.suppress_msg = false;

            if( symvar_entry.flags & local_var ) {  // lookup var in dict
                rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                    var_ind, &symsubval );
            } else {
                rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                                  &symsubval );
            }
            if( rc == 2 ) {             // variable found + resolved
                ProcFlags.substituted = true;
                if( !ProcFlags.CW_sep_ignore &&
                    symsubval->value[0] == CW_sep_char &&
                    symsubval->value[1] != CW_sep_char ) {

                                // split record at control word separator
                                // if variable starts with SINGLE cw separator
                                // and ignore cw separator

                    if( buf != buff2 ) {

                        // splitting input if not outermost buffer ++++ TBD
                        // needed ???
                        g_suicide();
                    }

                    if( *pchar == '.' ) {
                        pchar++;        // skip optional terminating dot
                    }
                    *p2 = '\0';
                    split_input_var( buf, pchar, &symsubval->value[1], true );
                    pw = pwend + 1;     // stop substitution for this record
                    varstart = NULL;

                    break;

                } else {
                    pw = symsubval->value;
                    if( symsubval->value[0] == CW_sep_char &&
                        symsubval->value[1] == CW_sep_char ) {
                        pw++;           // skip 1 CW_sep_char
                    }
                    strcpy( p2, pw );   // copy value
                    p2 += strlen(pw);
                    if( *pchar == '.' ) {
                        pchar++;        // skip optional terminating dot
                    }
                    pw = pchar;
                }
            } else {                    // variable not found
                if( (symvar_entry.flags & local_var )  // local var not found
                    ) {
                    if( (symvar_entry.name[0] == '\0') &&
                        (*pchar == ampchar) ) { // only &* as var name
                                                // followed by another var

                        if( var_unresolved == NULL ) {
                            ProcFlags.unresolved  = true;
                            var_unresolved = varstart;
                            var_unresolved2 = p2;
                        } else {
                            if( var_unresolved != varstart ) {
                                ProcFlags.unresolved  = true;
                            }
                        }
                        pw = varstart;
                        while( pw < pchar ) {   // treat var name as text
                            *p2++ = *pw++;  // and copy
                        }

                        continue;       // pchar points already to next &

                    } else {     // replace not found local var by nullstring
                        ProcFlags.substituted = true;
                        if( *pchar == '.' ) {
                            pchar++;    // skip optional terminating dot
                        }
                        pw = pchar;
                    }
                } else {                // global var not found
                                        // .. or local var outside of macro
                    /*******************************************************/
                    /*  keep trying for constructs such as                 */
                    /*                                                     */
                    /* .se prodgml = "Open Watcom GML"                     */
                    /* .se name = "GML"                                    */
                    /*                                                     */
                    /* My name is &prod&name..!                            */
                    /*                                                     */
                    /*  to become                                          */
                    /*                                                     */
                    /* My name is Open Watcom GML!                         */
                    /*                                                     */
                    /* This does not work for local variables, as these are*/
                    /* replaced by nullstring if not found                 */
                    /* My name is &*prod&*name..!                          */
                    /*  will become                                        */
                    /* My name is !                                        */
                    /*******************************************************/

                    if( var_unresolved == NULL ) {
                        ProcFlags.unresolved  = true;
                        var_unresolved = varstart;
                        var_unresolved2 = p2;
                    } else {
                        if( var_unresolved != varstart ) {
                            ProcFlags.unresolved  = true;
                        }
                    }

                    pw = varstart;
                    if( *pchar == '.' ) {
                        pchar++;        // copy terminating dot, too
                    }
                    while( pw < pchar ) {   // treat var name as text
                        *p2++ = *pw++;  // and copy
                    }
                }
            }
            pchar = strchr( pw, ampchar );  // look for next & in buffer
        }                               // while & found

        while( pw <= pwend) {           // copy remaining input
             *p2++ = *pw++;
        }
        *p2 = 0;                        // terminate string

    } while( ProcFlags.unresolved && ProcFlags.substituted );

    anything_substituted |= ProcFlags.substituted;

    mem_free( in_wk );                  // free workbuffer
    return( anything_substituted );
}
Beispiel #9
0
int thxscan(FILE *fp, label_ent *label_tab, char file_name[10])
{
	char *o_ptr;
	char out_str[255];
	//char fname[256];
	char out_num[8];
	size_t i, IIPlen, ret_code;
	char upstream_name[255];	
	char upstream_port_name[255];
	int upstream_elem_no;
	char procname[255];	


	proc_ent *proc_curr;
	//	proc_ent *proc_new;
	//	proc_ent *proc_find;
	cnxt_ent *cnxt_tab;
	cnxt_ent *cnxt_curr;
	cnxt_ent *cnxt_new;
	cnxt_ent *cnxt_hold;

//	label_ent *label_new;

	//int label_ct;
	bool eq_arrow;
	IIP *IIP_ptr;

	char buffer[100];

	while (true) {
		if (NULL == fgets(buffer, 100, fp))
			goto finish;
		if (0 == strcmp(buffer, "INPORT") || 0 == strcmp(buffer, "OUTPORT"))
			continue;

		ret_code = 0;

		curr_char = getc(fp);
		proc_tab = 0;
		cnxt_tab = 0;
		label_curr = label_tab;

		strcpy_s(label_curr->label, " ");
		strcpy_s(label_curr->file, file_name);
		label_curr->ent_type = 'L';

		IIPlen = -1;
		out_num[0] = '\0';
		cnxt_hold = 0;

		scan_blanks(fp);

	netloop:
		TCO(X0, '\'');
		goto Xs;       // quote found - scan off rest of IIP
	X0:
		if (scan_sym(fp, out_str) != 0) {  // this could be a network label or a process name...
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}

		TCO(X2, ':');
		strcpy_s(label_curr->label, out_str);  // it was a label		  
		printf("Scanning Network: %s\n", out_str);
		scan_blanks(fp);

	bigloop:

		cnxt_hold = 0;
		IIPlen = -1;
		TCO(X1, '\'');
	Xs:
		o_ptr = out_str;
		goto get_rest_of_IIP;

	X1:
		if (scan_sym(fp, out_str) != 0) {  // this must be a process name...
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}
	X2:
		strcpy_s(procname, out_str);
		printf("Procname: %s\n", procname);
		if (cnxt_hold != 0) {
			strcpy_s(cnxt_hold->downstream_name, procname);
			cnxt_hold = 0;
		}

		proc_curr = find_or_build_proc(procname);

		if (4 == scan_blanks(fp))
			goto bigloop;

		goto X3;

	get_rest_of_IIP:
		TCO(tbsl, EOF);
		printf("EOF encountered within quoted string\n");
		ret_code = 4;
		goto exit;
	tbsl:
		TCO(tbq, '\\');
		CC;
		goto get_rest_of_IIP;
	tbq:
		TCO(copy, '\'');
		goto NQ2;
	copy:
		CC;
		goto get_rest_of_IIP;
	NQ2:
		*o_ptr = '\0';
		IIPlen = static_cast<int>(o_ptr - out_str);
		IIP_ptr = (IIP *)malloc(IIPlen + 1);
		memcpy(IIP_ptr->datapart, out_str, IIPlen);
		IIP_ptr->datapart[IIPlen] = '\0';
		printf("IIP: %s\n", IIP_ptr->datapart);
		scan_blanks(fp);
		//IIPlen = -1;
		goto tArrow;


		// scan off process name with optional component name

	X3:
		TCO(NB1, '(');
		scan_blanks(fp);
		TCO(rest_of_comp, ')');
		goto NN2;
	rest_of_comp:

		TCO(NQ6, '"');           // this says that comp name may be surrounded by double quotes (not included in comp_name)
	NQ6:
		o_ptr = comp_name;      // if no data between brackets, comp_name will not be modified...

	TB1:
		TCO(NQ7, '"');
		scan_blanks(fp);

	NQ7:
		TCO(NB2, ')');
		goto NN2;
	NB2:
		CC;
		goto TB1;

	NN2:
		*o_ptr = '\0';

		if (strlen(comp_name) > 0) {
			strcpy_s(proc_curr->comp_name, comp_name);
			printf("Comp name: %s\n", comp_name);
		}

	NB1:
		// comp scanned off, if any
		strcpy_s(upstream_name, procname);	    // in case this proc is the upstream of another arrow

		if (4 == scan_blanks(fp))
			goto bigloop;

		TCO(NQ1, '?');
		proc_curr->trace = 1;
		if (4 == scan_blanks(fp))
			goto bigloop;
	NQ1:

		TCO(tsc, EOF);
		eof_found = TRUE;
		goto nxtnet;

	tsc:
		TCO(tcom, ';');
		scan_blanks(fp);
	nxtnet:
		// this is a fudge because multiple nets are not currently supported 
		IIPlen = -1;

		TCO(nextnet, EOF);
		goto exit;

	tcom:

		IIPlen = -1;
		TCO(not_com, ',');

		scan_blanks(fp);
		goto bigloop;

	not_com:

		o_ptr = out_str;
		TC(outport, '*');     /* automatic port */
		*o_ptr = '\0';

		goto GUy;

	outport:
		if (scan_sym(fp, out_str) != 0) {
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}
	GUy:
		scan_blanks(fp);

		strcpy_s(upstream_port_name, out_str);
		printf("Upstream port: %s\n", out_str);
		upstream_elem_no = 0;
		TCO(tArrow, '[');
		o_ptr = out_num;
	GNx:
		TN(NNx);
		goto GNx;
	NNx:
		TCO(elemerr, ']');
		*o_ptr = '\0';
		upstream_elem_no = atoi(out_num);

	tArrow:
		scan_blanks(fp);
		eq_arrow = FALSE;
		TCO(tEq, '-');
		goto tGr;
	tEq:
		TCO(nArrow, '=');
		eq_arrow = TRUE;
	tGr:
		TCO(nArrow, '>');
		printf("Arrow\n");
		cnxt_new = (cnxt_ent *)malloc(sizeof(cnxt_ent));
		cnxt_new->succ = 0;
		cnxt_new->dropOldest = false;
		if (cnxt_tab == 0) {
			cnxt_tab = cnxt_new;
			label_curr->cnxt_ptr = cnxt_tab;
			cnxt_curr = cnxt_tab;
		}
		else {
			cnxt_curr->succ = cnxt_new;
			cnxt_curr = cnxt_new;
		}

		cnxt_hold = cnxt_new;
		if (IIPlen != -1) {
			strcpy_s(cnxt_hold->upstream_name, "!");
			cnxt_hold->upstream_port_name[0] = '\0';
			cnxt_hold->gen.IIPptr = IIP_ptr;
		}
		else {
			strcpy_s(cnxt_hold->upstream_name, upstream_name);
			strcpy_s(cnxt_hold->upstream_port_name, upstream_port_name);

			cnxt_hold->upstream_elem_no = upstream_elem_no;
		}
		cnxt_hold->capacity = -1;
		scan_blanks(fp);
		TCO(ncap, '(');
		o_ptr = out_num;
	GNz:
		TN(NNz);
		goto GNz;
	NNz:
		TCO(caperr, ')');
		*o_ptr = '\0';
		cnxt_hold->capacity = atoi(out_num);
		scan_blanks(fp);
		goto ncap;
	caperr:
		printf("Capacity error\n");
		ret_code = 4;
		goto exit;
	ncap:
		cnxt_hold->downstream_elem_no = 0;

		/* Scan off downstream port name */
		o_ptr = out_str;
		TC(Y2a, '*');       /* automatic port */
		*o_ptr = '\0';
		strcpy_s(cnxt_hold->downstream_port_name, out_str);  /* ext. conn */
		goto is_outport;
	Y2a:
		if (scan_sym(fp, out_str) != 0) {
			printf("Downstream port name error for %s %s\n",
				cnxt_hold->upstream_name,
				cnxt_hold->upstream_port_name);
			ret_code = 4;
			goto exit;
		}
		strcpy_s(cnxt_hold->downstream_port_name, out_str);

	is_outport:

		printf("Downstream port: %s\n", cnxt_hold->downstream_port_name);

		scan_blanks(fp);
		TCO(X1, '[');
		o_ptr = out_num;
	GNy:
		TN(NNy);
		goto GNy;
	NNy:
		TCO(elemerr, ']');
		*o_ptr = '\0';
		cnxt_hold->downstream_elem_no = atoi(out_num);
		//cnxt_hold = 0;
		scan_blanks(fp);
		goto X1;

	nextnet:
		scan_blanks(fp);

		if (eof_found) {
			label_curr->succ = 0;   // temporary fix as we are only generating one network for now
			goto exit;
		}

		goto netloop;


	elemerr:
		printf("Port element error\n");
		ret_code = 4;
		goto exit;

	nArrow:
		printf("No arrow found\n");
		ret_code = 4;
	exit:
		printf("\nSummary:\n");
		proc_curr = proc_tab;
		while (proc_curr != 0) {
			printf(" Process: %s (%s)\n", proc_curr->proc_name,
				proc_curr->comp_name);
			proc_curr = proc_curr->succ;
		}

		cnxt_hold = cnxt_tab;
		while (cnxt_hold != 0) {
			char up[200];
			char down[200];
			char elem[20];
			if (cnxt_hold->upstream_name[0] != '!') {
				strcpy_s(up, cnxt_hold->upstream_port_name);
				if (up[0] != '*') {
					strcat_s(up, "[");
					_itoa_s(cnxt_hold->upstream_elem_no, elem, 10);
					strcat_s(up, elem);
					strcat_s(up, "]");
				}
				strcpy_s(down, cnxt_hold->downstream_port_name);
				if (down[0] != '*') {
					strcat_s(down, "[");
					_itoa_s(cnxt_hold->downstream_elem_no, elem, 10);
					strcat_s(down, elem);
					strcat_s(down, "]");
				}
				printf(" Connection: %s %s -> %s %s\n",
					cnxt_hold->upstream_name,
					up,
					down,
					cnxt_hold->downstream_name);
			}
			else {
				strcpy_s(down, cnxt_hold->downstream_port_name);
				if (down[0] != '*') {
					strcat_s(down, "[");
					_itoa_s(cnxt_hold->downstream_elem_no, elem, 10);
					strcat_s(down, elem);
					strcat_s(down, "]");
				}
				printf(" IIP: -> %s %s\n",
					down,
					cnxt_hold->downstream_name);
				IIP_ptr = cnxt_hold->gen.IIPptr;
				printf("    \'");
				auto j = strlen(IIP_ptr->datapart);
				for (i = 0; i < j; i++)
					printf("%c", IIP_ptr->datapart[i]);
				printf("\'\n");
			}
			cnxt_hold = cnxt_hold->succ;
		}
	 
	}
	finish:
	if (fclose(fp) != 0) {
		printf("Close error\n");
		if (ret_code == 0)
			ret_code = 2;
	}
	if (ret_code > 0) {
		// printf("Scan error\n");
		return(ret_code);
	}
	
	// printf("Scan finished\n");
	return (ret_code);
}