summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2008-02-13 10:26:53 -0800
committerAaron Plattner <aplattner@nvidia.com>2008-02-13 10:26:53 -0800
commit6d20700cde575d515a14a043f8ffe76171ed5355 (patch)
tree7941782a889ebb9ba8780abcfeeccbf654f06c0e
parent519a7f3cc9b213e2d1e7c94b64bd0d68d16bb872 (diff)
-rw-r--r--XF86Config-parser/Scan.c123
-rw-r--r--XF86Config-parser/Write.c25
-rw-r--r--nvidia-xconfig.c4
-rw-r--r--nvidia-xconfig.h1
-rw-r--r--option_table.h10
-rw-r--r--options.c9
6 files changed, 168 insertions, 4 deletions
diff --git a/XF86Config-parser/Scan.c b/XF86Config-parser/Scan.c
index 4e694ba..ab48af8 100644
--- a/XF86Config-parser/Scan.c
+++ b/XF86Config-parser/Scan.c
@@ -177,10 +177,129 @@ static unsigned int xconfigStrToUL (char *str)
}
+/*
+ * xconfigGetNextLine --
+ *
+ * read from the configFile FILE stream until we encounter a new
+ * line; this is effectively just a big wrapper for fgets(3).
+ *
+ * xconfigGetToken() assumes that we will read up to the next
+ * newline; we need to grow configBuf and configRBuf as needed to
+ * support that.
+ */
+
+static char *xconfigGetNextLine()
+{
+ static int configBufLen = CONFIG_BUF_LEN;
+ char *tmpConfigBuf, *tmpConfigRBuf;
+ int c, i, pos = 0, eolFound = 0;
+ char *ret = NULL;
+
+ /*
+ * reallocate the string if it was grown last time (i.e., is no
+ * longer CONFIG_BUF_LEN); we malloc the new strings first, so
+ * that if either of the mallocs fail, we can fall back on the
+ * existing buffer allocations
+ */
+
+ if (configBufLen != CONFIG_BUF_LEN) {
+
+ tmpConfigBuf = malloc(CONFIG_BUF_LEN);
+ tmpConfigRBuf = malloc(CONFIG_BUF_LEN);
+
+ if (!tmpConfigBuf || !tmpConfigRBuf) {
+
+ /*
+ * at least one of the mallocs failed; keep the old buffers
+ * and free any partial allocations
+ */
+
+ free(tmpConfigBuf);
+ free(tmpConfigRBuf);
+
+ } else {
+
+ /*
+ * malloc succeeded; free the old buffers and use the new
+ * buffers
+ */
+
+ configBufLen = CONFIG_BUF_LEN;
+
+ free(configBuf);
+ free(configRBuf);
+
+ configBuf = tmpConfigBuf;
+ configRBuf = tmpConfigRBuf;
+ }
+ }
+
+ /* read in another block of chars */
+
+ do {
+ ret = fgets(configBuf + pos, configBufLen - pos - 1, configFile);
+
+ if (!ret) break;
+
+ /* search for EOL in the new block of chars */
+
+ for (i = pos; i < (configBufLen - 1); i++) {
+ c = configBuf[i];
+
+ if (c == '\0') break;
+
+ if ((c == '\n') || (c == '\r')) {
+ eolFound = 1;
+ break;
+ }
+ }
+
+ /*
+ * if we didn't find EOL, then grow the string and
+ * read in more
+ */
+
+ if (!eolFound) {
+
+ tmpConfigBuf = realloc(configBuf, configBufLen + CONFIG_BUF_LEN);
+ tmpConfigRBuf = realloc(configRBuf, configBufLen + CONFIG_BUF_LEN);
+
+ if (!tmpConfigBuf || !tmpConfigRBuf) {
+
+ /*
+ * at least one of the reallocations failed; use the
+ * new allocation that succeeded, but we have to
+ * fallback to the previous configBufLen size and use
+ * the string we have, even though we don't have an
+ * EOL
+ */
+
+ if (tmpConfigBuf) configBuf = tmpConfigBuf;
+ if (tmpConfigRBuf) configRBuf = tmpConfigRBuf;
+
+ break;
+
+ } else {
+
+ /* reallocation succeeded */
+
+ configBuf = tmpConfigBuf;
+ configRBuf = tmpConfigRBuf;
+ pos = i;
+ configBufLen += CONFIG_BUF_LEN;
+ }
+ }
+
+ } while (!eolFound);
+
+ return ret;
+}
+
+
/*
* xconfigGetToken --
- * Read next Token form the config file. Handle the global variable
+ * Read next Token from the config file. Handle the global variable
* pushToken.
*/
@@ -214,7 +333,7 @@ again:
{
char *ret;
if (configFile)
- ret = fgets (configBuf, CONFIG_BUF_LEN - 1, configFile);
+ ret = xconfigGetNextLine();
else {
if (builtinConfig[builtinIndex] == NULL)
ret = NULL;
diff --git a/XF86Config-parser/Write.c b/XF86Config-parser/Write.c
index a1658e2..12d78f7 100644
--- a/XF86Config-parser/Write.c
+++ b/XF86Config-parser/Write.c
@@ -64,10 +64,13 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <locale.h>
+
int xconfigWriteConfigFile (const char *filename, XConfigPtr cptr)
{
FILE *cf;
+ char *locale;
if ((cf = fopen(filename, "w")) == NULL)
{
@@ -76,6 +79,20 @@ int xconfigWriteConfigFile (const char *filename, XConfigPtr cptr)
return FALSE;
}
+ /*
+ * read the current locale and then set the standard "C" locale,
+ * so that the X configuration writer does not use locale-specific
+ * formatting. After writing the configuration file, we restore
+ * the original locale.
+ */
+
+ locale = setlocale(LC_ALL, NULL);
+
+ if (locale) locale = strdup(locale);
+
+ setlocale(LC_ALL, "C");
+
+
if (cptr->comment)
fprintf (cf, "%s\n", cptr->comment);
@@ -110,5 +127,13 @@ int xconfigWriteConfigFile (const char *filename, XConfigPtr cptr)
xconfigPrintExtensionsSection (cf, cptr->extensions);
fclose(cf);
+
+ /* restore the original locale */
+
+ if (locale) {
+ setlocale(LC_ALL, locale);
+ free(locale);
+ }
+
return TRUE;
}
diff --git a/nvidia-xconfig.c b/nvidia-xconfig.c
index a810d4c..dfb43b5 100644
--- a/nvidia-xconfig.c
+++ b/nvidia-xconfig.c
@@ -579,6 +579,10 @@ Options *parse_commandline(int argc, char *argv[])
break;
}
+ case LOGO_PATH_OPTION:
+ op->logo_path = disable ? NV_DISABLE_STRING_OPTION : strval;
+ break;
+
default:
goto fail;
}
diff --git a/nvidia-xconfig.h b/nvidia-xconfig.h
index 593944d..521e494 100644
--- a/nvidia-xconfig.h
+++ b/nvidia-xconfig.h
@@ -153,6 +153,7 @@ typedef struct __options {
char *extract_edids_from_log;
char *extract_edids_output_file;
char *twinview_xinerama_info_order;
+ char *logo_path;
char *twinview_orientation;
struct {
diff --git a/option_table.h b/option_table.h
index 41660d0..6eaec1f 100644
--- a/option_table.h
+++ b/option_table.h
@@ -32,8 +32,9 @@
#define EXTRACT_EDIDS_OUTPUT_FILE_OPTION 21
#define MULTI_GPU_OPTION 22
#define TWINVIEW_XINERAMA_INFO_ORDER_OPTION 23
-#define TWINVIEW_ORIENTATION_OPTION 24
-#define VIRTUAL_OPTION 25
+#define LOGO_PATH_OPTION 24
+#define TWINVIEW_ORIENTATION_OPTION 25
+#define VIRTUAL_OPTION 26
/*
* To add a boolean option to nvidia-xconfig:
@@ -272,6 +273,11 @@ static const NVGetoptOption __options[] = {
XCONFIG_BOOL_VAL(NOLOGO_BOOL_OPTION), NVGETOPT_IS_BOOLEAN, NULL,
"Disable or enable the \"NoLogo\" X configuration option." },
+ { "logo-path", LOGO_PATH_OPTION,
+ NVGETOPT_STRING_ARGUMENT | NVGETOPT_ALLOW_DISABLE, "PATH",
+ "Set the path to the PNG file to be used as the logo splash screen at X "
+ "server startup." },
+
{ "mode",
MODE_OPTION, NVGETOPT_IS_BOOLEAN | NVGETOPT_STRING_ARGUMENT, NULL,
"Add the specified mode to the mode list." },
diff --git a/options.c b/options.c
index c5d561f..5d7c081 100644
--- a/options.c
+++ b/options.c
@@ -366,4 +366,13 @@ void update_options(Options *op, XConfigScreenPtr screen)
}
}
+ /* add the LogoPath option */
+
+ if (op->logo_path) {
+ remove_option(screen, "LogoPath");
+ if (op->logo_path != NV_DISABLE_STRING_OPTION) {
+ set_option_value(screen, "LogoPath", op->logo_path);
+ }
+ }
+
} /* update_options() */