2004-11-11 04:06:00 +00:00
|
|
|
string read_file (string filename)
|
|
|
|
{
|
|
|
|
local QFile file;
|
2011-02-10 05:55:58 +00:00
|
|
|
local string data = nil, d;
|
2004-11-11 04:06:00 +00:00
|
|
|
file = Qopen (filename, "rtz");
|
|
|
|
if (!file) {
|
|
|
|
printf ("Can't open %s for reading."
|
2007-06-09 13:44:06 +00:00
|
|
|
" Probably a bad hardcoded filename:)\n", filename);
|
2011-02-10 05:55:58 +00:00
|
|
|
return nil;
|
2004-11-11 04:06:00 +00:00
|
|
|
}
|
|
|
|
while ((d = Qgetline (file)))
|
|
|
|
data = data + d;
|
|
|
|
//FIXME can't read to a string, can't convert a pointer to a string ...
|
|
|
|
//Qread (file, data, 1023);
|
|
|
|
Qclose (file);
|
|
|
|
d = str_new ();
|
|
|
|
str_copy (d, data);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_plist (void)
|
|
|
|
{
|
|
|
|
local string data, l;
|
2010-11-19 04:39:20 +00:00
|
|
|
local plitem_t pl, item, i;
|
2004-11-11 04:06:00 +00:00
|
|
|
|
2011-01-10 02:44:22 +00:00
|
|
|
data = read_file ("/home/bill/.quakeforge/gamedir.conf");
|
2004-11-11 04:06:00 +00:00
|
|
|
pl = PL_GetPropertyList ("{" + data + "}");
|
|
|
|
l = PL_WritePropertyList (pl);
|
|
|
|
printf ("%s", data);
|
|
|
|
printf ("%s", l);
|
2010-11-19 04:39:20 +00:00
|
|
|
i = PL_ObjectForKey (pl, "QF");
|
|
|
|
item = PL_RemoveObjectForKey (pl, "QF");
|
|
|
|
l = PL_WritePropertyList (item);
|
|
|
|
printf ("%s", l);
|
|
|
|
PL_Free (item);
|
|
|
|
//Because i and item both point to the same plitem, and item has been,
|
|
|
|
//freed, freeing i will generate an error
|
|
|
|
//l = PL_WritePropertyList (i);
|
2004-11-11 04:06:00 +00:00
|
|
|
PL_Free (pl);
|
|
|
|
str_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script (void)
|
|
|
|
{
|
|
|
|
local script_t script;
|
|
|
|
local string token;
|
|
|
|
local string data;
|
|
|
|
|
|
|
|
data = read_file ("progs.src");
|
|
|
|
script = Script_New ();
|
|
|
|
token = Script_Start (script, "progs.src", data);
|
|
|
|
while (Script_GetToken (script, 1)) {
|
|
|
|
printf ("%s\n", token);
|
|
|
|
}
|
|
|
|
Script_Delete (script);
|
|
|
|
str_free (data);
|
|
|
|
}
|
|
|
|
|
2004-01-03 08:43:57 +00:00
|
|
|
void () test_str =
|
|
|
|
{
|
|
|
|
local string a,b,c,d;
|
|
|
|
a = "testing ";
|
|
|
|
b = "temp ";
|
|
|
|
c = "strings ";
|
|
|
|
d = "\n";
|
|
|
|
print (a + b + c + d);
|
2004-01-04 07:42:43 +00:00
|
|
|
printf ("%i \"%.5s\" %3.4f %v\n", 14, "hi there", 3.1415926, '4 1 3');
|
2004-01-03 08:43:57 +00:00
|
|
|
};
|
2007-06-09 09:43:21 +00:00
|
|
|
void (...) dprint = #0;
|
2011-02-13 10:07:30 +00:00
|
|
|
integer main (integer argc, string *argv)
|
2001-11-02 03:03:01 +00:00
|
|
|
{
|
2002-11-12 02:56:10 +00:00
|
|
|
local integer i;
|
2003-08-23 22:16:42 +00:00
|
|
|
local SEL sel;
|
2007-06-09 09:43:21 +00:00
|
|
|
dprint ("foo", "bar\n");
|
2002-11-12 02:56:10 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
print (argv[i]);
|
|
|
|
print ("\n");
|
|
|
|
}
|
2002-05-31 06:16:10 +00:00
|
|
|
local id foo = [[Foo alloc] init];
|
|
|
|
[foo run];
|
2003-08-23 22:16:42 +00:00
|
|
|
sel = sel_get_uid ("run");
|
|
|
|
if (sel) {
|
|
|
|
print ("found selector for `run'\n");
|
|
|
|
if ([foo respondsToSelector:sel])
|
|
|
|
print ("foo responds to `run'\n");
|
|
|
|
else
|
|
|
|
print ("foo does not repond to `run'\n");
|
|
|
|
} else
|
|
|
|
print ("did not find selector for `run'\n");
|
|
|
|
sel = sel_get_uid ("alloc");
|
|
|
|
if (sel) {
|
|
|
|
print ("found selector for `alloc'\n");
|
|
|
|
if ([Object instancesRespondToSelector:sel])
|
|
|
|
print ("Object instances respond to `alloc'\n");
|
|
|
|
else
|
|
|
|
print ("Object instances do not repond to `alloc'\n");
|
|
|
|
} else
|
|
|
|
print ("did not find selector for `alloc'\n");
|
|
|
|
sel = sel_get_uid ("run:with:me:");
|
|
|
|
if (sel) {
|
|
|
|
print ("found selector for `run:with:me:'\n");
|
|
|
|
if ([Object instancesRespondToSelector:sel])
|
|
|
|
print ("Object instances respond to `run:with:me:'\n");
|
|
|
|
else
|
|
|
|
print ("Object instances do not repond to `run:with:me:'\n");
|
|
|
|
} else
|
|
|
|
print ("did not find selector for `run:with:me:'\n");
|
2004-01-03 08:43:57 +00:00
|
|
|
test_str ();
|
2004-11-11 04:06:00 +00:00
|
|
|
test_script ();
|
|
|
|
test_plist ();
|
2001-08-10 20:35:42 +00:00
|
|
|
return 0;
|
2001-06-05 23:53:55 +00:00
|
|
|
};
|