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
/
vgmopen
/
vgmopen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-26
|
8KB
|
340 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: vgmopen.c
>>>>
>>>> Program Name: vgmopen
>>>>
>>>> Program Desc:
>>>>
>>>> Open a greyscale image X, by a structuring element B.
>>>>
>>>>
>>>> Author: Pascal ADAM and Greg DONOHOE
>>>>
>>>> Date Last Updated: Sat Jul 25 11:37:04 1992
>>>>
>>>> Routines: main- the main program for vgmopen
>>>> gw_usage - gives usage of the program
>>>> gw_args - gets arguments of program from command line
>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "vgmopen.h"
/****************************************************************
*
* Routine Name: main program for vgmopen
*
* Input:
* -i input image
* -k input kernel
* -o output image
*
*
*
*
*
****************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
/* -main_variable_list */
struct xvimage *image, *kernel,*readimage();
/* -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);
READINPUT (image, kernel);
CHECKINPUT (program, image, kernel);
/* -main_before_lib_call_end */
/* -main_library_call */
if(! lvgmopen(image,kernel))
{
(void) fprintf(stderr, "vgmopen: lvgmopen Failed\n");
exit(1);
}
/* -main_library_call_end */
/* -main_after_lib_call */
writeimage(vgmopen->o_file,image);
/* -main_after_lib_call_end */
khoros_close();
}
/****************************************************************
*
* Routine Name: gw_usage
*
*
* Purpose: prints out the usage for vgmopen
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_usage()
{
fprintf(stderr, "vgmopen :\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\tOpen a greyscale image X, by a structuring element B.\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\t\n");
/* -usage_additions */
/* -usage_additions_end */
fprintf(stderr,"\t-i input image (infile)\n");
fprintf(stderr,"\t-k input kernel (infile)\n");
fprintf(stderr,"\t-o output image (outfile)\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
fprintf(stderr, " \n");
fprintf(stderr, "\n");
fprintf(stderr, "\t[-V] Gives the version for vgmopen\n");
fprintf(stderr, "\t[-U] Gives the usage for vgmopen\n");
fprintf(stderr, "\t[-P] Prompts for command line options\n");
fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgmopen.ans or file1 \n");
fprintf(stderr, "\t[-a [file1]] Uses vgmopen.ans or file1 as the answer file \n\n\n");
}
/****************************************************************
*
* Routine Name: gw_getargs
*
*
* Purpose: gets arguments off command line for vgmopen
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_get_args()
{
char *i_pstr =
"\nEnter: (i) input image \n {infile}: ";
char *k_pstr =
"\nEnter: (k) input kernel \n {infile}: ";
char *o_pstr =
"\nEnter: (o) output image \n {outfile}: ";
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",
"vgmopen", 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, "vgmopen.ans");
while (fid < 0)
{
if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
{
fprintf(stderr, "vgmopen: 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, "vgmopen.ans");
}
}
}
/*
* allocate the vgmopen structure
*/
vgmopen = (vgmopen_struct *)
calloc((unsigned)1, (unsigned) sizeof (vgmopen_struct));
/*
* get required arguments for vgmopen
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nRequired Arguments:\n\n");
if (!(vgmopen->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmopen->i_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmopen->i_flag))
{
fprintf(stderr, "\t\ti is required, please re-enter: \n");
vgmopen->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmopen->i_file))
;
}
}
else
{
fprintf(stderr, "Error: '-i' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmopen->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmopen->k_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmopen->k_flag))
{
fprintf(stderr, "\t\tk is required, please re-enter: \n");
vgmopen->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmopen->k_file))
;
}
}
else
{
fprintf(stderr, "Error: '-k' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmopen->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmopen->o_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmopen->o_flag))
{
fprintf(stderr, "\t\to is required, please re-enter: \n");
vgmopen->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmopen->o_file))
;
}
}
else
{
fprintf(stderr, "Error: '-o' is a required argument\n");
gw_usage();
exit(1);
}
}
}