merge the formfield patch from ooo-build
[ooovba.git] / oox / source / token / gennamespaces.pl
blob1772f8662c0d4d179e93211e48c5257d04f20dfa
1 $ARGV0 = shift @ARGV;
2 $ARGV1 = shift @ARGV;
4 open ( NAMESPACES, $ARGV0 ) || die "can't open namespaces file: $!";
7 open ( HXX, ">$ARGV1" ) or die "can't open namespaces.hxx file: $!";
9 print ( HXX "#ifndef OOX_NAMESPACES_HXX\n" );
10 print ( HXX "#define OOX_NAMESPACES_HXX\n\n" );
11 print ( HXX "#include <sal/types.h>\n\n" );
12 print ( HXX "namespace oox {\n\n" );
14 $group = 0;
15 $i = 1;
16 while ( <NAMESPACES> )
18 chomp( $_ );
19 $_ =~ s/\s*//g;
20 if ( $_ =~ m/^$/ )
22 # Start a new group
23 print ( HXX "\n" );
24 $i = 0;
25 $group++;
27 elsif ( $_ =~ m/^[^#]/ )
29 # Neither an empty line nor a comment
30 $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Invalid namespace token $_";
31 $id = "NMSP_$_";
32 $id =~ s/-/_/g;
33 $no = $group*10 + $i;
34 print ( HXX "const sal_Int32 $id = $no << 16;\n" );
35 ++$i;
38 close ( NAMESPACES );
40 print ( HXX "\nconst sal_Int32 TOKEN_MASK = SAL_MAX_UINT16;\n" );
41 print ( HXX "const sal_Int32 NMSP_MASK = SAL_MAX_INT16 << 16;\n" );
43 print ( HXX "/** Returns the token identifier of the passed element without namespace. */\n" );
44 print ( HXX "inline sal_Int32 getToken( sal_Int32 nElement ) { return nElement & TOKEN_MASK; }\n\n" );
46 print ( HXX "/** Returns the namespace of the passed element without token identifier. */\n" );
47 print ( HXX "inline sal_Int32 getNamespace( sal_Int32 nElement ) { return nElement & NMSP_MASK; }\n\n" );
49 print ( HXX "// defines for tokens with specific namespaces, can be used in switch/cases\n\n" );
50 print ( HXX "#define A_TOKEN( token ) (::oox::NMSP_DRAWINGML | XML_##token)\n" );
51 print ( HXX "#define AX_TOKEN( token ) (::oox::NMSP_AX | XML_##token)\n" );
52 print ( HXX "#define C_TOKEN( token ) (::oox::NMSP_CHART | XML_##token)\n" );
53 print ( HXX "#define O_TOKEN( token ) (::oox::NMSP_OFFICE | XML_##token)\n" );
54 print ( HXX "#define PPT_TOKEN( token ) (::oox::NMSP_PPT | XML_##token)\n" );
55 print ( HXX "#define R_TOKEN( token ) (::oox::NMSP_RELATIONSHIPS | XML_##token)\n" );
56 print ( HXX "#define VML_TOKEN( token ) (::oox::NMSP_VML | XML_##token)\n" );
57 print ( HXX "#define VMLX_TOKEN( token ) (::oox::NMSP_VML_XLS | XML_##token)\n" );
58 print ( HXX "#define XDR_TOKEN( token ) (::oox::NMSP_XDR | XML_##token)\n" );
59 print ( HXX "#define XLS_TOKEN( token ) (::oox::NMSP_XLS | XML_##token)\n" );
60 print ( HXX "#define XM_TOKEN( token ) (::oox::NMSP_XM | XML_##token)\n" );
61 print ( HXX "#define XML_TOKEN( token ) (::oox::NMSP_XML | XML_##token)\n" );
64 print ( HXX "} // namespace oox\n\n" );
65 print ( HXX "#endif // OOX_NAMESPACES_HXX\n" );