2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-09-21 00:47:31 +03:00
|
|
|
#include "ManualSectionNode.h"
|
|
|
|
#include "ManualPageNode.h"
|
2020-05-26 14:52:44 +03:00
|
|
|
#include <AK/LexicalPath.h>
|
2020-04-23 19:43:40 +02:00
|
|
|
#include <AK/QuickSort.h>
|
2019-09-21 00:47:31 +03:00
|
|
|
#include <AK/String.h>
|
2020-02-06 15:04:03 +01:00
|
|
|
#include <LibCore/DirIterator.h>
|
2019-09-21 00:47:31 +03:00
|
|
|
|
|
|
|
String ManualSectionNode::path() const
|
|
|
|
{
|
|
|
|
return String::format("/usr/share/man/man%s", m_section.characters());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManualSectionNode::reify_if_needed() const
|
|
|
|
{
|
|
|
|
if (m_reified)
|
|
|
|
return;
|
|
|
|
m_reified = true;
|
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
Core::DirIterator dir_iter { path(), Core::DirIterator::Flags::SkipDots };
|
2019-09-21 00:47:31 +03:00
|
|
|
|
2020-04-23 19:43:40 +02:00
|
|
|
Vector<String> page_names;
|
2019-09-21 00:47:31 +03:00
|
|
|
while (dir_iter.has_next()) {
|
2020-05-26 14:52:44 +03:00
|
|
|
LexicalPath lexical_path(dir_iter.next_path());
|
|
|
|
if (lexical_path.extension() != "md")
|
2019-09-28 18:38:27 +02:00
|
|
|
continue;
|
2020-05-26 14:52:44 +03:00
|
|
|
page_names.append(lexical_path.title());
|
2019-09-21 00:47:31 +03:00
|
|
|
}
|
2020-04-23 19:43:40 +02:00
|
|
|
|
|
|
|
quick_sort(page_names);
|
|
|
|
|
|
|
|
for (auto& page_name : page_names)
|
|
|
|
m_children.append(make<ManualPageNode>(*this, move(page_name)));
|
2019-09-21 00:47:31 +03:00
|
|
|
}
|