LCOV - code coverage report
Current view: top level - cpputools/source/sp2bv - sp2bv.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 43 0.0 %
Date: 2014-04-11 Functions: 0 2 0.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             : #include <stdio.h>
      20             : #include <stdlib.h>
      21             : #include <string.h>
      22             : #include "osl/thread.h"
      23             : #include "osl/file.h"
      24             : #include "rtl/ustring.hxx"
      25             : #include "rtl/ustrbuf.h"
      26             : 
      27             : static sal_Bool hasOption(char const * szOption, int argc, char** argv);
      28             : 
      29             : 
      30             : #define HELP_TEXT    \
      31             : "SYNOPSIS \n\n" \
      32             : "\tsp2bv [-h] [-?] string \n\n" \
      33             : "DESCRIPTION\n\n" \
      34             : "\tsp2bv stands for \"system path to bootstrap variable\"." \
      35             : " First the system path is converted into a file URL. Then all " \
      36             : "characters which have a special meaning in bootstrap variables, " \
      37             : "such as \'$\' are escaped. The resulting string is written to " \
      38             : "stdout an can be assigned to a bootstrap variable.\n" \
      39             : "\n\n" \
      40             : "OPTIONS \n\n" \
      41             : "\tThe following options are supported: \n" \
      42             : "-?\n " \
      43             : "--help" \
      44             : "    Display help information.\n"
      45             : 
      46             : 
      47             : 
      48             : 
      49           0 : int main(int argc, char **argv)
      50             : {
      51           0 :     if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv))
      52             :     {
      53           0 :         fprintf(stdout, HELP_TEXT);// default
      54           0 :         return 0;
      55             :     }
      56             : 
      57           0 :     if (argc != 2)
      58             :     {
      59           0 :         fprintf(stdout, HELP_TEXT);
      60           0 :         return -1;
      61             :     }
      62             : 
      63           0 :     rtl_uString* pPath = NULL;
      64           0 :     rtl_string2UString( &pPath, argv[1], strlen(argv[1]),
      65           0 :                         osl_getThreadTextEncoding(),OSTRING_TO_OUSTRING_CVTFLAGS );
      66             : 
      67           0 :     rtl_uString* pUrl = NULL;
      68           0 :     if (osl_getFileURLFromSystemPath(pPath, &pUrl) != osl_File_E_None)
      69           0 :         return -1;
      70             : //escape the special characters
      71             : 
      72           0 :     sal_Unicode cEscapeChar = 0x5c;
      73           0 :     rtl_uString* pBuffer = NULL;
      74           0 :     sal_Int32 nCapacity = 255;
      75           0 :     rtl_uString_new_WithLength( &pBuffer, nCapacity );
      76             : 
      77           0 :     const sal_Unicode* pCur = pUrl->buffer;
      78           0 :     for (int i = 0; i != pUrl->length; i++)
      79             :     {
      80           0 :         switch( *pCur)
      81             :         {
      82             :         case '$':
      83           0 :             rtl_uStringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, &cEscapeChar, 1);
      84           0 :             rtl_uStringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, pCur, 1);
      85           0 :             break;
      86             :         case '{':
      87             :         case '}':
      88           0 :         case '\\': fprintf(stderr, "sp2vb: file URL contains invalid characters!\n");
      89           0 :             return -1;
      90             :         default:
      91           0 :             rtl_uStringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, pCur, 1);
      92             :         }
      93           0 :         pCur ++;
      94             :     }
      95             : //convert back to byte string so that we can print it.
      96           0 :     rtl_String* pBootVar = NULL;
      97             :     rtl_uString2String( &pBootVar, pBuffer->buffer, pBuffer->length,
      98           0 :                         osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS);
      99             : 
     100           0 :     fprintf(stdout, "%s", pBootVar->buffer);
     101           0 :     fflush(stdout);
     102             : 
     103           0 :     rtl_uString_release(pBuffer);
     104           0 :     rtl_uString_release(pPath);
     105           0 :     rtl_uString_release(pUrl);
     106           0 :     rtl_string_release(pBootVar);
     107           0 :     return 0;
     108             : }
     109             : 
     110             : 
     111             : 
     112           0 : static sal_Bool hasOption(char const * szOption, int argc, char** argv)
     113             : {
     114           0 :     sal_Bool retVal= sal_False;
     115           0 :     for(sal_Int16 i= 1; i < argc; i++)
     116             :     {
     117           0 :         if( ! strcmp(argv[i], szOption))
     118             :         {
     119           0 :             retVal= sal_True;
     120           0 :             break;
     121             :         }
     122             :     }
     123           0 :     return retVal;
     124             : }
     125             : 
     126             : 
     127             : 
     128             : 
     129             : 
     130             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10