<commit_before>/*
 * File      : cmd.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-04-30     Bernard      first implementation
 * 2006-05-04     Bernard      add list_thread,
 *                                 list_sem,
 *                                 list_timer
 * 2006-05-20     Bernard      add list_mutex,
 *                                 list_mailbox,
 *                                 list_msgqueue,
 *                                 list_event,
 *                                 list_fevent,
 *                                 list_mempool
 * 2006-06-03     Bernard      display stack information in list_thread
 * 2006-08-10     Bernard      change version to invoke rt_show_version
 * 2008-09-10     Bernard      update the list function for finsh syscall
 *                                 list and sysvar list
 * 2009-05-30     Bernard      add list_device
 * 2010-04-21     yi.qiu          add list_module
 */

#include <rtthread.h>
#include "finsh.h"

// Copy from kservice.h because we can not use it out of the kernel.
// Ugly. Should let kservice.h available for applications?
rt_inline int rt_list_isempty(const rt_list_t *l)
{
	return l->next == l;
}

rt_inline unsigned int rt_list_len(const rt_list_t *l)
{
	unsigned int len = 0;
	const rt_list_t *p = l;
	while( p->next != l )
	{
		p = p->next;
		len++;
	}
	return len;
}

long hello(void)
{
	rt_kprintf("Hello RT-Thread!\n");

	return 0;
}
FINSH_FUNCTION_EXPORT(hello, say hello world);

extern void rt_show_version(void);
long version(void)
{
	rt_show_version();

	return 0;
}
FINSH_FUNCTION_EXPORT(version, show RT-Thread version information);

#define rt_list_entry(node, type, member) \
    ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
extern struct rt_object_information rt_object_container[];

static long _list_thread(struct rt_list_node* list)
{
	struct rt_thread *thread;
	struct rt_list_node *node;
	rt_uint8_t* ptr;

	rt_kprintf(" thread  pri  status      sp     stack size max used   left tick  error\n");
	rt_kprintf("-------- ---- ------- ---------- ---------- ---------- ---------- ---\n");
	for (node = list->next; node != list; node = node->next)
	{
		thread = rt_list_entry(node, struct rt_thread, list);
		rt_kprintf("%-8s 0x%02x", thread->name, thread->current_priority);

		if (thread->stat == RT_THREAD_READY)		rt_kprintf(" ready  ");
		else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
		else if (thread->stat == RT_THREAD_INIT)	rt_kprintf(" init   ");

		ptr = (rt_uint8_t*)thread->stack_addr;
		while (*ptr == '#')ptr ++;

		rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n",
			thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
			thread->stack_size,
			thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr),<commit_msg>use precision in list_thread function.<commit_after>/*
 * File      : cmd.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-04-30     Bernard      first implementation
 * 2006-05-04     Bernard      add list_thread,
 *                                 list_sem,
 *                                 list_timer
 * 2006-05-20     Bernard      add list_mutex,
 *                                 list_mailbox,
 *                                 list_msgqueue,
 *                                 list_event,
 *                                 list_fevent,
 *                                 list_mempool
 * 2006-06-03     Bernard      display stack information in list_thread
 * 2006-08-10     Bernard      change version to invoke rt_show_version
 * 2008-09-10     Bernard      update the list function for finsh syscall
 *                                 list and sysvar list
 * 2009-05-30     Bernard      add list_device
 * 2010-04-21     yi.qiu          add list_module
 */

#include <rtthread.h>
#include "finsh.h"

// Copy from kservice.h because we can not use it out of the kernel.
// Ugly. Should let kservice.h available for applications?
rt_inline int rt_list_isempty(const rt_list_t *l)
{
	return l->next == l;
}

rt_inline unsigned int rt_list_len(const rt_list_t *l)
{
	unsigned int len = 0;
	const rt_list_t *p = l;
	while( p->next != l )
	{
		p = p->next;
		len++;
	}
	return len;
}

long hello(void)
{
	rt_kprintf("Hello RT-Thread!\n");

	return 0;
}
FINSH_FUNCTION_EXPORT(hello, say hello world);

extern void rt_show_version(void);
long version(void)
{
	rt_show_version();

	return 0;
}
FINSH_FUNCTION_EXPORT(version, show RT-Thread version information);

#define rt_list_entry(node, type, member) \
    ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
extern struct rt_object_information rt_object_container[];

static long _list_thread(struct rt_list_node* list)
{
	struct rt_thread *thread;
	struct rt_list_node *node;
	rt_uint8_t* ptr;

	rt_kprintf(" thread  pri  status      sp     stack size max used   left tick  error\n");
	rt_kprintf("-------- ---- ------- ---------- ---------- ---------- ---------- ---\n");
	for (node = list->next; node != list; node = node->next)
	{
		thread = rt_list_entry(node, struct rt_thread, list);
		rt_kprintf("%-8.*s 0x%02x", RT_NAME_MAX, thread->name, thread->current_priority);

		if (thread->stat == RT_THREAD_READY)		rt_kprintf(" ready  ");
		else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
		else if (thread->stat == RT_THREAD_INIT)	rt_kprintf(" init   ");

		ptr = (rt_uint8_t*)thread->stack_addr;
		while (*ptr == '#')ptr ++;

		rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n",
			thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
			thread->stack_size,
			thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr),
{'fraction_non_alphanumeric': 0.12994532003859763, 'fraction_numerical': 0.0321646831778707, 'mean_word_length': 2.3292291220556747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5248961', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2005, 'n_words': 536}