Changeset 14028 for trunk/ippTools/src/pxdata.c.template
- Timestamp:
- Jul 5, 2007, 3:53:56 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pxdata.c.template (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxdata.c.template
r12095 r14028 32 32 #include "pxdata.h" 33 33 34 int test_f(const char *path); 34 static psHash *cachedData = NULL; 35 36 static int test_f(const char *path); 35 37 36 38 psString pxDataGet(const char *filename) … … 50 52 if (test_f(filepath)) { 51 53 // if we do, slurp the file 52 psString text= psSlurpFilename(filepath);53 if (! text) {54 psString data = psSlurpFilename(filepath); 55 if (!data) { 54 56 psError(PS_ERR_IO, false, "failed to slurp %s", filepath); 55 57 psFree(filepath); 56 58 return NULL; 57 59 } 60 psTrace("pxdata", PS_LOG_INFO, "slupred %s", filepath); 58 61 psFree(filepath); 59 62 60 return text;63 return data; 61 64 } 62 65 psFree(filepath); 63 66 64 67 // look under our share path 65 psStringAppend(&filepath, "%s/%s", " PKGDATADIR", filename);68 psStringAppend(&filepath, "%s/%s", "/home/moanui/jhoblitt/jhroot/i686-pc-linux-gnu//share/ipptools", filename); 66 69 67 70 // see if we have a valid filename 68 71 if (test_f(filepath)) { 69 72 // if we do, slurp the file 70 psString text= psSlurpFilename(filepath);71 if (! text) {73 psString data = psSlurpFilename(filepath); 74 if (!data) { 72 75 psError(PS_ERR_IO, false, "failed to slurp %s", filepath); 73 76 psFree(filepath); 74 77 return NULL; 75 78 } 79 psTrace("pxdata", PS_LOG_INFO, "slupred %s", filepath); 76 80 psFree(filepath); 77 81 78 return text;82 return data; 79 83 } 80 84 psFree(filepath); … … 86 90 } 87 91 88 int test_f(const char *path)92 static int test_f(const char *path) 89 93 { 90 94 // copied from coreutils 6.4 test.c licenced under GPL v2 … … 93 97 && S_ISREG (stat_buf.st_mode)); 94 98 } 99 100 psString pxDataGetCached(const char *filename) 101 { 102 bool persistence = p_psMemAllocatePersistent(true); 103 104 // make sure the cache is initalized 105 if (!cachedData) { 106 cachedData = psHashAlloc(10); 107 } 108 109 // look to see if we've cached this file 110 { 111 psString data = psHashLookup(cachedData, filename); 112 if (data) { 113 p_psMemAllocatePersistent(persistence); 114 return psStringCopy(data); 115 } 116 } 117 118 // we didn't have a cached copy so we need to try to read the file 119 psString data = pxDataGet(filename); 120 if (!data) { 121 p_psMemAllocatePersistent(persistence); 122 psError(PS_ERR_IO, false, "pxDataGet(%s) failed", filename); 123 return NULL; 124 } 125 126 // store a copy of the file 127 if (!psHashAdd(cachedData, filename, data)) { 128 psFree(data); 129 p_psMemAllocatePersistent(persistence); 130 psError(PS_ERR_UNKNOWN, false, "psHashAdd() failed"); 131 return NULL; 132 } 133 134 p_psMemAllocatePersistent(persistence); 135 136 return psStringCopy(data); 137 }
Note:
See TracChangeset
for help on using the changeset viewer.
