Thanks for the author of cclip. http://sourceforge.net/projects/cclip/
We will have following code in cclip,
- main.c
- funcs.c
- clip/clip.c
- clip/clip.h
So I modify the main.c to main.cpp, then it works.
I add some function for more alike the professional program.
For example, we won't type argument for first time use or will type "--help" or "-h" to udnerstand how to use the option.
So I add the if statement,
====================
if(argc = = 1)
{
PrintfUsage(variables);
}
====================
Then, you can just type the command, for example,
in linux,
------------------------------
$ ./main
------------------------------
In DOS,
------------------------------
$ main.exe
------------------------------
The screen will show simple information of usage,
===================================
C:\>main.exe
USAGE : main [ options] +src Default
-i inputdata Load the input data XXXX
-i inputdata Load the input data XXXX
-i inputdata Load the input data XXXX
-i inputdata Load the input data XXXX
===================================
How to add options?
- modify opt options[NUM_OPTS] in clip.c
- include right location of your new function
- modify #define NUM_OPTS 6
opt options [NUM_OPTS] = {
{ "f", 1, SHORT, Givingformat },
{ "o", 1, SHORT, SaveResult },
{ "i", 1, SHORT, LoadFile },
{ "d", 0, SHORT, display_input_data },
{ "help", 0, LONG, PrintInfo },
{ "h", 0, SHORT, PrintInfo },
};
Comparing with the usage information,
{ "f", 1, SHORT, Givingformat }means -f argument1 to active subprocedure Givingformat ( ).
{ "help", 0, LONG, PrintInfo }means --help without argument to active subprocedure PrintInfo( ).
If you need to the options with 2 or more arguments, modify the 2nd value to be the integer you want.
For example, "--G goal1 goal2 goal3", means { "G", 3, LONG, GOAL }.
NUM_OPTS must be correct with the number of entry in options [ ].
If you subprocedure is not in funcs.c, you have include it right.
For example,
#include "../funcs.c"
#include "../goal.c"
Content in goal.c will be like,
int GOAL(char *args [ ])
{
printf("argument1 is %s, argument2 is %s, argument3 is %s",args[0], args[1], args[2]);
return 0;
}
It should be workable.
Then print "argument1 is goal1, argument2 is goal2, argument3 is goal3" on the screen.
No comments:
Post a Comment