/// <summary> /// Look in the first file for args embedded as comments. This gathers comments /// that come before any data line that start with #@. /// </summary> public static string GetEmbeddedArgs(IMultiStreamSource files) { Contracts.AssertValue(files); if (files.Count == 0) { return(null); } StringBuilder sb = new StringBuilder(); using (var rdr = files.OpenTextReader(0)) { string pre = ""; for (; ;) { string text = rdr.ReadLine(); if (text == null) { break; } if (text.Length == 0) { continue; } if (text.StartsWith("//")) { continue; } if (text[0] != '#') { break; } if (text.Length <= 2 || text[1] != '@') { continue; } sb.Append(pre).Append(text.Substring(2).Trim()); pre = " "; } } return(sb.ToString()); }
private void ThreadProc() { Contracts.Assert(_batchSize >= 2); try { if (_limit <= 0) { return; } long total = 0; long batch = -1; for (int ifile = 0; ifile < _files.Count; ifile++) { string path = _files.GetPathOrNull(ifile); using (var rdr = _files.OpenTextReader(ifile)) { string text; long line = 0; for (; ;) { // REVIEW: Avoid allocating a string for every line. This would probably require // introducing a CharSpan type (similar to DvText but based on char[] or StringBuilder) // and implementing all the necessary conversion functionality on it. See task 3871. text = rdr.ReadLine(); if (text == null) { goto LNext; } line++; if (text.Length > 0 && text[0] != '#' && !text.StartsWith("//")) { break; } } // REVIEW: Use a pool of batches? int index = 0; var infos = new LineInfo[_batchSize]; if (!_hasHeader) { // Not a header or comment, so first line is a real line. infos[index++] = new LineInfo(line, text); if (++total >= _limit) { PostPartial(path, total - index, ref batch, index, infos); return; } } for (; ;) { if (_abort) { return; } text = rdr.ReadLine(); if (text == null) { // We're done with this file. Queue the last partial batch. PostPartial(path, total - index, ref batch, index, infos); goto LNext; } line++; // Filter out comments and empty strings. if (text.Length >= 2) { // Don't use string.StartsWith("//") - it is too slow. if (text[0] == '/' && text[1] == '/') { continue; } } else if (text.Length == 0) { continue; } infos[index] = new LineInfo(line, text); if (++index >= infos.Length) { batch++; var lines = new LineBatch(path, total - index + 1, batch, infos); while (!_queue.TryAdd(lines, TimeOut)) { if (_abort) { return; } } infos = new LineInfo[_batchSize]; index = 0; } if (++total >= _limit) { PostPartial(path, total - index, ref batch, index, infos); return; } } LNext: ; } } } catch (Exception ex) { while (!_queue.TryAdd(new LineBatch(ex), TimeOut)) { if (_abort) { return; } } } finally { _queue.CompleteAdding(); } }