LCOV - code coverage report
Current view: top level - rdbmaker/source/rdbmaker - rdboptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 166 28.3 %
Date: 2012-08-25 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 149 24.2 %

           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                 :            : #include    <stdio.h>
      20                 :            : #include    <string.h>
      21                 :            : 
      22                 :            : #include    "rdboptions.hxx"
      23                 :            : 
      24                 :            : using ::rtl::OString;
      25                 :          4 : sal_Bool RdbOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
      26                 :            :     throw( IllegalArgument )
      27                 :            : {
      28                 :          4 :     sal_Bool    ret = sal_True;
      29                 :          4 :     sal_uInt16  i=0;
      30                 :            : 
      31         [ +  + ]:          4 :     if (!bCmdFile)
      32                 :            :     {
      33                 :          2 :         bCmdFile = sal_True;
      34                 :            : 
      35                 :          2 :         m_program = av[0];
      36                 :            : 
      37         [ -  + ]:          2 :         if (ac < 2)
      38                 :            :         {
      39 [ #  # ][ #  # ]:          0 :             fprintf(stderr, "%s", prepareHelp().getStr());
      40                 :          0 :             ret = sal_False;
      41                 :            :         }
      42                 :            : 
      43                 :          2 :         i = 1;
      44                 :            :     } else
      45                 :            :     {
      46                 :          2 :         i = 0;
      47                 :            :     }
      48                 :            : 
      49                 :          4 :     char    *s=NULL;
      50         [ +  + ]:        146 :     for (; i < ac; i++)
      51                 :            :     {
      52         [ +  + ]:        142 :         if (av[i][0] == '-')
      53                 :            :         {
      54   [ +  -  -  +  :        138 :             switch (av[i][1])
             +  +  -  -  
                      - ]
      55                 :            :             {
      56                 :            :                 case 'O':
      57         [ -  + ]:          2 :                     if (av[i][2] == '\0')
      58                 :            :                     {
      59 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      60                 :            :                         {
      61                 :          0 :                             i++;
      62                 :          0 :                             s = av[i];
      63                 :            :                         } else
      64                 :            :                         {
      65                 :          0 :                             OString tmp("'-O', please check");
      66         [ #  # ]:          0 :                             if (i <= ac - 1)
      67                 :            :                             {
      68                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
      69                 :            :                             }
      70                 :            : 
      71                 :          0 :                             throw IllegalArgument(tmp);
      72                 :            :                         }
      73                 :            :                     } else
      74                 :            :                     {
      75                 :          2 :                         s = av[i] + 2;
      76                 :            :                     }
      77                 :            : 
      78         [ +  - ]:          2 :                     m_options["-O"] = OString(s);
      79                 :          2 :                     break;
      80                 :            :                 case 'X':
      81         [ #  # ]:          0 :                     if (av[i][2] == '\0')
      82                 :            :                     {
      83 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      84                 :            :                         {
      85                 :          0 :                             i++;
      86                 :          0 :                             s = av[i];
      87                 :            :                         } else
      88                 :            :                         {
      89                 :          0 :                             OString tmp("'-X', please check");
      90         [ #  # ]:          0 :                             if (i <= ac - 1)
      91                 :            :                             {
      92                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
      93                 :            :                             }
      94                 :            : 
      95                 :          0 :                             throw IllegalArgument(tmp);
      96                 :            :                         }
      97                 :            :                     } else
      98                 :            :                     {
      99                 :          0 :                         s = av[i] + 2;
     100                 :            :                     }
     101                 :            : 
     102         [ #  # ]:          0 :                     m_options["-X"] = OString(s);
     103                 :          0 :                     break;
     104                 :            :                 case 'R':
     105         [ #  # ]:          0 :                     if (av[i][2] == '\0')
     106                 :            :                     {
     107 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     108                 :            :                         {
     109                 :          0 :                             i++;
     110                 :          0 :                             s = av[i];
     111                 :            :                         } else
     112                 :            :                         {
     113                 :          0 :                             OString tmp("'-R', please check");
     114         [ #  # ]:          0 :                             if (i <= ac - 1)
     115                 :            :                             {
     116                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     117                 :            :                             }
     118                 :            : 
     119                 :          0 :                             throw IllegalArgument(tmp);
     120                 :            :                         }
     121                 :            :                     } else
     122                 :            :                     {
     123                 :          0 :                         s = av[i] + 2;
     124                 :            :                     }
     125                 :            : 
     126         [ #  # ]:          0 :                     m_options["-R"] = OString(s);
     127                 :          0 :                     break;
     128                 :            :                 case 'B':
     129         [ -  + ]:          2 :                     if (av[i][2] == '\0')
     130                 :            :                     {
     131 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     132                 :            :                         {
     133                 :          0 :                             i++;
     134                 :          0 :                             s = av[i];
     135                 :            :                         } else
     136                 :            :                         {
     137                 :          0 :                             OString tmp("'-B', please check");
     138         [ #  # ]:          0 :                             if (i <= ac - 1)
     139                 :            :                             {
     140                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     141                 :            :                             }
     142                 :            : 
     143                 :          0 :                             throw IllegalArgument(tmp);
     144                 :            :                         }
     145                 :            :                     } else
     146                 :            :                     {
     147                 :          2 :                         s = av[i] + 2;
     148                 :            :                     }
     149                 :            : 
     150         [ +  - ]:          2 :                     m_options["-B"] = OString(s);
     151                 :          2 :                     break;
     152                 :            :                 case 'b':
     153         [ -  + ]:          2 :                     if (av[i][2] == '\0')
     154                 :            :                     {
     155 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     156                 :            :                         {
     157                 :          0 :                             i++;
     158                 :          0 :                             s = av[i];
     159                 :            :                         } else
     160                 :            :                         {
     161                 :          0 :                             OString tmp("'-b', please check");
     162         [ #  # ]:          0 :                             if (i <= ac - 1)
     163                 :            :                             {
     164                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     165                 :            :                             }
     166                 :            : 
     167                 :          0 :                             throw IllegalArgument(tmp);
     168                 :            :                         }
     169                 :            :                     } else
     170                 :            :                     {
     171                 :          2 :                         s = av[i] + 2;
     172                 :            :                     }
     173                 :            : 
     174         [ +  - ]:          2 :                     m_options["-b"] = OString(s);
     175                 :          2 :                     break;
     176                 :            :                 case 'T':
     177         [ -  + ]:        132 :                     if (av[i][2] == '\0')
     178                 :            :                     {
     179 [ #  # ][ #  # ]:          0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     180                 :            :                         {
     181                 :          0 :                             i++;
     182                 :          0 :                             s = av[i];
     183                 :            :                         } else
     184                 :            :                         {
     185                 :          0 :                             OString tmp("'-T', please check");
     186         [ #  # ]:          0 :                             if (i <= ac - 1)
     187                 :            :                             {
     188                 :          0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     189                 :            :                             }
     190                 :            : 
     191                 :          0 :                             throw IllegalArgument(tmp);
     192                 :            :                         }
     193                 :            :                     } else
     194                 :            :                     {
     195                 :        132 :                         s = av[i] + 2;
     196                 :            :                     }
     197                 :            : 
     198 [ +  - ][ +  + ]:        132 :                     if (m_options.count("-T") > 0)
     199                 :            :                     {
     200         [ +  - ]:        130 :                         OString tmp(m_options["-T"]);
     201                 :        130 :                         tmp = tmp + ";" + s;
     202         [ +  - ]:        130 :                         m_options["-T"] = tmp;
     203                 :            :                     } else
     204                 :            :                     {
     205         [ +  - ]:          2 :                         m_options["-T"] = OString(s);
     206                 :            :                     }
     207                 :        132 :                     break;
     208                 :            :                 case 'F':
     209         [ #  # ]:          0 :                     if (av[i][2] == 'T')
     210                 :            :                     {
     211         [ #  # ]:          0 :                         if (av[i][3] == '\0')
     212                 :            :                         {
     213 [ #  # ][ #  # ]:          0 :                             if (i < ac - 1 && av[i+1][0] != '-')
     214                 :            :                             {
     215                 :          0 :                                 i++;
     216                 :          0 :                                 s = av[i];
     217                 :            :                             } else
     218                 :            :                             {
     219                 :          0 :                                 OString tmp("'-FT', please check");
     220         [ #  # ]:          0 :                                 if (i <= ac - 1)
     221                 :            :                                 {
     222                 :          0 :                                     tmp += " your input '" + OString(av[i+1]) + "'";
     223                 :            :                                 }
     224                 :            : 
     225                 :          0 :                                 throw IllegalArgument(tmp);
     226                 :            :                             }
     227                 :            :                         } else
     228                 :            :                         {
     229                 :          0 :                             s = av[i] + 3;
     230                 :            :                         }
     231                 :            : 
     232 [ #  # ][ #  # ]:          0 :                         if (m_options.count("-FT") > 0)
     233                 :            :                         {
     234         [ #  # ]:          0 :                             OString tmp(m_options["-FT"]);
     235                 :          0 :                             tmp = tmp + ";" + s;
     236         [ #  # ]:          0 :                             m_options["-FT"] = tmp;
     237                 :            :                         } else
     238                 :            :                         {
     239         [ #  # ]:          0 :                             m_options["-FT"] = OString(s);
     240                 :            :                         }
     241                 :            :                     } else
     242                 :            :                     {
     243         [ #  # ]:          0 :                         if (av[i][2] == '\0')
     244                 :            :                         {
     245 [ #  # ][ #  # ]:          0 :                             if (i < ac - 1 && av[i+1][0] != '-')
     246                 :            :                             {
     247                 :          0 :                                 i++;
     248                 :          0 :                                 s = av[i];
     249                 :            :                             } else
     250                 :            :                             {
     251                 :          0 :                                 OString tmp("'-F', please check");
     252         [ #  # ]:          0 :                                 if (i <= ac - 1)
     253                 :            :                                 {
     254                 :          0 :                                     tmp += " your input '" + OString(av[i+1]) + "'";
     255                 :            :                                 }
     256                 :            : 
     257                 :          0 :                                 throw IllegalArgument(tmp);
     258                 :            :                             }
     259                 :            :                         } else
     260                 :            :                         {
     261                 :          0 :                             s = av[i] + 2;
     262                 :            :                         }
     263                 :            : 
     264         [ #  # ]:          0 :                         m_options["-F"] = OString(s);
     265                 :            :                     }
     266                 :          0 :                     break;
     267                 :            :                 case 'L':
     268         [ #  # ]:          0 :                     if (av[i][2] != '\0')
     269                 :            :                     {
     270                 :          0 :                         OString tmp("'-L', please check");
     271         [ #  # ]:          0 :                         if (i <= ac - 1)
     272                 :            :                         {
     273                 :          0 :                             tmp += " your input '" + OString(av[i+1]) + "'";
     274                 :            :                         }
     275                 :            : 
     276                 :          0 :                         throw IllegalArgument(tmp);
     277                 :            :                     }
     278                 :            : 
     279         [ #  # ]:          0 :                     m_options["-L"] = OString();
     280                 :          0 :                     m_generateTypeList = sal_True;
     281                 :          0 :                     break;
     282                 :            :                 default:
     283                 :        138 :                     throw IllegalArgument("the option is unknown" + OString(av[i]));
     284                 :            :             }
     285                 :            :         } else
     286                 :            :         {
     287         [ +  + ]:          4 :             if (av[i][0] == '@')
     288                 :            :             {
     289         [ +  - ]:          2 :                 FILE* cmdFile = fopen(av[i]+1, "r");
     290         [ -  + ]:          2 :                   if( cmdFile == NULL )
     291                 :            :                   {
     292 [ #  # ][ #  # ]:          0 :                     fprintf(stderr, "%s", prepareHelp().getStr());
     293                 :          0 :                     ret = sal_False;
     294                 :            :                 } else
     295                 :            :                 {
     296                 :          2 :                     int rargc=0;
     297                 :            :                     char* rargv[512];
     298                 :            :                     char  buffer[512];
     299                 :            : 
     300 [ +  - ][ +  + ]:        142 :                     while ( fscanf(cmdFile, "%s", buffer) != EOF )
     301                 :            :                     {
     302                 :        140 :                         rargv[rargc]= strdup(buffer);
     303                 :        140 :                         rargc++;
     304                 :            :                     }
     305         [ +  - ]:          2 :                     fclose(cmdFile);
     306                 :            : 
     307         [ +  - ]:          2 :                     ret = initOptions(rargc, rargv, bCmdFile);
     308                 :            : 
     309         [ +  + ]:        142 :                     for (long j=0; j < rargc; j++)
     310                 :            :                     {
     311                 :        140 :                         free(rargv[j]);
     312                 :            :                     }
     313                 :            :                 }
     314                 :            :             } else
     315                 :            :             {
     316         [ +  - ]:          2 :                 m_inputFiles.push_back(av[i]);
     317                 :            :             }
     318                 :            :         }
     319                 :            :     }
     320                 :            : 
     321                 :          4 :     return ret;
     322                 :            : }
     323                 :            : 
     324                 :          0 : OString RdbOptions::prepareHelp()
     325                 :            : {
     326                 :          0 :     OString help("\nusing: ");
     327                 :          0 :     help += m_program + " [-options] (-R<regname> | file_1 [... file_n])\n";
     328                 :          0 :     help += "The rdbmaker supports 2 modes:\n";
     329                 :            :     help += " 1. using the internal UNO type description manager -> use -R<regname>\n"
     330                 :            :             "    where regname specifies the type library used by the UNO type description manager\n"
     331                 :            :             "    after UNO is bootstrapped. This option disables the use of any other type libraries.\n"
     332                 :            :             "    The tpye library must be a valid product type library which means that all types are\n"
     333                 :          0 :             "    stored under the global base node UCR (Uno Core Reflection data).\n";
     334                 :            :     help += " 2. using one or more type library files -> use file_1 ... file_n\n"
     335                 :            :             "    file_1 .. file_n specifies one or more valid type library files which are used to\n"
     336                 :            :             "    find the needed type information. The used type libraries have to support the same base\n"
     337                 :          0 :             "    node (-B option).\n";
     338                 :          0 :     help += "Options:\n";
     339                 :          0 :     help += "    -O<filename> = filename specifies the name of the generated registry\n";
     340                 :          0 :     help += "                   or text file.\n";
     341                 :          0 :     help += "    -L           = specifies that only a text file is generated with the\n";
     342                 :          0 :     help += "                   names of the specified types and their dependencies.\n";
     343                 :          0 :     help += "                   Default is that a registry file will be created\n";
     344                 :          0 :     help += "    -T<name>     = name specifies a type or a list of types. The output for\n";
     345                 :          0 :     help += "      [t1;...]     this type is generated.\n";
     346                 :          0 :     help += "                   Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
     347                 :          0 :     help += "    -FT<name>    = name specifies a type or a list of types. For this types\n";
     348                 :          0 :     help += "      [t1;...]     nothing will be generated.\n";
     349                 :          0 :     help += "     |F<file>    = file specifies an text file. For the specified types in\n" ;
     350                 :          0 :     help += "                   this file nothing will be generated.\n";
     351                 :          0 :     help += "    -B<name>     = name specifies the base node. All types are searched under\n";
     352                 :          0 :     help += "                   this node. Default is the root '/' of the registry files.\n";
     353                 :          0 :     help += "                   This option takes effect using run mode 2 only.\n";
     354                 :          0 :     help += "    -b<name>     = name specifies the base node of the output registry. All\n";
     355                 :          0 :     help += "                   types will be generated under this node. Default is the\n";
     356                 :          0 :     help += "                   root '/' of the registry file.\n";
     357         [ #  # ]:          0 :     help += prepareVersion();
     358                 :            : 
     359                 :          0 :     return help;
     360                 :            : }
     361                 :            : 
     362                 :          0 : OString RdbOptions::prepareVersion()
     363                 :            : {
     364                 :          0 :     OString version("\nSun Microsystems (R) ");
     365                 :          0 :     version += m_program + " Version 2.0\n\n";
     366                 :            : 
     367                 :          0 :     return version;
     368                 :            : }
     369                 :            : 
     370                 :            : 
     371                 :            : 
     372                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10