ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

list.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS log2lines
00003  * Written by Jan Roeloffzen
00004  *
00005  * - List handling
00006  */
00007 
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include <stdlib.h>
00011 
00012 #include "config.h"
00013 #include "compat.h"
00014 #include "list.h"
00015 #include "util.h"
00016 #include "options.h"
00017 
00018 PLIST_MEMBER
00019 entry_lookup(PLIST list, char *name)
00020 {
00021     PLIST_MEMBER pprev = NULL;
00022     PLIST_MEMBER pnext;
00023 
00024     if (!name || !name[0])
00025         return NULL;
00026 
00027     pnext = list->phead;
00028     while (pnext != NULL)
00029     {
00030         if (PATHCMP(name, pnext->name) == 0)
00031         {
00032             if (pprev)
00033             {   // move to head for faster lookup next time
00034                 pprev->pnext = pnext->pnext;
00035                 pnext->pnext = list->phead;
00036                 list->phead = pnext;
00037             }
00038             return pnext;
00039         }
00040         pprev = pnext;
00041         pnext = pnext->pnext;
00042     }
00043     return NULL;
00044 }
00045 
00046 PLIST_MEMBER 
00047 entry_delete(PLIST_MEMBER pentry)
00048 {
00049     if (!pentry)
00050         return NULL;
00051     if (pentry->buf)
00052         free(pentry->buf);
00053     free(pentry);
00054     return NULL;
00055 }
00056 
00057 PLIST_MEMBER 
00058 entry_insert(PLIST list, PLIST_MEMBER pentry)
00059 {
00060     if (!pentry)
00061         return NULL;
00062 
00063     pentry->pnext = list->phead;
00064     list->phead = pentry;
00065     if (!list->ptail)
00066         list->ptail = pentry;
00067     return pentry;
00068 }
00069 
00070 void list_clear(PLIST list)
00071 {
00072     PLIST_MEMBER pentry = list->phead;
00073     PLIST_MEMBER pnext;
00074     while (pentry)
00075     {
00076         pnext = pentry->pnext;
00077         entry_delete(pentry);
00078         pentry = pnext;
00079     }
00080     list->phead = list->ptail = NULL;
00081 }
00082 
00083 #if 0
00084 LIST_MEMBER *
00085 entry_remove(LIST *list, LIST_MEMBER *pentry)
00086 {
00087     LIST_MEMBER *pprev = NULL, *p = NULL;
00088 
00089     if (!pentry)
00090         return NULL;
00091 
00092     if (pentry == list->phead)
00093     {
00094         list->phead = pentry->pnext;
00095         p = pentry;
00096     }
00097     else
00098     {
00099         pprev = list->phead;
00100         while (pprev->pnext)
00101         {
00102             if (pprev->pnext == pentry)
00103             {
00104                 pprev->pnext = pentry->pnext;
00105                 p = pentry;
00106                 break;
00107             }
00108             pprev = pprev->pnext;
00109         }
00110     }
00111     if (pentry == list->ptail)
00112         list->ptail = pprev;
00113 
00114     return p;
00115 }
00116 #endif
00117 
00118 PLIST_MEMBER 
00119 cache_entry_create(char *Line)
00120 {
00121     PLIST_MEMBER pentry;
00122     char *s = NULL;
00123     int l;
00124 
00125     if (!Line)
00126         return NULL;
00127 
00128     pentry = malloc(sizeof(LIST_MEMBER));
00129     if (!pentry)
00130         return NULL;
00131 
00132     l = strlen(Line);
00133     pentry->buf = s = malloc(l + 1);
00134     if (!s)
00135     {
00136         l2l_dbg(1, "Alloc entry failed\n");
00137         return entry_delete(pentry);
00138     }
00139 
00140     strcpy(s, Line);
00141     if (s[l] == '\n')
00142         s[l] = '\0';
00143 
00144     pentry->name = s;
00145     s = strchr(s, '|');
00146     if (!s)
00147     {
00148         l2l_dbg(1, "Name field missing\n");
00149         return entry_delete(pentry);
00150     }
00151     *s++ = '\0';
00152 
00153     pentry->path = s;
00154     s = strchr(s, '|');
00155     if (!s)
00156     {
00157         l2l_dbg(1, "Path field missing\n");
00158         return entry_delete(pentry);
00159     }
00160     *s++ = '\0';
00161     if (1 != sscanf(s, "%x", (unsigned int *)(&pentry->ImageBase)))
00162     {
00163         l2l_dbg(1, "ImageBase field missing\n");
00164         return entry_delete(pentry);
00165     }
00166     pentry->RelBase = INVALID_BASE;
00167     pentry->Size = 0;
00168     return pentry;
00169 }
00170 
00171 
00172 PLIST_MEMBER 
00173 sources_entry_create(PLIST list, char *path, char *prefix)
00174 {
00175     PLIST_MEMBER pentry;
00176     char *s = NULL;
00177     int l;
00178 
00179     if (!path)
00180         return NULL;
00181     if (!prefix)
00182         prefix = "";
00183 
00184     pentry = malloc(sizeof(LIST_MEMBER));
00185     if (!pentry)
00186         return NULL;
00187 
00188     l = strlen(path) + strlen(prefix);
00189     pentry->buf = s = malloc(l + 1);
00190     if (!s)
00191     {
00192         l2l_dbg(1, "Alloc entry failed\n");
00193         return entry_delete(pentry);
00194     }
00195 
00196     strcpy(s, prefix);
00197     strcat(s, path);
00198     if (s[l] == '\n')
00199         s[l] = '\0';
00200 
00201     pentry->name = s;
00202     if (list)
00203     {
00204         if (entry_lookup(list, pentry->name))
00205         {
00206             l2l_dbg(1, "Entry %s exists\n", pentry->name);
00207             pentry = entry_delete(pentry);
00208         }
00209         else
00210         {
00211             l2l_dbg(1, "Inserting entry %s\n", pentry->name);
00212             entry_insert(list, pentry);
00213         }
00214     }
00215 
00216     return pentry;
00217 }
00218 
00219 /* EOF */

Generated on Fri May 25 2012 04:16:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.