spBool spShapeLessThan(const spShape* a, const spShape* b) { NULLCHECK(a); NULLCHECK(b); return a < b ? spTrue : spFalse; }
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures) { NULLCHECK(option); NULLCHECK(defValue); CMeasurePlugin* measure = (CMeasurePlugin*)rm; CConfigParser& parser = measure->GetMeterWindow()->GetParser(); return parser.ReadString(measure->GetName(), option, defValue, (bool)replaceMeasures).c_str(); }
spBool spShapesCanCollide(spShape* a, spShape* b) { NULLCHECK(a); NULLCHECK(b); if (a->filter.group == spCollideAll && b->filter.group == spCollideAll) return spTrue; if (a->filter.group == b->filter.group) return spFalse; if (a->filter.type & b->filter.collide) return spTrue; if (b->filter.type & a->filter.collide) return spTrue; return spFalse; }
// Deprecated! LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue) { NULLCHECK(section); NULLCHECK(option); NULLCHECK(defValue); CConfigParser* parser = Rainmeter->GetCurrentParser(); if (parser) { return parser->ReadString(section, option, defValue, false).c_str(); } return defValue; }
void spShapeInit(spShape* shape, spMassData* data, spBound* bound, spShapeType type) { NULLCHECK(shape); NULLCHECK(data); NULLCHECK(bound); shape->mass_data = *data; shape->material = spDefaultMaterial; shape->bound = *bound; shape->type = type; shape->body = NULL; shape->next = NULL; shape->prev = NULL; shape->filter = spFilterCollideAll; }
void spShapeFree(spShape** Shape) { NULLCHECK(Shape); spShape* shape = *Shape; if (shape->body) { spBodyRemoveShape(shape->body, shape); } /// shape is a poly if (shape->type == SP_SHAPE_POLYGON) { spPolygonFree(Shape); } /// shape is a circle else if (shape->type == SP_SHAPE_CIRCLE) { spCircleFree(Shape); } /// shape is a segment else { spSegmentFree(Shape); } }
/** Test whether AF_INET or AF_INET6 sockaddr is included in the given access * control list, returning 1 if it is, and 0 if not. */ static int is_included_in_acl(int list_length, struct ip_and_mask (*list)[], union mysockaddr *test) { NULLCHECK(test); int i; for (i = 0; i < list_length; i++) { struct ip_and_mask *entry = &(*list)[i]; int testbits; unsigned char *raw_address1 = NULL, *raw_address2 = NULL; debug("checking acl entry %d (%d/%d)", i, test->generic.sa_family, entry->ip.family); if (test->generic.sa_family != entry->ip.family) { continue; } if (test->generic.sa_family == AF_INET) { debug("it's an AF_INET"); raw_address1 = (unsigned char *) &test->v4.sin_addr; raw_address2 = (unsigned char *) &entry->ip.v4.sin_addr; } else if (test->generic.sa_family == AF_INET6) { debug("it's an AF_INET6"); raw_address1 = (unsigned char *) &test->v6.sin6_addr; raw_address2 = (unsigned char *) &entry->ip.v6.sin6_addr; } else { fatal("Can't check an ACL for this address type."); } debug("testbits=%d", entry->mask); for (testbits = entry->mask; testbits > 0; testbits -= 8) { debug("testbits=%d, c1=%02x, c2=%02x", testbits, raw_address1[0], raw_address2[0]); if (testbits >= 8) { if (raw_address1[0] != raw_address2[0]) { goto no_match; } } else { if ((raw_address1[0] & testmasks[testbits % 8]) != (raw_address2[0] & testmasks[testbits % 8])) { goto no_match; } } raw_address1++; raw_address2++; } return 1; no_match:; debug("no match"); } return 0; }
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue) { NULLCHECK(option); CMeasurePlugin* measure = (CMeasurePlugin*)rm; CConfigParser& parser = measure->GetMeterWindow()->GetParser(); return parser.ReadFloat(measure->GetName(), option, defValue); }
void spMassDataInit(spMassData* data, const spVector center, spFloat inertia, spFloat mass) { NULLCHECK(data); data->inertia = inertia; data->mass = mass; data->com = center; }
spConstraint* spMotorJointNew(spBody* a, spBody* b, spFloat w) { spMotorJoint* joint = spMotorJointAlloc(); NULLCHECK(joint); spMotorJointInit(joint, a, b, w); return (spConstraint*) joint; }
spConstraint* spGearJointNew(spBody* a, spBody* b, spFloat ratio, spFloat phase) { spGearJoint* joint = spGearJointAlloc(); NULLCHECK(joint); spGearJointInit(joint, a, b, ratio, phase); return (spConstraint*) joint; }
void spGearJointInit(spGearJoint* joint, spBody* a, spBody* b, spFloat ratio, spFloat phase) { NULLCHECK(joint); NULLCHECK(a); NULLCHECK(b); joint->constraint = spConstraintConstruct(a, b, SP_GEAR_JOINT); joint->lambdaAccum = 0.0f; joint->ratioInv = ratio ? 1.0f / ratio : 0.0f; joint->ratio = ratio; joint->eMass = 0.0f; joint->phase = phase; joint->bias = 0.0f; spConstraintInitFuncs(&joint->constraint.funcs, (spFreeFunc)Free, (spPreSolveFunc)PreSolve, (spWarmStartFunc)WarmStart, (spSolveFunc)Solve); }
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath) { NULLCHECK(relativePath); CMeasurePlugin* measure = (CMeasurePlugin*)rm; g_Buffer = relativePath; measure->GetMeterWindow()->MakePathAbsolute(g_Buffer); return g_Buffer.c_str(); }
int acl_includes(struct acl *acl, union mysockaddr *addr) { NULLCHECK(acl); if (0 == acl->len) { return !(acl->default_deny); } else { return is_included_in_acl(acl->len, acl->entries, addr); } }
LPCWSTR __stdcall RmReplaceVariables(void* rm, LPCWSTR str) { NULLCHECK(str); MeasurePlugin* measure = (MeasurePlugin*)rm; ConfigParser& parser = measure->GetMeterWindow()->GetParser(); g_Buffer = str; parser.ReplaceVariables(g_Buffer); parser.ReplaceMeasures(g_Buffer); return g_Buffer.c_str(); }
void __stdcall RmLog(void* rm, int level, LPCWSTR message) { NULLCHECK(message); MeasurePlugin* measure = (MeasurePlugin*)rm; // Ignore Debug messages from plugins unless in debug mode. if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) { GetLogger().LogSection((Logger::Level)level, measure, message); } }
void parse_port(char *s_port, struct sockaddr_in *out) { NULLCHECK(s_port); int raw_port; raw_port = atoi(s_port); if (raw_port < 0 || raw_port > 65535) { fatal("Port number must be >= 0 and <= 65535"); } out->sin_port = htobe16(raw_port); }
BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage) { NULLCHECK(pszMessage); // Ignore LOG_DEBUG messages from plugins unless in debug mode if (nLevel != LOG_DEBUG || Rainmeter->GetDebug()) { Log(nLevel, pszMessage); } return TRUE; }
BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message) { NULLCHECK(message); // Ignore Debug messages from plugins unless in debug mode. if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) { GetLogger().Log((Logger::Level)level, L"", message); } return TRUE; }
/* FIXME: should change this to return negative on error like everything else */ int parse_ip_to_sockaddr(struct sockaddr *out, char *src) { NULLCHECK(out); NULLCHECK(src); char temp[64]; struct sockaddr_in *v4 = (struct sockaddr_in *) out; struct sockaddr_in6 *v6 = (struct sockaddr_in6 *) out; /* allow user to start with [ and end with any other invalid char */ { int i = 0, j = 0; if (src[i] == '[') { i++; } for (; i < 64 && IS_IP_VALID_CHAR(src[i]); i++) { temp[j++] = src[i]; } temp[j] = 0; } if (temp[0] == '0' && temp[1] == '\0') { v4->sin_family = AF_INET; v4->sin_addr.s_addr = INADDR_ANY; return 1; } if (inet_pton(AF_INET, temp, &v4->sin_addr) == 1) { out->sa_family = AF_INET; return 1; } if (inet_pton(AF_INET6, temp, &v6->sin6_addr) == 1) { out->sa_family = AF_INET6; return 1; } return 0; }
int parse_to_sockaddr(struct sockaddr *out, char *address) { struct sockaddr_un *un = (struct sockaddr_un *) out; NULLCHECK(address); if (address[0] == '/') { un->sun_family = AF_UNIX; strncpy(un->sun_path, address, 108); /* FIXME: linux only */ return 1; } return parse_ip_to_sockaddr(out, address); }
struct spCircle* spShapeCastCircle(const spShape* shape) { NULLCHECK(shape); if (shape->type == SP_SHAPE_CIRCLE) { return (spCircle*)shape; } else { spWarning(spFalse, "the shape is not a circle!\n"); return NULL; } }
struct spPolygon* spShapeCastPolygon(const spShape* shape) { NULLCHECK(shape); if (shape->type == SP_SHAPE_POLYGON) { return (spPolygon*)shape; } else { spWarning(spFalse, "the shape is not a polygon!\n"); return NULL; } }
struct spSegment* spShapeCastSegment(const spShape* shape) { NULLCHECK(shape); if (shape->type == SP_SHAPE_SEGMENT) { return (spSegment*)shape; } else { spWarning(spFalse, "the shape is not a segment!\n"); return NULL; } }
spBool spShapeTestPoint(spShape* shape, spVector point) { NULLCHECK(shape); switch (shape->type) { case SP_SHAPE_CIRCLE: return spCircleTestPoint((spCircle*) shape, point); case SP_SHAPE_POLYGON: return spPolygonTestPoint((spPolygon*) shape, point); case SP_SHAPE_SEGMENT: return spFalse; } return spFalse; }
void RmLogF(void* rm, int level, LPCWSTR format, ...) { NULLCHECK(format); MeasurePlugin* measure = (MeasurePlugin*)rm; // Ignore Debug messages from plugins unless in debug mode. if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) { va_list args; va_start(args, format); GetLogger().LogSectionVF((Logger::Level)level, measure, format, args); va_end(args); } }
static void Free(spMotorJoint** joint) { NULLCHECK(*joint); spFree(joint); }
void spShapeSetFilter(spShape* shape, const spFilter filter) { NULLCHECK(shape); shape->filter = filter; }
void spShapeSetRestitution(spShape* shape, spFloat restitution) { NULLCHECK(shape); shape->material.restitution = restitution; }
void spShapeSetFriction(spShape* shape, spFloat friction) { NULLCHECK(shape); shape->material.friction = friction; }