Kaydet (Commit) 3f033cae authored tarafından Nils Fuhrmann's avatar Nils Fuhrmann

Added new functionality for localization of configuration

üst 6227faf5
%{
/*
* lexer for parsing cfg source files
*
*/
/* enlarge token buffer to tokenize whole strings */
#undef YYLMAX
#define YYLMAX 64000
/* to enable debug output define LEXDEBUG */
#define LEXDEBUG 1
#ifdef LEXDEBUG
#define OUTPUT fprintf
#else
#define OUTPUT(Par1,Par2);
#endif
/* table of possible token ids */
#include "tokens.h"
#include <stdlib.h>
#include <stdio.h>
/* external functions (C++ code, declared as extren "C" */
extern WorkOnTokenSet( int, char* );
extern InitCfgExport( char * );
extern EndCfgExport();
extern GetError();
extern SetError();
extern char *GetOutputFile( int argc, char* argv[]);
extern FILE *GetCfgFile();
/* forwards */
void YYWarning();
int bText=0;
%}
%p 24000
%e 1200
%n 500
%%
\<.*\/\> {
bText = 0;
WorkOnTokenSet( ANYTOKEN, yytext );
}
\<[^\>]*"package-id="\".*\"[^\<]*\> {
bText = 0;
WorkOnTokenSet( CFG_TAG, yytext );
}
\<[^\>]*"xml:lang="\".*\"[^\<]*\> {
bText = 1;
WorkOnTokenSet( CFG_TEXT_START, yytext );
}
\<[^\>]*"="\".*\"[^\<]*\> {
bText = 0;
WorkOnTokenSet( CFG_TAG, yytext );
}
"<!--"[^\>]*\> {
bText = 0;
WorkOnTokenSet( COMMEND, yytext );
}
"<!--" {
char c1 = 0, c2 = 0, c3 = input();
char pChar[2];
pChar[1] = 0x00;
pChar[0] = c3;
WorkOnTokenSet( COMMEND, yytext );
WorkOnTokenSet( COMMEND, pChar );
for(;;) {
if ( c3 == EOF )
break;
if ( c1 == '-' && c2 == '-' && c3 == '>' )
break;
c1 = c2;
c2 = c3;
c3 = input();
pChar[0] = c3;
WorkOnTokenSet( COMMEND, pChar );
}
}
\<\/[^\>]*\> {
bText = 0;
WorkOnTokenSet( CFG_CLOSETAG, yytext );
}
\<[^\>]*\> {
bText = 0;
if ( yytext[ 1 ] == '!' && yytext[ 2 ] == '-' && yytext[ 3 ] == '-' )
WorkOnTokenSet( COMMEND, yytext );
else
WorkOnTokenSet( CFG_UNKNOWNTAG, yytext );
}
.|\n {
if ( bText == 1 )
WorkOnTokenSet( CFG_TEXTCHAR, yytext );
else
WorkOnTokenSet( UNKNOWNCHAR, yytext );
}
%%
/*****************************************************************************/
int yywrap(void)
/*****************************************************************************/
{
return 1;
}
/*****************************************************************************/
void YYWarning( char *s )
/*****************************************************************************/
{
/* write warning to stderr */
fprintf( stderr,
"Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
}
/*****************************************************************************/
#ifdef GCC
void yyerror ( char *s, ... )
#else
void yyerror ( char *s )
#endif
/*****************************************************************************/
{
/* write error to stderr */
fprintf( stderr,
"Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
SetError();
}
/*****************************************************************************/
int
#ifdef WNT
_cdecl
#endif
main( int argc, char* argv[])
/*****************************************************************************/
{
/* error level */
int nRetValue = 0;
char *pOutput;
FILE *pFile;
fprintf( stdout, "\nCfgEx 0.9 Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.\n" );
fprintf( stdout, "======================================================================\n" );
pOutput = GetOutputFile( argc, argv );
if ( !pOutput ) {
fprintf( stdout, "Syntax: CFGEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-b][-u][-d DoneFile][-g[:dtd]]\n" );
fprintf( stdout, " Prj: Project\n" );
fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
fprintf( stdout, " FileIn: Source files (*.src)\n" );
fprintf( stdout, " FileOut: Destination file (*.*)\n" );
fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
fprintf( stdout, " -e: Disable writing errorlog\n" );
fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" );
fprintf( stdout, " -g[:dtd]: enables generation of properties (dtds if :dtd is set) - in this case FileOut is the output path\n" );
fprintf( stdout, " -d: enables generation of *.don if work is done\n" );
return 1;
}
pFile = GetCfgFile();
if ( !pFile )
return 1;
yyin = pFile;
/* create global instance of class CfgExport */
InitCfgExport( pOutput );
/* start parser */
yylex();
/* get error info. and end export */
nRetValue = GetError();
EndCfgExport();
fprintf( stdout, "\n===================================\n\n" );
/* return error level */
return nRetValue;
}
/*************************************************************************
*
* $RCSfile: cfgmerge.cxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: nf $ $Date: 2000-11-20 13:49:48 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc..
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <stdio.h>
#include <tools/string.hxx>
#include <tools/fsys.hxx>
// local includes
#include "export.hxx"
#include "xmlmerge.hxx"
#include "tokens.h"
#include "utf8conv.hxx"
extern "C" { yyerror( char * ); }
extern "C" { YYWarning( char * ); }
// defines to parse command line
#define STATE_NON 0x0001
#define STATE_INPUT 0x0002
#define STATE_OUTPUT 0x0003
#define STATE_PRJ 0x0004
#define STATE_ROOT 0x0005
#define STATE_MERGESRC 0x0006
#define STATE_ERRORLOG 0x0007
// set of global variables
BOOL bEnableExport;
BOOL bMergeMode;
BOOL bErrorLog;
ByteString sPrj;
ByteString sPrjRoot;
ByteString sInputFileName;
ByteString sActFileName;
ByteString sOutputFile;
ByteString sMergeSrc;
BOOL bText = FALSE;
extern "C" {
// the whole interface to lexer is in this extern "C" section
/*****************************************************************************/
extern char *GetOutputFile( int argc, char* argv[])
/*****************************************************************************/
{
bEnableExport = FALSE;
bMergeMode = FALSE;
bErrorLog = TRUE;
sPrj = "";
sPrjRoot = "";
sInputFileName = "";
sActFileName = "";
USHORT nState = STATE_NON;
BOOL bInput = FALSE;
// parse command line
for( int i = 1; i < argc; i++ ) {
if ( ByteString( argv[ i ] ).ToUpperAscii() == "-I" ) {
nState = STATE_INPUT; // next token specifies source file
}
else if ( ByteString( argv[ i ] ).ToUpperAscii() == "-O" ) {
nState = STATE_OUTPUT; // next token specifies the dest file
}
else if ( ByteString( argv[ i ] ).ToUpperAscii() == "-P" ) {
nState = STATE_PRJ; // next token specifies the cur. project
}
else if ( ByteString( argv[ i ] ).ToUpperAscii() == "-R" ) {
nState = STATE_ROOT; // next token specifies path to project root
}
else if ( ByteString( argv[ i ] ).ToUpperAscii() == "-M" ) {
nState = STATE_MERGESRC; // next token specifies the merge database
}
else if ( ByteString( argv[ i ] ).ToUpperAscii() == "-E" ) {
nState = STATE_ERRORLOG;
bErrorLog = FALSE;
}
else {
switch ( nState ) {
case STATE_NON: {
return NULL; // no valid command line
}
break;
case STATE_INPUT: {
sInputFileName = argv[ i ];
bInput = TRUE; // source file found
}
break;
case STATE_OUTPUT: {
sOutputFile = argv[ i ]; // the dest. file
}
break;
case STATE_PRJ: {
sPrj = ByteString( argv[ i ]);
sPrj.ToLowerAscii(); // the project
}
break;
case STATE_ROOT: {
sPrjRoot = ByteString( argv[ i ]); // path to project root
}
break;
case STATE_MERGESRC: {
sMergeSrc = ByteString( argv[ i ]);
bMergeMode = TRUE; // activate merge mode, cause merge database found
}
}
}
}
if ( bInput ) {
// command line is valid
bEnableExport = TRUE;
char *pReturn = new char[ sOutputFile.Len() + 1 ];
strcpy( pReturn, sOutputFile.GetBuffer());
return pReturn;
}
// command line is not valid
return NULL;
}
/*****************************************************************************/
int InitCfgExport( char *pOutput )
/*****************************************************************************/
{
// instanciate Export
ByteString sOutput( pOutput );
return 1;
}
/*****************************************************************************/
int EndCfgExport()
/*****************************************************************************/
{
return 1;
}
/*****************************************************************************/
extern FILE *GetCfgFile()
/*****************************************************************************/
{
// look for valid filename
if ( sInputFileName.Len()) {
// able to open file?
FILE *pFile = fopen( sInputFileName.GetBuffer(), "r" );
if ( !pFile )
fprintf( stderr, "Error: Could not open file %s\n",
sInputFileName.GetBuffer());
else {
// this is a valid file which can be opened, so
// create path to project root
DirEntry aEntry( String( sInputFileName, RTL_TEXTENCODING_ASCII_US ));
aEntry.ToAbs();
ByteString sFullEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
aEntry += DirEntry( sPrjRoot );
ByteString sPrjEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
// create file name, beginnig with project root
// (e.g.: source\ui\src\menue.src)
sActFileName = sFullEntry.Copy( sPrjEntry.Len() + 1 );
sActFileName.ToLowerAscii();
fprintf( stdout, "\nProcessing File %s ...\n", sInputFileName.GetBuffer());
return pFile;
}
}
// this means the file could not be opened
return NULL;
}
/*****************************************************************************/
int WorkOnTokenSet( int nTyp, char *pTokenText )
/*****************************************************************************/
{
fprintf( stdout, pTokenText );
return 1;
if ( bText && nTyp != CFG_TEXTCHAR ) {
fprintf( stdout, "\n" );
bText = FALSE;
}
switch ( nTyp ) {
case CFG_TAG:
fprintf( stdout, "TAG: %s\n", pTokenText );
break;
case CFG_TEXT_START:
fprintf( stdout, "TEXT_START: %s\n ", pTokenText );
bText = TRUE;
break;
case CFG_TEXT_END:
fprintf( stdout, "\nTEXT_END: %s\n", pTokenText );
break;
case CFG_TEXTCHAR:
fprintf( stdout, "%s", pTokenText );
break;
case CFG_UNKNOWNTAG:
fprintf( stdout, "UNKNOWNTAG: %s\n", pTokenText );
break;
case CFG_CLOSETAG:
fprintf( stdout, "CLOSETAG: %s\n", pTokenText );
break;
}
return 1;
}
/*****************************************************************************/
int SetError()
/*****************************************************************************/
{
return 1;
}
/*****************************************************************************/
int GetError()
/*****************************************************************************/
{
return 0;
}
}
......@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
# $Revision: 1.1.1.1 $
# $Revision: 1.2 $
#
# last change: $Author: hr $ $Date: 2000-09-18 17:03:26 $
# last change: $Author: nf $ $Date: 2000-11-20 13:49:48 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
......@@ -85,7 +85,6 @@ OBJFILES= \
$(OBJ)$/wtratree.obj \
$(OBJ)$/wtranode.obj
APP1TARGET= $(TARGET)
APP1STACK= 16000
APP1OBJS= $(OBJ)$/src_yy.obj
......@@ -118,11 +117,17 @@ APP6STACK= 16000
APP6OBJS= $(OBJ)$/xmlmerge.obj $(OBJ)$/xml_yy.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/utf8conv.obj
APP6STDLIBS=$(STATIC_LIBS)
APP6TARGET= cfgex
APP6STACK= 16000
APP6OBJS= $(OBJ)$/cfgmerge.obj $(OBJ)$/cfg_yy.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/utf8conv.obj
APP6STDLIBS=$(STATIC_LIBS)
DEPOBJFILES=$(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS) $(APP5OBJS) $(APP6OBJS)
.IF "$(depend)" == ""
ALL : $(MISC)$/src_yy.c \
$(MISC)$/xml_yy.c \
$(MISC)$/cfg_yy.c \
ALLTAR
.ELSE
ALL : \
......@@ -138,3 +143,6 @@ $(MISC)$/src_yy.c : srclex.l
$(MISC)$/xml_yy.c : xmllex.l
+flex -l -8 -o$(MISC)$/xml_yy.c xmllex.l
$(MISC)$/cfg_yy.c : cfglex.l
+flex -l -8 -o$(MISC)$/cfg_yy.c cfglex.l
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment