36,19 → 36,27 |
|
static sysinfo_item_t* sysinfo_find_item(const char *name,sysinfo_item_t *subtree) |
{ |
if(subtree==NULL) return NULL; |
while(subtree!=NULL) |
{ |
int i; |
char *a,*b; |
a=(char *)name; |
b=subtree->name; |
while((a[i]==b[i])&&(b[i])) i++; |
if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ |
if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ |
{ |
if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_find_item(a+i+1,subtree->subinfo.table); |
//if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/ |
if (subtree == NULL) |
return NULL; |
|
while (subtree != NULL) { |
int i = 0; |
char *a = (char *) name; |
char *b = subtree->name; |
|
while ((a[i] == b[i]) && (b[i])) |
i++; |
|
if ((!a[i]) && (!b[i])) /* Last name in path matches */ |
return subtree; |
|
if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */ |
if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE) |
return sysinfo_find_item(a + i + 1, subtree->subinfo.table); |
|
//if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ |
// return NULL; |
|
return NULL; /*No subinfo*/ |
} |
/* No matches try next*/ |
63,12 → 71,10 |
sysinfo_item_t *subtree; |
subtree = *psubtree; |
|
if(subtree==NULL) |
{ |
sysinfo_item_t *item; |
if (subtree == NULL) { |
sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); |
int i=0,j; |
|
item = malloc(sizeof(sysinfo_item_t),0); |
ASSERT(item); |
*psubtree = item; |
item -> next = NULL; |
75,16 → 81,17 |
item -> val_type = SYSINFO_VAL_UNDEFINED; |
item -> subinfo.table = NULL; |
|
while(name[i]&&(name[i]!='.')) i++; |
while (name[i] && (name[i] != '.')) |
i++; |
|
item -> name = malloc(i,0); |
ASSERT(item -> name); |
|
for(j=0;j<i;j++) item->name[j]=name[j]; |
for (j = 0; j < i; j++) |
item->name[j] = name[j]; |
item->name[j]=0; |
|
if(name[i]/*=='.'*/) |
{ |
if (name[i]) { /* =='.' */ |
item -> subinfo_type = SYSINFO_SUBINFO_TABLE; |
return sysinfo_create_path(name+i+1,&(item->subinfo.table)); |
} |
92,31 → 99,35 |
return item; |
} |
|
while(subtree!=NULL) |
{ |
while (subtree != NULL) { |
int i=0,j; |
char *a,*b; |
a=(char *)name; |
b=subtree->name; |
while((a[i]==b[i])&&(b[i])) i++; |
if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ |
if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ |
{ |
if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); |
if(subtree->subinfo_type==SYSINFO_SUBINFO_NONE) |
{ |
char *a = (char *) name; |
char *b = subtree->name; |
|
while ((a[i] == b[i]) && (b[i])) |
i++; |
|
if ((!a[i]) && (!b[i])) /* Last name in path matches */ |
return subtree; |
|
if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */ |
if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE) |
return sysinfo_create_path(a + i + 1, &(subtree->subinfo.table)); |
|
if (subtree->subinfo_type == SYSINFO_SUBINFO_NONE) { |
subtree->subinfo_type=SYSINFO_SUBINFO_TABLE; |
return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); |
} |
//if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/ |
|
//if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ |
// return NULL; |
|
return NULL; |
} |
/* No matches try next or create new*/ |
if(subtree->next==NULL) |
{ |
sysinfo_item_t *item; |
if (subtree->next == NULL) { |
sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); |
|
item = malloc(sizeof(sysinfo_item_t),0); |
ASSERT(item); |
subtree -> next = item; |
item -> next = NULL; |
124,24 → 135,24 |
item -> subinfo.table = NULL; |
|
i=0; |
while(name[i]&&(name[i]!='.')) i++; |
while (name[i] && (name[i] != '.')) |
i++; |
|
item -> name = malloc(i,0); |
ASSERT(item -> name); |
for(j=0;j<i;j++) item->name[j]=name[j]; |
|
for (j = 0; j < i; j++) |
item->name[j] = name[j]; |
|
item->name[j]=0; |
|
if(name[i]/*=='.'*/) |
{ |
if(name[i]) { /* =='.' */ |
item -> subinfo_type = SYSINFO_SUBINFO_TABLE; |
return sysinfo_create_path(name+i+1,&(item->subinfo.table)); |
} |
item -> subinfo_type = SYSINFO_SUBINFO_NONE; |
return item; |
|
} |
else |
{ |
} else { |
subtree=subtree->next; |
i=0; |
} |
152,12 → 163,14 |
|
void sysinfo_set_item_val(const char *name,sysinfo_item_t **root,__native val) |
{ |
if(root==NULL) root=&_root; |
sysinfo_item_t *item; |
item = sysinfo_create_path(name,root); /* If already created create only returns pointer |
If ! , create it */ |
if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ |
{ |
if (root == NULL) |
root = &_root; |
|
/* If already created create only returns pointer |
If not, create it */ |
sysinfo_item_t *item = sysinfo_create_path(name, root); |
|
if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ |
item->val.val=val; |
item -> val_type = SYSINFO_VAL_VAL; |
} |
165,12 → 178,14 |
|
void sysinfo_set_item_function(const char *name,sysinfo_item_t **root,sysinfo_val_fn_t fn) |
{ |
if(root==NULL) root=&_root; |
sysinfo_item_t *item; |
item = sysinfo_create_path(name,root); /* If already created create only returns pointer |
If ! , create it */ |
if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ |
{ |
if (root == NULL) |
root = &_root; |
|
/* If already created create only returns pointer |
If not, create it */ |
sysinfo_item_t *item = sysinfo_create_path(name, root); |
|
if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ |
item->val.fn=fn; |
item -> val_type = SYSINFO_VAL_FUNCTION; |
} |
179,10 → 194,15 |
|
void sysinfo_set_item_undefined(const char *name,sysinfo_item_t **root) |
{ |
if(root==NULL) root=&_root; |
sysinfo_item_t *item; |
item = sysinfo_find_item(name,*root); |
if(item!=NULL) item -> val_type = SYSINFO_VAL_UNDEFINED; |
if (root == NULL) |
root = &_root; |
|
/* If already created create only returns pointer |
If not, create it */ |
sysinfo_item_t *item = sysinfo_create_path(name, root); |
|
if (item != NULL) |
item->val_type = SYSINFO_VAL_UNDEFINED; |
} |
|
|
189,40 → 209,40 |
void sysinfo_dump(sysinfo_item_t **proot,int depth) |
{ |
sysinfo_item_t *root; |
if(proot==NULL) proot=&_root; |
if (proot == NULL) |
proot = &_root; |
|
root = *proot; |
|
while(root!=NULL) |
{ |
|
while (root != NULL) { |
int i; |
__native val=0; |
char *vtype=NULL; |
|
|
for(i=0;i<depth;i++) printf(" "); |
for (i = 0; i < depth; i++) |
printf(" "); |
|
switch (root->val_type) |
{ |
case (SYSINFO_VAL_UNDEFINED): |
switch (root->val_type) { |
case SYSINFO_VAL_UNDEFINED: |
val=0; |
vtype="UND"; |
break; |
case (SYSINFO_VAL_VAL): |
case SYSINFO_VAL_VAL: |
val=root->val.val; |
vtype="VAL"; |
break; |
case (SYSINFO_VAL_FUNCTION): |
case SYSINFO_VAL_FUNCTION: |
val=((sysinfo_val_fn_t)(root->val.fn))(root); |
vtype="FUN"; |
break; |
} |
printf("%s %s val:%d(%X) sub:%s\n",root->name,vtype,val,val, |
(root->subinfo_type==SYSINFO_SUBINFO_NONE)?"NON":((root->subinfo_type==SYSINFO_SUBINFO_TABLE)?"TAB":"FUN")); |
|
printf("%s %s val:%d(%X) sub:%s\n", root->name, vtype, val, val, (root->subinfo_type == SYSINFO_SUBINFO_NONE) ? "NON" : ((root->subinfo_type == SYSINFO_SUBINFO_TABLE) ? "TAB" : "FUN")); |
|
if(root -> subinfo_type == SYSINFO_SUBINFO_TABLE) |
sysinfo_dump(&(root->subinfo.table),depth+1); |
|
root=root->next; |
} |
} |
229,23 → 249,25 |
|
sysinfo_rettype_t sysinfo_get_val(const char *name,sysinfo_item_t **root) |
{ |
/*TODO: |
Implement Subsystem subinfo (by function implemented subinfo) |
*/ |
// TODO: Implement Subsystem subinfo (by function implemented subinfo) |
|
sysinfo_rettype_t ret={0,false}; |
|
if(root==NULL) root=&_root; |
sysinfo_item_t *item; |
item = sysinfo_find_item(name,*root); |
if(item!=NULL) |
{ |
if (root == NULL) |
root = &_root; |
|
sysinfo_item_t *item = sysinfo_find_item(name, *root); |
|
if (item != NULL) { |
if (item -> val_type == SYSINFO_VAL_UNDEFINED) |
return ret; |
else ret.valid=true; |
else |
ret.valid = true; |
|
if (item -> val_type == SYSINFO_VAL_VAL) |
ret.val=item -> val.val; |
else ret.val=((sysinfo_val_fn_t)(item->val.fn))(item); |
else |
ret.val = ((sysinfo_val_fn_t) (item->val.fn)) (item); |
} |
return ret; |
} |
255,9 → 277,11 |
char *str; |
sysinfo_rettype_t ret={0,0}; |
str=malloc(len+1,0); |
|
ASSERT(str); |
if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) |
ret=sysinfo_get_val(str,NULL); |
|
free(str); |
return ret.valid; |
} |
267,11 → 291,11 |
char *str; |
sysinfo_rettype_t ret={0,0}; |
str=malloc(len+1,0); |
|
ASSERT(str); |
if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) |
ret=sysinfo_get_val(str,NULL); |
|
free(str); |
return ret.val; |
} |
|
|