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
/
vgdiskse
/
vgdiskse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-18
|
11KB
|
424 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: vgdiskse.c
>>>>
>>>> Program Name: vgdiskse
>>>>
>>>> Program Desc:
>>>>
>>>> Creates a image of a disk with the origin at the center
>>>>
>>>>
>>>> Author: Greg Donohoe
>>>>
>>>> Date Last Updated: Tue Aug 18 09:19:37 1992
>>>>
>>>> Routines: main- the main program for vgdiskse
>>>> gw_usage - gives usage of the program
>>>> gw_args - gets arguments of program from command line
>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "vgdiskse.h"
/****************************************************************
*
* Routine Name: main program for vgdiskse
*
* 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
* [-f] Foreground 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, vgdiskse->t_toggle)){
fprintf(stderr,"vgdiskse: 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(! lvgdiskse( &image,type, vgdiskse->b_float, vgdiskse->f_float,
vgdiskse->origin_logic, vgdiskse->x_float,vgdiskse->y_float, vgdiskse->d_float))
{
(void) fprintf(stderr, "lvgdiskse Failed\n");
exit(1);
}
/* -main_library_call_end */
/* -main_after_lib_call */
writeimage(vgdiskse->o_file,image);
/* -main_after_lib_call_end */
khoros_close();
}
/****************************************************************
*
* Routine Name: gw_usage
*
*
* Purpose: prints out the usage for vgdiskse
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_usage()
{
fprintf(stderr, "vgdiskse :\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\tCreates a image of a disk 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,"\t[-f] Foreground level (float) [0]\n");
fprintf(stderr, " \n");
fprintf(stderr, "\n");
fprintf(stderr, "\t[-V] Gives the version for vgdiskse\n");
fprintf(stderr, "\t[-U] Gives the usage for vgdiskse\n");
fprintf(stderr, "\t[-P] Prompts for command line options\n");
fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgdiskse.ans or file1 \n");
fprintf(stderr, "\t[-a [file1]] Uses vgdiskse.ans or file1 as the answer file \n\n\n");
}
/****************************************************************
*
* Routine Name: gw_getargs
*
*
* Purpose: gets arguments off command line for vgdiskse
*
* 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 *f_pstr =
"\nEnter: (f) Foreground level \n {float [0.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",
"vgdiskse", 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, "vgdiskse.ans");
while (fid < 0)
{
if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
{
fprintf(stderr, "vgdiskse: 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, "vgdiskse.ans");
}
}
}
/*
* allocate the vgdiskse structure
*/
vgdiskse = (vgdiskse_struct *)
calloc((unsigned)1, (unsigned) sizeof (vgdiskse_struct));
/*
* get required arguments for vgdiskse
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nRequired Arguments:\n\n");
if (!(vgdiskse->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgdiskse->o_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgdiskse->o_flag))
{
fprintf(stderr, "\t\to is required, please re-enter: \n");
vgdiskse->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgdiskse->o_file))
;
}
}
else
{
fprintf(stderr, "Error: '-o' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgdiskse->origin_flag = vget_logic(fid, prompt_flag,
"-origin", origin_pstr, &(vgdiskse->origin_logic), 0)))
{
if (prompt_flag == TRUE)
{
while(!(vgdiskse->origin_flag))
{
fprintf(stderr, "\t\torigin is required, please re-enter: \n");
vgdiskse->origin_flag = vget_logic(fid, prompt_flag,
"-origin", origin_pstr, &(vgdiskse->origin_logic), 0);
}
}
else
{
fprintf(stderr, "Error: '-origin' is a required argument\n");
gw_usage();
exit(1);
}
}
/*
* get required toggles for vgdiskse
*/
if (prompt_flag == TRUE)
{
ok = FALSE;
while(!ok)
{
vgdiskse->t_flag = vget_string(fid, prompt_flag,
"-t", t_pstr, &(vgdiskse->t_toggle),
"integer");
if ((((strcmp(vgdiskse->t_toggle, "integer") == 0)) ||
((strcmp(vgdiskse->t_toggle, "byte") == 0))) &&
(vgdiskse->t_flag))
ok = TRUE;
else
{
fprintf(stderr, "\nt is a required argument.\n");
}
}
}
else
{
vgdiskse->t_flag = vget_string(fid, prompt_flag,
"-t", t_pstr, &(vgdiskse->t_toggle),
"integer");
if ((((strcmp(vgdiskse->t_toggle, "integer") != 0)) &&
((strcmp(vgdiskse->t_toggle, "byte") != 0))) ||
(!(vgdiskse->t_flag)))
{
fprintf(stderr, "t is a required argument.\n");
fprintf(stderr, "\n");
gw_usage();
exit(0);
}
}
/*
* get optional arguments for vgdiskse
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nOptional Arguments:\n\n");
vgdiskse->trigger_flag = vget_infile(fid, prompt_flag,
"-trigger", trigger_pstr, &(vgdiskse->trigger_file))
;
vgdiskse->d_flag = vget_float(fid, prompt_flag,
"-d", d_pstr, &(vgdiskse->d_float),
15.000000, 1.000000, 1.000000);
vgdiskse->x_flag = vget_float(fid, prompt_flag,
"-x", x_pstr, &(vgdiskse->x_float),
8.000000, 0.000000, 0.000000);
vgdiskse->y_flag = vget_float(fid, prompt_flag,
"-y", y_pstr, &(vgdiskse->y_float),
8.000000, 0.000000, 0.000000);
vgdiskse->b_flag = vget_float(fid, prompt_flag,
"-b", b_pstr, &(vgdiskse->b_float),
-1.000000, 0.000000, 0.000000);
vgdiskse->f_flag = vget_float(fid, prompt_flag,
"-f", f_pstr, &(vgdiskse->f_float),
0.000000, 0.000000, 0.000000);
}