Deleted Added
full compact
var.c (213760) var.c (213811)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/sh/var.c 213760 2010-10-13 04:01:01Z obrien $");
39__FBSDID("$FreeBSD: head/bin/sh/var.c 213811 2010-10-13 22:18:03Z obrien $");
40
41#include <unistd.h>
42#include <stdlib.h>
43#include <paths.h>
44
45/*
46 * Shell variables.
47 */

--- 82 unchanged lines hidden (view full) ---

130static const char *const locale_names[7] = {
131 "LC_COLLATE", "LC_CTYPE", "LC_MONETARY",
132 "LC_NUMERIC", "LC_TIME", "LC_MESSAGES", NULL
133};
134static const int locale_categories[7] = {
135 LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, LC_MESSAGES, 0
136};
137
40
41#include <unistd.h>
42#include <stdlib.h>
43#include <paths.h>
44
45/*
46 * Shell variables.
47 */

--- 82 unchanged lines hidden (view full) ---

130static const char *const locale_names[7] = {
131 "LC_COLLATE", "LC_CTYPE", "LC_MONETARY",
132 "LC_NUMERIC", "LC_TIME", "LC_MESSAGES", NULL
133};
134static const int locale_categories[7] = {
135 LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, LC_MESSAGES, 0
136};
137
138STATIC struct var **hashvar(const char *);
139STATIC int varequal(const char *, const char *);
140STATIC int localevar(const char *);
138static struct var **hashvar(const char *);
139static int varequal(const char *, const char *);
140static int localevar(const char *);
141
142/*
143 * Initialize the variable symbol tables and import the environment.
144 */
145
146#ifdef mkinit
147INCLUDE "var.h"
148MKINIT char **environ;

--- 114 unchanged lines hidden (view full) ---

263 nameeq[namelen] = '=';
264 if (val)
265 scopy(val, nameeq + namelen + 1);
266 else
267 nameeq[namelen + 1] = '\0';
268 setvareq(nameeq, flags);
269}
270
141
142/*
143 * Initialize the variable symbol tables and import the environment.
144 */
145
146#ifdef mkinit
147INCLUDE "var.h"
148MKINIT char **environ;

--- 114 unchanged lines hidden (view full) ---

263 nameeq[namelen] = '=';
264 if (val)
265 scopy(val, nameeq + namelen + 1);
266 else
267 nameeq[namelen + 1] = '\0';
268 setvareq(nameeq, flags);
269}
270
271STATIC int
271static int
272localevar(const char *s)
273{
274 const char *const *ss;
275
276 if (*s != 'L')
277 return 0;
278 if (varequal(s + 1, "ANG"))
279 return 1;

--- 7 unchanged lines hidden (view full) ---

287 return 0;
288}
289
290
291/*
292 * Sets/unsets an environment variable from a pointer that may actually be a
293 * pointer into environ where the string should not be manipulated.
294 */
272localevar(const char *s)
273{
274 const char *const *ss;
275
276 if (*s != 'L')
277 return 0;
278 if (varequal(s + 1, "ANG"))
279 return 1;

--- 7 unchanged lines hidden (view full) ---

287 return 0;
288}
289
290
291/*
292 * Sets/unsets an environment variable from a pointer that may actually be a
293 * pointer into environ where the string should not be manipulated.
294 */
295STATIC void
295static void
296change_env(const char *s, int set)
297{
298 char *eqp;
299 char *ss;
300
301 ss = savestr(s);
302 if ((eqp = strchr(ss, '=')) != NULL)
303 *eqp = '\0';

--- 270 unchanged lines hidden (view full) ---

574 prev = &vp->next;
575 }
576 }
577 }
578 initvar();
579}
580
581
296change_env(const char *s, int set)
297{
298 char *eqp;
299 char *ss;
300
301 ss = savestr(s);
302 if ((eqp = strchr(ss, '=')) != NULL)
303 *eqp = '\0';

--- 270 unchanged lines hidden (view full) ---

574 prev = &vp->next;
575 }
576 }
577 }
578 initvar();
579}
580
581
582STATIC int
582static int
583var_compare(const void *a, const void *b)
584{
585 const char *const *sa, *const *sb;
586
587 sa = a;
588 sb = b;
589 /*
590 * This compares two var=value strings which creates a different

--- 313 unchanged lines hidden (view full) ---

904}
905
906
907
908/*
909 * Find the appropriate entry in the hash table from the name.
910 */
911
583var_compare(const void *a, const void *b)
584{
585 const char *const *sa, *const *sb;
586
587 sa = a;
588 sb = b;
589 /*
590 * This compares two var=value strings which creates a different

--- 313 unchanged lines hidden (view full) ---

904}
905
906
907
908/*
909 * Find the appropriate entry in the hash table from the name.
910 */
911
912STATIC struct var **
912static struct var **
913hashvar(const char *p)
914{
915 unsigned int hashval;
916
917 hashval = ((unsigned char) *p) << 4;
918 while (*p && *p != '=')
919 hashval += (unsigned char) *p++;
920 return &vartab[hashval % VTABSIZE];
921}
922
923
924
925/*
926 * Returns true if the two strings specify the same varable. The first
927 * variable name is terminated by '='; the second may be terminated by
928 * either '=' or '\0'.
929 */
930
913hashvar(const char *p)
914{
915 unsigned int hashval;
916
917 hashval = ((unsigned char) *p) << 4;
918 while (*p && *p != '=')
919 hashval += (unsigned char) *p++;
920 return &vartab[hashval % VTABSIZE];
921}
922
923
924
925/*
926 * Returns true if the two strings specify the same varable. The first
927 * variable name is terminated by '='; the second may be terminated by
928 * either '=' or '\0'.
929 */
930
931STATIC int
931static int
932varequal(const char *p, const char *q)
933{
934 while (*p == *q++) {
935 if (*p++ == '=')
936 return 1;
937 }
938 if (*p == '=' && *(q - 1) == '\0')
939 return 1;
940 return 0;
941}
932varequal(const char *p, const char *q)
933{
934 while (*p == *q++) {
935 if (*p++ == '=')
936 return 1;
937 }
938 if (*p == '=' && *(q - 1) == '\0')
939 return 1;
940 return 0;
941}