Harlequin RIP SDK
Main entry point and command-line parsing

Files

file  main.c
 PC command line entry point.
 
file  argusage.c
 Common platform argument parsing and usage reporting.
 
file  argusage.h
 Common platform argument parsing and usage reporting.
 

Data Structures

struct  parse_args_t
 

Macros

#define ENABLECOLORCONSOLE   1
 Whether to enable colorful console output, switched by the -! option.
 

Enumerations

enum  
 

Functions

static void monitorCallback (uint32 bufLen, const uint8 *u8buf)
 Monitor information callback. More...
 
static HqBool extendLibrarySearchPath (char *pszPath)
 
static void le_exception_handler (char *mess)
 
static uint8wchar_to_utf8 (WCHAR *arg, HqBool keep)
 
static HqBool args_used (void *data, int n)
 Callback to check that we have enough arguments left.
 
static uint8arg_to_utf8 (void *data, int index, HqBool keep)
 Callback to convert an indexed argument to UTF-8.
 
static uint8program_name_from_argv (WCHAR **argv)
 Function to get program leaf name in UTF-8 from initial argv.
 
static uint8program_name (void *data)
 Callback to get program leaf name in UTF-8.
 
static uint8program_name_from_opaque_argv (void *data)
 Function to get program leaf name in UTF-8 from initial argv, through opaque pointer for platform abstraction.
 
static void PlatformOptionInitialize (HqBool sdkinit)
 
static int32 PlatformOption (int32 option, HqBool sdkready, HqBool(*args_used)(void *data, int n), uint8 *(*arg_to_utf8)(void *data, int index, HqBool keep), uint8 *(*program_name)(void *data), void *data)
 
static HqBool AddFilesToInputQ (uint8 *pattern, const uint8 *configName, uint8 *errbuf)
 
static int32 ParseArguments (int argc, WCHAR **argv, HqBool sdkready)
 
static void do_cpuid (uint32 *info, uint32 id)
 
static HqBool cpuid_fail (char *reason)
 
static HqBool verify_system_requirements (void)
 
int __cdecl wmain (int argc, WCHAR *argv[])
 The main entry point to the Windows version of the clrip command-line RIP application. More...
 
static HqBool MountDriveType (char *pRootPath)
 
HqBool PTNextDrive (int32 index, uint8 *pDrivename)
 Called by MountAllDrives() to get the next (first if index == 0) drive that is on the machine. More...
 
int32 ClripOption (int32 option, HqBool sdkready, HqBool filenameConsumed, HqBool(*args_used)(void *data, int n), uint8 *(*arg_to_utf8)(void *data, int index, HqBool keep), uint8 *(*program_name)(void *data), void *data)
 Parse common options for all platform versions of clrip. More...
 
void ClripOptionInitialize (HqBool sdkinit)
 Initialise common options to empty or default values. More...
 
int32 PrepareProcessing (uint8 *(*program_name)(void *data), void *data)
 Prepare to process jobs by determining whether the stuff_to_do fields are consistent, and start the appropriate extra processing threads if necessary. More...
 
void ClripOptionFinalize (void)
 Finalise allocations used for option parsing before processing jobs.
 
int32 ClripUsage (const uint8 *program, char which, const char *error,...)
 Display help information for the clrip program, optionally restricting output to just one option. More...
 
void enable_color_console (int mode)
 Hook provided by platform to enable color console output.
 

Variables

HqBool fLogStderr
 
SwLeDoParams doparams = { sizeof(doparams) }
 The parameters structure used for calls to SwLeDo().
 
int stuff_to_do
 
HqBool fLogStderr
 
int stuff_to_do
 
SwLeDoParams doparams
 The parameters structure used for calls to SwLeDo().
 

Detailed Description

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Bitmask of stuff we've been asked to do.

Function Documentation

◆ AddFilesToInputQ()

static HqBool AddFilesToInputQ ( uint8 pattern,
const uint8 configName,
uint8 errbuf 
)
static

Add all of the files matching a pattern to the input queue.

Parameters
[in,out]patternA wildcard pattern for finding input files.
configNameA configuration name to use for printing the files.
[out]errbufA buffer of length at least LONGESTFILENAME into which an error message will be written if the function fails.
Return values
TRUEAll of the files matching the pattern were added to the input queue.
FALSEAn error occurred. An error message at most LONGESTFILENAME long was written into errbuf.

◆ ClripOption()

int32 ClripOption ( int32  option,
HqBool  sdkready,
HqBool  filenameConsumed,
HqBool(*)(void *data, int n)  args_used,
uint8 *(*)(void *data, int index, HqBool keep)  arg_to_utf8,
uint8 *(*)(void *data)  program_name,
void *  data 
)

Parse common options for all platform versions of clrip.

Parameters
[in]optionThe option character(s). Options may have multiple characters; up to four characters are packed into this parameter, but longer options can be checked by calling the arg_to_utf8() callback to examine the option itself.
sdkreadyArgument parsing is handled in two passes, one before initialising the RIP SDK, and the other after. The first pass should be used to handle options that affect the initial state of the SDK, or for idempotent flags; the second pass should be used to process configurations and job files. Processing of options for both passes should call the args_used() callback with the same number of arguments to consume. This flag is passed onto the ClripUsage() function in the case of an error, indicating whether the SDK should be shutdown before returning.
filenameConsumedSet to TRUE to indicate that a filename has just been consumed from the argument list. This is only used for argument handling sanity checks.
args_usedA callback function used to indicate how many arguments were consumed by the call. The function must return FALSE if the number of arguments requested are not available. It may be called multiple times in a single ClripOption() call: the final call is the number of arguments to be consumed. If this function is not called, or the final call used the value zero, then the option was not recognised by ClripOption(), and the caller should take appropriate action.
arg_to_utf8A function pointer called to convert an argument to UTF-8, and return it to the caller. The index passed to the callback is a zero-based index relative to the option argument itself. It will always be less than the number of arguments indicated by the preceding args_used() callback. The keep boolean passed to the callback indicates if the caller needs to retain the data beyond the scope of this ClripOption() call.
program_nameA callback function to return the program name (without directory path) in UTF-8. This is only called immediately prior to issuing an error message with ClripUsage().
dataAn opaque data pointer passed to all of the callback functions, indicating the platform-specific state of argument parsing.
Return values
EXIT_FAILUREif the option had an error. The error information has already been reported.
EXIT_SUCCESSif the option was successfully processed, or the option was not recognised. If the option was successfully processed, then the final args_used() callback will indicate one or more argument was used.

◆ ClripOptionInitialize()

void ClripOptionInitialize ( HqBool  sdkinit)

Initialise common options to empty or default values.

Parameters
sdkinitIf TRUE, this is before a full SDK init. If FALSE, we are resetting just the core RIP.

◆ ClripUsage()

int32 ClripUsage ( const uint8 program,
char  which,
const char *  error,
  ... 
)

Display help information for the clrip program, optionally restricting output to just one option.

Parameters
[in]programThe name of the program, i.e., the leafname of the RIP executable, as stored in argv[0].
whichThe option to report help for, or zero for all options.
[in]errorAn optional error format to print before reporting individual option help. All remaining parameters after this format string are interpreted according to the fprintf() specification.
Returns
Always returns EXIT_FAILURE.

◆ cpuid_fail()

static HqBool cpuid_fail ( char *  reason)
static

This CPU does not mean the minimum system requirements. Inform the user and exit.

◆ do_cpuid()

static void do_cpuid ( uint32 info,
uint32  id 
)
static

Call the OS to generate the cpuid intrinsic.

Double-check to make sure the given id is a valid call on this CPU, and pre-clear the 4 integer results array so that if there is any problem we will default to no SIMD available.

◆ extendLibrarySearchPath()

static HqBool extendLibrarySearchPath ( char *  pszPath)
static

Simple utility to add an extra entry to the end of the PATH environment variable.

The current value of PATH is obtained, and then extended with a semicolon followed by the string pszPath. The resulting string is applied as the new value of PATH.

Extending the PATH is a useful and generic way of broadening the search for DLLs. An alternative way to do this is to use the SetDllDirectory API, provided by Windows XP SP1 and later versions.

Parameters
[in]pszPathDirectory to add to PATH.
Return values
TRUEIf the path was extended
FALSEIf the path could not be extended

◆ le_exception_handler()

static void le_exception_handler ( char *  mess)
static

Output an exception message to stderr. This is installed as the exception handler for debug builds, to write out stack trace information.

◆ monitorCallback()

static void monitorCallback ( uint32  bufLen,
const uint8 u8buf 
)
static

Monitor information callback.

Parameters
bufLenThe length of the monitor information in u8buf.
[in]u8bufA buffer of data to write to the monitor.

The data in the buffer should be UTF-8 encoded, but this is not uniformly enforced yet. This function converts the buffer to wide characters, for console output on Windows, and routes it through the monitorFile() call to send it to the logfile(s), stdout, or stderr.

◆ MountDriveType()

static HqBool MountDriveType ( char *  pRootPath)
static

Predicate to determine whether a drive attached on this machine should be mounted on the RIP.

◆ ParseArguments()

static int32 ParseArguments ( int  argc,
WCHAR **  argv,
HqBool  sdkready 
)
static

Run the entire argument parsing loop for pre- or post- SDK cases.

◆ PlatformOption()

static int32 PlatformOption ( int32  option,
HqBool  sdkready,
HqBool(*)(void *data, int n)  args_used,
uint8 *(*)(void *data, int index, HqBool keep)  arg_to_utf8,
uint8 *(*)(void *data)  program_name,
void *  data 
)
static

Options that are handled by platform-specific code, either because the option is platform-specific, or the action requires a platform-specific function. We use the same parsing framework as the common options for consistency.

◆ PlatformOptionInitialize()

static void PlatformOptionInitialize ( HqBool  sdkinit)
static

Initialize platform-specific options before argument parsing.

◆ PrepareProcessing()

int32 PrepareProcessing ( uint8 *(*)(void *data)  program_name,
void *  data 
)

Prepare to process jobs by determining whether the stuff_to_do fields are consistent, and start the appropriate extra processing threads if necessary.

Parameters
program_nameA callback function to return the program name (without directory path) in UTF-8. This is only called immediately prior to issuing an error message with ClripUsage().
dataAn opaque data pointer passed to all of the callback functions, indicating the platform-specific state of argument parsing.
Return values
EXIT_FAILUREif the processing requested had an error. The error information has already been reported.
EXIT_SUCCESSif the processing was successfully prepared.

◆ PTNextDrive()

HqBool PTNextDrive ( int32  index,
uint8 pDrivename 
)

Called by MountAllDrives() to get the next (first if index == 0) drive that is on the machine.

Returns
FALSE when there are no more drives, and TRUE if it has more. The returned pDrivename can be an empty string.

◆ verify_system_requirements()

static HqBool verify_system_requirements ( void  )
static

Check that the machine meets the minimum system requirements.

By generating the cpuid intrinsic we can discover the level of SIMD supported by the CPU. Make sure we have at least the minimum level mandated by the code optimisations in use.

For Hqn 13, the RIP requires and uses SSE2 and below. For Hqn 14, we are mandating AVX2 and below on x86-amd64.

The hierarchy and introduction dates of SIMD are:

  • 1996 MMX = Intel MMX extensions for x86 architecture
  • 1998 3DNow!
  • 1999 SSE = Streaming SIMD Extensions
  • 2000 SSE2
  • 2004 SSE3
  • 2006 SSSE3
  • 2007 SSE4
  • 2007 SSE4.1 (minimal level required by Windows 11)
  • 2008 SSE4.2
  • 2009 XOP, FMA4, F16C
  • 2011 AVX = Advanced Vector Extensions
  • 2013 AVX2
  • 2016 AVX-512

◆ wchar_to_utf8()

static uint8* wchar_to_utf8 ( WCHAR *  arg,
HqBool  keep 
)
static

Convert zero-terminated wide-character argument to UTF8, retaining the argument in a static buffer if required.

◆ wmain()

int __cdecl wmain ( int  argc,
WCHAR *  argv[] 
)

The main entry point to the Windows version of the clrip command-line RIP application.

For pedagogical purposes, this command-line skin allows the entire RIP lifecycle to be run several times, using the -z (repeat count) option. This is not likely to be useful in production. The wmain() function is structured with a short startup sequence, a short finalisation sequence, and a repeat loop in between. The repeat loop shows all of the actions that need to be taken to initialise the SDK, process jobs using the RIP, and shut the SDK down. The actual RIP startup and shutdown is performed in the ProcessJobs() function.

Arguments to wmain() are scanned in two phases:

  • Before starting the SDK, so that options that affect the how the SDK is initialised, such as memory, directory changes, and Scalable RIP mode can be detected.
  • After starting the SDK, so that jobs can be added to the input queue, hotfolders can be monitored, and other options that require the SDK running can be processed.

This is a Unicode wide-character enabled entry point. Arguments and filenames are converted to UTF-8 by callbacks before being passed to the SDK or the RIP.

Variable Documentation

◆ fLogStderr [1/2]

HqBool fLogStderr

Send all MON_CHANNEL_STDERR event messages to stderr. By default, a compatibility mode is used where only messages originating in the skin or SDK are sent to stderr, RIP messages on MON_CHANNEL_STDERR are sent to stdout.

◆ fLogStderr [2/2]

HqBool fLogStderr
extern

Send all MON_CHANNEL_STDERR event messages to stderr. By default, a compatibility mode is used where only messages originating in the skin or SDK are sent to stderr, RIP messages on MON_CHANNEL_STDERR are sent to stdout.

◆ stuff_to_do [1/2]

int stuff_to_do

Variable holding bitmask of stuff we've been asked to do.

◆ stuff_to_do [2/2]

int stuff_to_do
extern

Variable holding bitmask of stuff we've been asked to do.