Use console properties. Add the --no-utf8 and --color options.

This commit is contained in:
Kugel Fuhr
2025-07-08 20:54:59 +02:00
parent da0e3907ec
commit 6f45af3c9e
2 changed files with 48 additions and 1 deletions

View File

@@ -73,6 +73,7 @@ Short options:
Long options:
--allow-multiple-definition Allow multiple definitions
--cfg-path path Specify a config file search path
--color [on|auto|off] Color diagnostics (default: auto)
--config name Use linker config file
--dbgfile name Generate debug information
--define sym=val Define a symbol
@@ -84,13 +85,13 @@ Long options:
--lib-path path Specify a library search path
--mapfile name Create a map file
--module-id id Specify a module id
--no-utf8 Disable use of UTF-8 in diagnostics
--obj file Link this object file
--obj-path path Specify an object file search path
--start-addr addr Set the default start address
--start-group Start a library group
--target sys Set the target system
--version Print the linker version
--warnings-as-errors Treat warnings as errors
---------------------------------------------------------------------------
</verb></tscreen>
@@ -292,6 +293,14 @@ Here is a description of all of the command-line options:
and in a built-in default directory.
<label id="option--color">
<tag><tt>--color</tt></tag>
This option controls if the linker will use colors when printing
diagnostics. The default is "auto" which will enable colors if the output
goes to a terminal (not to a file).
<label id="option--dbgfile">
<tag><tt>--dbgfile name</tt></tag>
@@ -315,6 +324,14 @@ Here is a description of all of the command-line options:
type because of an unusual extension.
<label id="option--no-utf8">
<tag><tt>--no-utf8</tt></tag>
Disable the use of UTF-8 characters in diagnostics. This might be necessary
if auto detection fails or if the output is captured for processing with a
tool that is not UTF-8 capable.
<tag><tt>--obj file</tt></tag>
Links an object file to the output. Use this command-line option instead

View File

@@ -54,6 +54,7 @@
#include "asserts.h"
#include "binfmt.h"
#include "condes.h"
#include "consprop.h"
#include "config.h"
#include "dbgfile.h"
#include "error.h"
@@ -130,6 +131,7 @@ static void Usage (void)
"Long options:\n"
" --allow-multiple-definition\tAllow multiple definitions\n"
" --cfg-path path\t\tSpecify a config file search path\n"
" --color [on|auto|off]\t\tColor diagnostics (default: auto)\n"
" --config name\t\t\tUse linker config file\n"
" --dbgfile name\t\tGenerate debug information\n"
" --define sym=val\t\tDefine a symbol\n"
@@ -141,6 +143,7 @@ static void Usage (void)
" --lib-path path\t\tSpecify a library search path\n"
" --mapfile name\t\tCreate a map file\n"
" --module-id id\t\tSpecify a module id\n"
" --no-utf8\t\t\tDisable use of UTF-8 in diagnostics\n"
" --obj file\t\t\tLink this object file\n"
" --obj-path path\t\tSpecify an object file search path\n"
" --start-addr addr\t\tSet the default start address\n"
@@ -310,6 +313,19 @@ static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
static void OptColor(const char* Opt, const char* Arg)
/* Handle the --color option */
{
ColorMode Mode = CP_Parse (Arg);
if (Mode == CM_INVALID) {
Error ("Invalid argument to %s: %s", Opt, Arg);
} else {
CP_SetColorMode (Mode);
}
}
static void OptConfig (const char* Opt attribute ((unused)), const char* Arg)
/* Define the config file */
{
@@ -457,6 +473,15 @@ static void OptModuleId (const char* Opt, const char* Arg)
static void OptNoUtf8 (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Handle the --no-utf8 option */
{
CP_DisableUTF8 ();
}
static void OptObj (const char* Opt attribute ((unused)), const char* Arg)
/* Link an object file */
{
@@ -629,6 +654,7 @@ static void ParseCommandLine(void)
static const LongOpt OptTab[] = {
{ "--allow-multiple-definition", 0, OptMultDef },
{ "--cfg-path", 1, OptCfgPath },
{ "--color", 1, OptColor },
{ "--config", 1, CmdlOptConfig },
{ "--dbgfile", 1, OptDbgFile },
{ "--define", 1, OptDefine },
@@ -640,6 +666,7 @@ static void ParseCommandLine(void)
{ "--lib-path", 1, OptLibPath },
{ "--mapfile", 1, OptMapFile },
{ "--module-id", 1, OptModuleId },
{ "--no-utf8", 0, OptNoUtf8 },
{ "--obj", 1, OptObj },
{ "--obj-path", 1, OptObjPath },
{ "--start-addr", 1, OptStartAddr },
@@ -800,6 +827,9 @@ int main (int argc, char* argv [])
{
unsigned MemoryAreaOverflows;
/* Initialize console output */
CP_Init ();
/* Initialize the cmdline module */
InitCmdLine (&argc, &argv, "ld65");