<commit_before>/* $Id$ */

#include <sys/types.h>
#include <sys/stat.h>

#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>

#include "pfl/cdefs.h"
#include "pfl/fcntl.h"
#include "pfl/stat.h"
#include "pfl/types.h"

void
pfl_print_flag(const char *str, int *seq)
{
	printf("%s%s", *seq ? "|" : "", str);
	*seq = 1;
}

#define PR_O_FLAG(fl, val, seq)						\
	do {								\
		if ((val) & (fl)) {					\
			pfl_print_flag(#fl, (seq));			\
			(val) &= ~(fl);					\
		}							\
	} while (0)

void
pfl_dump_fflags(int fflags)
{
	int seq = 0;

	PR_O_FLAG(O_WRONLY, fflags, &seq);
	PR_O_FLAG(O_RDWR, fflags, &seq);
	if ((fflags & O_ACCMODE) == O_RDONLY)
		pfl_print_flag("O_RDONLY", &seq);

	PR_O_FLAG(O_CREAT, fflags, &seq);
	PR_O_FLAG(O_EXCL, fflags, &seq);
	PR_O_FLAG(O_TRUNC, fflags, &seq);
	PR_O_FLAG(O_APPEND, fflags, &seq);
	PR_O_FLAG(O_NONBLOCK, fflags, &seq);
	PR_O_FLAG(O_SYNC, fflags, &seq);
	PR_O_FLAG(O_NOCTTY, fflags, &seq);
	PR_O_FLAG(O_NOFOLLOW, fflags, &seq);

	PR_O_FLAG(O_DSYNC, fflags, &seq);
	PR_O_FLAG(O_RSYNC, fflags, &seq);
	PR_O_FLAG(O_ASYNC, fflags, &seq);
	PR_O_FLAG(O_DIRECTORY, fflags, &seq);
	PR_O_FLAG(O_EXLOCK, fflags, &seq);
	PR_O_FLAG(O_SHLOCK, fflags, &seq);

	PR_O_FLAG(O_DIRECT, fflags, &seq);
	PR_O_FLAG(O_CLOEXEC, fflags, &seq);
	PR_O_FLAG(O_SYMLINK, fflags, &seq);
	PR_O_FLAG(O_NOATIME, fflags, &seq);
	PR_O_FLAG(O_LARGEFILE, fflags, &seq);

	if (fflags) {
		pfl_print_flag("", &seq);
		printf("%x", fflags);
	}
	printf("\n");
}

void
pfl_dump_mode(mode_t modes)
{
	char ch, buf[10];
	uint32_t m = modes;

	if (S_ISDIR(m))
		ch = 'd';
	else if (S_ISCHR(m))
		ch = 'c';
	else if (S_ISBLK(m))
		ch = 'b';
	else if (S_ISSOCK(m))
		ch = 's';
	else if (S_ISDIR(m))
		ch = 'd';
	else if (S_ISLNK(m))
		ch = 'l';
	else if (S_ISFIFO(m))
		ch = 'f';
	else if (S_ISREG(m))
		ch = '-';
	else
		ch = '?';

	buf[0] = m & S_IRUSR ? 'r' : '-';
	buf[1] = m & S_IWUSR ? 'w' : '-';
	if (m & S_ISUID)
		buf[2] = m & S_IXUSR ? 's' : 'S';
	else
		buf[2] = m & S_IXUSR ? 'x' : '-';

	buf[3] = m & S_IRGRP ? 'r' : '-';
	buf[4] = m & S_IWGRP ? 'w' : '-';
	if (m & S_ISGID)
		buf[5] = m & S_IXGRP ? 's' : 'S';
	else
		buf[5] = m & S_IXGRP ? 'x' : '-';

	buf[6] = m & S_IROTH ? 'r' : '-';
	buf[7] = m & S_IWOTH ? 'w' : '-';
	if (m & S_ISVTX)
		buf[8] = m & S_IXOTH ? 't' : 'T';
	else
		buf[8] = m & S_IXOTH ? 'x' : '-';
	buf[9] = '\0';
	m &= ~(ALLPERMS | S_IFMT);

	printf("%c%s", ch, buf);
	if (m)
		printf(" unknown bits: %#o\n", m);
	printf("\n");
}

#define psc_log_getlevel(ss)	PLL_MAX

#define _psclog(fn, func, ln, ss, lvl, flg, fmt, ...)			\
	printf(fmt, ## __VA_ARGS__)

void
pfl_dump_statbuf(const struct stat *stb)
{
	DEBUG_STATBUF(PLL_MAX, stb, "");
}<commit_msg>improve output format<commit_after>/* $Id$ */

#include <sys/types.h>
#include <sys/stat.h>

#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>

#include "pfl/cdefs.h"
#include "pfl/fcntl.h"
#include "pfl/stat.h"
#include "pfl/types.h"

void
pfl_print_flag(const char *str, int *seq)
{
	printf("%s%s", *seq ? "|" : "", str);
	*seq = 1;
}

#define PR_O_FLAG(fl, val, seq)						\
	do {								\
		if ((val) & (fl)) {					\
			pfl_print_flag(#fl, (seq));			\
			(val) &= ~(fl);					\
		}							\
	} while (0)

void
pfl_dump_fflags(int fflags)
{
	int seq = 0;

	PR_O_FLAG(O_WRONLY, fflags, &seq);
	PR_O_FLAG(O_RDWR, fflags, &seq);
	if ((fflags & O_ACCMODE) == O_RDONLY)
		pfl_print_flag("O_RDONLY", &seq);

	PR_O_FLAG(O_CREAT, fflags, &seq);
	PR_O_FLAG(O_EXCL, fflags, &seq);
	PR_O_FLAG(O_TRUNC, fflags, &seq);
	PR_O_FLAG(O_APPEND, fflags, &seq);
	PR_O_FLAG(O_NONBLOCK, fflags, &seq);
	PR_O_FLAG(O_SYNC, fflags, &seq);
	PR_O_FLAG(O_NOCTTY, fflags, &seq);
	PR_O_FLAG(O_NOFOLLOW, fflags, &seq);

	PR_O_FLAG(O_DSYNC, fflags, &seq);
	PR_O_FLAG(O_RSYNC, fflags, &seq);
	PR_O_FLAG(O_ASYNC, fflags, &seq);
	PR_O_FLAG(O_DIRECTORY, fflags, &seq);
	PR_O_FLAG(O_EXLOCK, fflags, &seq);
	PR_O_FLAG(O_SHLOCK, fflags, &seq);

	PR_O_FLAG(O_DIRECT, fflags, &seq);
	PR_O_FLAG(O_CLOEXEC, fflags, &seq);
	PR_O_FLAG(O_SYMLINK, fflags, &seq);
	PR_O_FLAG(O_NOATIME, fflags, &seq);
	PR_O_FLAG(O_LARGEFILE, fflags, &seq);

	if (fflags) {
		pfl_print_flag("", &seq);
		printf("%x", fflags);
	}
	printf("\n");
}

void
pfl_dump_mode(mode_t modes)
{
	char ch, buf[10];
	uint32_t m = modes;

	if (S_ISDIR(m))
		ch = 'd';
	else if (S_ISCHR(m))
		ch = 'c';
	else if (S_ISBLK(m))
		ch = 'b';
	else if (S_ISSOCK(m))
		ch = 's';
	else if (S_ISDIR(m))
		ch = 'd';
	else if (S_ISLNK(m))
		ch = 'l';
	else if (S_ISFIFO(m))
		ch = 'f';
	else if (S_ISREG(m))
		ch = '-';
	else
		ch = '?';

	buf[0] = m & S_IRUSR ? 'r' : '-';
	buf[1] = m & S_IWUSR ? 'w' : '-';
	if (m & S_ISUID)
		buf[2] = m & S_IXUSR ? 's' : 'S';
	else
		buf[2] = m & S_IXUSR ? 'x' : '-';

	buf[3] = m & S_IRGRP ? 'r' : '-';
	buf[4] = m & S_IWGRP ? 'w' : '-';
	if (m & S_ISGID)
		buf[5] = m & S_IXGRP ? 's' : 'S';
	else
		buf[5] = m & S_IXGRP ? 'x' : '-';

	buf[6] = m & S_IROTH ? 'r' : '-';
	buf[7] = m & S_IWOTH ? 'w' : '-';
	if (m & S_ISVTX)
		buf[8] = m & S_IXOTH ? 't' : 'T';
	else
		buf[8] = m & S_IXOTH ? 'x' : '-';
	buf[9] = '\0';
	m &= ~(ALLPERMS | S_IFMT);

	printf("%c%s", ch, buf);
	if (m)
		printf(" unknown bits: %#o\n", m);
	printf("\n");
}

#define psc_log_getlevel(ss)	PLL_MAX

#define _psclog(fn, func, ln, ss, lvl, flg, fmt, ...)			\
	do {								\
		fprintf(stderr, fmt, ## __VA_ARGS__);			\
		fprintf(stderr, "\n");					\
	} while (0)

void
pfl_dump_statbuf(const struct stat *stb)
{
	DEBUG_STATBUF(PLL_MAX, stb, "");
}
{'fraction_non_alphanumeric': 0.21969974368363238, 'fraction_numerical': 0.007872574148663493, 'mean_word_length': 3.5449251247920133, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2536474', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2870, 'n_words': 558}