[DGD] Scanf vs explode
Michael McKiel
crashnbrn71 at yahoo.ca
Sat Apr 10 07:03:23 CEST 2004
I fashioned my creator() function in driver.c after the way the sscanf's were
originally done, due to the way the directories have changed, it requires
quite a few of them depending on which one is true, I was wondering if it
would be more efficient to do a single explode, and a switch() instead.
I know I've asked other efficiency questions, and perhaps its a bit redundant
but seems to me too much software these days takes little consideration into
that heh ;)
current (working) creator()::
string creator(string file)
{
/*
** doc/ && log/ && include/ are 'nil'
*/
return
(sscanf(file, USR + "/%s/", file) != 0) ? file :
(sscanf(file, DOMAINS+"/%s/", file) != 0) ? file :
/*
** May want to change WORLD && COMMAND to "common" later.
*/
(sscanf(file, COMMAND_DIR+"/%*s/") != 0) ? "System" :
(sscanf(file, WORLD_DIR+"/%*s/" ) != 0) ? "System" :
(sscanf(file, "/%*s"+SECURE_DIR+"/") != 0) ? "System" :
(sscanf(file, "/%*s"+KERNEL_DIR+"/") != 0) ? "System" :
/*
** This one handles /data/common as well.
*/
(sscanf(file, "/%*s"+COMMON_DIR+"/") != 0) ? "common" :
(sscanf(file, DATA_DIR+"/%*s/" ) != 0) ? "System" : nil;
}
possible (untested) creator() using explode::
string creator(string file)
{
string *arr;
arr = explode(file, "/");
if (sizeof(arr) < 2) return nil;
switch ("/"+arr[0]) {
case USR: return arr[1];
case WORLD_DIR:
if ("/"+arr[1] == AREA_DIR && arr[2]) return arr[2];
return "System";
case COMMAND_DIR: return "System";
default:
switch ("/"+arr[2]) {
case SECURE_DIR:
case KERNEL_DIR: return "System";
case COMMON_DIR: return "common";
default:
if ("/"+arr[0] == DATA_DIR) return "System";
return nil;
}
}
}
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list