Jspice3
backq.c File Reference
#include "spice.h"
#include "misc.h"
#include "cpdefs.h"
#include "suffix.h"
Include dependency graph for backq.c:

Go to the source code of this file.

Functions

static wordlistbackeval ()
 
void cp_bquote (wordlist **list)
 
static wordlistbackeval (char *string)
 

Variables

char cp_back = '`'
 

Function Documentation

static wordlist* backeval ( )
static
static wordlist* backeval ( char *  string)
static

Definition at line 98 of file backq.c.

101 {
102  FILE *proc, *old;
103  wordlist *wl;
104  bool intv;
105  extern FILE *popen( );
106 
107  proc = popen(string, "r");
108  if (proc == NULL) {
109  fprintf(cp_err, "Error: can't evaluate %s.\n", string);
110  return (NULL);
111  }
112  old = cp_inp_cur;
113  cp_inp_cur = proc;
114  intv = cp_interactive;
115  cp_interactive = false;
116  cp_bqflag = true;
117  wl = cp_lexer((char *) NULL);
118  cp_bqflag = false;
119  cp_inp_cur = old;
120  cp_interactive = intv;
121  (void) pclose(proc);
122  return (wl);
123 }
bool cp_bqflag
Definition: lexical.c:51
Definition: library.c:18
FILE * cp_err
Definition: help.c:101
int pclose(FILE *fp)
Definition: libfuncs.c:41
bool cp_interactive
Definition: help.c:100
#define NULL
Definition: spdefs.h:121
wordlist * cp_lexer()
Definition: cpstd.h:21
FILE * cp_inp_cur
Definition: lexical.c:48
FILE * popen(char *cmd, char *mode) const
Definition: libfuncs.c:20
void cp_bquote ( wordlist **  list)

Definition at line 27 of file backq.c.

30 {
31  wordlist *wl, *nwl, *owl, *wlist;
32  char *s, *t, buf[BSIZE_SP], wbuf[BSIZE_SP];
33  int i;
34 
35  if (list == NULL)
36  return;
37  wlist = *list;
38 
39  for (wl = wlist; wl; wl = wl->wl_next) {
40  t = wl->wl_word;
41  if (!t)
42  continue;
43  i = 0;
44 
45  while (s = strchr(t, cp_back)) {
46  while (t < s)
47  wbuf[i++] = *t++;
48  wbuf[i] = '\0';
49  (void) strcpy(buf, ++s);
50  s = buf;
51  t++;
52  while (*s && (*s != cp_back)) {
53  /* Get s and t past the next backquote. */
54  t++;
55  s++;
56  }
57  /* What the heck, let "echo `foo" work... */
58  *s = '\0';
59  t++; /* Get past the second ` */
60  if (!(nwl = backeval(buf)) || !nwl->wl_word) {
61  wl_free(wlist);
62  *list = NULL;
63  return;
64  }
65  if (i) {
66  (void) strcpy(buf, wbuf);
67  if (nwl->wl_word) {
68  (void) strcat(buf, nwl->wl_word);
69  tfree(nwl->wl_word);
70  }
71  nwl->wl_word = copy(buf);
72  }
73  owl = wl;
74  wl = wl_splice(wl, nwl);
75  if (owl == wlist)
76  wlist = nwl;
77  (void) strcpy(buf, wl->wl_word);
78  i = strlen(buf);
79  (void) strcat(buf, t);
80  tfree(wl->wl_word);
81  wl->wl_word = copy(buf);
82  t = &wl->wl_word[i];
83  s = wl->wl_word;
84  for (i = 0; s < t; s++)
85  wbuf[i++] = *s;
86  }
87  }
88  *list = wlist;
89  return;
90 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
char * strcpy()
Definition: cddefs.h:119
Definition: library.c:18
char * copy()
void wl_free()
#define tfree(x)
Definition: cdmacs.h:22
char cp_back
Definition: backq.c:23
#define NULL
Definition: spdefs.h:121
wordlist * wl_splice()
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
static wordlist * backeval()
Definition: cddefs.h:192

Variable Documentation

char cp_back = '`'

Definition at line 23 of file backq.c.