annotate liboctave/util/file-info.h @ 27923:bd51beb6205e

update formatting of copyright notices * Use <https://octave.org/copyright/> instead of <https://octave.org/COPYRIGHT.html/>. * For consistency with other comments in the Octave sources, use C++-style comments for copyright blocks in C and C++ files. * Use delimiters above and below copyright blocks that are appropriate for the language used in the file. * Eliminate extra spacing inside copyright blocks. * lex.ll (looks_like_copyright): Also allow newlines and carriage returns before the word "Copyright". * scripts/mk-doc.pl (gethelp): Also skip empty comment lines. * bp-table.cc, type.m: Adjust tests.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Jan 2020 11:59:41 -0500
parents 1891570abac8
children 6b3faa844395 0a5b15007766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 2001-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if ! defined (octave_file_info_h)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #define octave_file_info_h 1
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "octave-config.h"
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <deque>
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <map>
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <string>
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include <vector>
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "oct-time.h"
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 namespace octave
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 class file_info
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 public:
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 file_info (void)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 : m_file_buf (), m_offsets (), m_timestamp (static_cast<time_t> (0))
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 { }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
23730
85f1d31956c0 make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
48 file_info (const std::string& text, const sys::time& timestamp)
85f1d31956c0 make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
49 : m_file_buf (text), m_offsets (get_line_offsets (m_file_buf)),
85f1d31956c0 make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
50 m_timestamp (timestamp)
85f1d31956c0 make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
51 { }
85f1d31956c0 make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
52
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 file_info (const std::string& fname)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 : m_file_buf (snarf_file (fname)),
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 m_offsets (get_line_offsets (m_file_buf)),
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 m_timestamp ()
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 { }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 file_info (const file_info&) = default;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 file_info& operator = (const file_info&) = default;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 ~file_info (void) = default;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 std::string get_line (size_t line) const;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 std::deque<std::string> get_lines (size_t line, size_t num_lines) const;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 size_t num_lines (void) const { return m_offsets.size (); }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 std::string text (void) const { return m_file_buf; }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 std::vector<size_t> line_offsets (void) const { return m_offsets; }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 sys::time timestamp (void) const { return m_timestamp; }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 size_t size (void) const { return m_file_buf.length (); }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 private:
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 // File contents as a string.
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 std::string m_file_buf;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 // Offsets to line beginnings.
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 std::vector<size_t> m_offsets;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 sys::time m_timestamp;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 // Read entire file called fname and return the contents as a string
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 static std::string snarf_file (const std::string& fname);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 static std::vector<size_t> get_line_offsets (const std::string& buf);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 };
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 #endif