home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / morpho.zip / morpho / src / vgballse / vgballse.c < prev    next >
C/C++ Source or Header  |  1992-07-28  |  11KB  |  415 lines

  1.  /*
  2.   * Khoros: $Id$
  3.   */
  4.  
  5. #if !defined(lint) && !defined(SABER)
  6. static char rcsid[] = "Khoros: $Id$";
  7. #endif
  8.  
  9.  /*
  10.   * $Log$
  11.   */
  12.  
  13. /*
  14.  *----------------------------------------------------------------------
  15.  *
  16.  * Copyright 1992, University of New Mexico.  All rights reserved.
  17.  * Permission to copy and modify this software and its documen-
  18.  * tation only for internal use in your organization is hereby
  19.  * granted, provided that this notice is retained thereon and
  20.  * on all copies.  UNM makes no representations as to the sui-
  21.  * tability and operability of this software for any purpose.
  22.  * It is provided "as is" without express or implied warranty.
  23.  * 
  24.  * UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  25.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  26.  * NESS.  IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
  27.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
  28.  * SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  29.  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  30.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
  31.  * FORMANCE OF THIS SOFTWARE.
  32.  * 
  33.  * No other rights, including, for example, the right to redis-
  34.  * tribute this software and its documentation or the right to
  35.  * prepare derivative works, are granted unless specifically
  36.  * provided in a separate license agreement.
  37.  *---------------------------------------------------------------------
  38.  */
  39.  
  40. #include "unmcopyright.h"        /* Copyright 1992 by UNM */
  41.  
  42. /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  43.  >>>>
  44.  >>>>         File Name: vgballse.c
  45.  >>>>
  46.  >>>>      Program Name: vgballse
  47.  >>>>
  48.  >>>>      Program Desc: 
  49.  >>>>    
  50.  >>>>    Creates a image of a ball with the origin at the center
  51.  >>>>    
  52.  >>>>    
  53.  
  54.  >>>>            Author: Greg Donohoe
  55.  >>>>
  56.  >>>> Date Last Updated: Tue Jul 28 16:40:35 1992
  57.  >>>>
  58.  >>>>          Routines: main- the main program for vgballse
  59.  >>>>          gw_usage - gives usage of the program
  60.  >>>>          gw_args  - gets arguments of program from command line
  61.  >>>>
  62.  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  63.  
  64.  
  65. #include "vgballse.h"
  66.  
  67.  
  68. /****************************************************************
  69.  *
  70.  * Routine Name:  main program for vgballse
  71.  *
  72.  *       Input:  
  73.  *          -o  output image 
  74.  *          -origin  origin at center 
  75.  *          -t  Selects data type of output image
  76.  *        'integer' (choose Integer data storage type),
  77.  *         or 'byte' (choose Byte data storage type)
  78.  *         
  79.  *
  80.  *
  81.  *          [-trigger] trigger input
  82.  *          [-d] Diameter of circle (in pixels)  (value >= 0.0)
  83.  *          [-x] X coordinate of origin 
  84.  *          [-y] Y coordinate of origin 
  85.  *          [-b] Background level 
  86.  *
  87.  *
  88.  *
  89.  ****************************************************************/
  90.  
  91.  
  92. main(argc, argv)
  93. int argc;
  94. char *argv[];
  95. {
  96.  
  97. /* -main_variable_list */
  98. struct xvimage *image;
  99. int type;
  100. /* -main_variable_list_end */
  101.  
  102.     program = VStrcpy(argv[0]);
  103.     ac = argc;
  104.     av = argv;
  105.  
  106.     khoros_init();
  107.  
  108.     gw_get_args();
  109.  
  110. /* -main_before_lib_call */
  111. if(check_args())exit(1);
  112.  
  113. if(!vget_type(&type, vgballse->t_toggle)){
  114.    fprintf(stderr,"vgballse:  Invalid data type specified\n");
  115.    exit(1);
  116. }
  117.  
  118. if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
  119.    fprintf(stderr,"%s:  Illegal image data type specified.\n",program);
  120.    exit(1);
  121. }
  122.  
  123. /* -main_before_lib_call_end */
  124.  
  125. /* -main_library_call */
  126. if(! lvgballse( &image, type, vgballse->b_float, vgballse->x_float,vgballse->y_float, vgballse->origin_logic, vgballse->d_float))
  127.   {
  128.       (void) fprintf(stderr, "lvgballse Failed\n");
  129.       exit(1);
  130.   }
  131. /* -main_library_call_end */
  132.  
  133. /* -main_after_lib_call */
  134. writeimage(vgballse->o_file,image);
  135. /* -main_after_lib_call_end */
  136.  
  137.  
  138.     khoros_close();
  139. }
  140.  
  141.  
  142. /****************************************************************
  143. *
  144. * Routine Name:  gw_usage 
  145. *
  146. *
  147. * Purpose:  prints out the usage for vgballse 
  148. *
  149. * Input:  none 
  150. *
  151. * Output:  none 
  152. *
  153. * Written By:  automatically generated by ghostwriter
  154. *
  155. ****************************************************************/
  156.  
  157.  
  158. gw_usage()
  159. {
  160.     fprintf(stderr, "vgballse :\n");
  161.     fprintf(stderr, "\t\n");
  162.     fprintf(stderr, "\tCreates a image of a ball with the origin at the center\n");
  163.     fprintf(stderr, "\t\n");
  164.     fprintf(stderr, "\t\n");
  165.  
  166. /* -usage_additions */
  167. /* -usage_additions_end */
  168.  
  169.     fprintf(stderr,"\t-o  output image  (outfile)\n");
  170.     fprintf(stderr,"\t-origin  origin at center  (boolean)\n");
  171.     fprintf(stderr, "\t-t  ");
  172.     fprintf(stderr, "Selects data type of output image\n  ");
  173.     fprintf(stderr, "\t\t'integer'  (choose Integer data storage type),\n");
  174.     fprintf(stderr, "\t\t or 'byte'  (choose Byte data storage type)\n");
  175.     fprintf(stderr, "\n");
  176.     fprintf(stderr, "\n");
  177.     fprintf(stderr, "\n");
  178.     fprintf(stderr,"\t[-trigger]  trigger input (infile) [null]\n");
  179.     fprintf(stderr,"\t[-d]  Diameter of circle (in pixels) (float, >= 0.0) [15]\n");
  180.     fprintf(stderr,"\t[-x]  X coordinate of origin (float) [8]\n");
  181.     fprintf(stderr,"\t[-y]  Y coordinate of origin (float) [8]\n");
  182.     fprintf(stderr,"\t[-b]  Background level (float) [-1]\n");
  183.     fprintf(stderr, " \n");
  184.     fprintf(stderr, "\n");
  185.     fprintf(stderr, "\t[-V] Gives the version for vgballse\n");
  186.     fprintf(stderr, "\t[-U] Gives the usage for vgballse\n");
  187.     fprintf(stderr, "\t[-P] Prompts for command line options\n");
  188.     fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgballse.ans or file1 \n");
  189.     fprintf(stderr, "\t[-a [file1]] Uses vgballse.ans or file1 as the answer file \n\n\n");
  190.  
  191. }
  192.  
  193.  
  194. /****************************************************************
  195. *
  196. * Routine Name:  gw_getargs 
  197. *
  198. *
  199. * Purpose:  gets arguments off command line for vgballse
  200. *
  201. * Input:  none 
  202. *
  203. * Output:  none 
  204. *
  205. * Written By:  automatically generated by ghostwriter
  206. *
  207. ****************************************************************/
  208.  
  209.  
  210. gw_get_args()
  211. {
  212.  
  213. char    *o_pstr = 
  214.     "\nEnter: (o) output image \n        {outfile}: "; 
  215. char    *origin_pstr = 
  216.     "\nEnter: (origin) origin at center \n        {boolean, (y/n) }: "; 
  217. char    *t_pstr = "\nEnter: (t) Selects data type of output image -- \n      \t\t'integer' (choose Integer data storage type)\n\t\tor 'byte' (choose Byte data storage type)\n     : "; 
  218. char    *trigger_pstr = 
  219.     "\nEnter: (trigger) trigger input \n        {infile}: "; 
  220. char    *d_pstr = 
  221.     "\nEnter: (d) Diameter of circle (in pixels) \n        {float, >= 0.0 [15.000000] }: "; 
  222. char    *x_pstr = 
  223.     "\nEnter: (x) X coordinate of origin \n        {float [8.000000] }: "; 
  224. char    *y_pstr = 
  225.     "\nEnter: (y) Y coordinate of origin \n        {float [8.000000] }: "; 
  226. char    *b_pstr = 
  227.     "\nEnter: (b) Background level \n        {float [-1.000000] }: "; 
  228. char  answer_file[512], temp[512];
  229.  
  230.  
  231.  
  232. int    fid = -1,
  233.     error, query, ok, count;
  234.     int prompt_flag = FALSE;
  235.  
  236.     /*
  237.      * print version if necessary
  238.      */
  239.     vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
  240.     if (error == 0)
  241.     {
  242.         printf ("\n%s: %s: Version %d.%d\n\n",
  243.         "vgballse", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
  244.         exit(1);
  245.     }
  246.  
  247.     /*
  248.      * print usage if necessary
  249.      */
  250.     vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
  251.     if (error == 0)
  252.     {
  253.         gw_usage();
  254.         exit(1);
  255.     }
  256.  
  257.     /*
  258.      * see if interactive prompting is desired
  259.      */
  260.     vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
  261.     if (error == 0)
  262.         prompt_flag = TRUE;
  263.  
  264.     /*
  265.      * see if answer file is to be used
  266.      */
  267.     vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
  268.     if (error == 0)
  269.     {
  270.          if (VStrlen(answer_file) == 0)
  271.         sprintf(answer_file, "vgballse.ans");
  272.          while (fid < 0)
  273.          {
  274.         if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
  275.         {
  276.             fprintf(stderr, "vgballse: can't open answer file \"%s\"",
  277.                 answer_file); 
  278.             fprintf(stderr, "please re-enter: ");
  279.             (void) gets(answer_file);
  280.             if (VStrlen(answer_file) == 0)
  281.             sprintf(answer_file, "vgballse.ans");
  282.         }
  283.  
  284.          }
  285.  
  286.     }
  287.  
  288.     /*
  289.      * allocate the vgballse structure
  290.      */
  291.     vgballse = (vgballse_struct *) 
  292.            calloc((unsigned)1, (unsigned) sizeof (vgballse_struct));
  293.  
  294.     /*
  295.      * get required arguments for vgballse
  296.      */
  297.     if (prompt_flag == TRUE)
  298.         fprintf(stderr,"\nRequired Arguments:\n\n");
  299.  
  300.     if (!(vgballse->o_flag = vget_outfile(fid, prompt_flag,
  301.             "-o", o_pstr, &(vgballse->o_file))
  302. ))
  303.     {
  304.         if (prompt_flag == TRUE)
  305.         {
  306.         while(!(vgballse->o_flag))
  307.         {
  308.             fprintf(stderr, "\t\to is required, please re-enter: \n");
  309.             vgballse->o_flag = vget_outfile(fid, prompt_flag,
  310.             "-o", o_pstr, &(vgballse->o_file))
  311. ;
  312.  
  313.         }
  314.         }
  315.         else
  316.         {
  317.         fprintf(stderr, "Error: '-o' is a required argument\n");
  318.         gw_usage();
  319.         exit(1);
  320.         }
  321.     }
  322.  
  323.     if (!(vgballse->origin_flag = vget_logic(fid, prompt_flag,
  324.             "-origin", origin_pstr, &(vgballse->origin_logic), 0)))
  325.     {
  326.         if (prompt_flag == TRUE)
  327.         {
  328.         while(!(vgballse->origin_flag))
  329.         {
  330.             fprintf(stderr, "\t\torigin is required, please re-enter: \n");
  331.             vgballse->origin_flag = vget_logic(fid, prompt_flag,
  332.             "-origin", origin_pstr, &(vgballse->origin_logic), 0);
  333.  
  334.         }
  335.         }
  336.         else
  337.         {
  338.         fprintf(stderr, "Error: '-origin' is a required argument\n");
  339.         gw_usage();
  340.         exit(1);
  341.         }
  342.     }
  343.  
  344.  
  345.     /*
  346.      * get required toggles for vgballse
  347.      */
  348.     if (prompt_flag == TRUE)
  349.     {
  350.         ok = FALSE;
  351.         while(!ok)
  352.         {
  353.         vgballse->t_flag = vget_string(fid, prompt_flag,
  354.         "-t", t_pstr, &(vgballse->t_toggle),
  355.         "integer");
  356.  
  357.         if ((((strcmp(vgballse->t_toggle, "integer") == 0)) || 
  358.              ((strcmp(vgballse->t_toggle, "byte") == 0))) &&
  359.              (vgballse->t_flag))
  360.               ok = TRUE;
  361.         else
  362.         {
  363.             fprintf(stderr, "\nt is a required argument.\n");
  364.         }
  365.         }
  366.     }
  367.     else
  368.     {
  369.         vgballse->t_flag = vget_string(fid, prompt_flag,
  370.         "-t", t_pstr, &(vgballse->t_toggle),
  371.         "integer");
  372.  
  373.         if ((((strcmp(vgballse->t_toggle, "integer") != 0)) && 
  374.              ((strcmp(vgballse->t_toggle, "byte") != 0))) ||
  375.              (!(vgballse->t_flag)))
  376.         {
  377.             fprintf(stderr, "t is a required argument.\n");
  378.             fprintf(stderr, "\n");
  379.             gw_usage();
  380.             exit(0);
  381.         }
  382.     }
  383.  
  384.     /*
  385.      * get optional arguments for vgballse
  386.      */
  387.     if (prompt_flag == TRUE)
  388.        fprintf(stderr,"\nOptional Arguments:\n\n");
  389.  
  390.     vgballse->trigger_flag = vget_infile(fid, prompt_flag,
  391.     "-trigger", trigger_pstr, &(vgballse->trigger_file))
  392. ;
  393.  
  394.     vgballse->d_flag = vget_float(fid, prompt_flag,
  395.     "-d", d_pstr, &(vgballse->d_float),
  396.     15.000000, 1.000000, 1.000000);
  397.  
  398.     vgballse->x_flag = vget_float(fid, prompt_flag,
  399.     "-x", x_pstr, &(vgballse->x_float),
  400.     8.000000, 0.000000, 0.000000);
  401.  
  402.     vgballse->y_flag = vget_float(fid, prompt_flag,
  403.     "-y", y_pstr, &(vgballse->y_float),
  404.     8.000000, 0.000000, 0.000000);
  405.  
  406.     vgballse->b_flag = vget_float(fid, prompt_flag,
  407.     "-b", b_pstr, &(vgballse->b_float),
  408.     -1.000000, 0.000000, 0.000000);
  409.  
  410.  
  411. }
  412.  
  413.  
  414.  
  415.