Compare commits

..

No commits in common. "e780eaa45f97dd379900d269d1bb0c7b0b0af4d5" and "f0b6844feb30050c8f68ae1c3604bf4a231b1ad6" have entirely different histories.

3 changed files with 7 additions and 81 deletions

Binary file not shown.

View File

@ -265,8 +265,6 @@ BAN::Vector<BAN::Vector<BAN::String>> parse_command(BAN::StringView command_view
int execute_command(BAN::Vector<BAN::String>& args, int fd_in, int fd_out);
int source_script(const BAN::String& path);
BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, int fd_out)
{
if (args.empty())
@ -314,15 +312,6 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
ERROR_RETURN("setenv", 1);
}
}
else if (args.front() == "source"sv)
{
if (args.size() != 2)
{
fprintf(fout, "usage: source FILE\n");
return 1;
}
return source_script(args[1]);
}
else if (args.front() == "env"sv)
{
char** current = environ;
@ -645,70 +634,6 @@ int execute_piped_commands(BAN::Vector<BAN::Vector<BAN::String>>& commands)
return exit_codes.back();
}
int parse_and_execute_command(BAN::StringView command)
{
if (command.empty())
return 0;
auto parsed_commands = parse_command(command);
if (parsed_commands.empty())
return 0;
tcsetattr(0, TCSANOW, &old_termios);
int ret = execute_piped_commands(parsed_commands);
tcsetattr(0, TCSANOW, &new_termios);
return ret;
}
int source_script(const BAN::String& path)
{
FILE* fp = fopen(path.data(), "r");
if (fp == nullptr)
ERROR_RETURN("fopen", 1);
int ret = 0;
BAN::String command;
char temp_buffer[128];
while (fgets(temp_buffer, sizeof(temp_buffer), fp))
{
MUST(command.append(temp_buffer));
if (command.back() != '\n')
continue;
command.pop_back();
if (!command.empty())
if (int temp = parse_and_execute_command(command))
ret = temp;
command.clear();
}
if (!command.empty())
if (int temp = parse_and_execute_command(command))
ret = temp;
fclose(fp);
return ret;
}
bool exists(const BAN::String& path)
{
struct stat st;
return stat(path.data(), &st) == 0;
}
int source_shellrc()
{
if (char* home = getenv("HOME"))
{
BAN::String path(home);
MUST(path.append("/.shellrc"sv));
if (exists(path))
return source_script(path);
}
return 0;
}
int character_length(BAN::StringView prompt)
{
int length { 0 };
@ -735,7 +660,7 @@ BAN::String get_prompt()
{
const char* raw_prompt = getenv("PS1");
if (raw_prompt == nullptr)
return "$ "sv;
return ""sv;
BAN::String prompt;
for (int i = 0; raw_prompt[i]; i++)
@ -871,8 +796,7 @@ int main(int argc, char** argv)
if (argc >= 1)
setenv("SHELL", argv[0], true);
source_shellrc();
setenv("PS1", "\e[32m\\u@\\h\e[m:\e[34m\\~\e[m$ ", false);
tcgetattr(0, &old_termios);
@ -977,7 +901,10 @@ int main(int argc, char** argv)
fputc('\n', stdout);
if (!buffers[index].empty())
{
last_return = parse_and_execute_command(buffers[index]);
tcsetattr(0, TCSANOW, &old_termios);
auto commands = parse_command(buffers[index]);
last_return = execute_piped_commands(commands);
tcsetattr(0, TCSANOW, &new_termios);
MUST(history.push_back(buffers[index]));
buffers = history;
MUST(buffers.emplace_back(""sv));

View File

@ -82,9 +82,8 @@ int main()
perror("read");
else
{
size_t percent_times_100 = 10000 * meminfo.phys_pages / meminfo.virt_pages;
printf(" vmem: %zu pages (%zu bytes)\n", meminfo.virt_pages, meminfo.page_size * meminfo.virt_pages);
printf(" pmem: %zu pages (%zu bytes) %zu.%02zu%%\n", meminfo.phys_pages, meminfo.page_size * meminfo.phys_pages, percent_times_100 / 100, percent_times_100 % 100);
printf(" pmem: %zu pages (%zu bytes)\n", meminfo.phys_pages, meminfo.page_size * meminfo.phys_pages);
}
close(fd);