Beispiel #1
0
/******************
*  scan an if instruction
*  return address of next instruction after else & end addresses
*  if no else found, set else address to NULL
******************/
static INSTRUCTION *ifscan( register INSTRUCTION *ip, INSTRUCTION **else_adr )
{
INSTRUCTION *r = NULL;
INSTRUCTION *t;
register BYTE c;

   do {
      c = *ip;
      ip = iscan( ip );
      if( c == 0x58 ) {	/* IF */
         ip = ifscan( ip, &t );
      }
      else if( c == 0x1b ) {	/* ELSE */
	 assert( r == NULL );
	 r = ip;
      } /* if */
   } while( c != 0x59 );  /* EIF */
   *else_adr = r;
   return ip;
} /* ifscan() */
Beispiel #2
0
static void fdef( void )
{
register uint8 fnr = pop();

   iprintf(( "defining func %d\n", fnr ));
   assert( fnr < maxpp->maxFunctionDefs );
   fTable[fnr].start_address = ins_ptr;
   while( *ins_ptr != 0x2d ) { 	/* ENDF */
#if LISTING
   INSTRUCTION *ip0 = ilist( ins_ptr );
       putchar( '\n' );
#endif
       ins_ptr = iscan( ins_ptr );
#if LISTING
       assert( ins_ptr == ip0 );
#endif
   } /* while */
#if LISTING
   ilist( ins_ptr ); iprintf( "\n\n" );	/* ENDF ins */
#endif
   fTable[fnr].end_address = ins_ptr;
   ins_ptr++;
} /* fdef() */
Beispiel #3
0
void get_pargs(int *argc,char *argv[],int nparg,t_pargs pa[],bool bKeepArgs)
{
  int  i,j,k,match;
  bool *bKeep;
  char buf[32];
  char *ptr;
  
  snew(bKeep,*argc+1);
  bKeep[0]     = TRUE;
  bKeep[*argc] = TRUE;
  
  for(i=1; (i<*argc); i++) {
    bKeep[i] = TRUE;
    for(j=0; (j<nparg); j++) {
      if (pa[j].type == etBOOL) {
	sprintf(buf,"-no%s",pa[j].option+1);
	if (strcmp(pa[j].option,argv[i])== 0) {
	  *pa[j].u.b = TRUE;
	  pa[j].bSet = TRUE;
	  bKeep[i] = FALSE;
	}
	else if (strcmp(buf,argv[i])== 0) {
	  *pa[j].u.b = FALSE;
	  pa[j].bSet = TRUE;
	  bKeep[i] = FALSE;
	}
      } else if (strcmp(pa[j].option,argv[i])== 0) {
	if (pa[j].bSet)
	  fprintf(stderr,"Setting option %s more than once!\n",pa[j].option);
	pa[j].bSet = TRUE;
	bKeep[i] = FALSE;
	switch(pa[j].type) {
	case etINT:
	  *pa[j].u.i = iscan(*argc,argv,&i);
	  break;
	case etTIME:
	case etREAL:
	  *pa[j].u.r = dscan(*argc,argv,&i);
	  break;
	case etSTR:
	  *(pa[j].u.c) = sscan(*argc,argv,&i);
	  break;
	case etENUM:
	  match=NOTSET;
	  ptr = sscan(*argc,argv,&i);
	  for(k=1; (pa[j].u.c[k] != NULL); k++)
	    /* only check ptr against beginning of pa[j].u.c[k] */
	    if (strncasecmp(ptr,pa[j].u.c[k],strlen(ptr)) == 0)
	      if ( ( match == NOTSET ) || 
		   ( strlen(pa[j].u.c[k]) < strlen(pa[j].u.c[match]) ) )
		     match = k;
	  if (match!=NOTSET)
	    pa[j].u.c[0] = pa[j].u.c[match];
	  else 
	    gmx_fatal(FARGS,"Invalid argument %s for option %s",
			ptr,pa[j].option);
	  break;
	case etRVEC:
	  (*pa[j].u.rv)[0] = dscan(*argc,argv,&i);
	  if ( (i+1 == *argc) || 
	       ( (argv[i+1][0]=='-') && !isdigit(argv[i+1][1]) ) )
	    (*pa[j].u.rv)[1] = (*pa[j].u.rv)[2] = (*pa[j].u.rv)[0];
	  else {
	    bKeep[i] = FALSE;
	    (*pa[j].u.rv)[1] = dscan(*argc,argv,&i);
	    if ( (i+1 == *argc) || 
		 ( (argv[i+1][0]=='-') && !isdigit(argv[i+1][1]) ) )
	      gmx_fatal(FARGS,"%s: vector must have 1 or 3 real parameters",
			  pa[j].option);
	    bKeep[i] = FALSE;
	    (*pa[j].u.rv)[2] = dscan(*argc,argv,&i);
	  }
	  break;
	default:
	  gmx_fatal(FARGS,"Invalid type %d in pargs",pa[j].type);
	}
	/* i may be incremented, so set it to not keep */
	bKeep[i] = FALSE;
      }
    }
  }
  if (!bKeepArgs) {
    /* Remove used entries */
    for(i=j=0; (i<=*argc); i++) {
      if (bKeep[i])
	argv[j++]=argv[i];
    }
    (*argc)=j-1;
  }
  sfree(bKeep);
}
Beispiel #4
0
int
loaddefs(int fromfile, char *fname, int mode)
{
  nialptr     ts;
  int         repeatloop,
              keepreading,
              nolines,
              inremark,
              linecnt;
  FILE       *f1 = NULL;     /* initialized to avoid complaint */
  int         errorsfound;

  if (fromfile) {
    f1 = openfile(fname, 'r', 't');
    if (f1 == OPENFAILED)
      return (false);
    pushsysfile(f1);
  }
  /* a loaddefs always affects the global environment. We reset current_env to
     relect this.  The code to restore the environment is below. This must be
     saved on the stack, otherwise it can get thrown away since it may only
     be owned by a transient definition value. The following example failed
     before I protected this on the stack: retry is { host 'vi bug.ndf';
     loaddefs"bug l } where this definition was in the file bug.ndf. */

  apush(current_env);
  current_env = Null;
  ts = topstack;             /* to monitor stack growth on each action */
  errorsfound = 0;           /* reset parse error counter */
  repeatloop = true;
  linecnt = 0;

  /* loop to pick up groups of lines */
  while (repeatloop) {      
    /* continue as long as their are line groups */

    /* test on each circuit if an interrupt signal has been posted */
#ifdef USER_BREAK_FLAG
    if (fromfile)
      checksignal(NC_CS_NORMAL);
#endif

    inremark = false;
    nolines = 0;
    keepreading = true;

    /* loop to pick up lines until a whitespace line occurs */
    while (keepreading) {
      if (fromfile) {
        /* reading a line from the file */
        readfileline(f1, (mode ? 2 : 0)); /* mode==2 only in a loaddefs */

        /* readfileline places result on the stack */
        if (top == Eoffault) {
          apop();            /* to remove the end of file marker */
          repeatloop = false;
          break;             /* to end read loop */
        }
      }

      else {
        /* select a line from array defsndf loadded from defstbl.h */
        char       *line;

        line = defsndf[linecnt++];
        if (linecnt == NOLINES) {
          repeatloop = false;
          keepreading = false;  /* to end read loop */
        }
        mkstring(line);      /* convert the line to a Nial string and push it */
      }

      if (nolines == 0) {    /* check first line of group for a remark */
        char        firstchar;
        int         i = 0;

        /* loop to skip blanks */
        while (i < tally(top) && fetch_char(top, i) <= BLANK)
          i++;

        /* note whether first char is "#" */
        firstchar = fetch_char(top, i);
        if (tally(top))
          inremark = firstchar == HASHSYMBOL;
        else
          inremark = false;
      }

      /* if the line is all while space then we are at the end of a group */
      if (top == Null || allwhitespace(pfirstchar(top))) {
        keepreading = false;
        freeup(apop());      /* to get rid of the empty line */
      }
      else                   /* count the line on the stack */
        nolines++;
    }

    /* we have a group of lines to process */
    if (nolines > 0) {
      mklist(nolines);       /* create a list of lines  and link them*/
      ilink(); 
      if (inremark) {
        freeup(apop()); /* remarks are ignored */
      }                      
      else 
      {                 
        /* carry out the actions of the main loop */
        iscan();
        parse(true);

        /* check whether parse produced an error */
        if (kind(top) == faulttype) {
          if (top != Nullexpr) {
            errorsfound++;
            if (mode == 0) { /* show error message */
              apush(top);
              ipicture();
              show(apop());
            }
          }
        }

        /* evaluate the parse tree, if it is a fault, it is the value returned */
        ieval();

#ifdef DEBUG
        memchk();
#endif

        if (mode) {  /* show the result */
          if (top != Nullexpr) {
            ipicture();
            show(apop());
          }
          else
            apop();          /* the Nullexpr */
        }
        else
          freeup(apop());    /* free because it might not be Nullexpr */
      }

      if (mode) {            /* now display empty line */
        writechars(STDOUT, "", (nialint) 0, true);
        if (keeplog && f1 == STDIN)
          writelog("", 0, true);
      }
    }
    /* check that the stack hasn't grown */
    if (ts != topstack) {
      while (ts != topstack)
        freeup(apop());
      exit_cover(NC_STACK_GROWN_I);
    }
  } 

  /* done reading groups of lines */
  if (fromfile) {
    closefile(f1);
    popsysfile();
  }

  /* restore the current_env */
  current_env = apop();
  if (errorsfound > 0)
    nprintf(OF_NORMAL_LOG, "errors found: %d\n", errorsfound);
  return (true);
}
Beispiel #5
0
void valscan() {
  // Must be local cosysop or better
  if (!lcs()) {
    return;
  }

  int ac = 0;
  int os = GetSession()->GetCurrentMessageArea();

  if (uconfsub[1].confnum != -1 && okconf(GetSession()->GetCurrentUser())) {
    ac = 1;
    tmp_disable_conf(true);
  }
  bool done = false;
  for (int sn = 0; sn < GetSession()->num_subs && !hangup && !done; sn++) {
    if (!iscan(sn)) {
      continue;
    }
    if (GetSession()->GetCurrentReadMessageArea() < 0) {
      return;
    }

    uint32_t sq = qsc_p[sn];

    // Must be sub with validation "on"
    if (!(xsubs[GetSession()->GetCurrentReadMessageArea()].num_nets)
        || !(subboards[GetSession()->GetCurrentReadMessageArea()].anony & anony_val_net)) {
      continue;
    }

    GetSession()->bout.NewLine();
    GetSession()->bout.Color(2);
    GetSession()->bout.ClearEOL();
    GetSession()->bout << "{{ ValScanning " << subboards[GetSession()->GetCurrentReadMessageArea()].name << " }}\r\n";
    lines_listed = 0;
    GetSession()->bout.ClearEOL();
    if (okansi() && !newline) {
      GetSession()->bout << "\r\x1b[2A";
    }

    for (int i = 1; i <= GetSession()->GetNumMessagesInCurrentMessageArea() && !hangup && !done; i++) {    // was i = 0
      if (get_post(i)->status & status_pending_net) {
        CheckForHangup();
        GetSession()->localIO()->tleft(true);
        if (i > 0 && i <= GetSession()->GetNumMessagesInCurrentMessageArea()) {
          bool next;
          int val;
          read_message(i, &next, &val);
          GetSession()->bout << "|#4[|#4Subboard: " << subboards[GetSession()->GetCurrentReadMessageArea()].name << "|#1]\r\n";
          GetSession()->bout <<  "|#1D|#9)elete, |#1R|#9)eread |#1V|#9)alidate, |#1M|#9)ark Validated, |#1Q|#9)uit: |#2";
          char ch = onek("QDVMR");
          switch (ch) {
          case 'Q':
            done = true;
            break;
          case 'R':
            i--;
            continue;
          case 'V': {
            open_sub(true);
            resynch(&i, nullptr);
            postrec *p1 = get_post(i);
            p1->status &= ~status_pending_net;
            write_post(i, p1);
            close_sub();
            send_net_post(p1, subboards[GetSession()->GetCurrentReadMessageArea()].filename,
                          GetSession()->GetCurrentReadMessageArea());
            GetSession()->bout.NewLine();
            GetSession()->bout << "|#7Message sent.\r\n\n";
          }
          break;
          case 'M':
            if (lcs() && i > 0 && i <= GetSession()->GetNumMessagesInCurrentMessageArea() &&
                subboards[GetSession()->GetCurrentReadMessageArea()].anony & anony_val_net &&
                xsubs[GetSession()->GetCurrentReadMessageArea()].num_nets) {
              open_sub(true);
              resynch(&i, nullptr);
              postrec *p1 = get_post(i);
              p1->status &= ~status_pending_net;
              write_post(i, p1);
              close_sub();
              GetSession()->bout.NewLine();
              GetSession()->bout << "|#9Not set for net pending now.\r\n\n";
            }
            break;
          case 'D':
            if (lcs()) {
              if (i > 0) {
                open_sub(true);
                resynch(&i, nullptr);
                postrec p2 = *get_post(i);
                delete_message(i);
                close_sub();
                if (p2.ownersys == 0) {
                  WUser tu;
                  GetApplication()->GetUserManager()->ReadUser(&tu, p2.owneruser);
                  if (!tu.IsUserDeleted()) {
                    if (static_cast<unsigned long>(date_to_daten(tu.GetFirstOn())) < p2.daten) {
                      GetSession()->bout.NewLine();
                      GetSession()->bout << "|#2Remove how many posts credit? ";
                      char szNumCredits[ 11 ];
                      input(szNumCredits, 3, true);
                      int nNumPostCredits = 1;
                      if (szNumCredits[0]) {
                        nNumPostCredits = atoi(szNumCredits);
                      }
                      nNumPostCredits = std::min<int>(tu.GetNumMessagesPosted(), nNumPostCredits);
                      if (nNumPostCredits) {
                        tu.SetNumMessagesPosted(tu.GetNumMessagesPosted() - static_cast<unsigned short>(nNumPostCredits));
                      }
                      GetSession()->bout.NewLine();
                      GetSession()->bout << "|#3Post credit removed = " << nNumPostCredits << wwiv::endl;
                      tu.SetNumDeletedPosts(tu.GetNumDeletedPosts() + 1);
                      GetApplication()->GetUserManager()->WriteUser(&tu, p2.owneruser);
                      GetApplication()->UpdateTopScreen();
                    }
                  }
                }
                resynch(&i, &p2);
              }
            }
            break;
          }
        }
      }
    }
    qsc_p[sn] = sq;
  }

  if (ac) {
    tmp_disable_conf(false);
  }

  GetSession()->SetCurrentMessageArea(os);
  GetSession()->bout.NewLine(2);
}