summaryrefslogtreecommitdiffstats
path: root/patches/source/vim/patches/7.4.247
blob: 36006e17b32ecc4219b8127b3a3b4613d2fe16a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
To: vim_dev@googlegroups.com
Subject: Patch 7.4.247
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.4.247
Problem:    When passing input to system() there is no way to keep NUL and
	    NL characters separate.
Solution:   Optionally use a list for the system() input. (ZyX)
Files:	    runtime/doc/eval.txt, src/eval.c


*** ../vim-7.4.246/runtime/doc/eval.txt	2014-04-02 22:16:59.995482236 +0200
--- runtime/doc/eval.txt	2014-04-05 18:47:12.907153201 +0200
***************
*** 5951,5960 ****
  
  system({expr} [, {input}])				*system()* *E677*
  		Get the output of the shell command {expr}.
! 		When {input} is given, this string is written to a file and
! 		passed as stdin to the command.  The string is written as-is,
! 		you need to take care of using the correct line separators
! 		yourself.  Pipes are not used.
  		Note: Use |shellescape()| or |::S| with |expand()| or 
  		|fnamemodify()| to escape special characters in a command 
  		argument.  Newlines in {expr} may cause the command to fail.  
--- 5964,5980 ----
  
  system({expr} [, {input}])				*system()* *E677*
  		Get the output of the shell command {expr}.
! 
! 		When {input} is given and is a string this string is written 
! 		to a file and passed as stdin to the command.  The string is 
! 		written as-is, you need to take care of using the correct line 
! 		separators yourself.
! 		If {input} is given and is a |List| it is written to the file
! 		in a way |writefile()| does with {binary} set to "b" (i.e.
! 		with a newline between each list item with newlines inside
! 		list items converted to NULs).  
! 		Pipes are not used.
! 
  		Note: Use |shellescape()| or |::S| with |expand()| or 
  		|fnamemodify()| to escape special characters in a command 
  		argument.  Newlines in {expr} may cause the command to fail.  
*** ../vim-7.4.246/src/eval.c	2014-04-02 22:17:00.003482236 +0200
--- src/eval.c	2014-04-05 18:47:50.971153284 +0200
***************
*** 836,841 ****
--- 836,842 ----
  static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
  static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp));
  static void setwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
+ static int write_list __ARGS((FILE *fd, list_T *list, int binary));
  
  
  #ifdef EBCDIC
***************
*** 18267,18280 ****
  	    EMSG2(_(e_notopen), infile);
  	    goto done;
  	}
! 	p = get_tv_string_buf_chk(&argvars[1], buf);
! 	if (p == NULL)
  	{
! 	    fclose(fd);
! 	    goto done;		/* type error; errmsg already given */
  	}
- 	if (fwrite(p, STRLEN(p), 1, fd) != 1)
- 	    err = TRUE;
  	if (fclose(fd) != 0)
  	    err = TRUE;
  	if (err)
--- 18268,18289 ----
  	    EMSG2(_(e_notopen), infile);
  	    goto done;
  	}
! 	if (argvars[1].v_type == VAR_LIST)
  	{
! 	    if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL)
! 		err = TRUE;
! 	}
! 	else
! 	{
! 	    p = get_tv_string_buf_chk(&argvars[1], buf);
! 	    if (p == NULL)
! 	    {
! 		fclose(fd);
! 		goto done;		/* type error; errmsg already given */
! 	    }
! 	    if (fwrite(p, STRLEN(p), 1, fd) != 1)
! 		err = TRUE;
  	}
  	if (fclose(fd) != 0)
  	    err = TRUE;
  	if (err)
***************
*** 19173,19178 ****
--- 19182,19230 ----
  }
  
  /*
+  * Write list of strings to file
+  */
+     static int
+ write_list(fd, list, binary)
+     FILE	*fd;
+     list_T	*list;
+     int		binary;
+ {
+     listitem_T	*li;
+     int		c;
+     int		ret = OK;
+     char_u	*s;
+ 
+     for (li = list->lv_first; li != NULL; li = li->li_next)
+     {
+ 	for (s = get_tv_string(&li->li_tv); *s != NUL; ++s)
+ 	{
+ 	    if (*s == '\n')
+ 		c = putc(NUL, fd);
+ 	    else
+ 		c = putc(*s, fd);
+ 	    if (c == EOF)
+ 	    {
+ 		ret = FAIL;
+ 		break;
+ 	    }
+ 	}
+ 	if (!binary || li->li_next != NULL)
+ 	    if (putc('\n', fd) == EOF)
+ 	    {
+ 		ret = FAIL;
+ 		break;
+ 	    }
+ 	if (ret == FAIL)
+ 	{
+ 	    EMSG(_(e_write));
+ 	    break;
+ 	}
+     }
+     return ret;
+ }
+ 
+ /*
   * "writefile()" function
   */
      static void
***************
*** 19183,19192 ****
      int		binary = FALSE;
      char_u	*fname;
      FILE	*fd;
-     listitem_T	*li;
-     char_u	*s;
      int		ret = 0;
-     int		c;
  
      if (check_restricted() || check_secure())
  	return;
--- 19235,19241 ----
***************
*** 19213,19245 ****
      }
      else
      {
! 	for (li = argvars[0].vval.v_list->lv_first; li != NULL;
! 							     li = li->li_next)
! 	{
! 	    for (s = get_tv_string(&li->li_tv); *s != NUL; ++s)
! 	    {
! 		if (*s == '\n')
! 		    c = putc(NUL, fd);
! 		else
! 		    c = putc(*s, fd);
! 		if (c == EOF)
! 		{
! 		    ret = -1;
! 		    break;
! 		}
! 	    }
! 	    if (!binary || li->li_next != NULL)
! 		if (putc('\n', fd) == EOF)
! 		{
! 		    ret = -1;
! 		    break;
! 		}
! 	    if (ret < 0)
! 	    {
! 		EMSG(_(e_write));
! 		break;
! 	    }
! 	}
  	fclose(fd);
      }
  
--- 19262,19269 ----
      }
      else
      {
! 	if (write_list(fd, argvars[0].vval.v_list, binary) == FAIL)
! 	    ret = -1;
  	fclose(fd);
      }
  
*** ../vim-7.4.246/src/version.c	2014-04-05 12:02:20.751100138 +0200
--- src/version.c	2014-04-05 18:49:24.411153488 +0200
***************
*** 736,737 ****
--- 736,739 ----
  {   /* Add new patch number below this line */
+ /**/
+     247,
  /**/

-- 
Time is an illusion.  Lunchtime doubly so.
		-- Ford Prefect, in Douglas Adams'
		   "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///