mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
Break into several files
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@300 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -40,7 +40,7 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
||||
|
||||
ASRCS =
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
CSRCS = nsh_main.c
|
||||
CSRCS = nsh_main.c nsh_fscmds.c nsh_proccmds.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* nsh.h
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NSH_H
|
||||
#define __HSH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define errno (*get_errno_ptr())
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef void (*cmd_t)(int argc, char **argv);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
extern const char g_fmtargrequired[];
|
||||
extern const char g_fmtarginvalid[];
|
||||
extern const char g_fmtcmdnotfound[];
|
||||
extern const char g_fmtcmdnotimpl[];
|
||||
extern const char g_fmtnosuch[];
|
||||
extern const char g_fmttoomanyargs[];
|
||||
extern const char g_fmtcmdfailed[];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_cat(int argc, char **argv);
|
||||
#endif
|
||||
void cmd_exec(int argc, char **argv);
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_ls(int argc, char **argv);
|
||||
#endif
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_mkdir(int argc, char **argv);
|
||||
void cmd_mount(int argc, char **argv);
|
||||
#endif
|
||||
void cmd_ps(int argc, char **argv);
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_umount(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#endif /* __NSH_H */
|
||||
File diff suppressed because it is too large
Load Diff
+14
-588
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
* nsh_proccmds.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sched.h>
|
||||
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "nsh.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef void (*exec_t)(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char *g_statenames[] =
|
||||
{
|
||||
"INVALID ",
|
||||
"PENDING ",
|
||||
"READY ",
|
||||
"RUNNING ",
|
||||
"INACTIVE",
|
||||
"WAITSEM ",
|
||||
#ifndef CONFIG_DISABLE_MQUEUE
|
||||
"WAITSIG ",
|
||||
#endif
|
||||
#ifndef CONFIG_DISABLE_MQUEUE
|
||||
"MQNEMPTY",
|
||||
"MQNFULL "
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ps_task
|
||||
****************************************************************************/
|
||||
|
||||
static void ps_task(FAR _TCB *tcb, FAR void *arg)
|
||||
{
|
||||
boolean needcomma = FALSE;
|
||||
int i;
|
||||
printf("%5d %3d %4s %7s%c%c %8s ",
|
||||
tcb->pid, tcb->sched_priority,
|
||||
tcb->flags & TCB_FLAG_ROUND_ROBIN ? "RR " : "FIFO",
|
||||
tcb->flags & TCB_FLAG_PTHREAD ? "PTHREAD" : "TASK ",
|
||||
tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ',
|
||||
tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ',
|
||||
g_statenames[tcb->task_state]);
|
||||
|
||||
printf("%s(", tcb->argv[0]);
|
||||
for (i = 1; i < CONFIG_MAX_TASK_ARGS+1 && tcb->argv[i]; i++)
|
||||
{
|
||||
if (needcomma)
|
||||
{
|
||||
printf(", %p", tcb->argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%p", tcb->argv[i]);
|
||||
}
|
||||
}
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_exec
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_exec(int argc, char **argv)
|
||||
{
|
||||
char *endptr;
|
||||
long addr;
|
||||
|
||||
addr = strtol(argv[1], &endptr, 0);
|
||||
if (!addr || endptr == argv[1] || *endptr != '\0')
|
||||
{
|
||||
printf(g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Calling %p\n", (exec_t)addr);
|
||||
((exec_t)addr)();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ps
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_ps(int argc, char **argv)
|
||||
{
|
||||
printf("PID PRI SCHD TYPE NP STATE NAME\n");
|
||||
sched_foreach(ps_task, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user