Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220/* * ReactOS log2lines * Written by Jan Roeloffzen * * - List handling */
#include <stdio.h>#include <string.h>#include <stdlib.h>
#include "config.h"#include "compat.h"#include "list.h"#include "util.h"#include "options.h"
PLIST_MEMBERentry_lookup(PLIST list, char *name){ PLIST_MEMBER pprev = NULL; PLIST_MEMBER pnext;
if (!name || !name[0]) return NULL;
pnext = list->phead; while (pnext != NULL) { if (PATHCMP(name, pnext->name) == 0) { if (pprev) { // move to head for faster lookup next time pprev->pnext = pnext->pnext; pnext->pnext = list->phead; list->phead = pnext; } return pnext; } pprev = pnext; pnext = pnext->pnext; } return NULL;}
PLIST_MEMBERentry_delete(PLIST_MEMBER pentry){ if (!pentry) return NULL; if (pentry->buf) free(pentry->buf); free(pentry); return NULL;}
PLIST_MEMBERentry_insert(PLIST list, PLIST_MEMBER pentry){ if (!pentry) return NULL;
pentry->pnext = list->phead; list->phead = pentry; if (!list->ptail) list->ptail = pentry; return pentry;}
void list_clear(PLIST list){ PLIST_MEMBER pentry = list->phead; PLIST_MEMBER pnext; while (pentry) { pnext = pentry->pnext; entry_delete(pentry); pentry = pnext; } list->phead = list->ptail = NULL;}
#if 0LIST_MEMBER *entry_remove(LIST *list, LIST_MEMBER *pentry){ LIST_MEMBER *pprev = NULL, *p = NULL;
if (!pentry) return NULL;
if (pentry == list->phead) { list->phead = pentry->pnext; p = pentry; } else { pprev = list->phead; while (pprev->pnext) { if (pprev->pnext == pentry) { pprev->pnext = pentry->pnext; p = pentry; break; } pprev = pprev->pnext; } } if (pentry == list->ptail) list->ptail = pprev;
return p;}#endif
PLIST_MEMBERcache_entry_create(char *Line){ PLIST_MEMBER pentry; char *s = NULL; int l;
if (!Line) return NULL;
pentry = malloc(sizeof(LIST_MEMBER)); if (!pentry) return NULL;
l = strlen(Line); pentry->buf = s = malloc(l + 1); if (!s) { l2l_dbg(1, "Alloc entry failed\n"); return entry_delete(pentry); }
strcpy(s, Line); if (s[l] == '\n') s[l] = '\0';
pentry->name = s; s = strchr(s, '|'); if (!s) { l2l_dbg(1, "Name field missing\n"); return entry_delete(pentry); } *s++ = '\0';
pentry->path = s; s = strchr(s, '|'); if (!s) { l2l_dbg(1, "Path field missing\n"); return entry_delete(pentry); } *s++ = '\0'; if (1 != sscanf(s, "%x", (unsigned int *)(&pentry->ImageBase))) { l2l_dbg(1, "ImageBase field missing\n"); return entry_delete(pentry); } pentry->RelBase = INVALID_BASE; pentry->Size = 0; return pentry;}
PLIST_MEMBERsources_entry_create(PLIST list, char *path, char *prefix){ PLIST_MEMBER pentry; char *s = NULL; int l;
if (!path) return NULL; if (!prefix) prefix = "";
pentry = malloc(sizeof(LIST_MEMBER)); if (!pentry) return NULL;
l = strlen(path) + strlen(prefix); pentry->buf = s = malloc(l + 1); if (!s) { l2l_dbg(1, "Alloc entry failed\n"); return entry_delete(pentry); }
strcpy(s, prefix); strcat(s, path); if (s[l] == '\n') s[l] = '\0';
pentry->name = s; if (list) { if (entry_lookup(list, pentry->name)) { l2l_dbg(1, "Entry %s exists\n", pentry->name); pentry = entry_delete(pentry); } else { l2l_dbg(1, "Inserting entry %s\n", pentry->name); entry_insert(list, pentry); } }
return pentry;}
/* EOF */