1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "cr_metho.hxx"
25
26 #include <string.h>
27 #include <fstream>
28 #include <iostream>
29
30
31
32 const char C_sFileHeader1[]
33 = "/* ";
34 const char C_sFileHeader2[]
35 = " */\r\n/* Implementation of component_getDescriptionFunc() */\r\n\r\n"
36 "#include <sal/types.h>\r\n\r\n";
37 const char C_sFuncBegin[]
38 = "#ifdef __cplusplus\r\n"
39 "extern \"C\" {\r\n"
40 "#endif\r\n\r\n"
41 "const sal_Char * SAL_CALL\r\ncomponent_getDescriptionFunc()\r\n"
42 "{\r\n"
43 " return (const sal_Char*) \r\n"
44 " \"";
45 const char C_sFuncEnd[] = "\";\r\n"
46 "}\r\n\r\n"
47 "#ifdef __cplusplus\r\n"
48 "} /* end of extern \"C\" */\r\n"
49 "#endif\r\n";
50
51
52 void
Create_AccessMethod(const char * i_pOutputFileName,const char * i_sText)53 Create_AccessMethod( const char * i_pOutputFileName,
54 const char * i_sText )
55 {
56 const char * pText = i_sText;
57 const char * pTrans = 0;
58 const char sDescrLineChange[] = "\"\r\n \"";
59 int sDescrLen = (int) strlen(sDescrLineChange);
60
61 std::ofstream aFile(i_pOutputFileName, std::ios::out
62 #if defined(WNT) || defined(OS2)
63 | std::ios::binary
64 #endif
65 );
66
67
68 if ( !aFile )
69 {
70 std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl;
71 return;
72 }
73
74 aFile.write( C_sFileHeader1, (int) strlen(C_sFileHeader1) );
75 aFile.write( i_pOutputFileName, (int) strlen(i_pOutputFileName) );
76 aFile.write( C_sFileHeader2, (int) strlen(C_sFileHeader2) );
77 aFile.write( C_sFuncBegin, (int) strlen(C_sFuncBegin) );
78
79 for ( pTrans = pText; *pTrans != '\0'; pTrans++ )
80 {
81 switch (*pTrans)
82 {
83 case '"': aFile.write( "\\\"", 2);
84 break;
85 case '\n': aFile.write( "\\n", 2);
86 aFile.write( sDescrLineChange, sDescrLen);
87 break;
88 case '\r': aFile.write( "\\r", 2);
89 break;
90 // case '\t': aFile.write( "\\t", 2);
91 // break;
92 default: aFile.write( pTrans, 1);
93 }
94 } /* end for */
95
96 aFile.write( C_sFuncEnd, (int) strlen(C_sFuncEnd) );
97
98
99 aFile.close();
100 }
101
102
103