[gl2ps] building gl2ps without warnings
Larry Doolittle
ldoolitt at recycle.lbl.gov
Wed Feb 9 23:16:35 CET 2011
Christophe -
I just built the fresh release 3.4.0 of octave, which includes
a copy of gl2ps.[ch]. Many of the warnings in that compile come
from gl2ps. I checked, they have an up-to-date copy of what's in
your svn repository (with trailing spaces deleted).
The reason so many warnings are generated is that they have gcc's
lint-checking features turned up high. Something like -Wall -W
-Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
-Wcast-align -Wcast-qual -g -O2.
I investigated all the warnings, and they are all innocuous, with
simple fixes. I attach a patch which makes gl2ps compile without
warnings under those conditions. Maybe you could apply it, and
also take out those silly trailing spaces ("1,$s/ *//" in vi).
- Larry
-------------- next part --------------
diff -u /home/ldoolitt/git/gl2ps/gl2ps.c gl2ps/gl2ps.c
--- /home/ldoolitt/git/gl2ps/gl2ps.c 2011-02-09 11:46:30.000000000 -0800
+++ gl2ps/gl2ps.c 2011-02-09 12:10:56.000000000 -0800
@@ -441,7 +441,7 @@
return ret;
}
-static void gl2psPrintGzipHeader()
+static void gl2psPrintGzipHeader(void)
{
#if defined(GL2PS_HAVE_ZLIB)
char tmp[10] = {'\x1f', '\x8b', /* magic numbers: 0x1f, 0x8b */
@@ -459,7 +459,7 @@
#endif
}
-static void gl2psPrintGzipFooter()
+static void gl2psPrintGzipFooter(void)
{
#if defined(GL2PS_HAVE_ZLIB)
int n;
@@ -789,6 +789,7 @@
static void gl2psUserFlushPNG(png_structp png_ptr)
{
+ (void) png_ptr; /* not used */
}
static void gl2psConvertPixmapToPNG(GL2PSimage *pixmap, GL2PSlist *png)
@@ -1363,12 +1364,12 @@
static int gl2psCompareDepth(const void *a, const void *b)
{
- GL2PSprimitive *q, *w;
+ const GL2PSprimitive *q, *w;
GLfloat dq = 0.0F, dw = 0.0F, diff;
int i;
- q = *(GL2PSprimitive**)a;
- w = *(GL2PSprimitive**)b;
+ q = *(const GL2PSprimitive* const*)a;
+ w = *(const GL2PSprimitive* const*)b;
for(i = 0; i < q->numverts; i++){
dq += q->verts[i].xyz[2];
@@ -1394,10 +1395,10 @@
static int gl2psTrianglesFirst(const void *a, const void *b)
{
- GL2PSprimitive *q, *w;
+ const GL2PSprimitive *q, *w;
- q = *(GL2PSprimitive**)a;
- w = *(GL2PSprimitive**)b;
+ q = *(const GL2PSprimitive* const*)a;
+ w = *(const GL2PSprimitive* const*)b;
return (q->type < w->type ? 1 : -1);
}
@@ -1614,7 +1615,7 @@
}
}
-static void gl2psRescaleAndOffset()
+static void gl2psRescaleAndOffset(void)
{
GL2PSprimitive *prim;
GLfloat minZ, maxZ, rangeZ, scaleZ;
@@ -3306,6 +3307,7 @@
static void gl2psPrintTeXBeginViewport(GLint viewport[4])
{
+ (void) viewport; /* not used */
glRenderMode(GL_FEEDBACK);
if(gl2ps->header){
@@ -5031,6 +5033,7 @@
gl2psPrintf("\"/>\n");
gl2psListDelete(png);
#else
+ (void) x; (void) y; (void) pixmap; /* not used */
gl2psMsg(GL2PS_WARNING, "GL2PS must be compiled with PNG support in "
"order to embed images in SVG streams");
#endif
@@ -5842,7 +5845,8 @@
const void *pixels)
{
int size, i;
- GLfloat pos[4], *piv, zoom_x, zoom_y;
+ const GLfloat *piv;
+ GLfloat pos[4], zoom_x, zoom_y;
GL2PSprimitive *prim;
GLboolean valid;
@@ -5894,7 +5898,7 @@
prim->data.image->format = GL_RGB;
size = height * width * 3;
prim->data.image->pixels = (GLfloat*)gl2psMalloc(size * sizeof(GLfloat));
- piv = (GLfloat*)pixels;
+ piv = (const GLfloat*)pixels;
for(i = 0; i < size; ++i, ++piv){
prim->data.image->pixels[i] = *piv;
if(!((i + 1) % 3))
@@ -5939,7 +5943,7 @@
glPassThrough((GLfloat)width);
glPassThrough((GLfloat)height);
for(i = 0; i < size; i += sizeoffloat){
- float *value = (float*)imagemap;
+ const float *value = (const float*)imagemap;
glPassThrough(*value);
imagemap += sizeoffloat;
}
diff -u /home/ldoolitt/git/gl2ps/gl2psTest.c gl2ps/gl2psTest.c
--- /home/ldoolitt/git/gl2ps/gl2psTest.c 2011-02-09 11:46:30.000000000 -0800
+++ gl2ps/gl2psTest.c 2011-02-09 12:20:43.000000000 -0800
@@ -133,7 +133,7 @@
"*..............................................................*",
"****************************************************************"};
-void triangles()
+static void triangles(void)
{
/* two intersecting triangles */
glBegin(GL_TRIANGLES);
@@ -155,7 +155,7 @@
glEnd();
}
-void extras()
+static void extras(void)
{
glColor3f(1., 0., 0.);
@@ -224,7 +224,7 @@
gl2psLineWidth(1);
}
-void objects()
+static void objects(void)
{
glPushMatrix();
glEnable(GL_LIGHTING);
@@ -240,7 +240,7 @@
glPopMatrix();
}
-void printstring(const char *string, float angle)
+static void printstring(const char *string, float angle)
{
unsigned int i;
const char *fonts[] =
@@ -257,7 +257,7 @@
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, string[i]);
}
-void text()
+static void text(void)
{
double x = -1.25, y = -0.33, dy = 0.13;
@@ -296,7 +296,7 @@
gl2psSpecial(GL2PS_TEX, "% This should only be printed in LaTeX output!");
}
-void cube()
+static void cube(void)
{
glColor3d (0.0,1.0,0.);
glBegin(GL_POLYGON);
@@ -332,7 +332,7 @@
glEnd();
}
-void image(float x, float y, GLboolean opaque)
+static void image(float x, float y, GLboolean opaque)
{
int w = 64, h = 66, row, col, pos = 0;
float *pixels, r = 0., g = 0., b = 0.;
@@ -386,7 +386,7 @@
}
/* A simple drawing function, using the default viewport */
-void draw_single()
+static void draw_single(void)
{
glScissor(0, 0, window_w, window_h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -398,7 +398,7 @@
}
/* A more complex drawing function, using 2 separate viewports */
-void draw_multi()
+static void draw_multi(void)
{
GLint viewport[4];
@@ -458,7 +458,7 @@
glFlush();
}
-void display()
+static void display(void)
{
GLfloat spec[4] = {0.6, 0.6, 0.6, 1.0};
glEnable(GL_DEPTH_TEST);
@@ -485,7 +485,7 @@
}
}
-void reshape(int w, int h)
+static void reshape(int w, int h)
{
window_w = w;
window_h = h;
@@ -500,7 +500,7 @@
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
-void writefile(int format, int sort, int options, int nbcol,
+static void writefile(int format, int sort, int options, int nbcol,
const char *filename, const char *extension)
{
FILE *fp;
@@ -542,12 +542,13 @@
fflush(stdout);
}
-void keyboard(unsigned char key, int x, int y)
+static void keyboard(unsigned char key, int x, int y)
{
int opt;
char ext[32];
static int format = GL2PS_PS;
+ (void) x; (void) y; /* not used */
switch(key){
case 27:
case 'q':
@@ -612,8 +613,9 @@
}
}
-void motion(int x, int y)
+static void motion(int x, int y)
{
+ (void) x; (void) y; /* not used */
rotation += 10.;
display();
}
diff -u /home/ldoolitt/git/gl2ps/gl2psTestSimple.c gl2ps/gl2psTestSimple.c
--- /home/ldoolitt/git/gl2ps/gl2psTestSimple.c 2011-02-09 11:46:30.000000000 -0800
+++ gl2ps/gl2psTestSimple.c 2011-02-09 12:39:03.000000000 -0800
@@ -50,11 +50,11 @@
#include <string.h>
#include "gl2ps.h"
-void display()
+static void display(void)
{
unsigned int i;
- int N = 50;
- char *help = "Press 's' to save image or 'q' to quit";
+ unsigned int N = 50;
+ const char *help = "Press 's' to save image or 'q' to quit";
glClearColor(0.3, 0.5, 0.8, 0.);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -91,11 +91,12 @@
glFlush();
}
-void keyboard(unsigned char key, int x, int y)
+static void keyboard(unsigned char key, int x, int y)
{
FILE *fp;
int state = GL2PS_OVERFLOW, buffsize = 0;
+ (void) x; (void) y; /* not used */
switch(key){
case 'q':
exit(0);