Ticket #148: makedepend.patch

File makedepend.patch, 130.8 KB (added by Mark Hammond, 17 years ago)

patch to get makedepend building

  • ifparser.h

     
    7878    const char *,
    7979    long *
    8080);
    81 
    82 /*
    83  * Copyright 1992 Network Computing Devices, Inc.
    84  *
    85  * Permission to use, copy, modify, and distribute this software and its
    86  * documentation for any purpose and without fee is hereby granted, provided
    87  * that the above copyright notice appear in all copies and that both that
    88  * copyright notice and this permission notice appear in supporting
    89  * documentation, and that the name of Network Computing Devices may not be
    90  * used in advertising or publicity pertaining to distribution of the software
    91  * without specific, written prior permission.  Network Computing Devices makes
    92  * no representations about the suitability of this software for any purpose.
    93  * It is provided ``as is'' without express or implied warranty.
    94  *
    95  * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
    96  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
    97  * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
    98  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    99  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
    100  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    101  * PERFORMANCE OF THIS SOFTWARE.
    102  *
    103  * Author:  Jim Fulton
    104  *          Network Computing Devices, Inc.
    105  *
    106  * Simple if statement processor
    107  *
    108  * This module can be used to evaluate string representations of C language
    109  * if constructs.  It accepts the following grammar:
    110  *
    111  *     EXPRESSION       :=      VALUE
    112  *                       |      VALUE  BINOP    EXPRESSION
    113  *                       |      VALUE   '?'     EXPRESSION ':'  EXPRESSION
    114  *
    115  *     VALUE            :=      '('  EXPRESSION  ')'
    116  *                       |      '!'  VALUE
    117  *                       |      '-'  VALUE
    118  *                       |      '~'  VALUE
    119  *                       |      'defined'  '('  variable  ')'
    120  *                       |      variable
    121  *                       |      number
    122  *
    123  *     BINOP            :=      '*'     |  '/'  |  '%'
    124  *                       |      '+'     |  '-'
    125  *                       |      '<<'    |  '>>'
    126  *                       |      '<'     |  '>'  |  '<='  |  '>='
    127  *                       |      '=='    |  '!='
    128  *                       |      '&'     |  '^'  |  '|'
    129  *                       |      '&&'    |  '||'
    130  *
    131  * The normal C order of precedence is supported.
    132  *
    133  *
    134  * External Entry Points:
    135  *
    136  *     ParseIfExpression                parse a string for #if
    137  */
    138 
    139 /* $Header: /code/makedepend/ifparser.h,v 1.2 2004/04/20 19:50:26 doj Exp $ */
    140 
    141 #include <stdio.h>
    142 
    143 typedef int Bool;
    144 #define False 0
    145 #define True 1
    146 
    147 typedef struct _if_parser {
    148     struct {                            /* functions */
    149         const char *(*handle_error) (struct _if_parser *, const char *,
    150                                      const char *);
    151         long (*eval_variable) (struct _if_parser *, const char *, int);
    152         int (*eval_defined) (struct _if_parser *, const char *, int);
    153     } funcs;
    154     char *data;
    155 } IfParser;
    156 
    157 const char *ParseIfExpression (
    158     IfParser *,
    159     const char *,
    160     long *
    161 );
    162 
  • imakemdep.h

     
    14261426# endif /* MAKEDEPEND */
    14271427
    14281428#endif /* CCIMAKE */
    1429 /*
    1430 
    1431 Copyright (c) 1993, 1994, 1998  The Open Group
    1432 
    1433 Permission to use, copy, modify, distribute, and sell this software and its
    1434 documentation for any purpose is hereby granted without fee, provided that
    1435 the above copyright notice appear in all copies and that both that
    1436 copyright notice and this permission notice appear in supporting
    1437 documentation.
    1438 
    1439 The above copyright notice and this permission notice shall be included in
    1440 all copies or substantial portions of the Software.
    1441 
    1442 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1443 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1444 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    1445 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    1446 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    1447 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1448 
    1449 Except as contained in this notice, the name of The Open Group shall not be
    1450 used in advertising or otherwise to promote the sale, use or other dealings
    1451 in this Software without prior written authorization from The Open Group.
    1452 
    1453 */
    1454 /* $Header: /code/makedepend/imakemdep.h,v 1.2 2004/04/20 19:50:26 doj Exp $ */
    1455 
    1456 
    1457 /*
    1458  * This file contains machine-dependent constants for the imake utility.
    1459  * When porting imake, read each of the steps below and add in any necessary
    1460  * definitions.  In general you should *not* edit ccimake.c or imake.c!
    1461  */
    1462 
    1463 #ifdef __UNIXOS2__
    1464 #define lstat stat
    1465 #endif
    1466 
    1467 #ifdef CCIMAKE
    1468 /*
    1469  * Step 1:  imake_ccflags
    1470  *     Define any special flags that will be needed to get imake.c to compile.
    1471  *     These will be passed to the compile along with the contents of the
    1472  *     make variable BOOTSTRAPCFLAGS.
    1473  */
    1474 #if defined(clipper) || defined(__clipper__)
    1475 #define imake_ccflags "-O -DSYSV -DBOOTSTRAPCFLAGS=-DSYSV"
    1476 #endif
    1477 
    1478 #ifdef hpux
    1479 #ifdef hp9000s800
    1480 #define imake_ccflags "-DSYSV"
    1481 #else
    1482 #define imake_ccflags "-Wc,-Nd4000,-Ns3000 -DSYSV"
    1483 #endif
    1484 #endif
    1485 
    1486 #if defined(macII) || defined(_AUX_SOURCE)
    1487 #define imake_ccflags "-DmacII -DSYSV"
    1488 #endif
    1489 
    1490 #ifdef stellar
    1491 #define imake_ccflags "-DSYSV"
    1492 #endif
    1493 
    1494 #if defined(USL) || defined(__USLC__) || defined(Oki) || defined(NCR)
    1495 #define imake_ccflags "-Xa -DSVR4"
    1496 #endif
    1497 
    1498 /* SCO may define __USLC__ so put this after the USL check */
    1499 #if defined(M_UNIX) || defined(_SCO_DS)
    1500 #ifdef imake_ccflags
    1501 #undef imake_ccflags
    1502 #endif
    1503 #define imake_ccflags "-Dsco -DSYSV -DSCO -DSCO325"
    1504 #endif
    1505 
    1506 #ifdef sony
    1507 #if defined(SYSTYPE_SYSV) || defined(_SYSTYPE_SYSV)
    1508 #define imake_ccflags "-DSVR4"
    1509 #else
    1510 #include <sys/param.h>
    1511 #if NEWSOS < 41
    1512 #define imake_ccflags "-Dbsd43 -DNOSTDHDRS"
    1513 #else
    1514 #if NEWSOS < 42
    1515 #define imake_ccflags "-Dbsd43"
    1516 #endif
    1517 #endif
    1518 #endif
    1519 #endif
    1520 #ifdef _CRAY
    1521 #define imake_ccflags "-DSYSV -DUSG"
    1522 #endif
    1523 
    1524 #if defined(_IBMR2) || defined(aix)
    1525 #define imake_ccflags "-Daix -DSYSV"
    1526 #endif
    1527 
    1528 #ifdef Mips
    1529 #  if defined(SYSTYPE_BSD) || defined(BSD) || defined(BSD43)
    1530 #    define imake_ccflags "-DBSD43"
    1531 #  else
    1532 #    define imake_ccflags "-DSYSV"
    1533 #  endif
    1534 #endif
    1535 
    1536 #ifdef is68k
    1537 #define imake_ccflags "-Dluna -Duniosb"
    1538 #endif
    1539 
    1540 #ifdef SYSV386
    1541 # ifdef SVR4
    1542 #  define imake_ccflags "-Xa -DSVR4"
    1543 # else
    1544 #  define imake_ccflags "-DSYSV"
    1545 # endif
    1546 #endif
    1547 
    1548 #ifdef SVR4
    1549 # ifdef i386
    1550 #  define imake_ccflags "-Xa -DSVR4"
    1551 # endif
    1552 #endif
    1553 
    1554 #ifdef SYSV
    1555 # ifdef i386
    1556 #  define imake_ccflags "-DSYSV"
    1557 # endif
    1558 #endif
    1559 
    1560 #if defined(Lynx) || defined(__Lynx__)
    1561 #define imake_ccflags "-DLynx"
    1562 #endif /* Lynx */
    1563 
    1564 #ifdef __convex__
    1565 #define imake_ccflags "-fn -tm c1"
    1566 #endif
    1567 
    1568 #ifdef apollo
    1569 #define imake_ccflags "-DX_NOT_POSIX"
    1570 #endif
    1571 
    1572 #ifdef WIN32
    1573 #if _MSC_VER < 1000
    1574 #define imake_ccflags "-nologo -batch -D__STDC__"
    1575 #else
    1576 #define imake_ccflags "-nologo -D__STDC__"
    1577 #endif
    1578 #endif
    1579 
    1580 #ifdef __uxp__
    1581 #define imake_ccflags "-DSVR4 -DANSICPP"
    1582 #endif
    1583 
    1584 #ifdef __sxg__
    1585 #define imake_ccflags "-DSYSV -DUSG -DNOSTDHDRS"
    1586 #endif
    1587 
    1588 #ifdef _SEQUENT_
    1589 #define imake_ccflags "-Xa -DSVR4"
    1590 #endif
    1591 
    1592 #if defined(SX) || defined(PC_UX)
    1593 #define imake_ccflags "-DSYSV"
    1594 #endif
    1595 
    1596 #ifdef nec_ews_svr2
    1597 #define imake_ccflags "-DUSG"
    1598 #endif
    1599 
    1600 #if defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(_nec_up) || defined(_nec_ft)
    1601 #define imake_ccflags "-DSVR4"
    1602 #endif
    1603 
    1604 #if defined(MACH) && !defined(__GNU__)
    1605 #define imake_ccflags "-DNOSTDHDRS"
    1606 #endif
    1607 
    1608 /* this is for OS/2 under UNIXOS2. This won't work with DOS */
    1609 #if defined(__UNIXOS2__)
    1610 #define imake_ccflags "-DBSD43"
    1611 #endif
    1612 
    1613 #if defined(__QNX__) && !defined(__QNXNTO__)
    1614 #define imake_ccflags "-D__QNX__ -D_i386"
    1615 #endif
    1616 
    1617 #if defined(__QNXNTO__)
    1618 #define imake_ccflags "-D__QNXNTO__"
    1619 #endif
    1620 
    1621 #else /* not CCIMAKE */
    1622 #ifndef MAKEDEPEND
    1623 /*
    1624  * Step 2:  dup2
    1625  *     If your OS doesn't have a dup2() system call to duplicate one file
    1626  *     descriptor onto another, define such a mechanism here (if you don't
    1627  *     already fall under the existing category(ies).
    1628  */
    1629 #if defined(SYSV) && !defined(_CRAY) && !defined(Mips) && !defined(_SEQUENT_) && !defined(sco)
    1630 #define dup2(fd1,fd2)   ((fd1 == fd2) ? fd1 : (close(fd2), \
    1631                                                fcntl(fd1, F_DUPFD, fd2)))
    1632 #endif
    1633 
    1634 
    1635 /*
    1636  * Step 3:  FIXUP_CPP_WHITESPACE
    1637  *     If your cpp collapses tabs in macro expansions into a single space and
    1638  *     replaces escaped newlines with a space, define this symbol.  This will
    1639  *     cause imake to attempt to patch up the generated Makefile by looking
    1640  *     for lines that have colons in them (this is why the rules file escapes
    1641  *     all colons).  One way to tell if you need this is to see whether or not
    1642  *     your Makefiles have no tabs in them and lots of @@ strings.
    1643  */
    1644 #if defined(sun) || defined(SYSV) || defined(SVR4) || defined(hcx) || defined(WIN32) || defined(sco) || (defined(AMOEBA) && defined(CROSS_COMPILE)) || defined(__QNX__) || defined(__sgi) || defined(__UNIXOS2__)
    1645 #define FIXUP_CPP_WHITESPACE
    1646 #endif
    1647 #ifdef WIN32
    1648 #define REMOVE_CPP_LEADSPACE
    1649 #define INLINE_SYNTAX
    1650 #define MAGIC_MAKE_VARS
    1651 #endif
    1652 #ifdef __minix_vmd
    1653 #define FIXUP_CPP_WHITESPACE
    1654 #endif
    1655 
    1656 #if defined(Lynx)
    1657 /* On LynxOS 2.4.0 imake gets built with the old "legacy"
    1658  * /bin/cc which has a rather pedantic builtin preprocessor.
    1659  * Using a macro which is not #defined (as in Step 5
    1660  * below) flags an *error*
    1661  */
    1662 #define __NetBSD_Version__ 0
    1663 #endif
    1664 
    1665 /*
    1666  * Step 4:  USE_CC_E, DEFAULT_CC, DEFAULT_CPP
    1667  *     If you want to use cc -E instead of cpp, define USE_CC_E.
    1668  *     If use cc -E but want a different compiler, define DEFAULT_CC.
    1669  *     If the cpp you need is not in /lib/cpp, define DEFAULT_CPP.
    1670  */
    1671 #if !defined (CROSSCOMPILE) || defined (CROSSCOMPILE_CPP)
    1672 
    1673 #if defined(__APPLE__)
    1674 #define DEFAULT_CPP "/usr/bin/cpp"
    1675 #define DEFAULT_CC "cc"
    1676 #endif
    1677 #if defined(Lynx) || defined(__Lynx__)
    1678 #define DEFAULT_CC "gcc"
    1679 #define USE_CC_E
    1680 #endif
    1681 #ifdef hpux
    1682 #define USE_CC_E
    1683 #endif
    1684 #ifdef WIN32
    1685 #define USE_CC_E
    1686 #define DEFAULT_CC "cl"
    1687 #endif
    1688 #ifdef apollo
    1689 #define DEFAULT_CPP "/usr/lib/cpp"
    1690 #endif
    1691 #if defined(clipper) || defined(__clipper__)
    1692 #define DEFAULT_CPP "/usr/lib/cpp"
    1693 #endif
    1694 #if defined(_IBMR2) && !defined(DEFAULT_CPP)
    1695 #define DEFAULT_CPP "/usr/ccs/lib/cpp"
    1696 #endif
    1697 #if defined(sun) && (defined(SVR4) || defined(__svr4__) || defined(__SVR4) || defined(__sol__))
    1698 #define DEFAULT_CPP "/usr/ccs/lib/cpp"
    1699 #endif
    1700 #ifdef __bsdi__
    1701 #define DEFAULT_CPP "/usr/bin/cpp"
    1702 #endif
    1703 #ifdef __uxp__
    1704 #define DEFAULT_CPP "/usr/ccs/lib/cpp"
    1705 #endif
    1706 #ifdef __sxg__
    1707 #define DEFAULT_CPP "/usr/lib/cpp"
    1708 #endif
    1709 #ifdef _CRAY
    1710 #define DEFAULT_CPP "/lib/pcpp"
    1711 #endif
    1712 #if defined(__386BSD__)
    1713 #define DEFAULT_CPP "/usr/libexec/cpp"
    1714 #endif
    1715 #if defined(__FreeBSD__)  || defined(__NetBSD__) || defined(__OpenBSD__)
    1716 #define USE_CC_E
    1717 #endif
    1718 #if defined(__sgi) && defined(__ANSI_CPP__)
    1719 #define USE_CC_E
    1720 #endif
    1721 #if defined(MACH) && !defined(__GNU__)
    1722 #define USE_CC_E
    1723 #endif
    1724 #ifdef __minix_vmd
    1725 #define DEFAULT_CPP "/usr/lib/cpp"
    1726 #endif
    1727 #if defined(__UNIXOS2__)
    1728 /* expects cpp in PATH */
    1729 #define DEFAULT_CPP "cpp"
    1730 #endif
    1731 #ifdef __CYGWIN__
    1732 #define DEFAULT_CC "gcc"
    1733 #define DEFAULT_CPP "/usr/bin/cpp"
    1734 #endif
    1735 #if defined (__QNX__)
    1736 #ifdef __QNXNTO__
    1737 #define DEFAULT_CPP "/usr/bin/cpp"
    1738 #else
    1739 #define DEFAULT_CPP "/usr/X11R6/bin/cpp"
    1740 #endif
    1741 #endif
    1742 #if defined(__GNUC__) && !defined(USE_CC_E)
    1743 #define USE_CC_E
    1744 #ifndef DEFAULT_CC
    1745 #define DEFAULT_CC "gcc"
    1746 #endif
    1747 #endif
    1748 
    1749 #endif /* !defined (CROSSCOMPILE) || defined (CROSSCOMPILE_CPP) */
    1750 /*
    1751  * Step 5:  cpp_argv
    1752  *     The following table contains the flags that should be passed
    1753  *     whenever a Makefile is being generated.  If your preprocessor
    1754  *     doesn't predefine any unique symbols, choose one and add it to the
    1755  *     end of this table.  Then, do the following:
    1756  *
    1757  *         a.  Use this symbol in Imake.cf when setting MacroFile.
    1758  *         b.  Put this symbol in the definition of BootstrapCFlags in your
    1759  *             <platform>.cf file.
    1760  *         c.  When doing a make World, always add "BOOTSTRAPCFLAGS=-Dsymbol"
    1761  *             to the end of the command line.
    1762  *
    1763  *     Note that you may define more than one symbol (useful for platforms
    1764  *     that support multiple operating systems).
    1765  */
    1766 
    1767 #define ARGUMENTS 50    /* number of arguments in various arrays */
    1768 #if !defined (CROSSCOMPILE) || defined (CROSSCOMPILE_CPP)
    1769 char *cpp_argv[ARGUMENTS] = {
    1770         "cc",           /* replaced by the actual program to exec */
    1771         "-I.",          /* add current directory to include path */
    1772 #if !defined(__NetBSD_Version__) || __NetBSD_Version__ < 103080000
    1773 #ifdef unix
    1774         "-Uunix",       /* remove unix symbol so that filename unix.c okay */
    1775 #endif
    1776 #endif
    1777 #if defined(__386BSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
    1778     defined(__FreeBSD__) || defined(MACH) || defined(linux) || \
    1779     defined(__GNU__) || defined(__bsdi__) || defined(__GNUC__)
    1780 # ifdef __i386__
    1781         "-D__i386__",
    1782 #  if defined(__GNUC__) && (__GNUC__ >= 3)
    1783         "-m32",
    1784 #  endif
    1785 # endif
    1786 # ifdef __i486__
    1787         "-D__i486__",
    1788 # endif
    1789 # ifdef __i586__
    1790         "-D__i586__",
    1791 # endif
    1792 # ifdef __i686__
    1793         "-D__i686__",
    1794 # endif
    1795 # ifdef __k6__
    1796         "-D__k6__",
    1797 # endif
    1798 # ifdef __ia64__
    1799         "-D__ia64__",
    1800 # endif
    1801 # ifdef __AMD64__
    1802         "-D__AMD64__",
    1803 # endif
    1804 # ifdef __x86_64__
    1805         "-D__AMD64__",
    1806 # endif
    1807 # ifdef __s390__
    1808         "-D__s390__",
    1809 # endif
    1810 # ifdef __alpha__
    1811         "-D__alpha__",
    1812 # endif
    1813 # ifdef __arm__
    1814         "-D__arm__",
    1815 # endif
    1816 # ifdef __s390x__
    1817        "-D__s390x__",
    1818 # endif
    1819 # ifdef __sparc__
    1820         "-D__sparc__",
    1821 # endif
    1822 # ifdef __m68k__
    1823         "-D__m68k__",
    1824 # endif
    1825 # ifdef __sh__
    1826         "-D__sh__",
    1827 # endif
    1828 # ifdef __sh3__
    1829         "-D__sh3__",
    1830 # endif
    1831 # ifdef __SH3__
    1832         "-D__SH3__",
    1833 # endif
    1834 # ifdef __SH4__
    1835         "-D__SH4__",
    1836 # endif
    1837 # ifdef __SH4NOFPU__
    1838         "-D__SH4_NOFPU__",
    1839 # endif
    1840 # ifdef __GNUC__
    1841         "-traditional",
    1842 # endif
    1843 #endif
    1844 #ifdef M4330
    1845         "-DM4330",      /* Tektronix */
    1846 #endif
    1847 #ifdef M4310
    1848         "-DM4310",      /* Tektronix */
    1849 #endif
    1850 #if defined(macII) || defined(_AUX_SOURCE)
    1851         "-DmacII",      /* Apple A/UX */
    1852 #endif
    1853 #if defined(USL) || defined(__USLC__)
    1854         "-DUSL",        /* USL */
    1855 #endif
    1856 #ifdef sony
    1857         "-Dsony",       /* Sony */
    1858 #if !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV) && NEWSOS < 42
    1859         "-Dbsd43",
    1860 #endif
    1861 #endif
    1862 #ifdef _IBMR2
    1863         "-D_IBMR2",     /* IBM RS-6000 (we ensured that aix is defined above */
    1864 #ifndef aix
    1865 #define aix             /* allow BOOTSTRAPCFLAGS="-D_IBMR2" */
    1866 #endif
    1867 #endif /* _IBMR2 */
    1868 #ifdef aix
    1869         "-Daix",        /* AIX instead of AOS */
    1870 #ifndef ibm
    1871 #define ibm             /* allow BOOTSTRAPCFLAGS="-Daix" */
    1872 #endif
    1873 #endif /* aix */
    1874 #ifdef ibm
    1875         "-Dibm",        /* IBM PS/2 and RT under both AOS and AIX */
    1876 #endif
    1877 #ifdef luna
    1878         "-Dluna",       /* OMRON luna 68K and 88K */
    1879 #ifdef luna1
    1880         "-Dluna1",
    1881 #endif
    1882 #ifdef luna88k          /* need not on UniOS-Mach Vers. 1.13 */
    1883         "-traditional", /* for some older version            */
    1884 #endif                  /* instead of "-DXCOMM=\\#"          */
    1885 #ifdef uniosb
    1886         "-Duniosb",
    1887 #endif
    1888 #ifdef uniosu
    1889         "-Duniosu",
    1890 #endif
    1891 #endif /* luna */
    1892 #ifdef _CRAY            /* Cray */
    1893         "-Ucray",
    1894 #endif
    1895 #ifdef Mips
    1896         "-DMips",       /* Define and use Mips for Mips Co. OS/mach. */
    1897 # if defined(SYSTYPE_BSD) || defined(BSD) || defined(BSD43)
    1898         "-DBSD43",      /* Mips RISCOS supports two environments */
    1899 # else
    1900         "-DSYSV",       /* System V environment is the default */
    1901 # endif
    1902 #endif /* Mips */
    1903 #ifdef MOTOROLA
    1904         "-DMOTOROLA",    /* Motorola Delta Systems */
    1905 # ifdef SYSV
    1906         "-DSYSV",
    1907 # endif
    1908 # ifdef SVR4
    1909         "-DSVR4",
    1910 # endif
    1911 #endif /* MOTOROLA */
    1912 #if defined(M_UNIX) || defined(sco)
    1913         "-Dsco",
    1914         "-DSYSV",
    1915 #endif
    1916 #ifdef i386
    1917         "-Di386",
    1918 # ifdef SVR4
    1919         "-DSVR4",
    1920 # endif
    1921 # ifdef SYSV
    1922         "-DSYSV",
    1923 #  ifdef ISC
    1924         "-DISC",
    1925 #   ifdef ISC40
    1926         "-DISC40",       /* ISC 4.0 */
    1927 #   else
    1928 #    ifdef ISC202
    1929         "-DISC202",      /* ISC 2.0.2 */
    1930 #    else
    1931 #     ifdef ISC30
    1932         "-DISC30",       /* ISC 3.0 */
    1933 #     else
    1934         "-DISC22",       /* ISC 2.2.1 */
    1935 #     endif
    1936 #    endif
    1937 #   endif
    1938 #  endif
    1939 #  ifdef SCO
    1940         "-DSCO",
    1941 #   ifdef _SCO_DS
    1942     "-DSCO325",
    1943 #   endif
    1944 #  endif
    1945 # endif
    1946 # ifdef ESIX
    1947         "-DESIX",
    1948 # endif
    1949 # ifdef ATT
    1950         "-DATT",
    1951 # endif
    1952 # ifdef DELL
    1953         "-DDELL",
    1954 # endif
    1955 #endif
    1956 #ifdef SYSV386           /* System V/386 folks, obsolete */
    1957         "-Di386",
    1958 # ifdef SVR4
    1959         "-DSVR4",
    1960 # endif
    1961 # ifdef ISC
    1962         "-DISC",
    1963 #  ifdef ISC40
    1964         "-DISC40",       /* ISC 4.0 */
    1965 #  else
    1966 #   ifdef ISC202
    1967         "-DISC202",      /* ISC 2.0.2 */
    1968 #   else
    1969 #    ifdef ISC30
    1970         "-DISC30",       /* ISC 3.0 */
    1971 #    else
    1972         "-DISC22",       /* ISC 2.2.1 */
    1973 #    endif
    1974 #   endif
    1975 #  endif
    1976 # endif
    1977 # ifdef SCO
    1978         "-DSCO",
    1979 #  ifdef _SCO_DS
    1980         "-DSCO325",
    1981 #  endif
    1982 # endif
    1983 # ifdef ESIX
    1984         "-DESIX",
    1985 # endif
    1986 # ifdef ATT
    1987         "-DATT",
    1988 # endif
    1989 # ifdef DELL
    1990         "-DDELL",
    1991 # endif
    1992 #endif
    1993 #ifdef __osf__
    1994         "-D__osf__",
    1995 # ifdef __mips__
    1996         "-D__mips__",
    1997 # endif
    1998 # ifdef __alpha
    1999         "-D__alpha",
    2000 # endif
    2001 # ifdef __amiga__
    2002         "-D__amiga__",
    2003 # endif
    2004 # ifdef __alpha__
    2005         "-D__alpha__",
    2006 # endif
    2007 # ifdef __i386__
    2008         "-D__i386__",
    2009 # endif
    2010 # ifdef __GNUC__
    2011         "-traditional",
    2012 # endif
    2013 #endif
    2014 #ifdef Oki
    2015         "-DOki",
    2016 #endif
    2017 #ifdef sun
    2018 #if defined(SVR4) || defined(__svr4__) || defined(__SVR4) || defined(__sol__)
    2019         "-DSVR4",
    2020 #endif
    2021 #endif
    2022 #ifdef WIN32
    2023         "-DWIN32",
    2024         "-nologo",
    2025 #if _MSC_VER < 1000
    2026         "-batch",
    2027 #endif
    2028         "-D__STDC__",
    2029 #endif
    2030 #ifdef NCR
    2031         "-DNCR",        /* NCR */
    2032 #endif
    2033 #ifdef linux
    2034         "-Dlinux",
    2035 #endif
    2036 #if defined(__CYGWIN__)
    2037         "-traditional",
    2038 #endif
    2039 #if defined(Lynx) || defined(__Lynx__)
    2040         "-traditional",
    2041 #if 0
    2042         "-DLYNX",               /* do we really need this?? */
    2043 #endif
    2044         "-DLynx",
    2045 # ifdef ppc
    2046         "-Dppc",
    2047 # endif
    2048 # if defined(m68k)  || defined(M68k) || defined(m68040)
    2049         "-Dm68k",
    2050         "-DM68k",
    2051 # endif
    2052 # ifdef uSPARC1
    2053         "-Dsparc",
    2054 # endif
    2055 #endif
    2056 #ifdef __uxp__
    2057         "-D__uxp__",
    2058 #endif
    2059 #ifdef __sxg__
    2060         "-D__sxg__",
    2061 #endif
    2062 #ifdef nec_ews_svr2
    2063         "-Dnec_ews_svr2",
    2064 #endif
    2065 #ifdef AMOEBA
    2066         "-DAMOEBA",
    2067 # ifdef CROSS_COMPILE
    2068         "-DCROSS_COMPILE",
    2069 #  ifdef CROSS_i80386
    2070         "-Di80386",
    2071 #  endif
    2072 #  ifdef CROSS_sparc
    2073         "-Dsparc",
    2074 #  endif
    2075 #  ifdef CROSS_mc68000
    2076         "-Dmc68000",
    2077 #  endif
    2078 # else
    2079 #  ifdef i80386
    2080         "-Di80386",
    2081 #  endif
    2082 #  ifdef sparc
    2083         "-Dsparc",
    2084 #  endif
    2085 #  ifdef mc68000
    2086         "-Dmc68000",
    2087 #  endif
    2088 # endif
    2089 #endif
    2090 #if defined(__sgi) && defined(__ANSI_CPP__)
    2091         "-cckr",
    2092 #endif
    2093 #ifdef __minix_vmd
    2094         "-Dminix",
    2095 #endif
    2096 
    2097 #if defined(__UNIXOS2__)
    2098         "-traditional",
    2099         "-Demxos2",
    2100 #endif
    2101 #ifdef MetroLink
    2102         "-DMetroLink",
    2103 # ifdef SVR4
    2104         "-DSVR4",
    2105 # endif
    2106 # ifdef __powerpc__
    2107         "-D__powerpc__",
    2108 # endif
    2109 # ifdef PowerMAX_OS
    2110         "-DPowerMAX_OS",
    2111 # endif
    2112 #endif
    2113 #if defined (__QNX__) && !defined(__QNXNTO__)
    2114         "-traditional",
    2115         "-D__QNX__",
    2116 #endif
    2117 
    2118 #if defined(__QNXNTO__)
    2119         "-traditional",
    2120         "-D__QNXNTO__",
    2121 #if defined(i386)
    2122         "-Di386",
    2123 #endif
    2124 #if defined(__i386__)
    2125         "-D__i386__",
    2126 #endif
    2127 #if defined(PPC)
    2128         "-DPPC",
    2129 #endif
    2130 #if defined(MIPS)
    2131         "-DMIPS",
    2132 #endif
    2133 #endif
    2134 
    2135 #if defined(__APPLE__)
    2136         "-D__APPLE__",
    2137         "-D__DARWIN__",
    2138 # ifdef __ppc__
    2139         "-D__ppc__",
    2140 # endif
    2141 # ifdef __i386__
    2142         "-D__i386__",
    2143 # endif
    2144 #endif
    2145 };
    2146 #endif /* CROSSCOMPILE */
    2147 
    2148 
    2149 /*
    2150  * Step 6: DEFAULT_OS_MAJOR_REV, DEFAULT_OS_MINOR_REV, DEFAULT_OS_TEENY_REV,
    2151  *      and DEFAULT_OS_NAME.
    2152  *      If your system provides a way to generate the default major,
    2153  *      minor, teeny, or system names at runtime add commands below.
    2154  *      The syntax of the _REV strings is 'f fmt' where 'f' is an argument
    2155  *      you would give to uname, and "fmt" is a scanf() format string.
    2156  *      Supported uname arguments are "snrvm", and if you specify multiple
    2157  *      arguments they will be separated by spaces.  No more than 5 arguments
    2158  *      may be given.  Unlike uname() order of arguments matters.
    2159  *
    2160  *      DEFAULT_OS_MAJOR_REV_FROB, DEFAULT_OS_MINOR_REV_FROB,
    2161  *      DEFAULT_OS_TEENY_REV_FROB, and DEFAULT_OS_NAME_FROB can be used to
    2162  *      modify the results of the use of the various strings.
    2163  */
    2164 #if !defined CROSSCOMPILE || defined CROSSCOMPILE_CPP
    2165 # if defined(aix)
    2166 /* uname -v returns "x" (e.g. "4"), and uname -r returns "y" (e.g. "1") */
    2167 #  define DEFAULT_OS_MAJOR_REV  "v %[0-9]"
    2168 #  define DEFAULT_OS_MINOR_REV  "r %[0-9]"
    2169 /* No information available to generate default OSTeenyVersion value. */
    2170 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2171 # elif defined(sun) || defined(sgi) || defined(ultrix) || defined(__uxp__) || defined(sony)
    2172 /* uname -r returns "x.y[.z]", e.g. "5.4" or "4.1.3" */
    2173 #  define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
    2174 #  define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
    2175 #  define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]"
    2176 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2177 # elif defined(hpux)
    2178 /* uname -r returns "W.x.yz", e.g. "B.10.01" */
    2179 #  define DEFAULT_OS_MAJOR_REV  "r %*[^.].%[0-9]"
    2180 #  define DEFAULT_OS_MINOR_REV  "r %*[^.].%*d.%1s"
    2181 #  define DEFAULT_OS_TEENY_REV  "r %*[^.].%*d.%*c%[0-9]"
    2182 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2183 # elif defined(USL) || defined(__USLC__)
    2184 /* uname -v returns "x.yz" or "x.y.z", e.g. "2.02" or "2.1.2". */
    2185 #  define DEFAULT_OS_MAJOR_REV  "v %[0-9]"
    2186 #  define DEFAULT_OS_MINOR_REV  "v %*d.%1s"
    2187 #  define DEFAULT_OS_TEENY_REV  "v %*d.%*c%[.0-9]"
    2188 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2189 # elif defined(__APPLE__)
    2190 /* uname -v returns "x.yz" or "x.y.z", e.g. "2.02" or "2.1.2". */
    2191 #  define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
    2192 #  define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
    2193 #  define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]" /* this will just get 0 */
    2194 #  define DEFAULT_OS_NAME       "s %[^\n]"
    2195 # elif defined(__osf__)
    2196 /* uname -r returns "Wx.y", e.g. "V3.2" or "T4.0" */
    2197 #  define DEFAULT_OS_MAJOR_REV  "r %*[^0-9]%[0-9]"
    2198 #  define DEFAULT_OS_MINOR_REV  "r %*[^.].%[0-9]"
    2199 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2200 # elif defined(__uxp__)
    2201 /* NOTE: "x.y[.z]" above handles UXP/DF.  This is a sample alternative. */
    2202 /* uname -v returns "VxLy Yzzzzz ....", e.g. "V20L10 Y95021 Increment 5 ..." */
    2203 #  define DEFAULT_OS_MAJOR_REV  "v V%[0-9]"
    2204 #  define DEFAULT_OS_MINOR_REV  "v V%*dL%[0-9]"
    2205 #  define DEFAULT_OS_NAME       "srvm %[^\n]"
    2206 # elif defined(linux) || defined(__bsdi__)
    2207 #  define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
    2208 #  define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
    2209 #  define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]"
    2210 #  define DEFAULT_OS_NAME       "srm %[^\n]"
    2211 #  if defined(linux) && defined  (CROSSCOMPILE_CPP)
    2212 #   define CROSS_UTS_SYSNAME "Linux"
    2213 #   include <linux/version.h>
    2214 #   define CROSS_UTS_RELEASE UTS_RELEASE
    2215 # endif
    2216 # elif defined(__CYGWIN__)
    2217 #  define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
    2218 #  define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
    2219 #  define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]"
    2220 #  define DEFAULT_OS_NAME       "srm %[^\n]"
    2221 #  if defined(__CYGWIN__) && defined  (CROSSCOMPILE_CPP)
    2222 #   define CROSS_UTS_SYSNAME "Cygwin"
    2223 #   include <cygwin/version.h>
    2224 #   define CROSS_UTS_RELEASE "1.3.12"
    2225 #  endif
    2226 # elif defined(__GNU__)
    2227 #  define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
    2228 #  define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
    2229 #  define DEFAULT_OS_NAME       "srm %[^\n]"
    2230 # elif defined(ISC)
    2231 /* ISC all Versions ? */
    2232 /* uname -r returns "x.y", e.g. "3.2" ,uname -v returns "x" e.g. "2" */
    2233 #  define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
    2234 #  define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
    2235 #  define DEFAULT_OS_TEENY_REV   "v %[0-9]"
    2236 /* # define DEFAULT_OS_NAME        "srm %[^\n]" */ /* Not useful on ISC */
    2237 # elif defined(__FreeBSD__) || defined(__OpenBSD__)
    2238 /* BSD/OS too? */
    2239 /* uname -r returns "x.y[.z]-mumble", e.g. "2.1.5-RELEASE" or "2.2-0801SNAP" */
    2240 #  define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
    2241 #  define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
    2242 #  define DEFAULT_OS_TEENY_REV   "r %*d.%*d.%[0-9]"
    2243 #  define DEFAULT_OS_NAME        "srm %[^\n]"
    2244 #  if defined(__FreeBSD__)
    2245 /* Use an alternate way to find the teeny version for -STABLE, -SNAP versions */
    2246 #   ifndef CROSSCOMPILE_CPP
    2247 #    define DEFAULT_OS_TEENY_REV_FROB(buf, size)                        \
    2248       do {                                                              \
    2249         if (*buf == 0) {                                                \
    2250                 int __mib[2];                                           \
    2251                 size_t __len;                                           \
    2252                 int __osrel;                                            \
    2253                                                                         \
    2254                 __mib[0] = CTL_KERN;                                    \
    2255                 __mib[1] = KERN_OSRELDATE;                              \
    2256                 __len = sizeof(__osrel);                                \
    2257                 sysctl(__mib, 2, &__osrel, &__len, NULL, 0);            \
    2258                 if (__osrel < 210000) {                                 \
    2259                         if (__osrel < 199607)                           \
    2260                                 buf[0] = '0';                           \
    2261                         else if (__osrel < 199612)                      \
    2262                                 buf[0] = '5';                           \
    2263                         else if (__osrel == 199612)                     \
    2264                                 buf[0] = '6';                           \
    2265                         else                                            \
    2266                                 buf[0] = '8'; /* guess */               \
    2267                 } else {                                                \
    2268                         buf[0] = ((__osrel / 1000) % 10) + '0';         \
    2269                 }                                                       \
    2270                 buf[1] = 0;                                             \
    2271         }                                                               \
    2272      } while (0)
    2273 #   endif
    2274 #  else
    2275    /* OpenBSD - Add DEFAULT_MACHINE_ARCHITECTURE */
    2276 #   define DEFAULT_MACHINE_ARCHITECTURE "m %[^\n]"
    2277 #  endif
    2278 # elif defined(__NetBSD__)
    2279 /*
    2280  * uname -r returns "x.y([ABCD...]|_mumble)", e.g.:
    2281  *      1.2     1.2_BETA        1.2A    1.2B
    2282  *
    2283  * That means that we have to do something special to turn the
    2284  * TEENY revision into a form that we can use (i.e., a string of
    2285  * decimal digits).
    2286  *
    2287  * We also frob the name DEFAULT_OS_NAME so that it looks like the
    2288  * 'standard' NetBSD name for the version, e.g. "NetBSD/i386 1.2B" for
    2289  * NetBSD 1.2B on an i386.
    2290  */
    2291 #  define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
    2292 #  define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
    2293 #  define DEFAULT_OS_TEENY_REV   "r %*d.%*d%[A-Z]"
    2294 #  define DEFAULT_OS_TEENY_REV_FROB(buf, size)                          \
    2295     do {                                                                \
    2296         int     teeny = 0;                                              \
    2297         char    *ptr = (buf);                                           \
    2298                                                                         \
    2299         while (*ptr >= 'A' && *ptr <= 'Z') /* sanity check */           \
    2300             teeny = teeny * 26 + (int)(*ptr++ - 'A');                   \
    2301                                                                         \
    2302         snprintf((buf), (size), "%d", teeny + 1);                       \
    2303     } while (0)
    2304 #  define DEFAULT_OS_NAME        "smr %[^\n]"
    2305 #  define DEFAULT_OS_NAME_FROB(buf, size)                               \
    2306     do {                                                                \
    2307         char *__sp;                                                     \
    2308         if ((__sp = strchr((buf), ' ')) != NULL)                        \
    2309                 *__sp = '/';                                            \
    2310     } while (0)
    2311 # elif defined(__Lynx__) || defined(Lynx)
    2312 /* Lynx 2.4.0 /bin/cc doesn't like #elif */
    2313 #  define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
    2314 #  define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
    2315 #  define DEFAULT_OS_TEENY_REV   "r %*d.%*d.%[0-9]"
    2316 #  define DEFAULT_OS_NAME        "srm %[^\n]"
    2317 # elif defined(_SEQUENT_)
    2318 /* uname -v returns 'Vx.y.z', e.g. 'V4.4.2' */
    2319 #  define DEFAULT_OS_MAJOR_REV  "v V%[0-9]"
    2320 #  define DEFAULT_OS_MINOR_REV  "v V%*d.%[0-9]"
    2321 #  define DEFAULT_OS_TEENY_REV  "v V%*d.%*d.%[0-9]"
    2322 #  define DEFAULT_OS_NAME       "s %[^\n]"
    2323 # endif
    2324 #endif /* !defined CROSSCOMPILE || defined CROSSCOMPILE_CPP */
    2325 
    2326 # if defined (CROSSCOMPILE_CPP)
    2327 #  ifndef CROSS_UTS_SYSNAME
    2328 char *cross_uts_sysname = "";
    2329 #  else
    2330 char *cross_uts_sysname = CROSS_UTS_SYSNAME;
    2331 #  endif
    2332 #  ifndef CROSS_UTS_RELEASE
    2333 char* cross_uts_release = "";
    2334 #  else
    2335 char* cross_uts_release = CROSS_UTS_RELEASE;
    2336 #  endif
    2337 #  ifndef CROSS_UTS_MACHINE
    2338 char *cross_uts_machine = "";
    2339 #  else
    2340 char *cross_uts_machine = CROSS_UTS_MACHINE;
    2341 #  endif
    2342 #  ifndef CROSS_UTS_VERSION
    2343 char * cross_uts_version = "";
    2344 #  else
    2345 char * cross_uts_version = CROSS_UTS_VERSION;
    2346 #  endif
    2347 #  ifdef DEFAULT_OS_NAME
    2348 char *defaultOsName = DEFAULT_OS_NAME;
    2349 #  else
    2350 char *defaultOsName = NULL;
    2351 # endif
    2352 #  ifdef DEFAULT_OS_MAJOR_REV
    2353 char *defaultOsMajorRev = DEFAULT_OS_MAJOR_REV;
    2354 #  else
    2355 char *defaultOsMajorRev = NULL;
    2356 # endif
    2357 #  ifdef DEFAULT_OS_MINOR_REV
    2358 char *defaultOsMinorRev = DEFAULT_OS_MINOR_REV;
    2359 #  else
    2360 char *defaultOsMinorRev = NULL;
    2361 #  endif
    2362 #  ifdef DEFAULT_OS_TEENY_REV
    2363 char *defaultOsTeenyRev = DEFAULT_OS_TEENY_REV;
    2364 #  else
    2365 char *defaultOsTeenyRev = NULL;
    2366 #  endif
    2367 #  ifdef DEFAULT_MACHINE_ARCHITECTURE
    2368 char *defaultMachineArchitecture = DEFAULT_MACHINE_ARCHITECTURE;
    2369 #  else
    2370 char *defaultMachineArchitecture = NULL;
    2371 #  endif
    2372 # ifdef DEFAULT_OS_NAME_FROB
    2373 void defaultOsNameFrob(char *buf, int size)
    2374 {DEFAULT_OS_NAME_FROB(buf,size)}
    2375 # else
    2376 void (*defaultOsNameFrob)(char *buf, int size) = NULL;
    2377 # endif
    2378 # ifdef DEFAULT_OS_MAJOR_REV_FROB
    2379 void defaultOsMajorRevFrob(char *buf, int size)
    2380 {DEFAULT_OS_MAJOR_REV_FROB(buf,size)}
    2381 # else
    2382 void (*defaultOsMajorRevFrob)(char *buf, int size) = NULL;
    2383 # endif
    2384 # ifdef DEFAULT_OS_MINOR_REV_FROB
    2385 void defaultOsMinorRevFrob(char *buf, int size)
    2386 {DEFAULT_OS_MINOR_REV_FROB(buf,size)}
    2387 # else
    2388 void (*defaultOsMinorRevFrob)(char *buf, int size) = NULL;
    2389 # endif
    2390 # ifdef DEFAULT_OS_TEENY_REV_FROB
    2391 void defaultOsTeenyRevFrob(char *buf, int size)
    2392 {DEFAULT_OS_TEENY_REV_FROB(buf,size)}
    2393 # else
    2394 void (*defaultOsTeenyRevFrob)(char *buf, int size) = NULL;
    2395 # endif
    2396 # endif /* CROSSCOMPILE_CPP */
    2397 
    2398 #else /* else MAKEDEPEND */
    2399 #if !defined (CROSSCOMPILE) || defined (CROSSCOMPILE_CPP)
    2400 /*
    2401  * Step 7:  predefs
    2402  *     If your compiler and/or preprocessor define any specific symbols, add
    2403  *     them to the the following table.  The definition of struct symtab is
    2404  *     in util/makedepend/def.h.
    2405  */
    2406 #undef DEF_EVALUATE
    2407 #undef DEF_STRINGIFY
    2408 #define DEF_EVALUATE(__x) #__x
    2409 #define DEF_STRINGIFY(_x) DEF_EVALUATE(_x)
    2410 struct symtab   predefs[] = {
    2411 #ifdef apollo
    2412         {"apollo", "1"},
    2413 #endif
    2414 #if defined(clipper) || defined(__clipper__)
    2415         {"clipper", "1"},
    2416         {"__clipper__", "1"},
    2417         {"clix", "1"},
    2418         {"__clix__", "1"},
    2419 #endif
    2420 #ifdef ibm032
    2421         {"ibm032", "1"},
    2422 #endif
    2423 #ifdef ibm
    2424         {"ibm", "1"},
    2425 #endif
    2426 #ifdef aix
    2427         {"aix", "1"},
    2428 #endif
    2429 #ifdef sun
    2430         {"sun", "1"},
    2431 #endif
    2432 #ifdef sun2
    2433         {"sun2", "1"},
    2434 #endif
    2435 #ifdef sun3
    2436         {"sun3", "1"},
    2437 #endif
    2438 #ifdef sun4
    2439         {"sun4", "1"},
    2440 #endif
    2441 #ifdef sparc
    2442         {"sparc", "1"},
    2443 #endif
    2444 #ifdef __sparc
    2445         {"__sparc", "1"},
    2446 #endif
    2447 #ifdef __sparcv9
    2448         {"__sparcv9", "1"},
    2449 #endif
    2450 #ifdef __sparc__
    2451         {"__sparc__", "1"},
    2452 #endif
    2453 #ifdef __sparcv9__
    2454         {"__sparcv9__", "1"},
    2455 #endif
    2456 #ifdef hpux
    2457         {"hpux", "1"},
    2458 #endif
    2459 #ifdef __hpux
    2460         {"__hpux", "1"},
    2461 #endif
    2462 #ifdef __hp9000s800
    2463         {"__hp9000s800", "1"},
    2464 #endif
    2465 #ifdef __hp9000s700
    2466         {"__hp9000s700", "1"},
    2467 #endif
    2468 #ifdef vax
    2469         {"vax", "1"},
    2470 #endif
    2471 #ifdef VMS
    2472         {"VMS", "1"},
    2473 #endif
    2474 #ifdef cray
    2475         {"cray", "1"},
    2476 #endif
    2477 #ifdef CRAY
    2478         {"CRAY", "1"},
    2479 #endif
    2480 #ifdef _CRAY
    2481         {"_CRAY", "1"},
    2482 #endif
    2483 #ifdef att
    2484         {"att", "1"},
    2485 #endif
    2486 #ifdef mips
    2487         {"mips", "1"},
    2488 #endif
    2489 #ifdef __mips__
    2490         {"__mips__", "1"},
    2491 #endif
    2492 #ifdef ultrix
    2493         {"ultrix", "1"},
    2494 #endif
    2495 #ifdef stellar
    2496         {"stellar", "1"},
    2497 #endif
    2498 #ifdef mc68000
    2499         {"mc68000", "1"},
    2500 #endif
    2501 #ifdef mc68020
    2502         {"mc68020", "1"},
    2503 #endif
    2504 #ifdef __GNUC__
    2505         {"__GNUC__", DEF_STRINGIFY(__GNUC__)},
    2506 #endif
    2507 #ifdef __STRICT_ANSI__
    2508         {"__STRICT_ANSI__", "1"},
    2509 #endif
    2510 #ifdef __STDC__
    2511         {"__STDC__", DEF_STRINGIFY(__STDC__)},
    2512 #endif
    2513 #ifdef __HIGHC__
    2514         {"__HIGHC__", "1"},
    2515 #endif
    2516 #ifdef CMU
    2517         {"CMU", "1"},
    2518 #endif
    2519 #ifdef luna
    2520         {"luna", "1"},
    2521 #ifdef luna1
    2522         {"luna1", "1"},
    2523 #endif
    2524 #ifdef luna2
    2525         {"luna2", "1"},
    2526 #endif
    2527 #ifdef luna88k
    2528         {"luna88k", "1"},
    2529 #endif
    2530 #ifdef uniosb
    2531         {"uniosb", "1"},
    2532 #endif
    2533 #ifdef uniosu
    2534         {"uniosu", "1"},
    2535 #endif
    2536 #endif
    2537 #ifdef ieeep754
    2538         {"ieeep754", "1"},
    2539 #endif
    2540 #ifdef is68k
    2541         {"is68k", "1"},
    2542 #endif
    2543 #ifdef m68k
    2544         {"m68k", "1"},
    2545 #endif
    2546 #ifdef M68k
    2547         {"M68k", "1"},
    2548 #endif
    2549 #ifdef __m68k__
    2550         {"__m68k__", "1"},
    2551 #endif
    2552 #ifdef m88k
    2553         {"m88k", "1"},
    2554 #endif
    2555 #ifdef __m88k__
    2556         {"__m88k__", "1"},
    2557 #endif
    2558 #ifdef bsd43
    2559         {"bsd43", "1"},
    2560 #endif
    2561 #ifdef hcx
    2562         {"hcx", "1"},
    2563 #endif
    2564 #ifdef sony
    2565         {"sony", "1"},
    2566 #ifdef SYSTYPE_SYSV
    2567         {"SYSTYPE_SYSV", "1"},
    2568 #endif
    2569 #ifdef _SYSTYPE_SYSV
    2570         {"_SYSTYPE_SYSV", "1"},
    2571 #endif
    2572 #endif
    2573 #ifdef __OSF__
    2574         {"__OSF__", "1"},
    2575 #endif
    2576 #ifdef __osf__
    2577         {"__osf__", "1"},
    2578 #endif
    2579 #ifdef __amiga__
    2580         {"__amiga__", "1"},
    2581 #endif
    2582 #ifdef __alpha
    2583         {"__alpha", "1"},
    2584 #endif
    2585 #ifdef __alpha__
    2586         {"__alpha__", "1"},
    2587 #endif
    2588 #ifdef __DECC
    2589         {"__DECC",  "1"},
    2590 #endif
    2591 #ifdef __decc
    2592         {"__decc",  "1"},
    2593 #endif
    2594 #ifdef __unix__
    2595         {"__unix__", "1"},
    2596 #endif
    2597 #ifdef __uxp__
    2598         {"__uxp__", "1"},
    2599 #endif
    2600 #ifdef __sxg__
    2601         {"__sxg__", "1"},
    2602 #endif
    2603 #ifdef _SEQUENT_
    2604         {"_SEQUENT_", "1"},
    2605         {"__STDC__", "1"},
    2606 #endif
    2607 #ifdef __bsdi__
    2608         {"__bsdi__", "1"},
    2609 #endif
    2610 #ifdef nec_ews_svr2
    2611         {"nec_ews_svr2", "1"},
    2612 #endif
    2613 #ifdef nec_ews_svr4
    2614         {"nec_ews_svr4", "1"},
    2615 #endif
    2616 #ifdef _nec_ews_svr4
    2617         {"_nec_ews_svr4", "1"},
    2618 #endif
    2619 #ifdef _nec_up
    2620         {"_nec_up", "1"},
    2621 #endif
    2622 #ifdef SX
    2623         {"SX", "1"},
    2624 #endif
    2625 #ifdef nec
    2626         {"nec", "1"},
    2627 #endif
    2628 #ifdef _nec_ft
    2629         {"_nec_ft", "1"},
    2630 #endif
    2631 #ifdef PC_UX
    2632         {"PC_UX", "1"},
    2633 #endif
    2634 #ifdef sgi
    2635         {"sgi", "1"},
    2636 #endif
    2637 #ifdef __sgi
    2638         {"__sgi", "1"},
    2639 #endif
    2640 #ifdef _MIPS_FPSET
    2641         {"_MIPS_FPSET", DEF_STRINGIFY(_MIPS_FPSET)},
    2642 #endif
    2643 #ifdef _MIPS_ISA
    2644         {"_MIPS_ISA", DEF_STRINGIFY(_MIPS_ISA)},
    2645 #endif
    2646 #ifdef _MIPS_SIM
    2647         {"_MIPS_SIM", DEF_STRINGIFY(_MIPS_SIM)},
    2648 #endif
    2649 #ifdef _MIPS_SZINT
    2650         {"_MIPS_SZINT", DEF_STRINGIFY(_MIPS_SZINT)},
    2651 #endif
    2652 #ifdef _MIPS_SZLONG
    2653         {"_MIPS_SZLONG", DEF_STRINGIFY(_MIPS_SZLONG)},
    2654 #endif
    2655 #ifdef _MIPS_SZPTR
    2656         {"_MIPS_SZPTR", DEF_STRINGIFY(_MIPS_SZPTR)},
    2657 #endif
    2658 #ifdef __FreeBSD__
    2659         {"__FreeBSD__", "1"},
    2660 #endif
    2661 #ifdef __OpenBSD__
    2662         {"__OpenBSD__", "1"},
    2663 #endif
    2664 #ifdef __NetBSD__
    2665         {"__NetBSD__", "1"},
    2666 #endif
    2667 #ifdef __GNU__
    2668         {"__GNU__", "1"},
    2669 #endif
    2670 #ifdef __ELF__
    2671         {"__ELF__", "1"},
    2672 #endif
    2673 #ifdef __UNIXOS2__
    2674         {"__UNIXOS2__", "1"},
    2675 #endif
    2676 #if defined(__QNX__)
    2677         {"__QNX__", "1"},
    2678 #endif
    2679 #ifdef __QNXNTO__
    2680         {"__QNXNTO__", "1"},
    2681 #endif
    2682 # ifdef __powerpc__
    2683         {"__powerpc__", "1"},
    2684 # endif
    2685 # ifdef PowerMAX_OS
    2686         {"PowerMAX_OS", "1"},
    2687 # endif
    2688 # ifdef ia64
    2689         {"ia64", "1"},
    2690 # endif
    2691 # ifdef __ia64__
    2692         {"__ia64__", "1"},
    2693 # endif
    2694 # if defined (AMD64) || defined (x86_64)
    2695         {"AMD64", "1"},
    2696         {"x86_64", "1"},
    2697 # endif
    2698 # if defined (__AMD64__) || defined (__x86_64__)
    2699         {"__AMD64__", "1"},
    2700         {"__x86_64__", "1"},
    2701 # endif
    2702 # ifdef __i386
    2703         {"__i386", "1"},
    2704 # endif
    2705 # ifdef __i386__
    2706         {"__i386__", "1"},
    2707 # endif
    2708 # ifdef __i486__
    2709         {"__i486__", "1"},
    2710 # endif
    2711 # ifdef __i586__
    2712         {"__i586__", "1"},
    2713 # endif
    2714 # ifdef __i686__
    2715         {"__i686__", "1"},
    2716 # endif
    2717 # ifdef __k6__
    2718         {"__k6__", "1"},
    2719 # endif
    2720 # ifdef i386
    2721         {"i386", "1"},
    2722 # endif
    2723 # ifdef i486
    2724         {"i486", "1"},
    2725 # endif
    2726 # ifdef i586
    2727         {"i586", "1"},
    2728 # endif
    2729 # ifdef i686
    2730         { "i686", "1"},
    2731 # endif
    2732 # ifdef k6
    2733         {"k6", "1"},
    2734 # endif
    2735 # ifdef sparc
    2736         {"sparc", "1"},
    2737 # endif
    2738 # ifdef __sparc__
    2739         {"__sparc__", "1"},
    2740 # endif
    2741 # ifdef __s390__
    2742         {"__s390__", "1"},
    2743 # endif
    2744 # ifdef __sh__
    2745         {"__sh__", "1"},
    2746 # endif
    2747 # ifdef __sh3_
    2748         {"__sh3__", "1"},
    2749 # endif
    2750 # ifdef __SH3__
    2751         {"__SH3__", "1"},
    2752 # endif
    2753 # ifdef __SH4__
    2754         {"__SH4__", "1"},
    2755 # endif
    2756 # ifdef __SH4NOFPU__
    2757         {"__SH4NOFPU__", "1"},
    2758 # endif
    2759 #if defined(__ppc__)
    2760         {"__ppc__", "1"},
    2761 #endif
    2762 #if defined(__BIG_ENDIAN__)
    2763       {"__BIG_ENDIAN__", "1"},
    2764 #endif
    2765 #if defined(__LITTLE_ENDIAN__)
    2766       {"__LITTLE_ENDIAN__", "1"},
    2767 #endif
    2768         /* add any additional symbols before this line */
    2769         {NULL, NULL}
    2770 };
    2771 #undef DEF_EVALUATE
    2772 #undef DEF_STRINGIFY
    2773 #endif /* CROSSCOMPILE */
    2774 #endif /* MAKEDEPEND */
    2775 
    2776 # ifndef MAKEDEPEND
    2777 #  if  defined (CROSSCOMPILE_CPP)
    2778 #   ifdef USE_CC_E
    2779 boolean crosscompile_use_cc_e = TRUE;
    2780 #    ifdef DEFAULT_CC
    2781 char* crosscompile_cpp = DEFAULT_CC;
    2782 #    else
    2783 char* crosscompile_cpp = "cc";
    2784 #    endif
    2785 #   else
    2786 boolean crosscompile_use_cc_e = FALSE;
    2787 #    ifdef DEFAULT_CPP
    2788 char* crosscompile_cpp = DEFAULT_CPP;
    2789 #    else
    2790 char* crosscompile_cpp = "cpp";
    2791 #    endif
    2792 #   endif
    2793 #   ifdef FIXUP_CPP_WHITESPACE
    2794 boolean fixup_whitespace = TRUE;
    2795 #   else
    2796 boolean fixup_whitespace = FALSE;
    2797 #   endif
    2798 #   ifdef REMOVE_CPP_LEADSPACE
    2799 boolean remove_cpp_leadspace = TRUE;
    2800 #   else
    2801 boolean remove_cpp_leadspace = FALSE;
    2802 #   endif
    2803 #   ifdef INLINE_SYNTAX
    2804 boolean inline_syntax = TRUE;
    2805 #   else
    2806 boolean inline_syntax = FALSE;
    2807 #   endif
    2808 #   ifdef MAGIC_MAKE_VARS
    2809 boolean magic_make_vars = TRUE;
    2810 #   else
    2811 boolean magic_make_vars = FALSE;
    2812 #   endif
    2813 
    2814 typedef enum {
    2815   unknown,
    2816   freeBSD,
    2817   netBSD,
    2818   LinuX,
    2819   emx,
    2820   win32
    2821 } System;
    2822 
    2823 #   ifdef linux
    2824 System sys = LinuX;
    2825 #   elif defined __FreeBSD__
    2826 System sys = freebsd;
    2827 #   elif defined __NetBSD__
    2828 System sys = netBSD;
    2829 #   elif defined __EMX__
    2830 System sys = emx;
    2831 #   elif defined WIN32
    2832 System sys = win32;
    2833 #   else
    2834 System sys = unknown;
    2835 #   endif
    2836 
    2837 #   if defined __GNUC__
    2838 int gnu_c = __GNUC__;
    2839 int gnu_c_minor = __GNUC_MINOR__;
    2840 #   else
    2841 int gnu_c = 0;
    2842 int gnu_c_minor = -1;
    2843 #   endif
    2844 #   if defined linux
    2845 #    include <features.h>
    2846 int glibc_major = __GLIBC__ + 4;
    2847 int glibc_minor = __GLIBC_MINOR__;
    2848 #   else
    2849 int glibc_major = 0;
    2850 int glibc_minor = -1;
    2851 #   endif
    2852 #  endif /* !CROSSCOMPILE || CROSSCOMPILE_CPP */
    2853 
    2854 # endif /* MAKEDEPEND */
    2855 
    2856 #endif /* CCIMAKE */
  • makedepend.dsp

     
    1 # Microsoft Developer Studio Project File - Name="makedepend" - Package Owner=<4>
    2 # Microsoft Developer Studio Generated Build File, Format Version 6.00
    3 # ** DO NOT EDIT **
    4 
    5 # TARGTYPE "Win32 (x86) Console Application" 0x0103
    6 
    7 CFG=makedepend - Win32 Debug
    8 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
    9 !MESSAGE use the Export Makefile command and run
    10 !MESSAGE
    11 !MESSAGE NMAKE /f "makedepend.mak".
    12 !MESSAGE
    13 !MESSAGE You can specify a configuration when running NMAKE
    14 !MESSAGE by defining the macro CFG on the command line. For example:
    15 !MESSAGE
    16 !MESSAGE NMAKE /f "makedepend.mak" CFG="makedepend - Win32 Debug"
    17 !MESSAGE
    18 !MESSAGE Possible choices for configuration are:
    19 !MESSAGE
    20 !MESSAGE "makedepend - Win32 Release" (based on "Win32 (x86) Console Application")
    21 !MESSAGE "makedepend - Win32 Debug" (based on "Win32 (x86) Console Application")
    22 !MESSAGE
    23 
    24 # Begin Project
    25 # PROP AllowPerConfigDependencies 0
    26 # PROP Scc_ProjName ""$/ALS2/tools/makedepend", XCGAAAAA"
    27 # PROP Scc_LocalPath "."
    28 CPP=cl.exe
    29 RSC=rc.exe
    30 
    31 !IF  "$(CFG)" == "makedepend - Win32 Release"
    32 
    33 # PROP BASE Use_MFC 0
    34 # PROP BASE Use_Debug_Libraries 0
    35 # PROP BASE Output_Dir "Release"
    36 # PROP BASE Intermediate_Dir "Release"
    37 # PROP BASE Target_Dir ""
    38 # PROP Use_MFC 0
    39 # PROP Use_Debug_Libraries 0
    40 # PROP Output_Dir "Release"
    41 # PROP Intermediate_Dir "Release"
    42 # PROP Target_Dir ""
    43 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
    44 # ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /c
    45 # ADD BASE RSC /l 0x409 /d "NDEBUG"
    46 # ADD RSC /l 0x409 /d "NDEBUG"
    47 BSC32=bscmake.exe
    48 # ADD BASE BSC32 /nologo
    49 # ADD BSC32 /nologo
    50 LINK32=link.exe
    51 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    52 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    53 
    54 !ELSEIF  "$(CFG)" == "makedepend - Win32 Debug"
    55 
    56 # PROP BASE Use_MFC 0
    57 # PROP BASE Use_Debug_Libraries 1
    58 # PROP BASE Output_Dir "makedepend___Win32_Debug"
    59 # PROP BASE Intermediate_Dir "makedepend___Win32_Debug"
    60 # PROP BASE Target_Dir ""
    61 # PROP Use_MFC 0
    62 # PROP Use_Debug_Libraries 1
    63 # PROP Output_Dir "makedepend___Win32_Debug"
    64 # PROP Intermediate_Dir "makedepend___Win32_Debug"
    65 # PROP Target_Dir ""
    66 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
    67 # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /GZ /c
    68 # ADD BASE RSC /l 0x409 /d "_DEBUG"
    69 # ADD RSC /l 0x409 /d "_DEBUG"
    70 BSC32=bscmake.exe
    71 # ADD BASE BSC32 /nologo
    72 # ADD BSC32 /nologo
    73 LINK32=link.exe
    74 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    75 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    76 
    77 !ENDIF
    78 
    79 # Begin Target
    80 
    81 # Name "makedepend - Win32 Release"
    82 # Name "makedepend - Win32 Debug"
    83 # Begin Group "Source Files"
    84 
    85 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
    86 # Begin Source File
    87 
    88 SOURCE=.\cppsetup.c
    89 # End Source File
    90 # Begin Source File
    91 
    92 SOURCE=.\ifparser.c
    93 # End Source File
    94 # Begin Source File
    95 
    96 SOURCE=.\include.c
    97 # End Source File
    98 # Begin Source File
    99 
    100 SOURCE=.\main.c
    101 # End Source File
    102 # Begin Source File
    103 
    104 SOURCE=.\parse.c
    105 # End Source File
    106 # Begin Source File
    107 
    108 SOURCE=.\pr.c
    109 # End Source File
    110 # End Group
    111 # Begin Group "Header Files"
    112 
    113 # PROP Default_Filter "h;hpp;hxx;hm;inl"
    114 # Begin Source File
    115 
    116 SOURCE=.\def.h
    117 # End Source File
    118 # Begin Source File
    119 
    120 SOURCE=.\ifparser.h
    121 # End Source File
    122 # Begin Source File
    123 
    124 SOURCE=.\imakemdep.h
    125 # End Source File
    126 # End Group
    127 # Begin Group "Resource Files"
    128 
    129 # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
    130 # End Group
    131 # End Target
    132 # End Project
    133 # Microsoft Developer Studio Project File - Name="makedepend" - Package Owner=<4>
    134 # Microsoft Developer Studio Generated Build File, Format Version 6.00
    135 # ** DO NOT EDIT **
    136 
    137 # TARGTYPE "Win32 (x86) Console Application" 0x0103
    138 
    139 CFG=makedepend - Win32 Debug
    140 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
    141 !MESSAGE use the Export Makefile command and run
    142 !MESSAGE
    143 !MESSAGE NMAKE /f "makedepend.mak".
    144 !MESSAGE
    145 !MESSAGE You can specify a configuration when running NMAKE
    146 !MESSAGE by defining the macro CFG on the command line. For example:
    147 !MESSAGE
    148 !MESSAGE NMAKE /f "makedepend.mak" CFG="makedepend - Win32 Debug"
    149 !MESSAGE
    150 !MESSAGE Possible choices for configuration are:
    151 !MESSAGE
    152 !MESSAGE "makedepend - Win32 Release" (based on "Win32 (x86) Console Application")
    153 !MESSAGE "makedepend - Win32 Debug" (based on "Win32 (x86) Console Application")
    154 !MESSAGE
    155 
    156 # Begin Project
    157 # PROP AllowPerConfigDependencies 0
    158 # PROP Scc_ProjName ""$/ALS2/tools/makedepend", XCGAAAAA"
    159 # PROP Scc_LocalPath "."
    160 CPP=cl.exe
    161 RSC=rc.exe
    162 
    163 !IF  "$(CFG)" == "makedepend - Win32 Release"
    164 
    165 # PROP BASE Use_MFC 0
    166 # PROP BASE Use_Debug_Libraries 0
    167 # PROP BASE Output_Dir "Release"
    168 # PROP BASE Intermediate_Dir "Release"
    169 # PROP BASE Target_Dir ""
    170 # PROP Use_MFC 0
    171 # PROP Use_Debug_Libraries 0
    172 # PROP Output_Dir "Release"
    173 # PROP Intermediate_Dir "Release"
    174 # PROP Target_Dir ""
    175 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
    176 # ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /c
    177 # ADD BASE RSC /l 0x409 /d "NDEBUG"
    178 # ADD RSC /l 0x409 /d "NDEBUG"
    179 BSC32=bscmake.exe
    180 # ADD BASE BSC32 /nologo
    181 # ADD BSC32 /nologo
    182 LINK32=link.exe
    183 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    184 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    185 
    186 !ELSEIF  "$(CFG)" == "makedepend - Win32 Debug"
    187 
    188 # PROP BASE Use_MFC 0
    189 # PROP BASE Use_Debug_Libraries 1
    190 # PROP BASE Output_Dir "makedepend___Win32_Debug"
    191 # PROP BASE Intermediate_Dir "makedepend___Win32_Debug"
    192 # PROP BASE Target_Dir ""
    193 # PROP Use_MFC 0
    194 # PROP Use_Debug_Libraries 1
    195 # PROP Output_Dir "makedepend___Win32_Debug"
    196 # PROP Intermediate_Dir "makedepend___Win32_Debug"
    197 # PROP Target_Dir ""
    198 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
    199 # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /GZ /c
    200 # ADD BASE RSC /l 0x409 /d "_DEBUG"
    201 # ADD RSC /l 0x409 /d "_DEBUG"
    202 BSC32=bscmake.exe
    203 # ADD BASE BSC32 /nologo
    204 # ADD BSC32 /nologo
    205 LINK32=link.exe
    206 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    207 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    208 
    209 !ENDIF
    210 
    211 # Begin Target
    212 
    213 # Name "makedepend - Win32 Release"
    214 # Name "makedepend - Win32 Debug"
    215 # Begin Group "Source Files"
    216 
    217 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
    218 # Begin Source File
    219 
    220 SOURCE=.\cppsetup.c
    221 # End Source File
    222 # Begin Source File
    223 
    224 SOURCE=.\ifparser.c
    225 # End Source File
    226 # Begin Source File
    227 
    228 SOURCE=.\include.c
    229 # End Source File
    230 # Begin Source File
    231 
    232 SOURCE=.\main.c
    233 # End Source File
    234 # Begin Source File
    235 
    236 SOURCE=.\parse.c
    237 # End Source File
    238 # Begin Source File
    239 
    240 SOURCE=.\pr.c
    241 # End Source File
    242 # End Group
    243 # Begin Group "Header Files"
    244 
    245 # PROP Default_Filter "h;hpp;hxx;hm;inl"
    246 # Begin Source File
    247 
    248 SOURCE=.\def.h
    249 # End Source File
    250 # Begin Source File
    251 
    252 SOURCE=.\ifparser.h
    253 # End Source File
    254 # Begin Source File
    255 
    256 SOURCE=.\imakemdep.h
    257 # End Source File
    258 # End Group
    259 # Begin Group "Resource Files"
    260 
    261 # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
    262 # End Group
    263 # End Target
    264 # End Project
     1
     2
     3
     4
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
  • pr.c

    +# Microsoft Developer Studio Project File - Name="makedepend" - Package Owner=<4>
    +# Microsoft Developer Studio Generated Build File, Format Version 6.00
    +# ** DO NOT EDIT **
    +
    +# TARGTYPE "Win32 (x86) Console Application" 0x0103
    +
    +CFG=makedepend - Win32 Debug
    +!MESSAGE This is not a valid makefile. To build this project using NMAKE,
    +!MESSAGE use the Export Makefile command and run
    +!MESSAGE 
    +!MESSAGE NMAKE /f "makedepend.mak".
    +!MESSAGE 
    +!MESSAGE You can specify a configuration when running NMAKE
    +!MESSAGE by defining the macro CFG on the command line. For example:
    +!MESSAGE 
    +!MESSAGE NMAKE /f "makedepend.mak" CFG="makedepend - Win32 Debug"
    +!MESSAGE 
    +!MESSAGE Possible choices for configuration are:
    +!MESSAGE 
    +!MESSAGE "makedepend - Win32 Release" (based on "Win32 (x86) Console Application")
    +!MESSAGE "makedepend - Win32 Debug" (based on "Win32 (x86) Console Application")
    +!MESSAGE 
    +
    +# Begin Project
    +# PROP AllowPerConfigDependencies 0
    +# PROP Scc_ProjName ""$/ALS2/tools/makedepend", XCGAAAAA"
    +# PROP Scc_LocalPath "."
    +CPP=cl.exe
    +RSC=rc.exe
    +
    +!IF  "$(CFG)" == "makedepend - Win32 Release"
    +
    +# PROP BASE Use_MFC 0
    +# PROP BASE Use_Debug_Libraries 0
    +# PROP BASE Output_Dir "Release"
    +# PROP BASE Intermediate_Dir "Release"
    +# PROP BASE Target_Dir ""
    +# PROP Use_MFC 0
    +# PROP Use_Debug_Libraries 0
    +# PROP Output_Dir "Release"
    +# PROP Intermediate_Dir "Release"
    +# PROP Target_Dir ""
    +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
    +# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /c
    +# ADD BASE RSC /l 0x409 /d "NDEBUG"
    +# ADD RSC /l 0x409 /d "NDEBUG"
    +BSC32=bscmake.exe
    +# ADD BASE BSC32 /nologo
    +# ADD BSC32 /nologo
    +LINK32=link.exe
    +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    +
    +!ELSEIF  "$(CFG)" == "makedepend - Win32 Debug"
    +
    +# PROP BASE Use_MFC 0
    +# PROP BASE Use_Debug_Libraries 1
    +# PROP BASE Output_Dir "makedepend___Win32_Debug"
    +# PROP BASE Intermediate_Dir "makedepend___Win32_Debug"
    +# PROP BASE Target_Dir ""
    +# PROP Use_MFC 0
    +# PROP Use_Debug_Libraries 1
    +# PROP Output_Dir "makedepend___Win32_Debug"
    +# PROP Intermediate_Dir "makedepend___Win32_Debug"
    +# PROP Target_Dir ""
    +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
    +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /GZ /c
    +# ADD BASE RSC /l 0x409 /d "_DEBUG"
    +# ADD RSC /l 0x409 /d "_DEBUG"
    +BSC32=bscmake.exe
    +# ADD BASE BSC32 /nologo
    +# ADD BSC32 /nologo
    +LINK32=link.exe
    +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    +
    +!ENDIF 
    +
    +# Begin Target
    +
    +# Name "makedepend - Win32 Release"
    +# Name "makedepend - Win32 Debug"
    +# Begin Group "Source Files"
    +
    +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
    +# Begin Source File
    +
    +SOURCE=.\cppsetup.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\ifparser.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\include.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\main.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\parse.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\pr.c
    +# End Source File
    +# End Group
    +# Begin Group "Header Files"
    +
    +# PROP Default_Filter "h;hpp;hxx;hm;inl"
    +# Begin Source File
    +
    +SOURCE=.\def.h
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\ifparser.h
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\imakemdep.h
    +# End Source File
    +# End Group
    +# Begin Group "Resource Files"
    +
    +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
    +# End Group
    +# End Target
    +# End Project
    +# Microsoft Developer Studio Project File - Name="makedepend" - Package Owner=<4>
    +# Microsoft Developer Studio Generated Build File, Format Version 6.00
    +# ** DO NOT EDIT **
    +
    +# TARGTYPE "Win32 (x86) Console Application" 0x0103
    +
    +CFG=makedepend - Win32 Debug
    +!MESSAGE This is not a valid makefile. To build this project using NMAKE,
    +!MESSAGE use the Export Makefile command and run
    +!MESSAGE 
    +!MESSAGE NMAKE /f "makedepend.mak".
    +!MESSAGE 
    +!MESSAGE You can specify a configuration when running NMAKE
    +!MESSAGE by defining the macro CFG on the command line. For example:
    +!MESSAGE 
    +!MESSAGE NMAKE /f "makedepend.mak" CFG="makedepend - Win32 Debug"
    +!MESSAGE 
    +!MESSAGE Possible choices for configuration are:
    +!MESSAGE 
    +!MESSAGE "makedepend - Win32 Release" (based on "Win32 (x86) Console Application")
    +!MESSAGE "makedepend - Win32 Debug" (based on "Win32 (x86) Console Application")
    +!MESSAGE 
    +
    +# Begin Project
    +# PROP AllowPerConfigDependencies 0
    +# PROP Scc_ProjName ""$/ALS2/tools/makedepend", XCGAAAAA"
    +# PROP Scc_LocalPath "."
    +CPP=cl.exe
    +RSC=rc.exe
    +
    +!IF  "$(CFG)" == "makedepend - Win32 Release"
    +
    +# PROP BASE Use_MFC 0
    +# PROP BASE Use_Debug_Libraries 0
    +# PROP BASE Output_Dir "Release"
    +# PROP BASE Intermediate_Dir "Release"
    +# PROP BASE Target_Dir ""
    +# PROP Use_MFC 0
    +# PROP Use_Debug_Libraries 0
    +# PROP Output_Dir "Release"
    +# PROP Intermediate_Dir "Release"
    +# PROP Target_Dir ""
    +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
    +# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /c
    +# ADD BASE RSC /l 0x409 /d "NDEBUG"
    +# ADD RSC /l 0x409 /d "NDEBUG"
    +BSC32=bscmake.exe
    +# ADD BASE BSC32 /nologo
    +# ADD BSC32 /nologo
    +LINK32=link.exe
    +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
    +
    +!ELSEIF  "$(CFG)" == "makedepend - Win32 Debug"
    +
    +# PROP BASE Use_MFC 0
    +# PROP BASE Use_Debug_Libraries 1
    +# PROP BASE Output_Dir "makedepend___Win32_Debug"
    +# PROP BASE Intermediate_Dir "makedepend___Win32_Debug"
    +# PROP BASE Target_Dir ""
    +# PROP Use_MFC 0
    +# PROP Use_Debug_Libraries 1
    +# PROP Output_Dir "makedepend___Win32_Debug"
    +# PROP Intermediate_Dir "makedepend___Win32_Debug"
    +# PROP Target_Dir ""
    +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
    +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D STANDALONE=1 /D OBJSUFFIX=\".obj\" /YX /FD /GZ /c
    +# ADD BASE RSC /l 0x409 /d "_DEBUG"
    +# ADD RSC /l 0x409 /d "_DEBUG"
    +BSC32=bscmake.exe
    +# ADD BASE BSC32 /nologo
    +# ADD BSC32 /nologo
    +LINK32=link.exe
    +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
    +
    +!ENDIF 
    +
    +# Begin Target
    +
    +# Name "makedepend - Win32 Release"
    +# Name "makedepend - Win32 Debug"
    +# Begin Group "Source Files"
    +
    +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
    +# Begin Source File
    +
    +SOURCE=.\cppsetup.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\ifparser.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\include.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\main.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\parse.c
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\pr.c
    +# End Source File
    +# End Group
    +# Begin Group "Header Files"
    +
    +# PROP Default_Filter "h;hpp;hxx;hm;inl"
    +# Begin Source File
    +
    +SOURCE=.\def.h
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\ifparser.h
    +# End Source File
    +# Begin Source File
    +
    +SOURCE=.\imakemdep.h
    +# End Source File
    +# End Group
    +# Begin Group "Resource Files"
    +
    +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
    +# End Group
    +# End Target
    +# End Project
     
    122122        for (i=0; i<head->i_listlen; i++)
    123123                recursive_pr_include(head->i_list[ i ], file, base);
    124124}
    125 /*
    126 
    127 Copyright (c) 1993, 1994, 1998 The Open Group
    128 
    129 Permission to use, copy, modify, distribute, and sell this software and its
    130 documentation for any purpose is hereby granted without fee, provided that
    131 the above copyright notice appear in all copies and that both that
    132 copyright notice and this permission notice appear in supporting
    133 documentation.
    134 
    135 The above copyright notice and this permission notice shall be included in
    136 all copies or substantial portions of the Software.
    137 
    138 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    139 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    140 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    141 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    142 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    143 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    144 
    145 Except as contained in this notice, the name of The Open Group shall not be
    146 used in advertising or otherwise to promote the sale, use or other dealings
    147 in this Software without prior written authorization from The Open Group.
    148 
    149 */
    150 /* $Header: /code/makedepend/pr.c,v 1.3 2005/03/03 18:13:08 doj Exp $ */
    151 
    152 #include "def.h"
    153 
    154 extern struct   inclist inclist[ MAXFILES ],
    155                         *inclistp;
    156 extern char     *objprefix;
    157 extern char     *objsuffix;
    158 extern int      width;
    159 extern boolean  printed;
    160 extern boolean  verbose;
    161 extern boolean  show_where_not;
    162 
    163 void
    164 add_include(struct filepointer *filep, struct inclist *file,
    165             struct inclist *file_red, char *include, int type,
    166             boolean failOK)
    167 {
    168         register struct inclist *newfile;
    169         register struct filepointer     *content;
    170 
    171         /*
    172          * First decide what the pathname of this include file really is.
    173          */
    174         newfile = inc_path(file->i_file, include, type);
    175         if (newfile == NULL) {
    176                 if (failOK)
    177                     return;
    178                 if (file != file_red)
    179                         warning("%s (reading %s, line %d): ",
    180                                 file_red->i_file, file->i_file, filep->f_line);
    181                 else
    182                         warning("%s, line %d: ", file->i_file, filep->f_line);
    183                 warning1("cannot find include file \"%s\"\n", include);
    184                 show_where_not = TRUE;
    185                 newfile = inc_path(file->i_file, include, type);
    186                 show_where_not = FALSE;
    187         }
    188 
    189         if (newfile) {
    190                 included_by(file, newfile);
    191                 if (!(newfile->i_flags & SEARCHED)) {
    192                         newfile->i_flags |= SEARCHED;
    193                         content = getfile(newfile->i_file);
    194                         find_includes(content, newfile, file_red, 0, failOK);
    195                         freefile(content);
    196                 }
    197         }
    198 }
    199 
    200 static void
    201 pr(struct inclist *ip, char *file, char *base)
    202 {
    203         static char     *lastfile;
    204         static int      current_len;
    205         register int    len, i;
    206         char    buf[ BUFSIZ ];
    207 
    208         printed = TRUE;
    209         len = strlen(ip->i_file)+1;
    210         if (current_len + len > width || file != lastfile) {
    211                 lastfile = file;
    212                 /* Added quotes here, as i_file may have spaces in the paths under Win32 */
    213                 sprintf(buf, "\n%s%s%s: \"%s\"", objprefix, base, objsuffix,
    214                         ip->i_file);
    215                 len = current_len = strlen(buf);
    216         }
    217         else {
    218                 buf[0] = ' ';
    219                 strcpy(buf+1, ip->i_file);
    220                 current_len += len;
    221         }
    222         fwrite(buf, len, 1, stdout);
    223 
    224         /*
    225          * If verbose is set, then print out what this file includes.
    226          */
    227         if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
    228                 return;
    229         ip->i_flags |= NOTIFIED;
    230         lastfile = NULL;
    231         printf("\n# %s includes:", ip->i_file);
    232         for (i=0; i<ip->i_listlen; i++)
    233                 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
    234 }
    235 
    236 void
    237 recursive_pr_include(struct inclist *head, char *file, char *base)
    238 {
    239         int     i;
    240 
    241         if (head->i_flags & MARKED)
    242                 return;
    243         head->i_flags |= MARKED;
    244         if (head->i_file != file)
    245                 pr(head, file, base);
    246         for (i=0; i<head->i_listlen; i++)
    247                 recursive_pr_include(head->i_list[ i ], file, base);
    248 }
  • cppsetup.c

     
    230230}
    231231#endif /* CPP */
    232232
    233 /*
    234 
    235 Copyright (c) 1993, 1994, 1998  The Open Group
    236 
    237 Permission to use, copy, modify, distribute, and sell this software and its
    238 documentation for any purpose is hereby granted without fee, provided that
    239 the above copyright notice appear in all copies and that both that
    240 copyright notice and this permission notice appear in supporting
    241 documentation.
    242 
    243 The above copyright notice and this permission notice shall be included in
    244 all copies or substantial portions of the Software.
    245 
    246 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    247 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    248 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    249 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    250 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    251 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    252 
    253 Except as contained in this notice, the name of The Open Group shall not be
    254 used in advertising or otherwise to promote the sale, use or other dealings
    255 in this Software without prior written authorization from The Open Group.
    256 
    257 */
    258 /* $Header: /code/makedepend/cppsetup.c,v 1.2 2004/04/20 19:50:26 doj Exp $ */
    259 
    260 #include "def.h"
    261 
    262 #ifdef  CPP
    263 /*
    264  * This file is strictly for the sake of cpy.y and yylex.c (if
    265  * you indeed have the source for cpp).
    266  */
    267 #define IB 1
    268 #define SB 2
    269 #define NB 4
    270 #define CB 8
    271 #define QB 16
    272 #define WB 32
    273 #define SALT '#'
    274 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
    275 #define COFF 128
    276 #else
    277 #define COFF 0
    278 #endif
    279 /*
    280  * These variables used by cpy.y and yylex.c
    281  */
    282 extern char     *outp, *inp, *newp, *pend;
    283 extern char     *ptrtab;
    284 extern char     fastab[];
    285 extern char     slotab[];
    286 
    287 /*
    288  * cppsetup
    289  */
    290 struct filepointer      *currentfile;
    291 struct inclist          *currentinc;
    292 
    293 int
    294 cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
    295 {
    296         char *p, savec;
    297         static boolean setupdone = FALSE;
    298         boolean value;
    299 
    300         if (!setupdone) {
    301                 cpp_varsetup();
    302                 setupdone = TRUE;
    303         }
    304 
    305         currentfile = filep;
    306         currentinc = inc;
    307         inp = newp = line;
    308         for (p=newp; *p; p++)
    309                 ;
    310 
    311         /*
    312          * put a newline back on the end, and set up pend, etc.
    313          */
    314         *p++ = '\n';
    315         savec = *p;
    316         *p = '\0';
    317         pend = p;
    318 
    319         ptrtab = slotab+COFF;
    320         *--inp = SALT;
    321         outp=inp;
    322         value = yyparse();
    323         *p = savec;
    324         return(value);
    325 }
    326 
    327 struct symtab **lookup(symbol)
    328         char    *symbol;
    329 {
    330         static struct symtab    *undefined;
    331         struct symtab   **sp;
    332 
    333         sp = isdefined(symbol, currentinc, NULL);
    334         if (sp == NULL) {
    335                 sp = &undefined;
    336                 (*sp)->s_value = NULL;
    337         }
    338         return (sp);
    339 }
    340 
    341 pperror(tag, x0,x1,x2,x3,x4)
    342         int     tag,x0,x1,x2,x3,x4;
    343 {
    344         warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
    345         warning(x0,x1,x2,x3,x4);
    346 }
    347 
    348 
    349 yyerror(s)
    350         register char   *s;
    351 {
    352         fatalerr("Fatal error: %s\n", s);
    353 }
    354 #else /* not CPP */
    355 
    356 #include "ifparser.h"
    357 struct _parse_data {
    358     struct filepointer *filep;
    359     struct inclist *inc;
    360     char *filename;
    361     const char *line;
    362 };
    363 
    364 static const char *
    365 my_if_errors (IfParser *ip, const char *cp, const char *expecting)
    366 {
    367     struct _parse_data *pd = (struct _parse_data *) ip->data;
    368     int lineno = pd->filep->f_line;
    369     char *filename = pd->filename;
    370     char prefix[300];
    371     int prefixlen;
    372     int i;
    373 
    374     sprintf (prefix, "\"%s\":%d", filename, lineno);
    375     prefixlen = strlen(prefix);
    376     fprintf (stderr, "%s:  %s", prefix, pd->line);
    377     i = cp - pd->line;
    378     if (i > 0 && pd->line[i-1] != '\n') {
    379         putc ('\n', stderr);
    380     }
    381     for (i += prefixlen + 3; i > 0; i--) {
    382         putc (' ', stderr);
    383     }
    384     fprintf (stderr, "^--- expecting %s\n", expecting);
    385     return NULL;
    386 }
    387 
    388 
    389 #define MAXNAMELEN 256
    390 
    391 static struct symtab **
    392 lookup_variable (IfParser *ip, const char *var, int len)
    393 {
    394     char tmpbuf[MAXNAMELEN + 1];
    395     struct _parse_data *pd = (struct _parse_data *) ip->data;
    396 
    397     if (len > MAXNAMELEN)
    398         return 0;
    399 
    400     strncpy (tmpbuf, var, len);
    401     tmpbuf[len] = '\0';
    402     return isdefined (tmpbuf, pd->inc, NULL);
    403 }
    404 
    405 
    406 static int
    407 my_eval_defined (IfParser *ip, const char *var, int len)
    408 {
    409     if (lookup_variable (ip, var, len))
    410         return 1;
    411     else
    412         return 0;
    413 }
    414 
    415 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
    416 
    417 static long
    418 my_eval_variable (IfParser *ip, const char *var, int len)
    419 {
    420     long val;
    421     struct symtab **s;
    422 
    423     s = lookup_variable (ip, var, len);
    424     if (!s)
    425         return 0;
    426     do {
    427         var = (*s)->s_value;
    428         if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
    429             break;
    430         s = lookup_variable (ip, var, strlen(var));
    431     } while (s);
    432 
    433     var = ParseIfExpression(ip, var, &val);
    434     if (var && *var) debug(4, ("extraneous: '%s'\n", var));
    435     return val;
    436 }
    437 
    438 int
    439 cppsetup(char *filename,
    440          char *line,
    441          struct filepointer *filep,
    442          struct inclist *inc)
    443 {
    444     IfParser ip;
    445     struct _parse_data pd;
    446     long val = 0;
    447 
    448     pd.filep = filep;
    449     pd.inc = inc;
    450     pd.line = line;
    451     pd.filename = filename;
    452     ip.funcs.handle_error = my_if_errors;
    453     ip.funcs.eval_defined = my_eval_defined;
    454     ip.funcs.eval_variable = my_eval_variable;
    455     ip.data = (char *) &pd;
    456 
    457     (void) ParseIfExpression (&ip, line, &val);
    458     if (val)
    459         return IF;
    460     else
    461         return IFFALSE;
    462 }
    463 #endif /* CPP */
    464 
  • def.h

     
    182182extern void fatalerr(char *, ...);
    183183extern void warning(char *, ...);
    184184extern void warning1(char *, ...);
    185 /*
    186 
    187 Copyright (c) 1993, 1994, 1998 The Open Group.
    188 
    189 Permission to use, copy, modify, distribute, and sell this software and its
    190 documentation for any purpose is hereby granted without fee, provided that
    191 the above copyright notice appear in all copies and that both that
    192 copyright notice and this permission notice appear in supporting
    193 documentation.
    194 
    195 The above copyright notice and this permission notice shall be included in
    196 all copies or substantial portions of the Software.
    197 
    198 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    199 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    200 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    201 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    202 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    203 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    204 
    205 Except as contained in this notice, the name of The Open Group shall not be
    206 used in advertising or otherwise to promote the sale, use or other dealings
    207 in this Software without prior written authorization from The Open Group.
    208 
    209 */
    210 
    211 /* $Header: /code/makedepend/def.h,v 1.2 2004/04/20 19:50:26 doj Exp $ */
    212 
    213 #ifndef STANDALONE
    214 #include "Xos.h"
    215 #include "Xfuncproto.h"
    216 #endif
    217 #include <stdlib.h>
    218 #include <stdio.h>
    219 #include <string.h>
    220 #include <ctype.h>
    221 #if 0
    222 #ifndef X_NOT_POSIX
    223 #ifndef _POSIX_SOURCE
    224 #define _POSIX_SOURCE
    225 #endif
    226 #endif
    227 #endif
    228 #include <sys/types.h>
    229 #include <fcntl.h>
    230 #include <sys/stat.h>
    231 
    232 #define MAXDEFINES      512
    233 #define MAXFILES        1024
    234 #define MAXINCFILES     128     /* "-include" files */
    235 #define MAXDIRS         64
    236 #define SYMTABINC       10      /* must be > 1 for define() to work right */
    237 #define TRUE            1
    238 #define FALSE           0
    239 
    240 /* the following must match the directives table in main.c */
    241 #define IF              0
    242 #define IFDEF           1
    243 #define IFNDEF          2
    244 #define ELSE            3
    245 #define ENDIF           4
    246 #define DEFINE          5
    247 #define UNDEF           6
    248 #define INCLUDE         7
    249 #define LINE            8
    250 #define PRAGMA          9
    251 #define ERROR           10
    252 #define IDENT           11
    253 #define SCCS            12
    254 #define ELIF            13
    255 #define EJECT           14
    256 #define WARNING         15
    257 #define INCLUDENEXT     16
    258 #define IFFALSE         17     /* pseudo value --- never matched */
    259 #define ELIFFALSE       18     /* pseudo value --- never matched */
    260 #define INCLUDEDOT      19     /* pseudo value --- never matched */
    261 #define IFGUESSFALSE    20     /* pseudo value --- never matched */
    262 #define ELIFGUESSFALSE  21     /* pseudo value --- never matched */
    263 #define INCLUDENEXTDOT  22     /* pseudo value --- never matched */
    264 
    265 #ifdef DEBUG
    266 extern int      _debugmask;
    267 /*
    268  * debug levels are:
    269  *
    270  *     0        show ifn*(def)*,endif
    271  *     1        trace defined/!defined
    272  *     2        show #include
    273  *     3        show #include SYMBOL
    274  *     4-6      unused
    275  */
    276 #define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
    277 #else
    278 #define debug(level,arg) /**/
    279 #endif /* DEBUG */
    280 
    281 typedef unsigned char boolean;
    282 
    283 struct symtab {
    284         char    *s_name;
    285         char    *s_value;
    286 };
    287 
    288 /* possible i_flag */
    289 #define DEFCHECKED      (1<<0)  /* whether defines have been checked */
    290 #define NOTIFIED        (1<<1)  /* whether we have revealed includes */
    291 #define MARKED          (1<<2)  /* whether it's in the makefile */
    292 #define SEARCHED        (1<<3)  /* whether we have read this */
    293 #define FINISHED        (1<<4)  /* whether we are done reading this */
    294 #define INCLUDED_SYM    (1<<5)  /* whether #include SYMBOL was found
    295                                    Can't use i_list if TRUE */
    296 struct  inclist {
    297         char            *i_incstring;   /* string from #include line */
    298         char            *i_file;        /* path name of the include file */
    299         struct inclist  **i_list;       /* list of files it itself includes */
    300         int             i_listlen;      /* length of i_list */
    301         struct symtab   **i_defs;       /* symbol table for this file and its
    302                                            children when merged */
    303         int             i_ndefs;        /* current # defines */
    304         boolean         *i_merged;      /* whether we have merged child
    305                                            defines */
    306         unsigned char   i_flags;
    307 };
    308 
    309 struct filepointer {
    310         char    *f_name;
    311         char    *f_p;
    312         char    *f_base;
    313         char    *f_end;
    314         long    f_len;
    315         long    f_line;
    316         long    cmdinc_count;
    317         char    **cmdinc_list;
    318         long    cmdinc_line;
    319 };
    320 
    321 #include <stdlib.h>
    322 #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
    323 char *malloc(), *realloc();
    324 #endif /* macII */
    325 
    326 char                    *copy(char *str);
    327 int                     match(char *str, char **list);
    328 char                    *base_name(char *file);
    329 char                    *getnextline(struct filepointer *fp);
    330 struct symtab           **slookup(char *symbol, struct inclist *file);
    331 struct symtab           **isdefined(char *symbol, struct inclist *file,
    332                                     struct inclist **srcfile);
    333 struct symtab           **fdefined(char *symbol, struct inclist *file,
    334                                    struct inclist **srcfile);
    335 struct filepointer      *getfile(char *file);
    336 void                    included_by(struct inclist *ip,
    337                                     struct inclist *newfile);
    338 struct inclist          *newinclude(char *newfile, char *incstring);
    339 void                    inc_clean (void);
    340 struct inclist          *inc_path(char *file, char *include, int type);
    341 
    342 void                    freefile(struct filepointer *fp);
    343 
    344 void                    define2(char *name, char *val, struct inclist *file);
    345 void                    define(char *def, struct inclist *file);
    346 void                    undefine(char *symbol, struct inclist *file);
    347 int                     find_includes(struct filepointer *filep,
    348                                       struct inclist *file,
    349                                       struct inclist *file_red,
    350                                       int recursion, boolean failOK);
    351 
    352 void                    recursive_pr_include(struct inclist *head,
    353                                              char *file, char *base);
    354 void                    add_include(struct filepointer *filep,
    355                                     struct inclist *file,
    356                                     struct inclist *file_red,
    357                                     char *include, int type,
    358                                     boolean failOK);
    359 
    360 int                     cppsetup(char *filename,
    361                                  char *line,
    362                                  struct filepointer *filep,
    363                                  struct inclist *inc);
    364 
    365 
    366 extern void fatalerr(char *, ...);
    367 extern void warning(char *, ...);
    368 extern void warning1(char *, ...);
  • include.c

     
    339339
    340340        return NULL;
    341341}
    342 /*
    343 
    344 Copyright (c) 1993, 1994, 1998 The Open Group
    345 
    346 Permission to use, copy, modify, distribute, and sell this software and its
    347 documentation for any purpose is hereby granted without fee, provided that
    348 the above copyright notice appear in all copies and that both that
    349 copyright notice and this permission notice appear in supporting
    350 documentation.
    351 
    352 The above copyright notice and this permission notice shall be included in
    353 all copies or substantial portions of the Software.
    354 
    355 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    356 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    357 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    358 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    359 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    360 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    361 
    362 Except as contained in this notice, the name of The Open Group shall not be
    363 used in advertising or otherwise to promote the sale, use or other dealings
    364 in this Software without prior written authorization from The Open Group.
    365 
    366 */
    367 /* $Header: /code/makedepend/include.c,v 1.3 2005/03/03 18:12:01 doj Exp $ */
    368 
    369 
    370 #include "def.h"
    371 
    372 extern struct   inclist inclist[ MAXFILES ],
    373         *inclistp, *inclistnext;
    374 extern char     *includedirs[ ],
    375         **includedirsnext;
    376 extern char     *notdotdot[ ];
    377 extern boolean show_where_not;
    378 extern boolean warn_multiple;
    379 
    380 static boolean
    381 isdot(char *p)
    382 {
    383         if(p && *p++ == '.' && *p++ == '\0')
    384                 return(TRUE);
    385         return(FALSE);
    386 }
    387 
    388 static boolean
    389 isdotdot(char *p)
    390 {
    391         if(p && *p++ == '.' && *p++ == '.' && *p++ == '\0')
    392                 return(TRUE);
    393         return(FALSE);
    394 }
    395 
    396 static boolean
    397 issymbolic(char *dir, char *component)
    398 {
    399 #ifdef S_IFLNK
    400         struct stat     st;
    401         char    buf[ BUFSIZ ], **pp;
    402 
    403         sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component);
    404         for (pp=notdotdot; *pp; pp++)
    405                 if (strcmp(*pp, buf) == 0)
    406                         return (TRUE);
    407         if (lstat(buf, &st) == 0
    408             && (st.st_mode & S_IFMT) == S_IFLNK) {
    409                 *pp++ = copy(buf);
    410                 if (pp >= &notdotdot[ MAXDIRS ])
    411                         fatalerr("out of .. dirs, increase MAXDIRS\n");
    412                 return(TRUE);
    413         }
    414 #endif
    415         return(FALSE);
    416 }
    417 
    418 /*
    419  * Occasionally, pathnames are created that look like .../x/../y
    420  * Any of the 'x/..' sequences within the name can be eliminated.
    421  * (but only if 'x' is not a symbolic link!!)
    422  */
    423 static void
    424 remove_dotdot(char *path)
    425 {
    426         register char   *end, *from, *to, **cp;
    427         char            *components[ MAXFILES ],
    428                 newpath[ BUFSIZ ];
    429         boolean         component_copied;
    430 
    431         /*
    432          * slice path up into components.
    433          */
    434         to = newpath;
    435         if (*path == '/')
    436                 *to++ = '/';
    437 #ifdef WIN32
    438         if (*path == '\\')
    439                 *to++ = '\\';
    440 #endif
    441         *to = '\0';
    442         cp = components;
    443         for (from=end=path; *end; end++)
    444         {
    445                 if (*end == '/') {
    446                         while (*end == '/')
    447                                 *end++ = '\0';
    448                         if (*from)
    449                                 *cp++ = from;
    450                         from = end;
    451                 }
    452 #ifdef WIN32
    453                 if (*end == '\\') {
    454                         while (*end == '\\')
    455                                 *end++ = '\0';
    456                         if (*from)
    457                                 *cp++ = from;
    458                         from = end;
    459                 }
    460 #endif
    461         }
    462         *cp++ = from;
    463         *cp = NULL;
    464 
    465         /*
    466          * Recursively remove all 'x/..' component pairs.
    467          */
    468         cp = components;
    469         while(*cp) {
    470                 if (!isdot(*cp) && !isdotdot(*cp) && isdotdot(*(cp+1))
    471                     && !issymbolic(newpath, *cp))
    472                 {
    473                         char **fp = cp + 2;
    474                         char **tp = cp;
    475 
    476                         do
    477                                 *tp++ = *fp; /* move all the pointers down */
    478                         while (*fp++);
    479                         if (cp != components)
    480                                 cp--;   /* go back and check for nested ".." */
    481                 } else {
    482                         cp++;
    483                 }
    484         }
    485         /*
    486          * Concatenate the remaining path elements.
    487          */
    488         cp = components;
    489         component_copied = FALSE;
    490         while(*cp) {
    491                 if (component_copied)
    492                         *to++ = '/';
    493                 component_copied = TRUE;
    494                 for (from = *cp; *from; )
    495                         *to++ = *from++;
    496                 *to = '\0';
    497                 cp++;
    498         }
    499         *to++ = '\0';
    500 
    501         /*
    502          * copy the reconstituted path back to our pointer.
    503          */
    504         strcpy(path, newpath);
    505 }
    506 
    507 /*
    508  * Add an include file to the list of those included by 'file'.
    509  */
    510 struct inclist *
    511 newinclude(char *newfile, char *incstring)
    512 {
    513         register struct inclist *ip;
    514 
    515         /*
    516          * First, put this file on the global list of include files.
    517          */
    518         ip = inclistp++;
    519         if (inclistp == inclist + MAXFILES - 1)
    520                 fatalerr("out of space: increase MAXFILES\n");
    521         ip->i_file = copy(newfile);
    522 
    523         if (incstring == NULL)
    524                 ip->i_incstring = ip->i_file;
    525         else
    526                 ip->i_incstring = copy(incstring);
    527 
    528         inclistnext = inclistp;
    529         return(ip);
    530 }
    531 
    532 void
    533 included_by(struct inclist *ip, struct inclist *newfile)
    534 {
    535         register int i;
    536 
    537         if (ip == NULL)
    538                 return;
    539         /*
    540          * Put this include file (newfile) on the list of files included
    541          * by 'file'.  If 'file' is NULL, then it is not an include
    542          * file itself (i.e. was probably mentioned on the command line).
    543          * If it is already on the list, don't stick it on again.
    544          */
    545         if (ip->i_list == NULL) {
    546                 ip->i_list = (struct inclist **)
    547                         malloc(sizeof(struct inclist *) * ++ip->i_listlen);
    548                 ip->i_merged = (boolean *)
    549                         malloc(sizeof(boolean) * ip->i_listlen);
    550         } else {
    551                 for (i=0; i<ip->i_listlen; i++)
    552                         if (ip->i_list[ i ] == newfile) {
    553                                 i = strlen(newfile->i_file);
    554                                 if (!(ip->i_flags & INCLUDED_SYM) &&
    555                                     !(i > 2 &&
    556                                       newfile->i_file[i-1] == 'c' &&
    557                                       newfile->i_file[i-2] == '.'))
    558                                 {
    559                                         /* only bitch if ip has */
    560                                         /* no #include SYMBOL lines  */
    561                                         /* and is not a .c file */
    562                                         if (warn_multiple)
    563                                         {
    564                                                 warning("%s includes %s more than once!\n",
    565                                                         ip->i_file, newfile->i_file);
    566                                                 warning1("Already have\n");
    567                                                 for (i=0; i<ip->i_listlen; i++)
    568                                                         warning1("\t%s\n", ip->i_list[i]->i_file);
    569                                         }
    570                                 }
    571                                 return;
    572                         }
    573                 ip->i_list = (struct inclist **) realloc(ip->i_list,
    574                                                          sizeof(struct inclist *) * ++ip->i_listlen);
    575                 ip->i_merged = (boolean *)
    576                         realloc(ip->i_merged, sizeof(boolean) * ip->i_listlen);
    577         }
    578         ip->i_list[ ip->i_listlen-1 ] = newfile;
    579         ip->i_merged[ ip->i_listlen-1 ] = FALSE;
    580 }
    581 
    582 void
    583 inc_clean (void)
    584 {
    585         register struct inclist *ip;
    586 
    587         for (ip = inclist; ip < inclistp; ip++) {
    588                 ip->i_flags &= ~MARKED;
    589         }
    590 }
    591 
    592 struct inclist *
    593 inc_path(char *file, char *include, int type)
    594 {
    595         static char             path[ BUFSIZ ];
    596         register char           **pp, *p;
    597         register struct inclist *ip;
    598         struct stat             st;
    599 
    600         /*
    601          * Check all previously found include files for a path that
    602          * has already been expanded.
    603          */
    604         if ((type == INCLUDE) || (type == INCLUDEDOT))
    605                 inclistnext = inclist;
    606         ip = inclistnext;
    607 
    608         for (; ip->i_file; ip++) {
    609                 if ((strcmp(ip->i_incstring, include) == 0) &&
    610                     !(ip->i_flags & INCLUDED_SYM)) {
    611                         inclistnext = ip + 1;
    612                         return ip;
    613                 }
    614         }
    615 
    616         if (inclistnext == inclist) {
    617                 /*
    618                  * If the path was surrounded by "" or is an absolute path,
    619                  * then check the exact path provided.
    620                  */
    621                 if ((type == INCLUDEDOT) ||
    622                     (type == INCLUDENEXTDOT) ||
    623                     (*include == '/')
    624 #ifdef WIN32
    625                     || (*include == '\\')
    626 #endif
    627                         ) {
    628                         if (stat(include, &st) == 0)
    629                                 return newinclude(include, include);
    630                         if (show_where_not)
    631                                 warning1("\tnot in %s\n", include);
    632                 }
    633 
    634                 /*
    635                  * If the path was surrounded by "" see if this include file is
    636                  * in the directory of the file being parsed.
    637                  */
    638                 if ((type == INCLUDEDOT) || (type == INCLUDENEXTDOT)) {
    639                         for (p=file+strlen(file); p>file; p--)
    640                                 if (*p == '/'
    641 #ifdef WIN32
    642                                     || *p == '\\'
    643 #endif
    644                                         )
    645 
    646                                         break;
    647                         if (p == file) {
    648                                 strcpy(path, include);
    649                         } else {
    650                                 strncpy(path, file, (p-file) + 1);
    651                                 path[ (p-file) + 1 ] = '\0';
    652                                 strcpy(path + (p-file) + 1, include);
    653                         }
    654                         remove_dotdot(path);
    655                         if (stat(path, &st) == 0)
    656                                 return newinclude(path, include);
    657                         if (show_where_not)
    658                                 warning1("\tnot in %s\n", path);
    659                 }
    660         }
    661 
    662         /*
    663          * Check the include directories specified.  Standard include dirs
    664          * should be at the end.
    665          */
    666         if ((type == INCLUDE) || (type == INCLUDEDOT))
    667                 includedirsnext = includedirs;
    668         pp = includedirsnext;
    669 
    670         for (; *pp; pp++) {
    671                 sprintf(path, "%s/%s", *pp, include);
    672                 remove_dotdot(path);
    673                 if (stat(path, &st) == 0) {
    674                         includedirsnext = pp + 1;
    675                         return newinclude(path, include);
    676                 }
    677                 if (show_where_not)
    678                         warning1("\tnot in %s\n", path);
    679         }
    680 
    681         return NULL;
    682 }
  • main.c

     
    910910        vfprintf(stderr, msg, args);
    911911        va_end(args);
    912912}
    913 /*
    914 
    915 Copyright (c) 1993, 1994, 1998 The Open Group
    916 
    917 Permission to use, copy, modify, distribute, and sell this software and its
    918 documentation for any purpose is hereby granted without fee, provided that
    919 the above copyright notice appear in all copies and that both that
    920 copyright notice and this permission notice appear in supporting
    921 documentation.
    922 
    923 The above copyright notice and this permission notice shall be included in
    924 all copies or substantial portions of the Software.
    925 
    926 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    927 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    928 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    929 THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    930 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    931 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    932 
    933 Except as contained in this notice, the name of The Open Group shall not be
    934 used in advertising or otherwise to promote the sale, use or other dealings
    935 in this Software without prior written authorization from The Open Group.
    936 
    937 */
    938 /* $Header: /code/makedepend/main.c,v 1.3 2005/03/03 18:13:08 doj Exp $ */
    939 
    940 /* modified for standalone and MS-Windows compilation by Dirk Jagdmann <doj@cubic.org> 2004-04-20 */
    941 
    942 #include <errno.h>
    943 #include <string.h>
    944 
    945 #if defined(_MSC_VER)
    946 #include <stdio.h>
    947 /* todo: fix this ugly rename hack */
    948 int myrename(char *from, char *to)
    949 {
    950   int r=1;
    951   char buf[1024];
    952   FILE *in, *out;
    953   in=fopen(from, "rb");
    954   if(in==0)
    955     return -1;
    956   out=fopen(to, "wb");
    957   if(out==0)
    958     return -1;
    959   while(!feof(in) && r>0)
    960     {
    961       r=fread(buf, 1, sizeof(buf), in);
    962       if(r>0)
    963         fwrite(buf, 1, r, out);
    964     }
    965   fclose(out);
    966   fclose(in);
    967   if(unlink(from) < 0)
    968     fprintf(stderr, "could not delete %s : %s\n", from, strerror(errno));
    969 
    970   return 0;
    971 }
    972 #else
    973 #define myrename rename
    974 #endif
    975 
    976 #include "def.h"
    977 #ifdef hpux
    978 #define sigvec sigvector
    979 #endif /* hpux */
    980 
    981 #ifdef X_POSIX_C_SOURCE
    982 #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
    983 #include <signal.h>
    984 #undef _POSIX_C_SOURCE
    985 #else
    986 #if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
    987 #include <signal.h>
    988 #else
    989 #define _POSIX_SOURCE
    990 #include <signal.h>
    991 #undef _POSIX_SOURCE
    992 #endif
    993 #endif
    994 
    995 #include <stdarg.h>
    996 
    997 #ifdef MINIX
    998 #define USE_CHMOD       1
    999 #endif
    1000 
    1001 #ifdef DEBUG
    1002 int     _debugmask;
    1003 #endif
    1004 
    1005 /* #define DEBUG_DUMP */
    1006 #ifdef DEBUG_DUMP
    1007 #define DBG_PRINT(file, fmt, args)   fprintf(file, fmt, args)
    1008 #else
    1009 #define DBG_PRINT(file, fmt, args)   /* empty */
    1010 #endif
    1011 
    1012 #define DASH_INC_PRE    "#include \""
    1013 #define DASH_INC_POST   "\""
    1014 
    1015 char *ProgramName;
    1016 
    1017 char    *directives[] = {
    1018         "if",
    1019         "ifdef",
    1020         "ifndef",
    1021         "else",
    1022         "endif",
    1023         "define",
    1024         "undef",
    1025         "include",
    1026         "line",
    1027         "pragma",
    1028         "error",
    1029         "ident",
    1030         "sccs",
    1031         "elif",
    1032         "eject",
    1033         "warning",
    1034         "include_next",
    1035         NULL
    1036 };
    1037 
    1038 #define MAKEDEPEND
    1039 #include "imakemdep.h"  /* from config sources */
    1040 #undef MAKEDEPEND
    1041 
    1042 struct  inclist inclist[ MAXFILES ],
    1043                 *inclistp = inclist,
    1044                 *inclistnext = inclist,
    1045                 maininclist;
    1046 
    1047 static char     *filelist[ MAXFILES ];
    1048 char            *includedirs[ MAXDIRS + 1 ],
    1049                 **includedirsnext = includedirs;
    1050 char            *notdotdot[ MAXDIRS ];
    1051 static int      cmdinc_count = 0;
    1052 static char     *cmdinc_list[ 2 * MAXINCFILES ];
    1053 char            *objprefix = "";
    1054 char            *objsuffix = OBJSUFFIX;
    1055 static char     *startat = "# DO NOT DELETE";
    1056 int             width = 78;
    1057 static boolean  append = FALSE;
    1058 boolean         printed = FALSE;
    1059 boolean         verbose = FALSE;
    1060 boolean         show_where_not = FALSE;
    1061 /* Warn on multiple includes of same file */
    1062 boolean         warn_multiple = FALSE;
    1063 
    1064 static void setfile_cmdinc(struct filepointer *filep, long count, char **list);
    1065 static void redirect(char *line, char *makefile);
    1066 
    1067 static
    1068 #ifdef SIGNALRETURNSINT
    1069 int
    1070 #else
    1071 void
    1072 #endif
    1073 catch (int sig)
    1074 {
    1075         fflush (stdout);
    1076         fatalerr ("got signal %d\n", sig);
    1077 }
    1078 
    1079 #if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__UNIXOS2__) || defined(Lynx_22) || defined(__CYGWIN__) || defined(_MSC_VER)
    1080 #define USGISH
    1081 #endif
    1082 
    1083 #ifndef USGISH
    1084 #ifdef X_NOT_POSIX
    1085 #define sigaction sigvec
    1086 #define sa_handler sv_handler
    1087 #define sa_mask sv_mask
    1088 #define sa_flags sv_flags
    1089 #endif
    1090 struct sigaction sig_act;
    1091 #endif /* USGISH */
    1092 
    1093 int
    1094 main(int argc, char *argv[])
    1095 {
    1096         char    **fp = filelist;
    1097         char    **incp = includedirs;
    1098         char    *p;
    1099         struct inclist  *ip;
    1100         char    *makefile = NULL;
    1101         struct filepointer      *filecontent;
    1102         struct symtab *psymp = predefs;
    1103         char *endmarker = NULL;
    1104         char *defincdir = NULL;
    1105         char **undeflist = NULL;
    1106         int numundefs = 0, i;
    1107 
    1108         ProgramName = argv[0];
    1109 
    1110         while (psymp->s_name)
    1111         {
    1112             define2(psymp->s_name, psymp->s_value, &maininclist);
    1113             psymp++;
    1114         }
    1115         if (argc == 2 && argv[1][0] == '@') {
    1116             struct stat ast;
    1117             int afd;
    1118             char *args;
    1119             char **nargv;
    1120             int nargc;
    1121             char quotechar = '\0';
    1122 
    1123             nargc = 1;
    1124             if ((afd = open(argv[1]+1, O_RDONLY)) < 0)
    1125                 fatalerr("cannot open \"%s\"\n", argv[1]+1);
    1126             fstat(afd, &ast);
    1127             args = (char *)malloc(ast.st_size + 1);
    1128             if ((ast.st_size = read(afd, args, ast.st_size)) < 0)
    1129                 fatalerr("failed to read %s\n", argv[1]+1);
    1130             args[ast.st_size] = '\0';
    1131             close(afd);
    1132             for (p = args; *p; p++) {
    1133                 if (quotechar) {
    1134                     if (quotechar == '\\' ||
    1135                         (*p == quotechar && p[-1] != '\\'))
    1136                         quotechar = '\0';
    1137                     continue;
    1138                 }
    1139                 switch (*p) {
    1140                 case '\\':
    1141                 case '"':
    1142                 case '\'':
    1143                     quotechar = *p;
    1144                     break;
    1145                 case ' ':
    1146                 case '\n':
    1147                     *p = '\0';
    1148                     if (p > args && p[-1])
    1149                         nargc++;
    1150                     break;
    1151                 }
    1152             }
    1153             if (p[-1])
    1154                 nargc++;
    1155             nargv = (char **)malloc(nargc * sizeof(char *));
    1156             nargv[0] = argv[0];
    1157             argc = 1;
    1158             for (p = args; argc < nargc; p += strlen(p) + 1)
    1159                 if (*p) nargv[argc++] = p;
    1160             argv = nargv;
    1161         }
    1162         for(argc--, argv++; argc; argc--, argv++) {
    1163                 /* if looking for endmarker then check before parsing */
    1164                 if (endmarker && strcmp (endmarker, *argv) == 0) {
    1165                     endmarker = NULL;
    1166                     continue;
    1167                 }
    1168                 if (**argv != '-') {
    1169                         /* treat +thing as an option for C++ */
    1170                         if (endmarker && **argv == '+')
    1171                                 continue;
    1172                         *fp++ = argv[0];
    1173                         continue;
    1174                 }
    1175                 switch(argv[0][1]) {
    1176                 case 'h':
    1177                 case '?':
    1178                   printf("see http://xfree86.org/current/makedepend.1.html\n");
    1179                   return 0;
    1180                 case '-':
    1181                         endmarker = &argv[0][2];
    1182                         if (endmarker[0] == '\0') endmarker = "--";
    1183                         break;
    1184                 case 'D':
    1185                         if (argv[0][2] == '\0') {
    1186                                 argv++;
    1187                                 argc--;
    1188                         }
    1189                         for (p=argv[0] + 2; *p ; p++)
    1190                                 if (*p == '=') {
    1191                                         *p = ' ';
    1192                                         break;
    1193                                 }
    1194                         define(argv[0] + 2, &maininclist);
    1195                         break;
    1196                 case 'I':
    1197                         if (incp >= includedirs + MAXDIRS)
    1198                             fatalerr("Too many -I flags.\n");
    1199                         *incp++ = argv[0]+2;
    1200                         if (**(incp-1) == '\0') {
    1201                                 *(incp-1) = *(++argv);
    1202                                 argc--;
    1203                         }
    1204                         break;
    1205                 case 'U':
    1206                         /* Undef's override all -D's so save them up */
    1207                         numundefs++;
    1208                         if (numundefs == 1)
    1209                             undeflist = malloc(sizeof(char *));
    1210                         else
    1211                             undeflist = realloc(undeflist,
    1212                                                 numundefs * sizeof(char *));
    1213                         if (argv[0][2] == '\0') {
    1214                                 argv++;
    1215                                 argc--;
    1216                         }
    1217                         undeflist[numundefs - 1] = argv[0] + 2;
    1218                         break;
    1219                 case 'Y':
    1220                         defincdir = argv[0]+2;
    1221                         break;
    1222                 /* do not use if endmarker processing */
    1223                 case 'a':
    1224                         if (endmarker) break;
    1225                         append = TRUE;
    1226                         break;
    1227                 case 'w':
    1228                         if (endmarker) break;
    1229                         if (argv[0][2] == '\0') {
    1230                                 argv++;
    1231                                 argc--;
    1232                                 width = atoi(argv[0]);
    1233                         } else
    1234                                 width = atoi(argv[0]+2);
    1235                         break;
    1236                 case 'o':
    1237                         if (endmarker) break;
    1238                         if (argv[0][2] == '\0') {
    1239                                 argv++;
    1240                                 argc--;
    1241                                 objsuffix = argv[0];
    1242                         } else
    1243                                 objsuffix = argv[0]+2;
    1244                         break;
    1245                 case 'p':
    1246                         if (endmarker) break;
    1247                         if (argv[0][2] == '\0') {
    1248                                 argv++;
    1249                                 argc--;
    1250                                 objprefix = argv[0];
    1251                         } else
    1252                                 objprefix = argv[0]+2;
    1253                         break;
    1254                 case 'v':
    1255                         if (endmarker) break;
    1256                         verbose = TRUE;
    1257 #ifdef DEBUG
    1258                         if (argv[0][2])
    1259                                 _debugmask = atoi(argv[0]+2);
    1260 #endif
    1261                         break;
    1262                 case 's':
    1263                         if (endmarker) break;
    1264                         startat = argv[0]+2;
    1265                         if (*startat == '\0') {
    1266                                 startat = *(++argv);
    1267                                 argc--;
    1268                         }
    1269                         if (*startat != '#')
    1270                                 fatalerr("-s flag's value should start %s\n",
    1271                                         "with '#'.");
    1272                         break;
    1273                 case 'f':
    1274                         if (endmarker) break;
    1275                         makefile = argv[0]+2;
    1276                         if (*makefile == '\0') {
    1277                                 makefile = *(++argv);
    1278                                 argc--;
    1279                         }
    1280                         break;
    1281 
    1282                 case 'm':
    1283                         warn_multiple = TRUE;
    1284                         break;
    1285 
    1286                 /* Ignore -O, -g so we can just pass ${CFLAGS} to
    1287                    makedepend
    1288                  */
    1289                 case 'O':
    1290                 case 'g':
    1291                         break;
    1292                 case 'i':
    1293                         if (strcmp(&argv[0][1],"include") == 0) {
    1294                                 char *buf;
    1295                                 if (argc<2)
    1296                                         fatalerr("option -include is a "
    1297                                                  "missing its parameter\n");
    1298                                 if (cmdinc_count >= MAXINCFILES)
    1299                                         fatalerr("Too many -include flags.\n");
    1300                                 argc--;
    1301                                 argv++;
    1302                                 buf = malloc(strlen(DASH_INC_PRE) +
    1303                                              strlen(argv[0]) +
    1304                                              strlen(DASH_INC_POST) + 1);
    1305                                 if(!buf)
    1306                                         fatalerr("out of memory at "
    1307                                                  "-include string\n");
    1308                                 cmdinc_list[2 * cmdinc_count + 0] = argv[0];
    1309                                 cmdinc_list[2 * cmdinc_count + 1] = buf;
    1310                                 cmdinc_count++;
    1311                                 break;
    1312                         }
    1313                         /* intentional fall through */
    1314                 default:
    1315                         if (endmarker) break;
    1316         /*              fatalerr("unknown opt = %s\n", argv[0]); */
    1317                         warning("ignoring option %s\n", argv[0]);
    1318                 }
    1319         }
    1320         /* Now do the undefs from the command line */
    1321         for (i = 0; i < numundefs; i++)
    1322             undefine(undeflist[i], &maininclist);
    1323         if (numundefs > 0)
    1324             free(undeflist);
    1325 
    1326         if (!defincdir) {
    1327 #ifdef PREINCDIR
    1328             if (incp >= includedirs + MAXDIRS)
    1329                 fatalerr("Too many -I flags.\n");
    1330             *incp++ = PREINCDIR;
    1331 #endif
    1332 #if defined(__UNIXOS2__) || defined(STANDALONE)
    1333             {
    1334                 char *emxinc = getenv("C_INCLUDE_PATH");
    1335                 /* can have more than one component */
    1336                 if (emxinc) {
    1337                     char *beg, *end;
    1338                     beg= (char*)strdup(emxinc);
    1339                     for (;;) {
    1340                         end = (char*)strchr(beg,';');
    1341                         if (end) *end = 0;
    1342                         if (incp >= includedirs + MAXDIRS)
    1343                                 fatalerr("Too many include dirs\n");
    1344                         *incp++ = beg;
    1345                         if (!end) break;
    1346                         beg = end+1;
    1347                     }
    1348                 }
    1349             }
    1350 #else /* !__UNIXOS2__, does not use INCLUDEDIR at all */
    1351             if (incp >= includedirs + MAXDIRS)
    1352                 fatalerr("Too many -I flags.\n");
    1353             *incp++ = INCLUDEDIR;
    1354 #endif
    1355 
    1356 #if defined(_MSC_VER)
    1357 /* MSVC defines the INCLUDE environment variable */
    1358             {
    1359                 char *emxinc = getenv("INCLUDE");
    1360                 /* can have more than one component */
    1361                 if (emxinc) {
    1362                     char *beg, *end;
    1363                     beg= (char*)strdup(emxinc);
    1364                     for (;;) {
    1365                         end = (char*)strchr(beg,';');
    1366                         if (end) *end = 0;
    1367                         if (incp >= includedirs + MAXDIRS)
    1368                                 fatalerr("Too many include dirs\n");
    1369                         *incp++ = beg;
    1370                         if (!end) break;
    1371                         beg = end+1;
    1372                     }
    1373                 }
    1374             }       
    1375 #endif
    1376 
    1377 #ifdef EXTRAINCDIR
    1378             if (incp >= includedirs + MAXDIRS)
    1379                 fatalerr("Too many -I flags.\n");
    1380             *incp++ = EXTRAINCDIR;
    1381 #endif
    1382 
    1383 #ifdef POSTINCDIR
    1384             if (incp >= includedirs + MAXDIRS)
    1385                 fatalerr("Too many -I flags.\n");
    1386             *incp++ = POSTINCDIR;
    1387 #endif
    1388         } else if (*defincdir) {
    1389             if (incp >= includedirs + MAXDIRS)
    1390                 fatalerr("Too many -I flags.\n");
    1391             *incp++ = defincdir;
    1392         }
    1393 
    1394         redirect(startat, makefile);
    1395 
    1396         /*
    1397          * catch signals.
    1398          */
    1399 #ifdef USGISH
    1400 /*  should really reset SIGINT to SIG_IGN if it was.  */
    1401 #ifdef SIGHUP
    1402         signal (SIGHUP, catch);
    1403 #endif
    1404         signal (SIGINT, catch);
    1405 #ifdef SIGQUIT
    1406         signal (SIGQUIT, catch);
    1407 #endif
    1408         signal (SIGILL, catch);
    1409 #ifdef SIGBUS
    1410         signal (SIGBUS, catch);
    1411 #endif
    1412         signal (SIGSEGV, catch);
    1413 #ifdef SIGSYS
    1414         signal (SIGSYS, catch);
    1415 #endif
    1416 #else
    1417         sig_act.sa_handler = catch;
    1418 #if defined(_POSIX_SOURCE) || !defined(X_NOT_POSIX)
    1419         sigemptyset(&sig_act.sa_mask);
    1420         sigaddset(&sig_act.sa_mask, SIGINT);
    1421         sigaddset(&sig_act.sa_mask, SIGQUIT);
    1422 #ifdef SIGBUS
    1423         sigaddset(&sig_act.sa_mask, SIGBUS);
    1424 #endif
    1425         sigaddset(&sig_act.sa_mask, SIGILL);
    1426         sigaddset(&sig_act.sa_mask, SIGSEGV);
    1427         sigaddset(&sig_act.sa_mask, SIGHUP);
    1428         sigaddset(&sig_act.sa_mask, SIGPIPE);
    1429 #ifdef SIGSYS
    1430         sigaddset(&sig_act.sa_mask, SIGSYS);
    1431 #endif
    1432 #else
    1433         sig_act.sa_mask = ((1<<(SIGINT -1))
    1434                            |(1<<(SIGQUIT-1))
    1435 #ifdef SIGBUS
    1436                            |(1<<(SIGBUS-1))
    1437 #endif
    1438                            |(1<<(SIGILL-1))
    1439                            |(1<<(SIGSEGV-1))
    1440                            |(1<<(SIGHUP-1))
    1441                            |(1<<(SIGPIPE-1))
    1442 #ifdef SIGSYS
    1443                            |(1<<(SIGSYS-1))
    1444 #endif
    1445                            );
    1446 #endif /* _POSIX_SOURCE */
    1447         sig_act.sa_flags = 0;
    1448         sigaction(SIGHUP, &sig_act, (struct sigaction *)0);
    1449         sigaction(SIGINT, &sig_act, (struct sigaction *)0);
    1450         sigaction(SIGQUIT, &sig_act, (struct sigaction *)0);
    1451         sigaction(SIGILL, &sig_act, (struct sigaction *)0);
    1452 #ifdef SIGBUS
    1453         sigaction(SIGBUS, &sig_act, (struct sigaction *)0);
    1454 #endif
    1455         sigaction(SIGSEGV, &sig_act, (struct sigaction *)0);
    1456 #ifdef SIGSYS
    1457         sigaction(SIGSYS, &sig_act, (struct sigaction *)0);
    1458 #endif
    1459 #endif /* USGISH */
    1460 
    1461         /*
    1462          * now peruse through the list of files.
    1463          */
    1464         for(fp=filelist; *fp; fp++) {
    1465                 DBG_PRINT(stderr,"file: %s\n",*fp);
    1466                 filecontent = getfile(*fp);
    1467                 setfile_cmdinc(filecontent, cmdinc_count, cmdinc_list);
    1468                 ip = newinclude(*fp, (char *)NULL);
    1469 
    1470                 find_includes(filecontent, ip, ip, 0, FALSE);
    1471                 freefile(filecontent);
    1472                 recursive_pr_include(ip, ip->i_file, base_name(*fp));
    1473                 inc_clean();
    1474         }
    1475         if (printed)
    1476                 printf("\n");
    1477         return 0;
    1478 }
    1479 
    1480 #ifdef __UNIXOS2__
    1481 /*
    1482  * eliminate \r chars from file
    1483  */
    1484 static int
    1485 elim_cr(char *buf, int sz)
    1486 {
    1487         int i,wp;
    1488         for (i= wp = 0; i<sz; i++) {
    1489                 if (buf[i] != '\r')
    1490                         buf[wp++] = buf[i];
    1491         }
    1492         return wp;
    1493 }
    1494 #endif
    1495 
    1496 struct filepointer *
    1497 getfile(char *file)
    1498 {
    1499         int     fd;
    1500         struct filepointer      *content;
    1501         struct stat     st;
    1502 
    1503         content = (struct filepointer *)malloc(sizeof(struct filepointer));
    1504         content->f_name = file;
    1505         if ((fd = open(file, O_RDONLY)) < 0) {
    1506                 warning("cannot open \"%s\"\n", file);
    1507                 content->f_p = content->f_base = content->f_end = (char *)malloc(1);
    1508                 *content->f_p = '\0';
    1509                 return(content);
    1510         }
    1511         fstat(fd, &st);
    1512         content->f_base = (char *)malloc(st.st_size+1);
    1513         if (content->f_base == NULL)
    1514                 fatalerr("cannot allocate mem\n");
    1515         if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0)
    1516                 fatalerr("failed to read %s\n", file);
    1517 #ifdef __UNIXOS2__
    1518         st.st_size = elim_cr(content->f_base,st.st_size);
    1519 #endif
    1520         close(fd);
    1521         content->f_len = st.st_size+1;
    1522         content->f_p = content->f_base;
    1523         content->f_end = content->f_base + st.st_size;
    1524         *content->f_end = '\0';
    1525         content->f_line = 0;
    1526         content->cmdinc_count = 0;
    1527         content->cmdinc_list = NULL;
    1528         content->cmdinc_line = 0;
    1529         return(content);
    1530 }
    1531 
    1532 void
    1533 setfile_cmdinc(struct filepointer* filep, long count, char** list)
    1534 {
    1535         filep->cmdinc_count = count;
    1536         filep->cmdinc_list = list;
    1537         filep->cmdinc_line = 0;
    1538 }
    1539 
    1540 void
    1541 freefile(struct filepointer *fp)
    1542 {
    1543         free(fp->f_base);
    1544         free(fp);
    1545 }
    1546 
    1547 char *copy(char *str)
    1548 {
    1549         char    *p = (char *)malloc(strlen(str) + 1);
    1550 
    1551         strcpy(p, str);
    1552         return(p);
    1553 }
    1554 
    1555 int
    1556 match(char *str, char **list)
    1557 {
    1558         int     i;
    1559 
    1560         for (i=0; *list; i++, list++)
    1561                 if (strcmp(str, *list) == 0)
    1562                         return(i);
    1563         return(-1);
    1564 }
    1565 
    1566 /*
    1567  * Get the next line.  We only return lines beginning with '#' since that
    1568  * is all this program is ever interested in.
    1569  */
    1570 char *getnextline(struct filepointer *filep)
    1571 {
    1572         char    *p,     /* walking pointer */
    1573                 *eof,   /* end of file pointer */
    1574                 *bol;   /* beginning of line pointer */
    1575         int     lineno; /* line number */
    1576         boolean whitespace = FALSE;
    1577 
    1578         /*
    1579          * Fake the "-include" line files in form of #include to the
    1580          * start of each file.
    1581          */
    1582         if (filep->cmdinc_line < filep->cmdinc_count) {
    1583                 char *inc = filep->cmdinc_list[2 * filep->cmdinc_line + 0];
    1584                 char *buf = filep->cmdinc_list[2 * filep->cmdinc_line + 1];
    1585                 filep->cmdinc_line++;
    1586                 sprintf(buf,"%s%s%s",DASH_INC_PRE,inc,DASH_INC_POST);
    1587                 DBG_PRINT(stderr,"%s\n",buf);
    1588                 return(buf);
    1589         }
    1590 
    1591         p = filep->f_p;
    1592         eof = filep->f_end;
    1593         if (p >= eof)
    1594                 return((char *)NULL);
    1595         lineno = filep->f_line;
    1596 
    1597         for (bol = p--; ++p < eof; ) {
    1598                 if ((bol == p) && ((*p == ' ') || (*p == '\t')))
    1599                 {
    1600                         /* Consume leading white-spaces for this line */
    1601                         while (((p+1) < eof) && ((*p == ' ') || (*p == '\t')))
    1602                         {
    1603                                 p++;
    1604                                 bol++;
    1605                         }
    1606                         whitespace = TRUE;
    1607                 }
    1608 
    1609                 if (*p == '/' && (p+1) < eof && *(p+1) == '*') {
    1610                         /* Consume C comments */
    1611                         *(p++) = ' ';
    1612                         *(p++) = ' ';
    1613                         while (p < eof && *p) {
    1614                                 if (*p == '*' && (p+1) < eof && *(p+1) == '/') {
    1615                                         *(p++) = ' ';
    1616                                         *(p++) = ' ';
    1617                                         break;
    1618                                 }
    1619                                 if (*p == '\n')
    1620                                         lineno++;
    1621                                 *(p++) = ' ';
    1622                         }
    1623                         --p;
    1624                 }
    1625                 else if (*p == '/' && (p+1) < eof && *(p+1) == '/') {
    1626                         /* Consume C++ comments */
    1627                         *(p++) = ' ';
    1628                         *(p++) = ' ';
    1629                         while (p < eof && *p) {
    1630                                 if (*p == '\\' && (p+1) < eof &&
    1631                                     *(p+1) == '\n') {
    1632                                         *(p++) = ' ';
    1633                                         lineno++;
    1634                                 }
    1635                                 else if (*p == '?' && (p+3) < eof &&
    1636                                          *(p+1) == '?' &&
    1637                                          *(p+2) == '/' &&
    1638                                          *(p+3) == '\n') {
    1639                                         *(p++) = ' ';
    1640                                         *(p++) = ' ';
    1641                                         *(p++) = ' ';
    1642                                         lineno++;
    1643                                 }
    1644                                 else if (*p == '\n')
    1645                                         break;  /* to process end of line */
    1646                                 *(p++) = ' ';
    1647                         }
    1648                         --p;
    1649                 }
    1650                 else if (*p == '\\' && (p+1) < eof && *(p+1) == '\n') {
    1651                         /* Consume backslash line terminations */
    1652                         *(p++) = ' ';
    1653                         *p = ' ';
    1654                         lineno++;
    1655                 }
    1656                 else if (*p == '?' && (p+3) < eof &&
    1657                          *(p+1) == '?' && *(p+2) == '/' && *(p+3) == '\n') {
    1658                         /* Consume trigraph'ed backslash line terminations */
    1659                         *(p++) = ' ';
    1660                         *(p++) = ' ';
    1661                         *(p++) = ' ';
    1662                         *p = ' ';
    1663                         lineno++;
    1664                 }
    1665                 else if (*p == '\n') {
    1666                         lineno++;
    1667                         if (*bol == '#') {
    1668                                 char *cp;
    1669 
    1670                                 *(p++) = '\0';
    1671                                 /* punt lines with just # (yacc generated) */
    1672                                 for (cp = bol+1;
    1673                                      *cp && (*cp == ' ' || *cp == '\t'); cp++);
    1674                                 if (*cp) goto done;
    1675                                 --p;
    1676                         }
    1677                         bol = p+1;
    1678                         whitespace = FALSE;
    1679                 }
    1680         }
    1681         if (*bol != '#')
    1682                 bol = NULL;
    1683 done:
    1684         if (bol && whitespace) {
    1685         //      warning("%s:  non-portable whitespace encountered at line %d\n",
    1686 //                      filep->f_name, lineno);
    1687         }
    1688         filep->f_p = p;
    1689         filep->f_line = lineno;
    1690 #ifdef DEBUG_DUMP
    1691         if (bol)
    1692                 DBG_PRINT(stderr,"%s\n",bol);
    1693 #endif
    1694         return(bol);
    1695 }
    1696 
    1697 /*
    1698  * Strip the file name down to what we want to see in the Makefile.
    1699  * It will have objprefix and objsuffix around it.
    1700  */
    1701 char *base_name(char *file)
    1702 {
    1703         char    *p;
    1704 
    1705         file = copy(file);
    1706         for(p=file+strlen(file); p>file && *p != '.'; p--) ;
    1707 
    1708         if (*p == '.')
    1709                 *p = '\0';
    1710         return(file);
    1711 }
    1712 
    1713 #if defined(USG) && !defined(CRAY) && !defined(SVR4) && !defined(__UNIXOS2__) && !defined(clipper) && !defined(__clipper__)
    1714 int myrename (char *from, char *to)
    1715 {
    1716     (void) unlink (to);
    1717     if (link (from, to) == 0) {
    1718         unlink (from);
    1719         return 0;
    1720     } else {
    1721         return -1;
    1722     }
    1723 }
    1724 #endif /* USGISH */
    1725 
    1726 void
    1727 redirect(char *line, char *makefile)
    1728 {
    1729         struct stat     st;
    1730         FILE    *fdin, *fdout;
    1731         char    backup[ BUFSIZ ],
    1732                 buf[ BUFSIZ ];
    1733         boolean found = FALSE;
    1734         int     len;
    1735 
    1736         /*
    1737          * if makefile is "-" then let it pour onto stdout.
    1738          */
    1739         if (makefile && *makefile == '-' && *(makefile+1) == '\0') {
    1740                 puts(line);
    1741                 return;
    1742         }
    1743 
    1744         /*
    1745          * use a default makefile is not specified.
    1746          */
    1747         if (!makefile) {
    1748                 if (stat("Makefile", &st) == 0)
    1749                         makefile = "Makefile";
    1750                 else if (stat("makefile", &st) == 0)
    1751                         makefile = "makefile";
    1752                 else
    1753                         fatalerr("[mM]akefile is not present\n");
    1754         }
    1755         else
    1756             stat(makefile, &st);
    1757         if ((fdin = fopen(makefile, "r")) == NULL)
    1758                 fatalerr("cannot open \"%s\"\n", makefile);
    1759         sprintf(backup, "%s.bak", makefile);
    1760         unlink(backup);
    1761 #if defined(WIN32) || defined(__UNIXOS2__) || defined(__CYGWIN__)
    1762         fclose(fdin);
    1763 #endif
    1764         if (myrename(makefile, backup) < 0)
    1765                 fatalerr("cannot rename %s to %s : %s\n", makefile, backup, strerror(errno));
    1766 #if defined(WIN32) || defined(__UNIXOS2__) || defined(__CYGWIN__)
    1767         if ((fdin = fopen(backup, "r")) == NULL)
    1768                 fatalerr("cannot open \"%s\"\n", backup);
    1769 #endif
    1770         if ((fdout = freopen(makefile, "w", stdout)) == NULL)
    1771                 fatalerr("cannot open \"%s\"\n", backup);
    1772         len = strlen(line);
    1773         while (!found && fgets(buf, BUFSIZ, fdin)) {
    1774                 if (*buf == '#' && strncmp(line, buf, len) == 0)
    1775                         found = TRUE;
    1776                 fputs(buf, fdout);
    1777         }
    1778         if (!found) {
    1779                 if (verbose)
    1780                 warning("Adding new delimiting line \"%s\" and dependencies...\n",
    1781                         line);
    1782                 puts(line); /* same as fputs(fdout); but with newline */
    1783         } else if (append) {
    1784             while (fgets(buf, BUFSIZ, fdin)) {
    1785                 fputs(buf, fdout);
    1786             }
    1787         }
    1788         fflush(fdout);
    1789 #if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
    1790         chmod(makefile, st.st_mode);
    1791 #else
    1792         fchmod(fileno(fdout), st.st_mode);
    1793 #endif /* USGISH */
    1794 }
    1795 
    1796 void
    1797 fatalerr(char *msg, ...)
    1798 {
    1799         va_list args;
    1800         fprintf(stderr, "%s: error:  ", ProgramName);
    1801         va_start(args, msg);
    1802         vfprintf(stderr, msg, args);
    1803         va_end(args);
    1804         exit (1);
    1805 }
    1806 
    1807 void
    1808 warning(char *msg, ...)
    1809 {
    1810         va_list args;
    1811         fprintf(stderr, "%s: warning:  ", ProgramName);
    1812         va_start(args, msg);
    1813         vfprintf(stderr, msg, args);
    1814         va_end(args);
    1815 }
    1816 
    1817 void
    1818 warning1(char *msg, ...)
    1819 {
    1820         va_list args;
    1821         va_start(args, msg);
    1822         vfprintf(stderr, msg, args);
    1823         va_end(args);
    1824 }
  • parse.c

     
    683683        debug(2,("finished with %s\n", file->i_file));
    684684        return(-1);
    685685}
    686 /*
    687 
    688 Copyright (c) 1993, 1994, 1998 The Open Group
    689 
    690 Permission to use, copy, modify, distribute, and sell this software and its
    691 documentation for any purpose is hereby granted without fee, provided that
    692 the above copyright notice appear in all copies and that both that
    693 copyright notice and this permission notice appear in supporting
    694 documentation.
    695 
    696 The above copyright notice and this permission notice shall be included in
    697 all copies or substantial portions of the Software.
    698 
    699 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    700 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    701 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    702 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    703 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    704 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    705 
    706 Except as contained in this notice, the name of The Open Group shall not be
    707 used in advertising or otherwise to promote the sale, use or other dealings
    708 in this Software without prior written authorization from The Open Group.
    709 
    710 */
    711 /* $Header: /code/makedepend/parse.c,v 1.3 2005/03/03 18:13:08 doj Exp $ */
    712 
    713 #include "def.h"
    714 
    715 extern char     *directives[];
    716 extern struct inclist   inclist[ MAXFILES ],
    717                         *inclistnext,
    718                         maininclist;
    719 extern char     *includedirs[ ],
    720                 **includedirsnext;
    721 
    722 static int deftype (char *line, struct filepointer *filep,
    723                     struct inclist *file_red, struct inclist *file,
    724                     int parse_it);
    725 static int zero_value(char *filename, char *exp, struct filepointer *filep,
    726                     struct inclist *file_red);
    727 static int merge2defines(struct inclist *file1, struct inclist *file2);
    728 
    729 static int
    730 gobble(struct filepointer *filep, struct inclist *file,
    731        struct inclist *file_red)
    732 {
    733         char    *line;
    734         int     type;
    735 
    736         while ((line = getnextline(filep))) {
    737                 switch(type = deftype(line, filep, file_red, file, FALSE)) {
    738                 case IF:
    739                 case IFFALSE:
    740                 case IFGUESSFALSE:
    741                 case IFDEF:
    742                 case IFNDEF:
    743                         type = gobble(filep, file, file_red);
    744                         while ((type == ELIF) || (type == ELIFFALSE) ||
    745                                (type == ELIFGUESSFALSE))
    746                             type = gobble(filep, file, file_red);
    747                         if (type == ELSE)
    748                                 (void)gobble(filep, file, file_red);
    749                         break;
    750                 case ELSE:
    751                 case ENDIF:
    752                         debug(0,("%s, line %d: #%s\n",
    753                                 file->i_file, filep->f_line,
    754                                 directives[type]));
    755                         return(type);
    756                 case DEFINE:
    757                 case UNDEF:
    758                 case INCLUDE:
    759                 case INCLUDEDOT:
    760                 case PRAGMA:
    761                 case ERROR:
    762                 case IDENT:
    763                 case SCCS:
    764                 case EJECT:
    765                 case WARNING:
    766                 case INCLUDENEXT:
    767                 case INCLUDENEXTDOT:
    768                         break;
    769                 case ELIF:
    770                 case ELIFFALSE:
    771                 case ELIFGUESSFALSE:
    772                         return(type);
    773                 case -1:
    774                         warning("%s", file_red->i_file);
    775                         if (file_red != file)
    776                                 warning1(" (reading %s)", file->i_file);
    777                         warning1(", line %d: unknown directive == \"%s\"\n",
    778                                 filep->f_line, line);
    779                         break;
    780                 }
    781         }
    782         return(-1);
    783 }
    784 
    785 /*
    786  * Decide what type of # directive this line is.
    787  */
    788 static int
    789 deftype (char *line, struct filepointer *filep,
    790              struct inclist *file_red, struct inclist *file, int parse_it)
    791 {
    792         register char   *p;
    793         char    *directive, savechar, *q;
    794         register int    ret;
    795 
    796         /*
    797          * Parse the directive...
    798          */
    799         directive=line+1;
    800         while (*directive == ' ' || *directive == '\t')
    801                 directive++;
    802 
    803         p = directive;
    804         while ((*p == '_') || (*p >= 'a' && *p <= 'z'))
    805                 p++;
    806         savechar = *p;
    807         *p = '\0';
    808         ret = match(directive, directives);
    809         *p = savechar;
    810 
    811         /* If we don't recognize this compiler directive or we happen to just
    812          * be gobbling up text while waiting for an #endif or #elif or #else
    813          * in the case of an #elif we must check the zero_value and return an
    814          * ELIF or an ELIFFALSE.
    815          */
    816 
    817         if (ret == ELIF && !parse_it)
    818         {
    819             while (*p == ' ' || *p == '\t')
    820                 p++;
    821             /*
    822              * parse an expression.
    823              */
    824             debug(0,("%s, line %d: #elif %s ",
    825                    file->i_file, filep->f_line, p));
    826             ret = zero_value(file->i_file, p, filep, file_red);
    827             if (ret != IF)
    828             {
    829                 debug(0,("false...\n"));
    830                 if (ret == IFFALSE)
    831                     return(ELIFFALSE);
    832                 else
    833                     return(ELIFGUESSFALSE);
    834             }
    835             else
    836             {
    837                 debug(0,("true...\n"));
    838                 return(ELIF);
    839             }
    840         }
    841 
    842         if (ret < 0 || ! parse_it)
    843                 return(ret);
    844 
    845         /*
    846          * now decide how to parse the directive, and do it.
    847          */
    848         while (*p == ' ' || *p == '\t')
    849                 p++;
    850         q = p + strlen(p);
    851         do {
    852                 q--;
    853         } while (*q == ' ' || *q == '\t');
    854         q[1] = '\0';
    855         switch (ret) {
    856         case IF:
    857                 /*
    858                  * parse an expression.
    859                  */
    860                 ret = zero_value(file->i_file, p, filep, file_red);
    861                 debug(0,("%s, line %d: %s #if %s\n",
    862                          file->i_file, filep->f_line, ret?"false":"true", p));
    863                 break;
    864         case IFDEF:
    865         case IFNDEF:
    866                 debug(0,("%s, line %d: #%s %s\n",
    867                         file->i_file, filep->f_line, directives[ret], p));
    868         case UNDEF:
    869                 /*
    870                  * separate the name of a single symbol.
    871                  */
    872                 while (isalnum(*p) || *p == '_')
    873                         *line++ = *p++;
    874                 *line = '\0';
    875                 break;
    876         case INCLUDE:
    877         case INCLUDENEXT:
    878                 debug(2,("%s, line %d: #include%s %s\n",
    879                         file->i_file, filep->f_line,
    880                         (ret == INCLUDE) ? "" : "_next", p));
    881 
    882                 /* Support ANSI macro substitution */
    883                 while (1) {
    884                         struct symtab **sym;
    885 
    886                         if (!*p || *p == '"' || *p == '<')
    887                                 break;
    888 
    889                         sym = isdefined(p, file_red, NULL);
    890                         if (!sym)
    891                                 break;
    892 
    893                         p = (*sym)->s_value;
    894                         debug(3,("%s : #includes SYMBOL %s = %s\n",
    895                                file->i_incstring,
    896                                (*sym) -> s_name,
    897                                (*sym) -> s_value));
    898                         /* mark file as having included a 'soft include' */
    899                         file->i_flags |= INCLUDED_SYM;
    900                 }
    901 
    902                 /*
    903                  * Separate the name of the include file.
    904                  */
    905                 while (*p && *p != '"' && *p != '<')
    906                         p++;
    907                 if (! *p)
    908                         return(-2);
    909                 if (*p++ == '"') {
    910                         if (ret == INCLUDE)
    911                                 ret = INCLUDEDOT;
    912                         else
    913                                 ret = INCLUDENEXTDOT;
    914                         while (*p && *p != '"')
    915                                 *line++ = *p++;
    916                 } else
    917                         while (*p && *p != '>')
    918                                 *line++ = *p++;
    919                 *line = '\0';
    920                 break;
    921         case DEFINE:
    922                 /*
    923                  * copy the definition back to the beginning of the line.
    924                  */
    925                 strcpy (line, p);
    926                 break;
    927         case ELSE:
    928         case ENDIF:
    929         case ELIF:
    930         case PRAGMA:
    931         case ERROR:
    932         case IDENT:
    933         case SCCS:
    934         case EJECT:
    935         case WARNING:
    936                 debug(0,("%s, line %d: #%s\n",
    937                         file->i_file, filep->f_line, directives[ret]));
    938                 /*
    939                  * nothing to do.
    940                  */
    941                 break;
    942         }
    943         return(ret);
    944 }
    945 
    946 struct symtab **
    947 fdefined(char *symbol, struct inclist *file, struct inclist **srcfile)
    948 {
    949         struct inclist  **ip;
    950         struct symtab   **val;
    951         int     i;
    952         static int      recurse_lvl = 0;
    953 
    954         if (file->i_flags & DEFCHECKED)
    955                 return(NULL);
    956         debug(2,("Looking for %s in %s\n", symbol, file->i_file));
    957         file->i_flags |= DEFCHECKED;
    958         if ((val = slookup(symbol, file)))
    959                 debug(1,("%s defined in %s as %s\n",
    960                          symbol, file->i_file, (*val)->s_value));
    961         if (val == NULL && file->i_list)
    962         {
    963                 for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++)
    964                         if (file->i_merged[i]==FALSE) {
    965                                 val = fdefined(symbol, *ip, srcfile);
    966                                 file->i_merged[i]=merge2defines(file,*ip);
    967                                 if (val!=NULL) break;
    968                         }
    969         }
    970         else if (val != NULL && srcfile != NULL) *srcfile = file;
    971         recurse_lvl--;
    972         file->i_flags &= ~DEFCHECKED;
    973 
    974         return(val);
    975 }
    976 
    977 struct symtab **
    978 isdefined(char *symbol, struct inclist *file, struct inclist **srcfile)
    979 {
    980         struct symtab   **val;
    981 
    982         if ((val = slookup(symbol, &maininclist))) {
    983                 debug(1,("%s defined on command line\n", symbol));
    984                 if (srcfile != NULL) *srcfile = &maininclist;
    985                 return(val);
    986         }
    987         if ((val = fdefined(symbol, file, srcfile)))
    988                 return(val);
    989         debug(1,("%s not defined in %s\n", symbol, file->i_file));
    990         return(NULL);
    991 }
    992 
    993 /*
    994  * Return type based on if the #if expression evaluates to 0
    995  */
    996 static int
    997 zero_value(char *filename,
    998            char *exp,
    999            struct filepointer *filep,
    1000            struct inclist *file_red)
    1001 {
    1002         if (cppsetup(filename, exp, filep, file_red))
    1003             return(IFFALSE);
    1004         else
    1005             return(IF);
    1006 }
    1007 
    1008 void
    1009 define2(char *name, char *val, struct inclist *file)
    1010 {
    1011     int first, last, below;
    1012     register struct symtab **sp = NULL, **dest;
    1013     struct symtab *stab;
    1014 
    1015     /* Make space if it's needed */
    1016     if (file->i_defs == NULL)
    1017     {
    1018         file->i_defs = (struct symtab **)
    1019                         malloc(sizeof (struct symtab*) * SYMTABINC);
    1020         file->i_ndefs = 0;
    1021     }
    1022     else if (!(file->i_ndefs % SYMTABINC))
    1023         file->i_defs = (struct symtab **)
    1024                         realloc(file->i_defs,
    1025                            sizeof(struct symtab*)*(file->i_ndefs+SYMTABINC));
    1026 
    1027     if (file->i_defs == NULL)
    1028         fatalerr("malloc()/realloc() failure in insert_defn()\n");
    1029 
    1030     below = first = 0;
    1031     last = file->i_ndefs - 1;
    1032     while (last >= first)
    1033     {
    1034         /* Fast inline binary search */
    1035         register char *s1;
    1036         register char *s2;
    1037         register int middle = (first + last) / 2;
    1038 
    1039         /* Fast inline strchr() */
    1040         s1 = name;
    1041         s2 = file->i_defs[middle]->s_name;
    1042         while (*s1++ == *s2++)
    1043             if (s2[-1] == '\0') break;
    1044 
    1045         /* If exact match, set sp and break */
    1046         if (*--s1 == *--s2)
    1047         {
    1048             sp = file->i_defs + middle;
    1049             break;
    1050         }
    1051 
    1052         /* If name > i_defs[middle] ... */
    1053         if (*s1 > *s2)
    1054         {
    1055             below = first;
    1056             first = middle + 1;
    1057         }
    1058         /* else ... */
    1059         else
    1060         {
    1061             below = last = middle - 1;
    1062         }
    1063     }
    1064 
    1065     /* Search is done.  If we found an exact match to the symbol name,
    1066        just replace its s_value */
    1067     if (sp != NULL)
    1068     {
    1069         debug(1,("redefining %s from %s to %s in file %s\n",
    1070                 name, (*sp)->s_value, val, file->i_file));
    1071         free((*sp)->s_value);
    1072         (*sp)->s_value = copy(val);
    1073         return;
    1074     }
    1075 
    1076     sp = file->i_defs + file->i_ndefs++;
    1077     dest = file->i_defs + below + 1;
    1078     while (sp > dest)
    1079     {
    1080         *sp = sp[-1];
    1081         sp--;
    1082     }
    1083     stab = (struct symtab *) malloc(sizeof (struct symtab));
    1084     if (stab == NULL)
    1085         fatalerr("malloc()/realloc() failure in insert_defn()\n");
    1086 
    1087     debug(1,("defining %s to %s in file %s\n", name, val, file->i_file));
    1088     stab->s_name = copy(name);
    1089     stab->s_value = copy(val);
    1090     *sp = stab;
    1091 }
    1092 
    1093 void
    1094 define(char *def, struct inclist *file)
    1095 {
    1096     char *val;
    1097 
    1098     /* Separate symbol name and its value */
    1099     val = def;
    1100     while (isalnum(*val) || *val == '_')
    1101         val++;
    1102     if (*val)
    1103         *val++ = '\0';
    1104     while (*val == ' ' || *val == '\t')
    1105         val++;
    1106 
    1107     if (!*val)
    1108         val = "1";
    1109     define2(def, val, file);
    1110 }
    1111 
    1112 struct symtab **
    1113 slookup(char *symbol, struct inclist *file)
    1114 {
    1115         register int first = 0;
    1116         register int last = file->i_ndefs - 1;
    1117 
    1118         if (file) while (last >= first)
    1119         {
    1120             /* Fast inline binary search */
    1121             register char *s1;
    1122             register char *s2;
    1123             register int middle = (first + last) / 2;
    1124 
    1125             /* Fast inline strchr() */
    1126             s1 = symbol;
    1127             s2 = file->i_defs[middle]->s_name;
    1128             while (*s1++ == *s2++)
    1129                 if (s2[-1] == '\0') break;
    1130 
    1131             /* If exact match, we're done */
    1132             if (*--s1 == *--s2)
    1133             {
    1134                 return file->i_defs + middle;
    1135             }
    1136 
    1137             /* If symbol > i_defs[middle] ... */
    1138             if (*s1 > *s2)
    1139             {
    1140                 first = middle + 1;
    1141             }
    1142             /* else ... */
    1143             else
    1144             {
    1145                 last = middle - 1;
    1146             }
    1147         }
    1148         return(NULL);
    1149 }
    1150 
    1151 static int
    1152 merge2defines(struct inclist *file1, struct inclist *file2)
    1153 {
    1154         int i;
    1155 
    1156         if ((file1==NULL) || (file2==NULL) ||
    1157             !(file2->i_flags & FINISHED))
    1158                 return 0;
    1159 
    1160         for (i=0; i < file2->i_listlen; i++)
    1161                 if (file2->i_merged[i]==FALSE)
    1162                         return 0;
    1163 
    1164         {
    1165                 int first1 = 0;
    1166                 int last1 = file1->i_ndefs - 1;
    1167 
    1168                 int first2 = 0;
    1169                 int last2 = file2->i_ndefs - 1;
    1170 
    1171                 int first=0;
    1172                 struct symtab** i_defs = NULL;
    1173                 int deflen=file1->i_ndefs+file2->i_ndefs;
    1174 
    1175                 debug(2,("merging %s into %s\n",
    1176                         file2->i_file, file1->i_file));
    1177 
    1178                 if (deflen>0)
    1179                 {
    1180                         /* make sure deflen % SYMTABINC == 0 is still true */
    1181                         deflen += (SYMTABINC - deflen % SYMTABINC) % SYMTABINC;
    1182                         i_defs=(struct symtab**)
    1183                             malloc(deflen*sizeof(struct symtab*));
    1184                         if (i_defs==NULL) return 0;
    1185                 }
    1186 
    1187                 while ((last1 >= first1) && (last2 >= first2))
    1188                 {
    1189                         char *s1=file1->i_defs[first1]->s_name;
    1190                         char *s2=file2->i_defs[first2]->s_name;
    1191 
    1192                         if (strcmp(s1,s2) < 0)
    1193                                 i_defs[first++]=file1->i_defs[first1++];
    1194                         else if (strcmp(s1,s2) > 0)
    1195                                 i_defs[first++]=file2->i_defs[first2++];
    1196                         else /* equal */
    1197                         {
    1198                                 i_defs[first++]=file2->i_defs[first2++];
    1199                                 first1++;
    1200                         }
    1201                 }
    1202                 while (last1 >= first1)
    1203                 {
    1204                         i_defs[first++]=file1->i_defs[first1++];
    1205                 }
    1206                 while (last2 >= first2)
    1207                 {
    1208                         i_defs[first++]=file2->i_defs[first2++];
    1209                 }
    1210 
    1211                 if (file1->i_defs) free(file1->i_defs);
    1212                 file1->i_defs=i_defs;
    1213                 file1->i_ndefs=first;
    1214 
    1215                 return 1;
    1216         }
    1217 }
    1218 
    1219 void
    1220 undefine(char *symbol, struct inclist *file)
    1221 {
    1222         register struct symtab **ptr;
    1223         struct inclist *srcfile;
    1224         while ((ptr = isdefined(symbol, file, &srcfile)) != NULL)
    1225         {
    1226             srcfile->i_ndefs--;
    1227             for (; ptr < srcfile->i_defs + srcfile->i_ndefs; ptr++)
    1228                 *ptr = ptr[1];
    1229         }
    1230 }
    1231 
    1232 int
    1233 find_includes(struct filepointer *filep, struct inclist *file,
    1234               struct inclist *file_red, int recursion, boolean failOK)
    1235 {
    1236         struct inclist  *inclistp;
    1237         char            **includedirsp;
    1238         register char   *line;
    1239         register int    type;
    1240         boolean recfailOK;
    1241 
    1242         while ((line = getnextline(filep))) {
    1243                 switch(type = deftype(line, filep, file_red, file, TRUE)) {
    1244                 case IF:
    1245                 doif:
    1246                         type = find_includes(filep, file,
    1247                                 file_red, recursion+1, failOK);
    1248                         while ((type == ELIF) || (type == ELIFFALSE) ||
    1249                                (type == ELIFGUESSFALSE))
    1250                                 type = gobble(filep, file, file_red);
    1251                         if (type == ELSE)
    1252                                 gobble(filep, file, file_red);
    1253                         break;
    1254                 case IFFALSE:
    1255                 case IFGUESSFALSE:
    1256                     doiffalse:
    1257                         if (type == IFGUESSFALSE || type == ELIFGUESSFALSE)
    1258                             recfailOK = TRUE;
    1259                         else
    1260                             recfailOK = failOK;
    1261                         type = gobble(filep, file, file_red);
    1262                         if (type == ELSE)
    1263                             find_includes(filep, file,
    1264                                           file_red, recursion+1, recfailOK);
    1265                         else
    1266                         if (type == ELIF)
    1267                             goto doif;
    1268                         else
    1269                         if ((type == ELIFFALSE) || (type == ELIFGUESSFALSE))
    1270                             goto doiffalse;
    1271                         break;
    1272                 case IFDEF:
    1273                 case IFNDEF:
    1274                         if ((type == IFDEF && isdefined(line, file_red, NULL))
    1275                          || (type == IFNDEF && !isdefined(line, file_red, NULL))) {
    1276                                 debug(1,(type == IFNDEF ?
    1277                                     "line %d: %s !def'd in %s via %s%s\n" : "",
    1278                                     filep->f_line, line,
    1279                                     file->i_file, file_red->i_file, ": doit"));
    1280                                 type = find_includes(filep, file,
    1281                                         file_red, recursion+1, failOK);
    1282                                 while (type == ELIF || type == ELIFFALSE || type == ELIFGUESSFALSE)
    1283                                         type = gobble(filep, file, file_red);
    1284                                 if (type == ELSE)
    1285                                         gobble(filep, file, file_red);
    1286                         }
    1287                         else {
    1288                                 debug(1,(type == IFDEF ?
    1289                                     "line %d: %s !def'd in %s via %s%s\n" : "",
    1290                                     filep->f_line, line,
    1291                                     file->i_file, file_red->i_file, ": gobble"));
    1292                                 type = gobble(filep, file, file_red);
    1293                                 if (type == ELSE)
    1294                                         find_includes(filep, file,
    1295                                                 file_red, recursion+1, failOK);
    1296                                 else if (type == ELIF)
    1297                                         goto doif;
    1298                                 else if (type == ELIFFALSE || type == ELIFGUESSFALSE)
    1299                                         goto doiffalse;
    1300                         }
    1301                         break;
    1302                 case ELSE:
    1303                 case ELIFFALSE:
    1304                 case ELIFGUESSFALSE:
    1305                 case ELIF:
    1306                         if (!recursion)
    1307                                 gobble(filep, file, file_red);
    1308                 case ENDIF:
    1309                         if (recursion)
    1310                                 return(type);
    1311                 case DEFINE:
    1312                         define(line, file);
    1313                         break;
    1314                 case UNDEF:
    1315                         if (!*line) {
    1316                             warning("%s", file_red->i_file);
    1317                             if (file_red != file)
    1318                                 warning1(" (reading %s)", file->i_file);
    1319                             warning1(", line %d: incomplete undef == \"%s\"\n",
    1320                                 filep->f_line, line);
    1321                             break;
    1322                         }
    1323                         undefine(line, file_red);
    1324                         break;
    1325                 case INCLUDE:
    1326                 case INCLUDEDOT:
    1327                 case INCLUDENEXT:
    1328                 case INCLUDENEXTDOT:
    1329                         inclistp = inclistnext;
    1330                         includedirsp = includedirsnext;
    1331                         debug(2,("%s, reading %s, includes %s\n",
    1332                                 file_red->i_file, file->i_file, line));
    1333                         add_include(filep, file, file_red, line, type, failOK);
    1334                         inclistnext = inclistp;
    1335                         includedirsnext = includedirsp;
    1336                         break;
    1337                 case ERROR:
    1338                 case WARNING:
    1339                         warning("%s", file_red->i_file);
    1340                         if (file_red != file)
    1341                                 warning1(" (reading %s)", file->i_file);
    1342                         warning1(", line %d: %s\n",
    1343                                  filep->f_line, line);
    1344                         break;
    1345 
    1346                 case PRAGMA:
    1347                 case IDENT:
    1348                 case SCCS:
    1349                 case EJECT:
    1350                         break;
    1351                 case -1:
    1352                         warning("%s", file_red->i_file);
    1353                         if (file_red != file)
    1354                             warning1(" (reading %s)", file->i_file);
    1355                         warning1(", line %d: unknown directive == \"%s\"\n",
    1356                                  filep->f_line, line);
    1357                         break;
    1358                 case -2:
    1359                         warning("%s", file_red->i_file);
    1360                         if (file_red != file)
    1361                             warning1(" (reading %s)", file->i_file);
    1362                         warning1(", line %d: incomplete include == \"%s\"\n",
    1363                                  filep->f_line, line);
    1364                         break;
    1365                 }
    1366         }
    1367         file->i_flags |= FINISHED;
    1368         debug(2,("finished with %s\n", file->i_file));
    1369         return(-1);
    1370 }
  • ifparser.c

     
    546546{
    547547    return parse_cond (g, cp, valp);
    548548}
    549 /*
    550  * Copyright 1992 Network Computing Devices, Inc.
    551  *
    552  * Permission to use, copy, modify, and distribute this software and its
    553  * documentation for any purpose and without fee is hereby granted, provided
    554  * that the above copyright notice appear in all copies and that both that
    555  * copyright notice and this permission notice appear in supporting
    556  * documentation, and that the name of Network Computing Devices may not be
    557  * used in advertising or publicity pertaining to distribution of the software
    558  * without specific, written prior permission.  Network Computing Devices makes
    559  * no representations about the suitability of this software for any purpose.
    560  * It is provided ``as is'' without express or implied warranty.
    561  *
    562  * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
    563  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
    564  * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
    565  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    566  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
    567  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    568  * PERFORMANCE OF THIS SOFTWARE.
    569  *
    570  * Author:  Jim Fulton
    571  *          Network Computing Devices, Inc.
    572  *
    573  * Simple if statement processor
    574  *
    575  * This module can be used to evaluate string representations of C language
    576  * if constructs.  It accepts the following grammar:
    577  *
    578  *     EXPRESSION       :=      VALUE
    579  *                       |      VALUE  BINOP    EXPRESSION
    580  *                       |      VALUE   '?'     EXPRESSION ':'  EXPRESSION
    581  *
    582  *     VALUE            :=      '('  EXPRESSION  ')'
    583  *                       |      '!'  VALUE
    584  *                       |      '-'  VALUE
    585  *                       |      '+'  VALUE
    586  *                       |      '~'  VALUE
    587  *                       |      'defined'  '('  variable  ')'
    588  *                       |      'defined'  variable
    589  *                       |      # variable '(' variable-list ')'
    590  *                       |      variable
    591  *                       |      number
    592  *
    593  *     BINOP            :=      '*'     |  '/'  |  '%'
    594  *                       |      '+'     |  '-'
    595  *                       |      '<<'    |  '>>'
    596  *                       |      '<'     |  '>'  |  '<='  |  '>='
    597  *                       |      '=='    |  '!='
    598  *                       |      '&'     |  '^'  |  '|'
    599  *                       |      '&&'    |  '||'
    600  *
    601  * The normal C order of precedence is supported.
    602  *
    603  *
    604  * External Entry Points:
    605  *
    606  *     ParseIfExpression                parse a string for #if
    607  */
    608 
    609 /* $Header: /code/makedepend/ifparser.c,v 1.2 2004/04/20 19:50:26 doj Exp $ */
    610 
    611 #include "ifparser.h"
    612 #include <ctype.h>
    613 #include <stdlib.h>
    614 #include <string.h>
    615 
    616 /****************************************************************************
    617                    Internal Macros and Utilities for Parser
    618  ****************************************************************************/
    619 
    620 #define DO(val) if (!(val)) return NULL
    621 #define CALLFUNC(ggg,fff) (*((ggg)->funcs.fff))
    622 #define SKIPSPACE(ccc) while (isspace(*ccc)) ccc++
    623 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
    624 
    625 
    626 static const char *
    627 parse_variable (IfParser *g, const char *cp, const char **varp)
    628 {
    629     SKIPSPACE (cp);
    630 
    631     if (!isvarfirstletter (*cp))
    632         return CALLFUNC(g, handle_error) (g, cp, "variable name");
    633 
    634     *varp = cp;
    635     /* EMPTY */
    636     for (cp++; isalnum(*cp) || *cp == '_'; cp++) ;
    637     return cp;
    638 }
    639 
    640 
    641 static const char *
    642 parse_number (IfParser *g, const char *cp, long *valp)
    643 {
    644     long base = 10;
    645     SKIPSPACE (cp);
    646 
    647     if (!isdigit(*cp))
    648         return CALLFUNC(g, handle_error) (g, cp, "number");
    649 
    650     *valp = 0;
    651 
    652     if (*cp == '0') {
    653         cp++;
    654         if ((*cp == 'x') || (*cp == 'X')) {
    655             base = 16;
    656             cp++;
    657         } else {
    658             base = 8;
    659         }
    660     }
    661 
    662     /* Ignore overflows and assume ASCII, what source is usually written in */
    663     while (1) {
    664         int increment = -1;
    665         if (base == 8) {
    666             if ((*cp >= '0') && (*cp <= '7'))
    667                 increment = *cp++ - '0';
    668         } else if (base == 16) {
    669             if ((*cp >= '0') && (*cp <= '9'))
    670                 increment = *cp++ - '0';
    671             else if ((*cp >= 'A') &&  (*cp <= 'F'))
    672                 increment = *cp++ - ('A' - 10);
    673             else if ((*cp >= 'a') && (*cp <= 'f'))
    674                 increment = *cp++ - ('a' - 10);
    675         } else {        /* Decimal */
    676             if ((*cp >= '0') && (*cp <= '9'))
    677                 increment = *cp++ - '0';
    678         }
    679         if (increment < 0)
    680             break;
    681         *valp = (*valp * base) + increment;
    682     }
    683 
    684     /* Skip trailing qualifiers */
    685     while (*cp == 'U' || *cp == 'u' || *cp == 'L' || *cp == 'l') cp++;
    686     return cp;
    687 }
    688 
    689 static const char *
    690 parse_character (IfParser *g, const char *cp, long *valp)
    691 {
    692     char val;
    693 
    694     SKIPSPACE (cp);
    695     if (*cp == '\\')
    696         switch (cp[1]) {
    697         case 'n': val = '\n'; break;
    698         case 't': val = '\t'; break;
    699         case 'v': val = '\v'; break;
    700         case 'b': val = '\b'; break;
    701         case 'r': val = '\r'; break;
    702         case 'f': val = '\f'; break;
    703         case 'a': val = '\a'; break;
    704         case '\\': val = '\\'; break;
    705         case '?': val = '\?'; break;
    706         case '\'': val = '\''; break;
    707         case '\"': val = '\"'; break;
    708         case 'x': val = (char) strtol (cp + 2, NULL, 16); break;
    709         default: val = (char) strtol (cp + 1, NULL, 8); break;
    710         }
    711     else
    712         val = *cp;
    713     while (*cp != '\'') cp++;
    714     *valp = (long) val;
    715     return cp;
    716 }
    717 
    718 static const char *
    719 parse_value (IfParser *g, const char *cp, long *valp)
    720 {
    721     const char *var, *varend;
    722 
    723     *valp = 0;
    724 
    725     SKIPSPACE (cp);
    726     if (!*cp)
    727         return cp;
    728 
    729     switch (*cp) {
    730       case '(':
    731         DO (cp = ParseIfExpression (g, cp + 1, valp));
    732         SKIPSPACE (cp);
    733         if (*cp != ')')
    734             return CALLFUNC(g, handle_error) (g, cp, ")");
    735 
    736         return cp + 1;                  /* skip the right paren */
    737 
    738       case '!':
    739         DO (cp = parse_value (g, cp + 1, valp));
    740         *valp = !(*valp);
    741         return cp;
    742 
    743       case '-':
    744         DO (cp = parse_value (g, cp + 1, valp));
    745         *valp = -(*valp);
    746         return cp;
    747 
    748       case '+':
    749         DO (cp = parse_value (g, cp + 1, valp));
    750         return cp;
    751 
    752       case '~':
    753         DO (cp = parse_value (g, cp + 1, valp));
    754         *valp = ~(*valp);
    755         return cp;
    756 
    757       case '#':
    758         DO (cp = parse_variable (g, cp + 1, &var));
    759         SKIPSPACE (cp);
    760         if (*cp != '(')
    761             return CALLFUNC(g, handle_error) (g, cp, "(");
    762         do {
    763             DO (cp = parse_variable (g, cp + 1, &var));
    764             SKIPSPACE (cp);
    765         } while (*cp && *cp != ')');
    766         if (*cp != ')')
    767             return CALLFUNC(g, handle_error) (g, cp, ")");
    768         *valp = 1; /* XXX */
    769         return cp + 1;
    770 
    771       case '\'':
    772         DO (cp = parse_character (g, cp + 1, valp));
    773         if (*cp != '\'')
    774             return CALLFUNC(g, handle_error) (g, cp, "'");
    775         return cp + 1;
    776 
    777       case 'd':
    778         if (strncmp (cp, "defined", 7) == 0 && !isalnum(cp[7])) {
    779             int paren = 0;
    780             int len;
    781 
    782             cp += 7;
    783             SKIPSPACE (cp);
    784             if (*cp == '(') {
    785                 paren = 1;
    786                 cp++;
    787             }
    788             DO (cp = parse_variable (g, cp, &var));
    789             len = cp - var;
    790             SKIPSPACE (cp);
    791             if (paren && *cp != ')')
    792                 return CALLFUNC(g, handle_error) (g, cp, ")");
    793             *valp = (*(g->funcs.eval_defined)) (g, var, len);
    794             return cp + paren;          /* skip the right paren */
    795         }
    796         /* fall out */
    797     }
    798 
    799     if (isdigit(*cp)) {
    800         DO (cp = parse_number (g, cp, valp));
    801     } else if (!isvarfirstletter(*cp))
    802         return CALLFUNC(g, handle_error) (g, cp, "variable or number");
    803     else {
    804         DO (cp = parse_variable (g, cp, &var));
    805         varend = cp;
    806         SKIPSPACE(cp);
    807         if (*cp != '(') {
    808             *valp = (*(g->funcs.eval_variable)) (g, var, varend - var);
    809         } else {
    810             do {
    811                 long dummy;
    812                 DO (cp = ParseIfExpression (g, cp + 1, &dummy));
    813                 SKIPSPACE(cp);
    814                 if (*cp == ')')
    815                     break;
    816                 if (*cp != ',')
    817                     return CALLFUNC(g, handle_error) (g, cp, ",");
    818             } while (1);
    819 
    820             *valp = 1;  /* XXX */
    821             cp++;
    822         }
    823     }
    824    
    825     return cp;
    826 }
    827 
    828 
    829 
    830 static const char *
    831 parse_product (IfParser *g, const char *cp, long *valp)
    832 {
    833     long rightval;
    834 
    835     DO (cp = parse_value (g, cp, valp));
    836     SKIPSPACE (cp);
    837 
    838     switch (*cp) {
    839       case '*':
    840         DO (cp = parse_product (g, cp + 1, &rightval));
    841         *valp = (*valp * rightval);
    842         break;
    843 
    844       case '/':
    845         DO (cp = parse_product (g, cp + 1, &rightval));
    846         *valp = (*valp / rightval);
    847         break;
    848 
    849       case '%':
    850         DO (cp = parse_product (g, cp + 1, &rightval));
    851         *valp = (*valp % rightval);
    852         break;
    853     }
    854     return cp;
    855 }
    856 
    857 
    858 static const char *
    859 parse_sum (IfParser *g, const char *cp, long *valp)
    860 {
    861     long rightval;
    862 
    863     DO (cp = parse_product (g, cp, valp));
    864     SKIPSPACE (cp);
    865 
    866     switch (*cp) {
    867       case '+':
    868         DO (cp = parse_sum (g, cp + 1, &rightval));
    869         *valp = (*valp + rightval);
    870         break;
    871 
    872       case '-':
    873         DO (cp = parse_sum (g, cp + 1, &rightval));
    874         *valp = (*valp - rightval);
    875         break;
    876     }
    877     return cp;
    878 }
    879 
    880 
    881 static const char *
    882 parse_shift (IfParser *g, const char *cp, long *valp)
    883 {
    884     long rightval;
    885 
    886     DO (cp = parse_sum (g, cp, valp));
    887     SKIPSPACE (cp);
    888 
    889     switch (*cp) {
    890       case '<':
    891         if (cp[1] == '<') {
    892             DO (cp = parse_shift (g, cp + 2, &rightval));
    893             *valp = (*valp << rightval);
    894         }
    895         break;
    896 
    897       case '>':
    898         if (cp[1] == '>') {
    899             DO (cp = parse_shift (g, cp + 2, &rightval));
    900             *valp = (*valp >> rightval);
    901         }
    902         break;
    903     }
    904     return cp;
    905 }
    906 
    907 
    908 static const char *
    909 parse_inequality (IfParser *g, const char *cp, long *valp)
    910 {
    911     long rightval;
    912 
    913     DO (cp = parse_shift (g, cp, valp));
    914     SKIPSPACE (cp);
    915 
    916     switch (*cp) {
    917       case '<':
    918         if (cp[1] == '=') {
    919             DO (cp = parse_inequality (g, cp + 2, &rightval));
    920             *valp = (*valp <= rightval);
    921         } else {
    922             DO (cp = parse_inequality (g, cp + 1, &rightval));
    923             *valp = (*valp < rightval);
    924         }
    925         break;
    926 
    927       case '>':
    928         if (cp[1] == '=') {
    929             DO (cp = parse_inequality (g, cp + 2, &rightval));
    930             *valp = (*valp >= rightval);
    931         } else {
    932             DO (cp = parse_inequality (g, cp + 1, &rightval));
    933             *valp = (*valp > rightval);
    934         }
    935         break;
    936     }
    937     return cp;
    938 }
    939 
    940 
    941 static const char *
    942 parse_equality (IfParser *g, const char *cp, long *valp)
    943 {
    944     long rightval;
    945 
    946     DO (cp = parse_inequality (g, cp, valp));
    947     SKIPSPACE (cp);
    948 
    949     switch (*cp) {
    950       case '=':
    951         if (cp[1] == '=')
    952             cp++;
    953         DO (cp = parse_equality (g, cp + 1, &rightval));
    954         *valp = (*valp == rightval);
    955         break;
    956 
    957       case '!':
    958         if (cp[1] != '=')
    959             break;
    960         DO (cp = parse_equality (g, cp + 2, &rightval));
    961         *valp = (*valp != rightval);
    962         break;
    963     }
    964     return cp;
    965 }
    966 
    967 
    968 static const char *
    969 parse_band (IfParser *g, const char *cp, long *valp)
    970 {
    971     long rightval;
    972 
    973     DO (cp = parse_equality (g, cp, valp));
    974     SKIPSPACE (cp);
    975 
    976     switch (*cp) {
    977       case '&':
    978         if (cp[1] != '&') {
    979             DO (cp = parse_band (g, cp + 1, &rightval));
    980             *valp = (*valp & rightval);
    981         }
    982         break;
    983     }
    984     return cp;
    985 }
    986 
    987 
    988 static const char *
    989 parse_bxor (IfParser *g, const char *cp, long *valp)
    990 {
    991     long rightval;
    992 
    993     DO (cp = parse_band (g, cp, valp));
    994     SKIPSPACE (cp);
    995 
    996     switch (*cp) {
    997       case '^':
    998         DO (cp = parse_bxor (g, cp + 1, &rightval));
    999         *valp = (*valp ^ rightval);
    1000         break;
    1001     }
    1002     return cp;
    1003 }
    1004 
    1005 
    1006 static const char *
    1007 parse_bor (IfParser *g, const char *cp, long *valp)
    1008 {
    1009     long rightval;
    1010 
    1011     DO (cp = parse_bxor (g, cp, valp));
    1012     SKIPSPACE (cp);
    1013 
    1014     switch (*cp) {
    1015       case '|':
    1016         if (cp[1] != '|') {
    1017             DO (cp = parse_bor (g, cp + 1, &rightval));
    1018             *valp = (*valp | rightval);
    1019         }
    1020         break;
    1021     }
    1022     return cp;
    1023 }
    1024 
    1025 
    1026 static const char *
    1027 parse_land (IfParser *g, const char *cp, long *valp)
    1028 {
    1029     long rightval;
    1030 
    1031     DO (cp = parse_bor (g, cp, valp));
    1032     SKIPSPACE (cp);
    1033 
    1034     switch (*cp) {
    1035       case '&':
    1036         if (cp[1] != '&')
    1037             return CALLFUNC(g, handle_error) (g, cp, "&&");
    1038         DO (cp = parse_land (g, cp + 2, &rightval));
    1039         *valp = (*valp && rightval);
    1040         break;
    1041     }
    1042     return cp;
    1043 }
    1044 
    1045 
    1046 static const char *
    1047 parse_lor (IfParser *g, const char *cp, long *valp)
    1048 {
    1049     long rightval;
    1050 
    1051     DO (cp = parse_land (g, cp, valp));
    1052     SKIPSPACE (cp);
    1053 
    1054     switch (*cp) {
    1055       case '|':
    1056         if (cp[1] != '|')
    1057             return CALLFUNC(g, handle_error) (g, cp, "||");
    1058         DO (cp = parse_lor (g, cp + 2, &rightval));
    1059         *valp = (*valp || rightval);
    1060         break;
    1061     }
    1062     return cp;
    1063 }
    1064 
    1065 
    1066 static const char *
    1067 parse_cond(IfParser *g, const char *cp, long *valp)
    1068 {
    1069     long trueval, falseval;
    1070 
    1071     DO (cp = parse_lor (g, cp, valp));
    1072     SKIPSPACE (cp);
    1073 
    1074     switch (*cp) {
    1075       case '?':
    1076         DO (cp = parse_cond (g, cp + 1, &trueval));
    1077         SKIPSPACE (cp);
    1078         if (*cp != ':')
    1079             return CALLFUNC(g, handle_error) (g, cp, ":");
    1080         DO (cp = parse_cond (g, cp + 1, &falseval));
    1081         *valp = (*valp ? trueval : falseval);
    1082         break;
    1083     }
    1084     return cp;
    1085 }
    1086 
    1087 
    1088 /****************************************************************************
    1089                              External Entry Points
    1090  ****************************************************************************/
    1091 
    1092 const char *
    1093 ParseIfExpression (IfParser *g, const char *cp, long *valp)
    1094 {
    1095     return parse_cond (g, cp, valp);
    1096 }