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