comparison mc-macro.c @ 609:af6b9ae79583 udpcl

modificatioon for udpcl
author kono
date Thu, 16 Mar 2006 17:03:24 +0900
parents e055df7c1082
children e4e007f4026d
comparison
equal deleted inserted replaced
608:c3ba27861c83 609:af6b9ae79583
310 getline(void) 310 getline(void)
311 { 311 {
312 int i; 312 int i;
313 int c; 313 int c;
314 char num[10]; 314 char num[10];
315 char *p;
315 316
316 if (next_eof) { 317 if (next_eof) {
317 next_eof=0; 318 next_eof=0;
318 error(EOFERR); 319 error(EOFERR);
319 } 320 }
333 glineno++; 334 glineno++;
334 chptr=linebuf; 335 chptr=linebuf;
335 i=0; 336 i=0;
336 while ((*chptr++ = c = getc(filep->fcb)) != '\n') { 337 while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
337 if (++i > LBUFSIZE-2) error(LNERR); 338 if (++i > LBUFSIZE-2) error(LNERR);
339 if (c=='\r') {
340 c = getc(filep->fcb);
341 if (c == '\n') {
342 chptr[-1]='\n'; break;
343 } else {
344 // single cr equal to nl
345 ungetc(c,filep->fcb);
346 chptr[-1]=c='\n'; i--; break;
347 }
348 }
338 if (c==EOF) { 349 if (c==EOF) {
339 next_eof=1; 350 next_eof=1;
340 --chptr; 351 --chptr;
341 break; 352 break;
342 } 353 }
347 gen_comment(linebuf); 358 gen_comment(linebuf);
348 if (inmode) { 359 if (inmode) {
349 // inline mode 360 // inline mode
350 int i=0; 361 int i=0;
351 int c; 362 int c;
352 char *p;
353 // should be done in some init 363 // should be done in some init
354 if (!st_cheap) { 364 if (!st_cheap) {
355 st_cheap = cheap1 = new_cheap(); 365 st_cheap = cheap1 = new_cheap();
356 } 366 }
357 367
375 st_cheap = increment_cheap(st_cheap,&p); 385 st_cheap = increment_cheap(st_cheap,&p);
376 } 386 }
377 } 387 }
378 } 388 }
379 } 389 }
380 if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) { 390 p = chptr = linebuf; while(*p==' '||*p=='\t') p++;
391 if (*p == '#' && !in_comment && !in_quote) {
392 chptr = p;
381 if (macro_processing()) return; 393 if (macro_processing()) return;
382 } 394 }
383 } while(!in_quote && (macro_if_skip || linebuf[0] == '#')); 395 } while(!in_quote && (macro_if_skip || linebuf[0] == '#'));
384 } 396 }
385 397
547 ++filep; 559 ++filep;
548 *(chptr = linebuf) = '\0'; 560 *(chptr = linebuf) = '\0';
549 return 0; 561 return 0;
550 } 562 }
551 break; 563 break;
564 case 'p':
565 if (macroeq("pragma")) {
566 getline();
567 return 0;
568 }
569 break;
552 #if ASM_CODE 570 #if ASM_CODE
553 // deprecated, use asm function 571 // deprecated, use asm function
554 case 'a': 572 case 'a':
555 if (c=='a'&&macroeq("asm")) { 573 if (macroeq("asm")) {
556 if (asmf) error(MCERR); 574 if (asmf) error(MCERR);
557 asmf = 1; 575 asmf = 1;
558 getline(); 576 getline();
559 while (asmf) { 577 while (asmf) {
560 printf("%s",linebuf); 578 printf("%s",linebuf);
569 asmf = 0; 587 asmf = 0;
570 return 0; 588 return 0;
571 } 589 }
572 break; 590 break;
573 #endif 591 #endif
574 case ' ': case '\t': 592 case ' ': case '\t': case '\n': case 0:
575 getline(); 593 getline();
576 return 0; 594 return 0;
577 } 595 }
578 error(MCERR); 596 error(MCERR);
579 return 0; 597 return 0;
923 { 941 {
924 char *p; 942 char *p;
925 *result = cheap->ptr; 943 *result = cheap->ptr;
926 for(;lists;lists = cadr(lists)) { 944 for(;lists;lists = cadr(lists)) {
927 p = (char *)car(lists); 945 p = (char *)car(lists);
928 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) { 946 for(;(*cheap->ptr = *p++);cheap = increment_cheap(cheap,result)) {
929 // in_quote + \n case ? should be \n. 947 // in_quote + \n case ? should be \n.
930 if (p[-1]=='\n') cheap->ptr[0]=' '; 948 if (p[-1]=='\n') cheap->ptr[0]=' ';
931 } 949 }
932 } 950 }
933 cheap = increment_cheap(cheap,0); 951 cheap = increment_cheap(cheap,result);
934 return *result; 952 return *result;
935 } 953 }
936 954
937 // do not replace \n 955 // do not replace \n
938 extern char * 956 extern char *
940 { 958 {
941 char *p; 959 char *p;
942 *result = cheap->ptr; 960 *result = cheap->ptr;
943 for(;lists;lists = cadr(lists)) { 961 for(;lists;lists = cadr(lists)) {
944 p = (char *)car(lists); 962 p = (char *)car(lists);
945 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) { 963 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,result)) {
946 // in_quote + \n case ? should be \n. 964 // in_quote + \n case ? should be \n.
947 // if (p[-1]=='\n') cheap->ptr[0]=' '; 965 // if (p[-1]=='\n') cheap->ptr[0]=' ';
948 } 966 }
949 } 967 }
950 cheap = increment_cheap(cheap,0); 968 cheap = increment_cheap(cheap,result);
951 return *result; 969 return *result;
952 } 970 }
953 971
954 /* end */ 972 /* end */