LCOV - code coverage report
Current view: top level - soltools/mkdepend - cppsetup.c (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 35 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* $XConsortium: cppsetup.c,v 1.13 94/04/17 20:10:32 gildea Exp $ */
       3             : /*
       4             : 
       5             : Copyright (c) 1993, 1994  X Consortium
       6             : 
       7             : Permission is hereby granted, free of charge, to any person obtaining a copy
       8             : of this software and associated documentation files (the "Software"), to deal
       9             : in the Software without restriction, including without limitation the rights
      10             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      11             : copies of the Software, and to permit persons to whom the Software is
      12             : furnished to do so, subject to the following conditions:
      13             : 
      14             : The above copyright notice and this permission notice shall be included in
      15             : all copies or substantial portions of the Software.
      16             : 
      17             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      18             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      19             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
      20             : X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
      21             : AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
      22             : CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      23             : 
      24             : Except as contained in this notice, the name of the X Consortium shall not be
      25             : used in advertising or otherwise to promote the sale, use or other dealings
      26             : in this Software without prior written authorization from the X Consortium.
      27             : 
      28             : */
      29             : 
      30             : #include "def.h"
      31             : 
      32             : #ifdef  CPP
      33             : /*
      34             :  * This file is strictly for the sake of cpy.y and yylex.c (if
      35             :  * you indeed have the source for cpp).
      36             :  */
      37             : #define IB 1
      38             : #define SB 2
      39             : #define NB 4
      40             : #define CB 8
      41             : #define QB 16
      42             : #define WB 32
      43             : #define SALT '#'
      44             : #if pdp11 | vax | ns16000 | mc68000 | ibm032
      45             : #define COFF 128
      46             : #else
      47             : #define COFF 0
      48             : #endif
      49             : /*
      50             :  * These variables used by cpy.y and yylex.c
      51             :  */
      52             : extern char *outp, *inp, *newp, *pend;
      53             : extern char *ptrtab;
      54             : extern char fastab[];
      55             : extern char slotab[];
      56             : 
      57             : /*
      58             :  * cppsetup
      59             :  */
      60             : struct filepointer  *currentfile;
      61             : struct inclist      *currentinc;
      62             : 
      63             : cppsetup(line, filep, inc)
      64             :     register char   *line;
      65             :     register struct filepointer *filep;
      66             :     register struct inclist     *inc;
      67             : {
      68             :     register char *p, savec;
      69             :     static boolean setupdone = FALSE;
      70             :     boolean value;
      71             : 
      72             :     if (!setupdone) {
      73             :         cpp_varsetup();
      74             :         setupdone = TRUE;
      75             :     }
      76             : 
      77             :     currentfile = filep;
      78             :     currentinc = inc;
      79             :     inp = newp = line;
      80             :     for (p=newp; *p; p++)
      81             :         ;
      82             : 
      83             :     /*
      84             :      * put a newline back on the end, and set up pend, etc.
      85             :      */
      86             :     *p++ = '\n';
      87             :     savec = *p;
      88             :     *p = '\0';
      89             :     pend = p;
      90             : 
      91             :     ptrtab = slotab+COFF;
      92             :     *--inp = SALT;
      93             :     outp=inp;
      94             :     value = yyparse();
      95             :     *p = savec;
      96             :     return(value);
      97             : }
      98             : 
      99             : pperror(tag, x0,x1,x2,x3,x4)
     100             :     int tag,x0,x1,x2,x3,x4;
     101             : {
     102             :     warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
     103             :     warning(x0,x1,x2,x3,x4);
     104             : }
     105             : 
     106             : 
     107             : yyerror(s)
     108             :     register char   *s;
     109             : {
     110             :     fatalerr("Fatal error: %s\n", s);
     111             : }
     112             : #else /* not CPP */
     113             : 
     114             : #include "ifparser.h"
     115             : struct _parse_data {
     116             :     struct filepointer *filep;
     117             :     struct inclist *inc;
     118             :     const char *line;
     119             : };
     120             : 
     121             : static const char *
     122           0 : _my_if_errors (ip, cp, expecting)
     123             :     IfParser *ip;
     124             :     const char *cp;
     125             :     const char *expecting;
     126             : {
     127             : #ifdef DEBUG_MKDEPEND
     128             :     struct _parse_data *pd = (struct _parse_data *) ip->data;
     129             :     int lineno = pd->filep->f_line;
     130             :     char *filename = pd->inc->i_file;
     131             :     char prefix[300];
     132             :     int prefixlen;
     133             :     int i;
     134             : 
     135             :     sprintf (prefix, "\"%s\":%d", filename, lineno);
     136             :     prefixlen = strlen(prefix);
     137             :     fprintf (stderr, "%s:  %s", prefix, pd->line);
     138             :     i = cp - pd->line;
     139             :     if (i > 0 && pd->line[i-1] != '\n') {
     140             :     putc ('\n', stderr);
     141             :     }
     142             :     for (i += prefixlen + 3; i > 0; i--) {
     143             :     putc (' ', stderr);
     144             :     }
     145             :     fprintf (stderr, "^--- expecting %s\n", expecting);
     146             : #endif /* DEBUG_MKDEPEND */
     147             :     (void)ip;
     148             :     (void)cp;
     149             :     (void)expecting;
     150           0 :     return NULL;
     151             : }
     152             : 
     153             : 
     154             : #define MAXNAMELEN 256
     155             : 
     156             : char *
     157           0 : _lookup_variable (var, len)
     158             :     const char *var;
     159             :     int len;
     160             : {
     161             :     char tmpbuf[MAXNAMELEN + 1];
     162             : 
     163           0 :     if (len > MAXNAMELEN)
     164           0 :         return 0;
     165             : 
     166           0 :     strncpy (tmpbuf, var, len);
     167           0 :     tmpbuf[len] = '\0';
     168           0 :     return isdefined(tmpbuf);
     169             : }
     170             : 
     171             : 
     172             : static int
     173           0 : _my_eval_defined (ip, var, len)
     174             :     IfParser *ip;
     175             :     const char *var;
     176             :     int len;
     177             : {
     178             :     (void)ip;
     179           0 :     if (_lookup_variable (var, len))
     180           0 :         return 1;
     181             :     else
     182           0 :         return 0;
     183             : }
     184             : 
     185             : #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
     186             : 
     187             : static int
     188           0 : _my_eval_variable (ip, var, len)
     189             :     IfParser *ip;
     190             :     const char *var;
     191             :     int len;
     192             : {
     193             :     char *s;
     194             : 
     195             :     (void)ip;
     196             : 
     197           0 :     s = _lookup_variable (var, len);
     198           0 :     if (!s)
     199           0 :         return 0;
     200             :     do {
     201           0 :     var = s;
     202           0 :     if (!isvarfirstletter(*var))
     203           0 :         break;
     204           0 :     s = _lookup_variable (var, strlen(var));
     205           0 :     } while (s);
     206             : 
     207           0 :     return atoi(var);
     208             : }
     209             : 
     210             : 
     211           0 : int cppsetup(line, filep, inc)
     212             :     register char   *line;
     213             :     register struct filepointer *filep;
     214             :     register struct inclist     *inc;
     215             : {
     216             :     IfParser ip;
     217             :     struct _parse_data pd;
     218           0 :     int val = 0;
     219             : 
     220           0 :     pd.filep = filep;
     221           0 :     pd.inc = inc;
     222           0 :     pd.line = line;
     223           0 :     ip.funcs.handle_error = _my_if_errors;
     224           0 :     ip.funcs.eval_defined = _my_eval_defined;
     225           0 :     ip.funcs.eval_variable = _my_eval_variable;
     226           0 :     ip.data = (char *) &pd;
     227             : 
     228           0 :     (void) ParseIfExpression (&ip, line, &val);
     229           0 :     if (val)
     230           0 :     return IF;
     231             :     else
     232           0 :     return IFFALSE;
     233             : }
     234             : #endif /* CPP */
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10