mirror of
https://github.com/fumiama/base16384.git
synced 2026-06-26 19:50:24 +08:00
add manpage
This commit is contained in:
@@ -27,3 +27,4 @@ target_link_libraries(base16384 libbase16384)
|
|||||||
INSTALL(TARGETS base16384 RUNTIME DESTINATION bin)
|
INSTALL(TARGETS base16384 RUNTIME DESTINATION bin)
|
||||||
INSTALL(TARGETS libbase16384 LIBRARY DESTINATION lib)
|
INSTALL(TARGETS libbase16384 LIBRARY DESTINATION lib)
|
||||||
INSTALL(FILES base16384.h DESTINATION include)
|
INSTALL(FILES base16384.h DESTINATION include)
|
||||||
|
INSTALL(FILES base16384.1 DESTINATION share/man/man1)
|
||||||
86
base16384.1
Normal file
86
base16384.1
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
.TH BASE16384 1 "27 April 2022" "GNU" "User Commands"
|
||||||
|
.SH NAME
|
||||||
|
base16384 \- Encode binary files to printable utf16be
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B base16384
|
||||||
|
-[e|d] <\fIinputfile\fR> <\fIoutputfile\fR>
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.LP
|
||||||
|
There are
|
||||||
|
.B 16384
|
||||||
|
Chinese characters ( from
|
||||||
|
.B 4E00
|
||||||
|
to
|
||||||
|
.B 8DFF
|
||||||
|
) being selected as the
|
||||||
|
.I "alphabet"
|
||||||
|
, just like what base64 did. If length of the data has a remainder after mod 7, an unicode Chinese character
|
||||||
|
.B 3Dxx
|
||||||
|
will be appended to present it with
|
||||||
|
.I xx
|
||||||
|
ranging from
|
||||||
|
.I 01
|
||||||
|
to
|
||||||
|
.I 06
|
||||||
|
.
|
||||||
|
.SH OPTIONS
|
||||||
|
.sp 1
|
||||||
|
.TP 0.5i
|
||||||
|
\fB\-e\fR
|
||||||
|
Read data from \fIinputfile\fR and encode them into \fIoutputfile\fR.
|
||||||
|
.TP 0.5i
|
||||||
|
\fBinputfile\fR
|
||||||
|
An absolute or relative file path. Specially, pass - to read from stdin.
|
||||||
|
.TP 0.5i
|
||||||
|
\fBoutputfile\fR
|
||||||
|
An absolute or relative file path. Specially, pass - to write to stdout.
|
||||||
|
.SH "EXIT STATUS"
|
||||||
|
.TP 0.5i
|
||||||
|
\fB0\fR
|
||||||
|
Exit on success.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB1\fR
|
||||||
|
Get file size error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB2\fR
|
||||||
|
Fopen output file error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB3\fR
|
||||||
|
Fopen input file error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB4\fR
|
||||||
|
Write file error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB5\fR
|
||||||
|
Open input file error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB6\fR
|
||||||
|
Map input file error.
|
||||||
|
.TP 0.5i
|
||||||
|
\fB7\fR
|
||||||
|
Write file error in mmap.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
https://github.com/fumiama/base16384
|
||||||
|
.SH BUGS
|
||||||
|
There are currently no known bugs in this application. If you have found them, please contact the
|
||||||
|
.B author
|
||||||
|
on github.
|
||||||
|
.SH AUTHOR
|
||||||
|
This manual page contributed by fumiama.
|
||||||
|
.SH "COPYRIGHT"
|
||||||
|
Copyright \(co 1992-1993, 1996-2022 Free Software Foundation, Inc.
|
||||||
|
This file is part of
|
||||||
|
.IR "base16384" .
|
||||||
|
.LP
|
||||||
|
Base16384 is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
.LP
|
||||||
|
Base16384 is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
.LP
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program. If not, see
|
||||||
|
.IR http://www.gnu.org/licenses/ .
|
||||||
43
base16384.c
43
base16384.c
@@ -25,7 +25,7 @@ static off_t get_file_size(const char* filepath) {
|
|||||||
char encbuf[BUFSIZ*1024/7*7];
|
char encbuf[BUFSIZ*1024/7*7];
|
||||||
char decbuf[BUFSIZ*1024/8*8+2];
|
char decbuf[BUFSIZ*1024/8*8+2];
|
||||||
|
|
||||||
void encode_file(const char* input, const char* output) {
|
static int encode_file(const char* input, const char* output) {
|
||||||
off_t inputsize;
|
off_t inputsize;
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
FILE* fpo;
|
FILE* fpo;
|
||||||
@@ -35,12 +35,12 @@ void encode_file(const char* input, const char* output) {
|
|||||||
} else inputsize = get_file_size(input);
|
} else inputsize = get_file_size(input);
|
||||||
if(inputsize < 0) {
|
if(inputsize < 0) {
|
||||||
perror("Get file size error: ");
|
perror("Get file size error: ");
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
|
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
|
||||||
if(!fpo) {
|
if(!fpo) {
|
||||||
perror("Fopen output file error: ");
|
perror("Fopen output file error: ");
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use encbuf & fread
|
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use encbuf & fread
|
||||||
inputsize = BUFSIZ*1024/7*7;
|
inputsize = BUFSIZ*1024/7*7;
|
||||||
@@ -50,7 +50,7 @@ void encode_file(const char* input, const char* output) {
|
|||||||
if(!fp) fp = fopen(input, "rb");
|
if(!fp) fp = fopen(input, "rb");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
perror("Fopen input file error: ");
|
perror("Fopen input file error: ");
|
||||||
return;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int outputsize = encode_len(inputsize)+16;
|
int outputsize = encode_len(inputsize)+16;
|
||||||
@@ -61,7 +61,7 @@ void encode_file(const char* input, const char* output) {
|
|||||||
int n = encode(encbuf, cnt, decbuf, outputsize);
|
int n = encode(encbuf, cnt, decbuf, outputsize);
|
||||||
if(fwrite(decbuf, n, 1, fpo) <= 0) {
|
if(fwrite(decbuf, n, 1, fpo) <= 0) {
|
||||||
perror("Write file error: ");
|
perror("Write file error: ");
|
||||||
return;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 由操作系统负责释放资源
|
/* 由操作系统负责释放资源
|
||||||
@@ -73,12 +73,12 @@ void encode_file(const char* input, const char* output) {
|
|||||||
int fd = open(input, O_RDONLY);
|
int fd = open(input, O_RDONLY);
|
||||||
if(fd <= 0) {
|
if(fd <= 0) {
|
||||||
perror("Open input file error: ");
|
perror("Open input file error: ");
|
||||||
return;
|
return 5;
|
||||||
}
|
}
|
||||||
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if(input_file == MAP_FAILED) {
|
if(input_file == MAP_FAILED) {
|
||||||
perror("Map input file error: ");
|
perror("Map input file error: ");
|
||||||
return;
|
return 6;
|
||||||
}
|
}
|
||||||
int outputsize = encode_len(inputsize)+16;
|
int outputsize = encode_len(inputsize)+16;
|
||||||
fputc(0xFE, fpo);
|
fputc(0xFE, fpo);
|
||||||
@@ -86,7 +86,7 @@ void encode_file(const char* input, const char* output) {
|
|||||||
int n = encode(input_file, (int)inputsize, decbuf, outputsize);
|
int n = encode(input_file, (int)inputsize, decbuf, outputsize);
|
||||||
if(fwrite(decbuf, n, 1, fpo) <= 0) {
|
if(fwrite(decbuf, n, 1, fpo) <= 0) {
|
||||||
perror("Write file error: ");
|
perror("Write file error: ");
|
||||||
return;
|
return 7;
|
||||||
}
|
}
|
||||||
munmap(input_file, (size_t)inputsize);
|
munmap(input_file, (size_t)inputsize);
|
||||||
/* 由操作系统负责释放资源
|
/* 由操作系统负责释放资源
|
||||||
@@ -95,6 +95,7 @@ void encode_file(const char* input, const char* output) {
|
|||||||
以缩短程序运行时间 */
|
以缩短程序运行时间 */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define rm_head(fp) {\
|
#define rm_head(fp) {\
|
||||||
@@ -112,7 +113,7 @@ static int is_next_end(FILE* fp) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode_file(const char* input, const char* output) {
|
static int decode_file(const char* input, const char* output) {
|
||||||
off_t inputsize;
|
off_t inputsize;
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
FILE* fpo;
|
FILE* fpo;
|
||||||
@@ -122,12 +123,12 @@ void decode_file(const char* input, const char* output) {
|
|||||||
} else inputsize = get_file_size(input);
|
} else inputsize = get_file_size(input);
|
||||||
if(inputsize < 0) {
|
if(inputsize < 0) {
|
||||||
perror("Get file size error: ");
|
perror("Get file size error: ");
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
|
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
|
||||||
if(!fpo) {
|
if(!fpo) {
|
||||||
perror("Fopen output file error: ");
|
perror("Fopen output file error: ");
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use decbuf & fread
|
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use decbuf & fread
|
||||||
inputsize = BUFSIZ*1024/8*8;
|
inputsize = BUFSIZ*1024/8*8;
|
||||||
@@ -137,7 +138,7 @@ void decode_file(const char* input, const char* output) {
|
|||||||
if(!fp) fp = fopen(input, "rb");
|
if(!fp) fp = fopen(input, "rb");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
perror("Fopen input file error: ");
|
perror("Fopen input file error: ");
|
||||||
return;
|
return 3;
|
||||||
}
|
}
|
||||||
int outputsize = decode_len(inputsize, 0)+16;
|
int outputsize = decode_len(inputsize, 0)+16;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@@ -150,7 +151,7 @@ void decode_file(const char* input, const char* output) {
|
|||||||
}
|
}
|
||||||
if(fwrite(encbuf, decode(decbuf, cnt, encbuf, outputsize), 1, fpo) <= 0) {
|
if(fwrite(encbuf, decode(decbuf, cnt, encbuf, outputsize), 1, fpo) <= 0) {
|
||||||
perror("Write file error: ");
|
perror("Write file error: ");
|
||||||
return;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 由操作系统负责释放资源
|
/* 由操作系统负责释放资源
|
||||||
@@ -162,18 +163,18 @@ void decode_file(const char* input, const char* output) {
|
|||||||
int fd = open(input, O_RDONLY);
|
int fd = open(input, O_RDONLY);
|
||||||
if(fd <= 0) {
|
if(fd <= 0) {
|
||||||
perror("Open input file error: ");
|
perror("Open input file error: ");
|
||||||
return;
|
return 5;
|
||||||
}
|
}
|
||||||
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if(input_file == MAP_FAILED) {
|
if(input_file == MAP_FAILED) {
|
||||||
perror("Map input file error: ");
|
perror("Map input file error: ");
|
||||||
return;
|
return 6;
|
||||||
}
|
}
|
||||||
int outputsize = decode_len(inputsize, 0)+16;
|
int outputsize = decode_len(inputsize, 0)+16;
|
||||||
int off = skip_offset(input_file);
|
int off = skip_offset(input_file);
|
||||||
if(fwrite(encbuf, decode(input_file+off, inputsize-off, encbuf, outputsize), 1, fpo) <= 0) {
|
if(fwrite(encbuf, decode(input_file+off, inputsize-off, encbuf, outputsize), 1, fpo) <= 0) {
|
||||||
perror("Write file error: ");
|
perror("Write file error: ");
|
||||||
return;
|
return 7;
|
||||||
}
|
}
|
||||||
munmap(input_file, (size_t)inputsize);
|
munmap(input_file, (size_t)inputsize);
|
||||||
/* 由操作系统负责释放资源
|
/* 由操作系统负责释放资源
|
||||||
@@ -182,6 +183,7 @@ void decode_file(const char* input, const char* output) {
|
|||||||
以缩短程序运行时间 */
|
以缩短程序运行时间 */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -206,17 +208,18 @@ int main(int argc, char** argv) {
|
|||||||
#else
|
#else
|
||||||
unsigned long t = get_start_ms();
|
unsigned long t = get_start_ms();
|
||||||
#endif
|
#endif
|
||||||
|
int exitstat = 0;
|
||||||
switch(argv[1][1]) {
|
switch(argv[1][1]) {
|
||||||
case 'e': encode_file(argv[2], argv[3]); break;
|
case 'e': exitstat = encode_file(argv[2], argv[3]); break;
|
||||||
case 'd': decode_file(argv[2], argv[3]); break;
|
case 'd': exitstat = decode_file(argv[2], argv[3]); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
if(*(uint16_t*)(argv[3]) != *(uint16_t*)"-") {
|
if(!exitstat && *(uint16_t*)(argv[3]) != *(uint16_t*)"-") {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
printf("spend time: %lums\n", clock() - t);
|
printf("spend time: %lums\n", clock() - t);
|
||||||
#else
|
#else
|
||||||
printf("spend time: %lums\n", get_start_ms() - t);
|
printf("spend time: %lums\n", get_start_ms() - t);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return exitstat;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user