annotate loadtools/ltexit.c @ 27:ae6294b8a015

loadtool: exit jump0 implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 04 May 2013 06:22:09 +0000
parents
children 768a3d012931
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the loadtool exit command, along with its
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * options for jump-reboot or eventual Iota power-off.
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <string.h>
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <strings.h>
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 static void
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 exit_bare()
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 exit(0);
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 }
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 static void
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 exit_jump0()
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 static char *jump0_argv[3] = {"jump", "0", 0};
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 tpinterf_make_cmd(jump0_argv);
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 tpinterf_send_cmd();
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 exit(0);
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 }
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 void (*default_exit)() = exit_bare;
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 static struct kwtab {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 char *kw;
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 void (*func)();
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 } exit_modes[] = {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 {"bare", exit_bare},
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 {"jump0", exit_jump0},
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 {0, 0}
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 };
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 cmd_exit(argc, argv)
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 char **argv;
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 struct kwtab *tp;
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (argc < 2)
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 default_exit();
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 for (tp = exit_modes; tp->kw; tp++)
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 if (!strcmp(tp->kw, argv[1]))
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 break;
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (!tp->func) {
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(stderr,
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 "error: \"%s\" is not an understood exit mode\n",
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 argv[1]);
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 return(-1);
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 }
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 tp->func();
ae6294b8a015 loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 }