|
From: <ai...@us...> - 2008-10-04 22:28:15
|
Revision: 8852
http://plplot.svn.sourceforge.net/plplot/?rev=8852&view=rev
Author: airwin
Date: 2008-10-04 22:23:53 +0000 (Sat, 04 Oct 2008)
Log Message:
-----------
Within plGetFam restore initial page status (which is necessarily AT_BOP for
current plGetFam usage) after the plP_init call. This solves a bug where
pages without a change to pls->page_status (e.g., empty pages and pages
which consisted just of text such as the last few pages in example 23) were
indirectly turning plP_eop into a no-op for familying because plP_init sets
the page_status to AT_EOP.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2008-10-04 20:24:08 UTC (rev 8851)
+++ trunk/src/plctrl.c 2008-10-04 22:23:53 UTC (rev 8852)
@@ -1931,10 +1931,15 @@
PLFLT xpmm_loc, ypmm_loc;
if (pls->family) {
if (pls->bytecnt > pls->bytemax || pls->famadv) {
+ PLINT local_page_status = pls->page_status;
plP_tidy();
pls->member += pls->finc;
pls->famadv = 0;
plP_init();
+ /* Restore page status (normally AT_BOP) that was changed
+ * to AT_EOP by plP_init. */
+ pls->page_status = local_page_status;
+
/* Apply compensating factor to original xpmm and ypmm so that
* character aspect ratio is preserved when overall aspect ratio
* is changed. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sm...@us...> - 2009-01-29 08:38:50
|
Revision: 9413
http://plplot.svn.sourceforge.net/plplot/?rev=9413&view=rev
Author: smekal
Date: 2009-01-29 08:38:36 +0000 (Thu, 29 Jan 2009)
Log Message:
-----------
strcat_delim() now adds backslash also for WIN32 case and not only for MSDOS case.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-01-28 20:35:44 UTC (rev 9412)
+++ trunk/src/plctrl.c 2009-01-29 08:38:36 UTC (rev 9413)
@@ -1716,7 +1716,7 @@
strcat_delim(char *dirspec)
{
int ldirspec = strlen(dirspec);
-#if defined (MSDOS)
+#if defined (MSDOS) || defined(WIN32)
if (dirspec[ldirspec-1] != '\\')
strcat(dirspec, "\\");
#elif defined (macintosh)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-02-07 17:26:37
|
Revision: 9470
http://plplot.svn.sourceforge.net/plplot/?rev=9470&view=rev
Author: andrewross
Date: 2009-02-07 17:26:32 +0000 (Sat, 07 Feb 2009)
Log Message:
-----------
Update plP_getmember so familying works even where filename includes %. Avoid using
user-supplied strings as format strings in sprintf. This removes potential security
issue.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-02-07 13:54:45 UTC (rev 9469)
+++ trunk/src/plctrl.c 2009-02-07 17:26:32 UTC (rev 9470)
@@ -1838,6 +1838,7 @@
char tmp[256];
char prefix[256];
char* suffix;
+ char num[12];
if (pls->FileName == NULL)
{
@@ -1849,15 +1850,17 @@
suffix = strstr (pls->BaseName, "%n");
+ sprintf(tmp, "%%0%1ii", (int) pls->fflen);
+ sprintf(num, tmp, pls->member);
+
if (suffix == NULL)
- sprintf (tmp, "%s.%%0%1ii", pls->BaseName, (int) pls->fflen);
+ sprintf (pls->FileName, "%s.%s", pls->BaseName, num);
else {
strncpy (prefix, pls->BaseName, 256);
prefix [suffix - pls->BaseName] = 0;
- sprintf (tmp, "%s%%0%1ii%s", prefix, (int) pls->fflen, suffix + 2);
+ sprintf (pls->FileName, "%s%s%s", prefix, num, suffix + 2);
}
- sprintf(pls->FileName, tmp, pls->member);
}
/*--------------------------------------------------------------------------*\
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-02-09 10:47:40
|
Revision: 9479
http://plplot.svn.sourceforge.net/plplot/?rev=9479&view=rev
Author: andrewross
Date: 2009-02-09 10:47:34 +0000 (Mon, 09 Feb 2009)
Log Message:
-----------
Modify plsnprintf so that plplot will abort if a buffer overrun occurs.
This is only used if snprintf is not natively available, and instead it
calls sprintf. We can detect when an overflow occurs, but not prevent
it, so the safest thing is probably to abort.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-02-09 09:41:11 UTC (rev 9478)
+++ trunk/src/plctrl.c 2009-02-09 10:47:34 UTC (rev 9479)
@@ -2151,6 +2151,10 @@
va_start(args, format);
ret=vsprintf(buffer, fmt, args);
va_end( argptr );
+
+ /* Check if overrun occured */
+ if (ret > n-1)
+ plabort("plsnprintf: buffer overrun");
return ret;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hba...@us...> - 2009-07-08 23:50:12
|
Revision: 10124
http://plplot.svn.sourceforge.net/plplot/?rev=10124&view=rev
Author: hbabcock
Date: 2009-07-08 23:50:09 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
Changed to use plLibOpen() instead of fopen().
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-08 19:07:11 UTC (rev 10123)
+++ trunk/src/plctrl.c 2009-07-08 23:50:09 UTC (rev 10124)
@@ -1224,7 +1224,7 @@
char color_info[30];
FILE *fp;
- fp = fopen(filename, "r");
+ fp = (FILE *)plLibOpen(filename);
fscanf(fp, "%d\n", &number_colors);
for(i=0;i<number_colors;i++){
fgets(color_info, 30, fp);
@@ -1264,7 +1264,7 @@
FILE *fp;
have_alpha = 1;
- fp = fopen(filename, "r");
+ fp = (FILE *)plLibOpen(filename);
fscanf(fp, "%d\n", &number_colors);
r = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
g = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
@@ -1646,8 +1646,9 @@
/**** search current directory ****/
- if ((file = pdf_fopen(fn, "rb")) != NULL)
+ if ((file = pdf_fopen(fn, "rb")) != NULL){
goto done;
+ }
/**** search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib ****/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-07-10 00:20:47
|
Revision: 10133
http://plplot.svn.sourceforge.net/plplot/?rev=10133&view=rev
Author: airwin
Date: 2009-07-10 00:20:46 +0000 (Fri, 10 Jul 2009)
Log Message:
-----------
Fix bug for old format where rgb colours were not properly normalized.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-10 00:17:31 UTC (rev 10132)
+++ trunk/src/plctrl.c 2009-07-10 00:20:46 UTC (rev 10133)
@@ -1344,9 +1344,11 @@
break;
}
return_sscanf_old = return_sscanf;
- r[i] = (PLFLT)r_i;
- g[i] = (PLFLT)g_i;
- b[i] = (PLFLT)b_i;
+ /* For old format, input colours range from 0 to 255 and
+ need to be renormalized to the range from 0. to 1.. */
+ r[i] = (PLFLT)r_i/255.;
+ g[i] = (PLFLT)g_i/255.;
+ b[i] = (PLFLT)b_i/255.;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
if(return_sscanf == 5) {
@@ -1369,7 +1371,9 @@
plwarn(msgbuf);
err = 1;
break;
- }
+ }
+ /* For rgb case of new format colours are already normalized from
+ 0., to 1. */
r[i] = (PLFLT)r_d;
g[i] = (PLFLT)g_d;
b[i] = (PLFLT)b_d;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-07-10 06:21:21
|
Revision: 10135
http://plplot.svn.sourceforge.net/plplot/?rev=10135&view=rev
Author: airwin
Date: 2009-07-10 06:21:20 +0000 (Fri, 10 Jul 2009)
Log Message:
-----------
Call plscmap0n from within plspal0 to allocate sufficient cmap0 colour space
to accomodate the specified number of colours.
Implement some additional range checking within plspal[01]. Most of this
checking is routine, but demand at least 16 cmap0 colours to make it
impossible to starve cmap0 colours with the plscmap0n call referred to
above.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-10 01:54:08 UTC (rev 10134)
+++ trunk/src/plctrl.c 2009-07-10 06:21:20 UTC (rev 10135)
@@ -1232,12 +1232,13 @@
plwarn(msgbuf);
return;
}
- if (fscanf(fp, "%d\n", &number_colors) != 1) {
+ if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 16) {
snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
plwarn(msgbuf);
fclose(fp);
return;
}
+ plscmap0n(number_colors);
for(i=0;i<number_colors;i++){
fgets(color_info, 30, fp);
color_info[strlen(color_info)-1] = '\0'; /* remove return character */
@@ -1255,6 +1256,11 @@
plwarn(msgbuf);
break;
}
+ if(a < 0. || a > 1.) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
+ plwarn(msgbuf);
+ break;
+ }
c_plscol0a(i, r, g, b, (PLFLT) a);
}
else{
@@ -1315,7 +1321,7 @@
fgets(color_info, 160, fp);
}
- if (sscanf(color_info, "%d\n", &number_colors) != 1) {
+ if (sscanf(color_info, "%d\n", &number_colors) != 1 || number_colors < 2) {
snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
plwarn(msgbuf);
fclose(fp);
@@ -1351,6 +1357,12 @@
b[i] = (PLFLT)b_i/255.;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
+ if(pos[i] < 0. || pos[i] > 1.) {
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
+ plwarn(msgbuf);
+ err = 1;
+ break;
+ }
if(return_sscanf == 5) {
/* Next to oldest tk format with rev specified. */
rev[i] = (PLBOOL)rev_i;
@@ -1372,8 +1384,21 @@
err = 1;
break;
}
- /* For rgb case of new format colours are already normalized from
- 0., to 1. */
+ /* Check that all rgba and pos data within range from 0. to
+ 1. except for the hls colour space case where the first
+ coordinate is checked within range from 0. to 360.*/
+ if((rgb && (r_d < 0. || r_d > 1.)) ||
+ (!rgb && (r_d < 0. || r_d > 360.)) ||
+ g_d < 0. || g_d > 1. ||
+ b_d < 0. || b_d > 1. ||
+ a_d < 0. || a_d > 1. ||
+ pos_d < 0. || pos_d > 1.) {
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
+ plwarn(msgbuf);
+ err = 1;
+ break;
+ }
+
r[i] = (PLFLT)r_d;
g[i] = (PLFLT)g_d;
b[i] = (PLFLT)b_d;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-07-11 17:55:35
|
Revision: 10141
http://plplot.svn.sourceforge.net/plplot/?rev=10141&view=rev
Author: airwin
Date: 2009-07-11 17:55:34 +0000 (Sat, 11 Jul 2009)
Log Message:
-----------
Allocate cmap0 colours for plspal0 only if current set is insufficient to
contain data in cmap0 palette file. This allows a cmap0 palette file to
override the first colours in an existing cmap0 palette without disturbing
the rest.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-11 17:26:13 UTC (rev 10140)
+++ trunk/src/plctrl.c 2009-07-11 17:55:34 UTC (rev 10141)
@@ -1232,13 +1232,21 @@
plwarn(msgbuf);
return;
}
- if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 16) {
+ if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 1) {
snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
plwarn(msgbuf);
fclose(fp);
return;
}
- plscmap0n(number_colors);
+
+ /* Allocate default number of cmap0 colours if cmap0 allocation not
+ done already. */
+ plscmap0n(0);
+ /* Allocate sufficient cmap0 colours to contain present data. */
+ if(number_colors > plsc->ncol0) {
+ plscmap0n(number_colors);
+ }
+
for(i=0;i<number_colors;i++){
fgets(color_info, 30, fp);
color_info[strlen(color_info)-1] = '\0'; /* remove return character */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-07-28 18:52:09
|
Revision: 10185
http://plplot.svn.sourceforge.net/plplot/?rev=10185&view=rev
Author: airwin
Date: 2009-07-28 18:51:57 +0000 (Tue, 28 Jul 2009)
Log Message:
-----------
Use default colour palette files if the filename is an empty string.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-28 16:44:08 UTC (rev 10184)
+++ trunk/src/plctrl.c 2009-07-28 18:51:57 UTC (rev 10185)
@@ -1225,12 +1225,21 @@
char color_info[30];
FILE *fp;
char msgbuf[1024];
-
- fp = plLibOpen(filename);
- if (fp == NULL) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
- plwarn(msgbuf);
- return;
+
+ if(strlen(filename) == 0) {
+ fp = plLibOpen("cmap0_default.pal");
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n","cmap0_default.pal");
+ plwarn(msgbuf);
+ return;
+ }
+ } else {
+ fp = plLibOpen(filename);
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
+ plwarn(msgbuf);
+ return;
+ }
}
if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 1) {
snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
@@ -1306,13 +1315,21 @@
rgb = TRUE;
err = 0;
format_version = 0;
- fp = plLibOpen(filename);
- if (fp == NULL) {
- snprintf(msgbuf,1024,"Unable to open cmap1 .pal file %s\n",filename);
- plwarn(msgbuf);
- return;
+ if(strlen(filename) == 0) {
+ fp = plLibOpen("cmap1_default.pal");
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap1 .pal file %s\n","cmap1_default.pal");
+ plwarn(msgbuf);
+ return;
+ }
+ } else {
+ fp = plLibOpen(filename);
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap1 .pal file %s\n",filename);
+ plwarn(msgbuf);
+ return;
+ }
}
-
/* Check for new file format */
fgets(color_info, 160, fp);
if (strncmp(color_info,"v2 ",2) == 0) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-24 02:38:49
|
Revision: 10318
http://plplot.svn.sourceforge.net/plplot/?rev=10318&view=rev
Author: airwin
Date: 2009-08-24 02:38:41 +0000 (Mon, 24 Aug 2009)
Log Message:
-----------
Implement cmap0_palette_read to read and check a cmap0 palette file. Call
this function from plcmap0_def to always define default colours between imin
and imax (which returns to previous behaviour for calls to plscmap0n and
which therefore solves the recently introduced uniform red cmap0 issue).
Also call this function from an updated plspal0.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-24 00:27:25 UTC (rev 10317)
+++ trunk/src/plctrl.c 2009-08-24 02:38:41 UTC (rev 10318)
@@ -7,6 +7,7 @@
Copyright (C) 2004 Joao Cardoso
Copyright (C) 2004 Rafael Laboissiere
Copyright (C) 2008 Hazen Babcock
+ Copyright (C) 2009 Alan W. Irwin
This file is part of PLplot.
@@ -55,6 +56,9 @@
#define BUFFER_SIZE 256
+#define color_def(i, r, g, b, a, n) \
+ if (i >= imin && i <= imax) color_set(i, r, g, b, a, n);
+
/* Static functions */
/* Used by any external init code to suggest a path */
@@ -81,6 +85,9 @@
static PLFLT
value(double n1, double n2, double hue);
+static int
+cmap0_palette_read(const char *filename,
+ int *number_colors, int **r, int **g, int **b, double **a);
/* An additional hardwired location for lib files. */
/* I have no plans to change these again, ever. */
@@ -783,7 +790,7 @@
/* Allocate the space */
if (plsc->cmap0 == NULL) {
- if ((plsc->cmap0 = (PLColor *) calloc(1, size))==NULL)
+ if ((plsc->cmap0 = (PLColor *) calloc(1, size))==NULL)
{
plexit("c_plscmap0n: Insufficient memory");
}
@@ -807,6 +814,75 @@
}
/*--------------------------------------------------------------------------*\
+ * color_set()
+ *
+ * Initializes color table entry by RGB values.
+\*--------------------------------------------------------------------------*/
+
+void
+color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, PLFLT a, char *name )
+{
+ plsc->cmap0[i].r = r;
+ plsc->cmap0[i].g = g;
+ plsc->cmap0[i].b = b;
+ plsc->cmap0[i].a = a;
+ plsc->cmap0[i].name = name;
+}
+
+/*--------------------------------------------------------------------------*\
+ * plcmap0_def()
+ *
+ * Initializes specified color map 0 color entry to its default.
+\*--------------------------------------------------------------------------*/
+
+void
+plcmap0_def(int imin, int imax)
+{
+ int i, rc, *r, *g, *b;
+ double *a;
+ int number_colors;
+ char msgbuf[1024];
+ if(imin <= imax) {
+ rc = cmap0_palette_read("", &number_colors, &r, &g, &b, &a);
+ if(rc == 1) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
+ plwarn(msgbuf);
+ return;
+ } else if(rc == 2) {
+ /* Should never get this return code for null string (default)
+ filename. */
+ snprintf(msgbuf,1024,"plcmap0_def: internal logic error \n");
+ plwarn(msgbuf);
+ return;
+ } else if(rc == 3) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
+ plwarn(msgbuf);
+ return;
+ } else if(rc > 3) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 format\n");
+ plwarn(msgbuf);
+ return;
+ }
+ for(i=imin;i<MIN(number_colors, imax+1);i++)
+ color_def(i, r[i], g[i], b[i], a[i], "color defined by palette file");
+
+ free(r);
+ free(g);
+ free(b);
+ free(a);
+
+ } else {
+ number_colors = 0;
+ }
+
+ /* Initialize all colours undefined by the default colour palette file
+ to opaque red as a warning. */
+ for (i = MAX(number_colors, imin); i <= imax; i++)
+ color_def(i, 255, 0, 0, 1.0,
+ "opaque red to mark not defined by palette file");
+}
+
+/*--------------------------------------------------------------------------*\
* plscmap1n()
*
* Set number of colors in cmap 1, (re-)allocate cmap 1, and set default
@@ -864,41 +940,6 @@
}
/*--------------------------------------------------------------------------*\
- * color_set()
- *
- * Initializes color table entry by RGB values.
-\*--------------------------------------------------------------------------*/
-
-static void
-color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, PLFLT a, char *name )
-{
- plsc->cmap0[i].r = r;
- plsc->cmap0[i].g = g;
- plsc->cmap0[i].b = b;
- plsc->cmap0[i].a = a;
- plsc->cmap0[i].name = name;
-}
-
-/*--------------------------------------------------------------------------*\
- * plcmap0_def()
- *
- * Initializes specified color map 0 color entry to its default.
-\*--------------------------------------------------------------------------*/
-
-#define color_def(i, r, g, b, a, n) \
- if (i >= imin && i <= imax) color_set(i, r, g, b, a, n);
-
-static void
-plcmap0_def(int imin, int imax)
-{
- int i;
-
- /* Initialize all unknown colours to red as a warning. */
- for (i = imin; i <= imax; i++)
- color_def(i, 255, 0, 0, 1.0, "red");
-}
-
-/*--------------------------------------------------------------------------*\
* plcmap1_def()
*
* Initializes color map 1.
@@ -911,7 +952,7 @@
* palette editor. If you don't like these settings.. change them!
\*--------------------------------------------------------------------------*/
-static void
+void
plcmap1_def(void)
{
PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
@@ -1062,7 +1103,7 @@
* Auxiliary function used by c_plhlsrgb().
\*--------------------------------------------------------------------------*/
-static PLFLT
+PLFLT
value(double n1, double n2, double hue)
{
PLFLT val;
@@ -1170,87 +1211,124 @@
}
/*--------------------------------------------------------------------------*\
- * void c_plspal0(filename)
+ * int cmap0_palette_read()
*
- * Set the palette for color map 0 using a cmap0*.pal format file.
- * filename: the name of the cmap0*.pal file to use.
+ * Read and check r, g, b, a data from a cmap0*.pal format file.
+ * Non-zero return code means some error occurred.
+ * The caller must free the returned malloc'ed space for r, g, b, and a.
\*--------------------------------------------------------------------------*/
-void
-c_plspal0(const char *filename)
+int
+cmap0_palette_read(const char *filename,
+ int *number_colors, int **r, int **g, int **b, double **a)
{
- int i, r, g, b, nread;
- double a;
- int number_colors;
+ int i;
char color_info[30];
FILE *fp;
- char msgbuf[1024];
if(strlen(filename) == 0) {
fp = plLibOpen(PL_DEFAULT_CMAP0_FILE);
- if (fp == NULL) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
- plwarn(msgbuf);
- return;
- }
+ if (fp == NULL) return 1;
} else {
fp = plLibOpen(filename);
- if (fp == NULL) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
- plwarn(msgbuf);
- return;
- }
+ if (fp == NULL) return 2;
}
- if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 1) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
- plwarn(msgbuf);
+ if (fscanf(fp, "%d\n", number_colors) != 1 || *number_colors < 1) {
fclose(fp);
- return;
+ return 3;
}
- /* Allocate default number of cmap0 colours if cmap0 allocation not
- done already. */
- plscmap0n(0);
- /* Allocate sufficient cmap0 colours to contain present data. */
- if(number_colors > plsc->ncol0) {
- plscmap0n(number_colors);
+ /* Allocate arrays to hold r, g, b, and a data for calling routine.
+ The caller must free these after it is finished with them. */
+ if(((*r = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*g = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*b = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*a = (double *)malloc(*number_colors * sizeof(double))) == NULL)) {
+ fclose(fp);
+ plexit("cmap0_palette_read: insufficient memory");
}
-
- for(i=0;i<number_colors;i++){
+
+ for(i=0;i<*number_colors;i++){
fgets(color_info, 30, fp);
color_info[strlen(color_info)-1] = '\0'; /* remove return character */
if(strlen(color_info) == 7){
- if (sscanf(color_info, "#%2x%2x%2x", &r, &g, &b) != 3) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
- plwarn(msgbuf);
- break;
+ if (sscanf(color_info, "#%2x%2x%2x",
+ (int *) (*r+i), (int *) (*g+i), (int *) (*b+i)) != 3) {
+ fclose(fp);
+ return 4;
}
- c_plscol0(i, r, g, b);
+ *(*a+i) = 1.0;
}
else if(strlen(color_info) > 9){
- if (sscanf(color_info, "#%2x%2x%2x %lf", &r, &g, &b, &a) != 4) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
- plwarn(msgbuf);
- break;
+ if (sscanf(color_info, "#%2x%2x%2x %lf",
+ (int *) (*r+i), (int *) (*g+i), (int *) (*b+i),
+ (double *) (*a+i)) != 4) {
+ fclose(fp);
+ return 5;
}
- if(a < 0. || a > 1.) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
- plwarn(msgbuf);
- break;
+ if(*(*a+i) < 0. || *(*a+i) > 1.) {
+ fclose(fp);
+ return 6;
}
- c_plscol0a(i, r, g, b, (PLFLT) a);
+ } else {
+ fclose(fp);
+ return 7;
}
- else{
- snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
- plwarn(msgbuf);
- break;
- }
-
}
fclose(fp);
+ return 0;
}
/*--------------------------------------------------------------------------*\
+ * void c_plspal0(filename)
+ *
+ * Set the palette for color map 0 using a cmap0*.pal format file.
+ * filename: the name of the cmap0*.pal file to use.
+\*--------------------------------------------------------------------------*/
+
+void
+c_plspal0(const char *filename)
+{
+ int i, *r, *g, *b;
+ double *a;
+ int number_colors;
+ char msgbuf[1024];
+ int rc = cmap0_palette_read(filename, &number_colors, &r, &g, &b, &a);
+ if(rc == 1) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
+ plwarn(msgbuf);
+ return;
+ } else if(rc == 2) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
+ plwarn(msgbuf);
+ return;
+ } else if(rc == 3) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
+ plwarn(msgbuf);
+ return;
+ } else if(rc > 3) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 format\n");
+ plwarn(msgbuf);
+ return;
+ }
+
+ /* Allocate default number of cmap0 colours if cmap0 allocation not
+ done already. */
+ plscmap0n(0);
+ /* Allocate sufficient cmap0 colours to contain present data. */
+ if(number_colors > plsc->ncol0) {
+ plscmap0n(number_colors);
+ }
+ for(i=0;i<number_colors;i++){
+ c_plscol0a(i, r[i], g[i], b[i], a[i]);
+ }
+ free(r);
+ free(g);
+ free(b);
+ free(a);
+}
+
+/*--------------------------------------------------------------------------*\
* void c_plspal1(filename)
*
* Set the palette for color map 1 using a cmap1*.pal format file.
@@ -1936,7 +2014,7 @@
* there already, or if dealing with a colon-terminated device name).
\*--------------------------------------------------------------------------*/
-static void
+void
strcat_delim(char *dirspec)
{
int ldirspec = strlen(dirspec);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-27 19:29:25
|
Revision: 10353
http://plplot.svn.sourceforge.net/plplot/?rev=10353&view=rev
Author: airwin
Date: 2009-08-27 19:29:11 +0000 (Thu, 27 Aug 2009)
Log Message:
-----------
Define and use fuzzy_range_check macro for much-used code fragment in
plspal1 to check range of floating-point result and adjust to range limit if
just outside range. This macro guards against the case of floating-point
data describing the cmap1 palette being just outside the valid range due to
floating-point errors.
When a bad cmap1 palette file is encountered, fall back to internally defined
gray scale.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-27 16:38:57 UTC (rev 10352)
+++ trunk/src/plctrl.c 2009-08-27 19:29:11 UTC (rev 10353)
@@ -56,9 +56,6 @@
#define BUFFER_SIZE 256
-#define color_def(i, r, g, b, a, n) \
- if (i >= imin && i <= imax) color_set(i, r, g, b, a, n);
-
/* Static functions */
/* Used by any external init code to suggest a path */
@@ -829,6 +826,9 @@
plsc->cmap0[i].name = name;
}
+#define color_def(i, r, g, b, a, n) \
+ if (i >= imin && i <= imax) color_set(i, r, g, b, a, n);
+
/*--------------------------------------------------------------------------*\
* plcmap0_def()
*
@@ -1328,6 +1328,21 @@
free(a);
}
+/* This code fragment used a lot in plspal1 to deal with
+ floating-point range checking of a value and the adjustment of that
+ value when close to the range when there is floating-point errors.
+*/
+#define fuzzy_range_check(value, min, max, fuzz) \
+ if(value < min - fuzz || value > max + fuzz) { \
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info); \
+ plwarn(msgbuf); \
+ err = 1; \
+ break; \
+ } else if (value < min) { \
+ value = min; \
+ } else if (value > max) { \
+ value = max; \
+ }
/*--------------------------------------------------------------------------*\
* void c_plspal1(filename)
*
@@ -1424,16 +1439,10 @@
b[i] = (PLFLT)b_i/255.;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
- if(pos[i] < -1.e-12 || pos[i] > 1. + 1.e-12) {
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
- plwarn(msgbuf);
- err = 1;
- break;
- } else if (pos[i] < 0.) {
- pos[i] = 0.;
- } else if (pos[i] > 1.) {
- pos[i] = 1.;
- }
+ fuzzy_range_check(r[i], 0., 1., 1.e-12);
+ fuzzy_range_check(g[i], 0., 1., 1.e-12);
+ fuzzy_range_check(b[i], 0., 1., 1.e-12);
+ fuzzy_range_check(pos[i], 0., 1., 1.e-12);
if(return_sscanf == 5) {
/* Next to oldest tk format with rev specified. */
rev[i] = (PLBOOL)rev_i;
@@ -1455,37 +1464,31 @@
err = 1;
break;
}
- /* Check that all rgba and pos data within range from 0. to
- 1. except for the hls colour space case where the first
- coordinate is checked within range from 0. to 360.*/
- if((rgb && (r_d < 0. || r_d > 1.)) ||
- (!rgb && (r_d < 0. || r_d > 360.)) ||
- g_d < 0. || g_d > 1. ||
- b_d < 0. || b_d > 1. ||
- a_d < 0. || a_d > 1. ||
- pos_d < 0. || pos_d > 1.) {
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
- plwarn(msgbuf);
- err = 1;
- break;
- }
r[i] = (PLFLT)r_d;
g[i] = (PLFLT)g_d;
b[i] = (PLFLT)b_d;
a[i] = (PLFLT)a_d;
pos[i] = (PLFLT)pos_d;
+ /* Check that all rgba and pos data within range from 0. to
+ 1. except for the hls colour space case where the first
+ coordinate is checked within range from 0. to 360.*/
+ if(rgb) {
+ fuzzy_range_check(r[i], 0., 1., 1.e-12);
+ } else {
+ fuzzy_range_check(r[i], 0., 360., 360.e-12);
+ }
+ fuzzy_range_check(g[i], 0., 1., 1.e-12);
+ fuzzy_range_check(b[i], 0., 1., 1.e-12);
+ fuzzy_range_check(a[i], 0., 1., 1.e-12);
+ fuzzy_range_check(pos[i], 0., 1., 1.e-12);
+
rev[i] = (PLBOOL)rev_i;
}
}
fclose(fp);
if (err == 0) {
- /* Set the first control point position to 0.0 and the last */
- /* to 1.0 to deal with any possible round off errors. */
- pos[0] = 0.0;
- pos[number_colors-1] = 1.0;
-
if (interpolate) {
c_plscmap1la(rgb, number_colors, pos, r, g, b, a, rev);
}
@@ -1497,6 +1500,26 @@
}
c_plscmap1a(ri, gi, bi, a, number_colors);
}
+ } else {
+ /* Fall back to grey scale if some problem occurred above. */
+ free(r);
+ free(g);
+ free(b);
+ free(pos);
+ number_colors = 2;
+ r = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
+ g = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
+ b = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
+ pos = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
+ r[0] = 0.;
+ r[1] = 1.;
+ g[0] = 0.;
+ g[1] = 1.;
+ b[0] = 0.;
+ b[1] = 1.;
+ pos[0] = 0.;
+ pos[1] = 1.;
+ c_plscmap1l(TRUE, number_colors, pos, r, g, b, NULL);
}
free(r);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-28 00:50:45
|
Revision: 10354
http://plplot.svn.sourceforge.net/plplot/?rev=10354&view=rev
Author: airwin
Date: 2009-08-28 00:26:59 +0000 (Fri, 28 Aug 2009)
Log Message:
-----------
cmap0_palette_read: handle own error conditions for reading and interpreting
a cmap0 palette file. If there is an error condition, fall back to opaque
red on opaque white background as visual warning to accompany the text
warning. Fuzzy check range on alpha.
plspal1: red scale (instead of previous grey scale) as visual warning
to accompany text warning of error conditions for reading and interpreting
a cmap1 palette file.
plLibOpenPdfstrm: free memory for fs for all conditions.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-27 19:29:11 UTC (rev 10353)
+++ trunk/src/plctrl.c 2009-08-28 00:26:59 UTC (rev 10354)
@@ -82,7 +82,7 @@
static PLFLT
value(double n1, double n2, double hue);
-static int
+static void
cmap0_palette_read(const char *filename,
int *number_colors, int **r, int **g, int **b, double **a);
/* An additional hardwired location for lib files. */
@@ -838,34 +838,11 @@
void
plcmap0_def(int imin, int imax)
{
- int i, rc, *r, *g, *b;
+ int i, *r, *g, *b;
double *a;
int number_colors;
- char msgbuf[1024];
if(imin <= imax) {
- rc = cmap0_palette_read("", &number_colors, &r, &g, &b, &a);
- if(rc == 1) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
- plwarn(msgbuf);
- return;
- } else if(rc == 2) {
- /* Should never get this return code for null string (default)
- filename. */
- snprintf(msgbuf,1024,"plcmap0_def: internal logic error \n");
- plwarn(msgbuf);
- return;
- } else if(rc == 3) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
- plwarn(msgbuf);
- return;
- } else if(rc > 3) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format\n");
- plwarn(msgbuf);
- return;
- }
- for(i=imin;i<MIN(number_colors, imax+1);i++)
- color_def(i, r[i], g[i], b[i], a[i], "color defined by palette file");
-
+ cmap0_palette_read("", &number_colors, &r, &g, &b, &a);
free(r);
free(g);
free(b);
@@ -1211,72 +1188,116 @@
}
/*--------------------------------------------------------------------------*\
- * int cmap0_palette_read()
+ * cmap0_palette_read()
*
* Read and check r, g, b, a data from a cmap0*.pal format file.
- * Non-zero return code means some error occurred.
* The caller must free the returned malloc'ed space for r, g, b, and a.
\*--------------------------------------------------------------------------*/
-int
+void
cmap0_palette_read(const char *filename,
int *number_colors, int **r, int **g, int **b, double **a)
{
- int i;
+ int i, err = 0;
char color_info[30];
+ char msgbuf[1024];
FILE *fp;
if(strlen(filename) == 0) {
fp = plLibOpen(PL_DEFAULT_CMAP0_FILE);
- if (fp == NULL) return 1;
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
+ plwarn(msgbuf);
+ err = 1;
+ }
} else {
fp = plLibOpen(filename);
- if (fp == NULL) return 2;
+ if (fp == NULL) {
+ snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
+ plwarn(msgbuf);
+ err = 1;
+ }
}
- if (fscanf(fp, "%d\n", number_colors) != 1 || *number_colors < 1) {
+ if (!err &&(fscanf(fp, "%d\n", number_colors) != 1 || *number_colors < 1)) {
fclose(fp);
- return 3;
+ snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
+ plwarn(msgbuf);
+ err = 1;
}
- /* Allocate arrays to hold r, g, b, and a data for calling routine.
- The caller must free these after it is finished with them. */
- if(((*r = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
- ((*g = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
- ((*b = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
- ((*a = (double *)malloc(*number_colors * sizeof(double))) == NULL)) {
- fclose(fp);
- plexit("cmap0_palette_read: insufficient memory");
- }
+ if(!err) {
+ /* Allocate arrays to hold r, g, b, and a data for calling routine.
+ The caller must free these after it is finished with them. */
+ if(((*r = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*g = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*b = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*a = (double *)malloc(*number_colors * sizeof(double))) == NULL)) {
+ fclose(fp);
+ plexit("cmap0_palette_read: insufficient memory");
+ }
- for(i=0;i<*number_colors;i++){
- fgets(color_info, 30, fp);
- color_info[strlen(color_info)-1] = '\0'; /* remove return character */
- if(strlen(color_info) == 7){
- if (sscanf(color_info, "#%2x%2x%2x",
- (int *) (*r+i), (int *) (*g+i), (int *) (*b+i)) != 3) {
- fclose(fp);
- return 4;
+ for(i=0;i<*number_colors;i++){
+ fgets(color_info, 30, fp);
+ color_info[strlen(color_info)-1] = '\0'; /* remove return character */
+ if(strlen(color_info) == 7){
+ if (sscanf(color_info, "#%2x%2x%2x",
+ (int *) (*r+i), (int *) (*g+i), (int *) (*b+i)) != 3) {
+ err = 1;
+ break;
+ }
+ *(*a+i) = 1.0;
+ } else if(strlen(color_info) > 9) {
+ if (sscanf(color_info, "#%2x%2x%2x %lf",
+ (int *) (*r+i), (int *) (*g+i), (int *) (*b+i),
+ (double *) (*a+i)) != 4) {
+ err = 1;
+ break;
+ }
+ /* fuzzy range check. */
+ if(*(*a+i) < -1.e-12 || *(*a+i) > 1. + 1.e-12) {
+ err = 1;
+ break;
+ } else if(*(*a+i) < 0.) {
+ *(*a+i) = 0.;
+ } else if(*(*a+i) > 1.) {
+ *(*a+i) = 1.;
+ }
+ } else {
+ err = 1;
+ break;
}
- *(*a+i) = 1.0;
}
- else if(strlen(color_info) > 9){
- if (sscanf(color_info, "#%2x%2x%2x %lf",
- (int *) (*r+i), (int *) (*g+i), (int *) (*b+i),
- (double *) (*a+i)) != 4) {
- fclose(fp);
- return 5;
- }
- if(*(*a+i) < 0. || *(*a+i) > 1.) {
- fclose(fp);
- return 6;
- }
- } else {
- fclose(fp);
- return 7;
+ fclose(fp);
+ if(err) {
+ snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
+ plwarn(msgbuf);
+ free(*r);
+ free(*g);
+ free(*b);
+ free(*a);
}
}
- fclose(fp);
- return 0;
+ /* Fall back to opaque red on opaque white as visual warning of any
+ error above. */
+ if(err) {
+ *number_colors = 16;
+ if(((*r = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*g = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*b = (int *)malloc(*number_colors * sizeof(int))) == NULL) ||
+ ((*a = (double *)malloc(*number_colors * sizeof(double))) == NULL)) {
+ plexit("cmap0_palette_read: insufficient memory");
+ }
+ **r = 255;
+ **g = 255;
+ **b = 255;
+ **a = 1.;
+ for(i=1;i<*number_colors;i++){
+ *(*r+i) = 255;
+ *(*g+i) = 0;
+ *(*b+i) = 0;
+ *(*a+i) = 1.0;
+ }
+ }
}
/*--------------------------------------------------------------------------*\
@@ -1292,26 +1313,7 @@
int i, *r, *g, *b;
double *a;
int number_colors;
- char msgbuf[1024];
- int rc = cmap0_palette_read(filename, &number_colors, &r, &g, &b, &a);
- if(rc == 1) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",PL_DEFAULT_CMAP0_FILE);
- plwarn(msgbuf);
- return;
- } else if(rc == 2) {
- snprintf(msgbuf,1024,"Unable to open cmap0 file %s\n",filename);
- plwarn(msgbuf);
- return;
- } else if(rc == 3) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 header\n");
- plwarn(msgbuf);
- return;
- } else if(rc > 3) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format\n");
- plwarn(msgbuf);
- return;
- }
-
+ cmap0_palette_read(filename, &number_colors, &r, &g, &b, &a);
/* Allocate default number of cmap0 colours if cmap0 allocation not
done already. */
plscmap0n(0);
@@ -1488,7 +1490,7 @@
}
fclose(fp);
- if (err == 0) {
+ if (!err) {
if (interpolate) {
c_plscmap1la(rgb, number_colors, pos, r, g, b, a, rev);
}
@@ -1501,7 +1503,8 @@
c_plscmap1a(ri, gi, bi, a, number_colors);
}
} else {
- /* Fall back to grey scale if some problem occurred above. */
+ /* Fall back to red scale as visual warning if some problem occurred
+ above. */
free(r);
free(g);
free(b);
@@ -1514,9 +1517,9 @@
r[0] = 0.;
r[1] = 1.;
g[0] = 0.;
- g[1] = 1.;
+ g[1] = 0.;
b[0] = 0.;
- b[1] = 1.;
+ b[1] = 0.;
pos[0] = 0.;
pos[1] = 1.;
c_plscmap1l(TRUE, number_colors, pos, r, g, b, NULL);
@@ -1857,7 +1860,6 @@
if ((file = pdf_fopen(fs, "rb")) != NULL)
goto done;
-
fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */
}
#endif /* PLPLOT_LIB_ENV */
@@ -1866,6 +1868,7 @@
if ((file = pdf_fopen(fn, "rb")) != NULL){
pldebug("plLibOpenPdfstr", "Found file %s in current directory.\n", fn);
+ free_mem(fs);
return (file);
}
@@ -1909,11 +1912,11 @@
plGetName(plplotLibDir, "", fn, &fs);
if ((file = pdf_fopen(fs, "rb")) != NULL)
goto done;
-
}
/**** not found, give up ****/
pldebug("plLibOpenPdfstr", "File %s not found.\n", fn);
+ free_mem(fs);
return NULL;
done:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-28 17:07:09
|
Revision: 10355
http://plplot.svn.sourceforge.net/plplot/?rev=10355&view=rev
Author: airwin
Date: 2009-08-28 17:07:01 +0000 (Fri, 28 Aug 2009)
Log Message:
-----------
Refine warning message for reading color palette files to make it easer
to identify exactly where the problems are occurring.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-28 00:26:59 UTC (rev 10354)
+++ trunk/src/plctrl.c 2009-08-28 17:07:01 UTC (rev 10355)
@@ -1254,7 +1254,7 @@
break;
}
/* fuzzy range check. */
- if(*(*a+i) < -1.e-12 || *(*a+i) > 1. + 1.e-12) {
+ if(*(*a+i) < -1.e-12 || *(*a+i) > (1. + 1.e-12)) {
err = 1;
break;
} else if(*(*a+i) < 0.) {
@@ -1269,7 +1269,8 @@
}
fclose(fp);
if(err) {
- snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info);
+ snprintf(msgbuf,1024,"Unrecognized cmap0 format data line. Line is %s\n",
+ color_info);
plwarn(msgbuf);
free(*r);
free(*g);
@@ -1334,9 +1335,9 @@
floating-point range checking of a value and the adjustment of that
value when close to the range when there is floating-point errors.
*/
-#define fuzzy_range_check(value, min, max, fuzz) \
- if(value < min - fuzz || value > max + fuzz) { \
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info); \
+#define fuzzy_range_check(value, min, max, fuzz, err_number) \
+ if(value < (min - fuzz) || value > (max + fuzz)) { \
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info); \
plwarn(msgbuf); \
err = 1; \
break; \
@@ -1403,7 +1404,7 @@
}
if (sscanf(color_info, "%d\n", &number_colors) != 1 || number_colors < 2) {
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format (wrong number of colors) %s\n", color_info);
plwarn(msgbuf);
fclose(fp);
return;
@@ -1428,7 +1429,7 @@
color_info[159] = '\0';
return_sscanf = sscanf(color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i);
if(return_sscanf < 4 || (return_sscanf_old != 0 && return_sscanf != return_sscanf_old)) {
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info);
plwarn(msgbuf);
err = 1;
break;
@@ -1441,10 +1442,10 @@
b[i] = (PLFLT)b_i/255.;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
- fuzzy_range_check(r[i], 0., 1., 1.e-12);
- fuzzy_range_check(g[i], 0., 1., 1.e-12);
- fuzzy_range_check(b[i], 0., 1., 1.e-12);
- fuzzy_range_check(pos[i], 0., 1., 1.e-12);
+ fuzzy_range_check(r[i], 0., 1., 1.e-12, 1);
+ fuzzy_range_check(g[i], 0., 1., 1.e-12, 2);
+ fuzzy_range_check(b[i], 0., 1., 1.e-12, 3);
+ fuzzy_range_check(pos[i], 0., 1., 1.e-12, 4);
if(return_sscanf == 5) {
/* Next to oldest tk format with rev specified. */
rev[i] = (PLBOOL)rev_i;
@@ -1460,8 +1461,8 @@
/* New floating point file version with support for alpha and rev values */
for(i=0;i<number_colors;i++){
fgets(color_info, 160, fp);
- if (sscanf(color_info, "%lf %lf %lf %lf %lf %d", &pos_d, &r_d, &g_d, &b_d, &a_d, &rev_i) < 6) {
- snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
+ if (sscanf(color_info, "%lf %lf %lf %lf %lf %d", &pos_d, &r_d, &g_d, &b_d, &a_d, &rev_i) != 6) {
+ snprintf(msgbuf,1024,"Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info);
plwarn(msgbuf);
err = 1;
break;
@@ -1476,14 +1477,14 @@
1. except for the hls colour space case where the first
coordinate is checked within range from 0. to 360.*/
if(rgb) {
- fuzzy_range_check(r[i], 0., 1., 1.e-12);
+ fuzzy_range_check(r[i], 0., 1., 1.e-12, 5);
} else {
- fuzzy_range_check(r[i], 0., 360., 360.e-12);
+ fuzzy_range_check(r[i], 0., 360., 360.e-12, 6);
}
- fuzzy_range_check(g[i], 0., 1., 1.e-12);
- fuzzy_range_check(b[i], 0., 1., 1.e-12);
- fuzzy_range_check(a[i], 0., 1., 1.e-12);
- fuzzy_range_check(pos[i], 0., 1., 1.e-12);
+ fuzzy_range_check(g[i], 0., 1., 1.e-12, 7);
+ fuzzy_range_check(b[i], 0., 1., 1.e-12, 8);
+ fuzzy_range_check(a[i], 0., 1., 1.e-12, 9);
+ fuzzy_range_check(pos[i], 0., 1., 1.e-12, 10);
rev[i] = (PLBOOL)rev_i;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-09-17 01:56:36
|
Revision: 10418
http://plplot.svn.sourceforge.net/plplot/?rev=10418&view=rev
Author: airwin
Date: 2009-09-17 01:56:26 +0000 (Thu, 17 Sep 2009)
Log Message:
-----------
Fix -bg bug by actually using (!) colours read in by cmap0_palette_read
in plcmap0_def. Thanks to Mark de Wever for reporting this issue.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-09-16 15:22:05 UTC (rev 10417)
+++ trunk/src/plctrl.c 2009-09-17 01:56:26 UTC (rev 10418)
@@ -836,7 +836,8 @@
/*--------------------------------------------------------------------------*\
* plcmap0_def()
*
- * Initializes specified color map 0 color entry to its default.
+ * Initializes specified color map 0 color entry to its default for
+ * index range from imin to imax.
\*--------------------------------------------------------------------------*/
void
@@ -847,6 +848,9 @@
int number_colors;
if(imin <= imax) {
cmap0_palette_read("", &number_colors, &r, &g, &b, &a);
+ for (i = imin; i <= MIN((number_colors-1),imax); i++)
+ color_def(i, r[i], g[i], b[i], a[i],
+ "colors defined by default cmap0 palette file");
free(r);
free(g);
free(b);
@@ -860,7 +864,7 @@
to opaque red as a warning. */
for (i = MAX(number_colors, imin); i <= imax; i++)
color_def(i, 255, 0, 0, 1.0,
- "opaque red to mark not defined by palette file");
+ "opaque red colour to mark not defined by palette file");
}
/*--------------------------------------------------------------------------*\
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2010-08-24 11:07:59
|
Revision: 11150
http://plplot.svn.sourceforge.net/plplot/?rev=11150&view=rev
Author: andrewross
Date: 2010-08-24 11:07:53 +0000 (Tue, 24 Aug 2010)
Log Message:
-----------
Check return value of fgets when reading in .pal palette files. These could be user supplied and so the format is not guaranteed. Fixes gcc warning.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2010-08-24 11:02:39 UTC (rev 11149)
+++ trunk/src/plctrl.c 2010-08-24 11:07:53 UTC (rev 11150)
@@ -1292,7 +1292,10 @@
for ( i = 0; i < *number_colors; i++ )
{
- fgets( color_info, 30, fp );
+ if (fgets( color_info, 30, fp ) == NULL) {
+ err = 1;
+ break;
+ }
color_info[strlen( color_info ) - 1] = '\0'; /* remove return character */
if ( strlen( color_info ) == 7 )
{
@@ -1469,7 +1472,12 @@
}
}
/* Check for new file format */
- fgets( color_info, 160, fp );
+ if (fgets( color_info, 160, fp ) == NULL) {
+ snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n",filename);
+ plwarn( msgbuf );
+ fclose( fp );
+ goto finish;
+ }
if ( strncmp( color_info, "v2 ", 2 ) == 0 )
{
format_version = 1;
@@ -1483,7 +1491,12 @@
plwarn( msgbuf );
rgb = TRUE;
}
- fgets( color_info, 160, fp );
+ if (fgets( color_info, 160, fp ) == NULL) {
+ snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n",filename);
+ plwarn( msgbuf );
+ fclose( fp );
+ goto finish;
+ }
}
if ( sscanf( color_info, "%d\n", &number_colors ) != 1 || number_colors < 2 )
@@ -1510,7 +1523,12 @@
/* Old tk file format */
for ( i = 0; i < number_colors; i++ )
{
- fgets( color_info, 160, fp );
+ if (fgets( color_info, 160, fp ) == NULL) {
+ snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n",filename);
+ plwarn( msgbuf );
+ fclose( fp );
+ goto finish;
+ }
/* Ensure string is null terminated if > 160 characters */
color_info[159] = '\0';
return_sscanf = sscanf( color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i );
@@ -1551,7 +1569,12 @@
/* New floating point file version with support for alpha and rev values */
for ( i = 0; i < number_colors; i++ )
{
- fgets( color_info, 160, fp );
+ if (fgets( color_info, 160, fp ) == NULL) {
+ snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n",filename);
+ plwarn( msgbuf );
+ fclose( fp );
+ goto finish;
+ }
if ( sscanf( color_info, "%lf %lf %lf %lf %lf %d", &pos_d, &r_d, &g_d, &b_d, &a_d, &rev_i ) != 6 )
{
snprintf( msgbuf, 1024, "Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <arj...@us...> - 2011-05-31 09:02:43
|
Revision: 11758
http://plplot.svn.sourceforge.net/plplot/?rev=11758&view=rev
Author: arjenmarkus
Date: 2011-05-31 09:02:36 +0000 (Tue, 31 May 2011)
Log Message:
-----------
Introduced three macros to deal with the size of the buffers in the various functions.
Introduced a static function read_line to read a complete line from a file and store as
much of it in the buffer as will fit. The line is stripped of carriage returns, newlines
and trailing blanks, so that reading the palette files is more robust.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2011-05-30 20:23:27 UTC (rev 11757)
+++ trunk/src/plctrl.c 2011-05-31 09:02:36 UTC (rev 11758)
@@ -56,6 +56,9 @@
#include "mt19937ar.h"
#define BUFFER_SIZE 256
+#define COLLEN 30
+#define PALLEN 160
+#define MSGLEN 1024
// small epsilon for fuzzy range checks that is still large enough to
// work even in the single precision floating point case.
@@ -87,6 +90,9 @@
static PLFLT
value( double n1, double n2, double hue );
+static char *
+read_line( char *buffer, int length, FILE *fp );
+
static void
cmap0_palette_read( const char *filename,
int *number_colors, int **r, int **g, int **b, double **a );
@@ -1212,6 +1218,53 @@
}
//--------------------------------------------------------------------------
+// read_line()
+//
+// Read a complete line and fill the buffer with its contents up to
+// capacity. Then sanitize the string - no control characters, no
+// trailing blanks
+//--------------------------------------------------------------------------
+
+static char *
+read_line( char *buffer, int length, FILE *fp )
+{
+ char *pchr;
+
+ // Read the string
+ if ( fgets( buffer, length, fp ) == NULL ) {
+ return NULL;
+ }
+
+ // Sanitize the string we read - it may contain EOL characters
+ // Make sure file reading starts at the next line
+ pchr = strchr( buffer, '\n' );
+ if ( pchr != NULL )
+ {
+ *pchr = '\0';
+ }
+ else
+ {
+ fscanf( fp, "%*[^\n]\n" );
+ }
+
+ pchr = strchr( buffer, '\r' );
+ if ( pchr != NULL )
+ {
+ *pchr = '\0';
+ }
+
+ // Remove trailing blanks
+ pchr = buffer + strlen(buffer)-1;
+ while ( pchr != buffer && *pchr == ' ' )
+ {
+ *pchr = '\0';
+ pchr --;
+ }
+
+ return buffer;
+}
+
+//--------------------------------------------------------------------------
// cmap0_palette_read()
//
// Read and check r, g, b, a data from a cmap0*.pal format file.
@@ -1223,8 +1276,8 @@
int *number_colors, int **r, int **g, int **b, double **a )
{
int i, err = 0;
- char color_info[30];
- char msgbuf[1024];
+ char color_info[COLLEN];
+ char msgbuf[MSGLEN];
FILE *fp;
char * save_locale = plsave_set_locale();
@@ -1233,7 +1286,7 @@
fp = plLibOpen( PL_DEFAULT_CMAP0_FILE );
if ( fp == NULL )
{
- snprintf( msgbuf, 1024, "Unable to open cmap0 file %s\n", PL_DEFAULT_CMAP0_FILE );
+ snprintf( msgbuf, MSGLEN, "Unable to open cmap0 file %s\n", PL_DEFAULT_CMAP0_FILE );
plwarn( msgbuf );
err = 1;
}
@@ -1243,7 +1296,7 @@
fp = plLibOpen( filename );
if ( fp == NULL )
{
- snprintf( msgbuf, 1024, "Unable to open cmap0 file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Unable to open cmap0 file %s\n", filename );
plwarn( msgbuf );
err = 1;
}
@@ -1251,7 +1304,7 @@
if ( !err && ( fscanf( fp, "%d\n", number_colors ) != 1 || *number_colors < 1 ) )
{
fclose( fp );
- snprintf( msgbuf, 1024, "Unrecognized cmap0 header\n" );
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap0 header\n" );
plwarn( msgbuf );
err = 1;
}
@@ -1271,12 +1324,13 @@
for ( i = 0; i < *number_colors; i++ )
{
- if ( fgets( color_info, 30, fp ) == NULL )
+ if ( read_line( color_info, COLLEN, fp ) == NULL )
{
err = 1;
break;
}
- color_info[strlen( color_info ) - 1] = '\0'; // remove return character
+
+ // Get the color data
if ( strlen( color_info ) == 7 )
{
if ( sscanf( color_info, "#%2x%2x%2x",
@@ -1320,7 +1374,7 @@
fclose( fp );
if ( err )
{
- snprintf( msgbuf, 1024, "Unrecognized cmap0 format data line. Line is %s\n",
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap0 format data line. Line is %s\n",
color_info );
plwarn( msgbuf );
free( *r );
@@ -1395,7 +1449,7 @@
//
#define fuzzy_range_check( value, min, max, fuzz, err_number ) \
if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
- snprintf( msgbuf, 1024, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
plwarn( msgbuf ); \
err = 1; \
break; \
@@ -1418,14 +1472,14 @@
int number_colors;
int format_version, err;
PLBOOL rgb;
- char color_info[160];
+ char color_info[PALLEN];
int r_i, g_i, b_i, pos_i, rev_i;
double r_d, g_d, b_d, a_d, pos_d;
PLFLT *r, *g, *b, *a, *pos;
PLINT *ri, *gi, *bi;
PLBOOL *rev;
FILE *fp;
- char msgbuf[1024];
+ char msgbuf[MSGLEN];
char * save_locale = plsave_set_locale();
rgb = TRUE;
@@ -1436,7 +1490,7 @@
fp = plLibOpen( PL_DEFAULT_CMAP1_FILE );
if ( fp == NULL )
{
- snprintf( msgbuf, 1024, "Unable to open cmap1 .pal file %s\n", PL_DEFAULT_CMAP1_FILE );
+ snprintf( msgbuf, MSGLEN, "Unable to open cmap1 .pal file %s\n", PL_DEFAULT_CMAP1_FILE );
plwarn( msgbuf );
goto finish;
}
@@ -1446,15 +1500,15 @@
fp = plLibOpen( filename );
if ( fp == NULL )
{
- snprintf( msgbuf, 1024, "Unable to open cmap1 .pal file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Unable to open cmap1 .pal file %s\n", filename );
plwarn( msgbuf );
goto finish;
}
}
// Check for new file format
- if ( fgets( color_info, 160, fp ) == NULL )
+ if ( read_line( color_info, PALLEN, fp ) == NULL )
{
- snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
plwarn( msgbuf );
fclose( fp );
goto finish;
@@ -1468,13 +1522,13 @@
rgb = TRUE;
else
{
- snprintf( msgbuf, 1024, "Invalid color space %s - assuming RGB\n", &color_info[3] );
+ snprintf( msgbuf, MSGLEN, "Invalid color space %s - assuming RGB\n", &color_info[3] );
plwarn( msgbuf );
rgb = TRUE;
}
- if ( fgets( color_info, 160, fp ) == NULL )
+ if ( read_line( color_info, PALLEN, fp ) == NULL )
{
- snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
plwarn( msgbuf );
fclose( fp );
goto finish;
@@ -1483,7 +1537,7 @@
if ( sscanf( color_info, "%d\n", &number_colors ) != 1 || number_colors < 2 )
{
- snprintf( msgbuf, 1024, "Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
plwarn( msgbuf );
fclose( fp );
goto finish;
@@ -1505,19 +1559,19 @@
// Old tk file format
for ( i = 0; i < number_colors; i++ )
{
- if ( fgets( color_info, 160, fp ) == NULL )
+ if ( read_line( color_info, PALLEN, fp ) == NULL )
{
- snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
plwarn( msgbuf );
fclose( fp );
goto finish;
}
// Ensure string is null terminated if > 160 characters
- color_info[159] = '\0';
+ color_info[PALLEN-1] = '\0';
return_sscanf = sscanf( color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i );
if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
{
- snprintf( msgbuf, 1024, "Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
plwarn( msgbuf );
err = 1;
break;
@@ -1552,16 +1606,16 @@
// New floating point file version with support for alpha and rev values
for ( i = 0; i < number_colors; i++ )
{
- if ( fgets( color_info, 160, fp ) == NULL )
+ if ( read_line( color_info, PALLEN, fp ) == NULL )
{
- snprintf( msgbuf, 1024, "Error reading cmap1 .pal file %s\n", filename );
+ snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
plwarn( msgbuf );
fclose( fp );
goto finish;
}
if ( sscanf( color_info, "%lf %lf %lf %lf %lf %d", &pos_d, &r_d, &g_d, &b_d, &a_d, &rev_i ) != 6 )
{
- snprintf( msgbuf, 1024, "Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
+ snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
plwarn( msgbuf );
err = 1;
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2011-06-02 00:02:29
|
Revision: 11762
http://plplot.svn.sourceforge.net/plplot/?rev=11762&view=rev
Author: airwin
Date: 2011-06-02 00:02:22 +0000 (Thu, 02 Jun 2011)
Log Message:
-----------
Style previous commit.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2011-06-01 20:50:58 UTC (rev 11761)
+++ trunk/src/plctrl.c 2011-06-02 00:02:22 UTC (rev 11762)
@@ -56,9 +56,9 @@
#include "mt19937ar.h"
#define BUFFER_SIZE 256
-#define COLLEN 30
+#define COLLEN 30
#define PALLEN 160
-#define MSGLEN 1024
+#define MSGLEN 1024
// small epsilon for fuzzy range checks that is still large enough to
// work even in the single precision floating point case.
@@ -1231,7 +1231,8 @@
char *pchr;
// Read the string
- if ( fgets( buffer, length, fp ) == NULL ) {
+ if ( fgets( buffer, length, fp ) == NULL )
+ {
return NULL;
}
@@ -1254,11 +1255,11 @@
}
// Remove trailing blanks
- pchr = buffer + strlen(buffer)-1;
+ pchr = buffer + strlen( buffer ) - 1;
while ( pchr != buffer && *pchr == ' ' )
{
*pchr = '\0';
- pchr --;
+ pchr--;
}
return buffer;
@@ -1447,16 +1448,16 @@
// floating-point range checking of a value and the adjustment of that
// value when close to the range when there is floating-point errors.
//
-#define fuzzy_range_check( value, min, max, fuzz, err_number ) \
- if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
+#define fuzzy_range_check( value, min, max, fuzz, err_number ) \
+ if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
- plwarn( msgbuf ); \
- err = 1; \
- break; \
- } else if ( value < min ) { \
- value = min; \
- } else if ( value > max ) { \
- value = max; \
+ plwarn( msgbuf ); \
+ err = 1; \
+ break; \
+ } else if ( value < min ) { \
+ value = min; \
+ } else if ( value > max ) { \
+ value = max; \
}
//--------------------------------------------------------------------------
// void c_plspal1(filename)
@@ -1567,8 +1568,8 @@
goto finish;
}
// Ensure string is null terminated if > 160 characters
- color_info[PALLEN-1] = '\0';
- return_sscanf = sscanf( color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i );
+ color_info[PALLEN - 1] = '\0';
+ return_sscanf = sscanf( color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i );
if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
{
snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2011-08-26 22:02:54
|
Revision: 11900
http://plplot.svn.sourceforge.net/plplot/?rev=11900&view=rev
Author: andrewross
Date: 2011-08-26 22:02:48 +0000 (Fri, 26 Aug 2011)
Log Message:
-----------
Check return value of fread - fixes gcc warning.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2011-08-25 18:28:33 UTC (rev 11899)
+++ trunk/src/plctrl.c 2011-08-26 22:02:48 UTC (rev 11900)
@@ -1245,8 +1245,11 @@
}
else
{
- fscanf( fp, "%*[^\n]\n" );
+ if ( fscanf( fp, "%*[^\n]\n" ) == EOF && ferror(fp) ) {
+ return NULL;
+ }
}
+
pchr = strchr( buffer, '\r' );
if ( pchr != NULL )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hba...@us...> - 2011-10-28 13:19:40
|
Revision: 12011
http://plplot.svn.sourceforge.net/plplot/?rev=12011&view=rev
Author: hbabcock
Date: 2011-10-28 13:19:30 +0000 (Fri, 28 Oct 2011)
Log Message:
-----------
Add doxygen style documentation for all the functions in plctrl.c
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2011-10-28 13:17:07 UTC (rev 12010)
+++ trunk/src/plctrl.c 2011-10-28 13:19:30 UTC (rev 12011)
@@ -8,7 +8,7 @@
// Copyright (C) 2004 Rafael Laboissiere
// Copyright (C) 2008 Hazen Babcock
// Copyright (C) 2009 Alan W. Irwin
-// Copyright (C) 2011 Hezekiah M. Carty
+// Copyright (C) 2011 Hezekiah M. Carty
//
// This file is part of PLplot.
//
@@ -28,6 +28,12 @@
//
//
+//! @file
+//!
+//! Part 1: Color map routines.
+//! Part 2: "A grab-bag of various control routines".
+//!
+
#define DEBUG
#define NEED_PLDEBUG
@@ -128,8 +134,10 @@
//--------------------------------------------------------------------------
// plcol0()
//
-// Set color, map 0. Argument is integer between 0 and plsc->ncol0.
-//--------------------------------------------------------------------------
+//! Set color, map 0. Argument is a integer between 0 and plsc->ncol0.
+//!
+//! @param icol0 The index of the color map 0 color to use as the current
+//! color. (0 - plsc->ncol0).
void
c_plcol0( PLINT icol0 )
@@ -160,8 +168,10 @@
//--------------------------------------------------------------------------
// plcol1()
//
-// Set color, map 1. Argument is a float between 0. and 1.
-//--------------------------------------------------------------------------
+//! Set color, map 1. Argument is a float between 0. and 1.
+//!
+//! @param icol1 The index of the color map 1 color to use as the current
+//! color. (0.0 - 1.0)
void
c_plcol1( PLFLT col1 )
@@ -197,8 +207,11 @@
//--------------------------------------------------------------------------
// plscolbg()
//
-// Set the background color (cmap0[0]) by 8 bit RGB value
-//--------------------------------------------------------------------------
+//! Set the background color (cmap0[0]) by 8 bit RGB value
+//!
+//! @param r Red value of the background color (0 - 255).
+//! @param g Green value of the background color (0 - 255).
+//! @param b Blue value of the background color (0 - 255).
void
c_plscolbg( PLINT r, PLINT g, PLINT b )
@@ -209,7 +222,14 @@
//--------------------------------------------------------------------------
// plscolbga()
//
-// Set the background color (cmap0[0]) by 8 bit RGB value and alpha value
+//! Set the background color (cmap0[0]) by 8 bit RGB value and alpha value
+//!
+//! @param r Red value of the background color (0 - 255).
+//! @param g Green value of the background color (0 - 255).
+//! @param b Blue value of the background color (0 - 255).
+//! @param a Alpha (transparency) value of the background color
+//! (0.0 - 1.0).
+
//--------------------------------------------------------------------------
void
@@ -221,8 +241,11 @@
//--------------------------------------------------------------------------
// plgcolbg()
//
-// Returns the background color (cmap0[0]) by 8 bit RGB value
-//--------------------------------------------------------------------------
+//! Returns the background color (cmap0[0]) by 8 bit RGB value
+//!
+//! @param r Current red value of the background color.
+//! @param g Current green value of the background color.
+//! @param b Current blue value of the background color.
void
c_plgcolbg( PLINT *r, PLINT *g, PLINT *b )
@@ -233,8 +256,12 @@
//--------------------------------------------------------------------------
// plgcolbga()
//
-// Returns the background color (cmap0[0]) by 8 bit RGB value and alpha value
-//--------------------------------------------------------------------------
+//! Returns the background color (cmap0[0]) by 8 bit RGB value and alpha value
+//!
+//! @param r Current red value of the background color.
+//! @param g Current green value of the background color.
+//! @param b Current blue value of the background color.
+//! @param a Current alpha value of the background color.
void
c_plgcolbga( PLINT *r, PLINT *g, PLINT *b, PLFLT *a )
@@ -245,9 +272,13 @@
//--------------------------------------------------------------------------
// plscol0()
//
-// Set a given color from color map 0 by 8 bit RGB value
-// Does not result in any additional cells to be allocated.
-//--------------------------------------------------------------------------
+//! Set a given color from color map 0 by 8 bit RGB value
+//! Does not result in any additional cells to be allocated.
+//!
+//! @param icol0 index of the color to set (0 - plsc->ncol0)
+//! @param r Red value of the color (0 - 255).
+//! @param g Green value of the color (0 - 255).
+//! @param b Blue value of the color (0 - 255).
void
c_plscol0( PLINT icol0, PLINT r, PLINT g, PLINT b )
@@ -276,9 +307,14 @@
//--------------------------------------------------------------------------
// plscol0a()
//
-// Set a given color from color map 0 by 8 bit RGB value and alpha value.
-// Does not result in any additional cells to be allocated.
-//--------------------------------------------------------------------------
+//! Set a given color from color map 0 by 8 bit RGB value and alpha value.
+//! Does not result in any additional cells to be allocated.
+//!
+//! @param icol0 index of the color to set (0 - plsc->ncol0)
+//! @param r Red value of the color (0 - 255).
+//! @param g Green value of the color (0 - 255).
+//! @param b Blue value of the color (0 - 255).
+//! @param a Alpha value of the color (0.0 - 1.0).
void
c_plscol0a( PLINT icol0, PLINT r, PLINT g, PLINT b, PLFLT a )
@@ -313,9 +349,13 @@
//--------------------------------------------------------------------------
// plgcol0()
//
-// Returns 8 bit RGB values for given color from color map 0
-// Values are negative if an invalid color id is given
-//--------------------------------------------------------------------------
+//! Returns 8 bit RGB values for given color from color map 0
+//! Values are negative if an invalid color id is given
+//!
+//! @param icol0 Index of the color to be return (0 - plsc->ncol0).
+//! @param r Current red value of the color.
+//! @param g Current green value of the color.
+//! @param b Current blue value of the color.
void
c_plgcol0( PLINT icol0, PLINT *r, PLINT *g, PLINT *b )
@@ -345,9 +385,14 @@
//--------------------------------------------------------------------------
// plgcol0a()
//
-// Returns 8 bit RGB values for given color from color map 0 and alpha value
-// Values are negative if an invalid color id is given
-//--------------------------------------------------------------------------
+//! Returns 8 bit RGB values for given color from color map 0 and alpha value
+//! Values are negative if an invalid color id is given
+//!
+//! @param icol0 Index of the color to be return (0 - plsc->ncol0).
+//! @param r Current red value of the color.
+//! @param g Current green value of the color.
+//! @param b Current blue value of the color.
+//! @param a Current alpha value of the color.
void
c_plgcol0a( PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *a )
@@ -379,9 +424,13 @@
//--------------------------------------------------------------------------
// plscmap0()
//
-// Set color map 0 colors by 8 bit RGB values. This sets the entire color
-// map -- only as many colors as specified will be allocated.
-//--------------------------------------------------------------------------
+//! Set color map 0 colors by 8 bit RGB values. This sets the entire color
+//! map -- only as many colors as specified will be allocated.
+//!
+//! @param r Array of red values.
+//! @param g Array of green values.
+//! @param b Array of blue values.
+//! @param ncol0 Total number of RGB values.
void
c_plscmap0( const PLINT *r, const PLINT *g, const PLINT *b, PLINT ncol0 )
@@ -416,9 +465,14 @@
//--------------------------------------------------------------------------
// plscmap0a()
//
-// Set color map 0 colors by 8 bit RGB and alpha value. This sets the
-// entire color map -- only as many colors as specified will be allocated.
-//--------------------------------------------------------------------------
+//! Set color map 0 colors by 8 bit RGB and alpha value. This sets the
+//! entire color map -- only as many colors as specified will be allocated.
+//!
+//! @param r Array of red values.
+//! @param g Array of green values.
+//! @param b Array of blue values.
+//! @param a Array of alpha values.
+//! @param ncol0 Total number of RGBA values.
void
c_plscmap0a( const PLINT *r, const PLINT *g, const PLINT *b, const PLFLT *a, PLINT ncol0 )
@@ -454,9 +508,13 @@
//--------------------------------------------------------------------------
// plscmap1()
//
-// Set color map 1 colors by 8 bit RGB values
-// This also sets the number of colors.
-//--------------------------------------------------------------------------
+//! Set color map 1 colors by 8 bit RGB values
+//! This also sets the number of colors.
+//!
+//! @param r Array of red values.
+//! @param g Array of green values.
+//! @param b Array of blue values.
+//! @param ncol1 Total number of RGB values.
void
c_plscmap1( const PLINT *r, const PLINT *g, const PLINT *b, PLINT ncol1 )
@@ -490,9 +548,14 @@
//--------------------------------------------------------------------------
// plscmap1a()
//
-// Set color map 1 colors by 8 bit RGB and alpha values
-// This also sets the number of colors.
-//--------------------------------------------------------------------------
+//! Set color map 1 colors by 8 bit RGB and alpha values
+//! This also sets the number of colors.
+//!
+//! @param r Array of red values.
+//! @param g Array of green values.
+//! @param b Array of blue values.
+//! @param a Array of alpha values.
+//! @param ncol1 Total number of RGBA values.
void
c_plscmap1a( const PLINT *r, const PLINT *g, const PLINT *b, const PLFLT *a, PLINT ncol1 )
@@ -527,53 +590,52 @@
//--------------------------------------------------------------------------
// plscmap1l()
//
-// Set color map 1 colors using a piece-wise linear relationship between
-// position in the color map (from 0 to 1) and position in HLS or RGB color
-// space. May be called at any time.
-//
-// The idea here is to specify a number of control points that specify the
-// mapping between HLS (or RGB or CMY) and palette 1 value. Between these
-// points, linear interpolation is used. By mapping position in the color
-// map to function value, this gives a smooth variation of color with
-// intensity. Any number of control points may be specified, located at
-// arbitrary positions (intensities), although typically 2 - 4 are enough.
-// Another way of stating this is that we are traversing a given number of
-// lines through HLS (or RGB) space as we move through cmap 1 entries. The
-// control points at the minimum and maximum intensity (0 and 1) must
-// always be specified. By adding more control points you can get more
-// variation. One good technique for plotting functions that vary about
-// some expected average is to use an additional 2 control points in the
-// center (intensity ~= 0.5) that are the same color as the background
-// (typically white for paper output, black for crt), and same hue as the
-// boundary control points. This allows the highs and lows to be very
-// easily distinguished.
-//
-// Each control point must specify the position in cmap 1 as well as three
-// coordinates in HLS or RGB space. The first point MUST correspond to
-// position = 0, and the last to position = 1.
-//
-// The hue is interpolated around the "front" of the color wheel
-// (red<->green<->blue<->red) unless the "rev" flag is set, in which case
-// interpolation proceeds around the back (reverse) side. Specifying
-// rev=NULL is equivalent to setting rev[]=0 for every control point.
-//
-// Bounds on RGB coordinates:
-// R,G,B [0, 1] magnitude
-//
-// Bounds on HLS coordinates:
-// hue [0, 360] degrees
-// lightness [0, 1] magnitude
-// saturation [0, 1] magnitude
-//
-// The inputs are:
-// itype 0: HLS, 1: RGB
-// npts number of control points
-// pos[] position for each control point
-// coord1[] first coordinate for each control point
-// coord2[] second coordinate for each control point
-// coord3[] third coordinate for each control point
-// rev[] reverse flag for each control point
-//--------------------------------------------------------------------------
+//! Set color map 1 colors using a piece-wise linear relationship between
+//! position in the color map (from 0 to 1) and position in HLS or RGB color
+//! space. May be called at any time.
+//!
+//! The idea here is to specify a number of control points that specify the
+//! mapping between HLS (or RGB or CMY) and palette 1 value. Between these
+//! points, linear interpolation is used. By mapping position in the color
+//! map to function value, this gives a smooth variation of color with
+//! intensity. Any number of control points may be specified, located at
+//! arbitrary positions (intensities), although typically 2 - 4 are enough.
+//! Another way of stating this is that we are traversing a given number of
+//! lines through HLS (or RGB) space as we move through cmap 1 entries. The
+//! control points at the minimum and maximum intensity (0 and 1) must
+//! always be specified. By adding more control points you can get more
+//! variation. One good technique for plotting functions that vary about
+//! some expected average is to use an additional 2 control points in the
+//! center (intensity ~= 0.5) that are the same color as the background
+//! (typically white for paper output, black for crt), and same hue as the
+//! boundary control points. This allows the highs and lows to be very
+//! easily distinguished.
+//!
+//! Each control point must specify the position in cmap 1 as well as three
+//! coordinates in HLS or RGB space. The first point MUST correspond to
+//! position = 0, and the last to position = 1.
+//!
+//! The hue is interpolated around the "front" of the color wheel
+//! (red<->green<->blue<->red) unless the "rev" flag is set, in which case
+//! interpolation proceeds around the back (reverse) side. Specifying
+//! rev=NULL is equivalent to setting rev[]=0 for every control point.
+//!
+//! Bounds on RGB coordinates:
+//! R,G,B [0, 1] magnitude
+//!
+//! Bounds on HLS coordinates:
+//! hue [0, 360] degrees
+//! lightness [0, 1] magnitude
+//! saturation [0, 1] magnitude
+//!
+//! The inputs are:
+//! @param itype 0: HLS, 1: RGB
+//! @param npts number of control points
+//! @param pos[] position for each control point
+//! @param coord1[] first coordinate for each control point
+//! @param coord2[] second coordinate for each control point
+//! @param coord3[] third coordinate for each control point
+//! @param rev[] reverse flag for each control point
void
c_plscmap1l( PLINT itype, PLINT npts, const PLFLT *pos,
@@ -645,9 +707,16 @@
//--------------------------------------------------------------------------
// plscmap1la()
//
-// This is the same as plscmap1l, but also allows alpha value interpolation.
-//
-//--------------------------------------------------------------------------
+//! This is the same as plscmap1l, but also allows alpha value interpolation.
+//!
+//! @param itype 0: HLS, 1: RGB
+//! @param npts number of control points
+//! @param pos[] position for each control point
+//! @param coord1[] first coordinate for each control point
+//! @param coord2[] second coordinate for each control point
+//! @param coord3[] third coordinate for each control point
+//! @param a[] alpha value for each control point
+//! @param rev[] reverse flag for each control point
void
c_plscmap1la( PLINT itype, PLINT npts, const PLFLT *pos,
@@ -719,9 +788,8 @@
//--------------------------------------------------------------------------
// plcmap1_calc()
//
-// Bin up cmap 1 space and assign colors to make inverse mapping easy.
-// Always do interpolation in HLS space.
-//--------------------------------------------------------------------------
+//! Bin up cmap 1 space and assign colors to make inverse mapping easy.
+//! Always do interpolation in HLS space.
void
plcmap1_calc( void )
@@ -843,12 +911,13 @@
//--------------------------------------------------------------------------
// plscmap0n()
//
-// Set number of colors in cmap 0, (re-)allocate cmap 0, and fill with
-// default values for those colors not previously allocated (and less
-// than index 15, after that you just get grey).
-//
-// The driver is not guaranteed to support all of these.
-//--------------------------------------------------------------------------
+//! Set number of colors in cmap 0, (re-)allocate cmap 0, and fill with
+//! default values for those colors not previously allocated (and less
+//! than index 15, after that you just get grey).
+//!
+//! The driver is not guaranteed to support all of these.
+//!
+//! @param ncol0 Total number of colors.
void
c_plscmap0n( PLINT ncol0 )
@@ -903,8 +972,14 @@
//--------------------------------------------------------------------------
// color_set()
//
-// Initializes color table entry by RGB values.
-//--------------------------------------------------------------------------
+//! Initializes color table 0 entry by RGB values.
+//!
+//! @param i Index of the color.
+//! @param r Red value of the color.
+//! @param g Green value of the color.
+//! @param b Blue value of the color.
+//! @param a Alpha value of the color.
+//! @param name The name of the color.
void
color_set( PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, PLFLT a, const char *name )
@@ -922,9 +997,11 @@
//--------------------------------------------------------------------------
// plcmap0_def()
//
-// Initializes specified color map 0 color entry to its default for
-// index range from imin to imax.
-//--------------------------------------------------------------------------
+//! Initializes specified color map 0 color entry to its default for
+//! index range from imin to imax.
+//!
+//! @param imin Index of the first color to set to its default.
+//! @param imax Index of the last color to set to its default.
void
plcmap0_def( int imin, int imax )
@@ -959,12 +1036,13 @@
//--------------------------------------------------------------------------
// plscmap1n()
//
-// Set number of colors in cmap 1, (re-)allocate cmap 1, and set default
-// values if this is the first allocation.
-//
-// Note that the driver is allowed to disregard this number.
-// In particular, most use fewer than we use internally.
-//--------------------------------------------------------------------------
+//! Set number of colors in cmap 1, (re-)allocate cmap 1, and set default
+//! values if this is the first allocation.
+//!
+//! Note that the driver is allowed to disregard this number.
+//! In particular, most use fewer than we use internally.
+//!
+//! @param ncol1 The number of colors in cmap1.
void
c_plscmap1n( PLINT ncol1 )
@@ -1017,15 +1095,15 @@
//--------------------------------------------------------------------------
// plcmap1_def()
//
-// Initializes color map 1.
-//
-// The default initialization uses 6 control points in HLS space, the inner
-// ones being very close to one of the vertices of the HLS double cone. The
-// vertex used (black or white) is chosen to be the closer to the background
-// color. The 6 points were chosen over the older 4 points in order to make
-// weaker structures more easily visible, and give more control through the
-// palette editor. If you don't like these settings.. change them!
-//--------------------------------------------------------------------------
+//! Initializes color map 1.
+//!
+//! The default initialization uses 6 control points in HLS space, the inner
+//! ones being very close to one of the vertices of the HLS double cone. The
+//! vertex used (black or white) is chosen to be the closer to the background
+//! color. The 6 points were chosen over the older 4 points in order to make
+//! weaker structures more easily visible, and give more control through the
+//! palette editor. If you don't like these settings.. change them!
+//!
void
plcmap1_def( void )
@@ -1096,7 +1174,9 @@
//--------------------------------------------------------------------------
// plscolor()
//
-// Used to globally turn color output on/off
+//! Used to globally turn color output on/off
+//!
+//! @param color 0 = no color, Not zero = color.
//--------------------------------------------------------------------------
void
@@ -1109,7 +1189,11 @@
//--------------------------------------------------------------------------
// void value()
//
-// Auxiliary function used by c_plhlsrgb().
+//! Auxiliary function used by c_plhlsrgb().
+//!
+//! @param n1 Lightness/saturation value 1.
+//! @param n2 Lightness/saturation value 2.
+//! @param hue hue (0.0 - 360.0).
//--------------------------------------------------------------------------
PLFLT
@@ -1137,16 +1221,22 @@
//--------------------------------------------------------------------------
// void c_plhlsrgb()
//
-// Convert HLS color to RGB color.
-// Bounds on HLS (input):
-// hue [0., 360.] degrees
-// lightness [0., 1.] magnitude
-// saturation [0., 1.] magnitude
-//
-// Hue is always mapped onto the interval [0., 360.] regardless of input.
-// Bounds on RGB (output) is always [0., 1.]. Convert to RGB color values
-// by multiplying by 2**nbits (nbits typically 8).
-//--------------------------------------------------------------------------
+//! Convert HLS color to RGB color.
+//! Bounds on HLS (input):
+//! hue [0., 360.] degrees
+//! lightness [0., 1.] magnitude
+//! saturation [0., 1.] magnitude
+//!
+//! Hue is always mapped onto the interval [0., 360.] regardless of input.
+//! Bounds on RGB (output) is always [0., 1.]. Convert to RGB color values
+//! by multiplying by 2**nbits (nbits typically 8).
+//!
+//! @param h hue in HLS color scheme (0.0 - 360.0)
+//! @param l lightness in HLS color scheme (0.0 - 1.0)
+//! @param s saturation in HLS color scheme (0.0 - 1.0)
+//! @param p_r red value of the HLS color
+//! @param p_g green value of the HLS color
+//! @param p_b blue value of the HLS color
void
c_plhlsrgb( PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b )
@@ -1168,13 +1258,18 @@
//--------------------------------------------------------------------------
// void c_plrgbhls()
//
-// Convert RGB color to HLS color.
-// Bounds on RGB (input) is always [0., 1.].
-// Bounds on HLS (output):
-// hue [0., 360.] degrees
-// lightness [0., 1.] magnitude
-// saturation [0., 1.] magnitude
-//--------------------------------------------------------------------------
+//! Convert RGB color to HLS color.
+//! Bounds on RGB (input) is always [0., 1.].
+//! Bounds on HLS (output):
+//! hue [0., 360.] degrees
+//! lightness [0., 1.] magnitude
+//! saturation [0., 1.] magnitude
+//! @param r red in RGB color scheme (0.0 - 1.0)
+//! @param g green in RGB color scheme (0.0 - 1.0)
+//! @param b blue in RGB color scheme (0.0 - 1.0)
+//! @param p_h hue value of the RGB color.
+//! @param p_l lightness value of the RGB color.
+//! @param p_s saturation value of the RGB color.
void
c_plrgbhls( PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s )
@@ -1224,10 +1319,15 @@
//--------------------------------------------------------------------------
// read_line()
//
-// Read a complete line and fill the buffer with its contents up to
-// capacity. Then sanitize the string - no control characters, no
-// trailing blanks
-//--------------------------------------------------------------------------
+//! Read a complete line and fill the buffer with its contents up to
+//! capacity. Then sanitize the string - no control characters, no
+//! trailing blanks
+//!
+//! @param buffer storage for the line of text.
+//! @param length size of the buffer.
+//! @param fp open file pointer from which the line of text should be read.
+//!
+//! @returns The sanitized line from the file.
static char *
read_line( char *buffer, int length, FILE *fp )
@@ -1276,9 +1376,15 @@
//--------------------------------------------------------------------------
// cmap0_palette_read()
//
-// Read and check r, g, b, a data from a cmap0*.pal format file.
-// The caller must free the returned malloc'ed space for r, g, b, and a.
-//--------------------------------------------------------------------------
+//! Read and check r, g, b, a data from a cmap0*.pal format file.
+//! The caller must free the returned malloc'ed space for r, g, b, and a.
+//!
+//! @param filename name of the cmap0 palette file.
+//! @param number_colors number of color found in the palette file.
+//! @param r red value of each color in the palette file.
+//! @param g green value of each color in the palette file.
+//! @param b blue value of each color in the palette file.
+//! @param a alpha value of each color in the palette file.
void
cmap0_palette_read( const char *filename,
@@ -1424,9 +1530,10 @@
//--------------------------------------------------------------------------
// void c_plspal0(filename)
//
-// Set the palette for color map 0 using a cmap0*.pal format file.
-// filename: the name of the cmap0*.pal file to use.
-//--------------------------------------------------------------------------
+//! Set the palette for color map 0 using a cmap0*.pal format file.
+//! filename: the name of the cmap0*.pal file to use.
+//!
+//! @param filename name of the cmap0 palette file.
void
c_plspal0( const char *filename )
@@ -1454,10 +1561,15 @@
free( a );
}
-// This code fragment used a lot in plspal1 to deal with
-// floating-point range checking of a value and the adjustment of that
-// value when close to the range when there is floating-point errors.
-//
+//! This code fragment used a lot in plspal1 to deal with
+//! floating-point range checking of a value and the adjustment of that
+//! value when close to the range when there is floating-point errors.
+//!
+//! @param value The value to range check.
+//! @param min The minimum allowable value.
+//! @param max The maximum allowable value.
+//! @param fuzz Amount of slop to allow beyond the range defined by min & max.
+//! @param err_number The error number.
#define fuzzy_range_check( value, min, max, fuzz, err_number ) \
if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
@@ -1469,12 +1581,15 @@
} else if ( value > max ) { \
value = max; \
}
+
//--------------------------------------------------------------------------
// void c_plspal1(filename)
//
-// Set the palette for color map 1 using a cmap1*.pal format file.
-// filename: the name of the cmap1*.pal file to use.
-//--------------------------------------------------------------------------
+//! Set the palette for color map 1 using a cmap1*.pal format file.
+//! filename: the name of the cmap1*.pal file to use.
+//!
+//! @param filename name of the cmap1 palette file.
+//! @param interpolate interpolate between control points.
void
c_plspal1( const char *filename, PLBOOL interpolate )
@@ -1720,8 +1835,9 @@
//--------------------------------------------------------------------------
// void plwarn()
//
-// A handy way to issue warnings, if need be.
-//--------------------------------------------------------------------------
+//! A handy way to issue warnings, if need be.
+//!
+//! @param errormsg The error message.
void
plwarn( const char *errormsg )
@@ -1745,13 +1861,14 @@
//--------------------------------------------------------------------------
// void plabort()
//
-// Much the same as plwarn(), but appends ", aborting operation" to the
-// error message. Helps to keep source code uncluttered and provides a
-// convention for error aborts.
-//
-// If cleanup needs to be done in the main program, the user should write
-// his/her own exit handler and pass it in via plsabort().
-//--------------------------------------------------------------------------
+//! Much the same as plwarn(), but appends ", aborting operation" to the
+//! error message. Helps to keep source code uncluttered and provides a
+//! convention for error aborts.
+//!
+//! If cleanup needs to be done in the main program, the user should write
+//! his/her own exit handler and pass it in via plsabort().
+//!
+//! @param errormsg The error message.
void
plabort( const char *errormsg )
@@ -1791,7 +1908,10 @@
//--------------------------------------------------------------------------
// void plsabort()
//
-// Sets an optional user abort handler.
+//! Sets an optional user abort handler.
+//!
+//! @param handler A function that takes a const char * argument that will
+//! be called in the event of a abort.
//--------------------------------------------------------------------------
void
@@ -1803,13 +1923,15 @@
//--------------------------------------------------------------------------
// void plexit()
//
-// In case of an abort this routine is called. It just prints out an error
-// message and tries to clean up as much as possible. It's best to turn
-// off pause and then restore previous setting before returning.
-//
-// If cleanup needs to be done in the main program, the user should write
-// his/her own exit handler and pass it in via plsexit(). This function
-// should should either call plend() before exiting, or simply return.
+//! In case of an abort this routine is called. It just prints out an error
+//! message and tries to clean up as much as possible...
[truncated message content] |
|
From: <ai...@us...> - 2013-09-18 19:12:46
|
Revision: 12509
http://sourceforge.net/p/plplot/code/12509
Author: airwin
Date: 2013-09-18 19:12:42 +0000 (Wed, 18 Sep 2013)
Log Message:
-----------
In doxygen documentation of plcol1, use the correct (col1 rather than
icol1) parameter name.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2013-09-18 18:51:03 UTC (rev 12508)
+++ trunk/src/plctrl.c 2013-09-18 19:12:42 UTC (rev 12509)
@@ -7,7 +7,7 @@
// Copyright (C) 2004 Joao Cardoso
// Copyright (C) 2004 Rafael Laboissiere
// Copyright (C) 2008 Hazen Babcock
-// Copyright (C) 2009 Alan W. Irwin
+// Copyright (C) 2009-2013 Alan W. Irwin
// Copyright (C) 2011 Hezekiah M. Carty
//
// This file is part of PLplot.
@@ -170,7 +170,7 @@
//
//! Set color, map 1. Argument is a float between 0. and 1.
//!
-//! @param icol1 The index of the color map 1 color to use as the current
+//! @param col1 The index of the color map 1 color to use as the current
//! color. (0.0 - 1.0)
void
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2013-12-11 00:45:36
|
Revision: 12841
http://sourceforge.net/p/plplot/code/12841
Author: andrewross
Date: 2013-12-11 00:45:33 +0000 (Wed, 11 Dec 2013)
Log Message:
-----------
Fix plscmap1l(a) and plspal so they assume the rev array is one element shorter than the coordinate arrays, consistent with the documentation and actual usage of this array.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2013-12-10 23:52:18 UTC (rev 12840)
+++ trunk/src/plctrl.c 2013-12-11 00:45:33 UTC (rev 12841)
@@ -698,7 +698,11 @@
if ( alt_hue_path == NULL )
plsc->cmap1cp[n].alt_hue_path = 0;
else
- plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
+ if ( n != npts-1 )
+ plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
+ else
+ // Note final element is unused, so we set to zero for completeness.
+ plsc->cmap1cp[n].alt_hue_path = 0;
}
// Calculate and set color map
@@ -780,7 +784,11 @@
if ( alt_hue_path == NULL )
plsc->cmap1cp[n].alt_hue_path = 0;
else
- plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
+ if ( n != npts-1 )
+ plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
+ else
+ // Note final element is unused, so we set to zero for completeness.
+ plsc->cmap1cp[n].alt_hue_path = 0;
}
// Calculate and set color map
@@ -1681,7 +1689,7 @@
bi = (PLINT *) malloc( (size_t) number_colors * sizeof ( PLINT ) );
a = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
pos = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
- alt_hue_path = (PLBOOL *) malloc( (size_t) number_colors * sizeof ( PLBOOL ) );
+ alt_hue_path = (PLBOOL *) malloc( (size_t) ( number_colors - 1 ) * sizeof ( PLBOOL ) );
if ( format_version == 0 )
{
@@ -1718,7 +1726,7 @@
fuzzy_range_check( g[i], 0., 1., FUZZ_EPSILON, 2 );
fuzzy_range_check( b[i], 0., 1., FUZZ_EPSILON, 3 );
fuzzy_range_check( pos[i], 0., 1., FUZZ_EPSILON, 4 );
- if ( return_sscanf == 5 )
+ if ( ( return_sscanf == 5 ) && ( i != number_colors - 1 ) )
{
// Next to oldest tk format with alt_hue_path specified.
alt_hue_path[i] = (PLBOOL) alt_hue_path_i;
@@ -1772,7 +1780,8 @@
fuzzy_range_check( a[i], 0., 1., FUZZ_EPSILON, 9 );
fuzzy_range_check( pos[i], 0., 1., FUZZ_EPSILON, 10 );
- alt_hue_path[i] = (PLBOOL) alt_hue_path_i;
+ if ( i != number_colors - 1 )
+ alt_hue_path[i] = (PLBOOL) alt_hue_path_i;
}
}
fclose( fp );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2014-05-20 18:37:51
|
Revision: 13125
http://sourceforge.net/p/plplot/code/13125
Author: airwin
Date: 2014-05-20 18:37:46 +0000 (Tue, 20 May 2014)
Log Message:
-----------
Fix size_t formatting issue for Microsoft platforms.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2014-05-18 22:05:54 UTC (rev 13124)
+++ trunk/src/plctrl.c 2014-05-20 18:37:46 UTC (rev 13125)
@@ -2466,7 +2466,14 @@
strcat_delim( *filespec );
strcat( *filespec, filename );
}
+#ifdef WIN32
+ // According to http://msdn.microsoft.com/en-us/library/vstudio/tcxf1dw6.aspx
+ // and also Wine tests, Microsoft does not support the c99 standard %zu
+ // format. Instead, %lu is recommended for size_t.
+ pldebug( "plGetName", "Maximum length of full pathname of file to be found is %lu\n", lfilespec - 1 );
+#else
pldebug( "plGetName", "Maximum length of full pathname of file to be found is %zu\n", lfilespec - 1 );
+#endif
pldebug( "plGetName", "Full pathname of file to be found is %s\n", *filespec );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-07-09 23:23:34
|
Revision: 10131
http://plplot.svn.sourceforge.net/plplot/?rev=10131&view=rev
Author: airwin
Date: 2009-07-09 23:23:21 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
Implement plGetName pldebug information.
Fix bug in current directory pldebug information output.
Deal with two (!) old tk formats, one without and one with rev information.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-07-09 23:19:05 UTC (rev 10130)
+++ trunk/src/plctrl.c 2009-07-09 23:23:21 UTC (rev 10131)
@@ -1290,7 +1290,6 @@
char msgbuf[1024];
rgb = TRUE;
- rev = NULL;
err = 0;
format_version = 0;
fp = plLibOpen(filename);
@@ -1328,28 +1327,38 @@
b = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
a = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
pos = (PLFLT *)malloc(number_colors * sizeof(PLFLT));
- if (format_version > 0) {
- rev = (PLBOOL *)malloc(number_colors * sizeof(PLBOOL));
- }
+ rev = (PLBOOL *)malloc(number_colors * sizeof(PLBOOL));
if (format_version == 0) {
+ int return_sscanf, return_sscanf_old=0;
/* Old tk file format */
for(i=0;i<number_colors;i++){
fgets(color_info, 160, fp);
/* Ensure string is null terminated if > 160 characters */
color_info[159] = '\0';
- if (sscanf(color_info, "#%2x%2x%2x %d", &r_i, &g_i, &b_i, &pos_i) < 4) {
+ return_sscanf = sscanf(color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &rev_i);
+ if(return_sscanf < 4 || (return_sscanf_old != 0 && return_sscanf != return_sscanf_old)) {
snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
plwarn(msgbuf);
err = 1;
break;
- }
+ }
+ return_sscanf_old = return_sscanf;
r[i] = (PLFLT)r_i;
g[i] = (PLFLT)g_i;
b[i] = (PLFLT)b_i;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
+ if(return_sscanf == 5) {
+ /* Next to oldest tk format with rev specified. */
+ rev[i] = (PLBOOL)rev_i;
+ }
}
+ if(return_sscanf == 4) {
+ /* Oldest tk format. No rev specified. */
+ free(rev);
+ rev = NULL;
+ }
}
else {
/* New floating point file version with support for alpha and rev values */
@@ -1365,8 +1374,8 @@
g[i] = (PLFLT)g_d;
b[i] = (PLFLT)b_d;
a[i] = (PLFLT)a_d;
+ pos[i] = (PLFLT)pos_d;
rev[i] = (PLBOOL)rev_i;
- pos[i] = (PLFLT)pos_d;
}
}
fclose(fp);
@@ -1385,6 +1394,7 @@
free(b);
free(a);
free(pos);
+ free(rev);
}
/*--------------------------------------------------------------------------*\
@@ -1719,7 +1729,8 @@
/**** search current directory ****/
if ((file = pdf_fopen(fn, "rb")) != NULL){
- goto done;
+ pldebug("plLibOpenPdfstr", "Found file %s in current directory.\n", fn);
+ return (file);
}
/**** search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib ****/
@@ -1867,7 +1878,6 @@
/* Malloc space for filespec */
free_mem(*filespec);
- lfilespec = 10;
lfilespec = strlen(dir) + strlen(subdir) + strlen(filename) + 10;
if ((*filespec = (char *) malloc(lfilespec))==NULL)
{
@@ -1884,6 +1894,8 @@
strcat_delim(*filespec);
strcat(*filespec, filename);
}
+ pldebug("plGetName", "Length of full pathname of file to be found is %d\n", lfilespec);
+ pldebug("plGetName", "Full pathname of file to be found is %s\n", *filespec);
}
/*--------------------------------------------------------------------------*\
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-22 20:28:33
|
Revision: 10315
http://plplot.svn.sourceforge.net/plplot/?rev=10315&view=rev
Author: airwin
Date: 2009-08-22 20:28:26 +0000 (Sat, 22 Aug 2009)
Log Message:
-----------
Unknown colours were set to red previously but identified as black. I
have fixed that small inconsistency in name and updated the comment
consistently.
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-21 20:16:22 UTC (rev 10314)
+++ trunk/src/plctrl.c 2009-08-22 20:28:26 UTC (rev 10315)
@@ -893,9 +893,9 @@
{
int i;
- /* Initialize all colors to black. */
+ /* Initialize all unknown colours to red as a warning. */
for (i = imin; i <= imax; i++)
- color_def(i, 255, 0, 0, 1.0, "black");
+ color_def(i, 255, 0, 0, 1.0, "red");
}
/*--------------------------------------------------------------------------*\
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2009-08-27 03:41:25
|
Revision: 10351
http://plplot.svn.sourceforge.net/plplot/?rev=10351&view=rev
Author: airwin
Date: 2009-08-27 03:41:19 +0000 (Thu, 27 Aug 2009)
Log Message:
-----------
Guard against floating-point errors in comparison of pos[i] with 0. and 1.
(Thanks to Valery Pipin for testing on hardware where this issue surfaced for
cmap1_default.pal.)
Modified Paths:
--------------
trunk/src/plctrl.c
Modified: trunk/src/plctrl.c
===================================================================
--- trunk/src/plctrl.c 2009-08-27 01:15:25 UTC (rev 10350)
+++ trunk/src/plctrl.c 2009-08-27 03:41:19 UTC (rev 10351)
@@ -1424,11 +1424,15 @@
b[i] = (PLFLT)b_i/255.;
a[i] = 1.0;
pos[i] = 0.01*(PLFLT)pos_i;
- if(pos[i] < 0. || pos[i] > 1.) {
+ if(pos[i] < -1.e-12 || pos[i] > 1. + 1.e-12) {
snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info);
plwarn(msgbuf);
err = 1;
break;
+ } else if (pos[i] < 0.) {
+ pos[i] = 0.;
+ } else if (pos[i] > 1.) {
+ pos[i] = 1.;
}
if(return_sscanf == 5) {
/* Next to oldest tk format with rev specified. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|