1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mkfilt.cxx,v $
10 * $Revision: 1.11.34.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
36 #include <../../inc/tools/string.hxx>
37 #include <../../inc/tools/list.hxx>
43 virtual void Filter();
45 TextFilter( ByteString aInFile
= "stdin",
46 ByteString aOutFile
= "stdout" );
47 virtual ~TextFilter();
49 virtual void Execute();
52 TextFilter::TextFilter( ByteString aInFile
, ByteString aOutFile
)
54 if ( aInFile
== "stdin" )
57 if (( pIn
= fopen( aInFile
.GetBuffer(), "r" )) == NULL
)
58 printf( "Can't read %s\n", aInFile
.GetBuffer() );
60 if ( aOutFile
== "stdout" )
63 if (( pOut
= fopen( aOutFile
.GetBuffer(), "w" )) == NULL
)
64 printf( "Can't write %s\n", aOutFile
.GetBuffer() );
67 TextFilter::~TextFilter()
73 void TextFilter::Execute()
78 void TextFilter::Filter()
81 while ( (c
= fgetc( pIn
)) != EOF
)
93 ByteStringList
* pPrivateTnrLst
;
104 pPrivateTnrLst
= NULL
;
107 DECLARE_LIST( ByteStringList
, MkLine
* )
109 class MkFilter
: public TextFilter
111 static ByteString aTnr
;
112 ByteStringList
*pLst
;
113 ByteStringList
*pTnrLst
;
115 virtual void Filter();
117 MkFilter( ByteString aInFile
= "stdin", ByteString aOutFile
= "stdout");
121 MkFilter::MkFilter( ByteString aInFile
, ByteString aOutFile
) :
122 TextFilter( aInFile
, aOutFile
)
124 pLst
= new ByteStringList
;
125 pTnrLst
= new ByteStringList
;
128 MkFilter::~MkFilter()
134 ByteString
MkFilter::aTnr
="$(TNR)";
136 void MkFilter::Filter()
138 char aLineBuf
[LINE_LEN
];
141 while(( fgets(aLineBuf
, LINE_LEN
, pIn
)) != NULL
)
143 ByteString
aLine( aLineBuf
);
144 //fprintf(stderr, "aLine :%s\n", aLine.GetBuffer());
145 if ( aLine
.Search("mkfilter1" ) != STRING_NOTFOUND
)
147 // Zeilen unterdruecken
148 fprintf( stderr
, "mkfilter1\n" );
151 else if ( aLine
.Search("unroll begin" ) != STRING_NOTFOUND
)
153 // Zeilen raus schreiben mit ersetzen von $(TNR) nach int n
154 fprintf( stderr
, "\nunroll begin\n" );
161 fprintf( stderr
, "." );
162 MkLine
*pMkLine
= new MkLine();
163 ByteString
*pStr
= new ByteString( aLineBuf
);
164 pMkLine
->aLine
= *pStr
;
165 pMkLine
->bOut
= FALSE
;
167 pLst
->Insert( pMkLine
, LIST_APPEND
);
169 else if ( nState
== 1 )
171 BOOL bInTnrList
= TRUE
;
172 fprintf( stderr
, ":" );
173 MkLine
*pMkLine
= new MkLine();
174 if ( aLine
.Search("unroll end") != STRING_NOTFOUND
)
176 fprintf( stderr
, ";\nunroll end\n" );
177 MkLine
*p_MkLine
= new MkLine();
178 p_MkLine
->bHier
= TRUE
;
179 ByteString
*pByteString
= new ByteString("# do not delete this line === mkfilter3i\n");
180 p_MkLine
->aLine
= *pByteString
;
181 p_MkLine
->bOut
= FALSE
;
182 p_MkLine
->pPrivateTnrLst
= pTnrLst
;
183 pTnrLst
= new ByteStringList();
184 pLst
->Insert( p_MkLine
, LIST_APPEND
);
188 ByteString
*pStr
= new ByteString( aLineBuf
);
189 pMkLine
->aLine
= *pStr
;
190 pMkLine
->bOut
= FALSE
;
193 pTnrLst
->Insert( pMkLine
, LIST_APPEND
);
196 /* Zeilen ignorieren */;
199 fprintf( stderr
, "\n" );
201 // das File wieder ausgegeben
202 ULONG nLines
= pLst
->Count();
203 for ( ULONG j
=0; j
<nLines
; j
++ )
205 MkLine
*pLine
= pLst
->GetObject( j
);
208 // die List n - Mal abarbeiten
209 for ( USHORT n
=1; n
<11; n
++)
211 ULONG nCount
= pLine
->pPrivateTnrLst
->Count();
212 for ( ULONG i
=0; i
<nCount
; i
++ )
214 MkLine
*pMkLine
= pLine
->pPrivateTnrLst
->GetObject(i
);
215 ByteString aLine
= pMkLine
->aLine
;
216 while( aLine
.SearchAndReplace( aTnr
, ByteString::CreateFromInt32( n
)) != (USHORT
)-1 ) ;
217 fputs( aLine
.GetBuffer(), pOut
);
218 fprintf( stderr
, "o" );
221 if ( pLine
->pPrivateTnrLst
!= NULL
)
222 delete pLine
->pPrivateTnrLst
;
223 pLine
->pPrivateTnrLst
= NULL
;
226 fputs(pLine
->aLine
.GetBuffer(), pOut
);
228 fprintf( stderr
, "\n" );
235 TextFilter
*pFlt
= new MkFilter();