Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/libjpeg/cdjpeg.c
Views: 11784
/*1* cdjpeg.c2*3* Copyright (C) 1991-1997, Thomas G. Lane.4* This file is part of the Independent JPEG Group's software.5* For conditions of distribution and use, see the accompanying README file.6*7* This file contains common support routines used by the IJG application8* programs (cjpeg, djpeg, jpegtran).9*/1011#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */12#include <ctype.h> /* to declare isupper(), tolower() */13#ifdef NEED_SIGNAL_CATCHER14#include <signal.h> /* to declare signal() */15#endif16#ifdef USE_SETMODE17#include <fcntl.h> /* to declare setmode()'s parameter macros */18/* If you have setmode() but not <io.h>, just delete this line: */19#include <io.h> /* to declare setmode() */20#endif212223/*24* Signal catcher to ensure that temporary files are removed before aborting.25* NB: for Amiga Manx C this is actually a global routine named _abort();26* we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...27*/2829#ifdef NEED_SIGNAL_CATCHER3031static j_common_ptr sig_cinfo;3233void /* must be global for Manx C */34signal_catcher (int signum)35{36if (sig_cinfo != NULL) {37if (sig_cinfo->err != NULL) /* turn off trace output */38sig_cinfo->err->trace_level = 0;39jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */40}41exit(EXIT_FAILURE);42}434445GLOBAL(void)46enable_signal_catcher (j_common_ptr cinfo)47{48sig_cinfo = cinfo;49#ifdef SIGINT /* not all systems have SIGINT */50signal(SIGINT, signal_catcher);51#endif52#ifdef SIGTERM /* not all systems have SIGTERM */53signal(SIGTERM, signal_catcher);54#endif55}5657#endif585960/*61* Optional progress monitor: display a percent-done figure on stderr.62*/6364#ifdef PROGRESS_REPORT6566METHODDEF(void)67progress_monitor (j_common_ptr cinfo)68{69cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;70int total_passes = prog->pub.total_passes + prog->total_extra_passes;71int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);7273if (percent_done != prog->percent_done) {74prog->percent_done = percent_done;75if (total_passes > 1) {76fprintf(stderr, "\rPass %d/%d: %3d%% ",77prog->pub.completed_passes + prog->completed_extra_passes + 1,78total_passes, percent_done);79} else {80fprintf(stderr, "\r %3d%% ", percent_done);81}82fflush(stderr);83}84}858687GLOBAL(void)88start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)89{90/* Enable progress display, unless trace output is on */91if (cinfo->err->trace_level == 0) {92progress->pub.progress_monitor = progress_monitor;93progress->completed_extra_passes = 0;94progress->total_extra_passes = 0;95progress->percent_done = -1;96cinfo->progress = &progress->pub;97}98}99100101GLOBAL(void)102end_progress_monitor (j_common_ptr cinfo)103{104/* Clear away progress display */105if (cinfo->err->trace_level == 0) {106fprintf(stderr, "\r \r");107fflush(stderr);108}109}110111#endif112113114/*115* Case-insensitive matching of possibly-abbreviated keyword switches.116* keyword is the constant keyword (must be lower case already),117* minchars is length of minimum legal abbreviation.118*/119120GLOBAL(boolean)121keymatch (char * arg, const char * keyword, int minchars)122{123register int ca, ck;124register int nmatched = 0;125126while ((ca = *arg++) != '\0') {127if ((ck = *keyword++) == '\0')128return FALSE; /* arg longer than keyword, no good */129if (isupper(ca)) /* force arg to lcase (assume ck is already) */130ca = tolower(ca);131if (ca != ck)132return FALSE; /* no good */133nmatched++; /* count matched characters */134}135/* reached end of argument; fail if it's too short for unique abbrev */136if (nmatched < minchars)137return FALSE;138return TRUE; /* A-OK */139}140141142/*143* Routines to establish binary I/O mode for stdin and stdout.144* Non-Unix systems often require some hacking to get out of text mode.145*/146147GLOBAL(FILE *)148read_stdin (void)149{150FILE * input_file = stdin;151152#ifdef USE_SETMODE /* need to hack file mode? */153setmode(fileno(stdin), O_BINARY);154#endif155#ifdef USE_FDOPEN /* need to re-open in binary mode? */156if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {157fprintf(stderr, "Cannot reopen stdin\n");158exit(EXIT_FAILURE);159}160#endif161return input_file;162}163164165GLOBAL(FILE *)166write_stdout (void)167{168FILE * output_file = stdout;169170#ifdef USE_SETMODE /* need to hack file mode? */171setmode(fileno(stdout), O_BINARY);172#endif173#ifdef USE_FDOPEN /* need to re-open in binary mode? */174if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {175fprintf(stderr, "Cannot reopen stdout\n");176exit(EXIT_FAILURE);177}178#endif179return output_file;180}181182183