1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "osl/thread.h"
24 #include "rtl/ustring.hxx"
25 #include "rtl/ustrbuf.h"
27 static bool hasOption(char const * szOption
, int argc
, char** argv
);
32 "\tsp2bv [-h] [-?] string \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" \
41 "\tThe following options are supported: \n" \
44 " Display help information.\n"
49 int main(int argc
, char **argv
)
51 if( hasOption("--help",argc
, argv
) || hasOption("-h", argc
, argv
))
53 fprintf(stdout
, HELP_TEXT
);// default
59 fprintf(stdout
, HELP_TEXT
);
63 rtl_uString
* pPath
= NULL
;
64 rtl_string2UString( &pPath
, argv
[1], strlen(argv
[1]),
65 osl_getThreadTextEncoding(),OSTRING_TO_OUSTRING_CVTFLAGS
);
67 rtl_uString
* pUrl
= NULL
;
68 if (osl_getFileURLFromSystemPath(pPath
, &pUrl
) != osl_File_E_None
)
70 //escape the special characters
72 sal_Unicode cEscapeChar
= 0x5c;
73 rtl_uString
* pBuffer
= NULL
;
74 sal_Int32 nCapacity
= 255;
75 rtl_uString_new_WithLength( &pBuffer
, nCapacity
);
77 const sal_Unicode
* pCur
= pUrl
->buffer
;
78 for (int i
= 0; i
!= pUrl
->length
; i
++)
83 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, &cEscapeChar
, 1);
84 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, pCur
, 1);
88 case '\\': fprintf(stderr
, "sp2vb: file URL contains invalid characters!\n");
91 rtl_uStringbuffer_insert( &pBuffer
, &nCapacity
, pBuffer
->length
, pCur
, 1);
95 //convert back to byte string so that we can print it.
96 rtl_String
* pBootVar
= NULL
;
97 rtl_uString2String( &pBootVar
, pBuffer
->buffer
, pBuffer
->length
,
98 osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS
);
100 fprintf(stdout
, "%s", pBootVar
->buffer
);
103 rtl_uString_release(pBuffer
);
104 rtl_uString_release(pPath
);
105 rtl_uString_release(pUrl
);
106 rtl_string_release(pBootVar
);
112 static bool hasOption(char const * szOption
, int argc
, char** argv
)
115 for(sal_Int16 i
= 1; i
< argc
; i
++)
117 if( ! strcmp(argv
[i
], szOption
))
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */