LCOV - code coverage report
Current view: top level - soltools/cpp - _unix.c (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 37 85 43.5 %
Date: 2014-11-03 Functions: 1 1 100.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             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : #include <stddef.h>
      22             : #include <stdlib.h>
      23             : #include <string.h>
      24             : #include <ctype.h>
      25             : #include <fcntl.h>
      26             : #if (defined(_WIN32) || defined(__IBMC__))
      27             : #include <io.h>
      28             : #else
      29             : #include <unistd.h>
      30             : #endif
      31             : 
      32             : #include "cpp.h"
      33             : 
      34             : #if defined MACOSX || defined AIX || defined WNT
      35             : #include <_getopt.h>
      36             : #else
      37             : #include <getopt.h>
      38             : #endif
      39             : 
      40             : int Pflag = 0;                          /* print no line information */
      41             : int Iflag = 0;                          /* print includes */
      42             : int Mflag = 0;                          /* print macor expansion */
      43             : int Aflag = 0;                          /* translate character sets */
      44             : int Xflag = 0;                          /* print pragma for include/import */
      45             : int Vflag = 0;                          /* verbose flag */
      46             : int Cflag = 0;                          /* do not remove any comments */
      47             : int Dflag = 0;                          /* add parameter check to delete op */
      48             : int Cplusplus = 0;
      49             : 
      50             : void
      51         112 :     setup(int argc, char **argv)
      52             : {
      53             :     int c, fd, i, n;
      54             :     char *fp, *dp;
      55             :     Tokenrow tr;
      56             : 
      57         112 :     setup_kwtab();
      58             : #if defined MACOSX || defined(AIX) || defined WNT
      59             :     while ((c = stgetopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
      60             : #else
      61        3404 :     while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
      62             : #endif
      63        3180 :         switch (c)
      64             :         {
      65             :             case 'N':
      66           0 :                 for (i = 0; i < NINCLUDE; i++)
      67           0 :                     if (includelist[i].always == 1)
      68           0 :                         includelist[i].deleted = 1;
      69           0 :                 break;
      70             : 
      71             :             case 'I':
      72        1520 :                 for (i = NINCLUDE - 2; i >= 0; i--)
      73             :                 {
      74        1520 :                     if (includelist[i].file == NULL)
      75             :                     {
      76         528 :                         includelist[i].always = 1;
      77         528 :                         includelist[i].file = optarg;
      78         528 :                         break;
      79             :                     }
      80             :                 }
      81         528 :                 if (i < 0)
      82           0 :                     error(FATAL, "Too many -I directives");
      83         528 :                 break;
      84             : 
      85             :             case 'D':
      86             :             case 'U':
      87             :             case 'A':
      88        2428 :                 setsource("<cmdarg>", -1, -1, optarg, 0);
      89        2428 :                 maketokenrow(3, &tr);
      90        2428 :                 gettokens(&tr, 1);
      91        2428 :                 doadefine(&tr, c);
      92        2428 :                 dofree(tr.bp);
      93        2428 :                 unsetsource();
      94        2428 :                 break;
      95             : 
      96             :             case 'P':                   /* Lineinfo */
      97         112 :                 Pflag++;
      98         112 :                 break;
      99             : 
     100             :             case 'V':
     101           0 :                 for (n = 0; (c = optarg[n]) != '\0'; n++)
     102           0 :                     switch (c)
     103             :                     {
     104             :                         case 'i':
     105           0 :                             Iflag++;
     106           0 :                             break;
     107             : 
     108             :                         case 'm':
     109           0 :                             Mflag = 1;
     110           0 :                             break;
     111             : 
     112             :                         case 'x':
     113           0 :                             Mflag = 2;
     114           0 :                             break;
     115             : 
     116             :                         case 't':
     117           0 :                             Vflag++;
     118           0 :                             break;
     119             : 
     120             :                         case 'v':
     121           0 :                             fprintf(stderr, "%s\n", argv[0]);
     122           0 :                             break;
     123             : 
     124             :                         default:
     125           0 :                             error(WARNING, "Unknown verbose option %c", c);
     126             :                     }
     127           0 :                 break;
     128             : 
     129             :             case 'X':
     130           0 :                 for (n = 0; (c = optarg[n]) != '\0'; n++)
     131           0 :                     switch (c)
     132             :                     {
     133             :                         case 'a':
     134           0 :                             Aflag++;
     135           0 :                             break;
     136             : 
     137             :                         case 'i':
     138           0 :                             Xflag++;
     139           0 :                             break;
     140             : 
     141             :                         case 'c':
     142           0 :                             Cflag++;
     143           0 :                             break;
     144             : 
     145             :                         case 'd':
     146           0 :                             Dflag++;
     147           0 :                             break;
     148             : 
     149             :                         case 'w':
     150           0 :                             dp = &optarg[n + 1];
     151           0 :                             n += (int)strlen(dp);
     152           0 :                             while (isspace(*dp)) dp++;
     153             : 
     154           0 :                             for (i = NINCLUDE - 1; i >= 0; i--)
     155             :                             {
     156           0 :                                 if (wraplist[i].file == NULL)
     157             :                                 {
     158           0 :                                     wraplist[i].file = dp;
     159           0 :                                     break;
     160             :                                 }
     161             :                             }
     162           0 :                             if (i < 0)
     163           0 :                                 error(WARNING, "Too many -Xw directives");
     164           0 :                             break;
     165             : 
     166             :                         default:
     167           0 :                             error(WARNING, "Unknown extension option %c", c);
     168             :                     }
     169           0 :                 break;
     170             : 
     171             :             case '+':
     172         112 :                 Cplusplus++;
     173         112 :                 break;
     174             : 
     175             :             case 'u':                   /* -undef fuer GCC (dummy) */
     176             :             case 'l':                   /* -lang-c++ fuer GCC (dummy) */
     177           0 :                 break;
     178             : 
     179             :             default:
     180           0 :                 break;
     181             :         }
     182         112 :     dp = ".";
     183         112 :     fp = "<stdin>";
     184         112 :     fd = 0;
     185         112 :     if (optind < argc)
     186             :     {
     187         112 :         if ((fp = strrchr(argv[optind], '/')) != NULL)
     188             :         {
     189         112 :             int len = (int)(fp - argv[optind]);
     190             : 
     191         112 :             dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
     192         112 :             dp[len] = '\0';
     193             :         }
     194         112 :         fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
     195         112 :         if ((fd = open(fp, O_RDONLY)) <= 0)
     196           0 :             error(FATAL, "Can't open input file %s", fp);
     197             :     }
     198             : 
     199         112 :     if (optind + 1 < argc)
     200             :     {
     201           0 :         int fdo = creat(argv[optind + 1], 0666);
     202             : 
     203           0 :         if (fdo < 0)
     204           0 :             error(FATAL, "Can't open output file %s", argv[optind + 1]);
     205             : 
     206           0 :         dup2(fdo, 1);
     207             :     }
     208         112 :     includelist[NINCLUDE - 1].always = 0;
     209         112 :     includelist[NINCLUDE - 1].file = dp;
     210         112 :     setsource(fp, -1, fd, NULL, 0);
     211         112 : }
     212             : 
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10