LCOV - code coverage report
Current view: top level - libreoffice/soltools/cpp - _unix.c (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 84 42.9 %
Date: 2012-12-27 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 HAVE_GETOPT
      35             : extern int stgetopt(int, char *const *, const char *);
      36             : extern char *optarg;
      37             : extern int optind;
      38             : #else
      39             : #include <getopt.h>
      40             : #endif
      41             : 
      42             : int Pflag = 0;                          /* print no line information */
      43             : int Iflag = 0;                          /* print includes */
      44             : int Mflag = 0;                          /* print macor expansion */
      45             : int Aflag = 0;                          /* translate character sets */
      46             : int Xflag = 0;                          /* print pragma for include/import */
      47             : int Vflag = 0;                          /* verbose flag */
      48             : int Cflag = 0;                          /* do not remove any comments */
      49             : int Dflag = 0;                          /* add parameter check to delete op */
      50             : int Cplusplus = 0;
      51             : 
      52             : extern void setup_kwtab(void);
      53             : 
      54             : void
      55          75 :     setup(int argc, char **argv)
      56             : {
      57             :     int c, fd, i, n;
      58             :     char *fp, *dp;
      59             :     Tokenrow tr;
      60             : 
      61          75 :     setup_kwtab();
      62             : #if defined MACOSX || defined(AIX) || !defined HAVE_GETOPT
      63             :     while ((c = stgetopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
      64             : #else
      65        3241 :     while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
      66             : #endif
      67        3091 :         switch (c)
      68             :         {
      69             :             case 'N':
      70           0 :                 for (i = 0; i < NINCLUDE; i++)
      71           0 :                     if (includelist[i].always == 1)
      72           0 :                         includelist[i].deleted = 1;
      73           0 :                 break;
      74             : 
      75             :             case 'I':
      76         378 :                 for (i = NINCLUDE - 2; i >= 0; i--)
      77             :                 {
      78         378 :                     if (includelist[i].file == NULL)
      79             :                     {
      80         201 :                         includelist[i].always = 1;
      81         201 :                         includelist[i].file = optarg;
      82         201 :                         break;
      83             :                     }
      84             :                 }
      85         201 :                 if (i < 0)
      86           0 :                     error(FATAL, "Too many -I directives");
      87         201 :                 break;
      88             : 
      89             :             case 'D':
      90             :             case 'U':
      91             :             case 'A':
      92        2740 :                 setsource("<cmdarg>", -1, -1, optarg, 0);
      93        2740 :                 maketokenrow(3, &tr);
      94        2740 :                 gettokens(&tr, 1);
      95        2740 :                 doadefine(&tr, c);
      96        2740 :                 unsetsource();
      97        2740 :                 break;
      98             : 
      99             :             case 'P':                   /* Lineinfo */
     100          75 :                 Pflag++;
     101          75 :                 break;
     102             : 
     103             :             case 'V':
     104           0 :                 for (n = 0; (c = optarg[n]) != '\0'; n++)
     105           0 :                     switch (c)
     106             :                     {
     107             :                         case 'i':
     108           0 :                             Iflag++;
     109           0 :                             break;
     110             : 
     111             :                         case 'm':
     112           0 :                             Mflag = 1;
     113           0 :                             break;
     114             : 
     115             :                         case 'x':
     116           0 :                             Mflag = 2;
     117           0 :                             break;
     118             : 
     119             :                         case 't':
     120           0 :                             Vflag++;
     121           0 :                             break;
     122             : 
     123             :                         case 'v':
     124           0 :                             fprintf(stderr, "%s\n", argv[0]);
     125           0 :                             break;
     126             : 
     127             :                         default:
     128           0 :                             error(WARNING, "Unknown verbose option %c", c);
     129             :                     }
     130           0 :                 break;
     131             : 
     132             :             case 'X':
     133           0 :                 for (n = 0; (c = optarg[n]) != '\0'; n++)
     134           0 :                     switch (c)
     135             :                     {
     136             :                         case 'a':
     137           0 :                             Aflag++;
     138           0 :                             break;
     139             : 
     140             :                         case 'i':
     141           0 :                             Xflag++;
     142           0 :                             break;
     143             : 
     144             :                         case 'c':
     145           0 :                             Cflag++;
     146           0 :                             break;
     147             : 
     148             :                         case 'd':
     149           0 :                             Dflag++;
     150           0 :                             break;
     151             : 
     152             :                         case 'w':
     153           0 :                             dp = &optarg[n + 1];
     154           0 :                             n += (int)strlen(dp);
     155           0 :                             while (isspace(*dp)) dp++;
     156             : 
     157           0 :                             for (i = NINCLUDE - 1; i >= 0; i--)
     158             :                             {
     159           0 :                                 if (wraplist[i].file == NULL)
     160             :                                 {
     161           0 :                                     wraplist[i].file = dp;
     162           0 :                                     break;
     163             :                                 }
     164             :                             }
     165           0 :                             if (i < 0)
     166           0 :                                 error(WARNING, "Too many -Xw directives");
     167           0 :                             break;
     168             : 
     169             :                         default:
     170           0 :                             error(WARNING, "Unknown extension option %c", c);
     171             :                     }
     172           0 :                 break;
     173             : 
     174             :             case '+':
     175          75 :                 Cplusplus++;
     176          75 :                 break;
     177             : 
     178             :             case 'u':                   /* -undef fuer GCC (dummy) */
     179             :             case 'l':                   /* -lang-c++ fuer GCC (dummy) */
     180           0 :                 break;
     181             : 
     182             :             default:
     183           0 :                 break;
     184             :         }
     185          75 :     dp = ".";
     186          75 :     fp = "<stdin>";
     187          75 :     fd = 0;
     188          75 :     if (optind < argc)
     189             :     {
     190          75 :         if ((fp = strrchr(argv[optind], '/')) != NULL)
     191             :         {
     192          75 :             int len = (int)(fp - argv[optind]);
     193             : 
     194          75 :             dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
     195          75 :             dp[len] = '\0';
     196             :         }
     197          75 :         fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
     198          75 :         if ((fd = open(fp, O_RDONLY)) <= 0)
     199           0 :             error(FATAL, "Can't open input file %s", fp);
     200             :     }
     201             : 
     202          75 :     if (optind + 1 < argc)
     203             :     {
     204           0 :         int fdo = creat(argv[optind + 1], 0666);
     205             : 
     206           0 :         if (fdo < 0)
     207           0 :             error(FATAL, "Can't open output file %s", argv[optind + 1]);
     208             : 
     209           0 :         dup2(fdo, 1);
     210             :     }
     211          75 :     includelist[NINCLUDE - 1].always = 0;
     212          75 :     includelist[NINCLUDE - 1].file = dp;
     213          75 :     setsource(fp, -1, fd, NULL, 0);
     214          75 : }
     215             : 
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10