예제 #1
0
파일: c80.c 프로젝트: adamsch1/scc
/*  definitions are legal...  */
parse()
  {
  while (eof==0)    /* do until no more input */
    {
    if(amatch("char",4)){declglb(cchar);ns();}
    else if(amatch("int",3)){declglb(cint);ns();}
    else if(match("#asm"))doasm();
    else if(match("#include"))doinclude();
    else if(match("#define"))addmac();
    else newfunc();
    blanks();  /* force eof if pending */
    }
  }
예제 #2
0
/*
 * We have a .de xx line in "line".  Add xx to the list of known commands.
 */
static void
addcmd(char *myline)
{
	char *mac;

	/* grab the macro being defined */
	mac = myline + 4;
	while (isspace(*mac))
		mac++;
	if (*mac == 0) {
		pe(lineno);
		printf("illegal define: %s\n", myline);
		return;
	}
	mac[2] = 0;
	if (isspace(mac[1]) || mac[1] == '\\')
		mac[1] = 0;
	addmac(mac);
}
예제 #3
0
/*
 * We have a .de xx line in "line".  Add xx to the list of known commands.
 */
void
addcmd(char *line)
{
	char *mac;

	/* grab the macro being defined */
	mac = line+4;
	while (isspace((unsigned char)*mac))
		mac++;
	if (*mac == 0) {
		pe(lineno);
		printf("illegal define: %s\n", line);
		return;
	}
	mac[2] = 0;
	if (isspace((unsigned char)mac[1]) || mac[1] == '\\')
		mac[1] = 0;
	if (ncmds >= MAXCMDS) {
		printf("Only %d known commands allowed\n", MAXCMDS);
		exit(1);
	}
	addmac(mac);
}
예제 #4
0
파일: main.c 프로젝트: meesokim/z88dk
void parse()
{
        while ( eof == 0 ) {            /* do until no more input */
                if ( amatch("extern") )
                        dodeclare(EXTERNAL, NULL_TAG, 0) ;
                else if (amatch("static"))
                        dodeclare(LSTATIC, NULL_TAG, 0) ;
                else if (amatch("typedef"))
                        dodeclare(TYPDEF,NULL_TAG,0) ;
                else if (dodeclare(STATIK, NULL_TAG, 0) ) ;
                else if ( ch() == '#' ) {
                        if (match("#asm")) doasm();
                        else if (match("#include")) doinclude() ;
                        else if (match("#define") ) addmac() ;
                        else 
                        {
                                clear();
                                blanks();
                        }
                }
                else newfunc();
                blanks();       /* force eof if pending */
        }
}
예제 #5
0
/*
 * checknr: check an nroff/troff input file for matching macro calls.
 * we also attempt to match size and font changes, but only the embedded
 * kind.  These must end in \s0 and \fP resp.  Maybe more sophistication
 * later but for now think of these restrictions as contributions to
 * structured typesetting.
 */
int
main(int argc, char **argv)
{
	FILE *f;
	int i;
	char *cp;
	char b1[4];

	/* Figure out how many known commands there are */
	ncmds = 0;
	while (ncmds < MAXCMDS && knowncmds[ncmds][0] != '\0')
		ncmds++;
	while (argc > 1 && argv[1][0] == '-') {
		switch(argv[1][1]) {

		/* -a: add pairs of macros */
		case 'a':
			if ((strlen(argv[1]) - 2) % 6 != 0)
				usage();
			/* look for empty macro slots */
			i = 0;
			while (i < MAXBR && br[i].opbr[0] != '\0')
				i++;
			if (i >= MAXBR) {
				errx(1, "Only %d known macro-pairs allowed",
				    MAXBR);
			}
			for (cp = argv[1] + 3; cp[-1]; cp += 6) {
				strncpy(br[i].opbr, cp, 2);
				strncpy(br[i].clbr, cp + 3, 2);
				/*
				 * known pairs are also known cmds
				 */
				addmac(br[i].opbr);
				addmac(br[i].clbr);
				i++;
			}
			break;

		/* -c: add known commands */
		case 'c':
			i = strlen(argv[1]) - 2;
			if (i % 3 != 0)
				usage();
			for (cp = argv[1] + 3; cp[-1]; cp += 3) {
				if (cp[2] && cp[2] != '.')
					usage();
				strncpy(b1, cp, 2);
				b1[2] = '\0';
				addmac(b1);
			}
			break;

		/* -f: ignore font changes */
		case 'f':
			fflag = 1;
			break;

		/* -s: ignore size changes */
		case 's':
			sflag = 1;
			break;
		default:
			usage();
		}
		argc--; argv++;
	}

	nfiles = argc - 1;

	if (nfiles > 0) {
		for (i = 1; i < argc; i++) {
			cfilename = argv[i];
			f = fopen(cfilename, "r");
			if (f == NULL)
				warn("%s", cfilename);
			else {
				process(f);
				fclose(f);
			}
		}
	} else {
		cfilename = "stdin";
		process(stdin);
	}
	exit(0);
}
예제 #6
0
파일: ex_tty.c 프로젝트: atsb/ex
void
setterm(char *type)
{
	register int unknown;
	char ltcbuf[TCBUFSIZE];

	if (type[0] == 0)
		type = "xx";
	unknown = 0;
	putpad(TE);
	if (tgetent(ltcbuf, type) != 1) {
		unknown++;
		CP(ltcbuf, "xx|dumb:");
	}
	gettmode(); /* must call gettmode() before setsize(). GR */
	setsize();
	aoftspace = tspace;
	zap();
	/*
	 * Initialize keypad arrow keys.
	 */
	addmac1(KU, "k", "up", arrows, 1);
	addmac1(KD, "j", "down", arrows, 1);
	addmac1(KL, "h", "left", arrows, 1);
	addmac1(KR, "l", "right", arrows, 1);
	addmac1(KH, "H", "home", arrows, 1);

	/*
	 * Handle funny termcap capabilities
	 */
	if (xCS && SC && RC) {
		if (AL==NULL) AL="";
		if (DL==NULL) DL="";
	}
	if (AL_PARM && AL==NULL) AL="";
	if (DL_PARM && DL==NULL) DL="";
	if (IC && IM==NULL) IM="";
	if (IC && EI==NULL) EI="";
	if (!GT) BT=NULL;	/* If we can't tab, we can't backtab either */

#ifdef	TIOCLGET
#define	HAS_JOB_CONTROL
#endif
#ifdef	_SC_JOB_CONTROL
#define	HAS_JOB_CONTROL
#endif
#ifdef	HAS_JOB_CONTROL
	/*
	 * Now map users susp char to ^Z, being careful that the susp
	 * overrides any arrow key, but only for hackers (=new tty driver).
	 */
	{
		static char sc[2];
		int i /* , fnd */;

		if (sysconf(_SC_JOB_CONTROL) != -1)
		{
			/*
			 * If a system supports job control but no job
			 * control shell is used, only one method of
			 * detection remains: Our session id equals our
			 * process group id. Any job control shell would
			 * have created at least one new process group.
			 * But as the VSUSP key may be active, we have
			 * to override arrow keys either.
			 */
#ifndef	_CRAY	/* getsid() is a bad syscall on UNICOS */
			if (getsid(0) != getpgid(0))
#endif	/* !_CRAY */
				ldisc = 2;	/* value of NTTYDISC */
			sc[0] = tty.c_cc[VSUSP];
			sc[1] = 0;
			if (tty.c_cc[VSUSP] == CTRL('z')) {
				for (i=0; i<=4; i++)
					if (arrows[i].cap &&
					    arrows[i].cap[0] == CTRL('z'))
						addmac(sc, NULL, NULL, arrows);
			} else if (sc[0]
#ifdef	_PC_VDISABLE
					&& sc[0] != fpathconf(1, _PC_VDISABLE)
#endif
					)
				addmac(sc, "\32", "susp", arrows);
		}
	}
#endif	/* HAS_JOB_CONTROL */

	if (CM != 0) {
		if (tgoto(CM, 2, 2)[0] == 'O')	/* OOPS */
			CA = 0, CM = 0;
		else
			CA = 1, costCM = cost(tgoto(CM, 8, 10));
	} else {
		CA = 0, CM = 0;
	}
	costSR = cost(SR);
	costAL = cost(AL);
	costDP = cost(tgoto(DOWN_PARM, 10, 10));
	costLP = cost(tgoto(LEFT_PARM, 10, 10));
	costRP = cost(tgoto(RIGHT_PARM, 10, 10));
	PC = xPC ? xPC[0] : 0;
	aoftspace = tspace;
	safecp(ttylongname, gettlongname(ltcbuf, type), sizeof ttylongname,
			"Terminal name too long");
	/* proper strings to change tty type */
	termreset();
	gettmode();
	value(REDRAW) = AL && DL;
	value(OPTIMIZE) = !CA && !GT;
	if (ospeed == B1200 && !value(REDRAW))
		value(SLOWOPEN) = 1;	/* see also gettmode above */
	if (unknown)
		serror(catgets(catd, 1, 191,
				"%s: Unknown terminal type"), type);
}
예제 #7
0
dodefine ()
{
	addmac();
}
예제 #8
0
파일: checknr.c 프로젝트: aksr/heirloom
int
main(int argc, char **argv)
{
	FILE *f;
	int i;
	char *cp, *cq, c;

	stk = calloc(sizeof *stk, maxstk = 100);
	/* Figure out how many known commands there are */
	while (knowncmds[ncmds])
		ncmds++;
	while (argc > 1 && argv[1][0] == '-') {
		switch (argv[1][1]) {

		/* -a: add pairs of macros */
		case 'a':
			/* look for empty macro slots */
			for (i = 0; br[i].opbr; i++)
				;
			cp = &argv[1][3];
			while (*cp) {
				if (i >= MAXBR - 3) {
					printf("Only %d known pairs allowed\n",
							MAXBR/2);
					exit(1);
				}
				for (cq = cp; *cq && *cq != '.'; cq++);
				if (*cq != '.')
					usage();
				*cq = 0;
				br[i].opbr = malloc(cq - cp + 1);
				strcpy(br[i].opbr, cp);
				*cq = '.';
				cp = &cq[1];
				for (cq = cp; *cq && *cq != '.'; cq++);
				c = *cq;
				*cq = 0;
				br[i].clbr = malloc(cq - cp + 1);
				strcpy(br[i].clbr, cp);
				*cq = c;
				cp = c ? &cq[1] : cq;
				/* knows pairs are also known cmds */
				addmac(br[i].opbr);
				addmac(br[i].clbr);
				i++;
			}
			break;

		/* -c: add known commands */
		case 'c':
			cp = &argv[1][3];
			while (*cp) {
				for (cq = cp; *cq && *cq != '.'; cq++);
				c = *cq;
				*cq = 0;
				addmac(cp);
				*cq = c;
				cp = c ? &cq[1] : cq;
			}
			break;

		/* -f: ignore font changes */
		case 'f':
			fflag = 1;
			break;

		/* -s: ignore size changes */
		case 's':
			sflag = 1;
			break;
		default:
			usage();
		}
		argc--; argv++;
	}

	nfiles = argc - 1;

	if (nfiles > 0) {
		for (i = 1; i < argc; i++) {
			cfilename = argv[i];
			f = fopen(cfilename, "r");
			if (f == NULL) {
				perror(cfilename);
				exit(1);
				}
			else {
				process(f);
				fclose(f);
			}
		}
	} else {
		cfilename = "stdin";
		process(stdin);
	}
	return (0);
}
예제 #9
0
파일: ex_tty.c 프로젝트: n-t-roff/ex-3.7
void
setterm(char *type)
{
	int tgetent(char *bp, const char *name);
	register int unknown, i;
	register int l;
	char ltcbuf[TCBUFSIZE];
	struct winsize win;
	char *s;

	if (type[0] == 0)
		type = "xx";
	unknown = 0;
	putpad(TE);
	if (tgetent(ltcbuf, type) != 1) {
		unknown++;
		CP(ltcbuf, "xx|dumb:");
	}
	gettmode();
	if (ioctl(0, TIOCGWINSZ, &win) < 0) {
		i = EX_LINES = tgetnum("li");
		COLUMNS = tgetnum("co");
	} else {
		if ((EX_LINES = win.ws_row) == 0)
			EX_LINES = tgetnum("li");
		i = EX_LINES;
		if ((COLUMNS = win.ws_col) == 0)
			COLUMNS = tgetnum("co");
	}
	if (EX_LINES <= 5)
		EX_LINES = 24;
	if (EX_LINES > TUBELINES)
		EX_LINES = TUBELINES;
	l = EX_LINES;
	if (ex_ospeed < B1200)
		l = 9;	/* including the message line at the bottom */
	else if (ex_ospeed < B2400)
		l = 17;
	if (l > EX_LINES)
		l = EX_LINES;
	aoftspace = tspace;
	zap();
	/*
	 * Initialize keypad arrow keys.
	 */
	arrows[0].cap = KU; arrows[0].mapto = "k"; arrows[0].descr = "up";
	arrows[1].cap = KD; arrows[1].mapto = "j"; arrows[1].descr = "down";
	arrows[2].cap = KL; arrows[2].mapto = "h"; arrows[2].descr = "left";
	arrows[3].cap = KR; arrows[3].mapto = "l"; arrows[3].descr = "right";
	arrows[4].cap = KH; arrows[4].mapto = "H"; arrows[4].descr = "home";

	/*
	 * Handle funny termcap capabilities
	 */
	if (CS && SC && RC) AL=DL="";
	if (AL_PARM && AL==NULL) AL="";
	if (DL_PARM && DL==NULL) DL="";
	if (IC && IM==NULL) IM="";
	if (IC && EI==NULL) EI="";
	if (!GT) BT=NULL;	/* If we can't tab, we can't backtab either */

#ifdef SIGTSTP
	/*
	 * Now map users susp char to ^Z, being careful that the susp
	 * overrides any arrow key, but only for hackers (=new tty driver).
	 */
	if (dosusp) {
		static char sc[2];
		int i;

		sc[0] = tty.c_cc[VSUSP];
		sc[1] = 0;
		if (*sc == CTRL('z')) {
			for (i=0; i<=4; i++)
				if (arrows[i].cap &&
				    arrows[i].cap[0] == CTRL('z'))
					addmac(sc, NULL, NULL, arrows);
		} else
			addmac(sc, "\32", "susp", arrows);
	}
#endif

	options[WINDOW].ovalue = options[WINDOW].odefault = l - 1;
	if (defwind) options[WINDOW].ovalue = defwind;
	options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2);
	if (COLUMNS <= 4)
		COLUMNS = 1000;
	if (!(s = tgoto(CM, 2, 2)) || *s == 'O')	/* OOPS */
		CA = 0, CM = 0;
	else
		CA = 1, costCM = cost(tgoto(CM, 8, 10));
	costSR = cost(SR);
	costAL = cost(AL);
	costDP = cost(tgoto(DOWN_PARM, 10, 10));
	costLP = cost(tgoto(LEFT_PARM, 10, 10));
	costRP = cost(tgoto(RIGHT_PARM, 10, 10));
	PC = xPC ? xPC[0] : 0;
	aoftspace = tspace;
	CP(ex_ttytype, longname(ltcbuf, type));
	if (i <= 0)
		EX_LINES = 2;
	/* proper strings to change tty type */
	termreset();
	value(REDRAW) = AL && DL;
	value(OPTIMIZE) = !CA && !GT;
	if (ex_ospeed == B1200 && !value(REDRAW))
		value(SLOWOPEN) = 1;	/* see also gettmode above */
	if (unknown)
		serror("%s: Unknown terminal type", type);
}
예제 #10
0
int
main(int argc, char **argv)
{
	FILE *f;
	int i;
	char *cp;
	char b1[4];

	/* Figure out how many known commands there are */
	while (knowncmds[ncmds])
		ncmds++;
	while (argc > 1 && argv[1][0] == '-') {
		switch(argv[1][1]) {

		/* -a: add pairs of macros */
		case 'a':
			i = strlen(argv[1]) - 2;
			if (i % 6 != 0)
				usage();
			/* look for empty macro slots */
			for (i=0; br[i].opbr; i++)
				;
			for (cp=argv[1]+3; cp[-1]; cp += 6) {
				if (i >= MAXBR)
					errx(1, "too many pairs");
				if ((br[i].opbr = malloc(3)) == NULL)
					err(1, "malloc");
				strlcpy(br[i].opbr, cp, 3);
				if ((br[i].clbr = malloc(3)) == NULL)
					err(1, "malloc");
				strlcpy(br[i].clbr, cp+3, 3);
				addmac(br[i].opbr);	/* knows pairs are also known cmds */
				addmac(br[i].clbr);
				i++;
			}
			break;

		/* -c: add known commands */
		case 'c':
			i = strlen(argv[1]) - 2;
			if (i % 3 != 0)
				usage();
			for (cp=argv[1]+3; cp[-1]; cp += 3) {
				if (cp[2] && cp[2] != '.')
					usage();
				strncpy(b1, cp, 2);
				addmac(b1);
			}
			break;

		/* -f: ignore font changes */
		case 'f':
			fflag = 1;
			break;

		/* -s: ignore size changes */
		case 's':
			sflag = 1;
			break;
		default:
			usage();
		}
		argc--; argv++;
	}

	nfiles = argc - 1;

	if (nfiles > 0) {
		for (i=1; i<argc; i++) {
			cfilename = argv[i];
			f = fopen(cfilename, "r");
			if (f == NULL)
				perror(cfilename);
			else {
				process(f);
				fclose(f);
			}
		}
	} else {
		cfilename = "stdin";
		process(stdin);
	}
	exit(0);
}