home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.0.031 < prev    next >
Encoding:
Internet Message Format  |  2001-10-27  |  9.9 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.0.031
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.0.031
  11. Problem:    Nextstep doesn't have setenv() or putenv().  (John Beppu)
  12. Solution:   Move putenv() from pty.c to misc2.c
  13. Files:      src/misc2.c, src/pty.c
  14.  
  15.  
  16. *** ../vim60.30/src/misc2.c    Sun Sep 30 10:53:07 2001
  17. --- src/misc2.c    Sun Oct 28 21:49:00 2001
  18. ***************
  19. *** 5186,5188 ****
  20. --- 5187,5364 ----
  21.   
  22.   
  23.   #endif /*FEAT_PRINTER*/
  24. + /*
  25. +  * The putenv() implementation below comes from the "screen" program.
  26. +  * Included with permission from Juergen Weigert.
  27. +  * See pty.c for the copyright notice.
  28. +  */
  29. + /*
  30. +  *  putenv  --    put value into environment
  31. +  *
  32. +  *  Usage:  i = putenv (string)
  33. +  *    int i;
  34. +  *    char  *string;
  35. +  *
  36. +  *  where string is of the form <name>=<value>.
  37. +  *  Putenv returns 0 normally, -1 on error (not enough core for malloc).
  38. +  *
  39. +  *  Putenv may need to add a new name into the environment, or to
  40. +  *  associate a value longer than the current value with a particular
  41. +  *  name.  So, to make life simpler, putenv() copies your entire
  42. +  *  environment into the heap (i.e. malloc()) from the stack
  43. +  *  (i.e. where it resides when your process is initiated) the first
  44. +  *  time you call it.
  45. +  *
  46. +  *  (history removed, not very interesting.  See the "screen" sources.)
  47. +  */
  48. + #if !defined(HAVE_SETENV) && !defined(HAVE_PUTENV)
  49. + #define EXTRASIZE 5        /* increment to add to env. size */
  50. + static int  envsize = -1;    /* current size of environment */
  51. + #ifndef MACOS
  52. + extern
  53. + #endif
  54. +        char **environ;        /* the global which is your env. */
  55. + static int  findenv __ARGS((char *name)); /* look for a name in the env. */
  56. + static int  newenv __ARGS((void));    /* copy env. from stack to heap */
  57. + static int  moreenv __ARGS((void));    /* incr. size of env. */
  58. +     int
  59. + putenv(string)
  60. +     const char *string;
  61. + {
  62. +     int        i;
  63. +     char    *p;
  64. +     if (envsize < 0)
  65. +     {                /* first time putenv called */
  66. +     if (newenv() < 0)    /* copy env. to heap */
  67. +         return -1;
  68. +     }
  69. +     i = findenv((char *)string); /* look for name in environment */
  70. +     if (i < 0)
  71. +     {                /* name must be added */
  72. +     for (i = 0; environ[i]; i++);
  73. +     if (i >= (envsize - 1))
  74. +     {            /* need new slot */
  75. +         if (moreenv() < 0)
  76. +         return -1;
  77. +     }
  78. +     p = (char *)alloc((unsigned)(strlen(string) + 1));
  79. +     if (p == NULL)        /* not enough core */
  80. +         return -1;
  81. +     environ[i + 1] = 0;    /* new end of env. */
  82. +     }
  83. +     else
  84. +     {                /* name already in env. */
  85. +     p = vim_realloc(environ[i], strlen(string) + 1);
  86. +     if (p == NULL)
  87. +         return -1;
  88. +     }
  89. +     sprintf(p, "%s", string);    /* copy into env. */
  90. +     environ[i] = p;
  91. +     return 0;
  92. + }
  93. +     static int
  94. + findenv(name)
  95. +     char *name;
  96. + {
  97. +     char    *namechar, *envchar;
  98. +     int        i, found;
  99. +     found = 0;
  100. +     for (i = 0; environ[i] && !found; i++)
  101. +     {
  102. +     envchar = environ[i];
  103. +     namechar = name;
  104. +     while (*namechar && *namechar != '=' && (*namechar == *envchar))
  105. +     {
  106. +         namechar++;
  107. +         envchar++;
  108. +     }
  109. +     found = ((*namechar == '\0' || *namechar == '=') && *envchar == '=');
  110. +     }
  111. +     return found ? i - 1 : -1;
  112. + }
  113. +     static int
  114. + newenv()
  115. + {
  116. +     char    **env, *elem;
  117. +     int        i, esize;
  118. + #ifdef MACOS
  119. +     /* for Mac a new, empty environment is created */
  120. +     i = 0;
  121. + #else
  122. +     for (i = 0; environ[i]; i++)
  123. +     ;
  124. + #endif
  125. +     esize = i + EXTRASIZE + 1;
  126. +     env = (char **)alloc((unsigned)(esize * sizeof (elem)));
  127. +     if (env == NULL)
  128. +     return -1;
  129. + #ifndef MACOS
  130. +     for (i = 0; environ[i]; i++)
  131. +     {
  132. +     elem = (char *)alloc((unsigned)(strlen(environ[i]) + 1));
  133. +     if (elem == NULL)
  134. +         return -1;
  135. +     env[i] = elem;
  136. +     strcpy(elem, environ[i]);
  137. +     }
  138. + #endif
  139. +     env[i] = 0;
  140. +     environ = env;
  141. +     envsize = esize;
  142. +     return 0;
  143. + }
  144. +     static int
  145. + moreenv()
  146. + {
  147. +     int        esize;
  148. +     char    **env;
  149. +     esize = envsize + EXTRASIZE;
  150. +     env = (char **)vim_realloc((char *)environ, esize * sizeof (*env));
  151. +     if (env == 0)
  152. +     return -1;
  153. +     environ = env;
  154. +     envsize = esize;
  155. +     return 0;
  156. + }
  157. + # ifdef USE_VIMPTY_GETENV
  158. +     char_u *
  159. + vimpty_getenv(string)
  160. +     const char_u *string;
  161. + {
  162. +     int i;
  163. +     char_u *p;
  164. +     if (envsize < 0)
  165. +     return NULL;
  166. +     i = findenv((char *)string);
  167. +     if (i < 0)
  168. +     return NULL;
  169. +     p = vim_strchr((char_u *)environ[i], '=');
  170. +     return (p + 1);
  171. + }
  172. + # endif
  173. + #endif /* !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) */
  174. *** ../vim60.30/src/pty.c    Sat Jul 28 12:34:41 2001
  175. --- src/pty.c    Sun Oct 28 21:46:44 2001
  176. ***************
  177. *** 9,15 ****
  178.   /*
  179.    * The stuff in this file mostly comes from the "screen" program.
  180.    * Included with permission from Juergen Weigert.
  181. !  * Copied from "pty.c" and "putenv.c".
  182.    *
  183.    * It has been modified to work better with Vim.
  184.    * The parts that are not used in Vim have been deleted.
  185. --- 9,15 ----
  186.   /*
  187.    * The stuff in this file mostly comes from the "screen" program.
  188.    * Included with permission from Juergen Weigert.
  189. !  * Copied from "pty.c".  "putenv.c" was used for putenv() in misc2.c.
  190.    *
  191.    * It has been modified to work better with Vim.
  192.    * The parts that are not used in Vim have been deleted.
  193. ***************
  194. *** 423,597 ****
  195.       return -1;
  196.   }
  197.   #endif
  198. - /* putenv.c */
  199. - /*
  200. -  *  putenv  --    put value into environment
  201. -  *
  202. -  *  Usage:  i = putenv (string)
  203. -  *    int i;
  204. -  *    char  *string;
  205. -  *
  206. -  *  where string is of the form <name>=<value>.
  207. -  *  Putenv returns 0 normally, -1 on error (not enough core for malloc).
  208. -  *
  209. -  *  Putenv may need to add a new name into the environment, or to
  210. -  *  associate a value longer than the current value with a particular
  211. -  *  name.  So, to make life simpler, putenv() copies your entire
  212. -  *  environment into the heap (i.e. malloc()) from the stack
  213. -  *  (i.e. where it resides when your process is initiated) the first
  214. -  *  time you call it.
  215. -  *
  216. -  *  (history removed, not very interesting.  See the "screen" sources.)
  217. -  */
  218. - /* RCS_ID("$Id: pty.c,v 1.2 1999/09/19 19:50:51 mool Exp $ FAU") */
  219. - #if !defined(HAVE_SETENV) && !defined(HAVE_PUTENV)
  220. - #define EXTRASIZE 5        /* increment to add to env. size */
  221. - static int  envsize = -1;    /* current size of environment */
  222. - #ifndef MACOS
  223. - extern
  224. - #endif
  225. -        char **environ;        /* the global which is your env. */
  226. - static int  findenv __ARGS((char *name)); /* look for a name in the env. */
  227. - static int  newenv __ARGS((void));    /* copy env. from stack to heap */
  228. - static int  moreenv __ARGS((void));    /* incr. size of env. */
  229. -     int
  230. - putenv(string)
  231. -     const char *string;
  232. - {
  233. -     int        i;
  234. -     char    *p;
  235. -     if (envsize < 0)
  236. -     {                /* first time putenv called */
  237. -     if (newenv() < 0)    /* copy env. to heap */
  238. -         return -1;
  239. -     }
  240. -     i = findenv((char *)string); /* look for name in environment */
  241. -     if (i < 0)
  242. -     {                /* name must be added */
  243. -     for (i = 0; environ[i]; i++);
  244. -     if (i >= (envsize - 1))
  245. -     {            /* need new slot */
  246. -         if (moreenv() < 0)
  247. -         return -1;
  248. -     }
  249. -     p = (char *)alloc((unsigned)(strlen(string) + 1));
  250. -     if (p == NULL)        /* not enough core */
  251. -         return -1;
  252. -     environ[i + 1] = 0;    /* new end of env. */
  253. -     }
  254. -     else
  255. -     {                /* name already in env. */
  256. -     p = vim_realloc(environ[i], strlen(string) + 1);
  257. -     if (p == NULL)
  258. -         return -1;
  259. -     }
  260. -     sprintf(p, "%s", string);    /* copy into env. */
  261. -     environ[i] = p;
  262. -     return 0;
  263. - }
  264. -     static int
  265. - findenv(name)
  266. -     char *name;
  267. - {
  268. -     char    *namechar, *envchar;
  269. -     int        i, found;
  270. -     found = 0;
  271. -     for (i = 0; environ[i] && !found; i++)
  272. -     {
  273. -     envchar = environ[i];
  274. -     namechar = name;
  275. -     while (*namechar && *namechar != '=' && (*namechar == *envchar))
  276. -     {
  277. -         namechar++;
  278. -         envchar++;
  279. -     }
  280. -     found = ((*namechar == '\0' || *namechar == '=') && *envchar == '=');
  281. -     }
  282. -     return found ? i - 1 : -1;
  283. - }
  284. -     static int
  285. - newenv()
  286. - {
  287. -     char    **env, *elem;
  288. -     int        i, esize;
  289. - #ifdef MACOS
  290. -     /* for Mac a new, empty environment is created */
  291. -     i = 0;
  292. - #else
  293. -     for (i = 0; environ[i]; i++)
  294. -     ;
  295. - #endif
  296. -     esize = i + EXTRASIZE + 1;
  297. -     env = (char **)alloc((unsigned)(esize * sizeof (elem)));
  298. -     if (env == NULL)
  299. -     return -1;
  300. - #ifndef MACOS
  301. -     for (i = 0; environ[i]; i++)
  302. -     {
  303. -     elem = (char *)alloc((unsigned)(strlen(environ[i]) + 1));
  304. -     if (elem == NULL)
  305. -         return -1;
  306. -     env[i] = elem;
  307. -     strcpy(elem, environ[i]);
  308. -     }
  309. - #endif
  310. -     env[i] = 0;
  311. -     environ = env;
  312. -     envsize = esize;
  313. -     return 0;
  314. - }
  315. -     static int
  316. - moreenv()
  317. - {
  318. -     int        esize;
  319. -     char    **env;
  320. -     esize = envsize + EXTRASIZE;
  321. -     env = (char **)vim_realloc((char *)environ, esize * sizeof (*env));
  322. -     if (env == 0)
  323. -     return -1;
  324. -     environ = env;
  325. -     envsize = esize;
  326. -     return 0;
  327. - }
  328. - # ifdef USE_VIMPTY_GETENV
  329. -     char_u *
  330. - vimpty_getenv(string)
  331. -     const char_u *string;
  332. - {
  333. -     int i;
  334. -     char_u *p;
  335. -     if (envsize < 0)
  336. -     return NULL;
  337. -     i = findenv((char *)string);
  338. -     if (i < 0)
  339. -     return NULL;
  340. -     p = vim_strchr((char_u *)environ[i], '=');
  341. -     return (p + 1);
  342. - }
  343. - # endif
  344. - #endif /* !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) */
  345. --- 423,425 ----
  346. *** ../vim60.30/src/version.c    Sun Oct 28 21:23:45 2001
  347. --- src/version.c    Sun Oct 28 21:51:26 2001
  348. ***************
  349. *** 608,609 ****
  350. --- 608,611 ----
  351.   {   /* Add new patch number below this line */
  352. + /**/
  353. +     31,
  354.   /**/
  355.  
  356. -- 
  357. -rwxr-xr-x  1 root          24 Oct 29  1929 /bin/ed
  358. -rwxr-xr-t  4 root      131720 Jan  1  1970 /usr/ucb/vi
  359. -rwxr-xr-x  1 root  5.89824e37 Oct 22  1990 /usr/bin/emacs
  360.  
  361.  ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
  362. (((   Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim   )))
  363.  \\\  Help me helping AIDS orphans in Uganda - http://iccf-holland.org  ///
  364.