Changeset 8003 for trunk/tools/common/kFileDef.cpp
- Timestamp:
- Feb 24, 2002, 3:47:28 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFileDef.cpp
r5531 r8003 1 /* 1 /* $Id: kFileDef.cpp,v 1.8 2002-02-24 02:47:25 bird Exp $ 2 * 2 3 * kFileDef - Definition files. 3 4 * 4 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2001 knut st. osmundsen 5 6 * 6 7 */ … … 21 22 * Header Files * 22 23 *******************************************************************************/ 23 #include <os2.h>24 24 #include <stdio.h> 25 25 #include <string.h> 26 26 #include <stdlib.h> 27 #include <assert.h> 28 27 28 #include "kTypes.h" 29 #include "kError.h" 29 30 #include "kFile.h" 30 31 #include "kFileFormatBase.h" 31 #include "k Interfaces.h"32 #include "kFileInterfaces.h" 32 33 #include "kFileDef.h" 34 33 35 34 36 /******************************************************************************* … … 43 45 * Internal Functions * 44 46 *******************************************************************************/ 45 static char *dupeString(const char *psz, BOOL fSkipFirstWord = FALSE);47 static char *dupeString(const char *psz, KBOOL fSkipFirstWord = FALSE); 46 48 static char *trim(char *psz); 47 49 static char *ltrim(const char *psz); … … 57 59 * @param fSkipFirstWord Skips the first word before duplicating the string. 58 60 */ 59 static char *dupeString(const char *psz, BOOL fSkipFirstWord/* = FALSE*/)61 static char *dupeString(const char *psz, KBOOL fSkipFirstWord/* = FALSE*/) 60 62 { 61 63 char *pszDupe; … … 117 119 118 120 119 kFileDef::kFileDef(kFile *pFile) throw(int) 120 :pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL), 121 kFileDef::kFileDef(kFile *pFile) : 122 kFileFormatBase(pFile), 123 pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL), 121 124 pszExeType(NULL), pszHeapSize(NULL), pszOld(NULL), pszProtmode(NULL), pszStackSize(NULL), 122 125 pszStub(NULL), pSegments(NULL), pImports(NULL), pExports(NULL), … … 125 128 chAppType(kFileDef::unknown) 126 129 { 127 /* determin file size */ 128 129 if (pFile->start()) 130 { 131 try 132 { 133 this->read(pFile); 134 } 135 catch (int err) 136 { 137 throw (err); 138 } 139 } 140 else 141 throw (0x001); 142 } 130 pFile->setThrowOnErrors(); 131 pFile->start(); 132 read(pFile); 133 } 143 134 144 135 … … 191 182 * @remark throws errorcode on error (TODO: errorhandling) 192 183 */ 193 void kFileDef::read(kFile *pFile) throw (int)184 void kFileDef::read(kFile *pFile) 194 185 { 195 186 char *pszTmp; … … 201 192 while (psz != NULL) 202 193 { 203 BOOLfNext = TRUE;194 KBOOL fNext = TRUE; 204 195 205 196 /* if-switch */ 206 197 if (StringCase(psz, "LIBRARY")) 207 198 { 208 if (pszType != NULL) throw ( 0x101);199 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 209 200 pszType = dupeString(psz); 210 201 fLibrary = TRUE; 211 202 if (!setModuleName()) 212 throw ( 0x107);203 throw (kError(kError::DEF_BAD_LIBRARY_STATEMENT)); 213 204 fInitInstance = stristr(pszType, "INITINSTANCE") != NULL; 214 205 fInitGlobal = stristr(pszType, "INITGLOBAL") != NULL || !fInitInstance; … … 218 209 else if (StringCase(psz, "NAME")) 219 210 { 220 if (pszType != NULL) throw ( 0x101);211 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 221 212 pszType = dupeString(psz); 222 213 fProgram = TRUE; … … 233 224 else if (StringCase(psz, "PHYSICAL DEVICE")) //gap is fixed to one space, this may be fixed in readln. 234 225 { 235 if (pszType != NULL) throw ( 0x101);226 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 236 227 pszType = dupeString(psz); 237 228 fPhysicalDevice = TRUE; … … 240 231 else if (StringCase(psz, "VIRTUAL DEVICE")) //gap is fixed to one space, this may be fixed in readln. 241 232 { 242 if (pszType != NULL) throw ( 0x101);233 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 243 234 pszType = dupeString(psz); 244 235 fVirtualDevice = TRUE; … … 301 292 { 302 293 (**ppi).ulOrdinal = strtol(psz, &pszTmp, 0); 303 if (psz ==pszTmp) throw (0x102);294 if (psz ==pszTmp) throw (kError(kError::DEF_BAD_IMPORT)); 304 295 } 305 296 else … … 355 346 psz = pszTmp + 1; 356 347 (**ppe).ulOrdinal = strtol(psz, &pszTmp, 0); 357 if (pszTmp == psz) throw ( 0x103);348 if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT)); 358 349 psz = trim(pszTmp); 359 350 … … 380 371 { /* 2 */ 381 372 (**ppe).cParam = strtol(psz, &pszTmp, 0); 382 if (pszTmp == psz) throw ( 0x104);373 if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT)); 383 374 } 384 375 } … … 391 382 } 392 383 else 393 throw (0x105);384 throw (kError(kError::DEF_UNKOWN_VERB)); 394 385 395 386 /* next ? */ … … 400 391 /* sanity check */ 401 392 if (pszType == NULL) 402 throw ( (int)0x106);393 throw (kError(kError::DEF_NO_MODULE_STATEMENT)); 403 394 } 404 395 … … 412 403 * @remark tabs are expanded. string is trimmed. comments removed. 413 404 */ 414 char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (int)405 char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) 415 406 { 416 407 int i; … … 420 411 { 421 412 /* read line */ 422 if ( !pFile->readln(pszBuffer, cbBuffer))413 if (pFile->readln(pszBuffer, cbBuffer)) 423 414 { 424 415 if (!pFile->isEOF()) 425 throw ( 0x201);426 return FALSE;416 throw (kError(pFile->getLastError())); 417 return NULL; 427 418 } 428 419 … … 472 463 * @remark TODO - we are going to check WORDS. 473 464 */ 474 BOOL kFileDef::isKeyword(const char *psz)465 KBOOL kFileDef::isKeyword(const char *psz) 475 466 { 476 467 return psz != NULL … … 503 494 * @remark Assumes that pszBuffer is large enough. 504 495 */ 505 BOOL kFileDef::setModuleName(void)496 KBOOL kFileDef::setModuleName(void) 506 497 { 507 498 char *pszEnd; 508 499 char *pszStart; 509 500 510 assert(pszType);501 kASSERT(pszType); 511 502 512 503 /* skip the first word */ … … 534 525 * @param cchBuffer Size of the buffer (defaults to 260 chars). 535 526 */ 536 BOOL kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)527 KBOOL kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/) 537 528 { 538 529 int cch; … … 554 545 * @param pExport Pointer to export structure. 555 546 */ 556 BOOLkFileDef::exportFindFirst(kExportEntry *pExport)547 KBOOL kFileDef::exportFindFirst(kExportEntry *pExport) 557 548 { 558 549 if (pExports != NULL && pExport != NULL) … … 581 572 * @param pExport Pointer to export structure. 582 573 */ 583 BOOLkFileDef::exportFindNext(kExportEntry *pExport)574 KBOOL kFileDef::exportFindNext(kExportEntry *pExport) 584 575 { 585 576 if (pExport != NULL && pExport->pv != NULL) … … 624 615 * @remark stub 625 616 */ 626 BOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)627 { 628 assert(!"not implemented.");617 KBOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) 618 { 619 kASSERT(!"not implemented."); 629 620 ulOrdinal = ulOrdinal; 630 621 pExport = pExport; … … 639 630 * @remark stub 640 631 */ 641 BOOL kFileDef::exportLookup(const char * pszName, kExportEntry *pExport)642 { 643 assert(!"not implemented.");632 KBOOL kFileDef::exportLookup(const char * pszName, kExportEntry *pExport) 633 { 634 kASSERT(!"not implemented."); 644 635 pszName = pszName; 645 636 pExport = pExport; … … 658 649 * @remark 659 650 */ 660 BOOL kFileDef::makeWatcomLinkFileAddtion(kFile *pFile) throw(int)651 KBOOL kFileDef::makeWatcomLinkFileAddtion(kFile *pOut) 661 652 { 662 653 PDEFSEGMENT pSeg; 663 654 PDEFIMPORT pImp; 664 655 PDEFEXPORT pExp; 665 p File->setThrowOnErrors();656 pOut->setThrowOnErrors(); 666 657 667 658 /* 668 659 * Write a little remark first to tell that converted stuff starts here. 669 660 */ 670 p File->printf("#\n# Directives generated from .DEF-file.\n#\n");661 pOut->printf("#\n# Directives generated from .DEF-file.\n#\n"); 671 662 672 663 /* Format - Module type */ 673 p File->printf("FORMAT OS2 LX %s %s %s\n",664 pOut->printf("FORMAT OS2 LX %s %s %s\n", 674 665 fLibrary ? "DLL" : 675 666 (fProgram ? (chAppType == pm ? "PM" … … 684 675 /* Module name */ 685 676 if (pszModName) 686 p File->printf("OPTION MODNAME=%s\n", pszModName);677 pOut->printf("OPTION MODNAME=%s\n", pszModName); 687 678 688 679 /* Description */ 689 680 if (pszDescription) 690 p File->printf("OPTION DESCRIPTION '%s'\n", pszDescription);681 pOut->printf("OPTION DESCRIPTION '%s'\n", pszDescription); 691 682 692 683 /* Base */ 693 684 if (pszBase) 694 p File->printf("OPTION OFFSET=%s\n", pszBase);685 pOut->printf("OPTION OFFSET=%s\n", pszBase); 695 686 696 687 /* Stub */ 697 688 if (pszStub) 698 p File->printf("OPTION STUB='%s'\n", pszStub);689 pOut->printf("OPTION STUB='%s'\n", pszStub); 699 690 700 691 /* Old */ 701 692 if (pszOld) 702 p File->printf("OPTION OLDLIBRARY=%s\n", pszOld);693 pOut->printf("OPTION OLDLIBRARY=%s\n", pszOld); 703 694 704 695 /* Protected mode */ 705 696 if (pszProtmode) 706 p File->printf("OPTION PROTMODE\n", pszProtmode);697 pOut->printf("OPTION PROTMODE\n", pszProtmode); 707 698 708 699 /* Stacksize */ 709 700 if (pszStackSize) 710 p File->printf("OPTION STACK=%s\n", pszStackSize);701 pOut->printf("OPTION STACK=%s\n", pszStackSize); 711 702 712 703 /* HeapSize */ 713 704 if (pszHeapSize) 714 p File->printf("OPTION HEAPSIZE=%s\n", pszHeapSize);705 pOut->printf("OPTION HEAPSIZE=%s\n", pszHeapSize); 715 706 716 707 /* Code - not supported */ … … 724 715 while (pSeg != NULL) 725 716 { 726 p File->printf("SEGMENT %s\n", pSeg->psz);717 pOut->printf("SEGMENT %s\n", pSeg->psz); 727 718 pSeg = pSeg->pNext; 728 719 } … … 735 726 { 736 727 if (pImp->pszName == NULL) 737 p File->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal);728 pOut->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal); 738 729 else 739 p File->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName);730 pOut->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName); 740 731 pImp = pImp->pNext; 741 732 } … … 747 738 while (pExp != NULL) 748 739 { 749 p File->printf("EXPORT '%s'", pExp->pszName);740 pOut->printf("EXPORT '%s'", pExp->pszName); 750 741 if (pExp->ulOrdinal != ~0UL) 751 p File->printf(".%d", pExp->ulOrdinal);742 pOut->printf(".%d", pExp->ulOrdinal); 752 743 if (pExp->pszIntName) 753 p File->printf("='%s'", pExp->pszIntName);744 pOut->printf("='%s'", pExp->pszIntName); 754 745 if (pExp->fResident) 755 p File->printf(" RESIDENT");746 pOut->printf(" RESIDENT"); 756 747 if (pExp->cParam != ~0UL) 757 p File->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */758 p File->printf("\n");748 pOut->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */ 749 pOut->printf("\n"); 759 750 pExp = pExp->pNext; 760 751 }
Note:
See TracChangeset
for help on using the changeset viewer.