Changeset 350 for trunk/dll/mle.c
- Timestamp:
- Jul 26, 2006, 9:01:20 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/mle.c
r301 r350 7 7 8 8 Copyright (c) 1993-97 M. Kimes 9 Copyright (c) 2004 Steven H.Levine9 Copyright (c) 2004, 2006 Steven H.Levine 10 10 11 11 01 Aug 04 SHL Rework lstrip/rstrip usage 12 12 16 Apr 06 SHL MLEexportfile: rework to avoid wrap problems 13 14 Jul 06 SHL Use Runtime_Error 13 14 14 15 ***********************************************************************/ 15 16 /* MLE support functions */17 16 18 17 #define INCL_DOS 19 18 #define INCL_WIN 20 21 19 #include <os2.h> 20 22 21 #include <stdlib.h> 23 22 #include <stdio.h> … … 25 24 #include <ctype.h> 26 25 #include <share.h> 26 27 27 #include "fm3dll.h" 28 28 #include "fm3dlg.h" 29 29 #include "mle.h" 30 30 #include "fm3str.h" 31 32 static PSZ pszSrcFile = __FILE__; 31 33 32 34 #pragma alloc_text(FMMLE,MLEgetlinetext,MLEdeleteline,MLEdeletecurline,MLEdeletetoeol) … … 152 154 IPT ancpos,curpos,here; 153 155 LONG len,oldlen; 156 APIRET rc; 154 157 155 158 len = MLEsizeofsel(h); 156 159 len = min(2048,len); 157 160 oldlen = len; 158 if (len) {161 if (len) { 159 162 len++; 160 if(!DosAllocMem((PVOID)&temp,4096, 161 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE) && temp) { 163 rc = DosAllocMem((PVOID)&temp,4096, 164 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 165 if (rc || !temp) 166 Dos_Error(MB_CANCEL,rc,h,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 167 else { 162 168 ancpos = MLEancpos(h); 163 169 curpos = MLEcurpos(h); … … 165 171 WinSendMsg(h,MLM_SETIMPORTEXPORT,MPFROMP(temp),MPFROMLONG(len)); 166 172 len = (LONG)WinSendMsg(h,MLM_EXPORT,MPFROMP(&here),MPFROMP(&len)); 167 if(len > 1) { 173 if (len <= 1) 174 Runtime_Error(pszSrcFile, __LINE__, "len <= 1"); 175 else { 168 176 if(len > oldlen) 169 177 len--; … … 189 197 } 190 198 } 191 else192 DosBeep(50,100);193 199 DosFreeMem(temp); 194 200 } … … 205 211 IPT ancpos,curpos,here; 206 212 LONG sellen,oldlen; 213 APIRET rc; 207 214 208 215 oldlen = MLEsizeofsel(h); 209 216 if(!oldlen) 210 217 return TRUE; 211 sel = malloc((INT)(oldlen + 2)); 212 if(!sel) { 213 DosBeep(50,100); 218 sel = xmallocz((size_t)(oldlen + 2),pszSrcFile,__LINE__); 219 if (!sel) 214 220 return FALSE; 215 } 216 memset(sel,0,(INT)(oldlen + 2)); 217 if(DosAllocMem((PVOID)&temp,32768L, 218 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE) || 219 !temp) { 220 DosBeep(50,100); 221 rc = DosAllocMem((PVOID)&temp,32768L, 222 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 223 if (rc || !temp) { 224 Dos_Error(MB_CANCEL,rc,h,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 221 225 free(sel); 222 226 DosPostEventSem(CompactSem); … … 233 237 WinSendMsg(h,MLM_SETIMPORTEXPORT,MPFROMP(temp),MPFROMLONG(sellen)); 234 238 sellen = (LONG)WinSendMsg(h,MLM_EXPORT,MPFROMP(&here),MPFROMP(&sellen)); 235 if (sellen < 1) {236 DosBeep(50,100);239 if (sellen < 1) { 240 Runtime_Error(pszSrcFile, __LINE__, "len < 1"); 237 241 free(sel); 238 242 DosPostEventSem(CompactSem); … … 260 264 fp = fopen(filename,"a+"); 261 265 if(!fp) 262 fp = fopen(filename,"w");263 if (fp) {266 fp = xfopen(filename,"w",pszSrcFile,__LINE__); 267 if (fp) { 264 268 fseek(fp,0L,SEEK_END); 265 269 fwrite(sel,1,strlen(sel),fp); … … 267 271 } 268 272 #ifdef __DEBUG_ALLOC__ 269 _heap_check();273 _heap_check(); 270 274 #endif 271 275 DosFreeMem(temp); … … 365 369 MPFROMP(&here), 366 370 MPFROMLONG(sellen)); 367 if (!sellen) {368 DosBeep(50,100);371 if (!sellen) { 372 Runtime_Error(pszSrcFile, __LINE__, "sellen 0"); 369 373 break; 370 374 } … … 373 377 if(oldlen && *p == '\n' /* && *(p - 1) == '\r' */) 374 378 p--; 375 } 379 } // while 376 380 WinSendMsg(h,MLM_SETSEL,MPFROMLONG(ancpos),MPFROMLONG(curpos)); 377 381 MLEenable(h); … … 454 458 XMLEWNDPTR *vw; 455 459 HFILE handle; 460 APIRET rc; 456 461 457 462 *titletext = 0; … … 463 468 *titletext = 0; 464 469 WinQueryWindowText(grandpa,512,titletext); 465 if(!DosOpen(filename,&handle,&action,0L,0L, 466 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 467 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | 468 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE | 469 OPEN_ACCESS_READONLY,0L)) { 470 rc = DosOpen(filename,&handle,&action,0L,0L, 471 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 472 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | 473 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE | 474 OPEN_ACCESS_READONLY,0L); 475 if (rc) { 476 ret = FALSE; 477 } 478 else { 470 479 DosChgFilePtr(handle, 0L, FILE_END, &len); 471 480 DosChgFilePtr(handle, 0L, FILE_BEGIN, &action); 472 if(len) { 473 if(!DosAllocMem((PVOID)&hexbuff,50001L, 474 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE) && 475 hexbuff) { 476 buffer = malloc(10000); 477 if(buffer) { 481 if (len) { 482 rc = DosAllocMem((PVOID)&hexbuff,50001L, 483 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 484 if (rc || !hexbuff) { 485 Dos_Error(MB_CANCEL,rc,h,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 486 ret = FALSE; 487 } 488 else { 489 buffer = xmalloc(10000,pszSrcFile,__LINE__); 490 if (!buffer) 491 ret = FALSE; 492 else { 478 493 MLEclearall(h); 479 494 WinSendMsg(h,MLM_SETIMPORTEXPORT,MPFROMP(hexbuff), … … 540 555 } 541 556 sprintf(s, 542 GetPString(IDS_LOADING 2TEXT),557 GetPString(IDS_LOADINGMLETEXT), 543 558 len); 544 559 WinSetWindowText(grandpa,s); … … 550 565 free(buffer); 551 566 } 552 else {553 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,554 HWND_DESKTOP,555 GetPString(IDS_ARGHTEXT),556 GetPString(IDS_OUTOFMEMORY));557 ret = FALSE;558 }559 567 DosFreeMem(hexbuff); 560 }561 else {562 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,563 HWND_DESKTOP,564 GetPString(IDS_ARGHTEXT),565 GetPString(IDS_OUTOFMEMORY));566 ret = FALSE;567 568 } 568 569 } … … 571 572 DosClose(handle); 572 573 } 573 else574 ret = FALSE;575 574 if(!first) { 576 575 WinEnableWindowUpdate(h,TRUE); … … 582 581 583 582 583 //== MLEinsertfile() insert a file into the current position in the MLE == 584 584 585 BOOL MLEinsertfile (HWND h,CHAR *filename) 585 586 { 586 /* insert a file into the current position in the MLE */587 587 588 588 HAB hab; … … 609 609 titletext); 610 610 fp = _fsopen(filename,"r",SH_DENYNO); 611 if(fp) { 611 if (!fp) 612 ret = FALSE; 613 else { 612 614 setvbuf(fp,NULL,_IONBF,0); 613 615 fseek(fp,0L,SEEK_END); … … 615 617 fseek(fp,0L,SEEK_SET); 616 618 if(len && len != -1) { 617 if(!DosAllocMem((PVOID)&buffer,619 rc = DosAllocMem((PVOID)&buffer, 618 620 50000L, 619 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE) && 620 buffer) { 621 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 622 if (rc || !buffer) { 623 Dos_Error(MB_CANCEL,rc,h,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 624 ret = FALSE; 625 } 626 else { 621 627 WinSendMsg(h, 622 628 MLM_SETIMPORTEXPORT, … … 716 722 } 717 723 sprintf(s, 718 GetPString(IDS_LOADING 2TEXT),724 GetPString(IDS_LOADINGMLETEXT), 719 725 len); 720 726 WinSetWindowText(grandpa,s); … … 724 730 DosFreeMem(buffer); 725 731 } 726 else {727 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,728 HWND_DESKTOP,729 GetPString(IDS_ARGHTEXT),730 GetPString(IDS_OUTOFMEMORY));731 ret = FALSE;732 }733 732 } 734 733 if(WinIsWindow(hab,h)) … … 736 735 fclose(fp); 737 736 } 738 else739 ret = FALSE;740 737 if(!first) { 741 738 WinEnableWindowUpdate(h,TRUE); … … 798 795 799 796 INT MLEbackgroundload (HWND hwndReport,ULONG msg,HWND h,CHAR *filename, 800 INT hex) { 801 802 /* load a file into the MLE in the background (via a separate thread) */ 797 INT hex) 798 { 799 /* load a file into the MLE in the background (via a separate thread) 800 * return _beginthread status 801 */ 803 802 804 803 BKGLOAD *bkg; 805 806 bkg = malloc(sizeof(BKGLOAD)); 807 if(bkg) { 808 memset(bkg,0,sizeof(BKGLOAD)); 809 bkg->size = sizeof(BKGLOAD); 810 bkg->hex = (USHORT)hex; 811 bkg->hwndReport = hwndReport; 812 bkg->msg = msg; 813 bkg->h = h; 814 strcpy(bkg->filename,filename); 815 return _beginthread(LoadThread,NULL,65536,bkg); 816 } 817 return -1; 804 INT rc; 805 806 bkg = xmallocz(sizeof(BKGLOAD),pszSrcFile,__LINE__); 807 if (!bkg) 808 return -1; 809 bkg->size = sizeof(BKGLOAD); 810 bkg->hex = (USHORT)hex; 811 bkg->hwndReport = hwndReport; 812 bkg->msg = msg; 813 bkg->h = h; 814 strcpy(bkg->filename,filename); 815 rc = _beginthread(LoadThread,NULL,65536,bkg); 816 if (rc == -1) 817 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_COULDNTSTARTTHREADTEXT)); 818 return rc; 818 819 } 819 820 … … 854 855 INT blanklines = 0; 855 856 BOOL fWrap = MLEgetwrap(h); 857 APIRET rc; 856 858 857 859 // saymsg(MB_ENTER,h,DEBUG_STRING,"len = %ld",MLEgetlen(h)); … … 881 883 } 882 884 883 if(!DosAllocMem((PVOID)&buffer,4096L, 884 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE) && 885 buffer) { 885 rc = DosAllocMem((PVOID)&buffer,4096L, 886 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 887 if (rc || !buffer) { 888 Dos_Error(MB_CANCEL,rc,h,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 889 ok = FALSE; 890 } 891 else 892 { 886 893 fp = fopen(filename,"a+"); 887 if(!fp) 888 fp = fopen(filename,"w"); 889 if(fp) { 890 894 if (!fp) 895 fp = xfopen(filename,"w",pszSrcFile,__LINE__); 896 if (!fp) 897 ok = FALSE; 898 else { 891 899 LONG numlines,ret,len,wl,temp; 892 900 IPT s; … … 954 962 } // for lines 955 963 } 956 else 957 ok = FALSE; 958 } 959 else 960 ok = FALSE; 964 } 961 965 962 966 MLEsetwrap(h, fWrap); // Restore
Note:
See TracChangeset
for help on using the changeset viewer.