Example #1
0
int treeprint(struct tree *t, int depth)
{
    if (t!=NULL) {
        int i=0;
        fflush(stdout);
        /**/  if(t->nkids==1) {
            for(i=0; i<t->nkids; i++) {
                treeprint(t->kids[i], depth);
            }
        }/**/
        else {
            if (depth != 0) {
                printf("%*s", depth*2, " ");
                fflush(stdout);
            }
            printf(" %d-%s: ",t->prodrule, rulename(t->prodrule));
            fflush(stdout);
            if (t->nkids==0) {
                printf("Leaf: %s\n", t->leaf->text);
            }
            else {
                printf("%d\n", t->nkids);
                fflush(stdout);
                for(i=0; i<t->nkids; i++) {
                    treeprint(t->kids[i], depth+1);
                }
            }
        }
    }
}
Example #2
0
status_t
LoadRules(const char *path, BObjectList<FilerRule> *ruleList)
{
	BEntry entry("/boot/home/config/settings/FilerRules");
	if (!entry.Exists())
		return B_OK;
	
	CppSQLite3DB db;
	db.open("/boot/home/config/settings/FilerRules");
	
	// Because this particular build of sqlite3 does not support multithreading
	// because of lack of pthreads support, we need to do this in a slightly different order
	
	CppSQLite3Query query;
	query = DBQuery(db,"select name from RuleList order by ruleid;","PrefsWindow::LoadRules");
	
	BString command;
	while (!query.eof())
	{
		BString rulename = query.getStringField((int)0);
		
		FilerRule *rule = new FilerRule;
		rule->SetDescription(DeescapeIllegalCharacters(rulename.String()).String());
		
		ruleList->AddItem(rule);
		
		query.nextRow();
	}
	
	query.finalize();
	
	for (int32 i = 0; i < ruleList->CountItems(); i++)
	{
		FilerRule *rule = ruleList->ItemAt(i);
		
		if (!rule)
			continue;
		
		BString rulename(EscapeIllegalCharacters(rule->GetDescription()));
		
		// Now comes the fun(?) part: loading the tests and actions. Joy. :/
		command = "select * from ";
		command << rulename << " where entrytype = 'test';";
		query = DBQuery(db,command.String(),"PrefsWindow::LoadRules");
		
		while (!query.eof())
		{
			BString classname = DeescapeIllegalCharacters(query.getStringField(1));
			BMessage *test = new BMessage;
			
			test->AddString("name",classname);
			
			if (classname.ICompare("Attribute") == 0)
			{
				test->AddString("mimetype",DeescapeIllegalCharacters(query.getStringField(4)));
				test->AddString("typename",DeescapeIllegalCharacters(query.getStringField(5)));
				test->AddString("attrname",DeescapeIllegalCharacters(query.getStringField(6)));
			}
			
			test->AddString("mode",DeescapeIllegalCharacters(query.getStringField(2)).String());
			test->AddString("value",DeescapeIllegalCharacters(query.getStringField(3)).String());
			
			rule->AddTest(test);
			
			query.nextRow();
		}
		query.finalize();
		
		command = "select * from ";
		command << rulename << " where entrytype = 'action';";
		query = DBQuery(db,command.String(),"PrefsWindow::LoadRules");
		
		while (!query.eof())
		{
			BMessage *action = new BMessage;
			
			action->AddString("name",DeescapeIllegalCharacters(query.getStringField(1)));
			action->AddString("value",DeescapeIllegalCharacters(query.getStringField(3)));
			
			rule->AddAction(action);
			
			query.nextRow();
		}
		query.finalize();
		
	}
	
	db.close();
	return B_OK;
}