Reworking usermode/libc to closer C compliance
[tpg/acess2.git] / Usermode / Applications / init_src / main.c
1 /*
2  * Acess2 System Init Task
3  */
4 #include <acess/sys.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 //#include <spiderscript.h>
8 //#include "common.h"
9
10 // === CONSTANTS ===
11 #define NUM_TERMS       4
12 #define DEFAULT_TERMINAL        "/Devices/VTerm/0"
13 #define DEFAULT_SHELL   "/Acess/SBin/login"
14 #define DEFAULT_SCRIPT  "/Acess/Conf/BootConf.isc"
15
16 #define ARRAY_SIZE(x)   ((sizeof(x))/(sizeof((x)[0])))
17
18 // === PROTOTYPES ===
19 /*
20 tSpiderVariable *Script_System_IO_Open(tSpiderScript *, int, tSpiderVariable *);
21 */
22
23 // === GLOBALS ===
24 /*
25 tSpiderFunction gaScriptNS_IO_Fcns[] = {
26         {"Open", Script_System_IO_Open}
27 };
28 tSpiderNamespace        gaScriptNS_System[] = {
29         {
30                 "IO",
31                 0, NULL,
32                 ARRAY_SIZE(gaScriptNS_IO_Fcns), gaScriptNS_IO_Fcns,
33                 0, NULL
34         }
35 };
36
37 tSpiderNamespace        gaScriptNamespaces[] = {
38         {
39                 "System",
40                 ARRAY_SIZE(gaScriptNS_System), gaScriptNS_System,
41                 0, NULL,
42                 0, NULL
43         }
44 };
45
46 tSpiderVariant  gScriptVariant = {
47         "init", 0,
48         ARRAY_SIZE(gaScriptNamespaces), gaScriptNamespaces
49 };
50 */
51
52 // === CODE ===
53 /**
54  * \fn int main(int argc, char *argv[])
55  * \brief Entrypoint
56  */
57 int main(int argc, char *argv[])
58 {
59          int    tid;
60          int    i;
61         char    termpath[sizeof(DEFAULT_TERMINAL)] = DEFAULT_TERMINAL;
62         char    *child_argv[2] = {DEFAULT_SHELL, 0};
63         
64         // - Parse init script
65         
66         // - Start virtual terminals
67         for( i = 0; i < NUM_TERMS; i++ )
68         {               
69                 tid = clone(CLONE_VM, 0);
70                 if(tid == 0)
71                 {
72                         termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i;
73                         
74                         open(termpath, OPENFLAG_READ);  // Stdin
75                         open(termpath, OPENFLAG_WRITE); // Stdout
76                         open(termpath, OPENFLAG_WRITE); // Stderr
77                         execve(DEFAULT_SHELL, child_argv, NULL);
78                         for(;;) sleep();
79                 }
80         }
81         
82         // TODO: Implement message watching
83         for(;;) sleep();
84         
85         return 42;
86 }
87
88 /**
89  * \brief Reads and parses the boot configuration script
90  * \param Filename      File to parse and execute
91  */
92 void ExecuteScript(const char *Filename)
93 {
94         /*
95         tSpiderScript   *script;
96         script = SpiderScript_ParseFile(&gScriptVariant, Filename);
97         SpiderScript_ExecuteMethod(script, "");
98         SpiderScript_Free(script);
99         */
100 }
101
102 /**
103  * \brief Open a file
104  */
105 /*
106 tSpiderVariable *Script_System_IO_Open(tSpiderScript *Script, int NArgs, tSpiderVariable *Args)
107 {
108         return NULL;
109 }
110 */

UCC git Repository :: git.ucc.asn.au