1
0
Files
overlaydirs/print.cc
2025-05-27 11:36:06 +03:00

63 lines
1.5 KiB
C++

/* SPDX-License-Identifier: Apache-2.0
* (c) 2025, Konstantin Demin
*/
#include "print.hh"
#include <cstdio>
#include <cstring>
extern "C" {
#include <unistd.h>
}
static
void print_simple(print_mode mode, const ovl_path_t * root, const ovl_path_t * subpath, const ovl_name_t * name);
// TODO: shell-escape mode
/*
static
void print_escape(print_mode mode, const ovl_path_t * root, const ovl_path_t * subpath, const ovl_name_t * name);
*/
void print_path(print_mode mode, const ovl_path_t * root, const ovl_path_t * subpath, const ovl_name_t * name)
{
// "root" and "name" are mandatory
/* if ((!root) || (!name)) return; */
switch (mode) {
case print_mode::normal: /* -fallthrough */
case print_mode::zero:
print_simple(mode, root, subpath, name);
return;
// TODO: shell-escape mode
/*
case print_mode::shell_escape:
print_escape(mode, root, subpath, name);
return;
*/
}
}
static
void print_simple(print_mode mode, const ovl_path_t * root, const ovl_path_t * subpath, const ovl_name_t * name)
{
// internal method, parameters are already checked
/* if ((!root) || (!name)) return 0; */
char eol = (mode == print_mode::zero) ? 0 : '\n';
if (subpath) {
(void) fprintf(stdout, "%s/%s/%s%c", root->str, subpath->str, name->str, eol);
} else {
(void) fprintf(stdout, "%s/%s%c", root->str, name->str, eol);
}
}
// TODO: shell-escape mode
/*
static
void print_escape(print_mode mode, const ovl_path_t * root, const ovl_path_t * subpath, const ovl_name_t * name)
{
}
*/