Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/cmd/mk/shprint.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include	"mk.h"
2
 
3
static char *vexpand(char*, Envy*, Bufblock*);
4
static char *shquote(char*, Rune, Bufblock*);
5
static char *shbquote(char*, Bufblock*);
6
 
7
void
8
shprint(char *s, Envy *env, Bufblock *buf)
9
{
10
	int n;
11
	Rune r;
12
 
13
	while(*s) {
14
		n = chartorune(&r, s);
15
		if (r == '$')
16
			s = vexpand(s, env, buf);
17
		else {
18
			rinsert(buf, r);
19
			s += n;
20
			s = copyq(s, r, buf);	/*handle quoted strings*/
21
		}
22
	}
23
	insert(buf, 0);
24
}
25
 
26
static char *
27
mygetenv(char *name, Envy *env)
28
{
29
	if (!env)
30
		return 0;
31
	if (symlook(name, S_WESET, 0) == 0 && symlook(name, S_INTERNAL, 0) == 0)
32
		return 0;
33
		/* only resolve internal variables and variables we've set */
34
	for(; env->name; env++){
35
		if (strcmp(env->name, name) == 0)
36
			return wtos(env->values, ' ');
37
	}
38
	return 0;
39
}
40
 
41
static char *
42
vexpand(char *w, Envy *env, Bufblock *buf)
43
{
44
	char *s, carry, *p, *q;
45
 
46
	assert(/*vexpand no $*/ *w == '$');
47
	p = w+1;	/* skip dollar sign */
48
	if(*p == '{') {
49
		p++;
50
		q = utfrune(p, '}');
51
		if (!q)
52
			q = strchr(p, 0);
53
	} else
54
		q = shname(p);
55
	carry = *q;
56
	*q = 0;
57
	s = mygetenv(p, env);
58
	*q = carry;
59
	if (carry == '}')
60
		q++;
61
	if (s) {
62
		bufcpy(buf, s, strlen(s));
63
		free(s);
64
	} else 		/* copy name intact*/
65
		bufcpy(buf, w, q-w);
66
	return(q);
67
}
68
 
69
void
70
front(char *s)
71
{
72
	char *t, *q;
73
	int i, j;
74
	char *flds[512];
75
 
76
	q = strdup(s);
77
	i = getfields(q, flds, nelem(flds), 0, " \t\n");
78
	if(i > 5){
79
		flds[4] = flds[i-1];
80
		flds[3] = "...";
81
		i = 5;
82
	}
83
	t = s;
84
	for(j = 0; j < i; j++){
85
		for(s = flds[j]; *s; *t++ = *s++);
86
		*t++ = ' ';
87
	}
88
	*t = 0;
89
	free(q);
90
}