diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2ea82d6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +language: c + +notifications: + email: true + +git: + depth: 1 + +before_script: + - USER_NAME='liu2guang' REPO_NAME='argparse' + + - sudo apt-get update + - "sudo apt-get -qq install gcc-multilib libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 libsdl-dev || true" + - "[ $RTT_TOOL_CHAIN = 'sourcery-arm' ] && curl -s https://launchpadlibrarian.net/287101520/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-5_4-2016q3/bin && /opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc --version || true" + + - git clone --depth=3 --branch=master https://github.com/RT-Thread/rt-thread.git ../RT-Thread + + - export RTT_ROOT=/home/travis/build/$USER_NAME/RT-Thread + - "[ x$RTT_CC == x ] && export RTT_CC='gcc' || true" + + - sudo mkdir $RTT_ROOT/bsp/$RTT_BSP/packages + - sudo cp /home/travis/build/$USER_NAME/$REPO_NAME/script/script_bspcfg $RTT_ROOT/bsp/$RTT_BSP/rtconfig.h + - sudo cp /home/travis/build/$USER_NAME/$REPO_NAME/script/script_scons $RTT_ROOT/bsp/$RTT_BSP/packages/SConscript + - sudo cp -r /home/travis/build/$USER_NAME/$REPO_NAME $RTT_ROOT/bsp/$RTT_BSP/packages/$REPO_NAME + +script: + - scons -C $RTT_ROOT/bsp/$RTT_BSP + +env: + - RTT_BSP='imxrt1052-evk' RTT_TOOL_CHAIN='sourcery-arm' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..248daf0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + + The MIT License (MIT) + Copyright (c) 2018 liu2guang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/SConscript b/SConscript new file mode 100644 index 0000000..ced9dc5 --- /dev/null +++ b/SConscript @@ -0,0 +1,75 @@ +# -*- coding:utf-8 –*- +# @File: Sconscript +# @Author: buildpkg.exe +# @Date: 2018-09-19 18:07:00(The date the template was created) +# +# @LICENSE: https://github.com/rtpkgs/buildpkg/blob/master/LICENSE. +# +# Change Logs: +# Date Author Notes +# 20xx-xx-xx buildpkg.exe auto create by buildpkg.exe. + +import os +from building import * + +# Get current dir path +cwd = GetCurrentDir() + +# Init inc_list and src_list vars +inc = [] +src = [] + +# debug info +print(inc) +print(src) + +# Remove ignore src and +list_ignore_inc = [] +list_ignore_src = [] + +# -------------------------------------------------------------------------------- +# user add ignore: +# -------------------------------------------------------------------------------- +list_ignore_inc += [] +list_ignore_src += [] + +# -------------------------------------------------------------------------------- +# auto add ignore: +# -------------------------------------------------------------------------------- +list_ignore_inc += ['.git', 'example', 'doc', 'test'] +list_ignore_src += ['test.c', 'example.c'] + +# Traverse package, add code and path to project +def traverse_package(f): + fs = os.listdir(f) + for f1 in fs: + tmp_path = os.path.join(f, f1) + filename = os.path.basename(tmp_path) + + if os.path.isdir(tmp_path): # dir + if not filename in list_ignore_inc: + print("DIR: " + filename) + inc.append(f) + traverse_package(tmp_path) + else: # file + suffix = os.path.splitext(tmp_path)[1] + if suffix == '.c' and not filename in list_ignore_src: + #print("FILE: " + filename) + src.append(tmp_path) + elif suffix == '.h': + inc.append(f) + +traverse_package(cwd) + +# Add group to IDE project +objs = DefineGroup('argparse-v1.0.1', src, depend = ['PKG_USING_ARGPARSE'], CPPPATH = inc) + +# Traversal subscript +list = os.listdir(cwd) +if GetDepend(['PKG_USING_ARGPARSE']): + for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') \ No newline at end of file diff --git a/argparse/.gitignore b/argparse/.gitignore new file mode 100644 index 0000000..fb716d2 --- /dev/null +++ b/argparse/.gitignore @@ -0,0 +1,5 @@ +tags +test_argparse +*.[ao] +*.dylib +*.so diff --git a/argparse/.travis.yml b/argparse/.travis.yml new file mode 100644 index 0000000..41bac87 --- /dev/null +++ b/argparse/.travis.yml @@ -0,0 +1,5 @@ +language: c +compiler: + - gcc + - clang +script: make test diff --git a/argparse/LICENSE b/argparse/LICENSE new file mode 100644 index 0000000..3c77749 --- /dev/null +++ b/argparse/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2012-2013 Yecheng Fu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/argparse/Makefile b/argparse/Makefile new file mode 100644 index 0000000..ca5a053 --- /dev/null +++ b/argparse/Makefile @@ -0,0 +1,52 @@ +# Defaults +CFLAGS ?= -O3 -g -ggdb +LDFLAGS ?= + +BASIC_CFLAGS = -Wall -Wextra -fPIC +BASIC_LDFLAGS = + +# We use ALL_* variants +ALL_CFLAGS = $(BASIC_CFLAGS) $(CFLAGS) +ALL_LDFLAGS = $(BASIC_LDFLAGS) $(LDFLAGS) + +LIBNAME=libargparse + +DYLIBSUFFIX=so +STLIBSUFFIX=a +DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) +DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS) +STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) +STLIB_MAKE_CMD=ar rcs $(STLIBNAME) + +# Platform-specific overrides +uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') +ifeq ($(uname_S),Darwin) +DYLIBSUFFIX=dylib +DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS) +endif + +all: $(DYLIBNAME) $(STLIBNAME) + +OBJS += argparse.o +OBJS += test_argparse.o + +$(OBJS): %.o: %.c + $(CC) -o $*.o -c $(ALL_CFLAGS) $< + +$(DYLIBNAME): argparse.o + $(DYLIB_MAKE_CMD) $^ + +$(STLIBNAME): argparse.o + $(STLIB_MAKE_CMD) $^ + +test: test_argparse + @echo "###### Unit Test #####" + @./test.sh + +test_argparse: $(OBJS) + $(CC) $(ALL_CFLAGS) -o $@ $^ $(ALL_LDFLAGS) + +clean: + rm -rf test_argparse + rm -rf *.[ao] + rm -rf *.dylib diff --git a/argparse/README.md b/argparse/README.md new file mode 100644 index 0000000..ddf66b4 --- /dev/null +++ b/argparse/README.md @@ -0,0 +1,103 @@ +# argparse [![Build Status](https://travis-ci.org/cofyc/argparse.png)](https://travis-ci.org/cofyc/argparse) + +argparse - A command line arguments parsing library in C (compatible with C++). + +## Description + +This module is inspired by parse-options.c (git) and python's argparse +module. + +Arguments parsing is common task in cli program, but traditional `getopt` +libraries are not easy to use. This library provides high-level arguments +parsing solutions. + +The program defines what arguments it requires, and `argparse` will figure +out how to parse those out of `argc` and `argv`, it also automatically +generates help and usage messages and issues errors when users give the +program invalid arguments. + +## Features + + - handles both optional and positional arguments + - produces highly informative usage messages + - issues errors when given invalid arguments + +There are basically three types of options: + + - boolean options + - options with mandatory argument + - options with optional argument + +There are basically two forms of options: + + - short option consist of one dash (`-`) and one alphanumeric character. + - long option begin with two dashes (`--`) and some alphanumeric characters. + +Short options may be bundled, e.g. `-a -b` can be specified as `-ab`. + +Options are case-sensitive. + +Options and non-option arguments can clearly be separated using the `--` option. + +## Examples + +```c +#include "argparse.h" + +static const char *const usage[] = { + "test_argparse [options] [[--] args]", + "test_argparse [options]", + NULL, +}; + +#define PERM_READ (1<<0) +#define PERM_WRITE (1<<1) +#define PERM_EXEC (1<<2) + +int +main(int argc, const char **argv) +{ + int force = 0; + int test = 0; + int num = 0; + const char *path = NULL; + int perms = 0; + struct argparse_option options[] = { + OPT_HELP(), + OPT_GROUP("Basic options"), + OPT_BOOLEAN('f', "force", &force, "force to do"), + OPT_BOOLEAN('t', "test", &test, "test only"), + OPT_STRING('p', "path", &path, "path to read"), + OPT_INTEGER('n', "num", &num, "selected num"), + OPT_GROUP("Bits options"), + OPT_BIT(0, "read", &perms, "read perm", NULL, PERM_READ, OPT_NONEG), + OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE), + OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC), + OPT_END(), + }; + + struct argparse argparse; + argparse_init(&argparse, options, usage, 0); + argparse_describe(&argparse, "\nA brief description of what the program does and how it works.", "\nAdditional description of the program after the description of the arguments."); + argc = argparse_parse(&argparse, argc, argv); + if (force != 0) + printf("force: %d\n", force); + if (test != 0) + printf("test: %d\n", test); + if (path != NULL) + printf("path: %s\n", path); + if (num != 0) + printf("num: %d\n", num); + if (argc != 0) { + printf("argc: %d\n", argc); + int i; + for (i = 0; i < argc; i++) { + printf("argv[%d]: %s\n", i, *(argv + i)); + } + } + if (perms) { + printf("perms: %d\n", perms); + } + return 0; +} +``` diff --git a/argparse/argparse.c b/argparse/argparse.c new file mode 100644 index 0000000..a9e00db --- /dev/null +++ b/argparse/argparse.c @@ -0,0 +1,385 @@ +/** + * Copyright (C) 2012-2015 Yecheng Fu + * All rights reserved. + * + * Use of this source code is governed by a MIT-style license that can be found + * in the LICENSE file. + */ +#include +#include +#include +#include +#include +#include "argparse.h" + +#define OPT_UNSET 1 +#define OPT_LONG (1 << 1) + +static const char * +prefix_skip(const char *str, const char *prefix) +{ + size_t len = strlen(prefix); + return strncmp(str, prefix, len) ? NULL : str + len; +} + +static int +prefix_cmp(const char *str, const char *prefix) +{ + for (;; str++, prefix++) + if (!*prefix) { + return 0; + } else if (*str != *prefix) { + return (unsigned char)*prefix - (unsigned char)*str; + } +} + +static void +argparse_error(struct argparse *self, const struct argparse_option *opt, + const char *reason, int flags) +{ + (void)self; + if (flags & OPT_LONG) { + fprintf(stderr, "error: option `--%s` %s\n", opt->long_name, reason); + } else { + fprintf(stderr, "error: option `-%c` %s\n", opt->short_name, reason); + } + exit(1); +} + +static int +argparse_getvalue(struct argparse *self, const struct argparse_option *opt, + int flags) +{ + const char *s = NULL; + if (!opt->value) + goto skipped; + switch (opt->type) { + case ARGPARSE_OPT_BOOLEAN: + if (flags & OPT_UNSET) { + *(int *)opt->value = *(int *)opt->value - 1; + } else { + *(int *)opt->value = *(int *)opt->value + 1; + } + if (*(int *)opt->value < 0) { + *(int *)opt->value = 0; + } + break; + case ARGPARSE_OPT_BIT: + if (flags & OPT_UNSET) { + *(int *)opt->value &= ~opt->data; + } else { + *(int *)opt->value |= opt->data; + } + break; + case ARGPARSE_OPT_STRING: + if (self->optvalue) { + *(const char **)opt->value = self->optvalue; + self->optvalue = NULL; + } else if (self->argc > 1) { + self->argc--; + *(const char **)opt->value = *++self->argv; + } else { + argparse_error(self, opt, "requires a value", flags); + } + break; + case ARGPARSE_OPT_INTEGER: + errno = 0; + if (self->optvalue) { + *(int *)opt->value = strtol(self->optvalue, (char **)&s, 0); + self->optvalue = NULL; + } else if (self->argc > 1) { + self->argc--; + *(int *)opt->value = strtol(*++self->argv, (char **)&s, 0); + } else { + argparse_error(self, opt, "requires a value", flags); + } + if (errno) + argparse_error(self, opt, strerror(errno), flags); + if (s[0] != '\0') + argparse_error(self, opt, "expects an integer value", flags); + break; + case ARGPARSE_OPT_FLOAT: + errno = 0; + if (self->optvalue) { + *(float *)opt->value = strtof(self->optvalue, (char **)&s); + self->optvalue = NULL; + } else if (self->argc > 1) { + self->argc--; + *(float *)opt->value = strtof(*++self->argv, (char **)&s); + } else { + argparse_error(self, opt, "requires a value", flags); + } + if (errno) + argparse_error(self, opt, strerror(errno), flags); + if (s[0] != '\0') + argparse_error(self, opt, "expects a numerical value", flags); + break; + default: + assert(0); + } + +skipped: + if (opt->callback) { + return opt->callback(self, opt); + } + + return 0; +} + +static void +argparse_options_check(const struct argparse_option *options) +{ + for (; options->type != ARGPARSE_OPT_END; options++) { + switch (options->type) { + case ARGPARSE_OPT_END: + case ARGPARSE_OPT_BOOLEAN: + case ARGPARSE_OPT_BIT: + case ARGPARSE_OPT_INTEGER: + case ARGPARSE_OPT_FLOAT: + case ARGPARSE_OPT_STRING: + case ARGPARSE_OPT_GROUP: + continue; + default: + fprintf(stderr, "wrong option type: %d", options->type); + break; + } + } +} + +static int +argparse_short_opt(struct argparse *self, const struct argparse_option *options) +{ + for (; options->type != ARGPARSE_OPT_END; options++) { + if (options->short_name == *self->optvalue) { + self->optvalue = self->optvalue[1] ? self->optvalue + 1 : NULL; + return argparse_getvalue(self, options, 0); + } + } + return -2; +} + +static int +argparse_long_opt(struct argparse *self, const struct argparse_option *options) +{ + for (; options->type != ARGPARSE_OPT_END; options++) { + const char *rest; + int opt_flags = 0; + if (!options->long_name) + continue; + + rest = prefix_skip(self->argv[0] + 2, options->long_name); + if (!rest) { + // negation disabled? + if (options->flags & OPT_NONEG) { + continue; + } + // only OPT_BOOLEAN/OPT_BIT supports negation + if (options->type != ARGPARSE_OPT_BOOLEAN && options->type != + ARGPARSE_OPT_BIT) { + continue; + } + + if (prefix_cmp(self->argv[0] + 2, "no-")) { + continue; + } + rest = prefix_skip(self->argv[0] + 2 + 3, options->long_name); + if (!rest) + continue; + opt_flags |= OPT_UNSET; + } + if (*rest) { + if (*rest != '=') + continue; + self->optvalue = rest + 1; + } + return argparse_getvalue(self, options, opt_flags | OPT_LONG); + } + return -2; +} + +int +argparse_init(struct argparse *self, struct argparse_option *options, + const char *const *usages, int flags) +{ + memset(self, 0, sizeof(*self)); + self->options = options; + self->usages = usages; + self->flags = flags; + self->description = NULL; + self->epilog = NULL; + return 0; +} + +void +argparse_describe(struct argparse *self, const char *description, + const char *epilog) +{ + self->description = description; + self->epilog = epilog; +} + +int +argparse_parse(struct argparse *self, int argc, const char **argv) +{ + self->argc = argc - 1; + self->argv = argv + 1; + self->out = argv; + + argparse_options_check(self->options); + + for (; self->argc; self->argc--, self->argv++) { + const char *arg = self->argv[0]; + if (arg[0] != '-' || !arg[1]) { + if (self->flags & ARGPARSE_STOP_AT_NON_OPTION) { + goto end; + } + // if it's not option or is a single char '-', copy verbatim + self->out[self->cpidx++] = self->argv[0]; + continue; + } + // short option + if (arg[1] != '-') { + self->optvalue = arg + 1; + switch (argparse_short_opt(self, self->options)) { + case -1: + break; + case -2: + goto unknown; + } + while (self->optvalue) { + switch (argparse_short_opt(self, self->options)) { + case -1: + break; + case -2: + goto unknown; + } + } + continue; + } + // if '--' presents + if (!arg[2]) { + self->argc--; + self->argv++; + break; + } + // long option + switch (argparse_long_opt(self, self->options)) { + case -1: + break; + case -2: + goto unknown; + } + continue; + +unknown: + fprintf(stderr, "error: unknown option `%s`\n", self->argv[0]); + argparse_usage(self); + exit(1); + } + +end: + memmove(self->out + self->cpidx, self->argv, + self->argc * sizeof(*self->out)); + self->out[self->cpidx + self->argc] = NULL; + + return self->cpidx + self->argc; +} + +void +argparse_usage(struct argparse *self) +{ + if (self->usages) { + fprintf(stdout, "Usage: %s\n", *self->usages++); + while (*self->usages && **self->usages) + fprintf(stdout, " or: %s\n", *self->usages++); + } else { + fprintf(stdout, "Usage:\n"); + } + + // print description + if (self->description) + fprintf(stdout, "%s\n", self->description); + + fputc('\n', stdout); + + const struct argparse_option *options; + + // figure out best width + size_t usage_opts_width = 0; + size_t len; + options = self->options; + for (; options->type != ARGPARSE_OPT_END; options++) { + len = 0; + if ((options)->short_name) { + len += 2; + } + if ((options)->short_name && (options)->long_name) { + len += 2; // separator ", " + } + if ((options)->long_name) { + len += strlen((options)->long_name) + 2; + } + if (options->type == ARGPARSE_OPT_INTEGER) { + len += strlen("="); + } + if (options->type == ARGPARSE_OPT_FLOAT) { + len += strlen("="); + } else if (options->type == ARGPARSE_OPT_STRING) { + len += strlen("="); + } + len = (len + 3) - ((len + 3) & 3); + if (usage_opts_width < len) { + usage_opts_width = len; + } + } + usage_opts_width += 4; // 4 spaces prefix + + options = self->options; + for (; options->type != ARGPARSE_OPT_END; options++) { + size_t pos = 0; + int pad = 0; + if (options->type == ARGPARSE_OPT_GROUP) { + fputc('\n', stdout); + fprintf(stdout, "%s", options->help); + fputc('\n', stdout); + continue; + } + pos = fprintf(stdout, " "); + if (options->short_name) { + pos += fprintf(stdout, "-%c", options->short_name); + } + if (options->long_name && options->short_name) { + pos += fprintf(stdout, ", "); + } + if (options->long_name) { + pos += fprintf(stdout, "--%s", options->long_name); + } + if (options->type == ARGPARSE_OPT_INTEGER) { + pos += fprintf(stdout, "="); + } + if (options->type == ARGPARSE_OPT_FLOAT) { + pos += fprintf(stdout, "="); + } else if (options->type == ARGPARSE_OPT_STRING) { + pos += fprintf(stdout, "="); + } + if (pos <= usage_opts_width) { + pad = usage_opts_width - pos; + } else { + fputc('\n', stdout); + pad = usage_opts_width; + } + fprintf(stdout, "%*s%s\n", pad + 2, "", options->help); + } + + // print epilog + if (self->epilog) + fprintf(stdout, "%s\n", self->epilog); +} + +int +argparse_help_cb(struct argparse *self, const struct argparse_option *option) +{ + (void)option; + argparse_usage(self); + exit(0); +} diff --git a/argparse/argparse.h b/argparse/argparse.h new file mode 100644 index 0000000..7fff31d --- /dev/null +++ b/argparse/argparse.h @@ -0,0 +1,130 @@ +/** + * Copyright (C) 2012-2015 Yecheng Fu + * All rights reserved. + * + * Use of this source code is governed by a MIT-style license that can be found + * in the LICENSE file. + */ +#ifndef ARGPARSE_H +#define ARGPARSE_H + +/* For c++ compatibility */ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct argparse; +struct argparse_option; + +typedef int argparse_callback (struct argparse *self, + const struct argparse_option *option); + +enum argparse_flag { + ARGPARSE_STOP_AT_NON_OPTION = 1, +}; + +enum argparse_option_type { + /* special */ + ARGPARSE_OPT_END, + ARGPARSE_OPT_GROUP, + /* options with no arguments */ + ARGPARSE_OPT_BOOLEAN, + ARGPARSE_OPT_BIT, + /* options with arguments (optional or required) */ + ARGPARSE_OPT_INTEGER, + ARGPARSE_OPT_FLOAT, + ARGPARSE_OPT_STRING, +}; + +enum argparse_option_flags { + OPT_NONEG = 1, /* disable negation */ +}; + +/** + * argparse option + * + * `type`: + * holds the type of the option, you must have an ARGPARSE_OPT_END last in your + * array. + * + * `short_name`: + * the character to use as a short option name, '\0' if none. + * + * `long_name`: + * the long option name, without the leading dash, NULL if none. + * + * `value`: + * stores pointer to the value to be filled. + * + * `help`: + * the short help message associated to what the option does. + * Must never be NULL (except for ARGPARSE_OPT_END). + * + * `callback`: + * function is called when corresponding argument is parsed. + * + * `data`: + * associated data. Callbacks can use it like they want. + * + * `flags`: + * option flags. + */ +struct argparse_option { + enum argparse_option_type type; + const char short_name; + const char *long_name; + void *value; + const char *help; + argparse_callback *callback; + intptr_t data; + int flags; +}; + +/** + * argpparse + */ +struct argparse { + // user supplied + const struct argparse_option *options; + const char *const *usages; + int flags; + const char *description; // a description after usage + const char *epilog; // a description at the end + // internal context + int argc; + const char **argv; + const char **out; + int cpidx; + const char *optvalue; // current option value +}; + +// built-in callbacks +int argparse_help_cb(struct argparse *self, + const struct argparse_option *option); + +// built-in option macros +#define OPT_END() { ARGPARSE_OPT_END, 0, NULL, NULL, 0, NULL, 0, 0 } +#define OPT_BOOLEAN(...) { ARGPARSE_OPT_BOOLEAN, __VA_ARGS__ } +#define OPT_BIT(...) { ARGPARSE_OPT_BIT, __VA_ARGS__ } +#define OPT_INTEGER(...) { ARGPARSE_OPT_INTEGER, __VA_ARGS__ } +#define OPT_FLOAT(...) { ARGPARSE_OPT_FLOAT, __VA_ARGS__ } +#define OPT_STRING(...) { ARGPARSE_OPT_STRING, __VA_ARGS__ } +#define OPT_GROUP(h) { ARGPARSE_OPT_GROUP, 0, NULL, NULL, h, NULL, 0, 0 } +#define OPT_HELP() OPT_BOOLEAN('h', "help", NULL, \ + "show this help message and exit", \ + argparse_help_cb, 0, 0) + +int argparse_init(struct argparse *self, struct argparse_option *options, + const char *const *usages, int flags); +void argparse_describe(struct argparse *self, const char *description, + const char *epilog); +int argparse_parse(struct argparse *self, int argc, const char **argv); +void argparse_usage(struct argparse *self); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/argparse/tap-functions b/argparse/tap-functions new file mode 100644 index 0000000..84f700e --- /dev/null +++ b/argparse/tap-functions @@ -0,0 +1,445 @@ +#!/bin/bash + + +_version='1.02' + +_plan_set=0 +_no_plan=0 +_skip_all=0 +_test_died=0 +_expected_tests=0 +_executed_tests=0 +_failed_tests=0 +TODO= + + +usage(){ + cat <<'USAGE' +tap-functions: A TAP-producing BASH library + +PLAN: + plan_no_plan + plan_skip_all [REASON] + plan_tests NB_TESTS + +TEST: + ok RESULT [NAME] + okx COMMAND + is RESULT EXPECTED [NAME] + isnt RESULT EXPECTED [NAME] + like RESULT PATTERN [NAME] + unlike RESULT PATTERN [NAME] + pass [NAME] + fail [NAME] + +SKIP: + skip [CONDITION] [REASON] [NB_TESTS=1] + + skip $feature_not_present "feature not present" 2 || { + is $a "a" + is $b "b" + } + +TODO: + Specify TODO mode by setting $TODO: + TODO="not implemented yet" + ok $result "some not implemented test" + unset TODO + +OTHER: + diag MSG + +EXAMPLE: + #!/bin/bash + + . tap-functions + + plan_tests 7 + + me=$USER + is $USER $me "I am myself" + like $HOME $me "My home is mine" + like "`id`" $me "My id matches myself" + + /bin/ls $HOME 1>&2 + ok $? "/bin/ls $HOME" + # Same thing using okx shortcut + okx /bin/ls $HOME + + [[ "`id -u`" != "0" ]] + i_am_not_root=$? + skip $i_am_not_root "Must be root" || { + okx ls /root + } + + TODO="figure out how to become root..." + okx [ "$HOME" == "/root" ] + unset TODO +USAGE + exit +} + +opt= +set_u= +while getopts ":sx" opt ; do + case $_opt in + u) set_u=1 ;; + *) usage ;; + esac +done +shift $(( OPTIND - 1 )) +# Don't allow uninitialized variables if requested +[[ -n "$set_u" ]] && set -u +unset opt set_u + +# Used to call _cleanup on shell exit +trap _exit EXIT + + + +plan_no_plan(){ + (( _plan_set != 0 )) && "You tried to plan twice!" + + _plan_set=1 + _no_plan=1 + + return 0 +} + + +plan_skip_all(){ + local reason=${1:-''} + + (( _plan_set != 0 )) && _die "You tried to plan twice!" + + _print_plan 0 "Skip $reason" + + _skip_all=1 + _plan_set=1 + _exit 0 + + return 0 +} + + +plan_tests(){ + local tests=${1:?} + + (( _plan_set != 0 )) && _die "You tried to plan twice!" + (( tests == 0 )) && _die "You said to run 0 tests! You've got to run something." + + _print_plan $tests + _expected_tests=$tests + _plan_set=1 + + return $tests +} + + +_print_plan(){ + local tests=${1:?} + local directive=${2:-''} + + echo -n "1..$tests" + [[ -n "$directive" ]] && echo -n " # $directive" + echo +} + + +pass(){ + local name=$1 + ok 0 "$name" +} + + +fail(){ + local name=$1 + ok 1 "$name" +} + + +# This is the workhorse method that actually +# prints the tests result. +ok(){ + local result=${1:?} + local name=${2:-''} + + (( _plan_set == 0 )) && _die "You tried to run a test without a plan! Gotta have a plan." + + _executed_tests=$(( $_executed_tests + 1 )) + + if [[ -n "$name" ]] ; then + if _matches "$name" "^[0-9]+$" ; then + diag " You named your test '$name'. You shouldn't use numbers for your test names." + diag " Very confusing." + fi + fi + + if (( result != 0 )) ; then + echo -n "not " + _failed_tests=$(( _failed_tests + 1 )) + fi + echo -n "ok $_executed_tests" + + if [[ -n "$name" ]] ; then + local ename=${name//\#/\\#} + echo -n " - $ename" + fi + + if [[ -n "$TODO" ]] ; then + echo -n " # TODO $TODO" ; + if (( result != 0 )) ; then + _failed_tests=$(( _failed_tests - 1 )) + fi + fi + + echo + if (( result != 0 )) ; then + local file='tap-functions' + local func= + local line= + + local i=0 + local bt=$(caller $i) + while _matches "$bt" "tap-functions$" ; do + i=$(( $i + 1 )) + bt=$(caller $i) + done + local backtrace= + eval $(caller $i | (read line func file ; echo "backtrace=\"$file:$func() at line $line.\"")) + + local t= + [[ -n "$TODO" ]] && t="(TODO) " + + if [[ -n "$name" ]] ; then + diag " Failed ${t}test '$name'" + diag " in $backtrace" + else + diag " Failed ${t}test in $backtrace" + fi + fi + + return $result +} + + +okx(){ + local command="$@" + + local line= + diag "Output of '$command':" + $command | while read line ; do + diag "$line" + done + ok ${PIPESTATUS[0]} "$command" +} + + +_equals(){ + local result=${1:?} + local expected=${2:?} + + if [[ "$result" == "$expected" ]] ; then + return 0 + else + return 1 + fi +} + + +# Thanks to Aaron Kangas for the patch to allow regexp matching +# under bash < 3. + _bash_major_version=${BASH_VERSION%%.*} +_matches(){ + local result=${1:?} + local pattern=${2:?} + + if [[ -z "$result" || -z "$pattern" ]] ; then + return 1 + else + if (( _bash_major_version >= 3 )) ; then + eval '[[ "$result" =~ "$pattern" ]]' + else + echo "$result" | egrep -q "$pattern" + fi + fi +} + + +_is_diag(){ + local result=${1:?} + local expected=${2:?} + + diag " got: '$result'" + diag " expected: '$expected'" +} + + +is(){ + local result=${1:?} + local expected=${2:?} + local name=${3:-''} + + _equals "$result" "$expected" + (( $? == 0 )) + ok $? "$name" + local r=$? + (( r != 0 )) && _is_diag "$result" "$expected" + return $r +} + + +isnt(){ + local result=${1:?} + local expected=${2:?} + local name=${3:-''} + + _equals "$result" "$expected" + (( $? != 0 )) + ok $? "$name" + local r=$? + (( r != 0 )) && _is_diag "$result" "$expected" + return $r +} + + +like(){ + local result=${1:?} + local pattern=${2:?} + local name=${3:-''} + + _matches "$result" "$pattern" + (( $? == 0 )) + ok $? "$name" + local r=$? + (( r != 0 )) && diag " '$result' doesn't match '$pattern'" + return $r +} + + +unlike(){ + local result=${1:?} + local pattern=${2:?} + local name=${3:-''} + + _matches "$result" "$pattern" + (( $? != 0 )) + ok $? "$name" + local r=$? + (( r != 0 )) && diag " '$result' matches '$pattern'" + return $r +} + + +skip(){ + local condition=${1:?} + local reason=${2:-''} + local n=${3:-1} + + if (( condition == 0 )) ; then + local i= + for (( i=0 ; i<$n ; i++ )) ; do + _executed_tests=$(( _executed_tests + 1 )) + echo "ok $_executed_tests # skip: $reason" + done + return 0 + else + return + fi +} + + +diag(){ + local msg=${1:?} + + if [[ -n "$msg" ]] ; then + echo "# $msg" + fi + + return 1 +} + + +_die(){ + local reason=${1:-''} + + echo "$reason" >&2 + _test_died=1 + _exit 255 +} + + +BAIL_OUT(){ + local reason=${1:-''} + + echo "Bail out! $reason" >&2 + _exit 255 +} + + +_cleanup(){ + local rc=0 + + if (( _plan_set == 0 )) ; then + diag "Looks like your test died before it could output anything." + return $rc + fi + + if (( _test_died != 0 )) ; then + diag "Looks like your test died just after $_executed_tests." + return $rc + fi + + if (( _skip_all == 0 && _no_plan != 0 )) ; then + _print_plan $_executed_tests + fi + + local s= + if (( _no_plan == 0 && _expected_tests < _executed_tests )) ; then + s= ; (( _expected_tests > 1 )) && s=s + local extra=$(( _executed_tests - _expected_tests )) + diag "Looks like you planned $_expected_tests test$s but ran $extra extra." + rc=-1 ; + fi + + if (( _no_plan == 0 && _expected_tests > _executed_tests )) ; then + s= ; (( _expected_tests > 1 )) && s=s + diag "Looks like you planned $_expected_tests test$s but only ran $_executed_tests." + fi + + if (( _failed_tests > 0 )) ; then + s= ; (( _failed_tests > 1 )) && s=s + diag "Looks like you failed $_failed_tests test$s of $_executed_tests." + fi + + return $rc +} + + +_exit_status(){ + if (( _no_plan != 0 || _plan_set == 0 )) ; then + return $_failed_tests + fi + + if (( _expected_tests < _executed_tests )) ; then + return $(( _executed_tests - _expected_tests )) + fi + + return $(( _failed_tests + ( _expected_tests - _executed_tests ))) +} + + +_exit(){ + local rc=${1:-''} + if [[ -z "$rc" ]] ; then + _exit_status + rc=$? + fi + + _cleanup + local alt_rc=$? + (( alt_rc != 0 )) && rc=$alt_rc + trap - EXIT + exit $rc +} + diff --git a/argparse/test.sh b/argparse/test.sh new file mode 100644 index 0000000..192357d --- /dev/null +++ b/argparse/test.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +. tap-functions +plan_no_plan + +is "$(./test_argparse -f --path=/path/to/file a 2>&1)" 'force: 1 +path: /path/to/file +argc: 1 +argv[0]: a' + +is "$(./test_argparse -f -f --force --no-force 2>&1)" 'force: 2' + +is "$(./test_argparse -i 2>&1)" 'error: option `-i` requires a value' + +is "$(./test_argparse -i 2 2>&1)" 'int_num: 2' + +is "$(./test_argparse -i2 2>&1)" 'int_num: 2' + +is "$(./test_argparse -ia 2>&1)" 'error: option `-i` expects an integer value' + +is "$(./test_argparse -i 0xFFFFFFFFFFFFFFFFF 2>&1)" \ + 'error: option `-i` Numerical result out of range' + +is "$(./test_argparse -s 2.4 2>&1)" 'flt_num: 2.4' + +is "$(./test_argparse -s2.4 2>&1)" 'flt_num: 2.4' + +is "$(./test_argparse -sa 2>&1)" 'error: option `-s` expects a numerical value' + +is "$(./test_argparse -s 1e999 2>&1)" \ + 'error: option `-s` Numerical result out of range' + +is "$(./test_argparse -f -- do -f -h 2>&1)" 'force: 1 +argc: 3 +argv[0]: do +argv[1]: -f +argv[2]: -h' + +is "$(./test_argparse -tf 2>&1)" 'force: 1 +test: 1' + +is "$(./test_argparse --read --write 2>&1)" 'perms: 3' + +is "$(./test_argparse -h)" 'Usage: test_argparse [options] [[--] args] + or: test_argparse [options] + +A brief description of what the program does and how it works. + + -h, --help show this help message and exit + +Basic options + -f, --force force to do + -t, --test test only + -p, --path= path to read + -i, --int= selected integer + -s, --float= selected float + +Bits options + --read read perm + --write write perm + --exec exec perm + +Additional description of the program after the description of the arguments.' diff --git a/argparse/test_argparse.c b/argparse/test_argparse.c new file mode 100644 index 0000000..b1f60c8 --- /dev/null +++ b/argparse/test_argparse.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include "argparse.h" + +static const char *const usages[] = { + "test_argparse [options] [[--] args]", + "test_argparse [options]", + NULL, +}; + +#define PERM_READ (1<<0) +#define PERM_WRITE (1<<1) +#define PERM_EXEC (1<<2) + +int +main(int argc, const char **argv) +{ + int force = 0; + int test = 0; + int int_num = 0; + float flt_num = 0.f; + const char *path = NULL; + int perms = 0; + struct argparse_option options[] = { + OPT_HELP(), + OPT_GROUP("Basic options"), + OPT_BOOLEAN('f', "force", &force, "force to do", NULL, 0, 0), + OPT_BOOLEAN('t', "test", &test, "test only", NULL, 0, 0), + OPT_STRING('p', "path", &path, "path to read", NULL, 0, 0), + OPT_INTEGER('i', "int", &int_num, "selected integer", NULL, 0, 0), + OPT_FLOAT('s', "float", &flt_num, "selected float", NULL, 0, 0), + OPT_GROUP("Bits options"), + OPT_BIT(0, "read", &perms, "read perm", NULL, PERM_READ, OPT_NONEG), + OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE, 0), + OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC, 0), + OPT_END(), + }; + + struct argparse argparse; + argparse_init(&argparse, options, usages, 0); + argparse_describe(&argparse, "\nA brief description of what the program does and how it works.", "\nAdditional description of the program after the description of the arguments."); + argc = argparse_parse(&argparse, argc, argv); + if (force != 0) + printf("force: %d\n", force); + if (test != 0) + printf("test: %d\n", test); + if (path != NULL) + printf("path: %s\n", path); + if (int_num != 0) + printf("int_num: %d\n", int_num); + if (flt_num != 0) + printf("flt_num: %g\n", flt_num); + if (argc != 0) { + printf("argc: %d\n", argc); + int i; + for (i = 0; i < argc; i++) { + printf("argv[%d]: %s\n", i, *(argv + i)); + } + } + if (perms) { + printf("perms: %d\n", perms); + } + return 0; +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..bfb750a --- /dev/null +++ b/config.json @@ -0,0 +1,18 @@ +{ + "username": "liu2guang", + "list_ignore_inc": "['.git', 'example', 'doc', 'test']", + "list_ignore_src": "['test.c', 'example.c']", + "templates": { + "readme_md": "template-readme-rtt.txt", + "sconscript": "template-sconscript.txt", + "sconscript_example": "template-sconscript-example.txt", + "ci_github": "template-ci-github.txt", + "kconfig": "template-kconfig.txt", + "package_json": "template-package-json.txt" + }, + "pkg_def_version": "v1.0.0", + "commit_content": "[builpkg] Use the buildpkg tool to quickly build ${pkgname}'s packages!", + "pkgname": "argparse", + "version": "v1.0.1", + "pkgname_letter": "ARGPARSE" +} \ No newline at end of file diff --git a/example/SConscript b/example/SConscript new file mode 100644 index 0000000..b5a31cf --- /dev/null +++ b/example/SConscript @@ -0,0 +1,20 @@ +import os +from building import * + +# get current dir path +cwd = GetCurrentDir() + +# init src and inc vars +src = [] +inc = [] + +# add libcsv common include +inc = inc + [cwd] + +# add libcsv basic code +src = src + Glob('./*.c') + +# add group to IDE project +objs = DefineGroup('argparse-v1.0.1', src, depend = ['ARGPARSE_USING_DEMO'], CPPPATH = inc) + +Return('objs') diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..590f781 --- /dev/null +++ b/readme.md @@ -0,0 +1,63 @@ +# argparse + +## 1、介绍 + +> 说明:你需要在这里对项目进行简单的介绍,描述项目背景,当前现状、功能特点等等…… + +这是一个在 RT-Thread 上,用于演示的 package 。展示了一个 package 大致包括的内容,以及对应的一些模版文件。 + +### 1.1 目录结构 + +> 说明:参考下面表格,整理出 packages 的目录结构 + +| 名称 | 说明 | +| ---- | ---- | +| docs | 文档目录 | +| examples | 例子目录,并有相应的一些说明 | +| inc | 头文件目录 | +| src | 源代码目录 | +| port | 移植代码目录。如果没有移植代码,可以不需要 | + +### 1.2 许可证 + +> 说明:请在这里说明该 package 的授权许可,例如: GPLv2、LGPLv2.1、MIT、Apache license v2.0、BSD 等。 + +hello package 遵循 LGPLv2.1 许可,详见 `LICENSE` 文件。 + +### 1.3 依赖 + +> 说明:列出该 package 对于其他 package 、RT-Thread 操作系统版本等软件方面的依赖关系。 + +- RT-Thread 3.0+ + +## 2、如何打开 hello + +> 说明:描述该 package 位于 menuconfig 的位置,并对与其相关的配置进行介绍 + +使用 hello package 需要在 RT-Thread 的包管理器中选择它,具体路径如下: + +``` +RT-Thread online packages + miscellaneous packages ---> + [*] A hello package +``` + +然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。 + +## 3、使用 argparse + +> 说明:在这里介绍 package 的移植步骤、使用方法、初始化流程、准备工作、API 等等,如果移植或 API 文档内容较多,可以将其独立至 `docs` 目录下。 + +在打开 hello package 后,当进行 bsp 编译时,它会被加入到 bsp 工程中进行编译。 + +* 完整的 API 手册可以访问这个[链接](docs/api.md) +* 更多文档位于 [`/docs`](/docs) 下,使用前 **务必查看** + +## 4、注意事项 + +> 说明:列出在使用这个 package 过程中需要注意的事项;列出常见的问题,以及解决办法。 + +## 5、联系方式 & 感谢 + +* 维护:liu2guang +* 主页:https://github.com/liu2guang/argparse \ No newline at end of file diff --git a/scripts/script_bspcfg b/scripts/script_bspcfg new file mode 100644 index 0000000..ee0522c --- /dev/null +++ b/scripts/script_bspcfg @@ -0,0 +1,258 @@ +#ifndef RT_CONFIG_H__ +#define RT_CONFIG_H__ + +/* Automatically generated file; DO NOT EDIT. */ +/* RT-Thread Configuration */ + +/* RT-Thread Kernel */ + +#define RT_NAME_MAX 8 +#define RT_ALIGN_SIZE 4 +#define RT_THREAD_PRIORITY_32 +#define RT_THREAD_PRIORITY_MAX 32 +#define RT_TICK_PER_SECOND 100 +#define RT_DEBUG +#define RT_USING_OVERFLOW_CHECK +#define RT_DEBUG_INIT 0 +#define RT_DEBUG_THREAD 0 +#define RT_USING_HOOK +#define RT_IDEL_HOOK_LIST_SIZE 4 +#define IDLE_THREAD_STACK_SIZE 256 + +/* Inter-Thread communication */ + +#define RT_USING_SEMAPHORE +#define RT_USING_MUTEX +#define RT_USING_EVENT +#define RT_USING_MAILBOX +#define RT_USING_MESSAGEQUEUE + +/* Memory Management */ + +#define RT_USING_MEMHEAP +#define RT_USING_MEMHEAP_AS_HEAP +#define RT_USING_HEAP + +/* Kernel Device Object */ + +#define RT_USING_DEVICE +#define RT_USING_CONSOLE +#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLE_DEVICE_NAME "uart1" +#define ARCH_ARM +#define ARCH_ARM_CORTEX_M +#define ARCH_ARM_CORTEX_M7 + +/* RT-Thread Components */ + +#define RT_USING_COMPONENTS_INIT +#define RT_USING_USER_MAIN +#define RT_MAIN_THREAD_STACK_SIZE 2048 + +/* C++ features */ + + +/* Command shell */ + +#define RT_USING_FINSH +#define FINSH_THREAD_NAME "tshell" +#define FINSH_USING_HISTORY +#define FINSH_HISTORY_LINES 5 +#define FINSH_USING_SYMTAB +#define FINSH_USING_DESCRIPTION +#define FINSH_THREAD_PRIORITY 20 +#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_CMD_SIZE 80 +#define FINSH_USING_MSH +#define FINSH_USING_MSH_DEFAULT +#define FINSH_ARG_MAX 10 + +/* Device virtual file system */ + +#define RT_USING_DFS +#define DFS_USING_WORKDIR +#define DFS_FILESYSTEMS_MAX 2 +#define DFS_FILESYSTEM_TYPES_MAX 2 +#define DFS_FD_MAX 4 +#define RT_USING_DFS_ELMFAT + +/* elm-chan's FatFs, Generic FAT Filesystem Module */ + +#define RT_DFS_ELM_CODE_PAGE 437 +#define RT_DFS_ELM_WORD_ACCESS +#define RT_DFS_ELM_USE_LFN_3 +#define RT_DFS_ELM_USE_LFN 3 +#define RT_DFS_ELM_MAX_LFN 255 +#define RT_DFS_ELM_DRIVES 2 +#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 +#define RT_DFS_ELM_REENTRANT +#define RT_USING_DFS_DEVFS + +/* Device Drivers */ + +#define RT_USING_DEVICE_IPC +#define RT_PIPE_BUFSZ 512 +#define RT_USING_SERIAL +#define RT_USING_I2C +#define RT_USING_I2C_BITOPS +#define RT_USING_PIN +#define RT_USING_RTC +#define RT_USING_SDIO +#define RT_SDIO_STACK_SIZE 512 +#define RT_SDIO_THREAD_PRIORITY 15 +#define RT_MMCSD_STACK_SIZE 1024 +#define RT_MMCSD_THREAD_PREORITY 22 +#define RT_MMCSD_MAX_PARTITION 16 +#define RT_USING_SPI + +/* Using USB */ + + +/* POSIX layer and C standard library */ + +#define RT_USING_LIBC + +/* Network stack */ + +/* light weight TCP/IP stack */ + +#define RT_USING_LWIP +#define RT_USING_LWIP202 +#define RT_LWIP_ICMP +#define RT_LWIP_DNS +#define RT_LWIP_DHCP +#define IP_SOF_BROADCAST 1 +#define IP_SOF_BROADCAST_RECV 1 + +/* Static IPv4 Address */ + +#define RT_LWIP_IPADDR "192.168.1.30" +#define RT_LWIP_GWADDR "192.168.1.1" +#define RT_LWIP_MSKADDR "255.255.255.0" +#define RT_LWIP_UDP +#define RT_LWIP_TCP +#define RT_MEMP_NUM_NETCONN 8 +#define RT_LWIP_PBUF_NUM 16 +#define RT_LWIP_RAW_PCB_NUM 4 +#define RT_LWIP_UDP_PCB_NUM 4 +#define RT_LWIP_TCP_PCB_NUM 4 +#define RT_LWIP_TCP_SEG_NUM 40 +#define RT_LWIP_TCP_SND_BUF 8196 +#define RT_LWIP_TCP_WND 8196 +#define RT_LWIP_TCPTHREAD_PRIORITY 10 +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +#define RT_LWIP_TCPTHREAD_STACKSIZE 1024 +#define RT_LWIP_ETHTHREAD_PRIORITY 12 +#define RT_LWIP_ETHTHREAD_STACKSIZE 1024 +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define SO_REUSE 1 +#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 +#define LWIP_SO_RCVBUF 1 +#define LWIP_NETIF_LOOPBACK 0 + +/* Modbus master and slave stack */ + + +/* VBUS(Virtual Software BUS) */ + + +/* Utilities */ + + +/* ARM CMSIS */ + + +/* RT-Thread online packages */ + +/* IoT - internet of things */ + + +/* Wi-Fi */ + +/* Marvell WiFi */ + + +/* Wiced WiFi */ + + +/* security packages */ + + +/* language packages */ + +#define PKG_USING_LUA +#define PKG_USING_LUA_LATEST_VERSION +#define LUA_USING_PORTING_V534 + +/* multimedia packages */ + + +/* tools packages */ + + +/* system packages */ + +#define PKG_USING_LITTLEVGL2RTT +#define PKG_USING_LITTLEVGL2RTT_V001 + +/* LittlevGL2RTT Options */ + +#define LV_MEM_DYNAMIC +#define LV_MEM_CUSTOM 1 +#define LV_COLOR_DEPTH_16 +#define LV_COLOR_DEPTH 16 +#define LV_HOR_RES 480 +#define LV_VER_RES 272 +#define LV_DPI 50 +#define LITTLEVGL2RTT_USING_DEMO + +/* peripheral libraries and drivers */ + + +/* miscellaneous packages */ + + +/* sample package */ + + +/* example package: hello */ + +#define SOC_IMXRT1052 +#define BOARD_USING_QSPIFLASH +#define BOARD_RT1050_FIRE + +/* RT1050 Bsp Config */ + +/* Select uart drivers */ + +#define RT_USING_UART1 + +/* Select spi bus and dev drivers */ + +#define LPSPI_CLK_SOURCE_FROM_PLL3PFD1 +#define LPSPI_CLK_SOURCE 0 +#define LPSPI_CLK_SOURCE_DIVIDER 8 + +/* Select iic bus drivers */ + + +/* Select lcd driver */ + +/* Notice: Fire Board para: 800*480 4 4 8 2 40 10 58 45 */ + +#define RT_USING_LCD +#define LCD_WIDTH 480 +#define LCD_HEIGHT 272 +#define LCD_HFP 4 +#define LCD_VFP 4 +#define LCD_HBP 8 +#define LCD_VBP 2 +#define LCD_HSW 40 +#define LCD_VSW 10 +#define LCD_BL_PIN 106 +#define LCD_RST_PIN 45 +#define RT_USING_SDRAM + +#endif diff --git a/scripts/script_scons b/scripts/script_scons new file mode 100644 index 0000000..6328b78 --- /dev/null +++ b/scripts/script_scons @@ -0,0 +1,12 @@ +import os +from building import * + +objs = [] +cwd = GetCurrentDir() +list = os.listdir(cwd) + +for item in list: + if os.path.isfile(os.path.join(cwd, item, 'SConscript')): + objs = objs + SConscript(os.path.join(item, 'SConscript')) + +Return('objs')