mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 19:58:30 +00:00
Update stb (#885)
This commit and, by extension, PR attempts to update `stb` in the most straightforward way possible as well as include fixes from main repo's unmerged PRs for cases rearing their ugly heads during everyday usage: - stb#1299: stb_rect_pack: Make rect_height_compare a stable sort - stb#1402: stb_image: Fix "unused invalid_chunk" with STBI_FAILURE_USERMSG - stb#1404: stb_image: Fix gif two_back memory address - stb#1420: stb_image: Improve error reporting if file operations fail within *_from_file functions - stb#1445: stb_vorbis: Few static analyzers fixes - stb#1487: stb_vorbis: Fix residue classdata bounding for f->temp_memory_required - stb#1490: stb_vorbis: Fix broken clamp in codebook_decode_deinterleave_repeat - stb#1496: stb_image: Fix pnm only build - stb#1497: stb_image: Fix memory leaks if stbi__convert failed - stb#1498: stb_vorbis: Fix memory leaks in stb_vorbis - stb#1499: stb_vorbis: Minor change to prevent the undefined behavior - left shift of a negative value - stb#1500: stb_vorbis: Fix signed integer overflow Includes additional small fixes that I felt didn't warrant a separate PR.
This commit is contained in:
parent
7faffde303
commit
1bc48bc8e4
20 changed files with 1560 additions and 1282 deletions
|
@ -551,8 +551,8 @@ static int ParseNumberOption(const char *arg) {
|
|||
return x;
|
||||
}
|
||||
|
||||
static void PrintUsage(int rc, FILE *f) {
|
||||
fputs(HELPTEXT, f);
|
||||
static void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, HELPTEXT, NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -573,9 +573,12 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
break;
|
||||
case '?':
|
||||
case 'H':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
default:
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "libc/str/unicode.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
|
@ -63,7 +64,7 @@ DESCRIPTION\n\
|
|||
\n\
|
||||
FLAGS\n\
|
||||
\n\
|
||||
-h help\n\
|
||||
-h or -? help\n\
|
||||
-z zoom\n\
|
||||
-m morton ordering\n\
|
||||
-H hilbert ordering\n\
|
||||
|
@ -887,10 +888,8 @@ static void MemZoom(void) {
|
|||
} while (!(action & INTERRUPTED));
|
||||
}
|
||||
|
||||
static wontreturn void PrintUsage(int rc) {
|
||||
Write("SYNOPSIS\n\n ");
|
||||
Write(program_invocation_name);
|
||||
Write(USAGE);
|
||||
static wontreturn void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "SYNOPSIS\n\n ", program_invocation_name, USAGE, NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -898,7 +897,7 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
int opt;
|
||||
char *p;
|
||||
fps = 10;
|
||||
while ((opt = getopt(argc, argv, "hzHNWf:p:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "?hmzHNWf:p:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'z':
|
||||
++zoom;
|
||||
|
@ -927,9 +926,13 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
}
|
||||
break;
|
||||
case 'h':
|
||||
PrintUsage(EXIT_SUCCESS);
|
||||
case '?':
|
||||
default:
|
||||
PrintUsage(EX_USAGE);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pid) {
|
||||
|
@ -941,10 +944,10 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
stpcpy(p, "/maps");
|
||||
} else {
|
||||
if (optind == argc) {
|
||||
PrintUsage(EX_USAGE);
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
if (!memccpy(path, argv[optind], '\0', sizeof(path))) {
|
||||
PrintUsage(EX_USAGE);
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/log/check.h"
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
||||
#define USAGE \
|
||||
|
@ -36,17 +38,15 @@ Flags:\n\
|
|||
-c INT\n\
|
||||
-w INT width (aka cols) [default 8]\n\
|
||||
-o PATH output path [default -]\n\
|
||||
-h shows this information\n\
|
||||
-h or -? shows this information\n\
|
||||
\n"
|
||||
|
||||
static long width_;
|
||||
static FILE *in_, *out_;
|
||||
static char *inpath_, *outpath_;
|
||||
|
||||
void PrintUsage(int rc, FILE *f) {
|
||||
fputs("Usage: ", f);
|
||||
fputs(program_invocation_name, f);
|
||||
fputs(USAGE, f);
|
||||
void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "Usage: ", program_invocation_name, USAGE, NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -63,11 +63,14 @@ void GetOpts(int *argc, char *argv[]) {
|
|||
case 'w':
|
||||
width_ = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case '?':
|
||||
case 'h':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
case '?':
|
||||
default:
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (optind == *argc) {
|
||||
|
|
|
@ -71,8 +71,8 @@ static struct Flags {
|
|||
enum TtyQuantizationAlgorithm quant;
|
||||
} g_flags;
|
||||
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "Usage: %s%s", program_invocation_name, "\
|
||||
static wontreturn void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "Usage: ", program_invocation_name, "\
|
||||
[FLAGS] [PATH]\n\
|
||||
\n\
|
||||
FLAGS\n\
|
||||
|
@ -86,7 +86,7 @@ EXAMPLES\n\
|
|||
\n\
|
||||
printansi.com -w80 -h40 logo.png\n\
|
||||
\n\
|
||||
\n");
|
||||
\n", NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ static void GetOpts(int *argc, char *argv[]) {
|
|||
g_flags.blocks = IsWindows() ? kTtyBlocksCp437 : kTtyBlocksUnicode;
|
||||
if (*argc == 2 &&
|
||||
(strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-help") == 0)) {
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
}
|
||||
while ((opt = getopt(*argc, argv, "?ivpfrtxads234o:w:h:")) != -1) {
|
||||
switch (opt) {
|
||||
|
@ -162,9 +162,12 @@ static void GetOpts(int *argc, char *argv[]) {
|
|||
++__log_level;
|
||||
break;
|
||||
case '?':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
default:
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (optind == *argc) {
|
||||
|
|
|
@ -66,8 +66,8 @@ static struct Flags {
|
|||
|
||||
struct winsize g_winsize;
|
||||
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "Usage: %s%s", program_invocation_name, "\
|
||||
static wontreturn void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "Usage: ", program_invocation_name, "\
|
||||
[FLAGS] [PATH]\n\
|
||||
\n\
|
||||
FLAGS\n\
|
||||
|
@ -94,7 +94,7 @@ FLAGS\n\
|
|||
EXAMPLES\n\
|
||||
\n\
|
||||
printimage.com -sxd lemurs.jpg # 256-color dither unsharp\n\
|
||||
\n");
|
||||
\n", NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ static void GetOpts(int *argc, char *argv[]) {
|
|||
g_flags.blocks = IsWindows() ? kTtyBlocksCp437 : kTtyBlocksUnicode;
|
||||
if (*argc == 2 &&
|
||||
(strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-help") == 0)) {
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
}
|
||||
while ((opt = getopt(*argc, argv, "?vpmfirtxads234o:w:h:")) != -1) {
|
||||
switch (opt) {
|
||||
|
@ -170,9 +170,12 @@ static void GetOpts(int *argc, char *argv[]) {
|
|||
++__log_level;
|
||||
break;
|
||||
case '?':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
default:
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_winsize.ws_col = 80;
|
||||
|
@ -435,7 +438,7 @@ int main(int argc, char *argv[]) {
|
|||
int i;
|
||||
ShowCrashReports();
|
||||
GetOpts(&argc, argv);
|
||||
if (optind == argc) PrintUsage(0, stdout);
|
||||
if (optind == argc) PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
stbi_set_unpremultiply_on_load(true);
|
||||
for (i = optind; i < argc; ++i) {
|
||||
WithImageFile(argv[i], ProcessImage);
|
||||
|
|
|
@ -123,7 +123,7 @@ Flags & Keyboard Shortcuts:\n\
|
|||
-v increases verbosity [flag]\n\
|
||||
-L PATH redirects stderr to path [flag]\n\
|
||||
-y yes to interactive prompts [flag]\n\
|
||||
-h shows this information [flag]\n\
|
||||
-h or -? shows this information [flag]\n\
|
||||
UP/DOWN adjust volume [keyboard]\n\
|
||||
CTRL+L redraw [keyboard]\n\
|
||||
CTRL+Z suspend [keyboard]\n\
|
||||
|
@ -1374,10 +1374,8 @@ static bool CanPlayAudio(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void PrintUsage(int rc, FILE *f) {
|
||||
fputs("Usage: ", f);
|
||||
fputs(program_invocation_name, f);
|
||||
fputs(USAGE, f);
|
||||
static void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "Usage: ", program_invocation_name, USAGE, NULL);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
@ -1399,12 +1397,15 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
case 'Y':
|
||||
yonly_ = true;
|
||||
break;
|
||||
case '?':
|
||||
case 'h':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
case '?':
|
||||
default:
|
||||
if (!ProcessOptKey(opt)) {
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
if (opt == optopt) {
|
||||
PrintUsage(EXIT_SUCCESS, STDOUT_FILENO);
|
||||
} else {
|
||||
PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1562,7 +1563,7 @@ int main(int argc, char *argv[]) {
|
|||
fullclear_ = true;
|
||||
GetOpts(argc, argv);
|
||||
if (!tuned_) PickDefaults();
|
||||
if (optind == argc) PrintUsage(EX_USAGE, stderr);
|
||||
if (optind == argc) PrintUsage(EX_USAGE, STDERR_FILENO);
|
||||
patharg_ = argv[optind];
|
||||
s = commandvenv("SOX", "sox");
|
||||
sox_ = s ? strdup(s) : 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue