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 : :
20 : : #include "cr_metho.hxx"
21 : :
22 : : #include <string.h>
23 : : #include <fstream>
24 : : #include <iostream>
25 : :
26 : :
27 : :
28 : : const char C_sFileHeader1[]
29 : : = "/* ";
30 : : const char C_sFileHeader2[]
31 : : = " */\r\n/* Implementation of component_getDescriptionFunc() */\r\n\r\n"
32 : : "#include <sal/types.h>\r\n\r\n";
33 : : const char C_sFuncBegin[]
34 : : = "#ifdef __cplusplus\r\n"
35 : : "extern \"C\" {\r\n"
36 : : "#endif\r\n\r\n"
37 : : "const sal_Char * SAL_CALL\r\ncomponent_getDescriptionFunc()\r\n"
38 : : "{\r\n"
39 : : " return (const sal_Char*) \r\n"
40 : : " \"";
41 : : const char C_sFuncEnd[] = "\";\r\n"
42 : : "}\r\n\r\n"
43 : : "#ifdef __cplusplus\r\n"
44 : : "} /* end of extern \"C\" */\r\n"
45 : : "#endif\r\n";
46 : :
47 : :
48 : : void
49 : 0 : Create_AccessMethod( const char * i_pOutputFileName,
50 : : const char * i_sText )
51 : : {
52 : 0 : const char * pText = i_sText;
53 : 0 : const char * pTrans = 0;
54 : 0 : const char sDescrLineChange[] = "\"\r\n \"";
55 : 0 : int sDescrLen = (int) strlen(sDescrLineChange);
56 : :
57 : : std::ofstream aFile(i_pOutputFileName, std::ios::out
58 : : #if defined(WNT)
59 : : | std::ios::binary
60 : : #endif
61 [ # # ]: 0 : );
62 : :
63 : :
64 [ # # ][ # # ]: 0 : if ( !aFile )
65 : : {
66 [ # # ][ # # ]: 0 : std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl;
[ # # ][ # # ]
67 : 0 : return;
68 : : }
69 : :
70 [ # # ]: 0 : aFile.write( C_sFileHeader1, (int) strlen(C_sFileHeader1) );
71 [ # # ]: 0 : aFile.write( i_pOutputFileName, (int) strlen(i_pOutputFileName) );
72 [ # # ]: 0 : aFile.write( C_sFileHeader2, (int) strlen(C_sFileHeader2) );
73 [ # # ]: 0 : aFile.write( C_sFuncBegin, (int) strlen(C_sFuncBegin) );
74 : :
75 [ # # ]: 0 : for ( pTrans = pText; *pTrans != '\0'; pTrans++ )
76 : : {
77 [ # # # # ]: 0 : switch (*pTrans)
78 : : {
79 [ # # ]: 0 : case '"': aFile.write( "\\\"", 2);
80 : 0 : break;
81 [ # # ]: 0 : case '\n': aFile.write( "\\n", 2);
82 [ # # ]: 0 : aFile.write( sDescrLineChange, sDescrLen);
83 : 0 : break;
84 [ # # ]: 0 : case '\r': aFile.write( "\\r", 2);
85 : 0 : break;
86 [ # # ]: 0 : default: aFile.write( pTrans, 1);
87 : : }
88 : : } /* end for */
89 : :
90 [ # # ]: 0 : aFile.write( C_sFuncEnd, (int) strlen(C_sFuncEnd) );
91 : :
92 : :
93 [ # # ][ # # ]: 0 : aFile.close();
[ # # ]
94 [ + - ][ + - ]: 6 : }
95 : :
96 : :
97 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|