rewrite comments into one, unified style
This commit is contained in:
1 parent
6260de0085
commit
467a58c9c6
163 files changed
+3560
-2556
No files matched your search
@@ -1,3 +1,5 @@
|
||||
// User application entry points for shell_posix.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
@@ -28,8 +30,10 @@ extern void PosixFdInit(void);
|
||||
|
||||
static int hIn = 0; static int hOut = 1;
|
||||
|
||||
// Prints the requested operation.
|
||||
static void print(const char* s) { write(hOut, s, strlen(s)); }
|
||||
|
||||
// Prints u Int.
|
||||
static void printUInt(uint32_t n) {
|
||||
char buf[12]; int i = 0;
|
||||
if (n == 0) { print("0"); return; }
|
||||
@@ -37,11 +41,13 @@ static void printUInt(uint32_t n) {
|
||||
while (i > 0) { char c[2] = { buf[--i], '\0' }; print(c); }
|
||||
}
|
||||
|
||||
// Prints int.
|
||||
static void printInt(int32_t n) {
|
||||
if (n < 0) { print("-"); n = -n; }
|
||||
printUInt((uint32_t)n);
|
||||
}
|
||||
|
||||
// Returns line.
|
||||
static void readLine(char* buf, int len) {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
@@ -55,6 +61,7 @@ static void readLine(char* buf, int len) {
|
||||
}
|
||||
|
||||
|
||||
// Implements the split Command Line operation.
|
||||
static int splitCommandLine(char* line, char** argv, int maxArgv) {
|
||||
int argc = 0;
|
||||
char* p = line;
|
||||
@@ -79,6 +86,7 @@ static int splitCommandLine(char* line, char** argv, int maxArgv) {
|
||||
return argc;
|
||||
}
|
||||
|
||||
// Implements the trim operation.
|
||||
static char* trim(char* s) {
|
||||
while (*s == ' ') s++;
|
||||
int len = (int)strlen(s);
|
||||
@@ -87,6 +95,7 @@ static char* trim(char* s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// Implements the cmd help operation.
|
||||
static void cmd_help() {
|
||||
print("Available commands:\n"
|
||||
" help - Show this list\n"
|
||||
@@ -99,6 +108,7 @@ static void cmd_help() {
|
||||
" exit - Close the shell\n");
|
||||
}
|
||||
|
||||
// Implements the cmd write operation.
|
||||
static void cmd_write(const char* args) {
|
||||
char filename[MAX_CMD]; int i = 0;
|
||||
while (args[i] != ' ' && args[i] != '\0' && i < MAX_CMD - 1) {
|
||||
@@ -113,6 +123,7 @@ static void cmd_write(const char* args) {
|
||||
print("File written successfully.\n");
|
||||
}
|
||||
|
||||
// Implements the cmd dir operation.
|
||||
static void cmd_dir(const char* path) {
|
||||
const char* target = (path && *path != '\0') ? path : ".";
|
||||
DIR* d = opendir(target);
|
||||
@@ -125,6 +136,7 @@ static void cmd_dir(const char* path) {
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
// Implements the cmd type operation.
|
||||
static void cmd_type(const char* filename) {
|
||||
int fd = open(filename, 0); // O_RDONLY
|
||||
if (fd < 0) { print("type: cannot open file\n"); return; }
|
||||
@@ -133,6 +145,7 @@ static void cmd_type(const char* filename) {
|
||||
close(fd); print("\n");
|
||||
}
|
||||
|
||||
// Runs command.
|
||||
static int runCommand(const char* cmd) {
|
||||
if (!cmd || *cmd == '\0') return 0;
|
||||
if (strcmp(cmd, "exit") == 0) return 1;
|
||||
@@ -162,6 +175,7 @@ static int runCommand(const char* cmd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Runs the requested operation.
|
||||
int main(void) {
|
||||
PosixFdInit();
|
||||
|
||||
|
||||
Reference in new issue
Block a user