Annotation of researchv9/X11/src/X.V11R1/lib/oldXrm/ParseCmd.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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