LCOV - code coverage report
Current view: top level - libreoffice/codemaker/source/javamaker - javaoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 127 26.0 %
Date: 2012-12-27 Functions: 1 3 33.3 %
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 <string.h>
      22             : #include "javaoptions.hxx"
      23             : #include "osl/process.h"
      24             : #include "osl/thread.h"
      25             : 
      26             : using ::rtl::OUString;
      27             : using ::rtl::OString;
      28             : using ::rtl::OUStringToOString;
      29             : 
      30             : #ifdef SAL_UNX
      31             : #define SEPARATOR '/'
      32             : #else
      33             : #define SEPARATOR '\\'
      34             : #endif
      35             : 
      36           3 : sal_Bool JavaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
      37             :     throw( IllegalArgument )
      38             : {
      39           3 :     sal_Bool    ret = sal_True;
      40           3 :     sal_uInt16  i=0;
      41             : 
      42           3 :     if (!bCmdFile)
      43             :     {
      44           3 :         bCmdFile = sal_True;
      45             : 
      46           3 :         OString name(av[0]);
      47           3 :         sal_Int32 index = name.lastIndexOf(SEPARATOR);
      48           3 :         m_program = name.copy((index > 0 ? index+1 : 0));
      49             : 
      50           3 :         if (ac < 2)
      51             :         {
      52           0 :             fprintf(stderr, "%s", prepareHelp().getStr());
      53           0 :             ret = sal_False;
      54             :         }
      55             : 
      56           3 :         i = 1;
      57             :     } else
      58             :     {
      59           0 :         i = 0;
      60             :     }
      61             : 
      62           3 :     char    *s=NULL;
      63          15 :     for( ; i < ac; i++)
      64             :     {
      65          12 :         if (av[i][0] == '-')
      66             :         {
      67           9 :             switch (av[i][1])
      68             :             {
      69             :                 case 'O':
      70           3 :                     if (av[i][2] == '\0')
      71             :                     {
      72           0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      73             :                         {
      74           0 :                             i++;
      75           0 :                             s = av[i];
      76             :                         } else
      77             :                         {
      78           0 :                             OString tmp("'-O', please check");
      79           0 :                             if (i <= ac - 1)
      80             :                             {
      81           0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
      82             :                             }
      83             : 
      84           0 :                             throw IllegalArgument(tmp);
      85             :                         }
      86             :                     } else
      87             :                     {
      88           3 :                         s = av[i] + 2;
      89             :                     }
      90             : 
      91           3 :                     m_options["-O"] = OString(s);
      92           3 :                     break;
      93             :                 case 'B':
      94           3 :                     if (av[i][2] == '\0')
      95             :                     {
      96           0 :                         if (i < ac - 1 && av[i+1][0] != '-')
      97             :                         {
      98           0 :                             i++;
      99           0 :                             s = av[i];
     100             :                         } else
     101             :                         {
     102           0 :                             OString tmp("'-B', please check");
     103           0 :                             if (i <= ac - 1)
     104             :                             {
     105           0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     106             :                             }
     107             : 
     108           0 :                             throw IllegalArgument(tmp);
     109             :                         }
     110             :                     } else
     111             :                     {
     112           3 :                         s = av[i] + 2;
     113             :                     }
     114             : 
     115           3 :                     m_options["-B"] = OString(s);
     116           3 :                     break;
     117             :                 case 'n':
     118           1 :                     if (av[i][2] != 'D' || av[i][3] != '\0')
     119             :                     {
     120           0 :                         OString tmp("'-nD', please check");
     121           0 :                             tmp += " your input '" + OString(av[i]) + "'";
     122           0 :                         throw IllegalArgument(tmp);
     123             :                     }
     124             : 
     125           1 :                     m_options["-nD"] = OString("");
     126           1 :                     break;
     127             :                 case 'T':
     128           0 :                     if (av[i][2] == '\0')
     129             :                     {
     130           0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     131             :                         {
     132           0 :                             i++;
     133           0 :                             s = av[i];
     134             :                         } else
     135             :                         {
     136           0 :                             OString tmp("'-T', please check");
     137           0 :                             if (i <= ac - 1)
     138             :                             {
     139           0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     140             :                             }
     141             : 
     142           0 :                             throw IllegalArgument(tmp);
     143             :                         }
     144             :                     } else
     145             :                     {
     146           0 :                         s = av[i] + 2;
     147             :                     }
     148             : 
     149           0 :                     if (m_options.count("-T") > 0)
     150             :                     {
     151           0 :                         OString tmp(m_options["-T"]);
     152           0 :                         tmp = tmp + ";" + s;
     153           0 :                         m_options["-T"] = tmp;
     154             :                     } else
     155             :                     {
     156           0 :                         m_options["-T"] = OString(s);
     157             :                     }
     158           0 :                     break;
     159             :                 case 'G':
     160           0 :                     if (av[i][2] == 'c')
     161             :                     {
     162           0 :                         if (av[i][3] != '\0')
     163             :                         {
     164           0 :                             OString tmp("'-Gc', please check");
     165           0 :                             if (i <= ac - 1)
     166             :                             {
     167           0 :                                 tmp += " your input '" + OString(av[i]) + "'";
     168             :                             }
     169             : 
     170           0 :                             throw IllegalArgument(tmp);
     171             :                         }
     172             : 
     173           0 :                         m_options["-Gc"] = OString("");
     174           0 :                         break;
     175           0 :                     } else if (av[i][2] != '\0')
     176             :                     {
     177           0 :                         OString tmp("'-G', please check");
     178           0 :                         if (i <= ac - 1)
     179             :                         {
     180           0 :                             tmp += " your input '" + OString(av[i]) + "'";
     181             :                         }
     182             : 
     183           0 :                         throw IllegalArgument(tmp);
     184             :                     }
     185             : 
     186           0 :                     m_options["-G"] = OString("");
     187           0 :                     break;
     188             :                 case 'X': // support for eXtra type rdbs
     189             :                 {
     190           2 :                     if (av[i][2] == '\0')
     191             :                     {
     192           0 :                         if (i < ac - 1 && av[i+1][0] != '-')
     193             :                         {
     194           0 :                             i++;
     195           0 :                             s = av[i];
     196             :                         } else
     197             :                         {
     198           0 :                             OString tmp("'-X', please check");
     199           0 :                             if (i <= ac - 1)
     200             :                             {
     201           0 :                                 tmp += " your input '" + OString(av[i+1]) + "'";
     202             :                             }
     203             : 
     204           0 :                             throw IllegalArgument(tmp);
     205             :                         }
     206             :                     } else
     207             :                     {
     208           2 :                         s = av[i] + 2;
     209             :                     }
     210             : 
     211           2 :                     m_extra_input_files.push_back( s );
     212           2 :                     break;
     213             :                 }
     214             : 
     215             :                 default:
     216           0 :                     throw IllegalArgument("the option is unknown" + OString(av[i]));
     217             :             }
     218             :         } else
     219             :         {
     220           3 :             if (av[i][0] == '@')
     221             :             {
     222           0 :                 FILE* cmdFile = fopen(av[i]+1, "r");
     223           0 :                   if( cmdFile == NULL )
     224             :                   {
     225           0 :                     fprintf(stderr, "%s", prepareHelp().getStr());
     226           0 :                     ret = sal_False;
     227             :                 } else
     228             :                 {
     229           0 :                     int rargc=0;
     230             :                     char* rargv[512];
     231             :                     char  buffer[512];
     232             : 
     233           0 :                     while ( fscanf(cmdFile, "%s", buffer) != EOF )
     234             :                     {
     235           0 :                         rargv[rargc]= strdup(buffer);
     236           0 :                         rargc++;
     237             :                     }
     238           0 :                     fclose(cmdFile);
     239             : 
     240           0 :                     ret = initOptions(rargc, rargv, bCmdFile);
     241             : 
     242           0 :                     for (long j=0; j < rargc; j++)
     243             :                     {
     244           0 :                         free(rargv[j]);
     245             :                     }
     246             :                 }
     247             :             } else
     248             :             {
     249           3 :                 if (bCmdFile)
     250             :                 {
     251           3 :                     m_inputFiles.push_back(av[i]);
     252             :                 } else
     253             :                 {
     254           0 :                     OUString system_filepath;
     255           0 :                     if (osl_getCommandArg( i-1, &system_filepath.pData )
     256             :                         != osl_Process_E_None)
     257             :                     {
     258             :                         OSL_ASSERT(false);
     259             :                     }
     260           0 :                     m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding()));
     261             :                 }
     262             :             }
     263             :         }
     264             :     }
     265             : 
     266           3 :     return ret;
     267             : }
     268             : 
     269           0 : OString JavaOptions::prepareHelp()
     270             : {
     271           0 :     OString help("\nusing: ");
     272           0 :     help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n";
     273           0 :     help += "    -O<path>   = path describes the root directory for the generated output.\n";
     274           0 :     help += "                 The output directory tree is generated under this directory.\n";
     275           0 :     help += "    -T<name>   = name specifies a type or a list of types. The output for this\n";
     276           0 :     help += "      [t1;...]   type and all dependent types are generated. If no '-T' option is \n";
     277           0 :     help += "                 specified, then output for all types is generated.\n";
     278           0 :     help += "                 Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
     279           0 :     help += "    -B<name>   = name specifies the base node. All types are searched under this\n";
     280           0 :     help += "                 node. Default is the root '/' of the registry files.\n";
     281           0 :     help += "    -nD        = no dependent types are generated.\n";
     282           0 :     help += "    -G         = generate only target files which does not exists.\n";
     283           0 :     help += "    -Gc        = generate only target files which content will be changed.\n";
     284           0 :     help += "    -X<file>   = extra types which will not be taken into account for generation.\n\n";
     285           0 :     help += prepareVersion();
     286             : 
     287           0 :     return help;
     288             : }
     289             : 
     290           0 : OString JavaOptions::prepareVersion()
     291             : {
     292           0 :     OString version(m_program);
     293           0 :     version += " Version 2.0\n\n";
     294           0 :     return version;
     295             : }
     296             : 
     297             : 
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10