-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.c
121 lines (103 loc) · 2.16 KB
/
app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (C) 2010,2011 by Milan Kazarka
*
* You may distribute under the terms of the Artistic License,
* as specified in the README file.
*
*/
/** a non finished implementation to handle application launching, which
* should replace our current very simple system
*/
#include "app.h"
struct app *apps = NULL;
struct app *appNew( )
{
struct app *myApp = NULL;
myApp = (struct app*)malloc(sizeof(struct app));
myApp->name[0] = 0x00;
myApp->next = NULL;
if (!apps)
apps = myApp;
else
{
myApp->next = apps;
apps = myApp;
}
return myApp;
}
void appRelease( struct app *myApp )
{
if (!myApp)
return;
free(myApp);
}
int appIsRegistered( unsigned char *name )
{
struct app *current = NULL;
if (!name)
return 0;
current = apps;
while(current)
{
if (current->name[0]!=0x00)
if (strcmp((char*)name,(char*)current->name)==0)
return 1;
current = current->next;
}
return 0;
}
void appListApplications( )
{
#ifdef _DEBUG
struct app *current = apps;
while(current)
{
if (current->name[0]!=0x00)
{
fprintf(stderr,"appListApplications app(%s)\n",
(char*)current->name);
}
current = current->next;
}
#endif
}
/** register all applications
*/
void appRegisterAll( )
{
struct app *current = NULL;
struct dirent *dp;
DIR *dir = opendir(_APPS_DIRECTORY);
unsigned char path[256];
if (!dir)
{
#ifdef _DEBUG
fprintf(stderr,
"appRegisterAll error no applications directory\n");
#endif
return;
}
while((dp=readdir(dir)) != NULL)
{
if (dp->d_name[0]=='.')
continue;
if (appIsRegistered((unsigned char*)dp->d_name))
continue;
sprintf((char*)path,"%s/%s/app.bin",_APPS_DIRECTORY,(char*)dp->d_name);
if( access((char*)path, F_OK ) != -1 )
{
current = appNew();
strcpy((char*)current->name,(char*)dp->d_name);
}
else
{
#ifdef _DEBUG
fprintf(stderr,
"appRegisterAll warning application %s missing binary\n",
(char*)dp->d_name);
#endif
}
}
closedir(dir);
appListApplications();
}