separated "standard library" string functions into bas_string.[ch]
This commit is contained in:
1
Makefile
1
Makefile
@@ -62,6 +62,7 @@ CSRCS= \
|
|||||||
$(SRCDIR)/sysinit.c \
|
$(SRCDIR)/sysinit.c \
|
||||||
$(SRCDIR)/init_fpga.c \
|
$(SRCDIR)/init_fpga.c \
|
||||||
$(SRCDIR)/bas_printf.c \
|
$(SRCDIR)/bas_printf.c \
|
||||||
|
$(SRCDIR)/bas_string.c \
|
||||||
$(SRCDIR)/BaS.c \
|
$(SRCDIR)/BaS.c \
|
||||||
$(SRCDIR)/cache.c \
|
$(SRCDIR)/cache.c \
|
||||||
$(SRCDIR)/mmc.c \
|
$(SRCDIR)/mmc.c \
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ SECTIONS
|
|||||||
objs/sd_card.o(.text)
|
objs/sd_card.o(.text)
|
||||||
objs/s19reader.o(.text)
|
objs/s19reader.o(.text)
|
||||||
objs/bas_printf.o(.text)
|
objs/bas_printf.o(.text)
|
||||||
|
objs/bas_string.o(.text)
|
||||||
objs/printf_helper.o(.text)
|
objs/printf_helper.o(.text)
|
||||||
objs/cache.o(.text)
|
objs/cache.o(.text)
|
||||||
objs/mmu.o(.text)
|
objs/mmu.o(.text)
|
||||||
|
|||||||
25
include/bas_string.h
Normal file
25
include/bas_string.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* bas_string.h
|
||||||
|
*
|
||||||
|
* Created on: 26.02.2013
|
||||||
|
* Author: mfro
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BAS_STRING_H_
|
||||||
|
#define BAS_STRING_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
extern int strncmp(const char *s1, const char *s2, int max);
|
||||||
|
extern char *strcpy(char *dst, const char *src);
|
||||||
|
extern size_t strlen(const char *str);
|
||||||
|
extern int strncat(char *dst, char *src, int max);
|
||||||
|
extern int atoi(const char *c);
|
||||||
|
|
||||||
|
#define isdigit(c) (((c) >= '0') && ((c) <= '9'))
|
||||||
|
#define isupper(c) ((c) >= 'A' && ((c) <= 'Z'))
|
||||||
|
#define islower(c) ((c) >= 'a' && ((c) <= 'z'))
|
||||||
|
#define isalpha(c) (isupper((c)) || islower(c))
|
||||||
|
#define tolower(c) (isupper(c) ? ((c) + 'a' - 'A') : (c))
|
||||||
|
|
||||||
|
#endif /* BAS_STRING_H_ */
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "MCF5475.h"
|
#include "MCF5475.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
#include "bas_string.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lexical definitions.
|
* Lexical definitions.
|
||||||
@@ -71,35 +72,6 @@ static void xputchar(int c)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define isdigit(c) (((c) >= '0') && ((c) <= '9'))
|
|
||||||
#define isupper(c) ((c) >= 'A' && ((c) <= 'Z'))
|
|
||||||
#define islower(c) ((c) >= 'a' && ((c) <= 'z'))
|
|
||||||
#define isalpha(c) (isupper((c)) || islower(c))
|
|
||||||
#define tolower(c) (isupper(c) ? ((c) + 'a' - 'A') : (c))
|
|
||||||
|
|
||||||
static int atoi(const char *c)
|
|
||||||
{
|
|
||||||
int value = 0;
|
|
||||||
while (isdigit(*c))
|
|
||||||
{
|
|
||||||
value *= 10;
|
|
||||||
value += (int) (*c - '0');
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t strlen(const char *s)
|
|
||||||
{
|
|
||||||
int length = 0;
|
|
||||||
|
|
||||||
while (*s++)
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void doprnt(void (*addchar)(int), const char *sfmt, va_list ap)
|
static void doprnt(void (*addchar)(int), const char *sfmt, va_list ap)
|
||||||
{
|
{
|
||||||
char buf[128]; /* FIXME: this gets allocated in BSS which is not reachable in -mpcrel code */
|
char buf[128]; /* FIXME: this gets allocated in BSS which is not reachable in -mpcrel code */
|
||||||
|
|||||||
65
sources/bas_string.c
Normal file
65
sources/bas_string.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* bas_string.c
|
||||||
|
*
|
||||||
|
* Created on: 26.02.2013
|
||||||
|
* Author: mfro
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bas_string.h"
|
||||||
|
|
||||||
|
int strncmp(const char *s1, const char *s2, int max)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
for (i = 0; i < max; i++);
|
||||||
|
{
|
||||||
|
cmp = (*s1++ - *s2++);
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
}
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strcpy(char *dst, const char *src)
|
||||||
|
{
|
||||||
|
char *ptr = dst;
|
||||||
|
|
||||||
|
while ((*dst++ = *src++) != '\0');
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int atoi(const char *c)
|
||||||
|
{
|
||||||
|
int value = 0;
|
||||||
|
while (isdigit(*c))
|
||||||
|
{
|
||||||
|
value *= 10;
|
||||||
|
value += (int) (*c - '0');
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t strlen(const char *s)
|
||||||
|
{
|
||||||
|
const char *start = s;
|
||||||
|
|
||||||
|
while (*s++);
|
||||||
|
|
||||||
|
return s - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int strncat(char *dst, char *src, int max)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
dst = &dst[strlen(dst) + 1];
|
||||||
|
for (i = 0; i < max && *src; i++)
|
||||||
|
{
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
*dst++ = '\0';
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
@@ -7,55 +7,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "bas_string.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "diskio.h"
|
#include "diskio.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "s19reader.h"
|
#include "s19reader.h"
|
||||||
|
|
||||||
int strncmp(const char *s1, const char *s2, int max)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int cmp;
|
|
||||||
|
|
||||||
for (i = 0; i < max; i++);
|
|
||||||
{
|
|
||||||
cmp = (*s1++ - *s2++);
|
|
||||||
if (cmp != 0) return cmp;
|
|
||||||
}
|
|
||||||
return cmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *strcpy(char *dst, const char *src)
|
|
||||||
{
|
|
||||||
while ((*dst++ = *src++));
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int strlen(char *str);
|
|
||||||
|
|
||||||
#ifdef _NOT_USED_ /* already defined in printf.c */
|
|
||||||
int strlen(char *str)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
do {} while (str[i++]);
|
|
||||||
return i - 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int strncat(char *dst, char *src, int max)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
dst = &dst[strlen(dst) + 1];
|
|
||||||
for (i = 0; i < max && *src; i++)
|
|
||||||
{
|
|
||||||
*dst++ = *src++;
|
|
||||||
}
|
|
||||||
*dst++ = '\0';
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t mx29lv640d_flash_sectors[] =
|
static uint32_t mx29lv640d_flash_sectors[] =
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user