Add document for file module

This commit is contained in:
Jiajie Chen 2015-03-07 22:00:43 +08:00
parent 7e524f7dd4
commit 234daa8a7c
2 changed files with 454 additions and 52 deletions

314
Doxyfile Normal file
View File

@ -0,0 +1,314 @@
# Doxyfile 1.8.9.1
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = NodeMCU
PROJECT_NUMBER = 0.9.5
PROJECT_BRIEF =
PROJECT_LOGO =
OUTPUT_DIRECTORY = docs
CREATE_SUBDIRS = NO
ALLOW_UNICODE_NAMES = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
ALIASES =
TCL_SUBST =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES
AUTOLINK_SUPPORT = YES
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
INLINE_GROUPED_CLASSES = NO
INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = NO
LOOKUP_CACHE_SIZE = 0
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = NO
HIDE_SCOPE_NAMES = NO
HIDE_COMPOUND_REFERENCE= NO
SHOW_INCLUDE_FILES = YES
SHOW_GROUPED_MEMB_INC = NO
FORCE_LOCAL_INCLUDES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
STRICT_PROTO_MATCHING = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_FILES = YES
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
LAYOUT_FILE =
CITE_BIB_FILES =
#---------------------------------------------------------------------------
# Configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = app/modules README.md
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.c *.md
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS =
USE_MDFILE_AS_MAINPAGE = README.md
#---------------------------------------------------------------------------
# Configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
REFERENCES_RELATION = NO
REFERENCES_LINK_SOURCE = YES
SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_EXTRA_STYLESHEET =
HTML_EXTRA_FILES =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = YES
HTML_DYNAMIC_SECTIONS = NO
HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
CHM_INDEX_ENCODING =
BINARY_TOC = NO
TOC_EXPAND = NO
GENERATE_QHP = NO
QCH_FILE =
QHP_NAMESPACE = org.doxygen.Project
QHP_VIRTUAL_FOLDER = doc
QHP_CUST_FILTER_NAME =
QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS =
QHG_LOCATION =
GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
GENERATE_TREEVIEW = NO
ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
USE_MATHJAX = NO
MATHJAX_FORMAT = HTML-CSS
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
MATHJAX_EXTENSIONS =
MATHJAX_CODEFILE =
SEARCHENGINE = YES
SERVER_BASED_SEARCH = NO
EXTERNAL_SEARCH = NO
SEARCHENGINE_URL =
SEARCHDATA_FILE = searchdata.xml
EXTERNAL_SEARCH_ID =
EXTRA_SEARCH_MAPPINGS =
#---------------------------------------------------------------------------
# Configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
EXTRA_PACKAGES =
LATEX_HEADER =
LATEX_FOOTER =
LATEX_EXTRA_STYLESHEET =
LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
LATEX_BIB_STYLE = plain
#---------------------------------------------------------------------------
# Configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
RTF_SOURCE_CODE = NO
#---------------------------------------------------------------------------
# Configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_SUBDIR =
MAN_LINKS = NO
#---------------------------------------------------------------------------
# Configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# Configuration options related to the DOCBOOK output
#---------------------------------------------------------------------------
GENERATE_DOCBOOK = NO
DOCBOOK_OUTPUT = docbook
DOCBOOK_PROGRAMLISTING = NO
#---------------------------------------------------------------------------
# Configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# Configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration options related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
DIA_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
DOT_FONTPATH =
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
UML_LIMIT_NUM_FIELDS = 10
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
INTERACTIVE_SVG = NO
DOT_PATH =
DOTFILE_DIRS =
MSCFILE_DIRS =
DIAFILE_DIRS =
PLANTUML_JAR_PATH =
PLANTUML_INCLUDE_PATH =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES

View File

@ -1,5 +1,7 @@
// Module for interfacing with file system
/// @file file.c Define file module for interfacing with file system
/// @cond
/// This should not be documented./// @cond
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
@ -11,16 +13,35 @@
#include "flash_fs.h"
#include "c_string.h"
static volatile int file_fd = FS_OPEN_OK - 1;
#define INVALID_FD (FS_OPEN_OK - 1)
static volatile int file_fd = INVALID_FD;
/// @endcond
/// Implements the lua method file.close.
/// It closes the current file opened in file_open().
// Lua: close()
static int file_close( lua_State* L )
{
if (INVALID_FD != file_fd){
fs_close(file_fd);
file_fd = INVALID_FD;
}
return 0;
}
/// Implements the lua method file.open.
/// Open a file.
/// @param filename the file name.
/// @param mode Optional. The open mode, default is "r".
/// @throws error if filename is too long.
/// @retval false open file failed.
/// @retval true open file succeeded.
/// @attention You can only open one file at one time.
// Lua: open(filename, mode)
static int file_open( lua_State* L )
{
size_t len;
if((FS_OPEN_OK - 1)!=file_fd){
fs_close(file_fd);
file_fd = FS_OPEN_OK - 1;
}
file_close();
const char *fname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH )
@ -30,42 +51,60 @@ static int file_open( lua_State* L )
file_fd = fs_open(fname, fs_mode2flag(mode));
if(file_fd < FS_OPEN_OK){
file_fd = FS_OPEN_OK - 1;
lua_pushnil(L);
file_fd = INVALID_FD;
lua_pushboolean(L, 0);
} else {
lua_pushboolean(L, 1);
}
return 1;
}
// Lua: close()
static int file_close( lua_State* L )
{
if((FS_OPEN_OK - 1)!=file_fd){
fs_close(file_fd);
file_fd = FS_OPEN_OK - 1;
}
return 0;
}
/// Implements the lua method file.format.
/// It closes the current file and formats the file system.
// Lua: format()
static int file_format( lua_State* L )
{
size_t len;
file_close(L);
if( !fs_format() )
if ( fs_format() != 0 )
{
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
}
else{
else {
NODE_ERR( "format done.\n" );
}
return 0;
}
/// Implements the lua method file.seek.
/// Seeks current file to position basded on mode.
/// @param The mode. Can be one of: set, cur, end.
/// @param The offest.
/// @throws error if file not opened.
/// @retval false seek failed.
/// @retval true seek succeeded.
// Lua: seek(mode, offest)
static int file_seek (lua_State *L)
{
static const int mode[] = {FS_SEEK_SET, FS_SEEK_CUR, FS_SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL};
if(INVALID_FD == file_fd)
return luaL_error(L, "open a file first");
int op = luaL_checkoption(L, 1, "cur", modenames);
long offset = luaL_optlong(L, 2, 0);
op = fs_seek(file_fd, offset, mode[op]);
if (op)
lua_pushboolean(L, 0); /* error */
else
lua_pushboolean(L, 1);
return 1;
}
#if defined(BUILD_WOFS)
// Lua: list()
/// Implements the lua method file.list.
/// It lists the files in the file system.
/// @return filenames a table consist of file names and their lengths.
static int file_list( lua_State* L )
{
uint32_t start = 0;
@ -83,6 +122,9 @@ static int file_list( lua_State* L )
extern spiffs fs;
/// Implements the lua method file.list.
/// It lists the files in the file system.
/// @return filenames a table consist of file names and their lengths.
// Lua: list()
static int file_list( lua_State* L )
{
@ -101,22 +143,23 @@ static int file_list( lua_State* L )
return 1;
}
static int file_seek (lua_State *L)
{
static const int mode[] = {FS_SEEK_SET, FS_SEEK_CUR, FS_SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL};
if((FS_OPEN_OK - 1)==file_fd)
/// Implements the lua method file.tell.
/// Tell the current position of current file.
/// @throws error if file not opened.
/// @return the currentposition of file.
static int file_tell (lua_State* L) {
if (INVALID_FD == file_fd) {
return luaL_error(L, "open a file first");
int op = luaL_checkoption(L, 1, "cur", modenames);
long offset = luaL_optlong(L, 2, 0);
op = fs_seek(file_fd, offset, mode[op]);
if (op)
lua_pushboolean(L, 1); /* error */
else
lua_pushinteger(L, fs_tell(file_fd));
}
lua_pushinteger(L, fs_tell(file_fd));
return 1;
}
/// Implements the lua method file.remove.
/// Close current file and remove the file from file system.
/// @param filename
/// @throws error if filename is too long.
// Lua: remove(filename)
static int file_remove( lua_State* L )
{
@ -129,35 +172,52 @@ static int file_remove( lua_State* L )
return 0;
}
/// Implements the lua method file.flush.
/// Flush the buffer to file.
/// @return the result of flush.
/// @throws error if file not opened.
/// @retval false flush failed.
/// @retval true flush succeeded.
// Lua: flush()
static int file_flush( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
if(INVALID_FD==file_fd)
return luaL_error(L, "open a file first");
if(fs_flush(file_fd) == 0)
if(fs_flush(file_fd) == SPIFFS_OK)
lua_pushboolean(L, 1);
else
lua_pushnil(L);
lua_pushboolean(L, 0);
return 1;
}
#if 0
// Lua: check()
/// Implements the lua method file.check.
/// Check the file system.
/// @return true check succeeded.
/// @return false check failed.
static int file_check( lua_State* L )
{
file_close(L);
lua_pushinteger(L, fs_check());
if (fs_check() == SPIFFS_OK)
lua_pushboolean(L, 1);
else
lua_pushboolean(L, 0);
return 1;
}
#endif
/// Implements the lua method file.rename.
/// Rename file after closing current file.
/// @param oldname old file name.
/// @param newname new file name.
/// @throws error if either file name is too long.
/// @retval true if rename succeeded.
/// @retval false if rename failed.
// Lua: rename("oldname", "newname")
static int file_rename( lua_State* L )
{
size_t len;
if((FS_OPEN_OK - 1)!=file_fd){
fs_close(file_fd);
file_fd = FS_OPEN_OK - 1;
}
file_close(L);
const char *oldname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH )
@ -177,6 +237,9 @@ static int file_rename( lua_State* L )
#endif
/// @cond
/// This should not be documented.
// g_read()
static int file_g_read( lua_State* L, int n, int16_t end_char )
{
@ -187,7 +250,7 @@ static int file_g_read( lua_State* L, int n, int16_t end_char )
int ec = (int)end_char;
luaL_Buffer b;
if((FS_OPEN_OK - 1)==file_fd)
if(INVALID_FD==file_fd)
return luaL_error(L, "open a file first");
luaL_buffinit(L, &b);
@ -218,10 +281,14 @@ static int file_g_read( lua_State* L, int n, int16_t end_char )
return 1; /* read at least an `eol' */
}
/// @endcond
// Lua: read()
// file.read() will read all byte in file
// file.read(10) will read 10 byte from file, or EOF is reached.
// file.read('q') will read until 'q' or EOF is reached.
/// Implements the lua method file.read.
/// file.read() will read all bytes in file
/// file.read(10) will read 10 byte from file, or EOF is reached.
/// file.read('q') will read until 'q' or EOF is reached.
/// @return the content.
static int file_read( lua_State* L )
{
unsigned need_len = LUAL_BUFFERSIZE;
@ -246,16 +313,25 @@ static int file_read( lua_State* L )
return file_g_read(L, need_len, end_char);
}
/// Implements the lua method file.readline.
/// Reads a line until '\n'.
/// @return the line.
// Lua: readline()
static int file_readline( lua_State* L )
{
return file_g_read(L, LUAL_BUFFERSIZE, '\n');
}
/// Implements the lua method file.write.
/// Write a string into file.
/// @param string
/// @throws error if file not opened
/// @retval true write succeeded.
/// @retval false write failed.
// Lua: write("string")
static int file_write( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
if(INVALID_FD==file_fd)
return luaL_error(L, "open a file first");
size_t l, rl;
const char *s = luaL_checklstring(L, 1, &l);
@ -263,14 +339,20 @@ static int file_write( lua_State* L )
if(rl==l)
lua_pushboolean(L, 1);
else
lua_pushnil(L);
lua_pushboolean(L, 0);
return 1;
}
/// Implements the lua method file.writeline.
/// Write a string and append line feed(LF, '\\n') into file.
/// @param string
/// @throws error if file not opened
/// @retval true write succeeded.
/// @retval nil write failed.
// Lua: writeline("string")
static int file_writeline( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
if(INVALID_FD==file_fd)
return luaL_error(L, "open a file first");
size_t l, rl;
const char *s = luaL_checklstring(L, 1, &l);
@ -288,6 +370,8 @@ static int file_writeline( lua_State* L )
return 1;
}
/// @cond
/// This should not be documented.
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
@ -302,11 +386,14 @@ const LUA_REG_TYPE file_map[] =
{ LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
{ LSTRKEY( "format" ), LFUNCVAL( file_format ) },
#if defined(BUILD_WOFS)
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) },
#elif defined(BUILD_SPIFFS)
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) },
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
{ LSTRKEY( "tell" ), LFUNCVAL( file_tell ) },
{ LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
// { LSTRKEY( "check" ), LFUNCVAL( file_check ) },
{ LSTRKEY( "check" ), LFUNCVAL( file_check ) },
{ LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
#endif
@ -327,3 +414,4 @@ LUALIB_API int luaopen_file( lua_State *L )
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
/// @endcond