~ubuntu-branches/ubuntu/utopic/linux86/utopic

« back to all changes in this revision

Viewing changes to bcc/input.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-07 20:33:39 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071207203339-uonmnsb2j32kh0sg
Tags: 0.16.17-2ubuntu1
* Merge with Debian; remaining changes:
  - Build elks-libc for lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "input.h"
19
19
 
20
20
#define INBUFSIZE 2048
 
21
#define NO_EOFHACK
21
22
 
22
23
struct fbufstruct               /* file buffer structure */
23
24
{
30
31
    char fbuf[INBUFSIZE + 1];   /* buffer to read into */
31
32
};
32
33
 
 
34
#ifdef BUILTIN_CPP
33
35
struct inclist                  /* list of include file directories */
34
36
{
35
37
    char *incdirname;
53
55
};
54
56
PRIVATE fastin_t inclevel;      /* nest level of include files */
55
57
                                /* depends on zero init */
 
58
#endif
56
59
PRIVATE struct fbufstruct *inputbuf;    /* current input file buffer */
57
60
                                        /* its fcb only to date in includes */
58
61
                                        /* depends on zero (NULL) init */
61
64
#ifdef ARBITRARY_BACKSLASH_NEWLINES
62
65
FORWARD void backslash P((void));
63
66
#endif
 
67
#ifdef BUILTIN_CPP
64
68
FORWARD void definefile P((char *fname));
 
69
FORWARD void leaveinclude P((void));
 
70
#endif
65
71
FORWARD void inputinit P((char *fname, fd_t fd));
66
 
FORWARD void leaveinclude P((void));
67
72
FORWARD void usage P((void));
68
73
 
69
74
#ifdef ARBITRARY_BACKSLASH_NEWLINES
138
143
#else
139
144
    close(input.fd);
140
145
#endif
 
146
#ifdef BUILTIN_CPP
141
147
    while (inclevel != 0)
142
148
        leaveinclude();
 
149
#endif
143
150
}
144
151
 
 
152
#ifdef BUILTIN_CPP
145
153
PRIVATE void definefile(fname)
146
154
char *fname;
147
155
{
155
163
    definestring(def);
156
164
    ourfree(def);
157
165
}
 
166
#endif
158
167
 
159
168
PUBLIC void errorloc()
160
169
{
170
179
    {
171
180
        outudec(input.linenumber);
172
181
        outbyte('.');
 
182
#ifdef BUILTIN_CPP
173
183
        if (maclevel == 0)
174
184
            outudec((unsigned) (lineptr - inputbuf->fbuf) - input.lineoffset);
175
185
        else
180
190
            outudec((unsigned) maclevel);
181
191
            outbyte(')');
182
192
        }
 
193
#else
 
194
        outudec((unsigned) (lineptr - inputbuf->fbuf) - input.lineoffset);
 
195
#endif
183
196
    }
184
197
    infbuf->fcb.includer = input.includer;
185
198
    while ((infbuf = infbuf->fcb.includer) != NULL)
202
215
    specialchar();
203
216
}
204
217
 
 
218
#ifdef BUILTIN_CPP
205
219
/* process #include */
206
220
 
207
221
PUBLIC void include()
345
359
#endif
346
360
    charptr = fnameptr;
347
361
}
 
362
#endif
348
363
 
349
364
/* initialise current input file */
350
365
 
373
388
    inputbuf = newinputbuf;
374
389
    newinputbuf->fname = fname;
375
390
    newinputbuf->fname_malloced = FALSE;
 
391
#ifdef BUILTIN_CPP
376
392
    undefinestring(filemacro);
377
393
    definefile(fname);
378
394
    if (orig_cppmode && !suppress_line_numbers)
379
395
        outcpplinenumber(1, fname, input.includer == NULL ? "" : " 1");
 
396
#endif
380
397
    *(input.limit = newinputbuf->fbuf) = EOL;
381
398
 
382
 
    /* dummy line so #include processing can start with skipline() */
 
399
    /* dummy line so processing can start with skipline() */
383
400
    ch = *(lineptr = newinputbuf->fbuf - 1) = EOL;
384
401
}
385
402
 
386
403
PUBLIC void linecontol()
387
404
{
388
 
static char linename[32];
 
405
   char linename[256];
389
406
   char * ptr;
390
407
   int i=0;
391
408
 
408
425
#endif
409
426
        ourfree(inputbuf->fname);
410
427
}
411
 
    inputbuf->fname_malloced = FALSE;
412
 
    inputbuf->fname = linename;
 
428
    inputbuf->fname_malloced = TRUE;
 
429
    ptr = ourmalloc(strlen(linename)+1);
 
430
    strcpy(ptr, linename);
 
431
    inputbuf->fname = ptr;
413
432
 
414
433
    ptr=lineptr;
 
434
#ifdef BUILTIN_CPP
415
435
    undefinestring(filemacro);
416
436
    definefile(inputbuf->fname);
 
437
#endif
417
438
    ch = *(lineptr = ptr);
418
439
}
419
440
 
 
441
#ifdef BUILTIN_CPP
420
442
/* switch from include file to file which included it */
421
443
 
422
444
PRIVATE void leaveinclude()
449
471
    if (orig_cppmode && !suppress_line_numbers)
450
472
        outcpplinenumber(input.linenumber, inputbuf->fname, " 2");
451
473
}
 
474
#endif
452
475
 
453
476
/* open input and output files and get options */
454
477
 
460
483
    int argn;
461
484
    fd_t fd;
462
485
    char *fname;
 
486
#ifdef BUILTIN_CPP
463
487
    struct inclist *incnew;
464
488
    struct inclist *incptr;
 
489
#endif
465
490
    bool_t flag[128];
466
491
 
467
492
#if 0
473
498
    flag['3'] = sizeof (int) >= 4;
474
499
#endif
475
500
    fname = "stdin";
 
501
#ifdef BUILTIN_CPP
476
502
    (incptr = &incfirst)->incnext = &inclast;
 
503
#endif
477
504
    initout();
478
505
    for (argn = 1; argn < argc; ++argn)
479
506
    {
496
523
            case '3':           /* generate 32-bit code */
497
524
#endif
498
525
            case 'c':           /* caller saves */
499
 
#ifdef DEBUG
 
526
#ifdef DBNODE
500
527
            case 'd':           /* print debugging information in asm output */
501
528
#endif
 
529
#ifdef BUILTIN_CPP
502
530
            case 'E':           /* acting as cpp */
 
531
#endif
503
532
            case 'f':           /* pass first argument in register */
504
533
#ifdef DYNAMIC_LONG_ORDER
505
534
            case 'l':           /* long big-endian */
520
549
                if (arg[1] == '0')      /* flag 0 is negative logic flag 3 */
521
550
                    flag['3'] = TRUE + FALSE - flag['0'];
522
551
                break;
 
552
#ifdef BUILTIN_CPP
523
553
            case 'D':
524
554
                definestring(arg + 2);
525
555
                break;
536
566
            case 'U':
537
567
                undefinestring(arg + 2);
538
568
                break;
 
569
#endif
539
570
            case 'o':
540
571
                if (arg[2] != 0 || ++argn >= argc)
541
572
                    usage();
546
577
                break;
547
578
            }
548
579
    }
 
580
#ifdef BUILTIN_CPP
549
581
#ifdef I8088
550
582
#ifdef I80386
551
583
    if (flag['3'])
569
601
        callersaves = TRUE;
570
602
        definestring("__CALLER_SAVES__");
571
603
    }
572
 
#ifdef DEBUG
573
 
    debugon = flag['d'];
 
604
#ifdef DBNODE
 
605
    dbnodeon = flag['d'];
574
606
#endif
575
607
    orig_cppmode = cppmode = flag['E'];
576
608
    if (flag['f'])
607
639
#ifdef NOFLOAT
608
640
    definestring("__HAS_NO_FLOATS__");
609
641
#endif
 
642
 
 
643
#else /* !BUILTIN_CPP */
 
644
 
 
645
#ifdef I80386
 
646
    if (flag['3']) i386_32 = TRUE;
 
647
#endif
 
648
    if (flag['c']) callersaves = TRUE;
 
649
#ifdef DBNODE
 
650
    dbnodeon = flag['d'];
 
651
#endif
 
652
    if (flag['f']) arg1inreg = TRUE;
 
653
    arg1op = arg1inreg ? ROOTLISTOP : LISTOP;
 
654
#ifdef DYNAMIC_LONG_ORDER
 
655
    if (flag['l']) long_big_endian = TRUE;
 
656
#endif
 
657
    suppress_line_numbers = flag['P'];
 
658
#ifdef POSINDEPENDENT
 
659
    if (flag['p']) posindependent = TRUE;
 
660
#endif
 
661
    if (flag['O']) optimise = TRUE;
 
662
 
 
663
#endif
610
664
    ctext = flag['t'];
611
 
#ifdef DEBUG
612
 
    if (ctext) debugon = 1;
 
665
#ifdef DBNODE
 
666
    if (ctext) dbnodeon = 1;
613
667
#endif
614
668
    watchlc = flag['w'];
615
669
    setoutbufs();
628
682
    static bool_t skip_printing_nl;
629
683
#endif
630
684
    int nread;
 
685
    debug(7, "skipeol %s:%d", inputbuf->fname, input.linenumber);
631
686
 
632
687
    if (eofile)
633
688
        return;
642
697
            outbyte(' ');
643
698
            outline(lineptr);
644
699
        }
 
700
#ifdef BUILTIN_CPP
645
701
#ifndef ASM_BARE
646
702
        if (!virtual_nl && (orig_cppmode || asmmode))
647
703
#else
651
707
            if (!skip_printing_nl)
652
708
#endif
653
709
                outbyte('\n');
 
710
#else   /* !BUILTIN_CPP */
 
711
        if (asmmode)
 
712
#ifdef INSERT_BACKSLASH_NEWLINES
 
713
            if (!skip_printing_nl)
 
714
#endif
 
715
                outbyte('\n');
 
716
#endif
654
717
 
655
718
#ifdef INSERT_BACKSLASH_NEWLINES
656
719
        if (bs_state == 1 && *(lineptr - 1) == EOL)
699
762
#endif
700
763
        nread = read(input.fd, lineptr = inputbuf->fbuf, INBUFSIZE);
701
764
#ifndef NO_EOFHACK
 
765
#ifdef BUILTIN_CPP
702
766
        if( nread == 0 && inclevel > 0 )
703
767
        {
704
768
           close(input.fd);
706
770
           memcpy(inputbuf->fbuf, "\n", 1);
707
771
           nread = 1;
708
772
        }
 
773
#endif
709
774
    }
710
775
#endif
711
776
#endif
715
780
    ch = *lineptr;
716
781
    if (nread == 0)
717
782
    {
 
783
#ifdef BUILTIN_CPP
718
784
        if (inclevel == 0)
719
785
        {
720
786
            eofile = TRUE;
725
791
            leaveinclude();
726
792
            skipeol();
727
793
        }
 
794
#else
 
795
        eofile = TRUE;
 
796
#endif
728
797
        return;
729
798
    }
730
799
    if (ctext && !asmmode)
738
807
 
739
808
PUBLIC void specialchar()
740
809
{
 
810
#ifdef BUILTIN_CPP
741
811
    if (maclevel != 0)
742
812
    {
743
813
        if (ch == EOL)          /* it might also be backslash or COEOL */
745
815
        if (ch != EOL)
746
816
            return;
747
817
    }
 
818
#endif
748
819
more:
749
820
#ifdef ARBITRARY_BACKSLASH_NEWLINES
750
821
    if (ch == '\\')
808
879
PRIVATE void usage()
809
880
{
810
881
    fatalerror(
811
 
#ifdef MC6809
812
 
"usage: cc1 [-cdfptw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]");
813
 
#else 
814
 
#ifdef I80386
815
 
"usage: cc1 [-03cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]");
816
 
#else 
817
 
"usage: cc1 [-cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]");
818
 
#endif
819
 
#endif
 
882
#ifdef BUILTIN_CPP
 
883
#  ifdef MC6809
 
884
"usage: cc1 [-cdfptw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"
 
885
#  else 
 
886
#    ifdef I80386
 
887
"usage: cc1 [-03cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"
 
888
#    else 
 
889
"usage: cc1 [-cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"
 
890
#    endif
 
891
#  endif
 
892
#else 
 
893
#  ifdef I80386
 
894
"usage: cc1 [-03cdfltw[-]] [-o outfile] [infile]"
 
895
#  else 
 
896
"usage: cc1 [-cdfltw[-]] [-o outfile] [infile]"
 
897
#  endif
 
898
#endif
 
899
   );
820
900
}