LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - cppuoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 158 39.9 %
Date: 2012-08-25 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 67 216 31.0 %

           Branch data     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 <string.h>
      22                 :            : 
      23                 :            : #include "cppuoptions.hxx"
      24                 :            : #include "osl/thread.h"
      25                 :            : #include "osl/process.h"
      26                 :            : 
      27                 :            : using ::rtl::OUString;
      28                 :            : using ::rtl::OUStringToOString;
      29                 :            : using ::rtl::OString;
      30                 :            : 
      31                 :            : #ifdef SAL_UNX
      32                 :            : #define SEPARATOR '/'
      33                 :            : #else
      34                 :            : #define SEPARATOR '\\'
      35                 :            : #endif
      36                 :            : 
      37                 :         44 : sal_Bool CppuOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
      38                 :            :     throw( IllegalArgument )
      39                 :            : {
      40                 :         44 :     sal_Bool    ret = sal_True;
      41                 :         44 :     sal_uInt16  i=0;
      42                 :            : 
      43         [ +  + ]:         44 :     if (!bCmdFile)
      44                 :            :     {
      45                 :         22 :         bCmdFile = sal_True;
      46                 :            : 
      47                 :         22 :         OString name(av[0]);
      48                 :         22 :         sal_Int32 index = name.lastIndexOf(SEPARATOR);
      49         [ +  - ]:         22 :         m_program = name.copy((index > 0 ? index+1 : 0));
      50                 :            : 
      51         [ -  + ]:         22 :         if (ac < 2)
      52                 :            :         {
      53 [ #  # ][ #  # ]:          0 :             fprintf(stderr, "%s", prepareHelp().getStr());
      54                 :          0 :             ret = sal_False;
      55                 :            :         }
      56                 :            : 
      57                 :         22 :         i = 1;
      58                 :            :     } else
      59                 :            :     {
      60                 :         22 :         i = 0;
      61                 :            :     }
      62                 :            : 
      63                 :         44 :     char    *s=NULL;
      64         [ +  + ]:        194 :     for( ; i < ac; i++)
      65                 :            :     {
      66         [ +  + ]:        150 :         if (av[i][0] == '-')
      67                 :            :         {
      68   [ +  +  +  +  :        106 :             switch (av[i][1])
             +  +  +  - ]
      69                 :            :             {
      70                 :            :                 case 'O':
      71         [ -  + ]:         22 :                     if (av[i][2] == '\0')
      72                 :            :                     {
      73 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      74                 :            :                         {
      75                 :          0 :                             i++;
      76                 :          0 :                             s = av[i];
      77                 :            :                         } else
      78                 :            :                         {
      79                 :          0 :                             OString tmp("'-O', please check");
      80         [ #  # ]:          0 :                             if (i <= ac - 1)
      81                 :            :                             {
      82                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
      83                 :            :                             }
      84                 :            : 
      85                 :          0 :                             throw IllegalArgument(tmp);
      86                 :            :                         }
      87                 :            :                     } else
      88                 :            :                     {
      89                 :         22 :                         s = av[i] + 2;
      90                 :            :                     }
      91                 :            : 
      92         [ +  - ]:         22 :                     m_options["-O"] = OString(s);
      93                 :         22 :                     break;
      94                 :            :                 case 'B':
      95         [ -  + ]:         22 :                     if (av[i][2] == '\0')
      96                 :            :                     {
      97 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      98                 :            :                         {
      99                 :          0 :                             i++;
     100                 :          0 :                             s = av[i];
     101                 :            :                         } else
     102                 :            :                         {
     103                 :          0 :                             OString tmp("'-B', please check");
     104         [ #  # ]:          0 :                             if (i <= ac - 1)
     105                 :            :                             {
     106                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     107                 :            :                             }
     108                 :            : 
     109                 :          0 :                             throw IllegalArgument(tmp);
     110                 :            :                         }
     111                 :            :                     } else
     112                 :            :                     {
     113                 :         22 :                         s = av[i] + 2;
     114                 :            :                     }
     115                 :            : 
     116         [ +  - ]:         22 :                     m_options["-B"] = OString(s);
     117                 :         22 :                     break;
     118                 :            :                 case 'T':
     119         [ -  + ]:          4 :                     if (av[i][2] == '\0')
     120                 :            :                     {
     121 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     122                 :            :                         {
     123                 :          0 :                             i++;
     124                 :          0 :                             s = av[i];
     125                 :            :                         } else
     126                 :            :                         {
     127                 :          0 :                             OString tmp("'-T', please check");
     128         [ #  # ]:          0 :                             if (i <= ac - 1)
     129                 :            :                             {
     130                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     131                 :            :                             }
     132                 :            : 
     133                 :          0 :                             throw IllegalArgument(tmp);
     134                 :            :                         }
     135                 :            :                     } else
     136                 :            :                     {
     137                 :          4 :                         s = av[i] + 2;
     138                 :            :                     }
     139                 :            : 
     140 [ +  - ][ +  + ]:          4 :                     if (m_options.count("-T") > 0)
     141                 :            :                     {
     142         [ +  - ]:          2 :                         OString tmp(m_options["-T"]);
     143                 :          2 :                         tmp = tmp + ";" + s;
     144         [ +  - ]:          2 :                         m_options["-T"] = tmp;
     145                 :            :                     } else
     146                 :            :                     {
     147         [ +  - ]:          2 :                         m_options["-T"] = OString(s);
     148                 :            :                     }
     149                 :          4 :                     break;
     150                 :            :                 case 'L':
     151         [ -  + ]:          8 :                     if (av[i][2] != '\0')
     152                 :            :                     {
     153                 :          0 :                         OString tmp("'-L', please check");
     154         [ #  # ]:          0 :                         if (i <= ac - 1)
     155                 :            :                         {
     156                 :          0 :                             tmp += " your input '" + OString(av[i]) + "'";
     157                 :            :                         }
     158                 :            : 
     159                 :          0 :                         throw IllegalArgument(tmp);
     160                 :            :                     }
     161                 :            : 
     162 [ +  - ][ +  - ]:          8 :                     if (isValid("-C") || isValid("-CS"))
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
           [ -  +  #  #  
          #  #  #  #  #  
                      # ]
     163                 :            :                     {
     164                 :          0 :                         OString tmp("'-L' could not be combined with '-C' or '-CS' option");
     165                 :          0 :                         throw IllegalArgument(tmp);
     166                 :            :                     }
     167         [ +  - ]:          8 :                     m_options["-L"] = OString("");
     168                 :          8 :                     break;
     169                 :            :                 case 'C':
     170         [ -  + ]:         12 :                     if (av[i][2] == 'S')
     171                 :            :                     {
     172         [ #  # ]:          0 :                         if (av[i][3] != '\0')
     173                 :            :                         {
     174                 :          0 :                             OString tmp("'-CS', please check");
     175         [ #  # ]:          0 :                             if (i <= ac - 1)
     176                 :            :                             {
     177                 :          0 :                                 tmp += " your input '" + OString(av[i]) + "'";
     178                 :            :                             }
     179                 :            : 
     180                 :          0 :                             throw IllegalArgument(tmp);
     181                 :            :                         }
     182                 :            : 
     183 [ #  # ][ #  # ]:          0 :                         if (isValid("-L") || isValid("-C"))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
          #  #  #  #  #  
                      # ]
     184                 :            :                         {
     185                 :          0 :                             OString tmp("'-CS' could not be combined with '-L' or '-C' option");
     186                 :          0 :                             throw IllegalArgument(tmp);
     187                 :            :                         }
     188         [ #  # ]:          0 :                         m_options["-CS"] = OString("");
     189                 :          0 :                         break;
     190                 :            :                     } else
     191         [ -  + ]:         12 :                     if (av[i][2] != '\0')
     192                 :            :                     {
     193                 :          0 :                         OString tmp("'-C', please check");
     194         [ #  # ]:          0 :                         if (i <= ac - 1)
     195                 :            :                         {
     196                 :          0 :                             tmp += " your input '" + OString(av[i]) + "'";
     197                 :            :                         }
     198                 :            : 
     199                 :          0 :                         throw IllegalArgument(tmp);
     200                 :            :                     }
     201                 :            : 
     202 [ +  - ][ +  - ]:         12 :                     if (isValid("-L") || isValid("-CS"))
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
           [ -  +  #  #  
          #  #  #  #  #  
                      # ]
     203                 :            :                     {
     204                 :          0 :                         OString tmp("'-C' could not be combined with '-L' or '-CS' option");
     205                 :          0 :                         throw IllegalArgument(tmp);
     206                 :            :                     }
     207         [ +  - ]:         12 :                     m_options["-C"] = OString("");
     208                 :         12 :                     break;
     209                 :            :                 case 'G':
     210         [ +  - ]:         20 :                     if (av[i][2] == 'c')
     211                 :            :                     {
     212         [ -  + ]:         20 :                         if (av[i][3] != '\0')
     213                 :            :                         {
     214                 :          0 :                             OString tmp("'-Gc', please check");
     215         [ #  # ]:          0 :                             if (i <= ac - 1)
     216                 :            :                             {
     217                 :          0 :                                 tmp += " your input '" + OString(av[i]) + "'";
     218                 :            :                             }
     219                 :            : 
     220                 :          0 :                             throw IllegalArgument(tmp);
     221                 :            :                         }
     222                 :            : 
     223         [ +  - ]:         20 :                         m_options["-Gc"] = OString("");
     224                 :         20 :                         break;
     225                 :            :                     } else
     226         [ #  # ]:          0 :                     if (av[i][2] != '\0')
     227                 :            :                     {
     228                 :          0 :                         OString tmp("'-G', please check");
     229         [ #  # ]:          0 :                         if (i <= ac - 1)
     230                 :            :                         {
     231                 :          0 :                             tmp += " your input '" + OString(av[i]) + "'";
     232                 :            :                         }
     233                 :            : 
     234                 :          0 :                         throw IllegalArgument(tmp);
     235                 :            :                     }
     236                 :            : 
     237         [ #  # ]:          0 :                     m_options["-G"] = OString("");
     238                 :          0 :                     break;
     239                 :            :                 case 'X': // support for eXtra type rdbs
     240                 :            :                 {
     241         [ -  + ]:         18 :                     if (av[i][2] == '\0')
     242                 :            :                     {
     243 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     244                 :            :                         {
     245                 :          0 :                             i++;
     246                 :          0 :                             s = av[i];
     247                 :            :                         } else
     248                 :            :                         {
     249                 :          0 :                             OString tmp("'-X', please check");
     250         [ #  # ]:          0 :                             if (i <= ac - 1)
     251                 :            :                             {
     252                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     253                 :            :                             }
     254                 :            : 
     255                 :          0 :                             throw IllegalArgument(tmp);
     256                 :            :                         }
     257                 :            :                     } else
     258                 :            :                     {
     259                 :         18 :                         s = av[i] + 2;
     260                 :            :                     }
     261                 :            : 
     262         [ +  - ]:         18 :                     m_extra_input_files.push_back( s );
     263                 :         18 :                     break;
     264                 :            :                 }
     265                 :            : 
     266                 :            :                 default:
     267                 :        106 :                     throw IllegalArgument("the option is unknown" + OString(av[i]));
     268                 :            :             }
     269                 :            :         } else
     270                 :            :         {
     271         [ +  + ]:         44 :             if (av[i][0] == '@')
     272                 :            :             {
     273         [ +  - ]:         22 :                 FILE* cmdFile = fopen(av[i]+1, "r");
     274         [ -  + ]:         22 :                   if( cmdFile == NULL )
     275                 :            :                   {
     276 [ #  # ][ #  # ]:          0 :                     fprintf(stderr, "%s", prepareHelp().getStr());
     277                 :          0 :                     ret = sal_False;
     278                 :            :                 } else
     279                 :            :                 {
     280                 :         22 :                     int rargc=0;
     281                 :            :                     char* rargv[512];
     282                 :            :                     char  buffer[512];
     283                 :            : 
     284 [ +  - ][ +  + ]:        150 :                     while ( fscanf(cmdFile, "%s", buffer) != EOF )
     285                 :            :                     {
     286                 :        128 :                         rargv[rargc]= strdup(buffer);
     287                 :        128 :                         rargc++;
     288                 :            :                     }
     289         [ +  - ]:         22 :                     fclose(cmdFile);
     290                 :            : 
     291         [ +  - ]:         22 :                     ret = initOptions(rargc, rargv, bCmdFile);
     292                 :            : 
     293         [ +  + ]:        150 :                     for (long j=0; j < rargc; j++)
     294                 :            :                     {
     295                 :        128 :                         free(rargv[j]);
     296                 :            :                     }
     297                 :            :                 }
     298                 :            :             } else
     299                 :            :             {
     300         [ +  - ]:         22 :                 if (bCmdFile)
     301                 :            :                 {
     302         [ +  - ]:         22 :                     m_inputFiles.push_back(av[i]);
     303                 :            :                 } else
     304                 :            :                 {
     305                 :          0 :                     OUString system_filepath;
     306         [ #  # ]:          0 :                     if (osl_getCommandArg( i-1, &system_filepath.pData )
     307                 :            :                         != osl_Process_E_None)
     308                 :            :                     {
     309                 :            :                         OSL_ASSERT(false);
     310                 :            :                     }
     311 [ #  # ][ #  # ]:          0 :                     m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding()));
                 [ #  # ]
     312                 :            :                 }
     313                 :            :             }
     314                 :            :         }
     315                 :            :     }
     316                 :            : 
     317                 :         44 :     return ret;
     318                 :            : }
     319                 :            : 
     320                 :          0 : OString CppuOptions::prepareHelp()
     321                 :            : {
     322                 :          0 :     OString help("\nusing: ");
     323                 :          0 :     help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
     324                 :          0 :     help += "    -O<path>   = path describes the root directory for the generated output.\n";
     325                 :          0 :     help += "                 The output directory tree is generated under this directory.\n";
     326                 :          0 :     help += "    -T<name>   = name specifies a type or a list of types. The output for this\n";
     327                 :          0 :     help += "      [t1;...]   type is generated. If no '-T' option is specified,\n";
     328                 :          0 :     help += "                 then output for all types is generated.\n";
     329                 :          0 :     help += "                 Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
     330                 :          0 :     help += "    -B<name>   = name specifies the base node. All types are searched under this\n";
     331                 :          0 :     help += "                 node. Default is the root '/' of the registry files.\n";
     332                 :          0 :     help += "    -L         = UNO type functions are generated lightweight, that means only\n";
     333                 :          0 :     help += "                 the name and typeclass are given and everything else is retrieved\n";
     334                 :          0 :     help += "                 from the type library dynamically. The default is that UNO type\n";
     335                 :          0 :     help += "                 functions provides enough type information for boostrapping C++.\n";
     336                 :          0 :     help += "                 '-L' should be the default for external components.\n";
     337                 :          0 :     help += "    -C         = UNO type functions are generated comprehensive that means all\n";
     338                 :          0 :     help += "                 necessary information is available for bridging the type in UNO.\n";
     339                 :          0 :     help += "    -G         = generate only target files which does not exists.\n";
     340                 :          0 :     help += "    -Gc        = generate only target files which content will be changed.\n";
     341                 :          0 :     help += "    -X<file>   = extra types which will not be taken into account for generation.\n\n";
     342         [ #  # ]:          0 :     help += prepareVersion();
     343                 :            : 
     344                 :          0 :     return help;
     345                 :            : }
     346                 :            : 
     347                 :          0 : OString CppuOptions::prepareVersion()
     348                 :            : {
     349                 :          0 :     OString version(m_program);
     350                 :          0 :     version += " Version 2.0\n\n";
     351                 :          0 :     return version;
     352                 :            : }
     353                 :            : 
     354                 :            : 
     355                 :            : 
     356                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10