1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "osl/thread.h"
33 #include "rtl/ustring.hxx"
34 #include "rtl/ustrbuf.h"
36 static sal_Bool
hasOption(char const * szOption
, int argc
, char** argv
);
41 "\tsp2bv [-h] [-?] string \n\n" \
43 "\tsp2bv stands for \"system path to bootstrap variable\"." \
44 " First the system path is converted into a file URL. Then all " \
45 "characters which have a special meaning in bootstrap variables, " \
46 "such as \'$\' are escaped. The resulting string is written to " \
47 "stdout an can be assigned to a bootstrap variable.\n" \
50 "\tThe following options are supported: \n" \
53 " Display help information.\n"
58 int main(int argc
, char **argv
)
60 if( hasOption("--help",argc
, argv
) || hasOption("-h", argc
, argv
))
62 fprintf(stdout
, HELP_TEXT
);// default
68 fprintf(stdout
, HELP_TEXT
);
72 rtl_uString
* pPath
= NULL
;
73 rtl_string2UString( &pPath
, argv
[1], strlen(argv
[1]),
74 osl_getThreadTextEncoding(),OSTRING_TO_OUSTRING_CVTFLAGS
);
76 rtl_uString
* pUrl
= NULL
;
77 if (osl_getFileURLFromSystemPath(pPath
, &pUrl
) != osl_File_E_None
)
79 //escape the special characters
81 sal_Unicode cEscapeChar
= 0x5c;
82 rtl_uString
* pBuffer
= NULL
;
83 sal_Int32 nCapacity
= 255;
84 rtl_uString_new_WithLength( &pBuffer
, nCapacity
);
86 const sal_Unicode
* pCur
= pUrl
->buffer
;
87 for (int i
= 0; i
!= pUrl
->length
; i
++)
92 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, &cEscapeChar
, 1);
93 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, pCur
, 1);
97 case '\\': fprintf(stderr
, "sp2vb: file URL contains invalid characters!\n");
100 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, pCur
, 1);
104 //convert back to byte string so that we can print it.
105 rtl_String
* pBootVar
= NULL
;
106 rtl_uString2String( &pBootVar
, pBuffer
->buffer
, pBuffer
->length
,
107 osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS
);
109 fprintf(stdout
, "%s", pBootVar
->buffer
);
112 rtl_uString_release(pBuffer
);
113 rtl_uString_release(pPath
);
114 rtl_uString_release(pUrl
);
115 rtl_string_release(pBootVar
);
121 static sal_Bool
hasOption(char const * szOption
, int argc
, char** argv
)
123 sal_Bool retVal
= sal_False
;
124 for(sal_Int16 i
= 1; i
< argc
; i
++)
126 if( ! strcmp(argv
[i
], szOption
))
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */