Skip to content

Commit dc3e9cd

Browse files
Syed-Shahrukh-OSSRevivalnijel
authored andcommitted
Added fix for enca to exit 1 each time it prints 'unknown' #19.
1 parent 7e7f54a commit dc3e9cd

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/enca.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int process_file (EncaAnalyser an,
2424
const char *fname);
2525
static void dwim_libenca_options(EncaAnalyser an,
2626
const File *file);
27-
static void print_results (const char *fname,
27+
static int print_results (const char *fname,
2828
EncaAnalyser an,
2929
EncaEncoding result,
3030
int gerrno);
@@ -104,6 +104,7 @@ process_file(EncaAnalyser an,
104104
static int utf8 = ENCA_CS_UNKNOWN;
105105
static Buffer *buffer = NULL; /* persistent i/o buffer */
106106
int ot_is_convert = (options.output_type == OTYPE_CONVERT);
107+
int res = ERR_OK;
107108

108109
EncaEncoding result; /* the guessed encoding */
109110
File *file; /* the processed file */
@@ -169,13 +170,12 @@ process_file(EncaAnalyser an,
169170
}
170171

171172
/* Print results. */
172-
print_results(file->name, an, result, enca_errno(an));
173+
res = print_results(file->name, an, result, enca_errno(an));
173174
if (result.charset == utf8)
174175
double_utf8_chk(an, buffer->data, buffer->pos);
175176

176177
file_free(file);
177-
178-
return enca_charset_is_known(result.charset) ? EXIT_SUCCESS : EXIT_FAILURE;
178+
return (res == ERR_OK) && enca_charset_is_known(result.charset) ? EXIT_SUCCESS : EXIT_FAILURE;
179179
}
180180

181181
/*
@@ -210,13 +210,14 @@ dwim_libenca_options(EncaAnalyser an, const File *file)
210210
/**
211211
* Prints results.
212212
**/
213-
static void
213+
static int
214214
print_results(const char *fname,
215215
EncaAnalyser an,
216216
EncaEncoding result,
217217
int gerrno)
218218
{
219219
char *s;
220+
int res = ERR_OK;
220221
EncaSurface surf = result.surface
221222
& ~enca_charset_natural_surface(result.charset);
222223

@@ -258,22 +259,28 @@ print_results(const char *fname,
258259
case OTYPE_CS2CS:
259260
if (enca_charset_name(result.charset, ENCA_NAME_STYLE_CSTOCS) != NULL)
260261
puts(enca_charset_name(result.charset, ENCA_NAME_STYLE_CSTOCS));
261-
else
262+
else {
262263
puts(enca_charset_name(ENCA_CS_UNKNOWN, ENCA_NAME_STYLE_CSTOCS));
264+
res = ERR_CANNOT;
265+
}
263266
break;
264267

265268
case OTYPE_ICONV:
266269
if (enca_charset_name(result.charset, ENCA_NAME_STYLE_ICONV) != NULL)
267270
puts(enca_charset_name(result.charset, ENCA_NAME_STYLE_ICONV));
268-
else
271+
else {
269272
puts(enca_charset_name(ENCA_CS_UNKNOWN, ENCA_NAME_STYLE_ICONV));
273+
res = ERR_CANNOT;
274+
}
270275
break;
271276

272277
case OTYPE_MIME:
273278
if (enca_charset_name(result.charset, ENCA_NAME_STYLE_MIME) != NULL)
274279
puts(enca_charset_name(result.charset, ENCA_NAME_STYLE_MIME));
275-
else
280+
else {
276281
puts(enca_charset_name(ENCA_CS_UNKNOWN, ENCA_NAME_STYLE_MIME));
282+
res = ERR_CANNOT;
283+
}
277284
break;
278285

279286
default:
@@ -283,7 +290,9 @@ print_results(const char *fname,
283290

284291
if (gerrno && options.output_type == OTYPE_DETAILS) {
285292
printf(" Failure reason: %s.\n", enca_strerror(an, gerrno));
293+
res = ERR_CANNOT;
286294
}
295+
return res;
287296
}
288297

289298
/**

0 commit comments

Comments
 (0)