from The Open Group.
*/
+/* $XFree86: xc/programs/xwud/xwud.c,v 3.7 2001/12/14 20:02:35 dawes Exp $ */
/* xwud - marginally useful raster image undumper */
#define XK_LATIN1
#include <X11/keysymdef.h>
#include <errno.h>
+#include <stdlib.h>
-#ifdef X_NOT_STDC_ENV
-extern int errno;
-#endif
-
-extern char *malloc();
-unsigned Image_Size();
Atom wm_protocols;
Atom wm_delete_window;
int split;
char *progname;
-usage()
+static void usage(void);
+static Bool Read(char *ptr, int size, int nitems, FILE *stream);
+static void putImage(Display *dpy, Window image_win, GC gc,
+ XImage *out_image, int x, int y, int w, int h);
+static void putScaledImage(Display *display, Drawable d, GC gc,
+ XImage *src_image, int exp_x, int exp_y,
+ unsigned int exp_width, unsigned int exp_height,
+ unsigned int dest_width, unsigned dest_height);
+static void Latin1Upper(char *s);
+static void Extract_Plane(XImage *in_image, XImage *out_image, int plane);
+static int EffectiveSize(XVisualInfo *vinfo);
+static int VisualRank(int class);
+static int IsGray(Display *dpy, XStandardColormap *stdmap);
+static void Do_StdGray(Display *dpy, XStandardColormap *stdmap, int ncolors,
+ XColor *colors, XImage *in_image, XImage *out_image);
+static void Do_StdCol(Display *dpy, XStandardColormap *stdmap, int ncolors,
+ XColor *colors, XImage *in_image, XImage *out_image);
+static Colormap CopyColormapAndFree(Display *dpy, Colormap colormap);
+static void Do_Pseudo(Display *dpy, Colormap *colormap, int ncolors,
+ XColor *colors, XImage *in_image, XImage *out_image);
+static void Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
+ int ncolors, XColor *colors,
+ XImage *in_image, XImage *out_image);
+static unsigned int Image_Size(XImage *image);
+static void Error(char *string);
+static void _swapshort(char *bp, unsigned int n);
+static void _swaplong(char *bp, unsigned int n);
+
+static void
+usage(void)
{
fprintf(stderr, "usage: %s [-in <file>] [-noclick] [-geometry <geom>] [-display <display>]\n", progname);
fprintf(stderr, " [-new] [-std <maptype>] [-raw] [-vis <vis-type-or-id>]\n");
exit(1);
}
-Bool
-Read(ptr, size, nitems, stream)
- char *ptr;
- int size;
- int nitems;
- FILE *stream;
+static Bool
+Read(char *ptr, int size, int nitems, FILE *stream)
{
size *= nitems;
while (size) {
return True;
}
-main(argc, argv)
- int argc;
- char **argv;
+int
+main(int argc, char *argv[])
{
Display *dpy;
int screen;
XSizeHints hints;
XTextProperty textprop;
XClassHint class_hint;
- XColor *colors, color, igncolor;
+ XColor *colors = NULL, color, igncolor;
Window image_win;
Colormap colormap;
XEvent event;
FILE *in_file = stdin;
char *map_name;
Atom map_prop;
- XStandardColormap *stdmaps, *stdmap;
+ XStandardColormap *stdmaps, *stdmap = NULL;
char c;
int win_width, win_height;
break;
}
}
+ exit(0);
}
-putImage (dpy, image_win, gc, out_image, x, y, w, h)
- Display *dpy;
- Window image_win;
- GC gc;
- XImage *out_image;
- int x, y, w, h;
+static void
+putImage(Display *dpy, Window image_win, GC gc, XImage *out_image,
+ int x, int y, int w, int h)
{
#define SPLIT_SIZE 100
int t_x, t_y, t_w, t_h;
Dimension *width, *height;
} Table;
-putScaledImage(display, d, gc, src_image, exp_x, exp_y,
- exp_width, exp_height, dest_width, dest_height)
- Display* display;
- Drawable d;
- GC gc;
- XImage* src_image;
- int exp_x;
- int exp_y;
- unsigned int exp_width;
- unsigned int exp_height;
- unsigned int dest_width;
- unsigned int dest_height;
+static void
+putScaledImage(Display *display, Drawable d, GC gc, XImage *src_image,
+ int exp_x, int exp_y,
+ unsigned int exp_width, unsigned int exp_height,
+ unsigned int dest_width, unsigned dest_height)
{
XImage *dest_image;
Position x, y, min_y, max_y, exp_max_y, src_x, src_max_x, src_y;
XDestroyImage(dest_image);
}
-Latin1Upper(s)
- char *s;
+static void
+Latin1Upper(char *s)
{
unsigned char *str = (unsigned char *)s;
unsigned char c;
}
}
-Extract_Plane(in_image, out_image, plane)
- register XImage *in_image, *out_image;
- int plane;
+static void
+Extract_Plane(XImage *in_image, XImage *out_image, int plane)
{
register int x, y;
(XGetPixel(in_image, x, y) >> plane) & 1);
}
-int
-EffectiveSize(vinfo)
- XVisualInfo *vinfo;
+static int
+EffectiveSize(XVisualInfo *vinfo)
{
if ((vinfo->class == DirectColor) || (vinfo->class == TrueColor))
return (vinfo->red_mask | vinfo->green_mask | vinfo->blue_mask) + 1;
return vinfo->colormap_size;
}
-VisualRank(class)
- int class;
+static int
+VisualRank(int class)
{
switch (class) {
case PseudoColor:
case StaticGray:
return 0;
}
+ /* NOTREACHED */
+ return -1;
}
-int
-IsGray(dpy, stdmap)
- Display *dpy;
- XStandardColormap *stdmap;
+static int
+IsGray(Display *dpy, XStandardColormap *stdmap)
{
XColor color;
return (color.green || color.blue);
}
-Do_StdGray(dpy, stdmap, ncolors, colors, in_image, out_image)
- Display *dpy;
- XStandardColormap *stdmap;
- int ncolors;
- XColor *colors;
- register XImage *in_image, *out_image;
+static void
+Do_StdGray(Display *dpy, XStandardColormap *stdmap,
+ int ncolors, XColor *colors, XImage *in_image, XImage *out_image)
{
register int i, x, y;
register XColor *color;
#define MapVal(val,lim,mult) ((((val * lim) + 32768) / 65535) * mult)
-Do_StdCol(dpy, stdmap, ncolors, colors, in_image, out_image)
- Display *dpy;
- XStandardColormap *stdmap;
- int ncolors;
- XColor *colors;
- register XImage *in_image, *out_image;
+static void
+Do_StdCol(Display *dpy, XStandardColormap *stdmap,
+ int ncolors, XColor *colors, XImage *in_image, XImage *out_image)
{
register int i, x, y;
register XColor *color;
}
}
-Colormap
-CopyColormapAndFree(dpy, colormap)
- Display *dpy;
- Colormap colormap;
+static Colormap
+CopyColormapAndFree(Display *dpy, Colormap colormap)
{
if (colormap == DefaultColormap(dpy, DefaultScreen(dpy)))
return XCopyColormapAndFree(dpy, colormap);
Error("Visual type is not large enough to hold all colors of the image.");
+ /*NOTREACHED*/
+ return (Colormap)0;
}
-Do_Pseudo(dpy, colormap, ncolors, colors, in_image, out_image)
- Display *dpy;
- Colormap *colormap;
- int ncolors;
- XColor *colors;
- register XImage *in_image, *out_image;
+static void
+Do_Pseudo(Display *dpy, Colormap *colormap,
+ int ncolors, XColor *colors, XImage *in_image, XImage *out_image)
{
register int i, x, y;
register XColor *color;
}
}
-Do_Direct(dpy, header, colormap, ncolors, colors, in_image, out_image)
- Display *dpy;
- XWDFileHeader *header;
- Colormap *colormap;
- int ncolors;
- XColor *colors;
- XImage *in_image, *out_image;
+static void
+Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
+ int ncolors, XColor *colors, XImage *in_image, XImage *out_image)
{
register int x, y;
XColor color;
}
}
-unsigned Image_Size(image)
- XImage *image;
+static unsigned int
+Image_Size(XImage *image)
{
if (image->format != ZPixmap)
return(image->bytes_per_line * image->height * image->depth);
return((unsigned)image->bytes_per_line * image->height);
}
-Error(string)
- char *string;
+static void
+Error(char *string)
{
fprintf(stderr, "xwud: Error => %s\n", string);
if (errno != 0) {
exit(1);
}
-_swapshort (bp, n)
- register char *bp;
- register unsigned n;
+static void
+_swapshort(char *bp, unsigned int n)
{
register char c;
register char *ep = bp + n;
}
}
-_swaplong (bp, n)
- register char *bp;
- register unsigned n;
+static void
+_swaplong(char *bp, unsigned int n)
{
register char c;
register char *ep = bp + n;