]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
heap.c: move environment from heap to static storage
authorLeo C <erbl259-lmu@yahoo.de>
Thu, 26 Jul 2018 00:04:05 +0000 (02:04 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Thu, 26 Jul 2018 00:04:05 +0000 (02:04 +0200)
avr/env.c

index 9fe61ea5fcc37d377b66af9b2f50dc0b339e4af1..1ec0c8eae2dae65eacc736f96fe4a588ff7a55bc 100644 (file)
--- 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;