diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-02-27 21:17:21 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-02-27 21:17:21 +0000 |
commit | 148cde5e982950ad5836fa96baa466de842e1c14 (patch) | |
tree | bf737b367b91c5da81345eb21016b07400d7a72f /nuttx/lib | |
parent | f6b81a790c28d7d36d9de33810df5270c1ebbfd7 (diff) | |
download | px4-nuttx-148cde5e982950ad5836fa96baa466de842e1c14.tar.gz px4-nuttx-148cde5e982950ad5836fa96baa466de842e1c14.tar.bz2 px4-nuttx-148cde5e982950ad5836fa96baa466de842e1c14.zip |
Finally, a clean SDCC compile
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@20 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/Makefile | 2 | ||||
-rw-r--r-- | nuttx/lib/dq_addafter.c | 12 | ||||
-rw-r--r-- | nuttx/lib/dq_addbefore.c | 12 | ||||
-rw-r--r-- | nuttx/lib/dq_addfirst.c | 3 | ||||
-rw-r--r-- | nuttx/lib/dq_addlast.c | 3 | ||||
-rw-r--r-- | nuttx/lib/dq_rem.c | 7 | ||||
-rw-r--r-- | nuttx/lib/dq_remfirst.c | 7 | ||||
-rw-r--r-- | nuttx/lib/dq_remlast.c | 7 | ||||
-rw-r--r-- | nuttx/lib/lib_fclose.c | 2 | ||||
-rw-r--r-- | nuttx/lib/lib_fflush.c | 2 | ||||
-rw-r--r-- | nuttx/lib/lib_filesem.c | 10 | ||||
-rw-r--r-- | nuttx/lib/lib_fopen.c | 28 | ||||
-rw-r--r-- | nuttx/lib/lib_getenv.c | 117 | ||||
-rw-r--r-- | nuttx/lib/lib_init.c | 15 | ||||
-rw-r--r-- | nuttx/lib/lib_internal.h | 14 | ||||
-rw-r--r-- | nuttx/lib/lib_libvsprintf.c | 1 | ||||
-rw-r--r-- | nuttx/lib/lib_sscanf.c | 384 | ||||
-rw-r--r-- | nuttx/lib/lib_strdup.c | 6 | ||||
-rw-r--r-- | nuttx/lib/lib_streamsem.c | 4 | ||||
-rw-r--r-- | nuttx/lib/sq_addafter.c | 2 | ||||
-rw-r--r-- | nuttx/lib/sq_addfirst.c | 2 | ||||
-rw-r--r-- | nuttx/lib/sq_addlast.c | 2 | ||||
-rw-r--r-- | nuttx/lib/sq_rem.c | 6 | ||||
-rw-r--r-- | nuttx/lib/sq_remafter.c | 5 | ||||
-rw-r--r-- | nuttx/lib/sq_remfirst.c | 5 | ||||
-rw-r--r-- | nuttx/lib/sq_remlast.c | 6 |
26 files changed, 346 insertions, 318 deletions
diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile index 361c0bb63..c05b9e96d 100644 --- a/nuttx/lib/Makefile +++ b/nuttx/lib/Makefile @@ -91,7 +91,7 @@ $(BIN): $(OBJS) depend: .depend clean: - rm -f $(BIN) *.o *~ + rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~ distclean: clean rm -f Make.dep .depend diff --git a/nuttx/lib/dq_addafter.c b/nuttx/lib/dq_addafter.c index 5533d57a1..6be30a501 100644 --- a/nuttx/lib/dq_addafter.c +++ b/nuttx/lib/dq_addafter.c @@ -56,7 +56,7 @@ * ************************************************************/ -void dq_addafter(dq_entry_t *prev, dq_entry_t *node, +void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, dq_queue_t *queue) { if (!queue->head || prev == queue->tail) @@ -65,10 +65,10 @@ void dq_addafter(dq_entry_t *prev, dq_entry_t *node, } else { - dq_entry_t *next = prev->flink; - node->blink = prev; - node->flink = next; - next->blink = node; - prev->flink = node; + FAR dq_entry_t *next = prev->flink; + node->blink = prev; + node->flink = next; + next->blink = node; + prev->flink = node; } } diff --git a/nuttx/lib/dq_addbefore.c b/nuttx/lib/dq_addbefore.c index 916a7db61..99df05574 100644 --- a/nuttx/lib/dq_addbefore.c +++ b/nuttx/lib/dq_addbefore.c @@ -55,7 +55,7 @@ * ************************************************************/ -void dq_addbefore(dq_entry_t *next, dq_entry_t *node, +void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node, dq_queue_t *queue) { if (!queue->head || next == queue->head) @@ -64,10 +64,10 @@ void dq_addbefore(dq_entry_t *next, dq_entry_t *node, } else { - dq_entry_t *prev = next->blink; - node->flink = next; - node->blink = prev; - prev->flink = node; - next->blink = node; + FAR dq_entry_t *prev = next->blink; + node->flink = next; + node->blink = prev; + prev->flink = node; + next->blink = node; } } diff --git a/nuttx/lib/dq_addfirst.c b/nuttx/lib/dq_addfirst.c index a11b1f8c3..d73f49db1 100644 --- a/nuttx/lib/dq_addfirst.c +++ b/nuttx/lib/dq_addfirst.c @@ -55,7 +55,7 @@ * ************************************************************/ -void dq_addfirst(dq_entry_t *node, dq_queue_t *queue) +void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue) { node->blink = NULL; node->flink = queue->head; @@ -71,3 +71,4 @@ void dq_addfirst(dq_entry_t *node, dq_queue_t *queue) queue->head = node; } } + diff --git a/nuttx/lib/dq_addlast.c b/nuttx/lib/dq_addlast.c index 85c6c72a9..8d7225682 100644 --- a/nuttx/lib/dq_addlast.c +++ b/nuttx/lib/dq_addlast.c @@ -55,7 +55,7 @@ * ************************************************************/ -void dq_addlast(dq_entry_t *node, dq_queue_t *queue) +void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue) { node->flink = NULL; node->blink = queue->tail; @@ -71,3 +71,4 @@ void dq_addlast(dq_entry_t *node, dq_queue_t *queue) queue->tail = node; } } + diff --git a/nuttx/lib/dq_rem.c b/nuttx/lib/dq_rem.c index d78ac8b6d..17f2b8622 100644 --- a/nuttx/lib/dq_rem.c +++ b/nuttx/lib/dq_rem.c @@ -55,10 +55,10 @@ * ************************************************************/ -void dq_rem(dq_entry_t *node, dq_queue_t *queue) +void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue) { - dq_entry_t *prev = node->blink; - dq_entry_t *next = node->flink; + FAR dq_entry_t *prev = node->blink; + FAR dq_entry_t *next = node->flink; if (!prev) { @@ -81,3 +81,4 @@ void dq_rem(dq_entry_t *node, dq_queue_t *queue) node->flink = NULL; node->blink = NULL; } + diff --git a/nuttx/lib/dq_remfirst.c b/nuttx/lib/dq_remfirst.c index 0c7381c77..ed64fe268 100644 --- a/nuttx/lib/dq_remfirst.c +++ b/nuttx/lib/dq_remfirst.c @@ -55,13 +55,13 @@ * ************************************************************/ -dq_entry_t *dq_remfirst(dq_queue_t *queue) +FAR dq_entry_t *dq_remfirst(dq_queue_t *queue) { - dq_entry_t *ret = queue->head; + FAR dq_entry_t *ret = queue->head; if (ret) { - dq_entry_t *next = ret->flink; + FAR dq_entry_t *next = ret->flink; if (!next) { queue->head = NULL; @@ -79,3 +79,4 @@ dq_entry_t *dq_remfirst(dq_queue_t *queue) return ret; } + diff --git a/nuttx/lib/dq_remlast.c b/nuttx/lib/dq_remlast.c index 476426021..812e1f701 100644 --- a/nuttx/lib/dq_remlast.c +++ b/nuttx/lib/dq_remlast.c @@ -55,13 +55,13 @@ * ************************************************************/ -dq_entry_t *dq_remlast(dq_queue_t *queue) +FAR dq_entry_t *dq_remlast(dq_queue_t *queue) { - dq_entry_t *ret = queue->tail; + FAR dq_entry_t *ret = queue->tail; if (ret) { - dq_entry_t *prev = ret->blink; + FAR dq_entry_t *prev = ret->blink; if (!prev) { queue->head = NULL; @@ -79,3 +79,4 @@ dq_entry_t *dq_remlast(dq_queue_t *queue) return ret; } + diff --git a/nuttx/lib/lib_fclose.c b/nuttx/lib/lib_fclose.c index c1cddeb69..9985c49c2 100644 --- a/nuttx/lib/lib_fclose.c +++ b/nuttx/lib/lib_fclose.c @@ -65,7 +65,7 @@ int fclose(FILE *stream) ret = close(stream->fs_filedes); } #warning REVIEW for race conditions -#if CONFIG_NFILE_STREAMS > 0 +#if CONFIG_STDIO_BUFFER_SIZE > 0 /* Destroy the semaphore */ sem_destroy(&stream->fs_sem); diff --git a/nuttx/lib/lib_fflush.c b/nuttx/lib/lib_fflush.c index b3dbb1109..dc2c99673 100644 --- a/nuttx/lib/lib_fflush.c +++ b/nuttx/lib/lib_fflush.c @@ -88,7 +88,7 @@ /* Called by the OS when a task exits */ -void lib_flushall(struct streamlist *list) +void lib_flushall(FAR struct streamlist *list) { /* Make sure that there are streams associated with this thread */ if (list) diff --git a/nuttx/lib/lib_filesem.c b/nuttx/lib/lib_filesem.c index eb2279b9d..62b45b4bc 100644 --- a/nuttx/lib/lib_filesem.c +++ b/nuttx/lib/lib_filesem.c @@ -39,14 +39,14 @@ #include <nuttx/config.h> -#if CONFIG_STDIO_BUFFER_SIZE > 0 - #include <unistd.h> #include <semaphore.h> #include <errno.h> #include <assert.h> #include "lib_internal.h" +#if CONFIG_STDIO_BUFFER_SIZE > 0 + /************************************************************ * Definitions ************************************************************/ @@ -63,7 +63,7 @@ * lib_sem_initialize ************************************************************/ -void lib_sem_initialize(struct file_struct *stream) +void lib_sem_initialize(FAR struct file_struct *stream) { /* Initialize the LIB semaphore to one (to support one-at- * a-time access to private data sets. @@ -79,7 +79,7 @@ void lib_sem_initialize(struct file_struct *stream) * lib_take_semaphore ************************************************************/ -void lib_take_semaphore(struct file_struct *stream) +void lib_take_semaphore(FAR struct file_struct *stream) { pid_t my_pid = getpid(); @@ -115,7 +115,7 @@ void lib_take_semaphore(struct file_struct *stream) * lib_give_semaphore ************************************************************/ -void lib_give_semaphore(struct file_struct *stream) +void lib_give_semaphore(FAR struct file_struct *stream) { pid_t my_pid = getpid(); diff --git a/nuttx/lib/lib_fopen.c b/nuttx/lib/lib_fopen.c index 0a935ddd2..11bce38a2 100644 --- a/nuttx/lib/lib_fopen.c +++ b/nuttx/lib/lib_fopen.c @@ -130,14 +130,14 @@ static int lib_mode2oflags(const char *mode) * Public Functions ************************************************************/ -struct file_struct *lib_fdopen(int fd, const char *mode, - struct filelist *flist, - struct streamlist *slist) +FAR struct file_struct *lib_fdopen(int fd, const char *mode, + FAR struct filelist *flist, + FAR struct streamlist *slist) { - struct inode *inode = flist->fl_files[fd].f_inode; - FILE *stream; - int oflags = lib_mode2oflags(mode); - int i; + FAR struct inode *inode = flist->fl_files[fd].f_inode; + FILE *stream; + int oflags = lib_mode2oflags(mode); + int i; if (fd < 0 || !flist || !slist) { @@ -209,19 +209,19 @@ struct file_struct *lib_fdopen(int fd, const char *mode, FILE *fdopen(int fd, const char *mode) { - struct filelist *flist = sched_getfiles(); - struct streamlist *slist = sched_getstreams(); + FAR struct filelist *flist = sched_getfiles(); + FAR struct streamlist *slist = sched_getstreams(); return lib_fdopen(fd, mode, flist, slist); } FILE *fopen(const char *path, const char *mode) { - struct filelist *flist = sched_getfiles(); - struct streamlist *slist = sched_getstreams(); - int oflags = lib_mode2oflags(mode); - int fd = open(path, oflags, 0666); + FAR struct filelist *flist = sched_getfiles(); + FAR struct streamlist *slist = sched_getstreams(); + int oflags = lib_mode2oflags(mode); + int fd = open(path, oflags, 0666); - FILE *ret = lib_fdopen(fd, mode, flist, slist); + FILE *ret = lib_fdopen(fd, mode, flist, slist); if (!ret) { (void)close(fd); diff --git a/nuttx/lib/lib_getenv.c b/nuttx/lib/lib_getenv.c index 2c75a4f16..dd659393a 100644 --- a/nuttx/lib/lib_getenv.c +++ b/nuttx/lib/lib_getenv.c @@ -103,61 +103,68 @@ char *getenv(const char *name) const char *pend = &environment[size-1]; const char *ptmp; - dbg("getenv(ge): name=\"%s\"\n", name); - - if (name) { - - /* Process each string in the environment. */ - while (penv < pend) { - - vdbg("(ge):\tCompare to=\"%s\"\n", penv); - - /* The logic below basically implements a version of - * strcmp where the strings may be terminated with = signs. */ - ptmp = name; - for (;;) { - - /* Are we at the end of the name-to-matching? */ - if ((!*ptmp) || (*ptmp == '=')) { - - /* Yes.. are we also at the end of the matching-name? */ - if (*penv == '=') { - - /* Yes.. return the pointer to the value. */ - dbg("(ge):\tReturning \"%s\"\n", penv+1); - return ((char*)penv+1); - - } /* end if */ - else { - - /* No.. Skip to the next name matching name candidate. */ - while(*penv++); - break; - - } /* end else */ - } /* end if */ - - /* NO.. are we at the end of the matching name candidate? */ - /* OR.. do the corresponding characters not match. */ - else if (*penv != *ptmp) { - - /* Yes.. Skip to the next name matching name candidate. */ - while(*penv++); - break; - - } /* end else if */ - else { - - /* No.. try the next characters. */ - penv++; ptmp++; - - } /* end else */ - } /* end for */ - } /* end while */ - } /* end if */ + dbg("name=\"%s\"\n", name); + + if (name) + { + /* Process each string in the environment. */ + + while (penv < pend) + { + vdbg("Compare to=\"%s\"\n", penv); + + /* The logic below basically implements a version of + * strcmp where the strings may be terminated with = signs. + */ + + ptmp = name; + for (;;) + { + /* Are we at the end of the name-to-matching? */ + + if (!*ptmp || *ptmp == '=') + { + /* Yes.. are we also at the end of the matching-name? */ + + if (*penv == '=') + { + /* Yes.. return the pointer to the value. */ + + dbg("Returning \"%s\"\n", penv+1); + return ((char*)penv+1); + } + else + { + /* No.. Skip to the next name matching name candidate. */ + + while(*penv++); + break; + } + } + + /* NO.. are we at the end of the matching name candidate? + * OR.. do the corresponding characters not match. + */ + + else if (*penv != *ptmp) + { + /* Yes.. Skip to the next name matching name candidate. */ + + while(*penv++); + break; + } + else + { + /* No.. try the next characters. */ + + penv++; ptmp++; + } + } + } + } /* If we got here, then no matching string was found. */ - dbg("(ge):\tReturning NULL\n"); - return NULL; -} /* end getenv */ + dbg("Returning NULL\n"); + return NULL; +} diff --git a/nuttx/lib/lib_init.c b/nuttx/lib/lib_init.c index a8195937f..d1672de06 100644 --- a/nuttx/lib/lib_init.c +++ b/nuttx/lib/lib_init.c @@ -57,7 +57,7 @@ * Private Functions ************************************************************/ -static void _lib_semtake(struct streamlist *list) +static void _lib_semtake(FAR struct streamlist *list) { /* Take the semaphore (perhaps waiting) */ @@ -92,10 +92,10 @@ void weak_const_function lib_initialize(void) * creates the streamlist instance that is stored in the TCB. */ -struct streamlist *lib_alloclist(void) +FAR struct streamlist *lib_alloclist(void) { - struct streamlist *list; - list = (struct streamlist*)kzmalloc(sizeof(struct streamlist)); + FAR struct streamlist *list; + list = (FAR struct streamlist*)kzmalloc(sizeof(struct streamlist)); if (list) { int i; @@ -136,7 +136,7 @@ struct streamlist *lib_alloclist(void) * list. */ -void lib_addreflist(struct streamlist *list) +void lib_addreflist(FAR struct streamlist *list) { if (list) { @@ -153,7 +153,7 @@ void lib_addreflist(struct streamlist *list) * separately when the file descriptor list is freed. */ -void lib_releaselist(struct streamlist *list) +void lib_releaselist(FAR struct streamlist *list) { int crefs; if (list) @@ -178,7 +178,7 @@ void lib_releaselist(struct streamlist *list) sched_free(list); /* Initialize each FILE structure */ - +#if CONFIG_STDIO_BUFFER_SIZE > 0 for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { /* Destroy the semaphore that protects the IO buffer */ @@ -191,6 +191,7 @@ void lib_releaselist(struct streamlist *list) free(list->sl_streams[i].fs_bufstart); } } +#endif } } } diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h index 736aec54f..9d23e8bf0 100644 --- a/nuttx/lib/lib_internal.h +++ b/nuttx/lib/lib_internal.h @@ -104,8 +104,8 @@ struct lib_rawstream_s /* Defined in lib_streamsem.c */ -extern void stream_semtake(struct streamlist *list); -extern void stream_semgive(struct streamlist *list); +extern void stream_semtake(FAR struct streamlist *list); +extern void stream_semgive(FAR struct streamlist *list); /* Defined in lib_memstream.c */ @@ -135,8 +135,8 @@ extern int lib_sprintf (struct lib_stream_s *obj, /* Defined lib_libvsprintf.c */ -extern int lib_vsprintf(struct lib_stream_s *obj, - const char *src, va_list ap); +extern int lib_vsprintf(struct lib_stream_s *obj, + const char *src, va_list ap); /* Defined in lib_libwrite.c */ @@ -149,9 +149,9 @@ extern ssize_t lib_fread(void *ptr, size_t count, FILE *stream); /* Defined in lib_sem.c */ #if CONFIG_STDIO_BUFFER_SIZE > 0 -extern void lib_sem_initialize(struct file_struct *stream); -extern void lib_take_semaphore(struct file_struct *stream); -extern void lib_give_semaphore(struct file_struct *stream); +extern void lib_sem_initialize(FAR struct file_struct *stream); +extern void lib_take_semaphore(FAR struct file_struct *stream); +extern void lib_give_semaphore(FAR struct file_struct *stream); #endif /* Defined in lib_libgetbase.c */ diff --git a/nuttx/lib/lib_libvsprintf.c b/nuttx/lib/lib_libvsprintf.c index 2e60ffa22..443d17d46 100644 --- a/nuttx/lib/lib_libvsprintf.c +++ b/nuttx/lib/lib_libvsprintf.c @@ -41,6 +41,7 @@ * Included Files ************************************************************/ +#include <nuttx/compiler.h> #include <sys/types.h> #include <stdio.h> #include <string.h> diff --git a/nuttx/lib/lib_sscanf.c b/nuttx/lib/lib_sscanf.c index efd4ebcfa..13d8c3c0d 100644 --- a/nuttx/lib/lib_sscanf.c +++ b/nuttx/lib/lib_sscanf.c @@ -37,6 +37,7 @@ * Included Files ************************************************************/ +#include <nuttx/compiler.h> #include <sys/types.h> #include <stdarg.h> #include <stdlib.h> @@ -128,203 +129,214 @@ int vsscanf(char *buf, const char *s, va_list ap) /* Skip over white space */ while (isspace(*s)) - s++; + s++; /* Check for a conversion specifier */ if (*s == '%') - { - vdbg("vsscanf: Specifier found\n"); - - /* Check for qualifiers on the conversion specifier */ - s++; - for (; *s; s++) - { - vdbg("vsscanf: Processing %c\n", *s); - - if (strchr("dibouxcsefg%", *s)) - break; - if (*s == '*') - noassign = 1; - else if (*s == 'l' || *s == 'L') - lflag = 1; - else if (*s >= '1' && *s <= '9') { - for (tc = s; isdigit(*s); s++); - strncpy(tmp, tc, s - tc); - tmp[s - tc] = '\0'; - width = atoi(tmp); - /* atob(&width, tmp, 10); */ - s--; - } - } - - /* Process %s: String conversion */ - - if (*s == 's') - { - vdbg("vsscanf: Performing string conversion\n"); - - while (isspace(*buf)) - buf++; - if (!width) - { - width = strcspn(buf, spaces); - } - if (!noassign) - { - tv = va_arg(ap, char*); - strncpy(tv, buf, width); - tv[width] = '\0'; - } - buf += width; - } - - /* Process %c: Character conversion */ - - else if (*s == 'c') - { - vdbg("vsscanf: Performing character conversion\n"); - - if (!width) - width = 1; - if (!noassign) - { - tv = va_arg(ap, char*); - strncpy(tv, buf, width); - tv[width] = '\0'; - } - buf += width; - } - - /* Process %d, %o, %b, %x, %u: Various integer conversions */ - - else if (strchr("dobxu", *s)) - { - vdbg("vsscanf: Performing integer conversion\n"); - - /* Skip over any white space before the integer string */ - - while (isspace(*buf)) - buf++; - - /* The base of the integer conversion depends on the specific - * conversion specification. - */ - - if (*s == 'd' || *s == 'u') - base = 10; - else if (*s == 'x') - base = 16; - else if (*s == 'o') - base = 8; - else if (*s == 'b') - base = 2; - - /* Copy the integer string into a temporary working buffer. */ - - if (!width) - { - if (isspace(*(s + 1)) || *(s + 1) == 0) - { - width = strcspn(buf, spaces); - } - else - { - width = strchr(buf, *(s + 1)) - buf; - } - } - strncpy(tmp, buf, width); - tmp[width] = '\0'; - - vdbg("vsscanf: tmp[]=\"%s\"\n", tmp); - - /* Perform the integer conversion */ - - buf += width; - if (!noassign) - { - int *pint = va_arg(ap, int*); - int tmpint = strtol(tmp, NULL, base); - vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint); - *pint = tmpint; - } - } - - /* Process %f: Floating point conversion */ - - else if (*s == 'f') - { - vdbg("vsscanf: Performing floating point conversion\n"); - - /* Skip over any white space before the real string */ - - while (isspace(*buf)) - buf++; - - /* Copy the real string into a temporary working buffer. */ - - if (!width) - { - if (isspace(*(s + 1)) || *(s + 1) == 0) - { - width = strcspn(buf, spaces); - } - else - { - width = strchr(buf, *(s + 1)) - buf; - } - } - strncpy(tmp, buf, width); - tmp[width] = '\0'; - buf += width; - - vdbg("vsscanf: tmp[]=\"%s\"\n", tmp); - - /* Perform the floating point conversion */ - - if (!noassign) - { - /* strtod always returns a double */ - - double_t dvalue = strtod(tmp, NULL); - void *pv = va_arg(ap, void*); - - vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv); - - /* But we have to check whether we need to return a - * float or a double. - */ + { + vdbg("vsscanf: Specifier found\n"); + + /* Check for qualifiers on the conversion specifier */ + s++; + for (; *s; s++) + { + vdbg("vsscanf: Processing %c\n", *s); + + if (strchr("dibouxcsefg%", *s)) + break; + if (*s == '*') + noassign = 1; + else if (*s == 'l' || *s == 'L') + lflag = 1; + else if (*s >= '1' && *s <= '9') { + for (tc = s; isdigit(*s); s++); + strncpy(tmp, tc, s - tc); + tmp[s - tc] = '\0'; + width = atoi(tmp); + /* atob(&width, tmp, 10); */ + s--; + } + } + + /* Process %s: String conversion */ + + if (*s == 's') + { + vdbg("vsscanf: Performing string conversion\n"); + + while (isspace(*buf)) + buf++; + if (!width) + { + width = strcspn(buf, spaces); + } + if (!noassign) + { + tv = va_arg(ap, char*); + strncpy(tv, buf, width); + tv[width] = '\0'; + } + buf += width; + } + + /* Process %c: Character conversion */ + + else if (*s == 'c') + { + vdbg("vsscanf: Performing character conversion\n"); + + if (!width) + width = 1; + if (!noassign) + { + tv = va_arg(ap, char*); + strncpy(tv, buf, width); + tv[width] = '\0'; + } + buf += width; + } + + /* Process %d, %o, %b, %x, %u: Various integer conversions */ + + else if (strchr("dobxu", *s)) + { + vdbg("vsscanf: Performing integer conversion\n"); + + /* Skip over any white space before the integer string */ + + while (isspace(*buf)) + buf++; + + /* The base of the integer conversion depends on the specific + * conversion specification. + */ + + if (*s == 'd' || *s == 'u') + base = 10; + else if (*s == 'x') + base = 16; + else if (*s == 'o') + base = 8; + else if (*s == 'b') + base = 2; + + /* Copy the integer string into a temporary working buffer. */ + + if (!width) + { + if (isspace(*(s + 1)) || *(s + 1) == 0) + { + width = strcspn(buf, spaces); + } + else + { + width = strchr(buf, *(s + 1)) - buf; + } + } + strncpy(tmp, buf, width); + tmp[width] = '\0'; + + vdbg("vsscanf: tmp[]=\"%s\"\n", tmp); + + /* Perform the integer conversion */ + + buf += width; + if (!noassign) + { + int *pint = va_arg(ap, int*); +#ifdef SDCC + char *endptr; + int tmpint = strtol(tmp, &endptr, base); +#else + int tmpint = strtol(tmp, NULL, base); +#endif + vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint); + *pint = tmpint; + } + } + + /* Process %f: Floating point conversion */ + + else if (*s == 'f') + { + vdbg("vsscanf: Performing floating point conversion\n"); + + /* Skip over any white space before the real string */ + + while (isspace(*buf)) + { + buf++; + } + + /* Copy the real string into a temporary working buffer. */ + + if (!width) + { + if (isspace(*(s + 1)) || *(s + 1) == 0) + { + width = strcspn(buf, spaces); + } + else + { + width = strchr(buf, *(s + 1)) - buf; + } + } + strncpy(tmp, buf, width); + tmp[width] = '\0'; + buf += width; + + vdbg("vsscanf: tmp[]=\"%s\"\n", tmp); + + /* Perform the floating point conversion */ + + if (!noassign) + { + /* strtod always returns a double */ +#ifdef SDCC + char *endptr; + double_t dvalue = strtod(tmp,&endptr); +#else + double_t dvalue = strtod(tmp, NULL); +#endif + void *pv = va_arg(ap, void*); + + vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv); + + /* But we have to check whether we need to return a + * float or a double. + */ #ifdef CONFIG_HAVE_DOUBLE - if (lflag) - { - *((double_t*)pv) = dvalue; - } - else + if (lflag) + { + *((double_t*)pv) = dvalue; + } + else #endif - { - *((float*)pv) = (float)dvalue; - } - } - } - - if (!noassign) - count++; - width = noassign = lflag = 0; - s++; - } + { + *((float*)pv) = (float)dvalue; + } + } + } + + if (!noassign) + count++; + width = noassign = lflag = 0; + s++; + } /* Its is not a conversion specifier */ else - { - while (isspace(*buf)) - buf++; - if (*s != *buf) - break; - else - s++, buf++; - } + { + while (isspace(*buf)) + buf++; + if (*s != *buf) + break; + else + s++, buf++; + } } return count; } diff --git a/nuttx/lib/lib_strdup.c b/nuttx/lib/lib_strdup.c index 285d76c2c..4b3ff8aa5 100644 --- a/nuttx/lib/lib_strdup.c +++ b/nuttx/lib/lib_strdup.c @@ -46,12 +46,12 @@ * Global Functions ************************************************************/ -char *strdup(const char *s) +FAR char *strdup(const char *s) { - char *news = NULL; + FAR char *news = NULL; if (s) { - news = malloc(strlen(s) + 1); + news = (FAR char*)malloc(strlen(s) + 1); if (news) { strcpy(news, s); diff --git a/nuttx/lib/lib_streamsem.c b/nuttx/lib/lib_streamsem.c index d0dbad56d..515366766 100644 --- a/nuttx/lib/lib_streamsem.c +++ b/nuttx/lib/lib_streamsem.c @@ -76,7 +76,7 @@ * Public Functions ************************************************************/ -void stream_semtake(struct streamlist *list) +void stream_semtake(FAR struct streamlist *list) { /* Take the semaphore (perhaps waiting) */ @@ -90,7 +90,7 @@ void stream_semtake(struct streamlist *list) } } -void stream_semgive(struct streamlist *list) +void stream_semgive(FAR struct streamlist *list) { sem_post(&list->sl_sem); } diff --git a/nuttx/lib/sq_addafter.c b/nuttx/lib/sq_addafter.c index 896aed5ca..268365a18 100644 --- a/nuttx/lib/sq_addafter.c +++ b/nuttx/lib/sq_addafter.c @@ -56,7 +56,7 @@ * ************************************************************/ -void sq_addafter(sq_entry_t *prev, sq_entry_t *node, +void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, sq_queue_t *queue) { if (!queue->head || prev == queue->tail) diff --git a/nuttx/lib/sq_addfirst.c b/nuttx/lib/sq_addfirst.c index f59fbc568..d34677241 100644 --- a/nuttx/lib/sq_addfirst.c +++ b/nuttx/lib/sq_addfirst.c @@ -56,7 +56,7 @@ * ************************************************************/ -void sq_addfirst(sq_entry_t *node, sq_queue_t *queue) +void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue) { node->flink = queue->head; if (!queue->head) diff --git a/nuttx/lib/sq_addlast.c b/nuttx/lib/sq_addlast.c index 172808b33..f3368dcae 100644 --- a/nuttx/lib/sq_addlast.c +++ b/nuttx/lib/sq_addlast.c @@ -55,7 +55,7 @@ * the 'queue' ************************************************************/ -void sq_addlast(sq_entry_t *node, sq_queue_t *queue) +void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue) { node->flink = NULL; if (!queue->head) diff --git a/nuttx/lib/sq_rem.c b/nuttx/lib/sq_rem.c index 30a49b9b1..e5d1bbed5 100644 --- a/nuttx/lib/sq_rem.c +++ b/nuttx/lib/sq_rem.c @@ -55,7 +55,7 @@ * ************************************************************/ -void sq_rem(sq_entry_t *node, sq_queue_t *queue) +void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue) { if (queue->head && node) { @@ -69,8 +69,8 @@ void sq_rem(sq_entry_t *node, sq_queue_t *queue) } else { - sq_entry_t *prev; - for(prev = (sq_entry_t*)queue->head; + FAR sq_entry_t *prev; + for(prev = (FAR sq_entry_t*)queue->head; prev && prev->flink != node; prev = prev->flink); diff --git a/nuttx/lib/sq_remafter.c b/nuttx/lib/sq_remafter.c index 353e8ec0a..d876d3a56 100644 --- a/nuttx/lib/sq_remafter.c +++ b/nuttx/lib/sq_remafter.c @@ -56,9 +56,9 @@ * ************************************************************/ -sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue) +FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue) { - sq_entry_t *ret = node->flink; + FAR sq_entry_t *ret = node->flink; if (queue->head && ret) { if (queue->tail == ret) @@ -76,3 +76,4 @@ sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue) return ret; } + diff --git a/nuttx/lib/sq_remfirst.c b/nuttx/lib/sq_remfirst.c index dbbd5f378..3cb00c599 100644 --- a/nuttx/lib/sq_remfirst.c +++ b/nuttx/lib/sq_remfirst.c @@ -56,9 +56,9 @@ * ************************************************************/ -sq_entry_t *sq_remfirst(sq_queue_t *queue) +FAR sq_entry_t *sq_remfirst(sq_queue_t *queue) { - sq_entry_t *ret = queue->head; + FAR sq_entry_t *ret = queue->head; if (ret) { @@ -73,3 +73,4 @@ sq_entry_t *sq_remfirst(sq_queue_t *queue) return ret; } + diff --git a/nuttx/lib/sq_remlast.c b/nuttx/lib/sq_remlast.c index 35e5cda6a..0e34492a3 100644 --- a/nuttx/lib/sq_remlast.c +++ b/nuttx/lib/sq_remlast.c @@ -55,9 +55,9 @@ * ************************************************************/ -sq_entry_t *sq_remlast(sq_queue_t *queue) +FAR sq_entry_t *sq_remlast(sq_queue_t *queue) { - sq_entry_t *ret = queue->tail; + FAR sq_entry_t *ret = queue->tail; if (ret) { @@ -68,7 +68,7 @@ sq_entry_t *sq_remlast(sq_queue_t *queue) } else { - sq_entry_t *prev; + FAR sq_entry_t *prev; for(prev = queue->head; prev && prev->flink != ret; prev = prev->flink); |