/*
$Header: /cvsroot/easymotif/EasyMotif/EasyMotif/lib/commline.c,v 2.1 2001/11/01 09:31:56 keidel Exp $
$Log: commline.c,v $
Revision 2.1  2001/11/01 09:31:56  keidel
set revision 2  as beta version
 
Revision 1.2  2001/10/19 17:02:42  keidel
dialog. all widgets and callbacks are checked for duplication (and
automagically solved by preceeding C_'s) eventhandling contains only the reference
as resources do.
added Clipboard

Revision 1.1  2001/10/12 15:38:22  keidel
added edit-dialog and delete-dialog to pulldown menu
added display dialogs widgets, blink them, edit or delete them
bug fixes
added first Makefile support (generate it from template)
added optional (compile option) writing/reading simple-save projectfiles gzipped

* Revision 1.3  2000/02/10 06:58:52  keidel
* Linux porting changes
* changes in calib structures (multi sofs)
* Prototyping changes (us_er_)
*
* Revision 1.2  1998/02/06 06:35:13  keidel
* adaptions to option -fullwarn IRIX 6.4
*
* Revision 1.1  1996/10/08  11:26:22  keidel
* Initial revision
*
*/
/* #include <strings.h> */
#include <string.h>
#ifndef NOEASY
#include "../include/commline.h"
#else
#include "../include/commline.h"
#endif

/* ============================================================ */
/*
C	DECODER ROUTINE FOR COMMANDLINE
C	The given structure array COMMarg
C	defines the keys and acvtions.
C	COMMarg.key	character string ([4]) defining the key to react
C			it should be a standard UNIX definition as -..
C	COMMarg.result  is a character pointer (where a string may be
C			stored)
C	COMMarg.func	is an address of a function to be called
C			if actual key detected.
C			its an int function 
C			arguments are the character string as char []
C			containing the next item after key
C			and the COMMarg entry (actual entry)
C			The next ityem after key is used as function
C			argument, NOT decoded as key
C		A NULL pointer inhibits calling
C
C		if a function is given, it is called
C		if no function given, the actual key
C		is marked in *result
*/
void commline_dec(int argc , char *argv[], COMMarg *def , int nentries)
{
    int i;
    char *arg;
    while(--argc  )  /* loop all items on command line */
    {
        arg = *++argv;
        for (i = 0 ; i < nentries ; i++) /* search through all structure entries */
        {
            if(!strcmp(def[i].key, arg))
            {                     /* key found */
                if(def[i].func) 
                {
                  (*def[i].func)(*++argv ,&def[i]);
                   --argc;        /* function called, goto next key */
                }
                else *(def[i].result) = i+1 ; /* no function set .result */
                break;
            }
        }
    }
}
