Ejemplo n.º 1
0
        //------------------------------------------------------------
        // CSourceText.Initialize
        //
        /// <summary>
        /// Read the source file.
        /// </summary>
        /// <param name="fileName">source file name.</param>
        /// <param name="computeChecksum">If true, calculate the checksum.</param>
        /// <param name="encoding">Encoding instance of the source text</param>
        /// <param name="controller">To output error messages.</param>
        /// <returns>If failed to read the file, return false.</returns>
        //------------------------------------------------------------
        internal bool Initialize(
            FileInfo srcFileInfo,
            bool computeChecksum,
            System.Text.Encoding encoding,
            CController controller)
        {
            Exception excp = null;

            // Remember the file name as given to us
            this.sourceFileInfo = srcFileInfo;
            if (srcFileInfo == null)
            {
                sourceText = null;
                return(false);
            }

            if (!IOUtil.ReadTextFile(srcFileInfo.FullName, encoding, out sourceText, out excp))
            {
                sourceText = null;
                controller.ReportError(ERRORKIND.ERROR, excp);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------------
        // CSConsoleArgs.ExpandResponseFiles
        //
        /// <summary>
        /// <para>(ConsoleArgs::ProcessResponseArgs in sscli.)</para>
        /// <para>Process Response files on the command line
        /// Returns true if it allocated a new argv array that must be freed later</para>
        /// <para>コマンドラインでレスポンスファイルが指定されていたら、
        /// その内容をオプションリストに追加する。
        /// (レスポンスファイルは @ファイル名 の形式で指定されている。)</para>
        /// </summary>
        //------------------------------------------------------------
        private void ExpandResponseFiles()
        {
            Dictionary <string, bool> processedResponseFiles
                = new Dictionary <string, bool>(new StringEqualityComparerIgnoreCase());
            List <string[]> listTemp     = null;
            string          fileName     = null;
            string          fullName     = null;
            string          fileContents = null;
            Exception       excp         = null;
            bool            foundResponseFile;
            int             loopCount    = 0;
            const int       maxLoopCount = 32;

            do
            {
                if (loopCount >= maxLoopCount)
                {
                    throw new Exception("Too many nested response file.");
                }

                listTemp          = new List <string[]>();
                foundResponseFile = false;
                foreach (string[] opt in this.OptionList)
                {
                    // オプションが null や空の場合は破棄する。
                    if (opt == null || opt.Length == 0)
                    {
                        continue;
                    }
                    // 1 文字目が @ でないものはそのままリストに追加する。
                    if (opt[1] != "@")
                    {
                        listTemp.Add(opt);
                        continue;
                    }

                    if (opt.Length <= 2 || String.IsNullOrEmpty(opt[2]))
                    {
                        this.Controller.ReportError(
                            CSCERRID.ERR_NoFileSpec,
                            ERRORKIND.ERROR,
                            opt[0]);
                        continue;
                    }

                    // Check for duplicates
                    // @ と引用符を外す。
                    fileName = opt[2];

                    IOUtil.RemoveQuotes(ref fileName);

                    if (String.IsNullOrEmpty(fileName))
                    {
                        this.Controller.ReportError(
                            CSCERRID.ERR_NoFileSpec,
                            ERRORKIND.ERROR,
                            opt[0]);
                        continue;
                    }

                    // ファイルのフルパスを求める。
                    fullName = this.GetFullFileName(fileName, false);
                    if (String.IsNullOrEmpty(fullName))
                    {
                        this.Controller.ReportError(
                            CSCERRID.ERR_NoFileSpec,
                            ERRORKIND.ERROR,
                            opt[0]);
                        continue;
                    }

                    // 得られたファイルがすでに処理されていないか調べる。
                    try
                    {
                        if (processedResponseFiles.ContainsKey(fullName))
                        {
                            continue;
                        }
                    }
                    catch (ArgumentException)
                    {
                        DebugUtil.Assert(false);
                        continue;
                    }

                    // ファイルの内容を読み込む。エラーの場合はメッセージを表示して次へ。
                    if (!IOUtil.ReadTextFile(fullName, null, out fileContents, out excp))
                    {
                        this.Controller.ReportError(ERRORKIND.ERROR, excp.Message);
                        continue;
                    }

                    // レスポンスファイル内で指定されているオプションを取得する。
                    TextToArgs(fileContents, listTemp);
                    foundResponseFile = true;

                    // 処理済みファイルのリストに追加する。
                    processedResponseFiles.Add(fullName, true);
                }
                this.OptionList = listTemp;
                ++loopCount;
            } while (foundResponseFile);
        }