Annotation of researchv9/X11/src/X.V11R1/lib/Xrm/ParseCmd.c, revision 1.1

1.1     ! root        1: /* $Header: ParseCmd.c,v 1.1 87/09/12 12:26:56 toddb Exp $ */
        !             2: /* $Header: ParseCmd.c,v 1.1 87/09/12 12:26:56 toddb Exp $ */
        !             3: #ifndef lint
        !             4: static char *sccsid = "@(#)ParseCommand.c      1.2     2/25/87";
        !             5: #endif lint
        !             6: 
        !             7: /*
        !             8:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !             9:  * 
        !            10:  *                         All Rights Reserved
        !            11:  * 
        !            12:  * Permission to use, copy, modify, and distribute this software and its 
        !            13:  * documentation for any purpose and without fee is hereby granted, 
        !            14:  * provided that the above copyright notice appear in all copies and that
        !            15:  * both that copyright notice and this permission notice appear in 
        !            16:  * supporting documentation, and that the name of Digital Equipment
        !            17:  * Corporation not be used in advertising or publicity pertaining to
        !            18:  * distribution of the software without specific, written prior permission.  
        !            19:  * 
        !            20:  * 
        !            21:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            22:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            23:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            24:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            25:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            26:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            27:  * SOFTWARE.
        !            28:  */
        !            29: 
        !            30: 
        !            31: /* XrmParseCommand.c 
        !            32:    Parse command line and store argument values into resource database */
        !            33: 
        !            34: #include "Xlib.h"
        !            35: #include "Xlibos.h"
        !            36: #include "Xresource.h"
        !            37: #include "Quarks.h"
        !            38: #include <stdio.h>
        !            39: #include <sys/types.h>
        !            40: 
        !            41: 
        !            42: void XrmParseCommand(rdb, table, tableCount, prependName, argc, argv)
        !            43:     XrmResourceDataBase *rdb;          /* data base */
        !            44:     XrmOptionDescList  table;          /* pointer to table of valid options */
        !            45:     int                        tableCount;     /* number of options                 */
        !            46:     XrmAtom            prependName;    /* application name to prepend       */
        !            47:     int                        *argc;          /* address of argument count         */
        !            48:     char               **argv;         /* argument list (command line)      */
        !            49: {
        !            50:     Bool               foundOption;
        !            51:     static XrmQuark    fullName[100];
        !            52:     XrmQuark           *resourceName;
        !            53:     char               **argsave;
        !            54:     XrmValue           resourceValue;
        !            55:     int                i, j, myargc;
        !            56: 
        !            57:     myargc = (*argc); 
        !            58:     argsave = ++argv;
        !            59:     if (prependName == NULLATOM) {
        !            60:         resourceName = fullName;
        !            61:     } else {
        !            62:        fullName[0] = XrmAtomToQuark(prependName);
        !            63:        resourceName = &fullName[1];
        !            64:     }
        !            65: 
        !            66:     for (--myargc; myargc>0;--myargc, ++argv) {
        !            67:        foundOption = False;
        !            68:        for (i=0; (!foundOption) && i < tableCount; ++i) {
        !            69:            foundOption = True;
        !            70:            for (j =0; table[i].option[j] != NULL; ++j) {
        !            71:                if (table[i].option[j] != (*argv)[j]) {
        !            72:                    foundOption = False;
        !            73:                    break;
        !            74:                }
        !            75:            }
        !            76: 
        !            77:            if (foundOption
        !            78:             && ((table[i].argKind == XrmoptionStickyArg)
        !            79:                 || (table[i].argKind == XrmoptionIsArg)
        !            80:                 || ((*argv)[j] == NULL))) {
        !            81:                switch (table[i].argKind){
        !            82:                case XrmoptionNoArg:
        !            83:                    resourceValue.addr = table[i].value;
        !            84:                    --(*argc);
        !            85:                    resourceValue.size = strlen(resourceValue.addr)+1;
        !            86:                    XrmStringToQuarkList(table[i].resourceName, resourceName);
        !            87:                    XrmPutResource(rdb, fullName, XrmQString, &resourceValue);
        !            88:                    break;
        !            89:                            
        !            90:                case XrmoptionIsArg:
        !            91:                    resourceValue.addr = (caddr_t)((*argv));
        !            92:                    --(*argc);
        !            93:                    resourceValue.size = strlen(resourceValue.addr)+1;
        !            94:                    XrmStringToQuarkList(table[i].resourceName, resourceName);
        !            95:                    XrmPutResource(rdb, fullName, XrmQString, &resourceValue);
        !            96:                    break;
        !            97: 
        !            98:                case XrmoptionStickyArg:
        !            99:                    resourceValue.addr = (caddr_t)((*argv)+j);
        !           100:                    --(*argc);
        !           101:                    resourceValue.size = strlen(resourceValue.addr)+1;
        !           102:                    XrmStringToQuarkList(table[i].resourceName, resourceName);
        !           103:                    XrmPutResource(rdb, fullName, XrmQString, &resourceValue);
        !           104:                    break;
        !           105: 
        !           106:                case XrmoptionSepArg:
        !           107:                    ++argv; --myargc; --(*argc); --(*argc);
        !           108:                    resourceValue.addr = (caddr_t)(*argv);
        !           109:                    resourceValue.size = strlen(resourceValue.addr)+1;
        !           110:                    XrmStringToQuarkList(table[i].resourceName, resourceName);
        !           111:                    XrmPutResource(rdb, fullName, XrmQString, &resourceValue);
        !           112:                    break;
        !           113:                
        !           114:                case XrmoptionSkipArg:
        !           115:                    --myargc;
        !           116:                    (*argsave++) = (*argv++);
        !           117:                    (*argsave++) = (*argv); 
        !           118:                    break;
        !           119: 
        !           120:                case XrmoptionSkipLine:
        !           121:                    for (;myargc>0;myargc--)
        !           122:                        (*argsave++) = (*argv++);
        !           123:                    break;
        !           124: 
        !           125:                }
        !           126:            } else foundOption = False;
        !           127: 
        !           128:        }
        !           129:        
        !           130:        if (!foundOption) 
        !           131:            (*argsave++) = (*argv);  /*compress arglist*/ 
        !           132:     }
        !           133: 
        !           134:     (*argsave)=NULL; /* put NULL terminator on compressed argv */
        !           135: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.