Subversion Repositories planix.SVN

Rev

Rev 42 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 93
Line 45... Line 45...
45
	S_STNL, S_COMNL, S_EOFCOM, S_COMMENT, S_EOB, S_WS, S_NAME
45
	S_STNL, S_COMNL, S_EOFCOM, S_COMMENT, S_EOB, S_WS, S_NAME
46
};
46
};
47
 
47
 
48
struct	fsm {
48
struct	fsm {
49
	int	state;		/* if in this state */
49
	int	state;		/* if in this state */
50
	uchar	ch[4];		/* and see one of these characters */
50
	uint	ch[5];		/* and see one of these characters */
51
	int	nextstate;	/* enter this state if +ve */
51
	int	nextstate;	/* enter this state if +ve */
52
};
52
};
53
 
53
 
54
/*const*/ struct fsm fsm[] = {
54
/*const*/ struct fsm fsm[] = {
55
	/* start state */
55
	/* start state */
Line 233... Line 233...
233
	-1
233
	-1
234
};
234
};
235
 
235
 
236
/* first index is char, second is state */
236
/* first index is char, second is state */
237
/* increase #states to power of 2 to encourage use of shift */
237
/* increase #states to power of 2 to encourage use of shift */
238
short	bigfsm[256][MAXSTATE];
238
short	bigfsm[256+2][MAXSTATE];
239
 
239
 
240
void
240
void
241
expandlex(void)
241
expandlex(void)
242
{
242
{
243
	/*const*/ struct fsm *fp;
243
	/*const*/ struct fsm *fp;
Line 249... Line 249...
249
			if (nstate >= S_SELF)
249
			if (nstate >= S_SELF)
250
				nstate = ~nstate;
250
				nstate = ~nstate;
251
			switch (fp->ch[i]) {
251
			switch (fp->ch[i]) {
252
 
252
 
253
			case C_XX:		/* random characters */
253
			case C_XX:		/* random characters */
254
				for (j=0; j<256; j++)
254
				for (j=0; j<256+2; j++)
255
					bigfsm[j][fp->state] = nstate;
255
					bigfsm[j][fp->state] = nstate;
256
				continue;
256
				continue;
257
			case C_ALPH:
257
			case C_ALPH:
258
				for (j=0; j<=256; j++)
258
				for (j=0; j<=256+2; j++)
259
					if ('a'<=j&&j<='z' || 'A'<=j&&j<='Z'
259
					if ('a'<=j&&j<='z' || 'A'<=j&&j<='Z'
260
					  || UTF2(j) || UTF3(j) || j=='_')
260
					  || UTF2(j) || UTF3(j) || j=='_')
261
						bigfsm[j][fp->state] = nstate;
261
						bigfsm[j][fp->state] = nstate;
262
				continue;
262
				continue;
263
			case C_NUM:
263
			case C_NUM:
Line 338... Line 338...
338
		tp->wslen = 0;
338
		tp->wslen = 0;
339
		tp->flag = 0;
339
		tp->flag = 0;
340
		state = START;
340
		state = START;
341
		for (;;) {
341
		for (;;) {
342
			oldstate = state;
342
			oldstate = state;
-
 
343
//print ("old state = %d .. %d\n",oldstate, ID1);
-
 
344
 
-
 
345
			if (ip >= s->inl){
-
 
346
				c=s->eob;
-
 
347
				//print ("eob found %d\n",c);
-
 
348
                        }
-
 
349
			else{
343
			c = *ip;
350
				c = *ip;
-
 
351
			}
-
 
352
 
-
 
353
//			printf("[%c(%d)]",c,c);
-
 
354
 
344
			if ((state = bigfsm[c][state]) >= 0) {
355
			if ((state = bigfsm[c][state]) >= 0) {
345
				ip += runelen;
356
				ip += runelen;
346
				runelen = 1;
357
				runelen = 1;
347
				continue;
358
				continue;
348
			}
359
			}
-
 
360
 
349
			state = ~state;
361
			state = ~state;
-
 
362
//print ("xor state > 0 = %d  S_NAME=%d, S_NL=%d\n",state,S_NAME,S_NL);
350
		reswitch:
363
		reswitch:
351
			switch (state&0177) {
364
			switch (state&0177) {
352
			case S_SELF:
365
			case S_SELF:
-
 
366
//print("self\n");				
353
				ip += runelen;
367
				ip += runelen;
354
				runelen = 1;
368
				runelen = 1;
355
			case S_SELFB:
369
			case S_SELFB:
-
 
370
//print("selfb\n");				
356
				tp->type = GETACT(state);
371
				tp->type = GETACT(state);
357
				tp->len = ip - tp->t;
372
				tp->len = ip - tp->t;
358
				tp++;
373
				tp++;
359
				goto continue2;
374
				goto continue2;
360
 
375
 
361
			case S_NAME:	/* like S_SELFB but with nmac check */
376
			case S_NAME:	/* like S_SELFB but with nmac check */
-
 
377
//print("Name state\n");				
362
				tp->type = NAME;
378
				tp->type = NAME;
363
				tp->len = ip - tp->t;
379
				tp->len = ip - tp->t;
364
				nmac |= quicklook(tp->t[0], tp->len>1?tp->t[1]:0);
380
				nmac |= quicklook(tp->t[0], tp->len>1?tp->t[1]:0);
365
				tp++;
381
				tp++;
366
				goto continue2;
382
				goto continue2;
367
 
383
 
368
			case S_WS:
384
			case S_WS:
369
				tp->wslen = ip - tp->t;
385
				tp->wslen = ip - tp->t;
370
				tp->t = ip;
386
				tp->t = ip;
371
				state = START;
387
				state = START;
372
				continue;
388
				continue;
373
 
389
 
374
			default:
390
			default:
375
				if ((state&QBSBIT)==0) {
391
				if ((state&QBSBIT)==0) {
376
					ip += runelen;
392
					ip += runelen;
377
					runelen = 1;
393
					runelen = 1;
378
					continue;
394
					continue;
379
				}
395
				}
380
				state &= ~QBSBIT;
396
				state &= ~QBSBIT;
381
				s->inp = ip;
397
				s->inp = ip;
382
				if (c=='?') { 	/* check trigraph */
398
				if (c=='?') { 	/* check trigraph */
383
					if (trigraph(s)) {
399
					if (trigraph(s)) {
384
						state = oldstate;
400
						state = oldstate;
385
						continue;
401
						continue;
386
					}
402
					}
387
					goto reswitch;
403
					goto reswitch;
388
				}
404
				}
389
				if (c=='\\') { /* line-folding */
405
				if (c=='\\') { /* line-folding */
390
					if (foldline(s)) {
406
					if (foldline(s)) {
391
						s->lineinc++;
407
						s->lineinc++;
392
						state = oldstate;
408
						state = oldstate;
393
						continue;
409
						continue;
394
					}
410
					}
395
					goto reswitch;
411
					goto reswitch;
396
				}
412
				}
397
				if (UTF2(c)) {
413
				if (UTF2(c)) {
398
					runelen = 2;
414
					runelen = 2;
399
					goto reswitch;
415
					goto reswitch;
400
				}
416
				}
401
				if (UTF3(c)) {
417
				if (UTF3(c)) {
402
					runelen = 3;
418
					runelen = 3;
403
					goto reswitch;
419
					goto reswitch;
404
				}
420
				}
405
				error(WARNING, "Lexical botch in cpp");
421
				error(WARNING, "Lexical botch in cpp");
406
				ip += runelen;
422
				ip += runelen;
407
				runelen = 1;
423
				runelen = 1;
408
				continue;
424
				continue;
409
 
425
 
410
			case S_EOB:
426
			case S_EOB:
-
 
427
//				print ("fill buffer\n");
411
				s->inp = ip;
428
				s->inp = ip;
412
				fillbuf(cursource);
429
				fillbuf(cursource);
413
				state = oldstate;
430
				state = oldstate;
414
				continue;
431
				continue;
415
 
432
 
416
			case S_EOF:
433
			case S_EOF:
-
 
434
//				print("The end eof\n");
417
				tp->type = END;
435
				tp->type = END;
418
				tp->len = 0;
436
				tp->len = 0;
419
				s->inp = ip;
437
				s->inp = ip;
420
				if (tp!=trp->bp && (tp-1)->type!=NL && cursource->fd!=-1)
438
				if (tp!=trp->bp && (tp-1)->type!=NL && cursource->fd!=-1)
421
					error(WARNING,"No newline at end of file");
439
					error(WARNING,"No newline at end of file");
422
				trp->lp = tp+1;
440
				trp->lp = tp+1;
423
				return nmac;
441
				return nmac;
424
 
442
 
425
			case S_STNL:
443
			case S_STNL:
426
				error(ERROR, "Unterminated string or char const");
444
				error(ERROR, "Unterminated string or char const");
427
			case S_NL:
445
			case S_NL:
-
 
446
//print ("We are at nl state\n");				
428
				tp->t = ip;
447
				tp->t = ip;
429
				tp->type = NL;
448
				tp->type = NL;
430
				tp->len = 1;
449
				tp->len = 1;
431
				tp->wslen = 0;
450
				tp->wslen = 0;
432
				s->lineinc++;
451
				s->lineinc++;
Line 523... Line 542...
523
	}
542
	}
524
	if (s->inp[ncr+1] == '\n') {
543
	if (s->inp[ncr+1] == '\n') {
525
		memmove(s->inp, s->inp+2+ncr, s->inl-s->inp+3-ncr);
544
		memmove(s->inp, s->inp+2+ncr, s->inl-s->inp+3-ncr);
526
		s->inl -= 2+ncr;
545
		s->inl -= 2+ncr;
527
		return 1;
546
		return 1;
528
	}
547
	}
529
	return 0;
548
	return 0;
530
}
549
}
531
 
550
 
532
int
551
int
533
fillbuf(Source *s)
552
fillbuf(Source *s)
Line 547... Line 566...
547
		s->inl = s->inb + l;
566
		s->inl = s->inb + l;
548
		s->inp = s->inb + p;
567
		s->inp = s->inb + p;
549
	}
568
	}
550
	if (s->fd<0 || (n=read(s->fd, (char *)s->inl, s->ins/8)) <= 0)
569
	if (s->fd<0 || (n=read(s->fd, (char *)s->inl, s->ins/8)) <= 0)
551
		n = 0;
570
		n = 0;
-
 
571
 
552
	if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
572
//	if ((*s->inp&0xff) == EOB) /* sentinel character appears in input 
553
		*s->inp = EOFC;
573
//		*s->inp = EOFC;
554
	s->inl += n;
574
	s->inl += n;
555
	s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOB;
575
//	s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOB;
556
	if (n==0) {
576
//	if (n==0) {
557
		s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOFC;
577
//		s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOFC;
-
 
578
//		return EOF;
-
 
579
//	}
-
 
580
//
-
 
581
 
-
 
582
	if (n!=0)
-
 
583
		s->eob=EOB;
-
 
584
	else {
-
 
585
		s->eob=EOFC;
558
		return EOF;
586
		return EOF;
559
	}
587
	}		
560
	return 0;
588
	return 0;
561
}
589
}
562
 
590
 
563
/*
591
/*
564
 * Push down to new source of characters.
592
 * Push down to new source of characters.
Line 576... Line 604...
576
	s->fd = fd;
604
	s->fd = fd;
577
	s->filename = name;
605
	s->filename = name;
578
	s->next = cursource;
606
	s->next = cursource;
579
	s->ifdepth = 0;
607
	s->ifdepth = 0;
580
	cursource = s;
608
	cursource = s;
-
 
609
	s->eob=EOB;
581
	/* slop at right for EOB */
610
	/* slop at right for EOB */
582
	if (str) {
611
	if (str) {
583
		len = strlen(str);
612
		len = strlen(str);
584
		s->inb = domalloc(len+4);
613
		s->inb = domalloc(len+4);
585
		s->inp = s->inb;
614
		s->inp = s->inb;
Line 601... Line 630...
601
		len = 0;
630
		len = 0;
602
	}
631
	}
603
 
632
 
604
	s->ins = INS;	
633
	s->ins = INS;	
605
	s->inl = s->inp+len;
634
	s->inl = s->inp+len;
606
	s->inl[0] = s->inl[1] = EOB;
635
//	s->inl[0] = s->inl[1] = EOB;
607
	return s;
636
	return s;
608
}
637
}
609
 
638
 
610
void
639
void
611
unsetsource(void)
640
unsetsource(void)