<commit_before>#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "dot_matrix_font_to_bmp.h"
#include "encoding_convert.h"
#include "bmp_io.h"
#include "debug_log.h"

#define GB2312_HZK	"gb2312.hzk"
#define ASCII_HZK	"ASC16"
#define FONT_BMP_SIZE	1024

struct text_style {
	uint32_t left_margin;
	uint32_t right_margin;
	uint32_t up_margin;
	uint32_t down_margin;
	uint32_t line_spacing;
	uint32_t character_spacing;
	uint32_t max_line_length;
};

int main(int argc, char **argv)
{
	int opt;
	struct text_style style = {0};
	uint32_t bits_per_pix = 16;
	int color_anti_flag = 0;
	FILE *in = stdin;
	int gb2312_num;
	uint16_t *mem_addr;
	uint8_t linebuf[MAX_LINE];
	uint8_t gb2312buf[MAX_LINE * 2];
	uint8_t *ptr;
	uint8_t *ptr_gb2312;
	uint8_t unicode[2] = {0};
	uint16_t gb2312_code;
	uint8_t *addr_fd_in;
	struct stat fd_stat;
	int font_fd;
	int ascii_fd;
	struct stat ascii_fd_stat;
	uint8_t *addr_ascii_fd_in;
	int once_read;
	int i;
	uint32_t offset;
	bmp_file_t bmp_char;
	bmp_file_t bmp_line;
	bmp_file_t bmp_all;
	bmp_file_t bmp_blank;
	int ret;

	while ((opt = getopt(argc, argv, "l:r:u:d:i:c:m:b:o")) != -1) {
		switch (opt) {
		case 'l': /* 左边距 */
			style.left_margin = strtol(optarg, NULL, 0);
			break;
		case 'r': /* 右边距 */
			style.right_margin = strtol(optarg, NULL, 0);
			break;
		case 'u': /* 上边距 */
			style.up_margin = strtol(optarg, NULL, 0);
			break;
		case 'd': /* 下边距 */
			style.down_margin = strtol(optarg, NULL, 0);
			break;
		case 'i': /* 行间距 */
			style.line_spacing = strtol(optarg, NULL, 0);
			break;
		case 'c': /* 字符间距 */
			style.character_spacing = strtol(optarg, NULL, 0);
			break;
		case 'm': /* 每行最大长度 */
			style.max_line_length = strtol(optarg, NULL, 0);
			break;
		case 'b': /* 位深 */
			bits_per_pix = strtol(optarg, NULL, 0);
			break;
		case 'o': /* 白底黑字 */
			color_anti_flag = 1;
			break;
		default:
			fprintf(stderr, "Usage: %s [-l left_margin] "
					"[-r right_margin] "
					"[-u up_margin] "
					"[-d down_margin] "
					"[-i line_spacing] "
					"[-c character_spacing] "
					"[-m max_line_length] "
					"[-b bits_per_pix] "
					"[-o] "
					"[inputfile]\n", argv[0]);
			exit(1);
		}
	} /* while ((opt = getopt(argc, argv, "l:r:u:d:i:c:m:b:o:")) != -1) */
	if (argc > optind) {
		in = fopen(argv[optind], "r");
		if (!in) {
			fprintf(stderr,
				"Unable to open input file \"%s\": %s\n",
				argv[optind], strerror(errno));
			return 1;
		}
	}

	mem_addr = mem_gb2312("./GB2312", &gb2312_num);

	font_fd = open(GB2312_HZK, O_RDONLY);
	if (font_fd < 0) {
		perror("open");
		exit(1);
	}
	ret = fstat(font_fd, &fd_stat);
	if (ret == -1) {
		perror("fstat");
		exit(1);
	}
	addr_fd_in = mmap(NULL, (size_t) fd_stat.st_size,
			  PROT_READ, MAP_PRIVATE, font_fd, (off_t) 0);
	if (addr_fd_in == MAP_FAILED) {
		perror("mmap");
		exit(1);
	}<commit_msg>added show_usage()<commit_after>#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "dot_matrix_font_to_bmp.h"
#include "encoding_convert.h"
#include "bmp_io.h"
#include "debug_log.h"

#define GB2312_HZK	"gb2312.hzk"
#define ASCII_HZK	"ASC16"
#define FONT_BMP_SIZE	1024

struct text_style {
	uint32_t left_margin;
	uint32_t right_margin;
	uint32_t up_margin;
	uint32_t down_margin;
	uint32_t line_spacing;
	uint32_t character_spacing;
	uint32_t max_line_length;
};

static void show_usage(const char *pro_name);

static void show_usage(const char *pro_name)
{
	fprintf(stderr, "Usage: %s [Options] [inputfile]\n", pro_name);
	fprintf(stderr, "\n");
	fprintf(stderr, "Options:\n");
	fprintf(stderr, "        -l val        set left margin\n");
	fprintf(stderr, "        -r val        set right margin\n");
	fprintf(stderr, "        -u val        set top margin\n");
	fprintf(stderr, "        -d val        set bottom margin\n");
	fprintf(stderr, "        -i val        set line spacing\n");
	fprintf(stderr, "        -c val        set character spacing\n");
	fprintf(stderr, "        -m val        set max line length\n");
	fprintf(stderr, "        -b val        set bits_per_pix\n");
	fprintf(stderr, "        -o            anti_color\n");
	fprintf(stderr, "\n");
}

int main(int argc, char **argv)
{
	int opt;
	struct text_style style = {0};
	uint32_t bits_per_pix = 16;
	int color_anti_flag = 0;
	FILE *in = stdin;
	int gb2312_num;
	uint16_t *mem_addr;
	uint8_t linebuf[MAX_LINE];
	uint8_t gb2312buf[MAX_LINE * 2];
	uint8_t *ptr;
	uint8_t *ptr_gb2312;
	uint8_t unicode[2] = {0};
	uint16_t gb2312_code;
	uint8_t *addr_fd_in;
	struct stat fd_stat;
	int font_fd;
	int ascii_fd;
	struct stat ascii_fd_stat;
	uint8_t *addr_ascii_fd_in;
	int once_read;
	int i;
	uint32_t offset;
	bmp_file_t bmp_char;
	bmp_file_t bmp_line;
	bmp_file_t bmp_all;
	bmp_file_t bmp_blank;
	int ret;

	while ((opt = getopt(argc, argv, "l:r:u:d:i:c:m:b:o")) != -1) {
		switch (opt) {
		case 'l': /* 左边距 */
			style.left_margin = strtol(optarg, NULL, 0);
			break;
		case 'r': /* 右边距 */
			style.right_margin = strtol(optarg, NULL, 0);
			break;
		case 'u': /* 上边距 */
			style.up_margin = strtol(optarg, NULL, 0);
			break;
		case 'd': /* 下边距 */
			style.down_margin = strtol(optarg, NULL, 0);
			break;
		case 'i': /* 行间距 */
			style.line_spacing = strtol(optarg, NULL, 0);
			break;
		case 'c': /* 字符间距 */
			style.character_spacing = strtol(optarg, NULL, 0);
			break;
		case 'm': /* 每行最大长度 */
			style.max_line_length = strtol(optarg, NULL, 0);
			break;
		case 'b': /* 位深 */
			bits_per_pix = strtol(optarg, NULL, 0);
			break;
		case 'o': /* 白底黑字 */
			color_anti_flag = 1;
			break;
		default:
			show_usage(argv[0]);
			exit(1);
		}
	} /* while ((opt = getopt(argc, argv, "l:r:u:d:i:c:m:b:o:")) != -1) */
	if (argc > optind) {
		in = fopen(argv[optind], "r");
		if (!in) {
			fprintf(stderr,
				"Unable to open input file \"%s\": %s\n",
				argv[optind], strerror(errno));
			return 1;
		}
	}

	mem_addr = mem_gb2312("./GB2312", &gb2312_num);

	font_fd = open(GB2312_HZK, O_RDONLY);
	if (font_fd < 0) {
		perror("open");
		exit(1);
	}
	ret = fstat(font_fd, &fd_stat);
	if (ret == -1) {
		perror("fstat");
		exit(1);
	}
	addr_fd_in = mmap(NULL, (size_t) fd_stat.st_size,
			  PROT_READ, MAP_PRIVATE, font_fd, (off_t) 0);
	if (addr_fd_in == MAP_FAILED) {
		perror("mmap");
		exit(1);
	}
{'fraction_non_alphanumeric': 0.16282714308102178, 'fraction_numerical': 0.031969910672308414, 'mean_word_length': 3.469187675070028, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, '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': '712436', 'n_tokens_mistral': 3155, 'n_tokens_neox': 2890, 'n_words': 605}