Spike::Spike(Sint16 xcord, Sint16 ycord, const ParameterMap& param): Object(xcord,ycord,param) { weapon=Weapon(-10,W_TOUCH,WS_SPIKE); /* Parameters */ if (hasParam(parameters,"direction")) dir=getDirFromString(parameters["direction"]); else dir=DIR_UP; otype|=(DIR_ALL&(~dir)); }
/******************************************************************************* * bk_get_dir_from_string() * public function * gets a pointer to a Dir in tree described by the string pathStr * */ int bk_get_dir_from_string(const VolInfo* volInfo, const char* pathStr, BkDir** dirFoundPtr) { return getDirFromString(&(volInfo->dirTree), pathStr, dirFoundPtr); }
/******************************************************************************* * getDirFromString() * recursive * gets a pointer to a Dir in tree described by the string pathStr * */ int getDirFromString(const BkDir* tree, const char* pathStr, BkDir** dirFoundPtr) { size_t count; size_t pathStrLen; bool stopLooking; /* name of the directory in the path this instance of the function works on */ char* currentDirName; BkFileBase* child; int rc; pathStrLen = strlen(pathStr); if(pathStrLen == 1 && pathStr[0] == '/') /* root, special case */ { /* cast to prevent compiler const warning */ *dirFoundPtr = (BkDir*)tree; return 1; } if(pathStrLen < 3 || pathStr[0] != '/' || pathStr[1] == '/' || pathStr[pathStrLen - 1] != '/') return BKERROR_MISFORMED_PATH; stopLooking = false; for(count = 2; count < pathStrLen && !stopLooking; count++) /* find the first directory in the path */ { if(pathStr[count] == '/') /* found it */ { /* make a copy of the string to use with strcmp */ currentDirName = (char*)malloc(count); if(currentDirName == NULL) return BKERROR_OUT_OF_MEMORY; strncpy(currentDirName, &(pathStr[1]), count - 1); currentDirName[count - 1] = '\0'; child = tree->children; while(child != NULL && !stopLooking) /* each child directory in tree */ { if( strcmp(child->name, currentDirName) == 0 && IS_DIR(child->posixFileMode) ) /* found the right child directory */ { if(pathStr[count + 1] == '\0') /* this is the directory i'm looking for */ { *dirFoundPtr = BK_DIR_PTR(child); stopLooking = true; rc = 1; } else /* intermediate directory, go further down the tree */ { rc = getDirFromString(BK_DIR_PTR(child), &(pathStr[count]), dirFoundPtr); if(rc <= 0) { free(currentDirName); return rc; } stopLooking = true; } } child = child->next; } free(currentDirName); if(!stopLooking) return BKERROR_DIR_NOT_FOUND_ON_IMAGE; } /* if(found it) */ } /* for(find the first directory in the path) */ /* can't see how i could get here but to keep the compiler happy */ return 1; }