about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-09 23:07:11 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-09 23:07:11 +0000
commitd113bea623ccd7b95f2672fbd1fcb88b550196a8 (patch)
treef1b198cd966337c439a3eb60e337a85675f5d982
parent756b2745e2bbdbd5b17a7e658669875f2325127b (diff)
downloadnetpbm-mirror-d113bea623ccd7b95f2672fbd1fcb88b550196a8.tar.gz
netpbm-mirror-d113bea623ccd7b95f2672fbd1fcb88b550196a8.tar.xz
netpbm-mirror-d113bea623ccd7b95f2672fbd1fcb88b550196a8.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4741 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/fiasco/binerror.c2
-rw-r--r--converter/other/fiasco/binerror.h8
-rw-r--r--converter/other/fiasco/buttons.c510
-rw-r--r--converter/other/fiasco/buttons.h50
-rw-r--r--converter/other/fiasco/display.c415
-rw-r--r--converter/other/fiasco/display.h49
-rw-r--r--converter/other/fiasco/fiascotopnm.c195
-rw-r--r--converter/other/fiasco/params.c1137
-rw-r--r--converter/other/fiasco/params.h4
9 files changed, 546 insertions, 1824 deletions
diff --git a/converter/other/fiasco/binerror.c b/converter/other/fiasco/binerror.c
index dd40dc9b..7a1ac656 100644
--- a/converter/other/fiasco/binerror.c
+++ b/converter/other/fiasco/binerror.c
@@ -1,5 +1,5 @@
 /*
- *  error.c:            Error handling
+ *  Error handling
  *
  *  Written by:         Stefan Frank
  *                      Ullrich Hafner
diff --git a/converter/other/fiasco/binerror.h b/converter/other/fiasco/binerror.h
index b30f53e0..50532be9 100644
--- a/converter/other/fiasco/binerror.h
+++ b/converter/other/fiasco/binerror.h
@@ -1,5 +1,4 @@
 /*
- *  error.h
  *
  *  Written by:         Stefan Frank
  *                      Ullrich Hafner
@@ -15,8 +14,8 @@
  *  $State: Exp $
  */
 
-#ifndef _ERROR_H
-#define _ERROR_H
+#ifndef BINERROR_H_INCLUDED
+#define BINERROR_H_INCLUDED
 
 #define error          error_line=__LINE__,error_file=__FILE__,_error
 #define warning        error_line=__LINE__,error_file=__FILE__,_warning
@@ -46,5 +45,4 @@ _file_error (const char *filename);
 #       define assert(exp)      {if (!(exp)) error ("Assertion `" #exp " != NULL' failed.");}
 #endif /* not HAVE_ASSERT_H */
 
-#endif /* not _ERROR_H */
-
+#endif
diff --git a/converter/other/fiasco/buttons.c b/converter/other/fiasco/buttons.c
deleted file mode 100644
index 7a6c77a3..00000000
--- a/converter/other/fiasco/buttons.c
+++ /dev/null
@@ -1,510 +0,0 @@
-/*
- *  buttons.c:          Draw MWFA player buttons in X11 window
- *
- *  Written by:         Ullrich Hafner
- *
- *  This file is part of FIASCO (Fractal Image And Sequence COdec)
- *  Copyright (C) 1994-2000 Ullrich Hafner
- */
-
-/*
- *  $Date: 2000/06/15 17:23:11 $
- *  $Author: hafner $
- *  $Revision: 5.2 $
- *  $State: Exp $
- */
-
-#include "config.h"
-
-#ifndef X_DISPLAY_MISSING
-
-#include <X11/Xlib.h>
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-
-#if STDC_HEADERS
-#       include <stdlib.h>
-#endif /* not STDC_HEADERS */
-
-#include "types.h"
-#include "macros.h"
-
-#include "display.h"
-#include "binerror.h"
-#include "buttons.h"
-
-/*****************************************************************************
-
-                             local variables
-
-*****************************************************************************/
-
-static const int EVENT_MASK = (KeyPressMask | ButtonPressMask |
-                               ButtonReleaseMask | ExposureMask);
-
-/*****************************************************************************
-
-                                prototypes
-
-*****************************************************************************/
-
-static void
-draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n,
-                   unsigned n_frames);
-static void
-draw_button (x11_info_t *xinfo, binfo_t *binfo,
-             buttons_t button, bool_t pressed);
-static void
-draw_control_panel (x11_info_t *xinfo, binfo_t *binfo,
-                    unsigned n, unsigned n_frames);
-
-/*****************************************************************************
-
-                                public code
-
-*****************************************************************************/
-
-binfo_t *
-init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames,
-              unsigned buttons_height, unsigned progbar_height)
-/*
- *  Initialize a toolbar with the typical collection of video player
- *  buttons (pause, play, record, next, etc.) in the window given by 'xinfo'.
- *  'n' gives the current frame, 'whereas' n_frames is the total number of
- *  frames of the video stream.
- *  The size of the button toolbar is given by 'buttons_height',
- *  the size of the progressbar is given by 'progbar_height'.
- *
- *  Return value:
- *      struct managing the toolbar and progressbar information
- */
-{
-   XGCValues  values;
-   XEvent     event;
-   Colormap   cmap;
-   XColor     gray, dgray, lgray, red;
-   XColor     graye, dgraye, lgraye, rede;
-   buttons_t  button;                   /* counter */
-   binfo_t   *binfo = calloc (1, sizeof (binfo_t));
-
-   if (!binfo)
-      error ("Out of memory.");
-
-   binfo->width            = xinfo->ximage->width;
-   binfo->height           = buttons_height;
-   binfo->progbar_height   = progbar_height;
-   binfo->record_is_rewind = NO;
-
-   /*
-    *  Generate sub-window for control panel
-    */
-   binfo->window = XCreateSimpleWindow (xinfo->display, xinfo->window,
-                                        0, xinfo->ximage->height,
-                                        binfo->width, binfo->height, 0,
-                                        BlackPixel (xinfo->display,
-                                                    xinfo->screen),
-                                        WhitePixel (xinfo->display,
-                                                    xinfo->screen));
-   XSelectInput(xinfo->display, binfo->window, StructureNotifyMask);
-   XMapWindow (xinfo->display, binfo->window);
-   do
-   {
-      XNextEvent (xinfo->display, &event);
-   }
-   while (event.type != MapNotify || event.xmap.event != binfo->window);
-   XSelectInput (xinfo->display, binfo->window, EVENT_MASK);
-
-   /*
-    *  Generate graphic contexts for different colors.
-    */
-   cmap = DefaultColormap (xinfo->display, xinfo->screen);
-   XAllocNamedColor (xinfo->display, cmap, "#404040", &dgray, &dgraye);
-   XAllocNamedColor (xinfo->display, cmap, "white", &lgray, &lgraye);
-   XAllocNamedColor (xinfo->display, cmap, "#a8a8a8", &gray, &graye);
-   XAllocNamedColor (xinfo->display, cmap, "red", &red, &rede);
-
-   values.foreground = BlackPixel (xinfo->display, xinfo->screen);
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   binfo->gc [BLACK] = XCreateGC (xinfo->display,
-                                  RootWindow (xinfo->display, xinfo->screen),
-                                  (GCForeground | GCBackground), &values);
-   values.foreground = BlackPixel (xinfo->display, xinfo->screen);
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   values.line_width = 3;
-   values.join_style = JoinRound;
-   binfo->gc [THICKBLACK] = XCreateGC (xinfo->display,
-                                       RootWindow (xinfo->display,
-                                                   xinfo->screen),
-                                       (GCForeground | GCBackground
-                                        | GCLineWidth | GCJoinStyle), &values);
-   values.foreground = gray.pixel;
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   binfo->gc [NGRAY] = XCreateGC (xinfo->display,
-                                  RootWindow (xinfo->display, xinfo->screen),
-                                  (GCForeground | GCBackground), &values);
-   values.foreground = lgray.pixel;
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   binfo->gc [LGRAY] = XCreateGC (xinfo->display,
-                                  RootWindow (xinfo->display, xinfo->screen),
-                                  (GCForeground | GCBackground), &values);
-   values.foreground = dgray.pixel;
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   binfo->gc [DGRAY] = XCreateGC (xinfo->display,
-                                  RootWindow (xinfo->display, xinfo->screen),
-                                  (GCForeground | GCBackground), &values);
-   values.foreground = red.pixel;
-   values.background = WhitePixel (xinfo->display, xinfo->screen);
-   binfo->gc [RED]   = XCreateGC (xinfo->display,
-                                  RootWindow (xinfo->display, xinfo->screen),
-                                  (GCForeground | GCBackground), &values);
-
-   for (button = 0; button < NO_BUTTON; button++)
-      binfo->pressed [button] = NO;
-
-   draw_control_panel (xinfo, binfo, n, n_frames);
-
-   return binfo;
-}
-
-void
-wait_for_input (x11_info_t *xinfo)
-/*
- *  Wait for key press or mouse click in window 'xinfo'.
- *  Redraw 'image' if event other then ButtonPress or KeyPress occurs.
- *  Enlarge or reduce size of image by factor 2^'enlarge_factor'.
- *
- *  No return value.
- *
- *  Side effect:
- *      program is terminated after key press or mouse click.
- */
-{
-   bool_t leave_loop = NO;
-
-   XSelectInput (xinfo->display, xinfo->window, EVENT_MASK);
-
-   while (!leave_loop)
-   {
-      XEvent event;
-
-      XMaskEvent (xinfo->display, EVENT_MASK, &event);
-      switch (event.type)
-      {
-         case ButtonPress:
-         case KeyPress:
-            leave_loop = YES;
-            break;
-         default:
-            display_image (0, 0, xinfo);
-            break;
-      }
-   }
-}
-
-void
-check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames)
-/*
- *  Check the X11 event loop. If the PAUSE buttonin the of panel 'binfo'
- *  is activated wait until next event occurs.
- *  Redraw 'image' if event other then ButtonPress or ButtonRelease occurs.
- *  Enlarge or reduce size of image by factor 2^'enlarge_factor'.
- *  'n' gives the current frame, 'whereas' n_frames is the total number of
- *  frames of the video stream.
- *
- *  No return values.
- *
- *  Side effects:
- *      status of buttons (binfo->pressed [button]) is changed accordingly.
- */
-{
-   bool_t leave_eventloop;
-
-   leave_eventloop = (!binfo->pressed [PAUSE_BUTTON]
-                      && binfo->pressed [PLAY_BUTTON])
-                     || (!binfo->pressed [PAUSE_BUTTON]
-                         && binfo->record_is_rewind
-                         && binfo->pressed [RECORD_BUTTON])
-                     || binfo->pressed [RECORD_BUTTON];
-   draw_progress_bar (xinfo, binfo, n, n_frames);
-
-   if (binfo->pressed [PAUSE_BUTTON] && binfo->pressed [PLAY_BUTTON])
-   {
-      XFlush (xinfo->display);
-      draw_button (xinfo, binfo, PLAY_BUTTON, NO); /* clear PLAY mode */
-      XFlush (xinfo->display);
-   }
-   if (binfo->pressed [PAUSE_BUTTON]
-       && binfo->record_is_rewind && binfo->pressed [RECORD_BUTTON])
-   {
-      XFlush (xinfo->display);
-      draw_button (xinfo, binfo, RECORD_BUTTON, NO); /* clear PLAY mode */
-      XFlush (xinfo->display);
-   }
-
-   if (binfo->pressed [STOP_BUTTON])
-   {
-      XFlush (xinfo->display);
-      draw_button (xinfo, binfo, STOP_BUTTON, NO); /* clear STOP button */
-      XFlush (xinfo->display);
-   }
-
-   do
-   {
-      XEvent event;
-      int    button;
-      bool_t wait_release = NO;
-
-
-      if (XCheckMaskEvent (xinfo->display, EVENT_MASK, &event))
-      {
-         switch (event.type)
-         {
-            case ButtonPress:
-               wait_release = NO;
-               if (!(binfo->pressed [RECORD_BUTTON] &&
-                     !binfo->record_is_rewind))
-                  for (button = 0; button < NO_BUTTON; button++)
-                  {
-                     int x0, y0, x1, y1; /* button coordinates */
-
-                     x0 = button * (binfo->width / NO_BUTTON);
-                     y0 = binfo->progbar_height;
-                     x1 = x0 + binfo->width / NO_BUTTON;
-                     y1 = y0 + binfo->height - binfo->progbar_height - 1;
-                     if (event.xbutton.x > x0 && event.xbutton.x < x1
-                         && event.xbutton.y > y0 && event.xbutton.y < y1)
-                     {
-                        draw_button (xinfo, binfo, button,
-                                     !binfo->pressed [button]);
-                        wait_release = YES;
-                        break;
-                     }
-                  }
-               break;
-            case ButtonRelease:
-               wait_release = NO;
-               break;
-            default:
-               wait_release = NO;
-               draw_control_panel (xinfo, binfo, n, n_frames);
-               display_image (0, 0, xinfo);
-               break;
-         }
-         leave_eventloop = !wait_release
-                           && (binfo->pressed [PLAY_BUTTON]
-                               || binfo->pressed [STOP_BUTTON]
-                               || binfo->pressed [RECORD_BUTTON]
-                               || binfo->pressed [QUIT_BUTTON]);
-      }
-   } while (!leave_eventloop);
-
-   if ((binfo->pressed [RECORD_BUTTON] && !binfo->record_is_rewind)
-       && n == n_frames - 1)
-   {
-      binfo->record_is_rewind = YES;
-      draw_button (xinfo, binfo, RECORD_BUTTON, NO);
-   }
-}
-
-/*****************************************************************************
-
-                                private code
-
-*****************************************************************************/
-
-static void
-draw_control_panel (x11_info_t *xinfo, binfo_t *binfo,
-                    unsigned n, unsigned n_frames)
-/*
- *  Draw control panel 'binfo' with all buttons and progressbar in
- *  the given 'window'.
- *  'n' gives the current frame, 'whereas' n_frames is the total number of
- *  frames of the video stream.
- *
- *  No return value.
- */
-{
-   buttons_t button;
-
-   XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY],
-                   0, 0, binfo->width, binfo->height);
-   draw_progress_bar (xinfo, binfo, n, n_frames);
-   for (button = 0; button < NO_BUTTON; button++)
-      draw_button (xinfo, binfo, button, binfo->pressed [button]);
-}
-
-static void
-draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n,
-                   unsigned n_frames)
-/*
- *  Draw progressbar of control panel 'binfo' in the given 'window'.
- *  'n' gives the current frame, whereas 'n_frames' is the total number of
- *  frames of the video stream.
- *
- *  No return value.
- */
-{
-   unsigned x, y, width, height;
-
-   x      = 2;
-   y      = 1;
-   width  = binfo->width - 5;
-   height = binfo->progbar_height - 3;
-
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY],
-              x, y, x + width, y);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY],
-              x, y, x, y + height - 1);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY],
-              x + width, y + 1, x + width, y + height);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY],
-              x, y + height, x + width, y + height);
-
-   x++; y++; width  -= 2; height -= 2;
-   XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY],
-                   x, y, width, height);
-
-   XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK],
-                   x + n * max (1, width / n_frames), y,
-                   max (1, width / n_frames), height);
-}
-
-static void
-draw_button (x11_info_t *xinfo, binfo_t *binfo,
-             buttons_t button, bool_t pressed)
-/*
- *  Draw 'button' of control panel 'binfo' in the given 'window'.
- *  'pressed' indicates whether the button is pressed or not.
- *
- *  No return value.
- */
-{
-   grayscale_t top, bottom;             /* index of GC */
-   unsigned    x, y, width, height;     /* coordinates of button */
-
-   x      = button * (binfo->width / NO_BUTTON);
-   y      = binfo->progbar_height;
-   width  = binfo->width / NO_BUTTON;
-   height = binfo->height - binfo->progbar_height - 1;
-
-   if (width < 4 || height < 4)
-      return;
-
-   if (pressed)
-   {
-      top    = DGRAY;
-      bottom = LGRAY;
-   }
-   else
-   {
-      top    = LGRAY;
-      bottom = DGRAY;
-   }
-
-   x     += 2;
-   width -= 4;
-
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [top],
-              x, y, x + width, y);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [top],
-              x, y, x, y + height - 1);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom],
-              x + width, y + 1, x + width, y + height);
-   XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom],
-              x, y + height, x + width, y + height);
-
-   x++; y++; width  -= 2; height -= 2;
-   XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY],
-                   x, y, width, height);
-
-   switch (button)
-   {
-      case STOP_BUTTON:
-         XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK],
-                         x + width / 2 - 6, y + height / 2 - 4, 11, 11);
-         if (pressed && !binfo->pressed [STOP_BUTTON])
-         {
-            draw_button (xinfo, binfo, PLAY_BUTTON, NO);
-            draw_button (xinfo, binfo, PAUSE_BUTTON, NO);
-            draw_button (xinfo, binfo, RECORD_BUTTON, NO);
-         }
-         break;
-      case PAUSE_BUTTON:
-         XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK],
-                         x + width / 2 - 6, y + height / 2 - 4, 5, 11);
-         XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK],
-                         x + width / 2 + 1, y + height / 2 - 4, 5, 11);
-         break;
-      case PLAY_BUTTON:
-         {
-            XPoint triangle [3];
-
-            triangle [0].x = x + width / 2 - 5;
-            triangle [0].y = y + height / 2 - 5;
-            triangle [1].x = 10;
-            triangle [1].y = 6;
-            triangle [2].x = -10;
-            triangle [2].y = 6;
-
-            XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK],
-                          triangle, 3, Convex, CoordModePrevious);
-            if (pressed && !binfo->pressed [PLAY_BUTTON]
-                && binfo->pressed [RECORD_BUTTON])
-               draw_button (xinfo, binfo, RECORD_BUTTON, NO);
-         }
-         break;
-      case RECORD_BUTTON:
-         if (!binfo->record_is_rewind)
-         {
-            XFillArc (xinfo->display, binfo->window, binfo->gc [RED],
-                      x + width / 2 - 5, y + height / 2 - 5, 11, 11, 0,
-                      360 * 64);
-            if (pressed && !binfo->pressed [RECORD_BUTTON])
-            {
-               draw_button (xinfo, binfo, STOP_BUTTON, YES);
-               draw_button (xinfo, binfo, PLAY_BUTTON, NO);
-               draw_button (xinfo, binfo, PAUSE_BUTTON, NO);
-            }
-         }
-         else
-         {
-            XPoint triangle [3];
-
-            triangle [0].x = x + width / 2 + 5;
-            triangle [0].y = y + height / 2 - 5;
-            triangle [1].x = -10;
-            triangle [1].y = 6;
-            triangle [2].x = 10;
-            triangle [2].y = 6;
-
-            XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK],
-                          triangle, 3, Convex, CoordModePrevious);
-            if (pressed && !binfo->pressed [RECORD_BUTTON]
-                && binfo->pressed [PLAY_BUTTON])
-               draw_button (xinfo, binfo, PLAY_BUTTON, NO);
-         }
-         break;
-      case QUIT_BUTTON:
-         {
-            XPoint triangle [3];
-
-            triangle [0].x = x + width / 2 - 6;
-            triangle [0].y = y + height / 2 + 2;
-            triangle [1].x = 6;
-            triangle [1].y = -7;
-            triangle [2].x = 6;
-            triangle [2].y = 7;
-
-            XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK],
-                          triangle, 3, Convex, CoordModePrevious);
-            XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK],
-                            x + width / 2 - 5, y + height / 2 + 4, 11, 3);
-         }
-         break;
-      default:
-         break;
-   }
-   binfo->pressed [button] = pressed;
-}
-
-#endif /* not X_DISPLAY_MISSING */
diff --git a/converter/other/fiasco/buttons.h b/converter/other/fiasco/buttons.h
deleted file mode 100644
index 19c4935e..00000000
--- a/converter/other/fiasco/buttons.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *  buttons.h
- *
- *  Written by:         Ullrich Hafner
- *
- *  This file is part of FIASCO (Fractal Image And Sequence COdec)
- *  Copyright (C) 1994-2000 Ullrich Hafner
- */
-
-/*
- *  $Date: 2000/06/14 20:51:17 $
- *  $Author: hafner $
- *  $Revision: 5.1 $
- *  $State: Exp $
- */
-
-#ifndef _BUTTONS_H
-#define _BUTTONS_H
-
-#ifndef X_DISPLAY_MISSING
-
-typedef enum grayscale_e {BLACK, NGRAY, LGRAY, DGRAY, RED,
-                          THICKBLACK, NO_GC} grayscale_t;
-typedef enum buttons_e {STOP_BUTTON, PLAY_BUTTON, PAUSE_BUTTON, RECORD_BUTTON,
-                        QUIT_BUTTON, NO_BUTTON} buttons_t;
-
-typedef struct buttoninfo
-{
-   Window   window;
-   bool_t   pressed [NO_BUTTON];
-   GC       gc [NO_GC];
-   unsigned width;
-   unsigned height;
-   unsigned progbar_height;
-   bool_t   record_is_rewind;
-} binfo_t;
-
-void
-check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n,
-              unsigned n_frames);
-void
-wait_for_input (x11_info_t *xinfo);
-binfo_t *
-init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames,
-              unsigned buttons_height, unsigned progbar_height);
-
-#endif /* not X_DISPLAY_MISSING */
-
-#endif /* not _BUTTONS_H */
-
diff --git a/converter/other/fiasco/display.c b/converter/other/fiasco/display.c
deleted file mode 100644
index 5eed6aeb..00000000
--- a/converter/other/fiasco/display.c
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- *  display.c:          X11 display of frames
- *
- *  Written by:         Ullrich Hafner
- *
- *  This file is part of FIASCO (Fractal Image And Sequence COdec)
- *  Copyright (C) 1994-2000 Ullrich Hafner
- *
- *  Based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
- *  and      mpeg2play,   (C) 1994 Stefan Eckart
- *                                 <stefan@lis.e-technik.tu-muenchen.de>
- *  and      tmndec       (C) 1995, 1996  Telenor R&D, Norway
- */
-
-/*
- *  $Date: 2000/07/03 19:35:59 $
- *  $Author: hafner $
- *  $Revision: 5.2 $
- *  $State: Exp $
- */
-
-#include "config.h"
-
-#ifndef X_DISPLAY_MISSING
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "types.h"
-#include "macros.h"
-#include "display.h"
-#include "binerror.h"
-
-/*****************************************************************************
-
-               shared memory functions (if USE_SHM is defined)
-
-*****************************************************************************/
-
-#ifdef USE_SHM
-
-#ifdef HAVE_FEATURES_H
-#include <features.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <X11/extensions/XShm.h>
-
-int
-XShmQueryExtension (Display *dpy);
-int
-XShmGetEventBase (Display *dpy);
-
-static int
-HandleXError (Display *dpy, XErrorEvent *event);
-static void
-InstallXErrorHandler (x11_info_t *xinfo);
-static void
-DeInstallXErrorHandler (x11_info_t *xinfo);
-
-static int              shmem_flag;
-static XShmSegmentInfo  shminfo1, shminfo2;
-static int              gXErrorFlag;
-static int              CompletionType = -1;
-
-static int
-HandleXError (Display *dpy, XErrorEvent *event)
-{
-   gXErrorFlag = 1;
-
-   return 0;
-}
-
-static void
-InstallXErrorHandler (x11_info_t *xinfo)
-{
-   XSetErrorHandler (HandleXError);
-   XFlush (xinfo->display);
-}
-
-static void
-DeInstallXErrorHandler (x11_info_t *xinfo)
-{
-   XSetErrorHandler (NULL);
-   XFlush (xinfo->display);
-}
-
-#endif /* USE_SHM */
-
-/*****************************************************************************
-
-                                public code
-
-*****************************************************************************/
-
-void
-display_image (unsigned x0, unsigned y0, x11_info_t *xinfo)
-/*
- *  Display 'image' at pos ('x0', 'y0') in the current window
- *  (given by 'xinfo->window').
- *
- *  No return value.
- */
-{
-   int byte_order_check = 1;
-
-   /*
-    *  Always work in native bit and byte order. This tells Xlib to
-    *  reverse bit and byte order if necessary when crossing a
-    *  network. Frankly, this part of XImages is somewhat
-    *  underdocumented, so this may not be exactly correct.
-    */
-   if (*(char *) & byte_order_check == 1)
-   {
-      xinfo->ximage->byte_order       = LSBFirst;
-      xinfo->ximage->bitmap_bit_order = LSBFirst;
-   }
-   else
-   {
-      xinfo->ximage->byte_order       = MSBFirst;
-      xinfo->ximage->bitmap_bit_order = MSBFirst;
-   }
-
-   /* Display dithered image */
-#ifdef USE_SHM
-   if (shmem_flag)
-   {
-      XEvent xev;
-
-      XShmPutImage (xinfo->display, xinfo->window, xinfo->gc, xinfo->ximage,
-                    0, 0, x0, y0, xinfo->ximage->width, xinfo->ximage->height,
-                    True);
-      XFlush (xinfo->display);
-
-      while (!XCheckTypedEvent (xinfo->display, CompletionType, &xev))
-         ;
-   }
-   else
-#endif /* USE_SHM */
-   {
-      xinfo->ximage->data = (char *) xinfo->pixels;
-      XPutImage (xinfo->display, xinfo->window, xinfo->gc, xinfo->ximage, 0, 0,
-                 x0, y0, xinfo->ximage->width, xinfo->ximage->height);
-   }
-}
-
-void
-close_window (x11_info_t *xinfo)
-{
-#ifdef USE_SHM
-   if (shmem_flag && xinfo->ximage)
-   {
-      XShmDetach (xinfo->display, &shminfo1);
-      XDestroyImage (xinfo->ximage);
-      xinfo->ximage = NULL;
-      shmdt (shminfo1.shmaddr);
-   }
-   else
-#endif /* USE_SHM */
-   if (xinfo->ximage)
-   {
-      XDestroyImage (xinfo->ximage);
-      xinfo->ximage = NULL;
-   }
-   if (xinfo->display)
-   {
-      XCloseDisplay (xinfo->display);
-      xinfo->display = NULL;
-   }
-}
-
-x11_info_t *
-open_window (const char *titlename, const char *iconname,
-             unsigned width, unsigned height)
-/*
- *  Open a X11 window of size 'width'x'height'.
- *  If 'color' is false then allocate a colormap with grayscales.
- *  Window and icon titles are given by 'titlename' and 'iconname',
- *  respectively.
- *
- *  Return value:
- *      X11 info struct containing display, gc, window ID and colormap.
- */
-{
-   XVisualInfo          visual_template; /* template for XGetVisualInfo() */
-   XVisualInfo          visual_info;    /* return value of XGetVisualInfo() */
-   int                  visual_n;       /* # of matches of XGetVisualInfo */
-   XEvent               xev;
-   XSizeHints           hint;
-   XSetWindowAttributes xswa;
-   unsigned int         fg, bg;         /* foreground and background color */
-   unsigned int         mask;           /* event mask */
-   x11_info_t           *xinfo = calloc (1, sizeof (x11_info_t));
-   long                 visual_mask;
-
-   if (!xinfo)
-      error ("Out of memory");
-   /*
-    *  Initialization of display
-    */
-   xinfo->display = XOpenDisplay (NULL);
-   if (xinfo->display == NULL)
-      error ("Can't open display.\n"
-             "Make sure that your environment variable DISPLAY "
-             "is set correctly.");
-
-   xinfo->screen = DefaultScreen (xinfo->display);
-   xinfo->gc     = DefaultGC (xinfo->display, xinfo->screen);
-
-   {
-      unsigned   depth []       = {32, 24, 16};
-      int        class []       = {TrueColor, PseudoColor};
-      const char *class_text [] = {"TrueColor", "PseudoColor"};
-      Status     found          = 0;
-      unsigned   d, c;
-
-      for (d = 0; !found && d < sizeof (depth) / sizeof (unsigned); d++)
-         for (c = 0; !found && c < sizeof (class) / sizeof (int); c++)
-         {
-            found = XMatchVisualInfo (xinfo->display, xinfo->screen,
-                                      depth [d], class [c], &visual_info);
-            if (found)
-               fprintf (stderr, "%s : %d bit colordepth.\n",
-                        class_text [c], depth [d]);
-         }
-      if (!found && fiasco_get_verbosity ())
-         error ("Can't find a 16/24/32 bit TrueColor/DirectColor display");
-   }
-
-   /* Width and height of the display window */
-   hint.x = hint.y = 0;
-   hint.min_width  = hint.max_width  = hint.width  = width;
-   hint.min_height = hint.max_height = hint.height = height;
-   hint.flags = PSize | PMinSize | PMaxSize;
-
-   /* Get some colors */
-   bg = WhitePixel (xinfo->display, xinfo->screen);
-   fg = BlackPixel (xinfo->display, xinfo->screen);
-
-   /* Make the window */
-   mask = CWBackPixel | CWBorderPixel;
-   if (visual_info.depth >= 16)
-   {
-      mask |= CWColormap;
-      xswa.colormap = XCreateColormap (xinfo->display,
-                                       DefaultRootWindow (xinfo->display),
-                                       visual_info.visual, AllocNone);
-   }
-   xswa.background_pixel = bg;
-   xswa.border_pixel     = fg;
-   xinfo->window = XCreateWindow (xinfo->display,
-                                  DefaultRootWindow (xinfo->display), 0, 0,
-                                  width, height, 1, visual_info.depth,
-                                  InputOutput, visual_info.visual,
-                                  mask, &xswa);
-
-   XSelectInput (xinfo->display, xinfo->window, StructureNotifyMask);
-
-   /* Tell other applications about this window */
-   XSetStandardProperties (xinfo->display, xinfo->window, titlename, iconname,
-                           None, NULL, 0, &hint);
-
-   /* Map window. */
-   XMapWindow (xinfo->display, xinfo->window);
-
-   /* Wait for map. */
-   do
-   {
-      XNextEvent (xinfo->display, &xev);
-   }
-   while (xev.type != MapNotify || xev.xmap.event != xinfo->window);
-
-   /* Allocate colors */
-
-   return xinfo;
-}
-
-void
-alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height)
-/*
- *  Allocate ximage of size 'width'x'height'.
- *  If USE_SHM is defined then use shared memory extensions.
- *
- *  No return value.
- *
- *  Side effects:
- *      'ximage->ximage' and 'ximage->pixels' are set to useful values.
- */
-{
-   char dummy;
-
-#ifdef USE_SHM
-   if (XShmQueryExtension(xinfo->display))
-   {
-      if (fiasco_get_verbosity ())
-         fprintf (stderr, "Trying shared memory.\n");
-      shmem_flag = 1;
-   }
-   else
-   {
-      shmem_flag = 0;
-      if (fiasco_get_verbosity ())
-         fprintf (stderr,
-              "Shared memory does not work on this system\n"
-              "Reverting to normal Xlib.\n");
-   }
-
-   if (shmem_flag)
-      CompletionType = XShmGetEventBase (xinfo->display) + ShmCompletion;
-
-   InstallXErrorHandler (xinfo);
-
-   if (shmem_flag)
-   {
-      xinfo->ximage = XShmCreateImage (xinfo->display,
-                                       DefaultVisual (xinfo->display,
-                                                      xinfo->screen),
-                                       DefaultDepth (xinfo->display,
-                                                     xinfo->screen), ZPixmap,
-                                       NULL, &shminfo1, width, height);
-
-      /* If no go, then revert to normal Xlib calls. */
-
-      if (xinfo->ximage == NULL)
-      {
-         if (fiasco_get_verbosity ())
-            fprintf (stderr,
-                     "Shared memory error, disabling (Ximage error).\n");
-         goto shmemerror;
-      }
-
-      /* Success here, continue. */
-
-      shminfo1.shmid = shmget (IPC_PRIVATE, xinfo->ximage->bytes_per_line
-                               * xinfo->ximage->height, IPC_CREAT | 0777);
-
-      if (shminfo1.shmid < 0)
-      {
-         XDestroyImage (xinfo->ximage);
-         if (fiasco_get_verbosity ())
-            fprintf (stderr,
-                     "Shared memory error, disabling (seg id error).\n");
-         goto shmemerror;
-      }
-
-      shminfo1.shmaddr = (char *) shmat (shminfo1.shmid, 0, 0);
-      shminfo2.shmaddr = (char *) shmat (shminfo2.shmid, 0, 0);
-
-      if (shminfo1.shmaddr == ((char *) -1))
-      {
-         XDestroyImage (xinfo->ximage);
-         if (shminfo1.shmaddr != ((char *) -1))
-            shmdt (shminfo1.shmaddr);
-         if (fiasco_get_verbosity ())
-            fprintf (stderr,
-                     "Shared memory error, disabling (address error).\n");
-         goto shmemerror;
-      }
-
-      xinfo->ximage->data = shminfo1.shmaddr;
-      xinfo->pixels       = (byte_t *) xinfo->ximage->data;
-      shminfo1.readOnly   = False;
-
-      XShmAttach (xinfo->display, &shminfo1);
-      XSync (xinfo->display, False);
-
-      if (gXErrorFlag)
-      {
-         /* Ultimate failure here. */
-         XDestroyImage (xinfo->ximage);
-         shmdt (shminfo1.shmaddr);
-         if (fiasco_get_verbosity ())
-            fprintf (stderr, "Shared memory error, disabling.\n");
-         gXErrorFlag = 0;
-         goto shmemerror;
-      }
-      else
-         shmctl (shminfo1.shmid, IPC_RMID, 0);
-      if (fiasco_get_verbosity ())
-         fprintf (stderr, "Sharing memory.\n");
-   }
-   else
-   {
-     shmemerror:
-      shmem_flag = 0;
-#endif /* USE_SHM */
-
-      xinfo->ximage = XCreateImage (xinfo->display,
-                                    DefaultVisual (xinfo->display,
-                                                   xinfo->screen),
-                                    DefaultDepth (xinfo->display,
-                                                  xinfo->screen),
-                                    ZPixmap, 0, &dummy, width, height, 8, 0);
-      xinfo->pixels = calloc (width * height,
-                              xinfo->ximage->depth <= 8
-                              ? sizeof (byte_t)
-                              : (xinfo->ximage->depth <= 16
-                                 ? sizeof (u_word_t) : sizeof (unsigned int)));
-      if (!xinfo->pixels)
-         error ("Out of memory.");
-
-#ifdef USE_SHM
-   }
-
-   DeInstallXErrorHandler (xinfo);
-#endif /* USE_SHM */
-}
-
-#endif /* not X_DISPLAY_MISSING */
diff --git a/converter/other/fiasco/display.h b/converter/other/fiasco/display.h
deleted file mode 100644
index 0f9c53dc..00000000
--- a/converter/other/fiasco/display.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  display.h
- *
- *  Written by:         Ullrich Hafner
- *              
- *  This file is part of FIASCO (Fractal Image And Sequence COdec)
- *  Copyright (C) 1994-2000 Ullrich Hafner
- */
-
-/*
- *  $Date: 2000/06/14 20:51:17 $
- *  $Author: hafner $
- *  $Revision: 5.1 $
- *  $State: Exp $
- */
-
-#ifndef _DISPLAY_H
-#define _DISPLAY_H
-
-#ifndef X_DISPLAY_MISSING
-
-#include <X11/Xlib.h>
-
-#include "types.h"
-#include "image.h"
-
-typedef struct x11_info
-{
-   Display *display;
-   int      screen;                     /* default screen number */
-   Window   window;                     
-   XImage  *ximage;
-   GC       gc;
-   byte_t  *pixels;
-} x11_info_t;
-
-void
-display_image (unsigned x0, unsigned y0, x11_info_t *xinfo);
-void
-close_window (x11_info_t *xinfo);
-x11_info_t *
-open_window (const char *titlename, const char *iconname,
-             unsigned width, unsigned height);
-void
-alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height);
-
-#endif /* X_DISPLAY_MISSING */
-
-#endif /* not _DISPLAY_H */
diff --git a/converter/other/fiasco/fiascotopnm.c b/converter/other/fiasco/fiascotopnm.c
index c97e201b..eb3c1994 100644
--- a/converter/other/fiasco/fiascotopnm.c
+++ b/converter/other/fiasco/fiascotopnm.c
@@ -38,14 +38,6 @@
 #include "params.h"
 #include "fiasco.h"
 
-#ifndef X_DISPLAY_MISSING
-
-#   include "display.h"
-#   include "buttons.h"
-
-static x11_info_t *xinfo = NULL;
-
-#endif /* not X_DISPLAY_MISSING */
 
 /*****************************************************************************
 
@@ -63,15 +55,6 @@ static void
 get_output_template (const char *image_name, const char *wfa_name,
                      bool_t color, char **basename, char **suffix);
 
-#ifndef X_DISPLAY_MISSING
-
-static void
-show_stored_frames (unsigned char * const *frame_buffer, int last_frame,
-                    x11_info_t *xinfo, binfo_t *binfo, size_t size,
-                    unsigned frame_time);
-
-#endif /* not X_DISPLAY_MISSING */
-
 /*****************************************************************************
 
                 public code
@@ -111,13 +94,8 @@ main (int argc, char **argv)
 
 static param_t params [] =
 {
-#ifdef X_DISPLAY_MISSING
     {"output", "FILE", 'o', PSTR, {0}, "-",
      "Write raw PNM frame(s) to `%s'."},
-#else  /* not X_DISPLAY_MISSING */
-    {"output", "FILE", 'o', POSTR, {0}, NULL,
-     "Write raw PNM frame(s) to INPUT.ppm/pgm [or `%s']."},
-#endif /* not X_DISPLAY_MISSING */
     {"double", NULL, 'd', PFLAG, {0}, "FALSE",
      "Interpolate images to double size before display."},
     {"fast", NULL, 'r', PFLAG, {0}, "FALSE",
@@ -150,17 +128,9 @@ checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel,
     int optind;              /* last processed commandline param */
 
     optind = parseargs (params, argc, argv,
-#ifdef X_DISPLAY_MISSING
                         "Decode FIASCO-FILEs and write frame(s) to disk.",
-#else  /* not X_DISPLAY_MISSING */
-                        "Decode and display FIASCO-FILEs using X11.",
-#endif /* not X_DISPLAY_MISSING */
                         "With no FIASCO-FILE, or if FIASCO-FILE is -, "
                         "read standard input.\n"
-#ifndef X_DISPLAY_MISSING
-                        "With --output=[FILE] specified, "
-                        "write frames without displaying them.\n\n"
-#endif  /* not X_DISPLAY_MISSING */
                         "Environment:\n"
                         "FIASCO_DATA   Search path for automata files. "
                         "Default: ./\n"
@@ -206,12 +176,6 @@ static void
 video_decoder (const char *wfa_name, const char *image_name, bool_t panel,
                bool_t double_resolution, int fps, fiasco_d_options_t *options)
 {
-#ifndef X_DISPLAY_MISSING
-    fiasco_renderer_t  *renderer     = NULL;
-    unsigned char     **frame_buffer = NULL;
-    binfo_t            *binfo        = NULL; /* buttons info */
-#endif /* not X_DISPLAY_MISSING */
-
     do
     {
         unsigned      width, height, frames, n;
@@ -273,123 +237,12 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel,
                 if (!fiasco_decoder_write_frame (decoder_state, filename))
                     error (fiasco_get_error_message ());
             }
-#ifndef X_DISPLAY_MISSING
-            else
-            {
-                fiasco_image_t *frame;
-
-                if (!(frame = fiasco_decoder_get_frame (decoder_state)))
-                    error (fiasco_get_error_message ());
-
-                if (frames == 1)
-                    panel = NO;
-
-                if (xinfo == NULL)      /* initialize X11 window */
-                {
-                    const char * const title =
-                        fiasco_decoder_get_title (decoder_state);
-                    char        titlename [MAXSTRLEN];
-
-
-                    sprintf (titlename, "dfiasco " VERSION ": %s",
-                             strlen (title) > 0 ? title : wfa_name);
-                    xinfo =
-                        open_window (titlename, "dfiasco",
-                                     (width  << (double_resolution ? 1 : 0)),
-                                     (height << (double_resolution ? 1 : 0))
-                                     + (panel ? 30 : 0));
-                    alloc_ximage (xinfo, width  << (double_resolution ? 1 : 0),
-                                  height << (double_resolution ? 1 : 0));
-                    if (panel)       /* initialize button panel */
-                        binfo = init_buttons (xinfo, n, frames, 30, 10);
-                    renderer =
-                        fiasco_renderer_new (xinfo->ximage->red_mask,
-                                             xinfo->ximage->green_mask,
-                                             xinfo->ximage->blue_mask,
-                                             xinfo->ximage->bits_per_pixel,
-                                             double_resolution);
-                    if (!renderer)
-                        error (fiasco_get_error_message ());
-                }
-                renderer->render (renderer, xinfo->pixels, frame);
-                frame->delete (frame);
-
-                if (frame_buffer != NULL) /* store next frame */
-                {
-                    size_t size = (width  << (double_resolution ? 1 : 0))
-                        * (height << (double_resolution ? 1 : 0))
-                        * (xinfo->ximage->depth <= 8
-                           ? sizeof (byte_t)
-                           : (xinfo->ximage->depth <= 16
-                              ? sizeof (u_word_t)
-                              : sizeof (unsigned int)));
-
-                    frame_buffer [n] = malloc (size);
-                    if (!frame_buffer [n])
-                        error ("Out of memory.");
-                    memcpy (frame_buffer [n], xinfo->pixels, size);
-
-                    if (n == frames - 1)
-                    {
-                        show_stored_frames (frame_buffer, frames - 1,
-                                            xinfo, binfo, size, frame_time);
-                        break;
-                    }
-                }
-
-                display_image (0, 0, xinfo);
-                if (frames == 1)
-                    wait_for_input (xinfo);
-                else if (panel)
-                {
-                    check_events (xinfo, binfo, n, frames);
-                    if (binfo->pressed [QUIT_BUTTON])
-                        /* start from beginning */
-                        break;
-                    if (binfo->pressed [STOP_BUTTON])
-                        /* start from beginning */
-                        n = frames;
-
-                    if (binfo->pressed [RECORD_BUTTON] && frame_buffer == NULL)
-                    {
-                        n = frames;
-                        frame_buffer =
-                            calloc (frames, sizeof (unsigned char *));
-                        if (!frame_buffer)
-                            error ("Out of memory.");
-                    }
-                }
-                while (prg_timer (&fps_timer, STOP) < frame_time) /* wait */
-                    ;
-            }
-#else
             if (frame_time) {/* defeat compiler warning */}
-#endif /* not X_DISPLAY_MISSING */
         }
         free (filename);
 
         fiasco_decoder_delete (decoder_state);
-    } while (panel
-
-#ifndef X_DISPLAY_MISSING
-             && !binfo->pressed [QUIT_BUTTON]
-#endif /* not X_DISPLAY_MISSING */
-
-        );
-
-#ifndef X_DISPLAY_MISSING
-    if (renderer)
-        renderer->delete (renderer);
-
-    if (!image_name)
-    {
-        close_window (xinfo);
-        free (xinfo);
-        xinfo = NULL;
-        if (binfo)
-            free (binfo);
-    }
-#endif /* not X_DISPLAY_MISSING */
+    } while (panel);
 }
 
 static void
@@ -434,49 +287,3 @@ get_output_template (const char *image_name, const char *wfa_name,
         *suffix = strdup (color ? "ppm" : "pgm");
 }
 
-#ifndef X_DISPLAY_MISSING
-
-static void
-show_stored_frames (unsigned char * const *frame_buffer, int last_frame,
-                    x11_info_t *xinfo, binfo_t *binfo, size_t size,
-                    unsigned frame_time)
-/*
- *  After a WFA video stream has been saved, all frames have been
- *  decoded and stored in memory. These frames are then displayed
- *  in an endless loop.
- *
- *  This function never returns, the program is terminated if the
- *  STOP button is pressed.
- */
-{
-    int n = last_frame;          /* frame number */
-
-    while (1)
-    {
-        clock_t fps_timer;        /* frames per second timer struct */
-
-        prg_timer (&fps_timer, START);
-
-        display_image (0, 0, xinfo);
-        check_events (xinfo, binfo, n, last_frame + 1);
-
-        if (binfo->pressed [STOP_BUTTON])
-            n = 0;
-        else if (binfo->pressed [QUIT_BUTTON])
-            break;
-        else if (binfo->pressed [PLAY_BUTTON])
-            n++;
-        else if (binfo->pressed [RECORD_BUTTON]) /* REWIND is mapped RECORD */
-            n--;
-        if (n < 0)
-            n = last_frame;
-        if (n > last_frame)
-            n = 0;
-
-        memcpy (xinfo->pixels, frame_buffer [n], size);
-        while (prg_timer (&fps_timer, STOP) < frame_time) /* wait */
-            ;
-    };
-}
-
-#endif /* not X_DISPLAY_MISSING */
diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c
index 32145fc3..f55e7e8d 100644
--- a/converter/other/fiasco/params.c
+++ b/converter/other/fiasco/params.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <math.h>                       /* strtod() on SUN sparc */
@@ -32,6 +33,7 @@
 #include <getopt.h>                     /* system or ../lib */
 
 #include "pm_c_util.h"
+#include "mallocvar.h"
 #include "nstring.h"
 
 #include "types.h"
@@ -40,626 +42,181 @@
 #include "misc.h"
 #include "fiasco.h"
 
-#include "binerror.h"
-
 #include "params.h"
 
-/*****************************************************************************
-
-                                prototypes
-
-*****************************************************************************/
 
 static void
-read_parameter_file (param_t *params, FILE *file);
-static int
-get_parameter_index (const param_t *params, const char *search_string);
-static void
-set_parameter (param_t *parameter, const char *value);
-static void
-usage (const param_t *params, const char *progname, const char *synopsis,
-       const char *comment, const char *non_opt_string,
-       bool_t show_all_options, const char *sys_file_name,
-       const char *usr_file_name);
+setParameter(param_t *    const parameter,
+             const char * const value) {
+/*----------------------------------------------------------------------------
 
-/*****************************************************************************
+  Set value of 'parameter' to 'value'.
 
-                                public code
+  No return value.
 
-*****************************************************************************/
+  Side effects:
+     'parameter.value' is changed accordingly
 
-int
-parseargs (param_t *usr_params,
-           int argc, char **argv,
-           const char *synopsis,
-           const char *comment,
-           const char *non_opt_string,
-           const char *path,
-           const char *sys_file_name,
-           const char *usr_file_name)
-/*
- *  Perform the command line parsing.
- *  List of allowed parameters is given by 'usr_params'.
- *  Command line and number of parameters are given by 'argv' and 'argc'.
- *  'synopsis' contains a brief description of the program and
- *  'comment' may contain some additional advice.
- *  Initialization order of parameters:
- *      1.) Default values given by the param_t struct
- *      2.) System parameter-file ('path'/'sys_file_name')
- *      3.) User parameter-file ($HOME/'usr_file_name')
- *      4.) Command line parameters
- *      5.) Parameter-file forced by option -f (--config-file)
- *
- *  Return value:
- *      index in ARGV of the first ARGV-element that is not an option.
- *
- *  Side effects:
- *      the elements of ARGV are permuted
- *      usr_params [].value is modified
- */
-{
-   extern int optind;                   /* index in ARGV of the 1st element
-                                           that is not an option */
-   bool_t     detailed_help = NO;       /* NO if all parameters can be modified
-                                           with short options too */
-   unsigned   n1;                       /* number of user parameters */
-   unsigned   n2;                       /* number of system parameters */
-   bool_t     read_config_file = NO;    /* will override command line */
-   param_t    *params;                  /* array of user and system params */
-   param_t    *sys_params;              /* array of system parameters */
-   param_t    detailed_sys_params [] =  /* detailed system parameters */
-   {
-      {"version", NULL, 'v', PFLAG, {0}, NULL,
-       "Print program version number, then exit."},
-      {"verbose", "NUM", 'V', PINT, {0}, "1",
-       "Set level of verbosity to `%s'."},
-      {"config", "FILE", 'f', PSTR, {0}, NULL,
-       "Load `%s' to initialize parameters."},
-      {"info", NULL, 'h', PFLAG, {0}, NULL,
-       "Print brief help, then exit."},
-      {"help", NULL, 'H', PFLAG, {0}, NULL,
-       "Print detailed help, then exit."},
-      {NULL, NULL, 0, PSTR, {0}, NULL, NULL }
-   };
-   param_t    short_sys_params [] =     /* short system parameters */
-   {
-      {"version", NULL, 'v', PFLAG, {0}, NULL,
-       "Print program version number, then exit."},
-      {"verbose", "NUM", 'V', PINT, {0}, "1",
-       "Set level of verbosity to `%s'."},
-      {"config", "FILE", 'f', PSTR, {0}, NULL,
-       "Load `%s' to initialize parameters."},
-      {"help", NULL, 'h', PFLAG, {0}, NULL,
-       "Print this help, then exit."},
-      {NULL, NULL, 0, PSTR, {0}, NULL, NULL }
-   };
-   char *sys_path;                      /* path to system config file */
-
-   sys_path = calloc (strlen (path) + strlen (sys_file_name) + 2,
-                      sizeof (char));
-   if (!sys_path)
-      error ("Out of memory.");
-   sprintf (sys_path, "%s/%s", path, sys_file_name);
-
-   /*
-    *  Set parameters defaults
-    */
-   {
-       param_t *p;
-
-       for (p = usr_params; p->name != NULL; p++)
-       {
-           set_parameter (p, p->default_value);
-           if (p->optchar == '\0')
-               detailed_help = YES;
-       }
-
-      sys_params = detailed_help ? detailed_sys_params : short_sys_params;
-
-      for (p = sys_params; p->name != NULL; p++)
-          set_parameter (p, p->default_value);
-   }
-   /*
-    *  Append system command line option to user parameters
-    */
-   for (n1 = 0; usr_params [n1].name != NULL; n1++)
-      ;
-   for (n2 = 0; sys_params [n2].name != NULL; n2++)
-      ;
-   params = calloc (n1 + n2 + 1, sizeof (param_t));
-   if (!params)
-      error ("Out of memory.");
-
-   memcpy (params, usr_params, n1 * sizeof (param_t));
-   memcpy (params + n1, sys_params, (n2 + 1) * sizeof (param_t));
-   /*
-    *  Try to open the system resource file 'path'/'sys_file_name'
-    */
-   {
-      FILE *parameter_file = open_file (sys_path, NULL, READ_ACCESS);
-      if (parameter_file == NULL)
-/*
-         warning ("No system resource file found.");
-*/ {}
-      else
-      {
-         read_parameter_file (params, parameter_file);
-         fclose (parameter_file);
-      }
-   }
-   /*
-    *  Try to read user resource file $HOME/'usr_file_name'
-    */
-   {
-      FILE *parameter_file = open_file (usr_file_name, "HOME", READ_ACCESS);
-      if (parameter_file != NULL)
-      {
-         read_parameter_file (params, parameter_file);
-         fclose (parameter_file);
-      }
-   }
-   /*
-    *  Parse command line options
-    */
-   {
-      extern char   *optarg;            /* argument of current option */
-      struct option *long_options;      /* array of long options */
-      int            option_index = 0;
-      char           optstr [MAXSTRLEN]; /* string containing the legitimate
-                                            option characters */
-      int            optchar;           /* found option character */
-
-      /*
-       *  Build short option string for getopt_long ().
-       */
-      {
-         param_t *p;                    /* counter */
-         char    *ptr_optstr;           /* pointer to position in string */
-
-         ptr_optstr = optstr;
-         for (p = params; p->name != NULL; p++)
-            if (p->optchar != '\0')
-            {
-               *ptr_optstr++ = p->optchar;
-               if (p->type == POSTR)
-               {
-                  *ptr_optstr++ = ':';
-                  *ptr_optstr++ = ':';
-               }
-               else if (p->type != PFLAG)
-                  *ptr_optstr++ = ':';
-            }
-         *ptr_optstr = '\0';
-      }
-
-      /*
-       *  Build long option string for getopt_long ().
-       */
-      {
-         int i;
-
-         long_options = calloc (n1 + n2 + 1, sizeof (struct option));
-         if (!long_options)
-            error ("Out of memory.");
-         for (i = 0; params [i].name != NULL; i++)
-         {
-            long_options [i].name    = params [i].name;
-            switch (params [i].type)
-            {
-               case PFLAG:
-                  long_options [i].has_arg = 0;
-                  break;
-               case POSTR:
-                  long_options [i].has_arg = 2;
-                  break;
-               case PINT:
-               case PSTR:
-               case PFLOAT:
-               default:
-                  long_options [i].has_arg = 1;
-                  break;
-            }
-            long_options [i].has_arg = params [i].type != PFLAG;
-            long_options [i].flag    = NULL;
-            long_options [i].val     = 0;
-         }
-      }
-
-      /*
-       *  Parse command line
-       */
-      while ((optchar = getopt_long (argc, argv, optstr, long_options,
-                                     &option_index)) != EOF)
-      {
-         int param_index = -1;
-
-         switch (optchar)
-         {
-            case 0:
-               param_index = option_index;
-               break;
-            case ':':
-               if (detailed_help)
-                  fprintf (stderr,
-                           "Try `%s -h' or `%s --help' for "
-                           "more information.\n",
-                           argv [0], argv [0]);
-               else
-                  fprintf (stderr, "Try `%s --help' for more information.\n",
-                           argv [0]);
-               exit (2);
-               break;
-            case '?':
-               if (detailed_help)
-                  fprintf (stderr,
-                           "Try `%s -h' or `%s --help' "
-                           "for more information.\n",
-                           argv [0], argv [0]);
-               else
-                  fprintf (stderr, "Try `%s --help' for more information.\n",
-                           argv [0]);
-               exit (2);
-               break;
-            default:
-               {
-                  int i;
+-----------------------------------------------------------------------------*/
+    assert (parameter);
 
-                  for (i = 0; params [i].name != NULL; i++)
-                     if (params [i].optchar == optchar)
-                     {
-                        param_index = i;
-                        break;
-                     }
-               }
-         }
-         /*
-          *  Check for system options
-          */
-         if (param_index >= 0)
-         {
-            set_parameter (params + param_index, optarg ? optarg : "");
-            if (streq (params [param_index].name, "help"))
-               usage (params, argv [0], synopsis, comment, non_opt_string,
-                      YES, sys_path, usr_file_name);
-            else if (streq (params [param_index].name, "info"))
-               usage (params, argv [0], synopsis, comment, non_opt_string,
-                      NO, sys_path, usr_file_name);
-            else if (streq (params [param_index].name, "version"))
-            {
-           fprintf (stderr, "%s " VERSION "\n", argv [0]);
-           {
-              /* Kludge for standard Netpbm version announcement */
-              char * modified_argv[2];
-              int argc;
-              modified_argv[0] = argv[0];
-              modified_argv[1] = (char *) "--version";
-              argc = 2;
-              pm_proginit(&argc, (const char **) modified_argv);
-           }
-           exit (2);
+    switch (parameter->type) {
+    case PFLAG:
+        if (value != NULL && *value != '\0') {
+            if (strcaseeq (value, "TRUE"))
+                parameter->value.b = YES;
+            else if (strcaseeq (value, "FALSE"))
+                parameter->value.b = NO;
+            else if (strcaseeq (value, "YES"))
+                parameter->value.b = YES;
+            else if (strcaseeq (value, "NO"))
+                parameter->value.b = NO;
+            else {
+                long int data;
+                char     *endptr;
+
+                data = strtol (value, &endptr, 0);
+                if (*endptr != '\0' || endptr == value)
+                    pm_message("Invalid value `%s' converted to %d",
+                               value, (int) data);
+                parameter->value.b = data ? YES : NO;
             }
-            else if (streq (params [param_index].name, "verbose"))
-               fiasco_set_verbosity (
-               * (fiasco_verbosity_e *) parameter_value (params,
-                                                         "verbose"));
-            else if (streq (params [param_index].name, "config"))
-               read_config_file = YES;
-            param_index = -1;           /* clear index flag */
-         }
-      }
-
-      free (long_options);
-   }
-
-   /*
-    *  Read config-file if specified by option -f
-    */
-   if (read_config_file)
-   {
-      char *filename;
-
-      if ((filename = (char *) parameter_value (params, "config")) != NULL)
-      {
-         FILE *parameter_file;          /* input file */
-
-         warning ("Options set in file `%s' will override"
-                  " command line options.", filename);
-         parameter_file = open_file (filename, NULL, READ_ACCESS);
-         if (parameter_file != NULL)
-         {
-            read_parameter_file (params, parameter_file);
-            fclose (parameter_file);
-         }
-         else
-            file_error (filename);
-      }
-      else
-         error ("Invalid config filename.");
-   }
-
-   memcpy (usr_params, params, n1 * sizeof (param_t)); /* fill user struct */
-   free (sys_path);
-
-   return optind;
+        } else
+            parameter->value.b = !parameter->value.b;
+        break;
+    case PINT: {
+        long int  data;
+        char     *endptr;
+
+        data = strtol (value, &endptr, 0);
+        if (*endptr != '\0' || endptr == value)
+           pm_message("Invalid value `%s' converted to %d",
+                      value, (int) data);
+        parameter->value.i = data;
+    } break;
+    case PFLOAT: {
+        double      data;
+        char        *endptr;
+
+        data = strtod (value, &endptr);
+        if (*endptr != '\0' || endptr == value)
+           pm_message("Invalid value `%s' converted to %f",
+                      value, (double) data);
+        parameter->value.f = data;
+    } break;
+    case PSTR:
+    case POSTR:
+        parameter->value.s = value ? strdup (value) : NULL;
+        break;
+    default:
+         pm_error("Invalid parameter type for %s", parameter->name);
+    }
 }
 
-void *
-parameter_value (const param_t *params, const char *name)
-/*
- *  Extract value of parameter 'name.' of the given parameters 'params'.
- *
- *  Return value:
- *      value of given parameter
- */
-{
-   int pind = get_parameter_index (params, name);
 
-   if (pind < 0)
-      error ("Invalid parameter `%s'.", name);
 
-   if (params [pind].type == PSTR || params [pind].type == POSTR)
-      return (void *) params [pind].value.s;
+static int
+getParameterIndex(const param_t * const params,
+                  const char *    const search_string) {
+/*----------------------------------------------------------------------------
+  Search for parameter with name 'search_string' in parameter struct.
+
+  Return value: index of parameter or -1 if no matching parameter has been
+  found
+-----------------------------------------------------------------------------*/
+    int n;
+    int index = -1;
+
+    assert (params && search_string);
+
+    for (n = 0; params [n].name != NULL; n++) {
+        if (strcaseeq (params [n].name, search_string)) {
+            index = n;
+            break;
+        }
+    }
 
-   return (void *) &(params [pind].value);
+    return index;
 }
 
-void
-ask_and_set (param_t *params, const char *name, const char *msg)
-/*
- *  Ask user (print given message 'msg') for missing mandatory
- *  parameter 'name' of the given parameters 'params'.
- *
- *  No return value.
- *
- *  Side effects:
- *      'params ['name'].value' is changed
- */
-{
-   char answer [MAXSTRLEN];
-   int  index = get_parameter_index (params, name);
-
-   if (index < 0)
-      error ("Invalid parameter %s.", name);
-
-   if (msg)
-      fprintf (stderr, "%s\n", msg);
-
-   switch (params [index].type)
-   {
-      case PFLAG:                       /* Unusual, at least. */
-         warning ("Flags should be initialized and set on demand, "
-                  "not request");
-      case PINT:
-      case PSTR:
-      case POSTR:
-      case PFLOAT:
-         scanf (MAXSTRLEN_SCANF, answer);
-         set_parameter (&params [index], answer);
-         break;
-      default:
-         error ("Invalid parameter type for %s", name);
-   }
-}
 
-void
-write_parameters (const param_t *params, FILE *output)
-/*
- *  Write all parameter settings to 'output'.
- *
- *  No return value.
- */
-{
-   int pind;
-
-   if (!params || !output)
-      error ("Parameters must be not NULL.");
-
-   for (pind = 0; params [pind].name != NULL; pind++)
-   {
-      fprintf (output, "# %s = ", params [pind].name);
-      switch (params [pind].type)
-      {
-         case PFLAG:
-            fprintf (output, "%s\n", params [pind].value.b ? "TRUE" : "FALSE");
-            break;
-         case PINT:
-            fprintf (output, "%d\n", params [pind].value.i);
-            break;
-         case PFLOAT:
-            fprintf (output, "%.4f\n", (double) params [pind].value.f);
-            break;
-         case PSTR:
-         case POSTR:
-            fprintf (output, "%s\n", params [pind].value.s);
-            break;
-         default:
-            error ("Invalid type %d for parameter %s",
-                   params [pind].type, params [pind].name);
-      }
-   }
-   fputc ('\n', output);
-}
 
-/*****************************************************************************
+static void
+readParameterFile(param_t * const params,
+                  FILE *    const file) {
+/*----------------------------------------------------------------------------
 
-                                private code
+  Read parameter settings from 'file'.
 
-*****************************************************************************/
+  No return value.
 
-static void
-set_parameter (param_t *parameter, const char *value)
-/*
- *  Set value of 'parameter' to 'value'.
- *
- *  No return value.
- *
- *  Side effects:
- *      'parameter.value' is changed accordingly
- */
-{
-   assert (parameter);
-
-   switch (parameter->type)
-   {
-      case PFLAG:
-         if (value != NULL && *value != '\0')
-         {
-            if (strcaseeq (value, "TRUE"))
-               parameter->value.b = YES;
-            else if (strcaseeq (value, "FALSE"))
-               parameter->value.b = NO;
-            else if (strcaseeq (value, "YES"))
-               parameter->value.b = YES;
-            else if (strcaseeq (value, "NO"))
-               parameter->value.b = NO;
-            else
-            {
-               long int data;
-               char     *endptr;
-
-               data = strtol (value, &endptr, 0);
-               if (*endptr != '\0' || endptr == value)
-                  warning ("Invalid value `%s' converted to %d",
-                           value, (int) data);
-               parameter->value.b = data ? YES : NO;
-            }
-         }
-         else
-            parameter->value.b = !parameter->value.b;
-         break;
-      case PINT:
-         {
-            long int  data;
-            char     *endptr;
-
-            data = strtol (value, &endptr, 0);
-            if (*endptr != '\0' || endptr == value)
-               warning ("Invalid value `%s' converted to %d",
-                        value, (int) data);
-            parameter->value.i = data;
-         }
-         break;
-      case PFLOAT:
-         {
-            double      data;
-            char        *endptr;
-
-            data = strtod (value, &endptr);
-            if (*endptr != '\0' || endptr == value)
-               warning ("Invalid value `%s' converted to %f",
-                        value, (double) data);
-            parameter->value.f = data;
-         }
-         break;
-      case PSTR:
-      case POSTR:
-         parameter->value.s = value ? strdup (value) : NULL;
-         break;
-      default:
-         error ("Invalid parameter type for %s", parameter->name);
-   }
-}
+  Side effects:
+      'params [].value' are changed if specified in 'file'
+-----------------------------------------------------------------------------*/
+    char buffer [MAXSTRLEN];
+    int  n = 0;
 
-static int
-get_parameter_index (const param_t *params, const char *search_string)
-/*
- *  Search for parameter with name 'search_string' in parameter struct.
- *
- *  Return value:
- *      index of parameter or -1 if no matching parameter has been found
- */
-{
-   int n;
-   int index = -1;
+    assert (params && file);
 
-   assert (params && search_string);
+    while (fgets (buffer, MAXSTRLEN, file) != NULL) {
+        char *b;                          /* temporary variable */
+        char *name;                       /* parameter name */
+        char *value;                      /* parameter value */
+        int   pind;                       /* current argument number */
 
-   for (n = 0; params [n].name != NULL; n++)
-      if (strcaseeq (params [n].name, search_string))
-      {
-         index = n;
-         break;
-      }
+        b = strchr (buffer, '#');
+        if (b != NULL)                    /* Strip comments. */
+            *b = '\0';
 
-   return index;
-}
+        b = strchr (buffer, '=');
+        if (b == NULL)                    /* Strip lines that contain no '=' */
+            continue;
+        *b = '\0';                       /* Replace '=' by string terminator */
 
-static void
-read_parameter_file (param_t *params, FILE *file)
-/*
- *  Read parameter settings from 'file'.
- *
- *  No return value.
- *
- *  Side effects:
- *      'params [].value' are changed if specified in 'file'
- */
-{
-   char buffer [MAXSTRLEN];
-   int  n = 0;
-
-   assert (params && file);
-
-   while (fgets (buffer, MAXSTRLEN, file) != NULL)
-   {
-      char *b;                          /* temporary variable */
-      char *name;                       /* parameter name */
-      char *value;                      /* parameter value */
-      int   pind;                       /* current argument number */
-
-      b = strchr (buffer, '#');
-      if (b != NULL)                    /* Strip comments. */
-         *b = '\0';
-
-      b = strchr (buffer, '=');
-      if (b == NULL)                    /* Strip lines that contain no '=' */
-         continue;
-      *b = '\0';                        /* Replace '=' by string terminator */
-
-      /*
-       *  Extract value of parameter
-       */
-      for (value = b + 1; ISSPACE (*value); value++)
-         ;                              /* Delete leading spaces */
-
-      for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--)
-         *b = '\0';                     /* Delete trailing spaces. */
-
-      /*
-       *  Extract parameter name
-       */
-      for (name = buffer; ISSPACE (*name); name++)
-         ;                              /* Delete leading spaces */
-
-      for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--)
-         *b = '\0';                     /* Delete trailing spaces. */
-
-      pind = get_parameter_index (params, name);
-      if (pind >= 0)
-         set_parameter (&params [pind], value);
-
-      n++;
-   }
+        /* Extract value of parameter */
+        for (value = b + 1; ISSPACE (*value); value++)
+            ;                              /* Delete leading spaces */
+
+        for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--)
+            *b = '\0';                     /* Delete trailing spaces. */
+
+        /* Extract parameter name */
+        for (name = buffer; ISSPACE (*name); name++)
+            ;                              /* Delete leading spaces */
+
+        for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--)
+            *b = '\0';                     /* Delete trailing spaces. */
+
+        pind = getParameterIndex(params, name);
+        if (pind >= 0)
+            setParameter(&params[pind], value);
+
+        ++n;
+    }
 }
 
 
 
 static void
-usage (const param_t *params, const char *progname, const char *synopsis,
-       const char *comment, const char *non_opt_string,
-       bool_t show_all_options, const char *sys_file_name,
-       const char *usr_file_name)
-/*
- *  Generates and prints command line description from param_t struct 'params'.
- *  'progname' is the name of the executable, 'synopsis' a short program
- *  description, and 'comment' some more advice.
- *  If flag 'show_all_options' is set then print also options that are not
- *  associated with a short option character.
- *  'sys_file_name' and 'usr_file_name' are filenames to parameter files.
- *
- *  No return value.
- */
-{
+usage(const param_t *  const params,
+      const char *     const progname,
+      const char *     const synopsis,
+      const char *     const comment,
+      const char *     const non_opt_string,
+      bool_t           const show_all_options,
+      const char *     const sys_file_name,
+      const char *     const usr_file_name) {
+/*----------------------------------------------------------------------------
+
+  Generates and prints command line description from param_t struct 'params'.
+  'progname' is the name of the executable, 'synopsis' a short program
+  description, and 'comment' some more advice.
+  If flag 'show_all_options' is set then print also options that are not
+  associated with a short option character.
+  'sys_file_name' and 'usr_file_name' are filenames to parameter files.
+
+  No return value.
+-----------------------------------------------------------------------------*/
     int   i;
     size_t width = 0;
 
@@ -671,9 +228,8 @@ usage (const param_t *params, const char *progname, const char *synopsis,
     fprintf (stderr, "Mandatory or optional arguments to long options "
              "are mandatory or optional\nfor short options too. "
              "Default values are surrounded by {}.\n");
-    for (i = 0; params [i].name != NULL; i++)
-        if (params [i].optchar != '\0' || show_all_options)
-        {
+    for (i = 0; params [i].name != NULL; i++) {
+        if (params [i].optchar != '\0' || show_all_options) {
             if (params [i].type == POSTR)
                 width = MAX(width, (strlen (params [i].name)
                                      + strlen (params [i].argument_name) + 2));
@@ -683,10 +239,9 @@ usage (const param_t *params, const char *progname, const char *synopsis,
             else
                 width = MAX(width, (strlen (params [i].name)) - 1);
         }
-
-    for (i = 0; params [i].name != NULL; i++)
-        if (params [i].optchar != '\0' || show_all_options)
-        {
+    }
+    for (i = 0; params [i].name != NULL; i++) {
+        if (params [i].optchar != '\0' || show_all_options) {
             if (params [i].optchar != '\0')
                 fprintf (stderr, "  -%c, --", params [i].optchar);
             else
@@ -708,8 +263,7 @@ usage (const param_t *params, const char *progname, const char *synopsis,
 
             fprintf (stderr, params [i].use, params [i].argument_name);
 
-            switch (params [i].type)
-            {
+            switch (params [i].type) {
             case PFLAG:
                 break;
             case PINT:
@@ -724,20 +278,405 @@ usage (const param_t *params, const char *progname, const char *synopsis,
                     fprintf (stderr, "{%s}", params [i].value.s);
                 break;
             default:
-                error ("type %d for %s invalid",
-                       params [i].type, params [i].name);
+               pm_error("type %d for %s invalid",
+                        params [i].type, params [i].name);
             }
             fprintf (stderr, "\n");
         }
+    }
     fprintf (stderr, "\n");
+
     fprintf (stderr, "Parameter initialization order:\n");
     fprintf (stderr,
              "1.) %s\n2.) $HOME/%s\t 3.) command line\t 4.) --config=file",
              sys_file_name, usr_file_name);
     fprintf (stderr, "\n\n");
+
     if (comment != NULL)
         fprintf (stderr, "%s\n", comment);
 
     exit (1);
 }
 
+
+
+const void *
+parameter_value(const param_t * const params,
+                const char *    const name) {
+/*----------------------------------------------------------------------------
+  Extract value of parameter 'name.' of the given parameters 'params'.
+
+  Return value: value of given parameter
+
+-----------------------------------------------------------------------------*/
+    int pind = getParameterIndex(params, name);
+
+    if (pind < 0)
+        pm_error("Invalid parameter '%s'.", name);
+
+    if (params[pind].type == PSTR || params[pind].type == POSTR)
+        return params[pind].value.s;
+
+    return &(params[pind].value);
+}
+
+
+
+int
+parseargs(param_t *    const usr_params,
+          int argc, char **argv,
+          const char * const synopsis,
+          const char * const comment,
+          const char * const non_opt_string,
+          const char * const path,
+          const char * const sys_file_name,
+          const char * const usr_file_name) {
+/*----------------------------------------------------------------------------
+  Perform the command line parsing.
+  List of allowed parameters is given by 'usr_params'.
+  Command line and number of parameters are given by 'argv' and 'argc'.
+  'synopsis' contains a brief description of the program and
+  'comment' may contain some additional advice.
+  Initialization order of parameters:
+     1.) Default values given by the param_t struct
+     2.) System parameter-file ('path'/'sys_file_name')
+     3.) User parameter-file ($HOME/'usr_file_name')
+     4.) Command line parameters
+     5.) Parameter-file forced by option -f (--config-file)
+
+  Return value:
+      index in ARGV of the first ARGV-element that is not an option.
+
+  Side effects:
+      the elements of ARGV are permuted
+      usr_params [].value is modified
+-----------------------------------------------------------------------------*/
+    extern int optind;                   /* index in ARGV of the 1st element
+                                            that is not an option */
+    bool_t     detailed_help = NO;      /* NO if all parameters can be modified
+                                            with short options too */
+    unsigned   n1;                       /* number of user parameters */
+    unsigned   n2;                       /* number of system parameters */
+    bool_t     read_config_file = NO;    /* will override command line */
+    param_t    *params;                  /* array of user and system params */
+    param_t    *sys_params;              /* array of system parameters */
+    param_t    detailed_sys_params [] =  /* detailed system parameters */
+        {
+            {"version", NULL, 'v', PFLAG, {0}, NULL,
+             "Print program version number, then exit."},
+            {"verbose", "NUM", 'V', PINT, {0}, "1",
+             "Set level of verbosity to `%s'."},
+            {"config", "FILE", 'f', PSTR, {0}, NULL,
+             "Load `%s' to initialize parameters."},
+            {"info", NULL, 'h', PFLAG, {0}, NULL,
+             "Print brief help, then exit."},
+            {"help", NULL, 'H', PFLAG, {0}, NULL,
+             "Print detailed help, then exit."},
+            {NULL, NULL, 0, PSTR, {0}, NULL, NULL }
+        };
+    param_t    short_sys_params [] =     /* short system parameters */
+        {
+            {"version", NULL, 'v', PFLAG, {0}, NULL,
+             "Print program version number, then exit."},
+            {"verbose", "NUM", 'V', PINT, {0}, "1",
+             "Set level of verbosity to `%s'."},
+            {"config", "FILE", 'f', PSTR, {0}, NULL,
+             "Load `%s' to initialize parameters."},
+            {"help", NULL, 'h', PFLAG, {0}, NULL,
+             "Print this help, then exit."},
+            {NULL, NULL, 0, PSTR, {0}, NULL, NULL }
+        };
+    const char * sys_path;                     /* path to system config file */
+
+    pm_asprintf(&sys_path, "%s/%s", path, sys_file_name);
+
+    /* Set parameters defaults */
+    {
+        param_t *p;
+
+        for (p = usr_params; p->name != NULL; p++)
+        {
+            setParameter(p, p->default_value);
+            if (p->optchar == '\0')
+                detailed_help = YES;
+        }
+
+        sys_params = detailed_help ? detailed_sys_params : short_sys_params;
+
+        for (p = sys_params; p->name != NULL; p++)
+            setParameter(p, p->default_value);
+    }
+    /* Append system command line option to user parameters */
+    for (n1 = 0; usr_params [n1].name != NULL; n1++)
+        ;
+    for (n2 = 0; sys_params [n2].name != NULL; n2++)
+        ;
+    MALLOCARRAY_NOFAIL(params, n1 + n2 + 1);
+
+    memcpy(params, usr_params, n1 * sizeof(param_t));
+    memcpy(params + n1, sys_params, (n2 + 1) * sizeof(param_t));
+
+    {
+        /* Try to open the system resource file 'path'/'sys_file_name' */
+
+        FILE *parameter_file = open_file(sys_path, NULL, READ_ACCESS);
+
+        if (parameter_file) {
+            readParameterFile(params, parameter_file);
+            fclose(parameter_file);
+        }
+    }
+    {
+        /* Try to read user resource file $HOME/'usr_file_name' */
+
+        FILE *parameter_file = open_file(usr_file_name, "HOME", READ_ACCESS);
+
+        if (parameter_file) {
+            readParameterFile(params, parameter_file);
+            fclose(parameter_file);
+        }
+    }
+    {
+        /* Parse command line options */
+
+        extern char   *optarg;            /* argument of current option */
+        struct option *long_options;      /* array of long options */
+        int            option_index = 0;
+        char           optstr [MAXSTRLEN]; /* string containing the legitimate
+                                              option characters */
+        int            optchar;           /* found option character */
+
+        {
+            /* Build short option string for getopt_long (). */
+            param_t *p;                    /* counter */
+            char    *ptr_optstr;           /* pointer to position in string */
+
+            ptr_optstr = optstr;
+            for (p = params; p->name != NULL; p++)
+                if (p->optchar != '\0')
+                {
+                    *ptr_optstr++ = p->optchar;
+                    if (p->type == POSTR)
+                    {
+                        *ptr_optstr++ = ':';
+                        *ptr_optstr++ = ':';
+                    }
+                    else if (p->type != PFLAG)
+                        *ptr_optstr++ = ':';
+                }
+            *ptr_optstr = '\0';
+        }
+
+        {
+            /* Build long option string for getopt_long (). */
+
+            int i;
+
+            MALLOCARRAY_NOFAIL(long_options, n1 + n2 + 1);
+
+            for (i = 0; params [i].name != NULL; i++) {
+                long_options [i].name    = params [i].name;
+                switch (params [i].type)
+                {
+                case PFLAG:
+                    long_options [i].has_arg = 0;
+                    break;
+                case POSTR:
+                    long_options [i].has_arg = 2;
+                    break;
+                case PINT:
+                case PSTR:
+                case PFLOAT:
+                default:
+                    long_options [i].has_arg = 1;
+                    break;
+                }
+                long_options [i].has_arg = params [i].type != PFLAG;
+                long_options [i].flag    = NULL;
+                long_options [i].val     = 0;
+            }
+        }
+
+        /* Parse command line */
+
+        while ((optchar = getopt_long(argc, argv, optstr, long_options,
+                                      &option_index)) != EOF) {
+            int param_index = -1;
+
+            switch (optchar) {
+            case 0:
+                param_index = option_index;
+                break;
+            case ':':
+                if (detailed_help)
+                    fprintf (stderr,
+                             "Try `%s -h' or `%s --help' for "
+                             "more information.\n",
+                             argv [0], argv [0]);
+                else
+                    fprintf (stderr, "Try `%s --help' for more information.\n",
+                             argv [0]);
+                exit (2);
+                break;
+            case '?':
+                if (detailed_help)
+                    fprintf (stderr,
+                             "Try `%s -h' or `%s --help' "
+                             "for more information.\n",
+                             argv [0], argv [0]);
+                else
+                    fprintf (stderr, "Try `%s --help' for more information.\n",
+                             argv [0]);
+                exit (2);
+                break;
+            default: {
+                int i;
+
+                for (i = 0; params [i].name != NULL; i++) {
+                    if (params [i].optchar == optchar) {
+                        param_index = i;
+                        break;
+                    }
+                }
+            }
+            }
+            /* Check for system options  */
+
+            if (param_index >= 0) {
+                setParameter(params + param_index, optarg ? optarg : "");
+                if (streq(params[param_index].name, "help"))
+                    usage(params, argv [0], synopsis, comment, non_opt_string,
+                          YES, sys_path, usr_file_name);
+                else if (streq(params[param_index].name, "info"))
+                    usage(params, argv [0], synopsis, comment, non_opt_string,
+                           NO, sys_path, usr_file_name);
+                else if (streq(params[param_index].name, "version")) {
+                    fprintf(stderr, "%s " VERSION "\n", argv [0]);
+                    {
+                        /* Kludge for standard Netpbm version announcement */
+                        char * modified_argv[2];
+                        int argc;
+                        modified_argv[0] = argv[0];
+                        modified_argv[1] = (char *) "--version";
+                        argc = 2;
+                        pm_proginit(&argc, (const char **) modified_argv);
+                    }
+                    exit (2);
+                } else if (streq(params[param_index].name, "verbose"))
+                    fiasco_set_verbosity(
+                        * (fiasco_verbosity_e *) parameter_value(params,
+                                                                 "verbose"));
+                else if (streq(params[param_index].name, "config"))
+                    read_config_file = YES;
+                param_index = -1;           /* clear index flag */
+            }
+        }
+        free(long_options);
+    }
+
+    /* Read config-file if specified by option -f */
+    if (read_config_file) {
+        char * filename;
+
+        if ((filename = (char *) parameter_value(params, "config")) != NULL) {
+            FILE * parameter_file;          /* input file */
+
+            pm_message("Options set in file `%s' will override"
+                       " command line options.", filename);
+            parameter_file = open_file(filename, NULL, READ_ACCESS);
+            if (parameter_file != NULL) {
+                readParameterFile(params, parameter_file);
+                fclose(parameter_file);
+            } else
+                pm_error("Failed to open config file '%s'", filename);
+        } else
+            pm_error("Invalid config filename.");
+    }
+
+    memcpy(usr_params, params, n1 * sizeof (param_t)); /* fill user struct */
+    pm_strfree(sys_path);
+
+    return optind;
+}
+
+
+
+void
+ask_and_set(param_t *    const params,
+            const char * const name,
+            const char * const msg) {
+/*----------------------------------------------------------------------------
+  Ask user (print given message 'msg') for missing mandatory
+  parameter 'name' of the given parameters 'params'.
+
+  No return value.
+
+  Side effects:
+     'params ['name'].value' is changed
+-----------------------------------------------------------------------------*/
+    char answer[MAXSTRLEN];
+    int  index = getParameterIndex(params, name);
+
+    if (index < 0)
+        pm_error("Invalid parameter '%s'.", name);
+
+    if (msg)
+        pm_message("%s", msg);
+
+    switch (params[index].type) {
+    case PFLAG:                       /* Unusual, at least. */
+        pm_message("Flags should be initialized and set on demand, "
+                   "not request");
+    case PINT:
+    case PSTR:
+    case POSTR:
+    case PFLOAT:
+        scanf(MAXSTRLEN_SCANF, answer);
+        setParameter(&params [index], answer);
+        break;
+    default:
+        pm_error("Invalid parameter type for %s", name);
+    }
+}
+
+
+
+void
+write_parameters(const param_t * const params,
+                 FILE *          const output) {
+/*----------------------------------------------------------------------------
+  Write all parameter settings to 'output'.
+
+  No return value.
+-----------------------------------------------------------------------------*/
+    unsigned int pind;
+
+    if (!params || !output)
+        pm_error("Parameters must be not NULL.");
+
+    for (pind = 0; params[pind].name != NULL; pind++) {
+        fprintf(output, "# %s = ", params[pind].name);
+        switch(params[pind].type) {
+        case PFLAG:
+            fprintf(output, "%s\n", params[pind].value.b ? "TRUE" : "FALSE");
+            break;
+        case PINT:
+            fprintf(output, "%d\n", params[pind].value.i);
+            break;
+        case PFLOAT:
+            fprintf(output, "%.4f\n", (double) params[pind].value.f);
+            break;
+        case PSTR:
+        case POSTR:
+            fprintf(output, "%s\n", params[pind].value.s);
+            break;
+        default:
+            pm_error("Invalid type %d for parameter %s",
+                     params[pind].type, params[pind].name);
+        }
+    }
+    fputc ('\n', output);
+}
+
+
+
diff --git a/converter/other/fiasco/params.h b/converter/other/fiasco/params.h
index dd79d43d..76427577 100644
--- a/converter/other/fiasco/params.h
+++ b/converter/other/fiasco/params.h
@@ -53,9 +53,11 @@ parseargs (param_t *usr_params,
            const char *usr_file_name);
 void
 write_parameters (const param_t *params, FILE *output);
+
 void
 ask_and_set (param_t *params, const char *name, const char *msg);
-void *
+
+const void *
 parameter_value (const param_t *params, const char *name);
 
 #endif /* not PARAMS_H */