LinkedList *tablist2linkedlist(char *strings) { LinkedList *list; list = LL_new(); /* Parse strings */ if (strings != NULL) { char *p = strings; char *tabptr, *new_s; while ((tabptr = strchr(p, '\t')) != NULL) { int len = (int)(tabptr - p); /* Alloc and copy substring */ new_s = malloc(len + 1); if (new_s != NULL) { strncpy(new_s, p, len); new_s[len] = 0; LL_Push(list, new_s); } /* Go to next string */ p = tabptr + 1; } /* Add last string */ new_s = strdup(p); if (new_s != NULL) LL_Push(list, new_s); } return list; }
LinkedList macros_get_names(pTHX_ CParseInfo *pCPI, size_t *count) { struct get_names_cb_arg a; #ifdef PERL_IMPLICIT_CONTEXT a.interp = aTHX; #endif if (count) { a.ll = NULL; a.count = 0; } else { a.ll = LL_new(); } macro_iterate_defs(pCPI, get_names_callback, &a, 0); if (count) { *count = a.count; } return a.ll; }
void LL_add_head(struct ll_node **headp, void *val) { struct ll_node *n = LL_new(val); if (n == NULL) return; n->next = *headp; *headp = n; return; }
char *test_linked_list_new() { head = LL_new(val1); test_assert(head, "Could not create new linked list"); test_assert_streq(head->val, val1, "linked list head has wrong val"); return NULL; }
/** Create a screen. * \param id Screen id; it's name. * \param client Client, the screen belongs to. * \return Pointer to freshly created screen. */ Screen * screen_create(char *id, Client *client) { Screen *s; debug(RPT_DEBUG, "%s(id=\"%.40s\", client=[%d])", __FUNCTION__, id, (client?client->sock:-1)); if (!id) { report(RPT_ERR, "%s: Need id string", __FUNCTION__); return NULL; } /* Client can be NULL for serverscreens and other client-less screens */ s = malloc(sizeof(Screen)); if (s == NULL) { report(RPT_ERR, "%s: Error allocating", __FUNCTION__); return NULL; } s->id = strdup(id); if (s->id == NULL) { report(RPT_ERR, "%s: Error allocating", __FUNCTION__); free(s); return NULL; } s->name = NULL; s->priority = PRI_INFO; s->duration = default_duration; s->heartbeat = HEARTBEAT_OPEN; s->width = display_props->width; s->height = display_props->height; s->keys = NULL; s->client = client; s->widgetlist = NULL; s->timeout = default_timeout; /*ignored unless greater than 0.*/ s->backlight = BACKLIGHT_OPEN; /*Lets the screen do it's own*/ /*or do what the client says.*/ s->cursor = CURSOR_OFF; s->cursor_x = 1; s->cursor_y = 1; s->widgetlist = LL_new(); if (s->widgetlist == NULL) { report(RPT_ERR, "%s: Error allocating", __FUNCTION__); free(s->id); free(s); return NULL; } menuscreen_add_screen(s); return s; }
int screenlist_init(void) { report(RPT_DEBUG, "%s()", __FUNCTION__); screenlist = LL_new(); if (!screenlist) { report(RPT_ERR, "%s: Error allocating", __FUNCTION__); return -1; } return 0; }
struct ll_node *LL_add_tail(struct ll_node *head, void *val) { struct ll_node *last = LL_last(head); struct ll_node *n = LL_new(val); check(n, "Could not allocate new node"); last->next = n; return n; error: return NULL; }
LinkedList macros_get_definitions(pTHX_ CParseInfo *pCPI) { struct get_defs_cb_arg a; #ifdef PERL_IMPLICIT_CONTEXT a.interp = aTHX; #endif a.ll = LL_new(); macro_iterate_defs(pCPI, get_defs_callback, &a, CMIF_WITH_DEFINITION); return a.ll; }
/** * Initialize the driver. * \param drvthis Pointer to driver structure. * \retval 0 Success. * \retval <0 Error. */ MODULE_EXPORT int linuxInput_init (Driver *drvthis) { PrivateData *p; const char *s; struct keycode *key; int i; /* Allocate and store private data */ p = (PrivateData *) calloc(1, sizeof(PrivateData)); if (p == NULL) return -1; if (drvthis->store_private_ptr(drvthis, p)) return -1; /* initialize private data */ p->fd = -1; if ((p->buttonmap = LL_new()) == NULL) { report(RPT_ERR, "%s: cannot allocate memory for buttons", drvthis->name); return -1; } /* Read config file */ /* What device should be used */ s = drvthis->config_get_string(drvthis->name, "Device", 0, LINUXINPUT_DEFAULT_DEVICE); report(RPT_INFO, "%s: using Device %s", drvthis->name, s); if ((p->fd = open(s, O_RDONLY | O_NONBLOCK)) < 0) { report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, s, strerror(errno)); return -1; } for (i = 0; (s = drvthis->config_get_string(drvthis->name, "key", i, NULL)) != NULL; i++) { if ((key = keycode_create(s)) == NULL) { report(RPT_ERR, "%s: parsing configvalue '%s' failed", drvthis->name, s); continue; } LL_AddNode(p->buttonmap, key); } report(RPT_DEBUG, "%s: init() done", drvthis->name); return 0; }
int input_init(void) { debug(RPT_DEBUG, "%s()", __FUNCTION__); keylist = LL_new(); /* Get rotate/scroll keys from config file */ toggle_rotate_key = strdup(config_get_string("server", "ToggleRotateKey", 0, "Enter")); prev_screen_key = strdup(config_get_string("server", "PrevScreenKey", 0, "Left")); next_screen_key = strdup(config_get_string("server", "NextScreenKey", 0, "Right")); scroll_up_key = strdup(config_get_string("server", "ScrollUpKey", 0, "Up")); scroll_down_key = strdup(config_get_string("server", "ScrollDownKey", 0, "Down")); return 0; }
MyObject *pObj; // pointer to an object LinkedList list; // linked list handle list = LL_new(); // create new linked list LL_push(list, NewObject("Foo", 3)); // push a new object onto the list LL_push(list, NewObject("Bar", 2)); // push a new object onto the list LL_push(list, NewObject("Cat", 7)); // push a new object onto the list LL_sort(list, CompareObjects); // sort the list printf("The list has %d elements\n", // print the list's size LL_size(list)); LL_foreach(pObj, list) // loop over all elements PrintObject(pObj); pObj = LL_shift(list); // shift off the first element DeleteObject(pObj); // ...and delete it LL_destroy(list, DeleteObject); // destroy the whole list
static void disabled_keywords(pTHX_ LinkedList *current, SV *sv, SV **rval, u_32 *pKeywordMask) { const char *str; LinkedList keyword_list = NULL; if (sv) { if (SvROK(sv)) { sv = SvRV(sv); if (SvTYPE(sv) == SVt_PVAV) { AV *av = (AV *) sv; SV **pSV; int i, max = av_len(av); u_32 keywords = HAS_ALL_KEYWORDS; keyword_list = LL_new(); for (i = 0; i <= max; i++) { if ((pSV = av_fetch(av, i, 0)) != NULL) { SvGETMAGIC(*pSV); str = SvPV_nolen(*pSV); #include "token/t_keywords.c" success: LL_push(keyword_list, string_new(str)); } else fatal("NULL returned by av_fetch() in disabled_keywords()"); } if (pKeywordMask != NULL) *pKeywordMask = keywords; if (current != NULL) { LL_destroy(*current, (LLDestroyFunc) string_delete); *current = keyword_list; } } else Perl_croak(aTHX_ "DisabledKeywords wants an array reference"); } else Perl_croak(aTHX_ "DisabledKeywords wants a reference to " "an array of strings"); } if (rval) { ListIterator li; AV *av = newAV(); LL_foreach (str, li, *current) av_push(av, newSVpv(CONST_CHAR(str), 0)); *rval = newRV_noinc((SV *) av); } return; unknown: LL_destroy(keyword_list, (LLDestroyFunc) string_delete); Perl_croak(aTHX_ "Cannot disable unknown keyword '%s'", str); }