Beispiel #1
0
void codegenfunc(astree node, FILE *outfile){
    astree temp = node->first;
    cstring type = oiltype(temp);
    cstring ident = getident(temp);
    fprintf(outfile,"%s __%s (\n",type,ident);
    astree x = temp->next->first;
    bool first = TRUE;
    for(; x != NULL; x = x->next){
        first ? first = FALSE : fprintf(outfile,",\n");
        fprintf(outfile,"        %s_%d_%s",
        oiltype(x),x->first->blocknr,getident(x));
    }
    fprintf(outfile,")\n{\n");
    traverseblock(temp->next->next->first,outfile);
    fprintf(outfile,"}\n\n");
}
Beispiel #2
0
main ()
{
	int ident, rez;
	char name [100];

	/* catch signals */
	sigcatch ();

	/* lock queue */
	lock (QLOCKFILE);

	/* get next free queue ident */
	ident = getident ();

	/* make queue file name */
	sprintf (name, QFILENAME, ident);

	/* create queue file */
	if (! freopen (name, "w", stdout)) {
		error ("cannot create %s", name);
		quit ();
	}

	/* save query into queue file */
	rez = ffcopy (stdin, stdout);
	if (rez < 0)
		quit ();

	/* append name of query to queue active file */
	enqueue (name);

	error ("batch %d queued", ident);
	unlock (QLOCKFILE);
	return (0);
}
Beispiel #3
0
static int getval(char *var)
{
    ident *id = getident(var);
    if(!id) return 0;
    else if(id->_type==ID_VAR) return *id->_storage;
    else if(id->_type==ID_ALIAS) return atoi(id->_action);
    else return 0;
};
Beispiel #4
0
void runqueuer ()
{
	FILE *fd, *tfd;
	register long beg, next;
	int ident;
	char name [100];
	char from [256], *fromptr;

	fd = fopen (MAILBOX, "r");
	if (! fd) {
		syslog (LOG_ERR, "cannot read %s", MAILBOX);
		return;
	}
	beg = findfrom (fd, 0L, &fromptr);
	strcpy (from, fromptr);
	for (;;) {
		next = findfrom (fd, beg+1, &fromptr);
		if (next < 0)
			break;

		/* get next free queue ident */
		ident = getident ();

		/* make queue file name */
		sprintf (name, "%s/queue/q%d", SERVDIR, ident);

		/* create queue file */
		tfd = fopen (name, "w");
		if (! tfd) {
			syslog (LOG_ERR, "cannot open %s, aborted", name);
			exit (-1);
		}

		/* save query into queue file */
		fseek (fd, beg, 0);
		ffncopy (fd, tfd, next - beg);
		if (ferror (tfd)) {
			syslog (LOG_ERR, "error writing to %s, aborted", name);
			exit (-1);
		}
		fclose (tfd);

		/* append name of query to queue active file */
		enqueue (name);

		syslog (LOG_INFO, "queued %d from %s", ident, from);
		beg = next;
		strcpy (from, fromptr);
	}
	fclose (fd);
	if (close (creat (MAILBOX, 0600)) < 0) {
		syslog (LOG_ERR, "cannot rewrite %s, aborted", MAILBOX);
		exit (-1);
	}
}
Beispiel #5
0
void get_next_ident(char *out, int &num) {
  // *sigh* re-write when not tired.
  int low = num;
  int mid = (num / 52);
  int top = (mid / 52);
  always_assert_log(num <= MAX_IDENT,
                    "Bailing, Ident %d, greater than maximum\n", num);
  if (top) {
    *out++ = getident(top - 1);
    low -= (top *52*52);
  }
  if (mid) {
    mid -= (top * 52);
    *out++ = getident(mid);
    low -= (mid * 52);
  }
  *out++ = getident(low);
  *out++ = '\0';
  num++;
}
Beispiel #6
0
static void updateval(char *var, int val, char *onchange)
{
    ident *id = getident(var);
    string assign;
    if(!id) return;
    else if(id->_type==ID_VAR) s_sprintf(assign)("%s %d", var, val);
    else if(id->_type==ID_ALIAS) s_sprintf(assign)("%s = %d", var, val);
    else return;
    executelater.add(newstring(assign));
    if(onchange[0]) executelater.add(newstring(onchange));
};
Beispiel #7
0
// Parse the next symbol in the current command line and update the "last" global variable with the results.  If an invalid
// string is found, return an error; otherwise, if a symbol is found, save it in last->p_tok, set last->p_sym to the symbol
// type, update last->p_clp to point to the next character past the symbol or the terminator character, and return current
// status (SUCCESS); otherwise, set last->p_tok to a null string, update last->p_clp to point to the terminating null if
// last->p_termch is TKC_COMMENT, or the (TKC_EXPREND) terminator otherwise, and return NOTFOUND (bypassing rcset()).
// Notes:
//   *	Symbols are delimited by white space or special characters and quoted strings are saved in last->p_tok in raw form with
//	the leading and trailing quote characters.
//   *	Command line ends at last->p_termch or null terminator.
//   *	The specific symbol type for every token is returned in last->p_sym.
int getsym(void) {
	int c;
	enum e_sym sym = s_nil;
	char *srcp0,*srcp;

	// Get ready.
	vnull(&last->p_tok);

	// Scan past any white space in the source string.
	srcp0 = srcp = nonwhite(last->p_clp);

	// Examine first character.
	if((c = *srcp) != '\0' && c != last->p_termch) {
		switch(c) {
			case '"':
			case '\'':
				sym = getslit(&srcp,c);		// String literal.
				if(*srcp != c)			// Unterminated string?
					return rcset(FAILURE,0,text123,
					 strsamp(srcp0,strlen(srcp0),(size_t) term.t_ncol * 3 / 10));
						// "Unterminated string %s"
				++srcp;
				goto savexit;
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				sym = s_nlit;			// Numeric literal.
				(void) getnlit(&srcp,true);
				goto savexit;

			// User variable?
			case TKC_GVAR:
				if(isdigit(srcp[1])) {
					++srcp;
					sym = s_nvar;
					(void) getnlit(&srcp,false);
					goto savexit;
					}
				sym = s_gvar;
				++srcp;
				(void) getident(&srcp,NULL);
				if(srcp > srcp0 + 1)
					goto savexit;
				--srcp;
				goto unk;

			// Identifier?
			default:
				if((sym = getident(&srcp,NULL)) != s_nil)
					goto savexit;
				if((sym = getspecial(&srcp)) != s_nil) {
savexit:
					c = *srcp;
					*srcp = '\0';
					if(vsetstr(srcp0,&last->p_tok) != 0)
						return vrcset();
					*srcp = c;
					break;
					}
unk:
				// Unknown character.  Return error.
				vsetchr(*srcp,&last->p_tok);
				return rcset(FAILURE,0,text289,last->p_tok.v_strp);
						// "Unexpected token '%s'"
			}
		}
#if 0
	// Check for call at end-of-string (should never happen).
	if(sym == s_nil && last->p_sym == s_nil)
		return rcset(FATALERROR,0,"getsym(): Unexpected end of string, parsing \"%s\"",last->p_tok.v_strp);
#endif
	// Update source pointer and return results.
	last->p_sym = sym;
	last->p_clp = (*srcp == last->p_termch && last->p_termch == TKC_COMMENT) ? strchr(srcp,'\0') : srcp;
#if MMDEBUG & DEBUG_TOKEN
	fprintf(logfile,"### getsym(): Parsed symbol \"%s\" (%d), \"%s\" remains.\n",last->p_tok.v_strp,last->p_sym,last->p_clp);
#endif
	return (sym == s_nil) ? NOTFOUND : rc.status;
	}
Beispiel #8
0
int
prep (void)                     /* Check for preprocessor commands */
{
    int b, c;
    char *ln;

    ln = line;

    while (*(++ln) == '#' || *ln == ' ') /* locate first directive character */
        ;
    
    if ( ! *ln)                   /* NULL directive */
        return (killine ());
    
    /* fprintf(stderr,"prep - line=%s\n",ln); */

    if (strcmp2 (ln, "if ") || strcmp2 (ln, "ifdef ") ||
                                strcmp2 (ln, "ifndef "))
    {
        /* fprintf(stderr,"prep - calling doif(%s)\n",ln); */
        doif (ln);
        return (killine ());
    }

    if (strcmp2 (ln, "else"))
    {
        doelse ();
        return (killine ());
    }

    if (strcmp2 (ln, "endif"))
    {
        doendif ();
        return (killine ());
    }
    
    if (strcmp2 (ln, "elif "))
    {
        doelif (ln);
        return (killine ());
    }
    
    if (procsw)
    {
        if (strcmp2 (ln, "define "))
        {
            c = getident (ln, 7) + 2;   /* get end of identifier */
            splittok (ln, c);   /* tokenize rest of line */
            dodefine (strlen (line), &ln[7] - line);    /* store #define info */
/*          fprintf(stderr,"PREP (after dodef): line=|%s|\n",line); */
            tstdupdef ();       /* Check for def duplication and fix */
            return (killine ());        /* Discard #define line */
        }
        
        if (strcmp2 (ln, "include "))
        {
            doinclude (&ln[8]); /* open include file */
            return (killine ());        /* Discard #include line */
        }
        
        if (strcmp2 (ln, "undef "))
        {
            /* fprintf(stderr,"prep - undef found %s\n",ln); */
            doundef (&ln[6]);   /* remove undef identifier from def table */
            /* fprintf(stderr,"prep - doundef done\n"); */
            return (killine ());        /* Discard #undef line */
        }
        
        if (strcmp2 (ln, "error "))
        {
            fprintf (stderr, "User error - %s\n", &ln[6]);      /* print error */
            return (killine ());        /* Discard #error line */
        }
        
        if (strcmp2 (ln, "asm"))
        {
            for (;;)            /* send all following lines through for assembler */
            {
                getln (0);
                if (eflag)
                    break;
                if (findstr (1, line, "#endasm"))
                    break;
                if (cflag)
                    puts ("#2");
                else
                    printf ("#pragma asm ");
                printf ("%s\n", line);
            }
            if (eflag && cflag) /* error only in Microware mode (no #endasm) */
                doerr (18, 1);
            return (killine ());
        }
        if (strcmp2 (ln, "pragma "))
        {
            dopragma (ln + 7);
            return (killine ());
        }
        if (strcmp2 (ln, "line "))
        {
            doline (ln + 5);
            return (killine ());
        }
        doerr (17, 1);          /* Illegal preprocessor directive */
        return (killine ());
    }
}
Beispiel #9
0
    /* Returns NULL if no errors */
int
dodefine (int a, int b)
{
    int c, d;

    if ((d = c = getident (line, b)) == ERROR)  /* Get identifier */
        return (doerr (1, b));  /* Return if invalid identifier */
/*    fprintf(stderr,"In dodef, defining '%s'\n",&line[b]); */

/* Lets convert a crashed program into an error exit here folks, by
   checking to see if we've run out of deftbl room regardless of the
   status of the string table checked on later. Gene Heskett WDTV5CE. */

    if ((defcntr + 1) >= MAX_DEFS)
        doerr (21, b);          /* doerr() will exit(0) on this one */
    defnam[defcntr] = dptr;     /* Put identifier addr in def name tbl */
    putiddtbl (b, d);           /* Put def name in $trng table */
/*  fprintf(stderr,"DODEFINE: line[c+1]=|%c|\n",line[c+1]);
    fprintf(stderr,"DODEFINE: line=%s\n",line); */
    if (line[c + 1] == '(')     /* if def is macro... */
    {
        d = b = skpbl (line, c + 2);    /* Align to 1st non-space char in macro */
        if (line[b] != ')')     /* if more than 0 arguments in macro */
        {
            --b;
            defarg[defcntr] = dptr;
            do                  /* Scan argument format */
            {
/*              fprintf(stderr,"DODEF (): b=|%d|\n",b); */
                ++b;
                b = skpbl (line, b);
/*              fprintf(stderr,"DODEF (2): b=|%d|\n",b); */
                if ((c = getident (line, b)) == ERROR)  /* Get identifier (args) */
                    return (doerr (2, b));      /* return if any args missing */
                putdtbl (b, c); /* put args in $trng table */
/*              fprintf(stderr,"DODEF (): dfarg=|%s|\n",defarg[defcntr]);*/
                *(dptr - 1) = ' ';
                b = skpbl (line, c + 1);        /* Should now point at , or ) */
/*              fprintf(stderr,"DODEF (3): b=|%d|\n",b);    */
                if (line[b] != ',' && line[b] != ')')   /* If not ) or , error */
                    return (doerr (3, b));      /* so return */
            }
            while (line[b] != ')');
            *dptr++ = 0;
/*          fprintf(stderr,"DODEF: dfarg=|%s|\n",defarg[defcntr]);  */
        }
        else
        {
            if (dptr + 5 >= &dstrtbl[STRNG_TBL_MAX - 1])        /* table overflow */
                doerr (5, b);
            strcpy (--dptr, "( ) ");
            dptr += 5;
            defarg[defcntr] = NULL;     /* 0 args in macro */
        }
    }
    else                        /* define is not a macro */
    {
        b = c;
        defarg[defcntr] = NULL;
    }
    if (line[b + 1] == '\n')    /* If EOL then define = 1 */
    {
        line[b + 1] = ' ';
        line[b + 2] = '1';      /* This does not test LINE to see if it is full */
        line[b + 3] = '\n';
    }
    b += 2;                     /* locate 1st char of token-sequence */
    c = rskpbl (line, a - 1);   /* locate last char of token-sequence */
    deftok[defcntr++] = dptr;   /* Put token addr in tok table */
    putdtbl (b, c);             /* Copy token into $trng table */
    return NULL;                /* No errors */
}
Beispiel #10
0
yylex()
{
	int k;
	STRING synfind(),strsave(),getident(),getword2(),getstring(),getword();
	float getnum();
	while(iswhite(c=lexgetc()));
	startoflex = curr_index;
	if((isalpha(c)||c=='@' )&& c != EOF) {
		s = getident(c);
		if(strcmp("include",s)==0){
			inclusion();
			return(yylex());
		}else if((k=keyfind(synfind(s)))!=NKEYWORDS && const_list == 0){
			   yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->strg =  keywords[k].keyname;
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  = startoflex;
				return(keywords[k].keyret);
		}else{ if (const_list != 0)
			{
			  yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			  yylval.resptr->strg = s;
			  yylval.resptr->line = in_files[in_index].in_line;
			  yylval.resptr->len  =
			  startoflex;
			  return(WORD);
			}
			else
			{
			  yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			  yylval.resptr->strg = s;
			  yylval.resptr->line = in_files[in_index].in_line;
			  yylval.resptr->len  =
			  startoflex;
			  return(IDENT);
			}
		     }
       }else if((isdigit(c) || c == '~') && c !=EOF) {
		yylval.numb = (float) getnum(c);
		return(CONST);
	}else{
		switch(c){
		case '+':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg = "plus";
			yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(ADDOP);
		case '-':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg =  "minus";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(ADDOP);
		case '*':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
			yylval.resptr->line = in_files[in_index].in_line;
			if (c=='*') { yylval.resptr->strg =  "exp";
				      yylval.resptr->len  = startoflex;
				      return(EXP); }
			peekc = c;
			yylval.resptr->strg =  "times";
			yylval.resptr->len  = startoflex;
			return(MULOP);
		case '/': c = lexgetc();
			if (const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->strg=getword2('/');
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			if (c=='/'){
			while((c=lexgetc())!='\n');
			peekc = c;
			return(yylex()); }
			peekc = c;
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			yylval.resptr->strg =  "fdiv";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(MULOP);
		case '^':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg ="strconc";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(STRCONC);
		case '#':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			return(c);
		case '"':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c = lexgetc() ;
			yylval.resptr->strg = getword(c);
			yylval.resptr->len  =
			  startoflex;
			return(WORD);
		case '`':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			c = lexgetc();
			yylval.resptr->strg =  getstring(c);
			yylval.resptr->len  =
			  startoflex;
			return(STRING_QUOTED);
		case ':':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  = startoflex;
			if (const_list!=0) {
			     yylval.resptr->strg = getword(c);
			     return(WORD); }
			c = lexgetc();
			if (c==':') { yylval.resptr->strg = "cons";
					return(CONS); } else {
					peekc=c;
					return(COLON);}
		case '[': c = lexgetc();
			if (c=='%' && const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2('[');
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			if (c == '%') { return(CLSTART);
				      }
				      else
				      { peekc = c;
					const_list++;
					return(LSTART);
				      }
		case '%':c = lexgetc();
			if ((c==']' || c==')') && const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2('%');
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			  if (c == ']')
				       {  return(CLEND);
				       }
				       else
				       {
				       my_yyerror("incorrect use of %","cannot continue compliation ");
					 my_exit(1);
				       }
		case ']':
				       { const_list--;
					 return(LEND);
				       }
		case '.':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			return(DOT);
		case '<':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
					if (c=='=') {
						   yylval.resptr->strg =  "le";
						   yylval.resptr->len  =
			  startoflex;
						     return(RELOP); } else
					if (c =='>') {
						 yylval.resptr->strg = "append";
						 yylval.resptr->len  =
			  startoflex;
						   return(APPEND); } else {
						     peekc=c;
						     yylval.resptr->strg = "lt";
						     yylval.resptr->len  =
			  startoflex;
						     return(RELOP);  }
		case '>':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
			if (c=='=') { yylval.resptr->strg =  "ge";
				      yylval.resptr->len  =
			  startoflex;
					return(RELOP); } else {
						 yylval.resptr->strg = "gt";
						 yylval.resptr->len  =
			  startoflex;
						 peekc=c;
						 return(RELOP); }
		case '&':
		case ',':
		case ';':
		case '=':
		case '$':
		case '(':
		case ')':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			 if (c==',') {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  = startoflex;
			     return(COMMA); }
		default:
			return(c);
		}
	}
}