1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-06 10:40:30 +08:00

Merge branch 'master' of https://github.com/fumiama/base16384 into debian

This commit is contained in:
fumiama
2022-06-03 13:54:26 +08:00
5 changed files with 82 additions and 21 deletions

View File

@@ -1,5 +1,20 @@
// base1432.c
// fumiama 20220319
/* base1432.c
* This file is part of the base16384 distribution (https://github.com/fumiama/base16384).
* Copyright (c) 2022 Fumiama Minamoto.
*
* This program 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, version 3.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef __cosmopolitan // always le
# define be16toh(x) bswap_16(x)
# define be32toh(x) bswap_32(x)

View File

@@ -1,5 +1,20 @@
// base1464.c
// fumiama 20211029
/* base1464.c
* This file is part of the base16384 distribution (https://github.com/fumiama/base16384).
* Copyright (c) 2022 Fumiama Minamoto.
*
* This program 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, version 3.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

View File

@@ -68,7 +68,7 @@ on github.
.SH AUTHOR
This manual page contributed by fumiama.
.SH "COPYRIGHT"
Copyright \(co 1992-1993, 1996-2022 Free Software Foundation, Inc.
Copyright \(co 2022, Fumiama Minamoto
This file is part of
.IR "base16384" .
.LP

View File

@@ -1,3 +1,20 @@
/* base16384.c
* This file is part of the base16384 distribution (https://github.com/fumiama/base16384).
* Copyright (c) 2022 Fumiama Minamoto.
*
* This program 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, version 3.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __cosmopolitan
#include <stdio.h>
#include <stdint.h>
@@ -34,12 +51,12 @@ static int encode_file(const char* input, const char* output) {
fp = stdin;
} else inputsize = get_file_size(input);
if(inputsize < 0) {
perror("Get file size error: ");
perror("Get file size error");
return 1;
}
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
if(!fpo) {
perror("Fopen output file error: ");
perror("Fopen output file error");
return 2;
}
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use encbuf & fread
@@ -49,7 +66,7 @@ static int encode_file(const char* input, const char* output) {
#endif
if(!fp) fp = fopen(input, "rb");
if(!fp) {
perror("Fopen input file error: ");
perror("Fopen input file error");
return 3;
}
@@ -60,7 +77,7 @@ static int encode_file(const char* input, const char* output) {
while((cnt = fread(encbuf, sizeof(char), inputsize, fp))) {
int n = encode(encbuf, cnt, decbuf, outputsize);
if(fwrite(decbuf, n, 1, fpo) <= 0) {
perror("Write file error: ");
perror("Write file error");
return 4;
}
}
@@ -72,12 +89,12 @@ static int encode_file(const char* input, const char* output) {
} else { // small file, use mmap & fwrite
int fd = open(input, O_RDONLY);
if(fd <= 0) {
perror("Open input file error: ");
perror("Open input file error");
return 5;
}
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
if(input_file == MAP_FAILED) {
perror("Map input file error: ");
perror("Map input file error");
return 6;
}
int outputsize = encode_len(inputsize)+16;
@@ -85,7 +102,7 @@ static int encode_file(const char* input, const char* output) {
fputc(0xFF, fpo);
int n = encode(input_file, (int)inputsize, decbuf, outputsize);
if(fwrite(decbuf, n, 1, fpo) <= 0) {
perror("Write file error: ");
perror("Write file error");
return 7;
}
munmap(input_file, (size_t)inputsize);
@@ -122,12 +139,12 @@ static int decode_file(const char* input, const char* output) {
fp = stdin;
} else inputsize = get_file_size(input);
if(inputsize < 0) {
perror("Get file size error: ");
perror("Get file size error");
return 1;
}
fpo = (*(uint16_t*)output == *(uint16_t*)"-")?stdout:fopen(output, "wb");
if(!fpo) {
perror("Fopen output file error: ");
perror("Fopen output file error");
return 2;
}
if(!inputsize || inputsize > BUFSIZ*1024) { // stdin or big file, use decbuf & fread
@@ -137,7 +154,7 @@ static int decode_file(const char* input, const char* output) {
#endif
if(!fp) fp = fopen(input, "rb");
if(!fp) {
perror("Fopen input file error: ");
perror("Fopen input file error");
return 3;
}
int outputsize = decode_len(inputsize, 0)+16;
@@ -150,7 +167,7 @@ static int decode_file(const char* input, const char* output) {
decbuf[cnt++] = end;
}
if(fwrite(encbuf, decode(decbuf, cnt, encbuf, outputsize), 1, fpo) <= 0) {
perror("Write file error: ");
perror("Write file error");
return 4;
}
}
@@ -162,18 +179,18 @@ static int decode_file(const char* input, const char* output) {
} else { // small file, use mmap & fwrite
int fd = open(input, O_RDONLY);
if(fd <= 0) {
perror("Open input file error: ");
perror("Open input file error");
return 5;
}
char *input_file = mmap(NULL, (size_t)inputsize, PROT_READ, MAP_PRIVATE, fd, 0);
if(input_file == MAP_FAILED) {
perror("Map input file error: ");
perror("Map input file error");
return 6;
}
int outputsize = decode_len(inputsize, 0)+16;
int off = skip_offset(input_file);
if(fwrite(encbuf, decode(input_file+off, inputsize-off, encbuf, outputsize), 1, fpo) <= 0) {
perror("Write file error: ");
perror("Write file error");
return 7;
}
munmap(input_file, (size_t)inputsize);

View File

@@ -1,8 +1,22 @@
#ifndef _BASE14_H_
#define _BASE14_H_
// base14.h
// fumiama 20220319
/* base16384.h
* This file is part of the base16384 distribution (https://github.com/fumiama/base16384).
* Copyright (c) 2022 Fumiama Minamoto.
*
* This program 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, version 3.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// encode_len calc min buf size to fill encode result
int encode_len(int dlen) {