Changeset 787 for trunk/dll/walkem.c
- Timestamp:
- Aug 19, 2007, 11:02:37 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/walkem.c
r766 r787 18 18 22 Mar 07 GKY Use QWL_USER 19 19 20 Apr 07 SHL Avoid spurious add_udir error reports 20 16 Aug 07 SHL Update add_setups for ticket# 109 20 21 21 22 ***********************************************************************/ … … 24 25 #define INCL_DOS 25 26 #define INCL_DOSERRORS 27 #define INCL_SHLERRORS // PMERR_NOT_IN_IDX 26 28 #include <os2.h> 27 29 … … 62 64 static ULONG WalkFontSize = sizeof(WalkFont); 63 65 66 /** 67 * States names management 68 */ 69 70 static BOOL fSetupsLoaded; 71 static LINKDIRS *pFirstSetup; 72 static const PSZ pszLastSetups = "LastSetups"; 73 // // 18 Aug 07 SHL fixme to stop supporting old style 1 year from now? 74 static const ULONG ulOldSetupsBytes = 100 * 13; // Prior to 3.0.7 75 76 /** 77 * Fill States drop down list with known state names 78 */ 79 80 VOID fill_setups_list(VOID) 81 { 82 WinSendMsg(hwndStatelist, LM_DELETEALL, MPVOID, MPVOID); 83 if (fUserComboBox) { 84 LINKDIRS *pld; 85 load_setups(); 86 for (pld = pFirstSetup; pld; pld = pld->next) { 87 // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path); 88 WinSendMsg(hwndStatelist, 89 LM_INSERTITEM, 90 MPFROM2SHORT(LIT_SORTASCENDING, 0), 91 MPFROMP(pld->path)); 92 } 93 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT)); 94 } 95 } 96 97 /** 98 * Lookup setup and do requested action 99 * @param - action, Support old/new style storage method 100 * @return 1 if found and action OK, 0 if not found and action OK, -1 if error during action 101 */ 102 103 #define LS_FIND 0 104 #define LS_ADD 1 105 #define LS_DELETE 2 106 107 static INT lookup_setup(PSZ name, UINT action) 108 { 109 LINKDIRS *pld; 110 LINKDIRS *pldLast = NULL; 111 112 if (!name || !*name) { 113 Runtime_Error(pszSrcFile, __LINE__, "no data"); 114 return -1; 115 } 116 117 load_setups(); 118 119 for (pld = pFirstSetup; pld; pld = pld->next) { 120 if (!stricmp(pld->path, name)) { 121 if (action == LS_DELETE) { 122 if (pldLast) 123 pldLast->next = pld->next; 124 else 125 pFirstSetup = pld->next; 126 xfree(pld->path); 127 xfree(pld); 128 } 129 return 1; // Found or added 130 } 131 pldLast = pld; // In case deleting 132 } // for 133 134 // Not found 135 if (action == LS_ADD) { 136 pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__); 137 if (!pld) 138 return -1; 139 pld->path = xstrdup(name, pszSrcFile, __LINE__); 140 if (!pld->path) { 141 xfree(pld); 142 return -1; 143 } 144 // Insert at front of list - drop down will sort 145 pld->next = pFirstSetup; 146 pFirstSetup = pld; 147 return 0; 148 } 149 150 return FALSE; // Not found 151 } 152 153 /** 154 * Load state names from ini 155 * Support old/new style storage method 156 */ 157 64 158 VOID load_setups(VOID) 65 159 { 66 ULONG len = sizeof(lastsetups); 67 68 memset(lastsetups, 0, len); 69 PrfQueryProfileData(fmprof, FM3Str, "LastSetups", lastsetups, &len); 70 len = sizeof(INT); 71 lastsetup = 0; 72 PrfQueryProfileData(fmprof, FM3Str, "LastSetup", &lastsetup, &len); 73 loadedsetups = TRUE; 160 ULONG ulDataBytes; 161 ULONG l; 162 PSZ pszBuf; 163 PSZ psz; 164 LINKDIRS *pld; 165 166 if (fSetupsLoaded) 167 return; 168 169 if (!PrfQueryProfileSize(fmprof, FM3Str, pszLastSetups, &ulDataBytes)) { 170 // fixme to use generic hab 171 ERRORID eid = WinGetLastError((HAB)0); 172 if ((eid & 0xffff) != PMERR_NOT_IN_IDX) { 173 Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileSize returned %u", eid); 174 return; 175 } 176 } 177 178 if (ulDataBytes == 0) { 179 Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileSize reported 0 bytes"); 180 return; 181 } 182 183 pszBuf = xmalloc(ulDataBytes + 1, pszSrcFile, __LINE__); // One extra for end marker 184 if (!pszBuf) 185 return; 186 l = ulDataBytes; 187 if (!PrfQueryProfileData(fmprof, FM3Str, pszLastSetups, pszBuf, &l)) { 188 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "PrfQueryProfileData"); 189 xfree(pszBuf); 190 return; 191 } 192 193 if (ulDataBytes != l) { 194 Runtime_Error(pszSrcFile, __LINE__, "PrfQueryProfileData reported %u expected %u", l, ulDataBytes); 195 xfree(pszBuf); 196 return; 197 } 198 199 *(pszBuf + ulDataBytes) = 0; // Insert end marker 200 201 psz = pszBuf; 202 if (!*psz && ulDataBytes == ulOldSetupsBytes) 203 psz += 13; // Rarely used 1st fixed width entry prior to 3.0.7 204 205 while (*psz) { 206 pld = xmalloc(sizeof(LINKDIRS), pszSrcFile, __LINE__); 207 if (!pld) { 208 xfree(pszBuf); 209 return; 210 } 211 pld->path = xstrdup(psz, pszSrcFile, __LINE__); 212 if (!pld->path) { 213 xfree(pszBuf); 214 xfree(pld); 215 return; 216 } 217 218 // Insert at front of list - drop down will sort 219 pld->next = pFirstSetup; 220 pFirstSetup = pld; 221 // DbgMsg(pszSrcFile, __LINE__, "Inserted %s", pld->path); 222 223 if (ulDataBytes == ulOldSetupsBytes) 224 psz += 13; // Buffers fixed width prior to 3.0.7 225 else 226 psz += strlen(psz) + 1; 227 } // while 228 229 xfree(pszBuf); 230 231 fSetupsLoaded = TRUE; 74 232 } 75 233 76 234 VOID save_setups(VOID) 77 235 { 78 if (!loadedsetups) 236 ULONG ulBufBytes; 237 ULONG ulFillBytes; 238 ULONG l; 239 PSZ pszBuf; 240 PSZ psz; 241 LINKDIRS *pld; 242 243 if (!fSetupsLoaded) 79 244 return; 80 PrfWriteProfileData(fmprof, 81 FM3Str, 82 "LastSetups", lastsetups, (ULONG) sizeof(lastsetups)); 83 PrfWriteProfileData(fmprof, 84 FM3Str, "LastSetup", &lastsetup, (ULONG) sizeof(INT)); 85 } 86 87 BOOL add_setup(CHAR * name) 88 { 89 INT x; 90 91 if (!name || !*name) 92 return FALSE; 93 if (!loadedsetups) 94 load_setups(); 95 for (x = 0; x < MAXNUMSETUPS; x++) { 96 if (!stricmp(lastsetups[x], name)) 97 return FALSE; 98 } 99 lastsetup++; 100 if (lastsetup >= MAXNUMSETUPS) 101 lastsetup = 0; 102 strcpy(lastsetups[lastsetup], name); 103 return TRUE; 104 } 105 106 BOOL remove_setup(CHAR * name) 107 { 108 INT x, y; 109 110 if (!name || !*name) 111 return FALSE; 112 if (!loadedsetups) 113 load_setups(); 114 for (x = 0; x < MAXNUMSETUPS; x++) { 115 if (!stricmp(lastsetups[x], name)) { 116 *lastsetups[x] = 0; 117 for (y = x + 1; y < MAXNUMSETUPS; y++) 118 strcpy(lastsetups[y - 1], lastsetups[y]); 119 *lastsetups[MAXNUMSETUPS - 1] = 0; 120 if (lastsetup >= x) 121 lastsetup--; 122 return TRUE; 123 } 124 } 125 return FALSE; 245 246 ulBufBytes = 0; 247 for (pld = pFirstSetup; pld; pld = pld->next) { 248 ulBufBytes += strlen(pld->path) + 1; 249 } // for 250 251 if (!ulBufBytes) 252 pszBuf = NULL; 253 else { 254 // Ensure different than size prior to 3.0.7 255 ulFillBytes = ulBufBytes == ulOldSetupsBytes ? 1 : 0; 256 pszBuf = xmalloc(ulBufBytes + ulFillBytes, pszSrcFile, __LINE__); 257 if (!pszBuf) 258 return; 259 260 psz = pszBuf; 261 for (pld = pFirstSetup; pld; pld = pld->next) { 262 l = strlen(pld->path) + 1; 263 memcpy(psz, pld->path, l); 264 psz += l; 265 } // for 266 if (ulFillBytes) 267 *psz = 0; 268 } 269 270 if (!PrfWriteProfileData(fmprof, 271 FM3Str, 272 pszLastSetups, pszBuf, ulBufBytes)) { 273 // Win_Error(pszSrcFile, __LINE__, HWND_DESKTOP, HWND_DESKTOP, "PrfWriteProfileData"); 274 ERRORID eid = WinGetLastError((HAB)0); 275 if ((eid & 0xffff) != PMERR_NOT_IN_IDX) 276 Runtime_Error(pszSrcFile, __LINE__, "PrfWriteProfileData returned %u", eid); 277 } 278 279 // Delete obsolete INI entry 280 PrfWriteProfileData(fmprof, FM3Str, "LastSetup", NULL, 0); 281 } 282 283 /** 284 * Add named state to setups list 285 * @return same as lookup_setup 286 */ 287 288 INT add_setup(PSZ name) 289 { 290 return lookup_setup(name, LS_ADD); 291 } 292 293 /** 294 * Delete named state from setups list 295 * @return same as lookup_setup 296 */ 297 298 INT remove_setup(PSZ name) 299 { 300 return lookup_setup(name, LS_DELETE); 126 301 } 127 302
Note:
See TracChangeset
for help on using the changeset viewer.