void initialize() { static int a_buf[7*FIELDS], *a = a_buf; static int ac_buf[7*FIELDS], *ac = ac_buf; static const int dr[8] = { -1, 0, 0, +1, -1, -1, +1, +1 }; static const int dc[8] = { 0, -1, +1, 0, -1, +1, -1, +1 }; int r1, c1, r2, c2, d; for (r1 = 0; r1 < 7; ++r1) { for (c1 = 0; c1 < 7; ++c1) { sprintf(field_str[POS(r1,c1)], "%c%c", 'a' + c1, '1' + r1); adjacent[POS(r1,c1)] = a; adjacent_capture[POS(r1,c1)] = ac; for (d = 0; d < ((POS(r1,c1)&1) ? 4 : 8); ++d) { r2 = r1 + dr[d]; c2 = c1 + dc[d]; if (VALID(r2, c2)) { *a++ = POS(r2,c2); if (VALID(r2 + dr[d], c2 + dc[d])) *ac++ = POS(r2,c2); } } *a++ = -1; *ac++ = -1; } } }
/************************************************************************* * StrMatchCase */ int StrMatchCase(char *string, char *pattern) { assert(VALID(string)); assert(VALID(pattern)); for (; ('*' != *pattern); ++pattern, ++string) { if (NIL == *string) { return (NIL == *pattern); } if ((*string != *pattern) && ('?' != *pattern)) { return FALSE; } } /* two-line patch to prevent *too* much recursiveness: */ while ('*' == pattern[1]) pattern++; do { if ( StrMatchCase(string, &pattern[1]) ) { return TRUE; } } while (*string++); return FALSE; }
/************************************************************************* * StrEqualMax */ int StrEqualMax(const char *first, size_t max, const char *second) { assert(VALID(first)); assert(VALID(second)); if (VALID(first) && VALID(second)) { #if defined(USE_STRNCASECMP) return (0 == strncasecmp(first, second, max)); #else /* Not adequately tested yet */ size_t cnt = 0; while ((*first != NIL) && (*second != NIL) && (cnt <= max)) { if (toupper(*first) != toupper(*second)) { break; } first++; second++; cnt++; } return ((cnt == max) || ((*first == NIL) && (*second == NIL))); #endif } return FALSE; }
int main() { printf("%d, %d, %d\n",DAYS(2010,2),DAYS(2010,8),DAYS(2010,11)); printf("%d,%d\n", VALID(2010,2,29),VALID(2020,2,29)); return 0; }
/************************************************************************* * StrAppendMax */ char *StrAppendMax(char *target, size_t max, const char *source) { assert(VALID(target)); assert(VALID(source)); assert(max > 0); max -= StrLength(target) + 1; return (max > 0) ? strncat(target, source, max) : target; }
/************************************************************************* * StrCopyMax */ char *StrCopyMax(char *target, size_t max, const char *source) { assert(VALID(target)); assert(VALID(source)); assert(max > 0); /* Includes != 0 */ target = strncpy(target, source, max - 1); target[max - 1] = (char)0; return target; }
void jx_pointer_clone(const jx_pointer *self, jx_pointer *out_clone) { VALID(self); /* point to the same data */ out_clone->data = self->data; /* increment the reference counter */ out_clone->data->refs++; VALID(out_clone); }
int strings(char *fn) { FILE *f; int state=1; int c; char *seq = 0; f = stdin; if (fn && (f = fopen(fn, "r")) == NULL) return -1; if (!fn) fn = "standard input"; while ((c = getc(f)) != EOF) { redo: switch (state) { case 0: /* searching for ascii */ if (VALID(c)) { state=1; seq = seq_hold; goto redo; } break; case 1: /* holding sequence */ if (VALID(c)) { *seq++ = c; if (seq-seq_hold >= opts.minlen) { *seq++ = 0; if (opts.pr_fn) printf("%s: ", fn); printf("%s", seq_hold); state = 2; } } else state = 0; break; case 2: /* write sequences */ if (VALID(c)) { putchar(c); } else { putchar('\n'); state = 0; } break; } } if (state == 2) putchar('\n'); if (f != stdin) fclose(f); return 0; }
/************************************************************************* * StrEqualLocale */ int StrEqualLocale(const char *first, const char *second) { assert(VALID(first)); assert(VALID(second)); #if defined(LC_COLLATE) return (strcoll(first, second) == 0); #else return StrEqual(first, second); #endif }
/************************************************************************* * StrEqualCaseMax */ int StrEqualCaseMax(const char *first, size_t max, const char *second) { assert(VALID(first)); assert(VALID(second)); if (VALID(first) && VALID(second)) { return (0 == strncmp(first, second, max)); } return FALSE; }
/************************************************************************* * StrEqualCase */ int StrEqualCase(const char *first, const char *second) { assert(VALID(first)); assert(VALID(second)); if (VALID(first) && VALID(second)) { return (0 == strcmp(first, second)); } return FALSE; }
/************************************************************************* * StrFormatDate */ size_t StrFormatDateMax(char *target, size_t max, const char *format, const struct tm *datetime) { assert(VALID(target)); assert(VALID(format)); assert(VALID(datetime)); assert(max > 0); return strftime(target, max, format, datetime); }
static void channel_info (void *elem, void *data) { CHANNEL *chan = (CHANNEL *) elem; ASSERT (VALID (elem)); ASSERT (VALID (data)); if ((chan->flags & ON_CHANNEL_PRIVATE) == 0) send_cmd ((CONNECTION *) data, MSG_SERVER_CHANNEL_LIST /* 618 */ , "%s %d %s", chan->name, effective_channel_count (chan->users, ((CONNECTION *) data)->user-> level >= LEVEL_MODERATOR), chan->topic); }
bool skiplist_itor_valid(const skiplist_itor* itor) { ASSERT(itor != NULL); return VALID(itor); }
bool DomainShader::Create(Blob & shaderbuffer) { HRESULT hr = DX11API::D3D11Device()->CreateDomainShader(shaderbuffer.m_pBlob->GetBufferPointer(), shaderbuffer.m_pBlob->GetBufferSize(), nullptr, &m_pShader); VALID(hr); }
/************************************************************************* * StrSpanFunction * * Untested */ size_t StrSpanFunction(char *source, int (*Function)(int)) { size_t count = 0; assert(VALID(source)); assert(VALID(Function)); while (*source != NIL) { if (Function(*source)) break; /* while */ source++; count++; } return count; }
void MPyEmbed_CBPostFrame(void) { int i; if (!PythonAvailable) { return; } PyThread_acquire_lock(threaddatalock, WAIT_LOCK); for (i = 0; i < THREADS; i++) { if (VALID(threaddata[i])) { PyObject *cb = threaddata[i].postframe; PyThreadState *ts = threaddata[i].mainstate; PyObject *rv; PyThread_release_lock(threaddatalock); ts->thread_id = PyThread_get_thread_ident(); PyEval_AcquireThread(ts); if (cb != NULL && PyCallable_Check(cb)) { rv = PyObject_CallObject(cb, NULL); Py_XDECREF(rv); if (rv == NULL) { PyErr_Print(); } } PyEval_ReleaseThread(ts); PyThread_acquire_lock(threaddatalock, WAIT_LOCK); } } PyThread_release_lock(threaddatalock); }
bool Texture2D::CreateDepthStencilView(ID3D11DepthStencilView** pView, const DepthStencilViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateDepthStencilView(m_pTexture, ¶ms, pView); VALID(hr); }
void glite_lbu_FreeDBContext(glite_lbu_DBContext ctx) { if (!ctx || !VALID(ctx->backend)) return; free(ctx->err.desc); ctx->err.desc = NULL; backends[ctx->backend]->freeContext(ctx); }
bool Texture2D::CreateRenderTargetView(RenderTargetView & view, const RenderTargetViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateRenderTargetView(m_pTexture, ¶ms, view.GetView(0)); VALID(hr); }
bool Texture2D::CreateRenderTargetView(ID3D11RenderTargetView** ppView, const RenderTargetViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateRenderTargetView(m_pTexture, ¶ms, ppView); VALID(hr); }
bool Texture2D::CreateUnorderedAccessView(ID3D11UnorderedAccessView** ppView, const UnorderedAccessViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateUnorderedAccessView(m_pTexture, ¶ms, ppView); VALID(hr); }
bool Texture2D::CreateUnorderedAccessView(UnorderedAccessView & view, const UnorderedAccessViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateUnorderedAccessView(m_pTexture, ¶ms, view.GetView(0)); VALID(hr); }
bool Texture2D::CreateShaderResourceView(ID3D11ShaderResourceView** ppView, const ShaderResourceViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateShaderResourceView(m_pTexture, ¶ms, ppView); VALID(hr); }
bool Texture2D::CreateShaderResourceView(ShaderResourceView & view, const ShaderResourceViewParams & params) const { auto hr = DX11API::D3D11Device()->CreateShaderResourceView(m_pTexture, ¶ms, view.GetView(0)); VALID(hr); }
bool skiplist_itor_first(skiplist_itor* itor) { ASSERT(itor != NULL); itor->node = itor->list->head->link[0]; return VALID(itor); }
bool skiplist_itor_prevn(skiplist_itor* itor, size_t count) { ASSERT(itor != NULL); while (count--) if (!skiplist_itor_prev(itor)) return false; return VALID(itor); }
int main(int argc, char **argv) { domainname d1, d2; char *data1, *data2, *data3, *data4; if (argc < 3) { printf("Usage: %s domainname domainname\n", argv[0]); return 1; } data1 = (char *) malloc(MAX_LENGTH); data2 = (char *) malloc(MAX_LENGTH); data3 = (char *) malloc(MAX_LENGTH); data4 = (char *) malloc(MAX_LENGTH); d1 = text_to_domain(argv[1]); if (!VALID(d1)) { printf("Invalid domain name \"%s\"\n", argv[1]); return 1; } d2 = text_to_domain(argv[2]); if (!VALID(d2)) { printf("Invalid domain name \"%s\"\n", argv[2]); return 1; } printf ("The canonical version of \"%s\" is \"%s\"; its TLD is \"%s\".\n\t**s registered domain is \"%s\", it has %i labels\n", orig_domain_name(data1, d1), domain_name(data2, d1), tld(data3, d1), registered_domain_name(data4, d1), (int) nlabels(d1)); if (are_equal(d1, d2)) { printf("%s and %s are equivalent domain names\n", argv[1], argv[2]); } else { printf("%s and %s are NOT equivalent domain names\n", argv[1], argv[2]); } if (are_identical(d1, d2)) { printf("%s and %s are absolutely identical\n", argv[1], argv[2]); } else { printf("%s and %s are NOT absolutely identical\n", argv[1], argv[2]); } free(data1); free(data2); free(data3); free(data4); return 0; }
bool skiplist_itor_next(skiplist_itor* itor) { ASSERT(itor != NULL); if (!itor->node) return skiplist_itor_first(itor); itor->node = itor->node->link[0]; return VALID(itor); }
bool skiplist_itor_prev(skiplist_itor* itor) { ASSERT(itor != NULL); if (!itor->node) return skiplist_itor_last(itor); itor->node = itor->node->prev; return VALID(itor); }