Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
29
Issues
29
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
a51c7ca9
Commit
a51c7ca9
authored
May 31, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shell: initial environment support (not tested)
parent
b9e4a55c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
6 deletions
+109
-6
shell.c
shell/shell.c
+109
-6
No files found.
shell/shell.c
View file @
a51c7ca9
...
...
@@ -6,6 +6,7 @@
#define SH_MAX_LINE_LEN 80
#define SH_MAX_ARGS 8
#define SH_ENVIRON_SIZE 256
/* interactive shell state definitions */
...
...
@@ -30,14 +31,22 @@ struct shell_cmd {
extern
int
uart_read_byte
();
static
int
cmd_env
(
const
char
*
args
[]);
static
int
cmd_saveenv
(
const
char
*
args
[]);
static
int
cmd_set
(
const
char
*
args
[]);
static
const
struct
shell_cmd
cmds_list
[]
=
{
{
"pll"
,
cmd_pll
},
{
"gui"
,
cmd_gui
},
{
"ver"
,
cmd_version
},
{
"stat"
,
cmd_stat
},
{
"ptp"
,
cmd_ptp
},
{
"mode"
,
cmd_mode
},
{
"pll"
,
cmd_pll
},
{
"gui"
,
cmd_gui
},
{
"ver"
,
cmd_version
},
{
"stat"
,
cmd_stat
},
{
"ptp"
,
cmd_ptp
},
{
"mode"
,
cmd_mode
},
{
"measure_t24p"
,
cmd_measure_t24p
},
{
"set"
,
cmd_set
},
{
"env"
,
cmd_env
},
{
"saveenv"
,
cmd_saveenv
},
{
NULL
,
NULL
}
};
...
...
@@ -46,6 +55,99 @@ static int cmd_pos = 0, cmd_len = 0;
static
int
state
=
SH_PROMPT
;
static
int
current_key
=
0
;
/* Environment-related functions */
static
unsigned
char
env_buf
[
SH_ENVIRON_SIZE
];
static
char
*
_env_get
(
const
char
*
var
)
{
int
i
=
0
;
while
(
i
<
SH_ENVIRON_SIZE
&&
env_buf
[
i
]
!=
0xff
)
{
if
(
env_buf
[
i
]
==
0xaa
&&
!
strcasecmp
(
env_buf
+
i
+
1
,
var
))
return
env_buf
+
i
;
i
++
;
}
return
NULL
;
}
static
char
*
env_get
(
const
char
*
var
)
{
char
*
p
=
_env_get
(
var
);
if
(
!
p
)
return
NULL
;
return
p
+
2
+
strlen
(
p
+
1
);
}
static
int
_env_end
()
{
int
i
;
for
(
i
=
0
;
i
<
SH_ENVIRON_SIZE
;
i
++
)
if
(
env_buf
[
i
]
==
0xff
)
return
i
;
}
static
int
env_set
(
const
char
*
var
,
const
char
*
value
)
{
unsigned
char
*
vstart
=
_env_get
(
var
),
*
p
;
int
end
;
if
(
vstart
)
/* entry already present? remove current and append at the end of environment */
{
p
=
vstart
+
1
;
while
(
*
p
!=
0xaa
&&
*
p
!=
0xff
)
p
++
;
memmove
(
vstart
,
p
,
SH_ENVIRON_SIZE
-
(
p
-
env_buf
));
}
end
=
_env_end
();
if
((
end
+
strlen
(
var
)
+
strlen
(
value
)
+
3
)
>=
SH_ENVIRON_SIZE
)
return
-
ENOMEM
;
p
=
&
env_buf
[
end
];
*
p
++
=
0xaa
;
memcpy
(
p
,
var
,
strlen
(
var
)
+
1
);
p
+=
strlen
(
var
)
+
1
;
memcpy
(
p
,
value
,
strlen
(
value
)
+
1
);
p
+=
strlen
(
value
)
+
1
;
*
p
++
=
0xff
;
p
=
env_buf
;
return
0
;
}
static
int
cmd_env
(
const
char
*
args
[])
{
unsigned
char
*
p
=
env_buf
;
while
(
*
p
!=
0xff
)
{
if
(
*
p
==
0xaa
)
mprintf
(
"%s=%s
\n
"
,
p
+
1
,
p
+
strlen
(
p
+
1
)
+
2
);
p
++
;
}
return
0
;
}
static
int
cmd_saveenv
(
const
char
*
args
[])
{
return
-
ENOTSUP
;
}
static
int
cmd_set
(
const
char
*
args
[])
{
if
(
!
args
[
1
])
return
-
EINVAL
;
return
env_set
(
args
[
0
],
args
[
1
]);
}
static
int
insert
(
char
c
)
{
if
(
cmd_len
>=
SH_MAX_LINE_LEN
)
...
...
@@ -124,6 +226,7 @@ int shell_exec(const char *cmd)
void
shell_init
()
{
env_buf
[
0
]
=
0xff
;
cmd_len
=
cmd_pos
=
0
;
state
=
SH_PROMPT
;
mprintf
(
"
\033
[2J
\033
[1;1H"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment