xref: /trunk/main/xml2cmp/source/xcd/cr_metho.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "cr_metho.hxx"
29 
30 #include <string.h>
31 #include <fstream>
32 #include <iostream>
33 
34 
35 
36 const char C_sFileHeader1[]
37                       = "/* ";
38 const char C_sFileHeader2[]
39                       = " */\r\n/* Implementation of component_getDescriptionFunc() */\r\n\r\n"
40                         "#include <sal/types.h>\r\n\r\n";
41 const char C_sFuncBegin[]
42                       = "#ifdef __cplusplus\r\n"
43                         "extern \"C\" {\r\n"
44                         "#endif\r\n\r\n"
45                         "const sal_Char * SAL_CALL\r\ncomponent_getDescriptionFunc()\r\n"
46                         "{\r\n"
47                         "    return (const sal_Char*) \r\n"
48                         "    \"";
49 const char C_sFuncEnd[]    =  "\";\r\n"
50                         "}\r\n\r\n"
51                         "#ifdef __cplusplus\r\n"
52                         "} /* end of extern \"C\" */\r\n"
53                         "#endif\r\n";
54 
55 
56 void
57 Create_AccessMethod( const char *           i_pOutputFileName,
58                      const char *           i_sText )
59 {
60     const char * pText = i_sText;
61     const char * pTrans = 0;
62     const char   sDescrLineChange[] = "\"\r\n    \"";
63     int    sDescrLen = (int) strlen(sDescrLineChange);
64 
65     std::ofstream aFile(i_pOutputFileName, std::ios::out
66 #if defined(WNT) || defined(OS2)
67                                                | std::ios::binary
68 #endif
69     );
70 
71 
72     if ( !aFile )
73     {
74         std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl;
75         return;
76     }
77 
78     aFile.write( C_sFileHeader1, (int) strlen(C_sFileHeader1) );
79     aFile.write( i_pOutputFileName, (int) strlen(i_pOutputFileName) );
80     aFile.write( C_sFileHeader2, (int) strlen(C_sFileHeader2) );
81     aFile.write( C_sFuncBegin, (int) strlen(C_sFuncBegin) );
82 
83     for ( pTrans = pText; *pTrans != '\0'; pTrans++ )
84     {
85         switch (*pTrans)
86         {
87             case '"':   aFile.write( "\\\"", 2);
88                         break;
89             case '\n':  aFile.write( "\\n", 2);
90                         aFile.write( sDescrLineChange, sDescrLen);
91                         break;
92             case '\r':  aFile.write( "\\r", 2);
93                         break;
94 //          case '\t':  aFile.write( "\\t", 2);
95 //                      break;
96             default:    aFile.write( pTrans, 1);
97         }
98     }   /* end for */
99 
100     aFile.write( C_sFuncEnd, (int) strlen(C_sFuncEnd) );
101 
102 
103     aFile.close();
104 }
105 
106 
107