Ejemplo n.º 1
0
        /// <summary>processes an include directive</summary>
        /// <exception cref="Ch.Elca.Iiop.IdlPreprocessor.IllegalPreprocDirectiveException">
        /// illegal include directive encountered
        /// </exception>
        private void ProcessInclude(String currentLine)
        {
            currentLine = currentLine.Trim();
            String[] tokens = s_tokenSplitEx.Split(currentLine);
            if (tokens.Length != 2)
            {
                throw new IllegalPreprocDirectiveException(currentLine,
                                                           "file argument not found / more than one argument");
            }

            // fileToInclude enclosed in quotation mark: search in current directory for file
            // fileToInclude enclosed in <>: search in compiler include dir!
            String   fileToInclude = tokens[1];
            FileInfo toInclude     = null;
            char     ch0           = fileToInclude[0];
            char     ch1           = fileToInclude[fileToInclude.Length - 1];

            fileToInclude = fileToInclude.Substring(1, fileToInclude.Length - 2);

            if ((ch0 == '"') && (ch1 == '"'))
            {
                toInclude = new FileInfo(Path.Combine(m_thisFileDirectory.FullName, fileToInclude)); // search in the directory, the file containing the include is in
            }
            else if ((ch0 != '<') || (ch1 != '>'))
            {
                throw new IllegalPreprocDirectiveException(currentLine);
            }
            if ((toInclude == null) || (!toInclude.Exists))
            {
                toInclude = GetFile(fileToInclude);
            }

            IDLPreprocessor includePreproc = new IDLPreprocessor(toInclude,
                                                                 m_defined);

            includePreproc.Process();
            MemoryStream result = includePreproc.GetProcessed();

            // copy result into current output stream
            CopyToOutputStream(result);
        }
Ejemplo n.º 2
0
        /// <summary>processes an include directive</summary>
        /// <exception cref="Ch.Elca.Iiop.IdlPreprocessor.IllegalPreprocDirectiveException">
        /// illegal include directive encountered
        /// </exception>
        private void ProcessInclude(String currentLine) {
            currentLine = currentLine.Trim();
            String[] tokens = s_tokenSplitEx.Split(currentLine);
            if (tokens.Length != 2) { 
                throw new IllegalPreprocDirectiveException(currentLine, 
                                                           "file argument not found / more than one argument");
            }
            
            // fileToInclude enclosed in quotation mark: search in current directory for file
            // fileToInclude enclosed in <>: search in compiler include dir!
            String fileToInclude = tokens[1];
            FileInfo toInclude = null;
            char ch0 = fileToInclude[0];
            char ch1 = fileToInclude[fileToInclude.Length-1];
            fileToInclude = fileToInclude.Substring(1, fileToInclude.Length - 2);

            if ((ch0 == '"') && (ch1 == '"')) {
                toInclude = new FileInfo(Path.Combine(m_thisFileDirectory.FullName, fileToInclude)); // search in the directory, the file containing the include is in
            } else if ((ch0 != '<') || (ch1 != '>')) {
                throw new IllegalPreprocDirectiveException(currentLine);
            }
            if ((toInclude == null) || (!toInclude.Exists)) {
                toInclude = GetFile(fileToInclude);
            }
                
            IDLPreprocessor includePreproc = new IDLPreprocessor(toInclude, 
                                                                 m_defined);
            includePreproc.Process();
            MemoryStream result = includePreproc.GetProcessed();
            // copy result into current output stream
            CopyToOutputStream(result);
        }
Ejemplo n.º 3
0
    private MemoryStream Preprocess(String fileName) {
        FileInfo file = new FileInfo(fileName);
        // all Preprocessor instances share the same symbol definitions
        IDLPreprocessor preproc = new IDLPreprocessor(file);
        preproc.Process();
        MemoryStream resultProc = preproc.GetProcessed();

        // debug print, create a new memory stream to protect resultProc from beeing manipulated...
        MemoryStream forRead = new MemoryStream();
        resultProc.WriteTo(forRead);
        forRead.Seek(0, SeekOrigin.Begin); 
        Encoding latin1 = Encoding.GetEncoding("ISO-8859-1");
        StreamReader stReader = new StreamReader(forRead, latin1);
        String line = "";
        while (line != null) {
            Debug.WriteLine(line);
            line = stReader.ReadLine();
        }
        stReader.Close();

        // make sure, resultStream is at the beginning
        resultProc.Seek(0, SeekOrigin.Begin);
        return resultProc;
    }