summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2018-07-26 02:04:05 +0200
committerLeo C2018-07-26 02:04:05 +0200
commitdd2c2ec080fbb9b9d0d3145887d05347934dddba (patch)
tree8a447788b937bf5fab7c74d112e640b837a65e29 /avr
parent1816a69880b3a19d323b2a158bca4d6656d917c3 (diff)
downloadz180-stamp-dd2c2ec080fbb9b9d0d3145887d05347934dddba.zip
heap.c: move environment from heap to static storage
Diffstat (limited to 'avr')
-rw-r--r--avr/env.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/avr/env.c b/avr/env.c
index 9fe61ea..1ec0c8e 100644
--- a/avr/env.c
+++ b/avr/env.c
@@ -12,7 +12,7 @@
#include "crc.h"
#include "getopt-min.h"
-#define DEBUG_ENV 1 /* set to 1 to debug */
+#define DEBUG_ENV 0 /* set to 1 to debug */
#define debug_env(fmt, args...) \
debug_cond(DEBUG_ENV, fmt, ##args)
@@ -38,7 +38,7 @@ const FLASH char default_env[] = {
ENV_CPM3_SYSFILE "=" CONFIG_CPM3_SYSFILE DELIM
ENV_PINALIAS "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7,"
"6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM
- ENV_STARTADDRESS "=" "0" DELIM
+ //ENV_STARTADDRESS "=" "0" DELIM
"pins" "=" "2,8 low 9 high 3 2" DELIM
DELIM
};
@@ -51,17 +51,6 @@ typedef struct environment_s {
char data[ENV_SIZE]; /* Environment data */
} env_t;
-#if 0
-/* */
-typedef struct env_item_s {
- char * envvar;
-} env_item_t;
-
-
-static uint8_t env_valid;
-static env_item_t env_list[CONFIG_ENVVAR_MAX];
-static int entrycount;
-#endif
static uint8_t env_valid;
static char env_list[ENV_SIZE];
@@ -97,7 +86,7 @@ int env_item_delete(char *ep)
{
char *next = ep + strlen(ep) + 1;
char *end = next;
- while (*end++ != 0);
+ while (*end++ != 0)
while (*end++ != 0);
memmove(ep, next, end - next);
@@ -105,6 +94,21 @@ int env_item_delete(char *ep)
return 0;
}
+static int envcmp(const char *s1, const char *s2)
+{
+ const unsigned char *u1 = (const unsigned char *)s1;
+ const unsigned char *u2 = (const unsigned char *)s2;
+ unsigned char c1, c2;
+
+ do {
+ c1 = *u1++; c2 = *u2++;
+ if (c1 == '=') c1 = '\0';
+ if (c2 == '=') c2 = '\0';
+ } while (c1 != 0 && c1 - c2 == 0);
+
+ return c1 - c2;
+}
+
static char *envlist_search(const MEMX char *name)
{
char key[CONFIG_SYS_ENV_NAMELEN + 1];
@@ -116,11 +120,9 @@ static char *envlist_search(const MEMX char *name)
key[keylen++] = c;
key[keylen] = '\0';
-debug_env("### len: %d, key: \"%s\"\n", keylen, key);
-
for (char *lp = env_list; *lp != 0; ++lp) {
- if (strncmp(lp, key, keylen) == 0)
+ if (envcmp(lp, key) == 0)
return lp;
while (*lp != 0)
@@ -134,7 +136,7 @@ static char *env_item_insert(char *pos, const char *envstr)
{
char *dstp = pos + strlen(envstr) + 1;
char *end = pos;
- while (*end++ != 0);
+ while (*end++ != 0)
while (*end++ != 0);
if (end > env_list + ENV_SIZE)
@@ -156,7 +158,7 @@ static char *envlist_enter(const char *ep)
for (lp = env_list; *lp != 0; ++lp) {
- rc = strncmp(lp, ep, len);
+ rc = envcmp(lp, ep);
if (rc >= 0)
break;