/** * Remove all entries in the context's include path. */ XKB_EXPORT void xkb_context_include_path_clear(struct xkb_context *ctx) { char **path; darray_foreach(path, ctx->includes) free(*path); darray_free(ctx->includes); darray_foreach(path, ctx->failed_includes) free(*path); darray_free(ctx->failed_includes); }
static Ret linear_container_darray_foreach(LinearContainer* thiz, DataVisitFunc visit, void* ctx) { PrivInfo* priv = (PrivInfo*)thiz->priv; return darray_foreach(priv->darray, visit, ctx); }
static void unbreak_backslash_broken_lines(struct token_list *tl, tok_message_queue *mq) { const char *s = tl->orig, *e = s+tl->orig_size; darray_char *txt = talloc_darray(tl); darray(const char*) *olines = talloc_darray(tl); darray(const char*) *tlines = talloc_darray(tl); do { const char *line_start = s, *line_end; const char *lnw; //last non-white size_t start_offset = txt->size; //scan to the next line and find the last non-white character in the line while (s<e && !creturn(*s)) s++; line_end = s; lnw = s; while (lnw>line_start && cspace(lnw[-1])) lnw--; if (s<e && creturn(*s)) { s++; //check for non-standard newlines (i.e. "\r", "\r\n", or "\n\r") if (s<e && *s=='\n'+'\r'-s[-1]) s++; } //add the backslash-break-free version of the text if (lnw>line_start && lnw[-1]=='\\' && line_end<e) { darray_append_items(*txt, line_start, lnw-1-line_start); if (lnw<e && cspace(*lnw)) { tok_msg_warn(spaces_after_backslash_break, lnw, "Trailing spaces after backslash-broken line"); } } else darray_append_items(*txt, line_start, s-line_start); //add the line starts for this line darray_append(*olines, line_start); darray_append(*tlines, (const char*)start_offset); //Since the txt buffer moves when expanded, we're storing offsets // for now. Once we're done building txt, we can add the base // of it to all the offsets to make them pointers. } while (s<e); //stick a null terminator at the end of the text darray_realloc(*txt, txt->size+1); txt->item[txt->size] = 0; //convert the line start offsets to pointers { const char **i; darray_foreach(i, *tlines) *i = txt->item + (size_t)(*i); } tl->olines = olines->item; tl->olines_size = olines->size; tl->txt = txt->item; tl->txt_size = txt->size; tl->tlines = tlines->item; tl->tlines_size = tlines->size; }
int main(int argc, char* argv[]) { int i = 0; int n = 100; int data = 0; DArray* darray = darray_create(NULL, NULL); for (i = 0; i < n; i++) { darray_append(darray, (void*)(rand() % n)); } darray_sort(darray, quick_sort, cmp_int); darray_foreach(darray, print_int, NULL); printf("\n"); darray_get_by_index(darray, 0, (void*)&data); data = !data; darray_foreach(darray, unique_print_int, &data); printf("\n"); darray_destroy(darray); return 0; }