Skip to content

Commit

Permalink
Allow va_args in die method
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinbjornt committed Nov 5, 2023
1 parent 2a2134a commit d4d90cf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Hear.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ - (instancetype)initWithLocale:(NSString *)loc
if (self) {

if ([[Hear supportedLocales] containsObject:loc] == NO) {
NSPrintErr(@"Locale '%@' not supported. Run with -s flag to see list of supported locales", loc);
exit(EXIT_FAILURE);
[self die:@"Locale '%@' not supported. Run with -s flag to see list of supported locales", loc];
}

self.locale = loc;
Expand All @@ -91,8 +90,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {

#pragma mark -

- (void)die:(NSString *)errMsg {
NSPrintErr(@"Error: %@", errMsg);
- (void)die:(NSString *)format, ... {
va_list args;
va_start(args, format);
NSString *string = [[NSString alloc] initWithFormat:format arguments:args];
va_end(args);
fprintf(stderr, "%s\n", [string UTF8String]);
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -141,7 +144,7 @@ - (void)initRecognizer {
}

if (self.useOnDeviceRecognition && !self.recognizer.supportsOnDeviceRecognition) {
[self die:[NSString stringWithFormat:@"On-device recognition is not supported for locale '%@'", self.locale]];
[self die:@"On-device recognition is not supported for locale '%@'", self.locale];
}
}

Expand All @@ -157,7 +160,7 @@ - (void)processFile {

NSString *filePath = self.inputFile;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] == NO) {
[self die:[NSString stringWithFormat:@"No file at path '%@'", filePath]];
[self die:@"No file at path '%@'", filePath];
}

// OK, the file exists, let's try to run speech recognition on it
Expand Down Expand Up @@ -292,7 +295,7 @@ - (void)startListening {
NSError *err;
[self.engine startAndReturnError:&err];
if (err != nil) {
[self die:[NSString stringWithFormat:@"Failed to start audio engine: %@", [err localizedDescription]]];
[self die:@"Failed to start audio engine: %@", [err localizedDescription]];
}

if (self.timeout > 0) {
Expand Down

0 comments on commit d4d90cf

Please sign in to comment.