Skip to content

Fix sfntdiff & sfntedit exit codes #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions c/sfntdiff/source/Dmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static void printUsage(void) {
/* Show usage information */
static void showUsage(void) {
printUsage();
quit(0);
}

/* Show usage and help information */
Expand Down Expand Up @@ -85,7 +84,6 @@ static void showHelp(void) {
" e.g., -i cmap,name\n"
" will inspect/compare ONLY the 'cmap' and 'name' tables\n");
printf(" -i and -x switches are exclusive of each other.\n");
quit(1);
}

/* Main program */
Expand Down Expand Up @@ -115,16 +113,20 @@ IntN main(IntN argc, Byte8 *argv[]) {

argi = opt_Scan(argc, argv, opt_NOPTS(opt), opt, NULL, NULL);

if (opt_Present("-u") || opt_Present("-h")) return 0;

if (opt_Present("-x") && opt_Present("-i")) {
printf("ERROR: '-x' switch and '-i' switch are exclusive of each other.\n");
showUsage();
return 1;
}

if (level > 4) level = 4;

if ((argc - argi) < 2) {
printf("ERROR: not enough files/directories specified.\n");
showUsage();
return 1;
}

filename1 = argv[argi];
Expand Down Expand Up @@ -303,8 +305,7 @@ IntN main(IntN argc, Byte8 *argv[]) {
} else {
printf("ERROR: Incorrect/insufficient files/directories specified.\n");
showUsage();
return 1;
}

/*printf( "\nDone.\n");*/
return 0;
}
15 changes: 15 additions & 0 deletions c/sfntdiff/source/Dopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include "Dopt.h"

Expand Down Expand Up @@ -99,6 +100,16 @@ void opt_Error(int error, opt_Option *opt, char *arg) {
global.error += global.handler(error, opt, arg, global.client);
}

bool is_known_option(char *arg) {
const char *known_options[] = {"-u", "-h", "-T", "-d", "-x", "-i", "-X"};
int num_opts = sizeof(known_options) / sizeof(known_options[0]);
int i;
for (i = 0; i < num_opts; i++)
if (strcmp(arg, known_options[i]) == 0)
return true;
return false;
}

/* Process argument list */
int opt_Scan(int argc, char *argv[],
int nOpts, opt_Option *opts, opt_Handler handler, void *client) {
Expand Down Expand Up @@ -138,6 +149,10 @@ int opt_Scan(int argc, char *argv[],
argi = 1;
while (argi < argc) {
char *arg = argv[argi];
if (arg[0] == '-' && !is_known_option(arg)) {
opt_Error(opt_Unknown, NULL, arg);
exit(1);
}
opt_Option *opt = lookup(arg, matchWhole);
if (opt != NULL)
/* Whole argument matched option */
Expand Down
44 changes: 20 additions & 24 deletions c/sfntedit/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static void cleanup(int code) {

/* Print usage information */
static void printUsage(void) {
fprintf(stderr,
fprintf(stdout,
"Usage:\n"
" %s [options] <srcfile> [<dstfile>]\n"
"OR: %s -X <scriptfile>\n\n"
Expand All @@ -209,63 +209,62 @@ static void printUsage(void) {
/* Show usage information */
static void showUsage(void) {
printUsage();
quit(0);
}

/* Show usage and help information */
static void showHelp(void) {
printUsage();
fprintf(stderr,
fprintf(stdout,
"Notes:\n"
" This program supports table-editing, listing, and checksumming options\n"
"on sfnt-formatted files such as OpenType Format (OTF) or TrueType. The\n"
"mandatory source file is specified as an argument to the program. An\n"
"optional destination file may also be specified which receives the edited\n"
"data otherwise the source data is edited in-place thus modifying the source\n");
fprintf(stderr,
fprintf(stdout,
"file. In-place editing is achieved by the use of a temporary file called\n"
"%s that is created in the directory of execution (requiring you\n"
"to have write permission to that directory).\n"
" The target table of an editing option (-x, -d, and -a) is specified\n"
"with a table tag argument that is nominally 4 characters long. If fewer\n"
"than 4 characters are specified the tag is padded with spaces (more than 4\n",
tmpname);
fprintf(stderr,
fprintf(stdout,
"characters is a fatal error). Multiple tables may be specified as a single\n"
"argument composed from a comma-separated list of tags.\n"
" The extract option (-x) copies the table data into a file whose default\n"
"name is the concatenation of the source filename (less its .otf or .ttf\n"
"extension), a period character (.), and the table tag. If the tag contains\n"
"non-alphanumeric characters they are replaced by underscore characters (_)\n");
fprintf(stderr,
fprintf(stdout,
"and finally trailing underscores are removed. The default filename may be\n"
"overridden by appending an equals character (=) followed by an alternate\n"
"filename to the table tag argument. The delete option (-d) deletes a table.\n"
"Unlike the -x option no files may be specified in the table tag list. The\n"
"add option (-a) adds a table or replaces one if the table already exists.\n"
"The source file containing the table data is specified by appending an\n");
fprintf(stderr,
fprintf(stdout,
"equals character (=) followed by a filename to the table tag.\n"
" The 3 editing options may be specified together as acting on the same\n"
"table. In such cases the -x option is applied before the -d option which is\n"
"applied before the -a option. (The -d option applied to the same table as a\n"
"subsequent -a option is permitted but redundant.) The -d and -a options\n"
"change the contents of the sfnt and cause the table checksums and the head\n");
fprintf(stderr,
fprintf(stdout,
"table's checksum adjustment field to be recomputed.\n"
" The list option (-l) simply lists the contents of the sfnt table\n"
"directory. This is the default action if no other options are specified.\n"
"The check checksum option (-c) performs a check of all the table checksums\n"
"and the head table's checksum adjustment field and reports any errors. The\n"
"fix checksum option (-f) fixes any checksum errors.\n");
fprintf(stderr,
fprintf(stdout,
" The -d, -a, and -f options create a new sfnt file by copying tables\n"
"from the source file to the destination file. The tables are copied in the\n"
"order recommended in the OpenType specification. A side effect of copying\n"
"is that all table information including checksums and sfnt search fields\n"
"is recalculated.\n"
"Examples:\n");
fprintf(stderr,
fprintf(stdout,
"o Extract GPOS and GSUB tables to files minion.GPOS and minion.GSUB.\n"
" sfntedit -x GPOS,GSUB minion.otf\n"
"o Add tables extracted previously to different font.\n"
Expand All @@ -274,7 +273,6 @@ static void showHelp(void) {
" sfntedit -d TR01,TR02,TR03 pala.ttf\n"
"o Copy font to new file fixing checksums and reordering tables.\n"
" sfntedit -f helv.ttf newhelv.ttf\n");
quit(0);
}

static void makeArgs(char *filename) {
Expand Down Expand Up @@ -525,10 +523,10 @@ static int parseArgs(int argc, char *argv[]) {
break;
case 'u':
showUsage();
break;
exit(0);
case 'h':
showHelp();
break;
exit(0);
default:
fatal(SFED_MSG_UNRECOGOPT, arg);
}
Expand Down Expand Up @@ -635,21 +633,21 @@ static void sfntReadHdr(void) {
static void sfntDumpHdr(void) {
int i;

fprintf(stderr, "--- sfnt header [%s]\n", srcfile.name);
fprintf(stdout, "--- sfnt header [%s]\n", srcfile.name);
if (sfnt.version == 0x00010000)
fprintf(stderr, "version =1.0 (00010000)\n");
fprintf(stdout, "version =1.0 (00010000)\n");
else
fprintf(stderr, "version =%c%c%c%c (%08x)\n",
fprintf(stdout, "version =%c%c%c%c (%08x)\n",
TAG_ARG(sfnt.version), sfnt.version);
fprintf(stderr, "numTables =%hu\n", sfnt.numTables);
fprintf(stderr, "searchRange =%hu\n", sfnt.searchRange);
fprintf(stderr, "entrySelector=%hu\n", sfnt.entrySelector);
fprintf(stderr, "rangeShift =%hu\n", sfnt.rangeShift);
fprintf(stdout, "numTables =%hu\n", sfnt.numTables);
fprintf(stdout, "searchRange =%hu\n", sfnt.searchRange);
fprintf(stdout, "entrySelector=%hu\n", sfnt.entrySelector);
fprintf(stdout, "rangeShift =%hu\n", sfnt.rangeShift);

fprintf(stderr, "--- table directory [index]={tag,checksum,offset,length}\n");
fprintf(stdout, "--- table directory [index]={tag,checksum,offset,length}\n");
for (i = 0; i < sfnt.numTables; i++) {
Table *tbl = &sfnt.directory[i];
fprintf(stderr, "[%2d]={%c%c%c%c,%08x,%08x,%08x}\n", i,
fprintf(stdout, "[%2d]={%c%c%c%c,%08x,%08x,%08x}\n", i,
TAG_ARG(tbl->tag), tbl->checksum, tbl->offset, tbl->length);
}
}
Expand Down Expand Up @@ -1245,7 +1243,5 @@ int main(int argc, char *argv[]) {

doingScripting = 0;
}

fprintf(stdout, "\nDone.\n");
return 0;
}
22 changes: 11 additions & 11 deletions tests/makeotf_data/expected_output/ttf-dev.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
<ulUnicodeRange2 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="UKWN"/>
<achVendID value="ADBE"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="65"/>
<usLastCharIndex value="65"/>
<usLastCharIndex value="97"/>
<sTypoAscender value="660"/>
<sTypoDescender value="-340"/>
<sTypoLineGap value="200"/>
Expand All @@ -131,12 +131,15 @@
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0x41" name="a"/><!-- LATIN CAPITAL LETTER A -->
<map code="0x61" name="a"/><!-- LATIN SMALL LETTER A -->
</cmap_format_4>
<cmap_format_6 platformID="1" platEncID="0" language="0">
<map code="0x41" name="a"/>
<map code="0x61" name="a"/>
</cmap_format_6>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x41" name="a"/><!-- LATIN CAPITAL LETTER A -->
<map code="0x61" name="a"/><!-- LATIN SMALL LETTER A -->
</cmap_format_4>
</cmap>

Expand Down Expand Up @@ -236,37 +239,34 @@

<name>
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="2" platformID="1" platEncID="0" langID="0x0" unicode="True">
Regular
</namerecord>
<namerecord nameID="3" platformID="1" platEncID="0" langID="0x0" unicode="True">
1.000;UKWN;SourceSans-Test
1.000;ADBE;SourceSans-Test
</namerecord>
<namerecord nameID="4" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="5" platformID="1" platEncID="0" langID="0x0" unicode="True">
Version 1.000;hotconv 1.0.109;makeotfexe 2.5.65593 DEVELOPMENT
</namerecord>
<namerecord nameID="6" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans-Test
</namerecord>
<namerecord nameID="17" platformID="1" platEncID="0" langID="0x0" unicode="True">
Test
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
1.000;UKWN;SourceSans-Test
1.000;ADBE;SourceSans-Test
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
Version 1.000;hotconv 1.0.109;makeotfexe 2.5.65593 DEVELOPMENT
Expand Down
22 changes: 11 additions & 11 deletions tests/makeotf_data/expected_output/ttf-rel.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
<ulUnicodeRange2 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="UKWN"/>
<achVendID value="ADBE"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="97"/>
<usFirstCharIndex value="65"/>
<usLastCharIndex value="97"/>
<sTypoAscender value="660"/>
<sTypoDescender value="-340"/>
Expand All @@ -130,12 +130,15 @@
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0x41" name="a"/><!-- LATIN CAPITAL LETTER A -->
<map code="0x61" name="a"/><!-- LATIN SMALL LETTER A -->
</cmap_format_4>
<cmap_format_6 platformID="1" platEncID="0" language="0">
<map code="0x41" name="a"/>
<map code="0x61" name="a"/>
</cmap_format_6>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x41" name="a"/><!-- LATIN CAPITAL LETTER A -->
<map code="0x61" name="a"/><!-- LATIN SMALL LETTER A -->
</cmap_format_4>
</cmap>
Expand Down Expand Up @@ -236,37 +239,34 @@

<name>
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="2" platformID="1" platEncID="0" langID="0x0" unicode="True">
Regular
</namerecord>
<namerecord nameID="3" platformID="1" platEncID="0" langID="0x0" unicode="True">
1.000;UKWN;SourceSans-Test
1.000;ADBE;SourceSans-Test
</namerecord>
<namerecord nameID="4" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="5" platformID="1" platEncID="0" langID="0x0" unicode="True">
Version 1.000;hotconv 1.0.109;makeotfexe 2.5.65593
</namerecord>
<namerecord nameID="6" platformID="1" platEncID="0" langID="0x0" unicode="True">
SourceSans-Test
</namerecord>
<namerecord nameID="17" platformID="1" platEncID="0" langID="0x0" unicode="True">
Test
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
1.000;UKWN;SourceSans-Test
1.000;ADBE;SourceSans-Test
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
SourceSans
Source Sans
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
Version 1.000;hotconv 1.0.109;makeotfexe 2.5.65593
Expand Down
2 changes: 1 addition & 1 deletion tests/makeotf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_exit_known_option(arg):
assert subprocess.call([TOOL, arg]) == 0


@pytest.mark.parametrize('arg', ['j', 'bogus'])
@pytest.mark.parametrize('arg', ['-j', '--bogus'])
def test_exit_unknown_option(arg):
assert subprocess.call([TOOL, arg]) == 1

Expand Down
2 changes: 1 addition & 1 deletion tests/makeotfexe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_exit_known_option(arg):
assert subprocess.call([TOOL, arg]) == 0


@pytest.mark.parametrize('arg', ['j', 'bogus'])
@pytest.mark.parametrize('arg', ['-j', '--bogus'])
def test_exit_unknown_option(arg):
assert subprocess.call([TOOL, arg]) == 1

Expand Down
5 changes: 0 additions & 5 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ def _check_tool(tool_name):
Returns the tool's name if the check is successful,
or a tuple with the tool's name and the error if it's not.
"""
# XXX start hack to bypass this issue
# https://github.com/adobe-type-tools/afdko/issues/348
if tool_name.split('.')[0] in ('sfntdiff', 'sfntedit'):
return tool_name
# XXX end hack
try:
subprocess.check_output([tool_name, '-h'], timeout=TIMEOUT)
return tool_name
Expand Down
Loading