graveyard/tools/org/apache/axis/tools/cbindings/CBindingGenerator.java
/**
     * Generates a C header file from a C++ header file.
     */
Generates a C header file from a C++ header file.
Generates a C header file from a C ++ header file .
private void generateHeader(InputCppSourceCode inputFile, BufferedWriter outputFile) throws Exception 
    {
        boolean foundCopyright = false;
        String define = inputFile.getName();
        define = define.toUpperCase();
        define = define.substring(0, define.indexOf("."));
        define += "_INCLUDED";
        String syncComment = 
            "/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */\n" +
            "/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE   */\n" +
            "/* ----------------------------------------------------------------   */\n" +
            "/* THIS HEADER FILE PATTERNED AFTER CORRESPONDING hpp HEADER FILE.    */\n" +
            "/* CHANGES TO hpp HEADER FILE MAY NEED TO BE PROPAGATED HERE AND IN   */\n" +
            "/* THE IMPLEMEMTATION OF THE C APIS.                                  */\n" +
            "/*                                                                    */\n" +
            "/* THIS FILE GENERATED BY CBINDINGGENERATOR TOOL.                     */\n" +
            "/* ----------------------------------------------------------------   */\n" +
            "/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE   */\n" +
            "/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */\n";
        String cplusplusStart = "#ifdef __cplusplus\n extern \"C\" {\n#endif\n"; 
        String cplusplusEnd   = "#ifdef __cplusplus\n }\n#endif\n"; 
        int prevPart = FilePart.COMMENT; 
        String text;
        Iterator it = inputFile.getPartIterator();
        while (it.hasNext()) 
        {
            FilePart fp = (FilePart) (it.next());
            if (!foundCopyright
                && (FilePart.DIRECTIVE == fp.getType()
                    || FilePart.ENUM == fp.getType()
                    || FilePart.PROTOTYPE == fp.getType())) 
            {
                outputFile.write("#ifndef " + define);
                outputFile.newLine();
                outputFile.write("#define " + define);
                outputFile.newLine();
                outputFile.newLine();
                outputFile.write(syncComment);  
                outputFile.newLine();
                outputFile.write(cplusplusStart);  
                outputFile.newLine();                
                foundCopyright = true;
            }
            switch (fp.getType()) 
            {
                case FilePart.COMMENT :
                    if (FilePart.COMMENT != prevPart)
                        outputFile.newLine();
                    prevPart = fp.getType();
                    text = fp.toString().trim();
                    StringTokenizer tkzr = new StringTokenizer(text, "\n\r");
                    while (tkzr.hasMoreTokens()) 
                    {
                        String line = tkzr.nextToken().trim();
                        if (-1 == line.indexOf("@author")) 
                        {
                            if (line.startsWith("*"))
                                outputFile.write(" ");
                            outputFile.write(line);
                            outputFile.newLine();
                        }
                    }
                    break;
                case FilePart.DIRECTIVE :
                    if (FilePart.DIRECTIVE != prevPart)
                        outputFile.newLine();
                    prevPart = fp.getType();
                    generateDirective(fp, outputFile, inputFile.getName());
                    break;
                case FilePart.TYPEDEF :
                    prevPart = fp.getType();
                    generateTypedef(fp, outputFile);
                    break;
                case FilePart.METHOD :
                case FilePart.PROTOTYPE :
                    if (FilePart.COMMENT != prevPart
                        && FilePart.METHOD != prevPart
                        && FilePart.PROTOTYPE != prevPart)
                        outputFile.newLine();
                    prevPart = fp.getType();
                    generateFunctionPrototype(fp, outputFile);
                    break;
                case FilePart.ENUM :
                    Utils.rude(
                        "Enums should be wrappered with a typedef so "
                            + "they appear the same in C and C++",
                        inputFile.getName(), 0, fp.toString());
                    break;
            }
        }
        outputFile.newLine();
        outputFile.write(cplusplusEnd);  
        outputFile.newLine();                
        outputFile.write("#endif /* " + define + " */");
        outputFile.newLine();
    }
private void generateHeader ( InputCppSourceCode inputFile , BufferedWriter outputFile ) throws Exception { boolean foundCopyright = false ; String define = inputFile . getName ( ) ; define = define . toUpperCase ( ) ; define = define . substring ( 0 , define . indexOf ( "." ) ) ; define += "_INCLUDED" ; String syncComment = "/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */\n" + "/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE   */\n" + "/* ----------------------------------------------------------------   */\n" + "/* THIS HEADER FILE PATTERNED AFTER CORRESPONDING hpp HEADER FILE.    */\n" + "/* CHANGES TO hpp HEADER FILE MAY NEED TO BE PROPAGATED HERE AND IN   */\n" + "/* THE IMPLEMEMTATION OF THE C APIS.                                  */\n" + "/*                                                                    */\n" + "/* THIS FILE GENERATED BY CBINDINGGENERATOR TOOL.                     */\n" + "/* ----------------------------------------------------------------   */\n" + "/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE   */\n" + "/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */\n" ; String cplusplusStart = "#ifdef __cplusplus\n extern \"C\" {\n#endif\n" ; String cplusplusEnd = "#ifdef __cplusplus\n }\n#endif\n" ; int prevPart = FilePart . COMMENT ; String text ; Iterator it = inputFile . getPartIterator ( ) ; while ( it . hasNext ( ) ) { FilePart fp = ( FilePart ) ( it . next ( ) ) ; if ( ! foundCopyright && ( FilePart . DIRECTIVE == fp . getType ( ) || FilePart . ENUM == fp . getType ( ) || FilePart . PROTOTYPE == fp . getType ( ) ) ) { outputFile . write ( "#ifndef " + define ) ; outputFile . newLine ( ) ; outputFile . write ( "#define " + define ) ; outputFile . newLine ( ) ; outputFile . newLine ( ) ; outputFile . write ( syncComment ) ; outputFile . newLine ( ) ; outputFile . write ( cplusplusStart ) ; outputFile . newLine ( ) ; foundCopyright = true ; } switch ( fp . getType ( ) ) { case FilePart . COMMENT : if ( FilePart . COMMENT != prevPart ) outputFile . newLine ( ) ; prevPart = fp . getType ( ) ; text = fp . toString ( ) . trim ( ) ; StringTokenizer tkzr = new StringTokenizer ( text , "\n\r" ) ; while ( tkzr . hasMoreTokens ( ) ) { String line = tkzr . nextToken ( ) . trim ( ) ; if ( - 1 == line . indexOf ( "@author" ) ) { if ( line . startsWith ( "*" ) ) outputFile . write ( " " ) ; outputFile . write ( line ) ; outputFile . newLine ( ) ; } } break ; case FilePart . DIRECTIVE : if ( FilePart . DIRECTIVE != prevPart ) outputFile . newLine ( ) ; prevPart = fp . getType ( ) ; generateDirective ( fp , outputFile , inputFile . getName ( ) ) ; break ; case FilePart . TYPEDEF : prevPart = fp . getType ( ) ; generateTypedef ( fp , outputFile ) ; break ; case FilePart . METHOD : case FilePart . PROTOTYPE : if ( FilePart . COMMENT != prevPart && FilePart . METHOD != prevPart && FilePart . PROTOTYPE != prevPart ) outputFile . newLine ( ) ; prevPart = fp . getType ( ) ; generateFunctionPrototype ( fp , outputFile ) ; break ; case FilePart . ENUM : Utils . rude ( "Enums should be wrappered with a typedef so " + "they appear the same in C and C++" , inputFile . getName ( ) , 0 , fp . toString ( ) ) ; break ; } } outputFile . newLine ( ) ; outputFile . write ( cplusplusEnd ) ; outputFile . newLine ( ) ; outputFile . write ( "#endif /* " + define + " */" ) ; outputFile . newLine ( ) ; }
Generates a C header file from a C++ header file.
Generates a C header file from a C ++ header file .
// Suppresse newline before copyright // do nothing for other file parts