void SetActFrames( )
{
 STACK_PARMS  parms;
 UCHAR       *pActCSAtrs = NULL;
 UINT        *pActFrames = NULL;
 UINT        *pActFaddrs = NULL;
 ULONG        n;
 DEBFILE     *pdf;                                                      /*901*/

 parms.CS          = AppPTB.CS;
 parms.SS          = AppPTB.SS;
 parms.EBP         = AppPTB.EBP;
 parms.ESP         = AppPTB.ESP;
 parms.SSAtr       = AppPTB.SSAtr;
 parms.ShowAllFlag = ShowAllFlag;

 NActFrames = xGetCallStack( &parms,&pActCSAtrs,&pActFrames,&pActFaddrs );
 memcpy(ActCSAtrs,pActCSAtrs,NActFrames*sizeof(ActCSAtrs[0]));
 memcpy(ActFrames,pActFrames,NActFrames*sizeof(ActFrames[0]));
 memcpy(ActFaddrs,pActFaddrs,NActFrames*sizeof(ActFaddrs[0]));
 if(pActCSAtrs) Tfree(pActCSAtrs);
 if(pActFrames) Tfree(pActFrames);
 if(pActFaddrs) Tfree(pActFaddrs);

 for( n = 0; n < NActFrames; n++ )
 {
  ActScopes[n] = FindScope( ActFaddrs[n] , &ActFlines[n][0] );
 }
 pdf = FindExeOrDllWithAddr( GetExecAddr() );                            /*901*/
 ExecScope = LocateScope(GetExecAddr(),GetExecMid(),pdf);                /*901*/
}
void CMemTest::Zerofilling()
{
    TestStruct* TSMas;
    size_t CountElement;
    CountErrors=0;
    if (FullLog) REPORT("\nzeroings elements of array....");
    //test struct
    for (int i=0; i<COUNTEXPERIMENT; i++)
    {
        CountElement=rand()%MAX_SIZE;
        TSMas=(TestStruct*)Tcalloc(CountElement,sizeof(TestStruct));
        if (NULL == TSMas)
            continue;
        for (size_t j=0; j<CountElement; j++)
        {
            if (NonZero(TSMas+j, sizeof(TestStruct)))
            {
                CountErrors++;
                if (ShouldReportError()) REPORT("detect nonzero element at TestStruct\n");
            }
        }
        Tfree(TSMas);
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
}
void ClearBrks( )
{
  BRK   *bp;
  BRK   *bpnext;
  BRK   *bplast;

  bplast=(BRK*)&pAllBrks;
  bp=pAllBrks;
  while(  bp )
  {
   bpnext= bp->next;
   if(bp->funcname)
    Tfree((void*)bp->funcname);
   if(bp->dllname)
    Tfree((void*)bp->dllname);
   Tfree((void*)bp);
   bplast->next=bpnext;
   bp=bpnext;
  }
  pAllBrks = NULL;
}
void XSrvUndBrk( ULONG brkat )
{
 BRK *p, *pprev;

 /****************************************************************************/
 /* - scan the break point list and remove this break point.                 */
 /****************************************************************************/
 pprev = (BRK*)&pAllBrks;
 p = pprev->next;
 for( ; p ; )
 {
  if( p->brkat == brkat )
  {
   pprev->next = p->next;
   if( p->cond )
     Tfree( (void*)p->cond );
   Tfree((void*)p);
   return;
  }
  pprev = p;
  p = pprev->next;
 }
}
int GetLineNumber( char c )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 uchar *SaveArea;
 int    LineNumber;
 static int _iview;

 LineNumber = 0;
 sprintf(PromptString,"%c",c);
 Popup.title = LN_Title;
 Popup.instructions = LN_Instructions;
 Popup.help = LNFUNCHELP;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* loop to handle user entry/errors.                                        */
 /****************************************************************************/
 for(;;)
 {
  hp = LN_Instructions;

  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if( key == ESC )
   break;
  else if ( key == ENTER )
  {
   if( strlen(PromptString) == 0 )
    continue;
   LineNumber = atoi(PromptString);
   break;
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
  iview=_iview;
 return(LineNumber);
}
void CMemTest::Free_NULL()
{
    CountErrors=0;
    if (FullLog) REPORT("\ncall free with parameter NULL....");
    errno = 0;
    for (int i=0; i<COUNTEXPERIMENT; i++)
    {
        Tfree(NULL);
        if (errno != 0)
        {
            CountErrors++;
            if (ShouldReportError()) REPORT("error is found by a call free with parameter NULL\n");
        }
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
}
Example #7
0
void InvariantDataRealloc(bool aligned, size_t maxAllocSize, bool checkData)
{
    Harness::FastRandom fastRandom(1);
    size_t size = 0, start = 0;
    char *ptr = NULL,
        // master to create copies and compare ralloc result against it
        *master = (char*)Tmalloc(2*maxAllocSize);

    ASSERT(master, NULL);
    ASSERT(!(2*maxAllocSize%sizeof(unsigned short)),
           "The loop below expects that 2*maxAllocSize contains sizeof(unsigned short)");
    for (size_t k = 0; k<2*maxAllocSize; k+=sizeof(unsigned short))
        *(unsigned short*)(master+k) = fastRandom.get();

    for (int i=0; i<100; i++) {
        // don't want sizeNew==0 here
        const size_t sizeNew = fastRandom.get() % (maxAllocSize-1) + 1;
        char *ptrNew = aligned?
            (char*)Taligned_realloc(ptr, sizeNew, choose_random_alignment())
            : (char*)Trealloc(ptr, sizeNew);
        ASSERT(ptrNew, NULL);
        // check that old data not changed
        if (checkData)
            ASSERT(!memcmp(ptrNew, master+start, min(size, sizeNew)), "broken data");

        // prepare fresh data, copying them from random position in master
        size = sizeNew;
        ptr = ptrNew;
        if (checkData) {
            start = fastRandom.get() % maxAllocSize;
            memcpy(ptr, master+start, size);
        }
    }
    if (aligned)
        Taligned_realloc(ptr, 0, choose_random_alignment());
    else
        Trealloc(ptr, 0);
    Tfree(master);
}
AFILE *makefp(DEBFILE *pdf, ULONG mid, ULONG instaddr, UCHAR *fname)
{
 uchar    *cp = NULL;
 uint      segbase;
 uchar    *srcbuf;
 uint      Nlines;
 uint      Tlines;
 SEL       srcsel;
 SEL       offsel;

 ushort    srcseglen;
 ushort   *offtab;
 AFILE    *fp;
 int       ftype;
 int       OffsetTableBufSize;
 char      FileNameBuffer[CCHMAXPATH];
 char      FileSpecBuffer[CCHMAXPATH];
 UCHAR     FileNameLength;
 LNOTAB   *pLnoTabEntry;
 int       sfi;
 MODULE   *pModule;
 CSECT    *pCsect;
 UCHAR    *pFileName;
 UCHAR    *fn;
 BOOL      found;
 ULONG     junk;
 int       lno;

 if( fname )
 {
  /***************************************************************************/
  /* - if fname is specified, then the view is to be build using the source  */
  /*   file name supplied by the user as in the case of getfile.             */
  /* - we need to find an sfi to associate with the file.                    */
  /* - build a length-prefixed z-string from the supplied name.              */
  /***************************************************************************/
  fn         = strrchr(fname, '\\');
  fn         = (fn) ? (fn + 1) : fname ;
  pFileName  = Talloc( strlen(fn) + 2 );
  *pFileName = (UCHAR)strlen(fn);
  strcpy( pFileName+1, fn );

  found = FALSE;
  for( sfi=mid=0, pdf = pnode->ExeStruct; pdf != NULL; pdf=pdf->next )
  {
   mid = MapSourceFileToMidSfi( pFileName, &sfi, pdf );
   if( mid && sfi )
   {
    found = TRUE;
    memset(FileNameBuffer, 0, sizeof(FileNameBuffer) );
    strcpy(FileNameBuffer+1, fname );
    FileNameBuffer[0] = (UCHAR)strlen(fname);
    break;
   }
  }

  Tfree( pFileName );

  if( found == FALSE )
   return(NULL);

  instaddr = DBMapLno(mid, 0, sfi, &junk , pdf );
  DBMapInstAddr(instaddr, &pLnoTabEntry, pdf);
  lno = 0;
  if( pLnoTabEntry )
   lno = pLnoTabEntry->lno;
 }
 else
 {
  /***************************************************************************/
  /* - we're going to build the view from an instruction address.            */
  /***************************************************************************/
  if ( pdf->SrcOrAsm == SOURCE_LEVEL )
  {
   mid = DBMapInstAddr(instaddr, &pLnoTabEntry, pdf);
   lno = sfi = 0;
   if( pLnoTabEntry )
   {
    lno = pLnoTabEntry->lno;
    sfi = pLnoTabEntry->sfi;
   }
   if( (pLnoTabEntry != NULL) && (sfi != 0) )
   {
    memset(FileNameBuffer, 0, sizeof(FileNameBuffer) );
    cp = GetFileName( mid, sfi );
    if( cp )
     strcpy(FileNameBuffer, cp);
   }
  }
 }

 if(ftype)
 {
  findsrc(FileNameBuffer+1,FileSpecBuffer+1,sizeof(FileSpecBuffer) );
  FileSpecBuffer[0] = (UCHAR)strlen(FileSpecBuffer+1);
  memcpy(FileNameBuffer,FileSpecBuffer,sizeof(FileSpecBuffer));
 }

 FileNameLength = FileNameBuffer[0];

 fp = (AFILE*) Talloc(SizeOfAFILE(FileNameLength));
 memcpy( fp->filename, FileNameBuffer, FileNameLength+1);

 /****************************************************************************/
 /* - allocate 64k for the source buffer.                                    */
 /* - allocate 20k for the offset buffer.                                    */
 /* - load source file into a buffer and define:                             */
 /*    - srcsel    =  source buffer selector.                                */
 /*    - offsel    =  offset buffer selector.                                */
 /*    - 0         =  number of lines to skip at the beginning of the file.  */
 /*    - srcseglen =  source buffer bytes actually used by the load.         */
 /*    - Nlines    =  number of source lines in the buffer.                  */
 /*    - Tlines    =  number of source lines in the entire file.             */
 /* - reallocate the source buffer to size really needed.                    */
 /****************************************************************************/
 Nlines = srcsel = offsel = 0;
 if( !DosAllocSeg(0,(PSEL)&srcsel,0) &&
     !DosAllocSeg(20*1024,(PSEL)&offsel, 0) )
 {
  LoadSource( fp->filename+1, (UCHAR *)Sel2Flat(srcsel),
             (USHORT *)Sel2Flat(offsel), 0, &srcseglen, &Nlines, &Tlines);
  if( Nlines )
   DosReallocSeg(srcseglen, srcsel);
 }

 /****************************************************************************/
 /* - now, define the view structure.                                        */
 /****************************************************************************/
 fp->shower   = showA;
 fp->pdf      = pdf;
 fp->mid      = mid;
 fp->sfi      = sfi;
 fp->mseg     = segbase;
 fp->Tlines   = Tlines;                 /* number of lines in file.          */
 fp->Nlines   = Nlines;                 /* number of lines in source buffer. */
 fp->Nbias    = 0;                      /* number of lines skipped in source.*/
 fp->topline  = 1;                      /* init to 1st line in the file.     */
 fp->csrline  = lno;                    /*  " "                              */
 fp->hotline  = lno;                    /*  " "                              */
 fp->hotaddr  = instaddr;
 fp->skipcols = 0;                      /* columns skipped on left.          */
 fp->Nshown   = 0;
 fp->topoff   = instaddr;
 fp->csr.row  = 0;
 fp->csr.col  = 0;
 fp->csr.mode = CSR_NORMAL;
 fp->sview    = NOSRC;                  /* assume no source disassembler view*/
 fp->flags    = ASM_VIEW_NEW;

 if( Nlines )
 {
  srcbuf = (uchar*)Sel2Flat(srcsel);
  fp->source = srcbuf;

  /**************************************************************************/
  /* Allocate the offtab[] buffer to hold Nlines + 1 offsets. We add the 1  */
  /* so that we can make the offset table indices line up with the          */
  /* source line numbers.                                                   */
  /**************************************************************************/
  OffsetTableBufSize = (Nlines+1)*sizeof(USHORT);
  offtab             = (USHORT*) Talloc(OffsetTableBufSize);

  memcpy(offtab + 1, (uchar*)Sel2Flat(offsel), Nlines*sizeof(USHORT) );

  fp->offtab = offtab;
  fp->flags  = 0;                      /* clear asm flag.                   */

  if( Tlines > Nlines )                /* does compressed source exceed 64k?*/
   fp->flags |= AF_HUGE;               /* mark afile with huge file flag    */

  fp->shower = showC;                  /*  display source                   */
  fp->sview  = MIXEDN;                 /* assume no source disassembler view*/

/*
  Flag all text lines for which a (line #, offset) pair exists.
*/

  pModule = GetModuleWithAddr( instaddr, pdf );
  if( pModule )
  {
   for(pCsect = pModule->pCsects; pCsect != NULL; pCsect=pCsect->next )
   {
    int NumEntries;

    NumEntries   = pCsect->NumEntries;
    pLnoTabEntry = pCsect->pLnoTab;

    if( (pLnoTabEntry != NULL) && ( NumEntries > 0 ) )
    {
     for( ; NumEntries; pLnoTabEntry++, NumEntries-- )
     {
      if( pLnoTabEntry->sfi == sfi )
      {
       int lno;

       lno = pLnoTabEntry->lno;
       if( (lno != 0) && (lno <= Nlines) )
       {
        *(srcbuf + offtab[lno] - 1) |= LINE_OK;
       }
      }
     }
    }
   }
  }
  MarkLineBRKs( fp );                   /* mark the active breakpoints       */
 }

 if( offsel )                           /* if there was an offset segment    */
  DosFreeSeg(offsel);                   /* allocated then free it up         */
 if( !Nlines && srcsel )                /* if there was no source then       */
  DosFreeSeg(srcsel);                   /* free up the temp source buffer    */

 return( fp );
}
void CMemTest::UniquePointer()
{
    CountErrors=0;
    int **MasPointer = (int **)Tmalloc(sizeof(int*)*COUNT_ELEM);
    size_t *MasCountElem = (size_t*)Tmalloc(sizeof(size_t)*COUNT_ELEM);
    if (FullLog) REPORT("\nUnique pointer using 0\n");
    ASSERT(MasCountElem && MasPointer, NULL);
    //
    //-------------------------------------------------------
    //malloc
    for (int i=0; i<COUNT_ELEM; i++)
    {
        MasCountElem[i]=rand()%MAX_SIZE;
        MasPointer[i]=(int*)Tmalloc(MasCountElem[i]*sizeof(int));
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
        memset(MasPointer[i], 0, sizeof(int)*MasCountElem[i]);
    }
    if (FullLog) REPORT("malloc....");
    for (UINT i=0; i<COUNT_ELEM-1; i++)
    {
        if (size_t badOff = NonZero(MasPointer[i], sizeof(int)*MasCountElem[i])) {
            CountErrors++;
            if (ShouldReportError())
                REPORT("error, detect non-zero at %p\n", (char*)MasPointer[i]+badOff-1);
        }
        memset(MasPointer[i], 1, sizeof(int)*MasCountElem[i]);
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    //----------------------------------------------------------
    //calloc
    for (int i=0; i<COUNT_ELEM; i++)
        Tfree(MasPointer[i]);
    CountErrors=0;
    for (long i=0; i<COUNT_ELEM; i++)
    {
        MasPointer[i]=(int*)Tcalloc(MasCountElem[i]*sizeof(int),2);
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
    }
    if (FullLog) REPORT("calloc....");
    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        if (size_t badOff = NonZero(MasPointer[i], sizeof(int)*MasCountElem[i])) {
            CountErrors++;
            if (ShouldReportError())
                REPORT("error, detect non-zero at %p\n", (char*)MasPointer[i]+badOff-1);
        }
        memset(MasPointer[i], 1, sizeof(int)*MasCountElem[i]);
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    //---------------------------------------------------------
    //realloc
    CountErrors=0;
    for (int i=0; i<COUNT_ELEM; i++)
    {
        MasCountElem[i]*=2;
        *(MasPointer+i)=
            (int*)Trealloc(*(MasPointer+i),MasCountElem[i]*sizeof(int));
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
        memset(MasPointer[i], 0, sizeof(int)*MasCountElem[i]);
    }
    if (FullLog) REPORT("realloc....");
    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        if (NonZero(MasPointer[i], sizeof(int)*MasCountElem[i]))
            CountErrors++;
        memset(MasPointer[i], 1, sizeof(int)*MasCountElem[i]);
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    for (int i=0; i<COUNT_ELEM; i++)
        Tfree(MasPointer[i]);
    Tfree(MasCountElem);
    Tfree(MasPointer);
}
void CMemTest::NULLReturn(UINT MinSize, UINT MaxSize, int total_threads)
{
    const int MB_PER_THREAD = TOTAL_MB_ALLOC / total_threads;
    // find size to guarantee getting NULL for 1024 B allocations
    const int MAXNUM_1024 = (MB_PER_THREAD + (MB_PER_THREAD>>2)) * 1024;

    std::vector<MemStruct> PointerList;
    void *tmp;
    CountErrors=0;
    int CountNULL, num_1024;
    if (FullLog) REPORT("\nNULL return & check errno:\n");
    UINT Size;
    Limit limit_total(TOTAL_MB_ALLOC), no_limit(0);
    void **buf_1024 = (void**)Tmalloc(MAXNUM_1024*sizeof(void*));

    ASSERT(buf_1024, NULL);
    /* We must have space for pointers when memory limit is hit.
       Reserve enough for the worst case, taking into account race for
       limited space between threads.
    */
    PointerList.reserve(TOTAL_MB_ALLOC*MByte/MinSize);

    /* There is a bug in the specific version of GLIBC (2.5-12) shipped
       with RHEL5 that leads to erroneous working of the test
       on Intel64 and IPF systems when setrlimit-related part is enabled.
       Switching to GLIBC 2.5-18 from RHEL5.1 resolved the issue.
     */
    if (perProcessLimits)
        limitBarrier->wait(limit_total);
    else
        limitMem(MB_PER_THREAD);

    /* regression test against the bug in allocator when it dereference NULL
       while lack of memory
    */
    for (num_1024=0; num_1024<MAXNUM_1024; num_1024++) {
        buf_1024[num_1024] = Tcalloc(1024, 1);
        if (! buf_1024[num_1024]) {
            ASSERT_ERRNO(errno == ENOMEM, NULL);
            break;
        }
    }
    for (int i=0; i<num_1024; i++)
        Tfree(buf_1024[i]);
    Tfree(buf_1024);

    do {
        Size=rand()%(MaxSize-MinSize)+MinSize;
        tmp=Tmalloc(Size);
        if (tmp != NULL)
        {
            myMemset(tmp, 0, Size);
            PointerList.push_back(MemStruct(tmp, Size));
        }
    } while(tmp != NULL);
    ASSERT_ERRNO(errno == ENOMEM, NULL);
    if (FullLog) REPORT("\n");

    // preparation complete, now running tests
    // malloc
    if (FullLog) REPORT("malloc....");
    CountNULL = 0;
    while (CountNULL==0)
        for (int j=0; j<COUNT_TESTS; j++)
        {
            Size=rand()%(MaxSize-MinSize)+MinSize;
            errno = ENOMEM+j+1;
            tmp=Tmalloc(Size);
            if (tmp == NULL)
            {
                CountNULL++;
                if ( CHECK_ERRNO(errno != ENOMEM) ) {
                    CountErrors++;
                    if (ShouldReportError()) REPORT("NULL returned, error: errno (%d) != ENOMEM\n", errno);
                }
            }
            else
            {
                // Technically, if malloc returns a non-NULL pointer, it is allowed to set errno anyway.
                // However, on most systems it does not set errno.
                bool known_issue = false;
#if __linux__
                if( CHECK_ERRNO(errno==ENOMEM) ) known_issue = true;
#endif /* __linux__ */
                if ( CHECK_ERRNO(errno != ENOMEM+j+1) && !known_issue) {
                    CountErrors++;
                    if (ShouldReportError()) REPORT("error: errno changed to %d though valid pointer was returned\n", errno);
                }
                myMemset(tmp, 0, Size);
                PointerList.push_back(MemStruct(tmp, Size));
            }
        }
    if (FullLog) REPORT("end malloc\n");
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;

    CountErrors=0;
    //calloc
    if (FullLog) REPORT("calloc....");
    CountNULL = 0;
    while (CountNULL==0)
        for (int j=0; j<COUNT_TESTS; j++)
        {
            Size=rand()%(MaxSize-MinSize)+MinSize;
            errno = ENOMEM+j+1;
            tmp=Tcalloc(COUNT_ELEM_CALLOC,Size);
            if (tmp == NULL)
            {
                CountNULL++;
                if ( CHECK_ERRNO(errno != ENOMEM) ){
                    CountErrors++;
                    if (ShouldReportError()) REPORT("NULL returned, error: errno(%d) != ENOMEM\n", errno);
                }
            }
            else
            {
                // Technically, if calloc returns a non-NULL pointer, it is allowed to set errno anyway.
                // However, on most systems it does not set errno.
                bool known_issue = false;
#if __linux__
                if( CHECK_ERRNO(errno==ENOMEM) ) known_issue = true;
#endif /* __linux__ */
                if ( CHECK_ERRNO(errno != ENOMEM+j+1) && !known_issue ) {
                    CountErrors++;
                    if (ShouldReportError()) REPORT("error: errno changed to %d though valid pointer was returned\n", errno);
                }
                PointerList.push_back(MemStruct(tmp, Size));
            }
        }
    if (FullLog) REPORT("end calloc\n");
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    CountErrors=0;
    if (FullLog) REPORT("realloc....");
    CountNULL = 0;
    if (PointerList.size() > 0)
        while (CountNULL==0)
            for (size_t i=0; i<(size_t)COUNT_TESTS && i<PointerList.size(); i++)
            {
                errno = 0;
                tmp=Trealloc(PointerList[i].Pointer,PointerList[i].Size*2);
                if (PointerList[i].Pointer == tmp) // the same place
                {
                    bool known_issue = false;
#if __linux__
                    if( errno==ENOMEM ) known_issue = true;
#endif /* __linux__ */
                    if (errno != 0 && !known_issue) {
                        CountErrors++;
                        if (ShouldReportError()) REPORT("valid pointer returned, error: errno not kept\n");
                    }
                    PointerList[i].Size *= 2;
                }
                else if (tmp != PointerList[i].Pointer && tmp != NULL) // another place
                {
                    bool known_issue = false;
#if __linux__
                    if( errno==ENOMEM ) known_issue = true;
#endif /* __linux__ */
                    if (errno != 0 && !known_issue) {
                        CountErrors++;
                        if (ShouldReportError()) REPORT("valid pointer returned, error: errno not kept\n");
                    }
                    // newly allocated area have to be zeroed
                    myMemset((char*)tmp + PointerList[i].Size, 0, PointerList[i].Size);
                    PointerList[i].Pointer = tmp;
                    PointerList[i].Size *= 2;
                }
                else if (tmp == NULL)
                {
                    CountNULL++;
                    if ( CHECK_ERRNO(errno != ENOMEM) )
                    {
                        CountErrors++;
                        if (ShouldReportError()) REPORT("NULL returned, error: errno(%d) != ENOMEM\n", errno);
                    }
                    // check data integrity
                    if (NonZero(PointerList[i].Pointer, PointerList[i].Size)) {
                        CountErrors++;
                        if (ShouldReportError()) REPORT("NULL returned, error: data changed\n");
                    }
                }
            }
    if (FullLog) REPORT("realloc end\n");
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    for (UINT i=0; i<PointerList.size(); i++)
    {
        Tfree(PointerList[i].Pointer);
    }

    if (perProcessLimits)
        limitBarrier->wait(no_limit);
    else
        limitMem(0);
}
 AFILE *
GetFunction( char *InitString , uint func )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 AFILE *fp;
 uchar *SaveArea;
 int    IsAddr;
 static int _iview;

 /****************************************************************************/
 /* - copy the initstring ( cursor sensitive prompt ) into the prompt string.*/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area.                                                  */
 /* - get a function name from the user.                                     */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area.                                          */
 /*                                                                          */
 /****************************************************************************/
 fp = NULL;

#if defined(MSH)
 if(commandLine.nparms>1) {
    IsAddr = (func==GETADDRESS)?TRUE:FALSE;
    fp = FindFuncOrAddr(commandLine.parms[1],IsAddr);
    if(fp)
    {
#if defined(SD386LOG)
        SD386Log(STRINGCODE," ");
        SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
        return(fp);
    }
 }
#endif
 _iview=iview; iview=0;
 strcpy(PromptString,InitString);
 Popup.Flags = 0;
 if( func == GETFUNCTION )
 {
  Popup.title = GF_Title;
  Popup.instructions = GF_Instructions;
  Popup.help = GETFUNCHELP;
  Popup.Flags = CLEAR1ST;
 }
 else /* func == GETADDRESS */
 {
  Popup.title = GA_Title;
  Popup.instructions = GA_Instructions;
  Popup.help = GETADDRHELP;
 }

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* loop to handle user entry/errors.                                        */
 /****************************************************************************/
 for(;;)
 {
  if( func == GETFUNCTION )
   hp = GF_Instructions;
  else
   hp = GA_Instructions;

  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);


  if( key == ESC )
  {
#if 0
    SD386Log(STRINGCODE," ");
   SD386Log(KEYCODE|key,"");
#endif
   break;
  }
  else if ( key == ENTER )
  {
   if( strlen(PromptString) == 0 )
    continue;
   IsAddr = (func==GETADDRESS)?TRUE:FALSE;
   fp = FindFuncOrAddr(PromptString,IsAddr);
   if( fp )
   {
#if 0
    SD386Log(STRINGCODE," ");
    SD386Log(STRINGCODE,PromptString);
#endif
    break;
   }

   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
   beep();
   hp = CantFind;
   fmterr( hp);
   continue;
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
 iview=_iview;
 return(fp);
}
void CMemTest::AddrArifm()
{
    PtrSize *arr = (PtrSize*)Tmalloc(COUNT_ELEM*sizeof(PtrSize));

    if (FullLog) REPORT("\nUnique pointer using Address arithmetics\n");
    if (FullLog) REPORT("malloc....");
    ASSERT(arr, NULL);
    for (int i=0; i<COUNT_ELEM; i++)
    {
        arr[i].size=rand()%MAX_SIZE;
        arr[i].ptr=Tmalloc(arr[i].size);
    }
    qsort(arr, COUNT_ELEM, sizeof(PtrSize), cmpAddrs);

    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        if (NULL!=arr[i].ptr && NULL!=arr[i+1].ptr)
            ASSERT((uintptr_t)arr[i].ptr+arr[i].size <= (uintptr_t)arr[i+1].ptr,
                   "intersection detected");
    }
    //----------------------------------------------------------------
    if (FullLog) REPORT("realloc....");
    for (int i=0; i<COUNT_ELEM; i++)
    {
        size_t count=arr[i].size*2;
        void *tmpAddr=Trealloc(arr[i].ptr,count);
        if (NULL!=tmpAddr) {
            arr[i].ptr = tmpAddr;
            arr[i].size = count;
        } else if (count==0) { // becasue realloc(..., 0) works as free
            arr[i].ptr = NULL;
            arr[i].size = 0;
        }
    }
    qsort(arr, COUNT_ELEM, sizeof(PtrSize), cmpAddrs);

    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        if (NULL!=arr[i].ptr && NULL!=arr[i+1].ptr)
            ASSERT((uintptr_t)arr[i].ptr+arr[i].size <= (uintptr_t)arr[i+1].ptr,
                   "intersection detected");
    }
    for (int i=0; i<COUNT_ELEM; i++)
    {
        Tfree(arr[i].ptr);
    }
    //-------------------------------------------
    if (FullLog) REPORT("calloc....");
    for (int i=0; i<COUNT_ELEM; i++)
    {
        arr[i].size=rand()%MAX_SIZE;
        arr[i].ptr=Tcalloc(arr[i].size,1);
    }
    qsort(arr, COUNT_ELEM, sizeof(PtrSize), cmpAddrs);

    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        if (NULL!=arr[i].ptr && NULL!=arr[i+1].ptr)
            ASSERT((uintptr_t)arr[i].ptr+arr[i].size <= (uintptr_t)arr[i+1].ptr,
                   "intersection detected");
    }
    for (int i=0; i<COUNT_ELEM; i++)
    {
        Tfree(arr[i].ptr);
    }
    Tfree(arr);
}
Example #13
0
void CMemTest::UniquePointer()
{
    CountErrors=0;
    int **MasPointer = (int **)Tmalloc(sizeof(int*)*COUNT_ELEM);
    size_t *MasCountElem = (size_t*)Tmalloc(sizeof(size_t)*COUNT_ELEM);
    if (FullLog) REPORT("\nUnique pointer using 0\n");
    ASSERT(MasCountElem && MasPointer, NULL);
    //
    //-------------------------------------------------------
    //malloc
    for (int i=0; i<COUNT_ELEM; i++)
    {
        MasCountElem[i]=rand()%MAX_SIZE;
        MasPointer[i]=(int*)Tmalloc(MasCountElem[i]*sizeof(int));
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
        for (UINT j=0; j<MasCountElem[i]; j++)
            *(MasPointer[i]+j)=0;
    }
    if (FullLog) REPORT("malloc....");
    for (UINT i=0; i<COUNT_ELEM-1; i++)
    {
        for (UINT j=0; j<MasCountElem[i]; j++)
        {
            if (*(*(MasPointer+i)+j)!=0)
            {
                CountErrors++;
                if (ShouldReportError()) REPORT("error, detect 1 with 0x%p\n",(*(MasPointer+i)+j));
            }
            *(*(MasPointer+i)+j)+=1;
        }
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    //----------------------------------------------------------
    //calloc
    for (int i=0; i<COUNT_ELEM; i++)
        Tfree(MasPointer[i]);
    CountErrors=0;
    for (long i=0; i<COUNT_ELEM; i++)
    {
        MasPointer[i]=(int*)Tcalloc(MasCountElem[i]*sizeof(int),2);
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
    }
    if (FullLog) REPORT("calloc....");
    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        for (UINT j=0; j<*(MasCountElem+i); j++)
        {
            if (*(*(MasPointer+i)+j)!=0)
            {
                CountErrors++;
                if (ShouldReportError()) REPORT("error, detect 1 with 0x%p\n",(*(MasPointer+i)+j));
            }
            *(*(MasPointer+i)+j)+=1;
        }
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    //---------------------------------------------------------
    //realloc
    CountErrors=0;
    for (int i=0; i<COUNT_ELEM; i++)
    {
        MasCountElem[i]*=2;
        *(MasPointer+i)=
            (int*)Trealloc(*(MasPointer+i),MasCountElem[i]*sizeof(int));
        if (NULL == MasPointer[i])
            MasCountElem[i]=0;
        for (UINT j=0; j<MasCountElem[i]; j++)
            *(*(MasPointer+i)+j)=0;
    }
    if (FullLog) REPORT("realloc....");
    for (int i=0; i<COUNT_ELEM-1; i++)
    {
        for (UINT j=0; j<*(MasCountElem+i); j++)
        {
            if (*(*(MasPointer+i)+j)!=0)
            {
                CountErrors++;
            }
            *(*(MasPointer+i)+j)+=1;
        }
    }
    if (CountErrors) REPORT("%s\n",strError);
    else if (FullLog) REPORT("%s\n",strOk);
    error_occurred |= ( CountErrors>0 ) ;
    for (int i=0; i<COUNT_ELEM; i++)
        Tfree(MasPointer[i]);
    Tfree(MasCountElem);
    Tfree(MasPointer);
}
 AFILE *
GetF( )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 AFILE *fp;
 uchar *SaveArea;

 static int _iview;
 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get a function name from the user.                                     */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/
 fp = NULL;
#if defined(MSH)
 if(commandLine.nparms>1) {
    fp=GetFile(commandLine.parms[1]);
    if(fp)
    {
#if defined(SD386LOG)
        SD386Log(STRINGCODE," ");
        SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
        return fp;
    }
 }
#endif
 _iview=iview; iview=0;
 *PromptString = '\0';

 Popup.title = GE_Title;
 Popup.instructions = GE_Instructions;
 Popup.help = GETFILEHELP;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* loop to handle user entry/errors.                                        */
 /****************************************************************************/
 for(;;)
 {
  hp = GE_Instructions;
  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if( key == ESC )
  {
#if 0
    SD386Log(STRINGCODE," ");
   SD386Log(KEYCODE|key,"");
#endif
   break;
  }
  else if ( key == ENTER )
  {
   if( strlen(PromptString) == 0 )
    continue;
   fp = GetFile(PromptString);
   if( fp )
   {
#if 0
        SD386Log(STRINGCODE," ");
        SD386Log(STRINGCODE,PromptString);
#endif
        break;
   }

   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
   beep();
   hp = CantFind;
   fmterr( hp);
   continue;
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
 iview=_iview;
 return(fp);
}
uint GetString( uint FieldRow, uint FieldCol, uint length, uint displen,
                uint *cursor, uchar *pInbuf, uint InFlags, POPUPSHELL *pShell)
{
  /***************************************************************************/
  /* Diagram to explain local variables.                                     */
  /*                                                                         */
  /*  0  ...     10        ...                   40       ...          200   */
  /*                                                                         */
  /*             +-------------------------------+                           */
  /*  +----------|                               |---------------------+     */
  /*  |          |  Portion of the string shown  |                     |     */
  /*  |          |  in the screen.               |                     |     */
  /*  +----------|                               |---------------------+     */
  /*             +-------------------------------+                           */
  /*             |<---- Display Length --------->|                           */
  /*                                                                         */
  /*  |<------------ length (length of the entire buffer) ------------>|     */
  /*                                                                         */
  /*   In the above example:                                                 */
  /*                                                                         */
  /*   length            ===>  200                                           */
  /*   DisplayLength     ===>  30                                            */
  /*   DisplayOffset     ===>  10                                            */
  /*                                                                         */
  /***************************************************************************/
  uint        key;
  int         n, i;
  ushort      rc;
  int         voff;
  uint        IsInsertMode = 0, scratch, BufLen;
  uint        DisplayOffset;
  uint        CursorRow, CursorCol;
  int         FirstKeyEntry = TRUE;                                     /*910*/
  uint        flags = InFlags;                                          /*910*/
  int         state = MOU_STATE_UP; /* assume this! */                  /*910*/
  int         NextState = 0;                                            /*910*/
  BUTTON     *pButtonDown = NULL;                                       /*910*/

  /***************************************************************************/
  /*                                                                         */
  /* flags  - Flags which indicate type of the field.                        */
  /*          (AUTOEXIT / HEXONLY / BINONLY)                                 */
  /***************************************************************************/
  if(pShell)
   flags = pShell->Flags;                                               /*910*/

  /***************************************************************************/
  /* - Set keyboard flush buffer flag to indiacte not to flush the keyboard  */
  /*   buffer while we are in getstring.                                     */
  /* - Initialise the local variables.                                       */
  /***************************************************************************/
  SetFlushBufferFlag( NOFLUSHNOW );                                     /*820*/
  FieldDisplayLength = displen;
  DisplayOffset = 0;
  CursorRow = FieldRow;

  CursorCol = ( *cursor > displen ) ? FieldCol : FieldCol + *cursor;

#ifdef MSH
  if(iview) {
    CursorRow+=RowStart;
    FieldRow+=RowStart;
    CursorCol+=ColStart;
    FieldCol+=ColStart;
  }
#endif

  /***************************************************************************/
  /* Allocate memory for the local buffer.                                   */
  /***************************************************************************/
  Buffer = (uchar *)Talloc( (length+1) * sizeof( uchar ) );
  memset( Buffer, '\0', length+1 );
  if(!iview) {
  /***************************************************************************/
  /* Adjust display length if the length specified by the caller goes out of */
  /* the screen.                                                             */
  /***************************************************************************/
  if( FieldCol + FieldDisplayLength > VideoCols )
    FieldDisplayLength = VideoCols - FieldCol;

  /***************************************************************************/
  /* Check to see if the field would over lap some other window, if so adjust*/
  /* the display length accordingly.                                         */
  /***************************************************************************/
  if( FieldDisplayLength + FieldCol > BoundPtr[FieldRow] )
    FieldDisplayLength = BoundPtr[FieldRow] - FieldCol;
  }
  else
  {
#ifdef MSH
      if( FieldDisplayLength + FieldCol - ColStart> VideoWidth )
        FieldDisplayLength = VideoWidth - FieldCol + ColStart;
#endif

  }/* End if*/
  /***************************************************************************/
  /* RightScrollOffset is the amount of scrolling to be done when the user   */
  /* goes out of the display length. It is 2/3 rds of the display length.    */
  /***************************************************************************/
  RightScrollOffset  = (FieldDisplayLength * 2)/3;
  LeftScrollOffset   = FieldDisplayLength - RightScrollOffset;

  FieldBase = (uchar *)Sel2Flat( HiFlat(VideoPtr) ) +
              ( voff = 2*(FieldRow*VideoCols + FieldCol) );
  FieldType = flags;

  /***************************************************************************/
  /* Depending on the type of the string copy the initial string to the local*/
  /* buffer. Display the string.                                             */
  /***************************************************************************/
  if( (FieldType & HEXONLY) || (FieldType & BINONLY) )
  {
    for( i = 0; i < length; i++ )
      Buffer[i] = FieldBase[i*2];
  }
  else
    strcpy( Buffer, pInbuf );

  DisplayField( DisplayOffset );
  VioShowBuf( (ushort)voff,(ushort) (2*FieldDisplayLength), 0 );

  VioSetCurType( &NormalCursor, 0 );

  for(;;)
  {
    VioSetCurPos( (ushort)CursorRow, (ushort)CursorCol, 0 );

    Event = GetEvent( SEM_INDEFINITE_WAIT );

    switch( Event->Type )
    {
      case TYPE_MOUSE_EVENT:                                            /*910*/
      {                                                                 /*910*/
       /******************************************************************910*/
       /* Test for mouse event between the string brackets.               910*/
       /******************************************************************910*/
       if( ( Event->Row == (ushort)FieldRow ) &&                        /*910*/
           ( Event->Col >= (ushort)FieldCol ) &&                        /*910*/
           ( Event->Col <= ((ushort)FieldCol+(ushort)FieldDisplayLength-1))
         )                                                              /*910*/
       {                                                                /*910*/
        /*****************************************************************910*/
        /* - If it's a button down event then set the cursor at the       910*/
        /*   end of the string or on the character that was clicked on.   910*/
        /*****************************************************************910*/
        if( Event->Value == EVENT_BUTTON_1_DOWN)                        /*910*/
        {                                                               /*910*/
          BufLen = strlen( Buffer );                                    /*910*/
          if( (DisplayOffset + (Event->Col - FieldCol)) > BufLen )      /*910*/
          {                                                             /*910*/
            keybeep();                                                  /*910*/
            CursorCol = FieldCol + (BufLen - DisplayOffset);            /*910*/
          }                                                             /*910*/
          else                                                          /*910*/
            CursorCol = (uint)Event->Col;                               /*910*/
        }                                                               /*910*/
        /*****************************************************************910*/
        /* - Ignore events between the brackets that are not button       910*/
        /*   down events.                                                 910*/
        /* - Any mouse event between []s turns off the erasure of a       910*/
        /*   cursor sensitive prompt.                                     910*/
        /*****************************************************************910*/
        FieldType &= ~CLEAR1ST;                                         /*910*/
        continue;                                                       /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       /**********************************************************************/
       /* - handle strings that are not in the context of a popup.           */
       /**********************************************************************/
       if(pShell == NULL )                                              /*910*/
       {                                                                /*910*/
        NextState = GetMouseState( Event );                             /*910*/
        if( (state == MOU_STATE_UP) &&                                  /*910*/
            (NextState == MOU_STATE_DOWN)                               /*910*/
          )                                                             /*910*/
        {                                                               /*910*/
         key = LEFTMOUSECLICK;                                          /*910*/
         break;                                                         /*910*/
        }                                                               /*910*/
                                                                        /*910*/
        state = NextState;                                              /*910*/
        continue;                                                       /*910*/
       }                                                                /*910*/
       /******************************************************************910*/
       /* - Now, handle mouse events outside the []s within the context   910*/
       /*   of a popup.                                                   910*/
       /*                                                                 910*/
       /* - Button events are valid on the release event.                 910*/
       /*                                                                 910*/
       /* - Transitions from up to down "outside" the <>s and []s         910*/
       /*   are returned to the caller as a LEFTMOUSECLICK.               910*/
       /*                                                                 910*/
       /*  ------------------------                                       910*/
       /* |                        |                                      910*/
       /* |                       -----------                             910*/
       /* |         <------------|           |<----------------           910*/
       /* |        |              -----------                  |          910*/
       /* |      ----                                        ----         910*/
       /* |     |    |---                                ---|    |---     910*/
       /* |     | UP |   | BU,BUM                BD,BDM |   | DN |   |    910*/
       /* |     |    |<--                                -->|    |<--     910*/
       /* |      ----                                        ----         910*/
       /* |        |                                           |          910*/
       /* |        |                                           |          910*/
       /* |        |              -----------                  |          910*/
       /* |         ------------>|           |---------------->           910*/
       /* |                       -----------                             910*/
       /* |                               |                               910*/
       /* |                               |                               910*/
       /* | BU  - Button up event.        |                               910*/
       /* | BUM - Button up move event.    -(1) If BD or BDM event        910*/
       /* | BD  - Button down event.            occurs in a button(<>s),  910*/
       /* | BDM - Button down move event.       then set pButtonDown      910*/
       /* |                                     to point to the BUTTON    910*/
       /* |                                     structure. This is        910*/
       /* |                                     effectively a "pending"   910*/
       /*  ----(1) If BU or BUM event           button event. If the      910*/
       /*          && if the event occurs       up event occurs within    910*/
       /*          in the same button as        the same <>s, then we've  910*/
       /*          a "pending" button           got ourselves a valid     910*/
       /*          then we have a button        button event.             910*/
       /*          event.                                                 910*/
       /*                                   (2) If BD or BDM do not       910*/
       /*                                       occur within a button,    910*/
       /*                                       then set pButtonDown=NULL 910*/
       /*                                       and go back to the        910*/
       /*                                       caller with a             910*/
       /*                                       LEFTMOUSECLICK.           910*/
       /*                                                                 910*/
       /******************************************************************910*/
       NextState = GetMouseState( Event );                              /*910*/
       if( (state == MOU_STATE_DOWN) &&                                 /*910*/
           (NextState == MOU_STATE_UP) &&                               /*910*/
           (pButtonDown != NULL) &&                                     /*910*/
           (pButtonDown == GetButtonPtr(pShell,Event))                  /*910*/
         )                                                              /*910*/
       {                                                                /*910*/
        key = pButtonDown->Key;                                         /*910*/
        break;                                                          /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       if( (state == MOU_STATE_UP) &&                                   /*910*/
           (NextState == MOU_STATE_DOWN)                                /*910*/
         )                                                              /*910*/
       {                                                                /*910*/
        pButtonDown = GetButtonPtr( pShell,Event);                      /*910*/
        if( pButtonDown == NULL )                                       /*910*/
        {                                                               /*910*/
         key = LEFTMOUSECLICK;                                          /*910*/
         break;                                                         /*910*/
        }                                                               /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       state = NextState;                                               /*910*/
       continue;                                                        /*910*/
      }

      case TYPE_KBD_EVENT:
      {
        key = Event->Value;
        break;
      }
    }

    if( (FieldType & CLEAR1ST) && (FirstKeyEntry == TRUE) )             /*910*/
     FirstKeyEntry = FALSE;                                             /*910*/

    switch( key )
    {
      case F1:
      case ESC:
      case ENTER:
      case UP:
      case DOWN:
      case A_ENTER:
      case MOUSECLICK:
      /***********************************************************************/
      /* - these keys are specific to the watchpoint dialog.              910*/
      /***********************************************************************/
      case TYNEXT:                      /* watchpoint type button.        910*/
      case SPNEXT:                      /* watchpoint scope button.       910*/
      case SZNEXT:                      /* watchpoint size button.        910*/
      case STNEXT:                      /* watchpoint status button.      910*/
      {
        /*********************************************************************/
        /* All the above keys cannot be proccessed by getstring, so return   */
        /* the key to the caller.                                            */
        /*********************************************************************/
        rc = RCBREAK;
        break;
      }

      case C_HOME:
      {
        /*********************************************************************/
        /* Control-Home takes you to the start of the string.                */
        /*********************************************************************/
        DisplayOffset = 0;
        CursorCol = FieldCol;
        rc = RCREDRAW;
        break;
      }

      case C_END:
      {
        /*********************************************************************/
        /* Control-End takes you to the end of the string (to the last char  */
        /* the user has types in).                                           */
        /*********************************************************************/
        BufLen = strlen( Buffer );
        if( BufLen > FieldDisplayLength )
        {
          DisplayOffset = BufLen - FieldDisplayLength;
          CursorCol = FieldCol + FieldDisplayLength - 1;
        }
        else
        {
          DisplayOffset = 0;
          CursorCol = FieldCol + BufLen;
        }
        rc = RCREDRAW;
        break;
      }

      case TAB:
      case S_TAB:
      {
        /*********************************************************************/
        /* If the user has keyed in a tab  and the field type is AUTOEXIT,   */
        /* return to the caller.                                             */
        /*********************************************************************/
        if( FieldType & AUTOEXIT )
          rc = RCBREAK;
        else
        {
          keybeep();
          rc = 0;
        }
        break;
      }

      case LEFT:
      {
        /*********************************************************************/
        /* The user has pressed the left arrow key.                          */
        /*  - If the cursor is not in the starting column move the cursor    */
        /*    one column to the left.                                        */
        /*********************************************************************/
        if( CursorCol > FieldCol )
        {
          CursorCol--;
          rc = 0;
        }
        else
        {
          /*******************************************************************/
          /* If the cursor is in the starting column, a non zero value in the*/
          /* display offset would indicate we have some characters to the    */
          /* left to be displayed (see diagram above). If you have enough    */
          /* characters to scroll to LeftScrollOffset amount, do so. If not  */
          /* scroll to the start of the string.                              */
          /*******************************************************************/
          if( DisplayOffset )
          {
            if( (int)(DisplayOffset - LeftScrollOffset) >= 0 )
            {
              DisplayOffset -= LeftScrollOffset;
              CursorCol += (LeftScrollOffset - 1);
            }
            else
            {
              CursorCol += DisplayOffset;
              DisplayOffset = 0;
            }
            rc = RCREDRAW;
          }
          else
          {
            if( FieldType & AUTOEXIT )
              rc = RCBREAK;
            else
            {
               keybeep();
               rc = 0;
            }
          }
        }
        break;
      }

      case RIGHT:
      {
        /*********************************************************************/
        /* The user has pressed the right arrow key.                         */
        /*  - If the cursor is not in the ending column of display and not   */
        /*    end of the string, move the cursor one column to the right.    */
        /*********************************************************************/
        BufLen = strlen( Buffer );
        if( CursorCol < ( FieldCol + FieldDisplayLength - 1 ) )
        {
          if( (DisplayOffset + (CursorCol - FieldCol)) < BufLen )
          {
            CursorCol++;
            rc = 0;
          }
          else
          {
            keybeep();
            rc = 0;
          }
        }
        else
        {
          /*******************************************************************/
          /* If the cursor is at the ending column of display, check to see  */
          /* if we are within the buffer length. If we have enough space to  */
          /* scroll by RightScrollOffset amount do so, if not scroll till the*/
          /* end of the string.                                              */
          /*******************************************************************/
          if( DisplayOffset + FieldDisplayLength < BufLen )
          {
            DisplayOffset += (FieldDisplayLength - RightScrollOffset);
            if( (DisplayOffset + (CursorCol - FieldCol)) > BufLen )
              CursorCol = FieldCol + (BufLen - DisplayOffset);
            else
              CursorCol = FieldCol + RightScrollOffset;
            rc = RCREDRAW;
          }
          else
          {
            /*****************************************************************/
            /* If we reached the ending column and the end of the buffer, if */
            /* the field type is AUTOEXIT return to the caller.              */
            /*****************************************************************/
            if( FieldType & AUTOEXIT )
              rc = RCBREAK;
            else
            {
              keybeep();
              rc = 0;
            }
          }
        }
        break;
      }

      case HOME:
      {
        /*********************************************************************/
        /* Home takes to the starting column of the string.                  */
        /*********************************************************************/
        CursorCol = FieldCol;
        break;
      }

      case END:
      {
        /*********************************************************************/
        /* End takes you to the ending column of the string. If the string   */
        /* is not long enough till the ending column of the display, End     */
        /* takes you to the end of the string.                               */
        /*********************************************************************/
        CursorCol = FieldCol + FieldDisplayLength - 1;
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        BufLen = strlen( Buffer );
        if( scratch > BufLen )
          CursorCol = FieldCol + (BufLen - DisplayOffset);
        break;
      }

      case INS:
      {
        /*********************************************************************/
        /* Insert key is pressed. This toggles the InsertMode flag. If the   */
        /* current length of the string is less than the buffer length,      */
        /* InsertMode could be allowed. Set the cusror type accordingly.     */
        /*********************************************************************/
        if( IsInsertMode )
        {
          IsInsertMode = 0;
          VioSetCurType( &NormalCursor, 0 );
        }
        else
        {
          if( length != strlen( Buffer ) )
          {
            IsInsertMode = 1 - IsInsertMode;
            IsInsertMode ? VioSetCurType( &InsertCursor, 0 ) :
                           VioSetCurType( &NormalCursor, 0 );
          }
          else                           /* Display proper error message...   */
            keybeep();
        }
        break;
      }

      case DEL:
      {
        /*********************************************************************/
        /* Delete the current character. The rest of the string is shifted   */
        /* left.                                                             */
        /*********************************************************************/
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        ( scratch < strlen( Buffer ) ) ? ShiftLeft( scratch ) :
                                       keybeep();
        rc = RCREDRAW;
        break;
      }

      case BACKSPACE:
      {
        /*********************************************************************/
        /* The previous character to the cursor is deleted. By default the   */
        /* string is shifted left by one character. But if the cursor is on  */
        /* the starting column then the string is shifted by LeftScrollOffset*/
        /* amount.                                                           */
        /*********************************************************************/
        scratch = DisplayOffset + (CursorCol - FieldCol);
        if( scratch )
        {
          ShiftLeft( scratch - 1 );
          CursorCol--;
          if( CursorCol < FieldCol )
          {
            if( (int)(DisplayOffset - LeftScrollOffset) >= 0 )
            {
              DisplayOffset -= LeftScrollOffset;
              CursorCol += LeftScrollOffset;
            }
            else
            {
              CursorCol += (DisplayOffset + 1);
              DisplayOffset = 0;
            }
          }
        }
        else
          keybeep();
        rc = RCREDRAW;
        break;
      }

      default:
      {
        /*********************************************************************/
        /* Any other character key is pressed. Verify the validity of the    */
        /* character depending on the type of the string (HEX/BIN).          */
        /*********************************************************************/
        key &= 0xFF;
        if( key != 0x15 )
        if( (key < 0x20) || (key > 0x7E) )
        {
          rc = RCBREAK;
          break;
        }

        if( FieldType & HEXONLY )
        {
          if( (key < '0') || (key > '9') )
          {
            key &= 0xDF;
            if( (key < 'A') || (key > 'F') )
            {
              keybeep();
              rc = 0;
              break;
            }
          }
        }

        if( FieldType & BINONLY )
        {
          if( (key != '0') && (key != '1') )
          {
            keybeep();
            rc = 0;
            break;
          }
        }


        if( FieldType & CLEAR1ST )                                      /*910*/
        {                                                               /*910*/
         memset(Buffer,'\0',strlen(Buffer) );                           /*910*/
         *cursor = 0;                                                   /*910*/
         CursorCol = (*cursor > displen)?FieldCol : FieldCol + *cursor; /*910*/
        }                                                               /*910*/

        /*********************************************************************/
        /* Scratch gives you the exact number of characters so far typed in  */
        /* by the user. Accept the last character only if scratch is less    */
        /* than the total length of the string.                              */
        /*********************************************************************/
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        if( scratch < length )
        {
          if( IsInsertMode )
          {
            if( (strlen( Buffer ) + 1) > length )
            {
              keybeep();
              rc = 0;
              break;      /* reject */
            }
            else
               ShiftRight( scratch );
          }

          Buffer[scratch] = ( uchar )key;

          /*******************************************************************/
          /* Adjust the cursor position accordingly so that it stays ahead   */
          /* of the last character.                                          */
          /*******************************************************************/
          if( CursorCol >= (FieldCol + FieldDisplayLength) )
          {
            DisplayOffset += (FieldDisplayLength - RightScrollOffset - 1);
            CursorCol = FieldCol + RightScrollOffset + 2;
          }
          else
            CursorCol++;

          /*******************************************************************/
          /* It the type of the field is AUTOEXIT return to the caller once  */
          /* the buffer is full.                                             */
          /*******************************************************************/
          BufLen = strlen( Buffer );
          if( (BufLen == length) &&
              (FieldType & AUTOEXIT) &&
              ((CursorCol - FieldCol) == FieldDisplayLength) )
            rc = RCREDRAW + RCBREAK + RCDATAXT;
          else
            rc = RCREDRAW;
          break;
        }
        else
        {
          keybeep();
          rc = 0;
          break;
        }
      }
    }

    /*************************************************************************/
    /* - Turn off the clear field flag after any event.                      */
    /*************************************************************************/
    FieldType &= ~CLEAR1ST;                                             /*910*/

   if( rc & RCREDRAW )
   {
     DisplayField( DisplayOffset );
     VioShowBuf( (ushort)voff, (ushort)( 2 * FieldDisplayLength ), 0 );
   }
   if( rc & RCBREAK )
     break;
  }                                     /* end of for loop to handle keystrks*/
    VioSetCurType( &HiddenCursor, 0 );

    /*************************************************************************/
    /* - Copy the local buffer to the caller supplied buffer.                */
    /* - Free the local buffer.                                              */
    /* - Reset the keyboard buffer flush flag.                               */
    /*************************************************************************/
    for( n = 0; n < strlen( Buffer ); n++ )
        *pInbuf++ = Buffer[n];

    *pInbuf = 0;
    *cursor = CursorCol;
    Tfree( Buffer );
    ResetFlushBufferFlag();                                             /*820*/
    return( (rc & RCDATAXT) ? DATAKEY : key );
}
UINT GetFormatType( DFILE *dfp )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 uchar *SaveArea;
 int    LeaveLoop;
 static int _iview;

 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get a function name from the user.                                     */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/
 _iview=iview; iview=0;
 *PromptString = '\0';

 Popup.title = GT_Title;
 Popup.instructions = GT_Instructions;
 Popup.help = GETTYPEHELP;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* loop to handle user entry/errors.                                        */
 /****************************************************************************/
 for( LeaveLoop=FALSE; LeaveLoop==FALSE;)
 {
  hp = GT_Instructions;
  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if(  (key == ESC) ||
       ( (key == ENTER) && (strlen(PromptString)==0) )
    )
   LeaveLoop = TRUE;
  else
  {
   switch( key )
   {
    case ENTER:
    case PADENTER:
    {
     UINT    mid4type = 0;
     USHORT  typeno;
     UCHAR  *hp;
     UCHAR   buffer[PROMAX+2];

     memset(buffer, 0, sizeof(buffer));
     strcpy(buffer+2, PromptString);

     *(USHORT*)buffer = (USHORT)strlen(PromptString);

     typeno = QtypeNumber(dfp->mid, buffer, &mid4type );

     if( mid4type != 0 )
      dfp->mid = mid4type;

     if(typeno)
     {
      SetShowType( dfp, (UINT)typeno );
      LeaveLoop = TRUE;
     }
     else
     {
      beep();
      hp = "Incorrect type name";
      fmterr( hp);
     }
    }
    break;

    case ESC:
     LeaveLoop = TRUE;
     break;
   }
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
  iview=_iview;
 return(0);
}
void FindStr( AFILE *fp )
{
 char  *hp;
 uint   key;
 uchar *SaveArea;

 static int _iview;
 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get the string to find from the user.                                  */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/
#if defined(MSH)
 if(commandLine.nparms>1) {
    strcpy(FindString,commandLine.parms[1]);
    if(ScanStr(fp)) {
#if defined(SD386LOG)
        SD386Log(STRINGCODE," ");
        SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
        return;
    }
 }
#endif

 Popup.title = FI_Title;
 Popup.instructions = FI_Instructions;
 Popup.help = FINDSTRHELP;
 Popup.Flags = CLEAR1ST;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* - loop to handle user entry/errors.                                      */
 /*                                                                          */
 /*                                                                          */
 /* NOTE:                                                                    */
 /*   FindString is a static variable that will be saved for repeat finds and*/
 /*   subsequent prompts.                                                    */
 /****************************************************************************/
 for(;;)
 {
  hp = FI_Instructions;
  key = PopPrompt( FindString, hp);

  stripblk(FindString);

  if( key == ESC )
  {
#if 0
    SD386Log(STRINGCODE," ");
    SD386Log(KEYCODE|key,"");
#endif
    break;
  }
  else if ( key == ENTER )
  {
   if( strlen(FindString) == 0 )
    continue;

   if( ScanStr(fp) )
   {
#if 0
    SD386Log(STRINGCODE," ");
    SD386Log(KEYCODE|key,"");
#endif
    break;
   }

   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
   beep();
   hp = CantFind;
   fmterr( hp);
   continue;
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
 iview=_iview;
}
 void
BrowseFile( )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 uchar *SaveArea;


 static int _iview;
 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get the file to browse from the user.                                  */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/

#if defined(MSH)
 if(commandLine.nparms>1)
 {
   uchar    *fnfull;                    /* fully qualified filespec.         */
   int       fnlen, rc;                 /* filename/filespec buffer length.  */
   fnlen = CCHMAXPATH;
   fnfull = Talloc( fnlen );
   rc = FindExe( commandLine.parms[1], fnfull+1 , fnlen );
   if(!rc) {
       if( !browse(commandLine.parms[1], 0) ) {
#if defined(SD386LOG)
         SD386Log(STRINGCODE," ");
         SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
         return;
       }
    }
 }
#endif

 _iview=iview; iview=0;
 *PromptString = '\0';

 Popup.title = BR_Title;
 Popup.instructions = BR_Instructions;
 Popup.help = BROWSEHELP;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* - loop to handle user entry/errors.                                      */
 /****************************************************************************/
 for(;;)
 {
  hp = BR_Instructions;
  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if( key == ESC )
  {
#if 0
   SD386Log(STRINGCODE," ");
   SD386Log(KEYCODE|key,"");
#endif
   break;
  }

  else if ( key == ENTER )
  {
   uchar    *fnfull;                    /* fully qualified filespec.         */
   int       fnlen, rc;                 /* filename/filespec buffer length.  */

   if( strlen(PromptString) == 0 )
    continue;

   if( strpbrk( PromptString, "*?" ) )                                  /*802*/
   {                                                                    /*802*/
     hp = CantFind;                                                     /*802*/
     fmterr( hp );                                                      /*802*/
     beep();                                                            /*802*/
     continue;                                                          /*802*/
   }                                                                    /*802*/

   fnlen = CCHMAXPATH;
   fnfull = Talloc( fnlen );
   rc = FindExe( PromptString, fnfull+1 , fnlen );
   if( !rc )
   {
    PutPopArea(SaveArea);
    Tfree(SaveArea );
    SaveArea = NULL;
    if( !browse(PromptString, 0) )
    {
#if 0
      SD386Log(STRINGCODE," ");
      SD386Log(STRINGCODE,PromptString);
#endif
      break;
    }
   }

   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
   beep();
   hp = CantFind;
   fmterr( hp);
   continue;
  }
 }
 if( SaveArea != NULL )
 {
  PutPopArea(SaveArea);
  Tfree(SaveArea );
  iview=_iview;
 }
}
void  SetNameOrAddrBkpt( AFILE *fp , uint func )
{
 char   *hp;
 uint    key;
 char    PromptString[MAXPROMPTSTRING];
 uchar  *SaveArea;
 int     DorI;
 int     DefineType;
 char   *pmsg;
 APIRET  rc;
 static int _iview;

#if defined(MSH) && 0
 if(commandLine.nparms>1) {
    msg = SetIDBrk( pnode, commandLine.parms[1], &Brk );                         /*707*/
    if( !msg )
    {
      AFILE *lfp;                                                        /*707*/

      for( lfp = allfps; lfp; lfp = lfp->next )                          /*707*/
        if( lfp->mid == Brk.mid )                                        /*707*/
          MarkLineBRKs( lfp );                                           /*707*/
#if defined(SD386LOG)
      SD386Log(STRINGCODE," ");
      SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
      return;
    }
 }
#endif

 _iview=iview; iview=0;
 *PromptString = '\0';
 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get the file to browse from the user.                                  */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/
 switch( func )
 {
  case SETFUNCTIONBKPT:
   Popup.title        = IF_Title;
   Popup.instructions = IF_Instructions;
   Popup.help         = IDFUNCHELP;
   DorI               = BP_IMMEDIATE;
   DefineType         = BP_FUNC_NAME;
   hp                 = IF_Instructions;
   break;

  case SETADDRESSBKPT:
   Popup.title        = IA_Title;
   Popup.instructions = IA_Instructions;
   Popup.help         = IDADDRHELP;
   DorI               = BP_IMMEDIATE;
   DefineType         = BP_ADDR;
   hp                 = IA_Instructions;

   strcpy( PromptString, "0x" );
   break;

  case SETDEFERREDBKPT:
   Popup.title        = ID_Title;
   Popup.instructions = ID_Instructions;
   Popup.help         = IDDEFRHELP;
   DorI               = BP_DEFR;
   DefineType         = BP_FUNC_NAME;
   hp                 = ID_Instructions;
   break;

  case  SETADDRLOADBKPT:
   Popup.title        = IO_Title;
   Popup.instructions = IO_Instructions;
   Popup.help         = IDLOADHELP;
   DorI               = BP_DEFR;
   DefineType         = BP_LOAD_ADDR;
   hp                 = IO_Instructions;

   strcpy( PromptString, "0x" );
   break;

  case  SETDLLLOADBKPT:
   Popup.title        = IL_Title;
   Popup.instructions = IL_Instructions;
   Popup.help         = IDDLLHELP;
   DorI               = BP_DEFR;
   DefineType         = BP_DLL_LOAD;
   hp                 = IL_Instructions;
   break;
 }

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* - loop to handle user entry/errors.                                      */
 /****************************************************************************/
 for(;;)
 {

  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if( key == ESC )
  {
#if 0
   SD386Log(STRINGCODE," ");
   SD386Log(KEYCODE|key,"");
#endif
   break;
  }
  else if ( key == ENTER )
  {
   if( strlen(PromptString) == 0 )
    continue;

   pmsg = NULL;
   rc = SetIDBrk( PromptString, DorI, DefineType, &pmsg );

   if( rc )
   {
    beep();
    hp = pmsg;
    fmterr( pmsg );
    continue;

#if 0
     AFILE *lfp;                                                        /*707*/
     SD386Log(STRINGCODE," ");
     SD386Log(STRINGCODE,PromptString);

     for( lfp = allfps; lfp; lfp = lfp->next )                          /*707*/
       if( lfp->mid == Brk.mid )                                        /*707*/
         MarkLineBRKs( lfp );                                           /*707*/
#endif
   }
   break;
   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
  iview=_iview;
}
 void
SetCondBrk( AFILE *fp, uint SrcLnNumOfCsr, uchar *pSrcLnInBuf )
{
 char  *hp;
 uint   key;
 char   PromptString[MAXPROMPTSTRING];
 char  *msg;
 uchar  SrcLnFlag;
 BRK   *pBrk;
 uchar *SaveArea;
 static int _iview;

#if defined(MSH)
 if(commandLine.nparms>1) {
    msg = SetLineBRK( fp,SrcLnNumOfCsr,pSrcLnInBuf,BRK_COND,commandLine.parms[1]);
#if defined(SD386LOG)
    SD386Log(STRINGCODE," ");
    SD386Log(STRINGCODE,commandLine.parms[1]);
#endif
 }
#endif

 _iview=iview; iview=0;
 *PromptString = '\0';
 /***************************************************************************/
 /* If there is a conditional bp already on this line, then we need to      */
 /* initialize the PromptString to the last prompt.                         */
 /***************************************************************************/
 SrcLnFlag = *(pSrcLnInBuf-1);
 if( (SrcLnFlag & LINE_BP) &&
     (pBrk=IsBrk(fp , SrcLnNumOfCsr) ) &&
      pBrk->cond )
  strcpy(PromptString, pBrk->cond->pCondition);

 /****************************************************************************/
 /* - put the title, instructions, and help appropriate for this popup       */
 /*   into the popup structure.                                              */
 /* - save the screen area used by the popup if CUA interface.               */
 /* - get the file to browse from the user.                                  */
 /* - handle user string and keys.                                           */
 /* - handle errors.                                                         */
 /* - restore the screen save area if CUA interface.                         */
 /*                                                                          */
 /****************************************************************************/
 Popup.title = CB_Title;
 Popup.instructions = CB_Instructions;
 Popup.help = CONDBPHELP;

 SaveArea = (uchar *)Talloc(Popup.length * Popup.width * 2);
 GetPopArea(SaveArea);
 DisplayPop( &Popup );

 /****************************************************************************/
 /* - loop to handle user entry/errors.                                      */
 /****************************************************************************/
 for(;;)
 {
  hp = CB_Instructions;
  key = PopPrompt( PromptString, hp);

  stripblk(PromptString);

  if( key == ESC )
  {
#if 0
   SD386Log(STRINGCODE," ");
   SD386Log(KEYCODE|key,"");
#endif
   break;
  }
  else if ( key == ENTER )
  {
   if( strlen(PromptString) == 0 )
    continue;

   msg = SetLineBRK( fp,SrcLnNumOfCsr,pSrcLnInBuf,BRK_COND,PromptString);
   if( !msg )
   {
#if 0
     SD386Log(STRINGCODE," ");
     SD386Log(STRINGCODE,PromptString);
#endif
    break;
   }

   /**************************************************************************/
   /* display an error message and then ask for another name.                */
   /**************************************************************************/
   beep();
   hp = msg;
   fmterr( msg );
   continue;
  }
 }

 PutPopArea(SaveArea);
 Tfree(SaveArea );
  iview=_iview;
}