home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / cmddisp.c < prev    next >
C/C++ Source or Header  |  1990-06-03  |  11KB  |  326 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    cmddisp.c (Command Display)
  6.  * Purpose:    Set options from command line pertaining to display
  7.  * Subroutine:    parse_rotate()            returns: int
  8.  * Subroutine:    parse_scale()            returns: int
  9.  * Subroutine:    parse_color()            returns: int
  10.  * Subroutine:    parse_display()            returns: int
  11.  * Xlib calls:    none
  12.  * Copyright:    1988, 1989 Smithsonian Astrophysical Observatory
  13.  *        You may do anything you like with this file except remove
  14.  *        this copyright.  The Smithsonian Astrophysical Observatory
  15.  *        makes no representations about the suitability of this
  16.  *        software for any purpose.  It is provided "as is" without
  17.  *        express or implied warranty.
  18.  * Modified:    {0} Michael VanHilst    initial version        20 September 1988
  19.  *        {1} MVH    modified and renamed parse_display        18 May 1989
  20.  *        {2} MVH    BSDonly strings.h compatability          19 Feb 1990
  21.  *        {n} <who> -- <does what> -- <when>
  22.  */
  23.  
  24. #include <stdio.h>        /* stderr, NULL, etc. */
  25. #include <ctype.h>
  26.  
  27. #ifndef VMS
  28. #ifdef SYSV
  29. #include <string.h>
  30. #else
  31. #include <strings.h>        /* strlen, etc. for unenlightened BSD's */
  32. #endif
  33. #else
  34. #include <string.h>
  35. #endif
  36.  
  37. #include <X11/Xlib.h>        /* X window stuff */
  38. #include <X11/Xutil.h>        /* X window manager stuff */
  39. #include "hfiles/constant.h"    /* define codes */
  40. #include "hfiles/struct.h"    /* declare structure types */
  41. #include "hfiles/extern.h"    /* extern main ximage parameter structures */
  42. #include "hfiles/cmdparse.h"    /* define parse status bits */
  43. #include "hfiles/magnify.h"    /* magnifier quick access structure */
  44.  
  45. extern struct magRec magset;
  46. extern char *border_color_name;
  47. /* Flag in GrphCInit.c to set color graph background black, else white */
  48. extern int black_graph_background;
  49. extern int init_done;
  50. /* strings to set cursor colors to standard colors */
  51. static char *RedString = "red";
  52. static char *GreenString = "green";
  53. static char *BlueString = "blue";
  54. /*
  55.  * Subroutine:    parse_rotate
  56.  * Purpose:    Parse command line for coordinate adjustment or rotation
  57.  *        parameters
  58.  * Returns:    1 if one of its parameters was found, else 0
  59.  */
  60. int parse_rotate ( argc, argv, argi, new_rotate )
  61.      int argc;        /* total number of arg tokens */
  62.      char *argv[];    /* array of arg tokens */
  63.      int *argi;        /* first arg to check, (returned as last arg used) */
  64.      int *new_rotate;    /* status word knows coordinate parameter was found */
  65. {
  66.   int i;
  67.   int usage();
  68.  
  69.   i = *argi;
  70.   if( (strcmp(argv[i], "-rot") == 0) ||
  71.       (strcmp(argv[i], "-rotate") == 0) ) {
  72.     if( (++i >= argc) ||
  73.         ((img.rotate_code = (3 & atoi(argv[i]))) < 0) ||
  74.         (img.rotate_code > 3) )
  75.       return( usage("rotate code", argc, argv, i-1, i) );
  76.     *argi = i;
  77.   } else if( (strcmp(argv[i], "-ul") == 0) || 
  78.          (strcmp(argv[i], "-upperleft") == 0) ) {
  79.     /* --- image orientation (first row at top) --- */
  80.     img.row_order = 0;
  81.   } else if( (strcmp(argv[i], "-ll") == 0) ||
  82.          (strcmp(argv[i], "-lowerleft") == 0) ) {
  83.     /* --- image orientation (first row at bottom) --- */
  84.     img.row_order = 1;
  85.   } else if( strcmp(argv[i], "-zero") == 0 ) {
  86.     /* --- start file indexing with 0  --- */
  87.     img.index_base = 0;
  88.   } else if( strcmp(argv[i], "-one") == 0 ) {
  89.     /* --- start file indexing with 1  --- */
  90.     img.index_base = 1;
  91.   } else {
  92.     return( 0 );
  93.   }
  94.   *argi = i;
  95.   *new_rotate |= CMD_ROTATE;
  96.   return( 1 );
  97. }
  98.  
  99. /*
  100.  * Subroutine:    parse_color
  101.  * Purpose:    Parse command line for display color parameters
  102.  * Returns:    1 if one of its parameters was found, else 0
  103.  */
  104. int parse_color ( argc, argv, argi, got_color )
  105.      int argc;        /* total number of arg tokens */
  106.      char *argv[];    /* array of arg tokens */
  107.      int *argi;        /* first arg to check, (returned as last arg used) */
  108.      int *got_color;    /* status word knows coloring parameter was found */
  109. {
  110.   int i;
  111.   int usage();
  112.   void set_submenu_toggle();
  113.  
  114.   i = *argi;
  115.   /* number of planes */
  116.   if( (strcmp(argv[i], "-p") == 0) ||
  117.       (strcmp(argv[i], "-palette") == 0) ) {
  118.     if (++i >= argc)
  119.       return( usage("planes", argc, argv, i-1, i) );
  120.     color.cells.wanted = atoi(argv[i]);
  121.     /* if planes request is negative, overlay for cursor */
  122.     if( color.cells.wanted < 0 ) {
  123.       color.cells.wanted = -color.cells.wanted;
  124.       color.cells.overlay = 1;
  125.     } else
  126.       color.cells.overlay = 0;
  127.     if( color.cells.wanted <= 1 ) {
  128.       color.cells.wanted = 1;
  129.       color.cells.overlay = 0;
  130.       color.colormap_mode = VOP_Halftone;
  131.     }
  132.     *got_color |= CMD_COLOR;
  133.   } else if( (strcmp(argv[i], "-n") == 0) ||
  134.          (strcmp(argv[i], "-neg") == 0) ) {
  135.     /* negative map */
  136.     color.inverse = 1;
  137.     *got_color |= CMD_COLOR;
  138.   /* on machines with only one functional color, use that color */
  139.   } else if( strcmp(argv[i], "-red") == 0 ) {
  140.     color.cur.desired_cur = RedString;
  141.     color.cur.desired_one = RedString;
  142.     color.cur.desired_two = RedString;
  143.     black_graph_background = 1;
  144.   } else if( strcmp(argv[i], "-green") == 0 ) {
  145.     color.cur.desired_cur = GreenString;
  146.     color.cur.desired_one = GreenString;
  147.     color.cur.desired_two = GreenString;
  148.     black_graph_background = 1;
  149.   } else if( strcmp(argv[i], "-blue") == 0 ) {
  150.     color.cur.desired_cur = BlueString;
  151.     color.cur.desired_one = BlueString;
  152.     color.cur.desired_two = BlueString;
  153.     black_graph_background = 1;
  154.   } else if( (strcmp(argv[i], "-vg") == 0) ||
  155.          (strcmp(argv[i], "-vertgragh") == 0) ) {
  156.     graphbox.hints.width = 143;
  157.     graphbox.hints.height = 550;
  158.     graphbox.hints.min_width = 123;
  159.     graphbox.hints.min_height = 300;
  160.   } else if( (strcmp(argv[i], "-hg") == 0) ||
  161.          (strcmp(argv[i], "-horizgragh") == 0) ) {
  162.     graphbox.hints.width = 516;
  163.     graphbox.hints.height = 84;
  164.     graphbox.hints.min_width = 404;
  165.     graphbox.hints.min_height = 69;
  166.   } else {
  167.     return( 0 );
  168.   }
  169.   *argi = i;
  170.   return( 1 );
  171. }
  172.  
  173. /*
  174.  * Subroutine:    parse_scale
  175.  * Purpose:    Parse command line for image scaling parameters
  176.  * Returns:    1 if one of its parameters was found, else 0
  177.  */
  178. int parse_scale ( argc, argv, argi, got_scale )
  179.      int argc;        /* total number of arg tokens */
  180.      char *argv[];    /* array of arg tokens */
  181.      int *argi;        /* first arg to check, (returned as last arg used) */
  182.      int *got_scale;    /* flag that scaling parameter was found */
  183. {
  184.   float val;
  185.   int i;
  186.   int usage();
  187.  
  188.   i = *argi;
  189.   if( strcmp(argv[i], "-wrap") == 0 ) {
  190.     /* image to display rescaling types */
  191.     color.scale.mode = SOP_Wrap;
  192.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) )
  193.       color.scale.wrap_cnt = val;
  194.     else
  195.       --i;
  196.   } else if( strcmp(argv[i], "-linear") == 0 ) {
  197.     color.scale.mode = SOP_Linear;
  198.   } else if( strcmp(argv[i], "-sqrt") == 0 ) {
  199.     color.scale.mode = SOP_Sqrt;
  200.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) )
  201.       color.scale.root_power = val;
  202.     else
  203.       --i;
  204.   } else if( strcmp(argv[i], "-log") == 0 ) {
  205.     color.scale.mode = SOP_Log;
  206.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) )
  207.       color.scale.log_expo = val;
  208.     else
  209.       --i;
  210.   } else if( strcmp(argv[i], "-histeq") == 0 ) {
  211.     color.scale.mode = SOP_HistEq;
  212.   } else if( strcmp(argv[i], "-min") == 0 ) {
  213.     /* scaling threshold level */
  214.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) ) {
  215.       buffer.cmdMin = val;
  216.       buffer.min_given = 1;
  217.     } else {
  218.       --i;
  219.       buffer.min_given = 0;
  220.     }
  221.   } else if( strcmp(argv[i], "-max") == 0 ) {
  222.     /* scaling saturation level */
  223.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) ) {
  224.       buffer.cmdMax = val;
  225.       buffer.max_given = 1;
  226.     } else {
  227.       --i;
  228.       buffer.max_given = 0;
  229.     }
  230.   } else if( strcmp(argv[i], "-rmax") == 0 ) {
  231.     /* file reading saturation level */
  232.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) ) {
  233.       img.fimax = val;
  234.       *got_scale |= CMD_FREAD;
  235.     } else
  236.       return( usage("saturate", argc, argv, i-1, i) );
  237.   } else if( strcmp(argv[i], "-rmin") == 0 ) {
  238.     /* file reading threshold level */
  239.     if( ((++i) < argc) && (sscanf(argv[i], "%f", &val) == 1) ) {
  240.       img.fimin = val;
  241.       *got_scale |= CMD_FREAD;
  242.     } else
  243.       return( usage("threshold", argc, argv, i-1, i) );
  244.   } else {
  245.     return( 0 );
  246.   }
  247.   *argi = i;
  248.   *got_scale |= CMD_SCALE;
  249.   return( 1 );
  250. }
  251.  
  252. /*
  253.  * Subroutine:    parse_display
  254.  * Purpose:    Parse the command line for window and server parameters
  255.  */
  256. int parse_display ( argc, argv, argi, got_geo, displayname )
  257.      int argc;            /* i: total number of arg tokens */
  258.      char *argv[];        /* i: array of arg tokens */
  259.      int *argi;            /* i/o: current arg in list */
  260.      int *got_geo;        /* o: got server or window parameters */
  261.      char **displayname;    /* o: name of display server */
  262. {
  263.   int i, temp;
  264.   int usage(), parse_geometry();
  265.   void set_magnifier(), redraw_magnifier(), SetTAEButtonLook();
  266.  
  267.   i = *argi;
  268.   if( (strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "-display") == 0) ) {
  269.     /* X window server socket name (overrides DISPLAY env variable) */
  270.     *displayname = argv[++i];
  271.   } else if( (strcmp(argv[i], "-g") == 0) ||
  272.          (strcmp(argv[i], "-geometry") == 0) ) {
  273.     /* initial program desktop size and/or position */
  274.     /* X window geometry (size and position) -g <width>x<height>+<x>+<y> */
  275.     if( parse_geometry(argv[++i], 0) == 0 ) {
  276.       (void)fprintf(stderr, "Error: Cannot parse geometry: %s\n", argv[i]);
  277.       return( 0 );
  278.     }
  279.   } else if( strcmp(argv[i], "-gd") == 0 ) {
  280.     /* initial display window size and/or desktop position */
  281.     /* X window geometry (size and position) -gd <width>x<height>+<x>+<y> */
  282.     if( parse_geometry(argv[++i], 1) == 0 ) {
  283.       (void)fprintf(stderr, "Error: Cannot parse geometry: %s\n", argv[i]);
  284.       return( 0 );
  285.     }
  286.   } else if( (strcmp(argv[i], "-bc") == 0) ||
  287.          (strcmp(argv[i], "-bordercolor") == 0) ) {
  288.     /* border color */
  289.     if( ++i >= argc )
  290.       return( usage("border color", argc, argv, i-1, i) );
  291.     border_color_name = argv[i];
  292.   } else if( strcmp(argv[i], "-mtf") == 0) {
  293.     /* make buttons less of a sore thumb when surrounded by motif */
  294.     SetTAEButtonLook(2);
  295.   } else if( strcmp(argv[i], "-mtfa") == 0) {
  296.     /* as above but with even less highlighting */
  297.     SetTAEButtonLook(1);
  298.   } else if( strcmp(argv[i], "-mag") == 0 ) {
  299.     /* magnifier magnification */
  300.     if( ((++i) < argc) && ((temp = atoi(argv[i])) > 0) ) {
  301.       magset.magnify = temp;
  302.       /* if init has already been run, then set must be run to update */
  303.       if( init_done && (magset.image == &magnibox.image) ) {
  304.     set_magnifier();
  305.     redraw_magnifier();
  306.       }
  307.     } else
  308.       return( usage("magnifier", argc, argv, i-1, i) );
  309.   } else if( strcmp(argv[i], "-panboxav") == 0 ) {
  310.     img.panbox_zoomtype = SOP_ZoomAv;
  311.   } else if( strcmp(argv[i], "-panboxsamp") == 0 ) {
  312.     img.panbox_zoomtype = SOP_ZoomSamp;
  313.   } else if( strcmp(argv[i], "-panboxsum") == 0 ) {
  314.     img.panbox_zoomtype = SOP_ZoomSum;
  315.   } else if( strcmp(argv[i], "-panboxmax") == 0 ) {
  316.     img.panbox_zoomtype = SOP_ZoomMax;
  317.   } else if( strcmp(argv[i], "-lprbuttons") == 0 ) {
  318.     control.print_buttons = 1;
  319.   } else {
  320.     return( 0 );
  321.   }
  322.   *argi = i;
  323.   *got_geo |= CMD_GEOMETRY;
  324.   return( 1 );
  325. }
  326.