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 >
Wrap
C/C++ Source or Header
|
1992-07-28
|
11KB
|
415 lines
/*
* Khoros: $Id$
*/
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "Khoros: $Id$";
#endif
/*
* $Log$
*/
/*
*----------------------------------------------------------------------
*
* Copyright 1992, University of New Mexico. All rights reserved.
* Permission to copy and modify this software and its documen-
* tation only for internal use in your organization is hereby
* granted, provided that this notice is retained thereon and
* on all copies. UNM makes no representations as to the sui-
* tability and operability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
* NESS. IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
* SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
* FORMANCE OF THIS SOFTWARE.
*
* No other rights, including, for example, the right to redis-
* tribute this software and its documentation or the right to
* prepare derivative works, are granted unless specifically
* provided in a separate license agreement.
*---------------------------------------------------------------------
*/
#include "unmcopyright.h" /* Copyright 1992 by UNM */
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>
>>>> File Name: vgballse.c
>>>>
>>>> Program Name: vgballse
>>>>
>>>> Program Desc:
>>>>
>>>> Creates a image of a ball with the origin at the center
>>>>
>>>>
>>>> Author: Greg Donohoe
>>>>
>>>> Date Last Updated: Tue Jul 28 16:40:35 1992
>>>>
>>>> Routines: main- the main program for vgballse
>>>> gw_usage - gives usage of the program
>>>> gw_args - gets arguments of program from command line
>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "vgballse.h"
/****************************************************************
*
* Routine Name: main program for vgballse
*
* Input:
* -o output image
* -origin origin at center
* -t Selects data type of output image
* 'integer' (choose Integer data storage type),
* or 'byte' (choose Byte data storage type)
*
*
*
* [-trigger] trigger input
* [-d] Diameter of circle (in pixels) (value >= 0.0)
* [-x] X coordinate of origin
* [-y] Y coordinate of origin
* [-b] Background level
*
*
*
****************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
/* -main_variable_list */
struct xvimage *image;
int type;
/* -main_variable_list_end */
program = VStrcpy(argv[0]);
ac = argc;
av = argv;
khoros_init();
gw_get_args();
/* -main_before_lib_call */
if(check_args())exit(1);
if(!vget_type(&type, vgballse->t_toggle)){
fprintf(stderr,"vgballse: Invalid data type specified\n");
exit(1);
}
if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
fprintf(stderr,"%s: Illegal image data type specified.\n",program);
exit(1);
}
/* -main_before_lib_call_end */
/* -main_library_call */
if(! lvgballse( &image, type, vgballse->b_float, vgballse->x_float,vgballse->y_float, vgballse->origin_logic, vgballse->d_float))
{
(void) fprintf(stderr, "lvgballse Failed\n");
exit(1);
}
/* -main_library_call_end */
/* -main_after_lib_call */
writeimage(vgballse->o_file,image);
/* -main_after_lib_call_end */
khoros_close();
}
/****************************************************************
*
* Routine Name: gw_usage
*
*
* Purpose: prints out the usage for vgballse
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_usage()
{
fprintf(stderr, "vgballse :\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\tCreates a image of a ball with the origin at the center\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\t\n");
/* -usage_additions */
/* -usage_additions_end */
fprintf(stderr,"\t-o output image (outfile)\n");
fprintf(stderr,"\t-origin origin at center (boolean)\n");
fprintf(stderr, "\t-t ");
fprintf(stderr, "Selects data type of output image\n ");
fprintf(stderr, "\t\t'integer' (choose Integer data storage type),\n");
fprintf(stderr, "\t\t or 'byte' (choose Byte data storage type)\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
fprintf(stderr,"\t[-trigger] trigger input (infile) [null]\n");
fprintf(stderr,"\t[-d] Diameter of circle (in pixels) (float, >= 0.0) [15]\n");
fprintf(stderr,"\t[-x] X coordinate of origin (float) [8]\n");
fprintf(stderr,"\t[-y] Y coordinate of origin (float) [8]\n");
fprintf(stderr,"\t[-b] Background level (float) [-1]\n");
fprintf(stderr, " \n");
fprintf(stderr, "\n");
fprintf(stderr, "\t[-V] Gives the version for vgballse\n");
fprintf(stderr, "\t[-U] Gives the usage for vgballse\n");
fprintf(stderr, "\t[-P] Prompts for command line options\n");
fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgballse.ans or file1 \n");
fprintf(stderr, "\t[-a [file1]] Uses vgballse.ans or file1 as the answer file \n\n\n");
}
/****************************************************************
*
* Routine Name: gw_getargs
*
*
* Purpose: gets arguments off command line for vgballse
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_get_args()
{
char *o_pstr =
"\nEnter: (o) output image \n {outfile}: ";
char *origin_pstr =
"\nEnter: (origin) origin at center \n {boolean, (y/n) }: ";
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 : ";
char *trigger_pstr =
"\nEnter: (trigger) trigger input \n {infile}: ";
char *d_pstr =
"\nEnter: (d) Diameter of circle (in pixels) \n {float, >= 0.0 [15.000000] }: ";
char *x_pstr =
"\nEnter: (x) X coordinate of origin \n {float [8.000000] }: ";
char *y_pstr =
"\nEnter: (y) Y coordinate of origin \n {float [8.000000] }: ";
char *b_pstr =
"\nEnter: (b) Background level \n {float [-1.000000] }: ";
char answer_file[512], temp[512];
int fid = -1,
error, query, ok, count;
int prompt_flag = FALSE;
/*
* print version if necessary
*/
vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
printf ("\n%s: %s: Version %d.%d\n\n",
"vgballse", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
exit(1);
}
/*
* print usage if necessary
*/
vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
gw_usage();
exit(1);
}
/*
* see if interactive prompting is desired
*/
vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
if (error == 0)
prompt_flag = TRUE;
/*
* see if answer file is to be used
*/
vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
if (error == 0)
{
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgballse.ans");
while (fid < 0)
{
if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
{
fprintf(stderr, "vgballse: can't open answer file \"%s\"",
answer_file);
fprintf(stderr, "please re-enter: ");
(void) gets(answer_file);
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgballse.ans");
}
}
}
/*
* allocate the vgballse structure
*/
vgballse = (vgballse_struct *)
calloc((unsigned)1, (unsigned) sizeof (vgballse_struct));
/*
* get required arguments for vgballse
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nRequired Arguments:\n\n");
if (!(vgballse->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgballse->o_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgballse->o_flag))
{
fprintf(stderr, "\t\to is required, please re-enter: \n");
vgballse->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgballse->o_file))
;
}
}
else
{
fprintf(stderr, "Error: '-o' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgballse->origin_flag = vget_logic(fid, prompt_flag,
"-origin", origin_pstr, &(vgballse->origin_logic), 0)))
{
if (prompt_flag == TRUE)
{
while(!(vgballse->origin_flag))
{
fprintf(stderr, "\t\torigin is required, please re-enter: \n");
vgballse->origin_flag = vget_logic(fid, prompt_flag,
"-origin", origin_pstr, &(vgballse->origin_logic), 0);
}
}
else
{
fprintf(stderr, "Error: '-origin' is a required argument\n");
gw_usage();
exit(1);
}
}
/*
* get required toggles for vgballse
*/
if (prompt_flag == TRUE)
{
ok = FALSE;
while(!ok)
{
vgballse->t_flag = vget_string(fid, prompt_flag,
"-t", t_pstr, &(vgballse->t_toggle),
"integer");
if ((((strcmp(vgballse->t_toggle, "integer") == 0)) ||
((strcmp(vgballse->t_toggle, "byte") == 0))) &&
(vgballse->t_flag))
ok = TRUE;
else
{
fprintf(stderr, "\nt is a required argument.\n");
}
}
}
else
{
vgballse->t_flag = vget_string(fid, prompt_flag,
"-t", t_pstr, &(vgballse->t_toggle),
"integer");
if ((((strcmp(vgballse->t_toggle, "integer") != 0)) &&
((strcmp(vgballse->t_toggle, "byte") != 0))) ||
(!(vgballse->t_flag)))
{
fprintf(stderr, "t is a required argument.\n");
fprintf(stderr, "\n");
gw_usage();
exit(0);
}
}
/*
* get optional arguments for vgballse
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nOptional Arguments:\n\n");
vgballse->trigger_flag = vget_infile(fid, prompt_flag,
"-trigger", trigger_pstr, &(vgballse->trigger_file))
;
vgballse->d_flag = vget_float(fid, prompt_flag,
"-d", d_pstr, &(vgballse->d_float),
15.000000, 1.000000, 1.000000);
vgballse->x_flag = vget_float(fid, prompt_flag,
"-x", x_pstr, &(vgballse->x_float),
8.000000, 0.000000, 0.000000);
vgballse->y_flag = vget_float(fid, prompt_flag,
"-y", y_pstr, &(vgballse->y_float),
8.000000, 0.000000, 0.000000);
vgballse->b_flag = vget_float(fid, prompt_flag,
"-b", b_pstr, &(vgballse->b_float),
-1.000000, 0.000000, 0.000000);
}