Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "cdjpeg.h"
00013 #include <ctype.h>
00014 #ifdef NEED_SIGNAL_CATCHER
00015 #include <signal.h>
00016 #endif
00017 #ifdef USE_SETMODE
00018 #include <fcntl.h>
00019
00020 #include <io.h>
00021 #endif
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef NEED_SIGNAL_CATCHER
00031
00032 static j_common_ptr sig_cinfo;
00033
00034 void
00035 signal_catcher (int signum)
00036 {
00037 if (sig_cinfo != NULL) {
00038 if (sig_cinfo->err != NULL)
00039 sig_cinfo->err->trace_level = 0;
00040 jpeg_destroy(sig_cinfo);
00041 }
00042 exit(EXIT_FAILURE);
00043 }
00044
00045
00046 GLOBAL(void)
00047 enable_signal_catcher (j_common_ptr cinfo)
00048 {
00049 sig_cinfo = cinfo;
00050 #ifdef SIGINT
00051 signal(SIGINT, signal_catcher);
00052 #endif
00053 #ifdef SIGTERM
00054 signal(SIGTERM, signal_catcher);
00055 #endif
00056 }
00057
00058 #endif
00059
00060
00061
00062
00063
00064
00065 #ifdef PROGRESS_REPORT
00066
00067 METHODDEF(void)
00068 progress_monitor (j_common_ptr cinfo)
00069 {
00070 cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
00071 int total_passes = prog->pub.total_passes + prog->total_extra_passes;
00072 int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
00073
00074 if (percent_done != prog->percent_done) {
00075 prog->percent_done = percent_done;
00076 if (total_passes > 1) {
00077 fprintf(stderr, "\rPass %d/%d: %3d%% ",
00078 prog->pub.completed_passes + prog->completed_extra_passes + 1,
00079 total_passes, percent_done);
00080 } else {
00081 fprintf(stderr, "\r %3d%% ", percent_done);
00082 }
00083 fflush(stderr);
00084 }
00085 }
00086
00087
00088 GLOBAL(void)
00089 start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
00090 {
00091
00092 if (cinfo->err->trace_level == 0) {
00093 progress->pub.progress_monitor = progress_monitor;
00094 progress->completed_extra_passes = 0;
00095 progress->total_extra_passes = 0;
00096 progress->percent_done = -1;
00097 cinfo->progress = &progress->pub;
00098 }
00099 }
00100
00101
00102 GLOBAL(void)
00103 end_progress_monitor (j_common_ptr cinfo)
00104 {
00105
00106 if (cinfo->err->trace_level == 0) {
00107 fprintf(stderr, "\r \r");
00108 fflush(stderr);
00109 }
00110 }
00111
00112 #endif
00113
00114
00115
00116
00117
00118
00119
00120
00121 GLOBAL(boolean)
00122 keymatch (char * arg, const char * keyword, int minchars)
00123 {
00124 register int ca, ck;
00125 register int nmatched = 0;
00126
00127 while ((ca = *arg++) != '\0') {
00128 if ((ck = *keyword++) == '\0')
00129 return FALSE;
00130 if (isupper(ca))
00131 ca = tolower(ca);
00132 if (ca != ck)
00133 return FALSE;
00134 nmatched++;
00135 }
00136
00137 if (nmatched < minchars)
00138 return FALSE;
00139 return TRUE;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148 GLOBAL(FILE *)
00149 read_stdin (void)
00150 {
00151 FILE * input_file = stdin;
00152
00153 #ifdef USE_SETMODE
00154 setmode(fileno(stdin), O_BINARY);
00155 #endif
00156 #ifdef USE_FDOPEN
00157 if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
00158 fprintf(stderr, "Cannot reopen stdin\n");
00159 exit(EXIT_FAILURE);
00160 }
00161 #endif
00162 return input_file;
00163 }
00164
00165
00166 GLOBAL(FILE *)
00167 write_stdout (void)
00168 {
00169 FILE * output_file = stdout;
00170
00171 #ifdef USE_SETMODE
00172 setmode(fileno(stdout), O_BINARY);
00173 #endif
00174 #ifdef USE_FDOPEN
00175 if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
00176 fprintf(stderr, "Cannot reopen stdout\n");
00177 exit(EXIT_FAILURE);
00178 }
00179 #endif
00180 return output_file;
00181 }