All: Cleanup all files

Add newline to end of files and remove whitespace from end of lines
This commit is contained in:
2024-01-24 14:43:46 +02:00
parent 3441f63298
commit dfe5a2d665
226 changed files with 466 additions and 460 deletions

View File

@@ -26,7 +26,7 @@ static BAN::String hostname;
static void clean_exit()
{
tcsetattr(0, TCSANOW, &old_termios);
exit(0);
exit(0);
}
BAN::Vector<BAN::Vector<BAN::String>> parse_command(BAN::StringView);
@@ -42,7 +42,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
{
i++;
return BAN::String::formatted("{}", last_return);
}
}
if (isalnum(command[i]))
{
size_t len = 1;
@@ -436,7 +436,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
if (clock_gettime(CLOCK_MONOTONIC, &end) == -1)
ERROR_RETURN("clock_gettime", 1);
uint64_t total_ns = 0;
total_ns += (end.tv_sec - start.tv_sec) * 1'000'000'000;
total_ns += end.tv_nsec - start.tv_nsec;
@@ -683,9 +683,9 @@ int source_script(const BAN::String& path)
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;
@@ -769,7 +769,7 @@ BAN::String get_prompt()
char buffer[256];
if (getcwd(buffer, sizeof(buffer)) == nullptr)
strcpy(buffer, strerrorname_np(errno));
const char* home = getenv("HOME");
size_t home_len = home ? strlen(home) : 0;
if (home && strncmp(buffer, home, home_len) == 0)
@@ -817,7 +817,7 @@ BAN::String get_prompt()
{
MUST(prompt.push_back(ch));
}
}
}
return prompt;
}
@@ -883,7 +883,7 @@ int main(int argc, char** argv)
if (argc >= 1)
setenv("SHELL", argv[0], true);
source_shellrc();
new_termios = old_termios;
@@ -940,7 +940,7 @@ int main(int argc, char** argv)
waiting_utf8 = 3;
else
ASSERT_NOT_REACHED();
fputc(ch, stdout);
MUST(buffers[index].insert(ch, col++));
continue;

View File

@@ -111,7 +111,7 @@ i64 puzzle1(FILE* fp)
{
if (positions[0].x == positions[1].x && positions[0].y == positions[1].y)
return distance;
for (auto& position : positions)
{
Direction direction = tile_exit_direction(grid[position.y][position.x], position.from);
@@ -140,7 +140,7 @@ i64 puzzle2(FILE* fp)
auto position = find_grid_first_moves(grid)[0];
while ((grid[position.y][position.x] & ~Flag::Mask) != 'S')
{
{
Direction direction = tile_exit_direction(grid[position.y][position.x] & ~Flag::Mask, position.from);
switch (grid[position.y][position.x] & ~Flag::Mask)
@@ -196,7 +196,7 @@ i64 puzzle2(FILE* fp)
// Mark start tile as part of the path
grid[position.y][position.x] |= Flag::Path;
// Clean up flags
for (auto& row : grid)
{

View File

@@ -84,7 +84,7 @@ i64 solution(FILE* fp, u64 expansion)
const u64 x2 = j % map[0].size();
if (map[y2][x2] != '#')
continue;
result += distance_with_expansion(map, x1, y1, x2, y2, expansion);
}
}

View File

@@ -53,7 +53,7 @@ i64 count_possibilities(BAN::StringView record, BAN::Span<u64> groups)
for (size_t i = 0; i + groups[0] <= record.size(); i++)
{
bool valid = true;
if (record.substring(i, groups[0]).contains('.'))
valid = false;
@@ -91,7 +91,7 @@ i64 puzzle1(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.size() < 3)
continue;
auto parts = MUST(line.split(' '));
auto record = parts[0];
@@ -119,7 +119,7 @@ i64 puzzle2(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.size() < 3)
continue;
auto parts = MUST(line.split(' '));
BAN::String record;

View File

@@ -191,7 +191,7 @@ i64 puzzle2(FILE* fp)
tilt_platform(platform, Direction::North);
tilt_platform(platform, Direction::West);
tilt_platform(platform, Direction::South);
tilt_platform(platform, Direction::East);
tilt_platform(platform, Direction::East);
}
i64 result = 0;

View File

@@ -69,7 +69,7 @@ Grid parse_grid(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.empty())
break;
MUST(grid.emplace_back(line.size()));
for (size_t i = 0; i < line.size(); i++)
grid.back()[i] = char_to_tile(line[i]);

View File

@@ -52,7 +52,7 @@ BAN::Vector<BAN::Vector<i64>> parse_grid(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.empty())
break;
MUST(grid.emplace_back(line.size()));
for (size_t i = 0; i < line.size(); i++)
grid.back()[i] = line[i] - '0';
@@ -95,7 +95,7 @@ i64 solve_general(FILE* fp)
BAN::HashSet<Position> visited;
BAN::HashSet<Position> pending;
MUST(pending.insert({ 0, 0 }));
while (!pending.empty())
{
auto position = *pending.begin();
@@ -175,7 +175,7 @@ i64 puzzle1(FILE* fp)
i64 puzzle2(FILE* fp)
{
return solve_general<4, 10>(fp);
return solve_general<4, 10>(fp);
}
int main(int argc, char** argv)

View File

@@ -153,7 +153,7 @@ i64 solve_general(FILE* fp, auto parse_dir, auto parse_count)
i32 rmin_x = INT32_MAX;
find_min_and_remove_duplicates(rpath, lpath, rmin_x);
ASSERT(lmin_x != rmin_x);
auto& expand = (lmin_x < rmin_x) ? rpath : lpath;
@@ -177,7 +177,7 @@ i64 solve_general(FILE* fp, auto parse_dir, auto parse_count)
MUST(visited.insert(next));
}
}
return path.size() + inner_area.size();
}

View File

@@ -140,7 +140,7 @@ BAN::Vector<Item> parse_items(FILE* fp)
item.values[1] = parse_i64(values[1].substring(2));
item.values[2] = parse_i64(values[2].substring(2));
item.values[3] = parse_i64(values[3].substring(2));
MUST(items.push_back(item));
}
@@ -245,15 +245,15 @@ i64 puzzle2(FILE* fp)
}};
if (!is_accepted(item, "in"sv, workflows))
continue;
i64 x_count = values_sorted[0][xi + 1] - values_sorted[0][xi];
i64 m_count = values_sorted[1][mi + 1] - values_sorted[1][mi];
i64 a_count = values_sorted[2][ai + 1] - values_sorted[2][ai];
i64 s_count = values_sorted[3][si + 1] - values_sorted[3][si];
result += x_count * m_count * a_count * s_count;
}
}
}
}
}
timespec time_stop;

View File

@@ -24,7 +24,7 @@ int puzzle1(FILE* fp)
if (strncmp("Game ", ptr, 5))
continue;
ptr += 5;
int id = parse_int_and_advance(ptr);
ptr += 2;
@@ -63,7 +63,7 @@ int puzzle2(FILE* fp)
if (strncmp("Game ", ptr, 5))
continue;
ptr += 5;
parse_int_and_advance(ptr);
ptr += 2;

View File

@@ -131,7 +131,7 @@ i64 puzzle1(FILE* fp)
auto modules = parse_modules(fp);
BAN::Queue<Signal> signal_queue;
i64 sent_hi = 0;
i64 sent_lo = 0;

View File

@@ -104,7 +104,7 @@ i64 puzzle1(FILE* fp)
MUST(visited.insert(position));
if (i % 2 == 0)
MUST(reachable.insert(position));
Position offsets[4] { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
for (i32 j = 0; j < 4; j++)
{

View File

@@ -29,7 +29,7 @@ BAN::Vector<BAN::Vector<char>> parse_grid(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.empty())
break;
MUST(grid.emplace_back(line.size(), '\0'));
for (size_t i = 0; i < line.size(); i++)
grid.back()[i] = line[i];
@@ -86,7 +86,7 @@ i64 recurse_grid(BAN::Vector<Position>& path, const BAN::Vector<BAN::Vector<char
if (valid_next_count == 0)
return 0;
if (valid_next_count == 1)
{
MUST(path.push_back(valid_next.front()));

View File

@@ -46,7 +46,7 @@ BAN::Vector<Hailstone> parse_hailstones(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.empty())
break;
auto position_velocity_strs = MUST(line.split('@'));
ASSERT(position_velocity_strs.size() == 2);
@@ -73,7 +73,7 @@ BAN::Vector<Hailstone> parse_hailstones(FILE* fp)
i64 puzzle1(FILE* fp)
{
auto hailstones = parse_hailstones(fp);
i64 result = 0;
for (size_t i = 0; i < hailstones.size(); i++)

View File

@@ -37,7 +37,7 @@ BAN::HashMap<BAN::String, Component> parse_components(FILE* fp)
line = line.substring(0, line.size() - 1);
if (line.empty())
break;
auto parts = MUST(line.split(' '));
ASSERT(parts.size() >= 2);
@@ -46,7 +46,7 @@ BAN::HashMap<BAN::String, Component> parse_components(FILE* fp)
if (!components.contains(parts.front()))
MUST(components.emplace(parts.front(), parts.front()));
for (size_t i = 1; i < parts.size(); i++)
{
MUST(components[parts.front()].connections.emplace_back(parts[i]));
@@ -96,7 +96,7 @@ size_t graph_size(const BAN::HashMap<BAN::String, Component>& graph, const BAN::
const auto& targets = graph[current].connections;
for (const auto& target : targets)
{
if (removed.contains(connection_key(current, target)))
if (removed.contains(connection_key(current, target)))
continue;
if (visited.contains(target))
continue;

View File

@@ -17,14 +17,14 @@ int puzzle1(FILE* fp)
{
buffer[strlen(buffer) - 1] = '\0';
MUST(lines.emplace_back(buffer));
}
}
int result = 0;
for (size_t y = 0; y < lines.size(); y++)
{
for (size_t x = 0; x < lines[y].size(); x++)
{
{
if (!isdigit(lines[y][x]))
continue;
@@ -52,7 +52,7 @@ int puzzle1(FILE* fp)
should_add = true;
break;
}
}
}
if (should_add)
break;
@@ -88,7 +88,7 @@ int puzzle2(FILE* fp)
{
buffer[strlen(buffer) - 1] = '\0';
MUST(lines.emplace_back(buffer));
}
}
// Didn't want to think about O(1) space, this is much simpler.
// Map numbers next to '*' to asterisk's coordinates.

View File

@@ -26,7 +26,7 @@ i64 puzzle1(FILE* fp)
char buffer[256];
if (!fgets(buffer, sizeof(buffer), fp))
return -1;
{
BAN::StringView line(buffer);
line = line.substring(0, line.size() - 1);
@@ -88,7 +88,7 @@ i64 puzzle2(FILE* fp)
char buffer[256];
if (!fgets(buffer, sizeof(buffer), fp))
return -1;
{
BAN::StringView line(buffer);
line = line.substring(0, line.size() - 1);

View File

@@ -39,7 +39,7 @@ BAN::ErrorOr<BAN::UniqPtr<Image>> load_netbpm(const void* mmap_addr, size_t size
}
const uint8_t* u8_ptr = reinterpret_cast<const uint8_t*>(mmap_addr);
if (u8_ptr[0] != 'P')
{
fprintf(stderr, "not Netbpm image\n");

View File

@@ -14,7 +14,7 @@ int main(int argc, char** argv)
{
if (argc != 2)
return usage(argv[0], 1);
auto image = Image::load_from_file(argv[1]);
if (!image)
return 1;

View File

@@ -106,9 +106,9 @@ int main()
exit(1);
}
endpwent();
if (pid == -1)
{
perror("fork");

View File

@@ -24,7 +24,7 @@ int main(int argc, char** argv)
struct stat st;
if (stat(argv[1], &st) == 0)
return try_load_keymap(argv[1]);
char buffer[128];
strcpy(buffer, "/usr/share/keymaps/");
strcat(buffer, argv[1]);

View File

@@ -73,7 +73,7 @@ int main()
{
strcpy(path_buffer, proc_ent->d_name);
strcat(path_buffer, "/meminfo");
int fd = openat(dirfd(proc), path_buffer, O_RDONLY);
if (fd == -1)
{

View File

@@ -112,7 +112,7 @@ int main(int argc, char** argv)
ret = 1;
continue;
}
if (S_ISDIR(st.st_mode))
{
fprintf(stderr, "%s: %s\n", argv[i], strerror(EISDIR));

View File

@@ -14,7 +14,7 @@ int main(int argc, char** argv)
{
if (argc != 2)
return usage(argv[0], 1);
if (strlen(argv[1]) > 9)
{
fprintf(stderr, "SECONDS argument too large\n");

View File

@@ -12,7 +12,7 @@ int main(int argc, char** argv)
{
if (argc < 2)
return usage(argv[0], 1);
if (setuid(0) == -1)
{
perror("setuid");

View File

@@ -32,7 +32,7 @@ int main(int argc, char** argv)
perror(argv[i]);
else
file_count++;
if (file_count >= MAX_FILES)
{
fprintf(stderr, "only up to %d files are supported\n", MAX_FILES);
@@ -54,7 +54,7 @@ int main(int argc, char** argv)
}
free(buffer);
if (ferror(stdin))
if (ferror(stdin))
perror("stdin");
for (size_t i = 0; i < file_count; i++)

View File

@@ -124,13 +124,13 @@ int main(int argc, char** argv)
perror("tcsetattr");
return 1;
}
uint32_t color = 0xFF0000;
int mouse_x = fb_info.width / 2;
int mouse_y = fb_info.height / 2;
int radius = 10;
// clear screen and render
// clear screen and render
memset(fb_mmap, 0x00, fb_bytes);
draw_circle(mouse_x, mouse_y, radius, color);
msync(fb_mmap, fb_bytes, MS_SYNC);
@@ -138,7 +138,7 @@ int main(int argc, char** argv)
while (true)
{
using namespace Kernel::Input;
MouseEvent event;
if (read(mouse_fd, &event, sizeof(event)) == -1)
{