3 * ParseComand.c was originally part of FvwmForm.c.
5 * Turned into separate file 02/27/99, Dan Espen.
7 * FvwmForm is original work of Thomas Zuwei Feng.
9 * Copyright Feb 1995, Thomas Zuwei Feng. No guarantees or warantees are
10 * provided or implied in any way whatsoever. Use this program at your own
11 * risk. Permission to use, modify, and redistribute this program is hereby
12 * given, provided that this copyright is kept intact.
15 /* This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "libs/fvwmlib.h"
34 #include <sys/types.h>
35 #include <FvwmForm.h> /* common FvwmForm stuff */
40 /* Macro used in following functions */
41 #define AddChar(chr) \
44 buf = (char *)saferealloc(buf, N);\
49 /* do var substitution for command string */
50 char * ParseCommand (int dn
, char *sp
, char end
, int *dn1
, char **sp1
)
53 char c
, x
, *wp
, *cp
, *vp
;
58 if (buf
== 0) { /* if no buffer yet */
59 buf
= (char *)malloc(N
);
63 if (c
== '\0' || c
== end
) { /* end of substitution */
66 if (end
== 0) { /* if end of command reached */
67 AddChar('\0'); /* make sure theres a null */
71 if (c
== '$') { /* variable */
82 else if (x
== ')' || x
== '?' || x
== '!') {
89 for (item
= root_item_ptr
; item
!= 0;
90 item
= item
->header
.next
) {/* all items */
91 if (strcmp(var
, item
->header
.name
) == 0) {
95 for (cp
= item
->input
.value
; *cp
!= '\0'; cp
++) {
99 ParseCommand(dn
, sp
, ')', &dn2
, &sp
);
100 if ((x
== '?' && strlen(item
->input
.value
) > 0) ||
101 (x
== '!' && strlen(item
->input
.value
) == 0))
107 for (cp
= item
->choice
.value
; *cp
!= '\0'; cp
++)
110 ParseCommand(dn
, sp
, ')', &dn2
, &sp
);
111 if ((x
== '?' && item
->choice
.on
) ||
112 (x
== '!' && !item
->choice
.on
))
118 ParseCommand(dn
, sp
, ')', &dn2
, &sp
);
120 for (j
= 0; j
< item
->selection
.n
; j
++) {
121 if (item
->selection
.choices
[j
]->choice
.on
) {
122 if (added_sel
) { /* if not first sel added */
123 AddChar(' '); /* insert space before next value */
126 for (cp
= item
->selection
.choices
[j
]->choice
.value
;
138 } /* end char is $, not followed by ( */
139 /* if char is \, followed by ), want to pass thru the paren literally */
140 if (c
== '\\' && *sp
== ')') {
141 c
= *(sp
++); /* skip to the paren */