예제 #1
0
int main(int argc, char * argv[]) {

  Tinit();
  ReferentialAlgebra_init();

  recordid rootEntry;
  recordid hash;
  int xid = Tbegin();
  if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) {
    printf("Creating new store\n");

    rootEntry = Talloc(xid, sizeof(recordid));
    assert(rootEntry.page == ROOT_RECORD.page);
    assert(rootEntry.slot == ROOT_RECORD.slot);

    hash = ReferentialAlgebra_allocContext(xid);

    Tset(xid, rootEntry, &hash);

  } else {
    printf("Opened existing store\n");
    rootEntry.page = ROOT_RECORD.page;
    rootEntry.slot = ROOT_RECORD.slot;
    rootEntry.size = sizeof(recordid);

    Tread(xid, rootEntry, &hash);

  }

  context = ReferentialAlgebra_openContext(xid,hash);

  Tcommit(xid);

  FILE * in;
  if(argc == 3) { // listen on socket
    if(strcmp("--socket", argv[1])) {
      printf("usage:\n\n%s\n%s <filename>\n%s --socket addr:port\n",
	     argv[0],argv[0],argv[0]);
    } else {
      startServer(argv[2], hash);
    }

    printf("Shutting down...\n");
  } else {
    if(argc == 2) {
      in = fopen(argv[1], "r");
      if(!in) {
	printf("Couldn't open input file.\n");
	return 1;
      }
    } else {
      in = stdin;
    }
    openInterpreter(in, stdout, hash);
  }
  Tdeinit();
}
예제 #2
0
recordid TlinkedListCreate(int xid, int keySize, int valueSize) {
  recordid ret;

  ret = Talloc(xid, sizeof(stasis_linkedList_entry) + keySize + valueSize);
  byte * cleared = stasis_calloc(sizeof(stasis_linkedList_entry) + keySize + valueSize, byte);
  Tset(xid, ret, cleared);
  free(cleared);

  return ret;
}
BRK *XSrvDefBrk( ULONG where )
{
 BRK *p;

 p = (BRK *)Talloc(sizeof(BRK));
 p->brkat = where;
 p->byte = BREAKPT8086OPCODE;
 p->next = pAllBrks;
 pAllBrks = p ;
 return(p);
}
예제 #4
0
void * init_pointer_stack(int size)
{
	POINTER_STACK * stack;
	BYTE * buffer;
	buffer=Talloc(sizeof(POINTER_STACK)+sizeof(void *)*size);
	if(buffer==NULL)
		return NULL;
	stack=(POINTER_STACK *)buffer;
	stack->top=(void **)(buffer+sizeof(POINTER_STACK));
	stack->curr=stack->top;
	stack->size=size;
	return stack;
}
예제 #5
0
int
sisy_midi_alsa_init(sisy_t *sisy, char *midi_device)
{
    sisy->nb_tracks=1;
    ck_err(!(sisy->tracks=Talloc(sisy_track_t)));
    dbg(DBG_MIDI, "sisy_midi_alsa_init\n");
    ck_err (!(sisy->tracks->midi.midi=midi_alsa_create (midi_device, MIDI_FLAG_GET)));
    ck_err (sisy_track_init(sisy->tracks) < 0);

    return 0;
  error:
    return -1;
}
예제 #6
0
void * init_pointer_queue(int size)
{
	POINTER_QUEUE * queue;
	BYTE * buffer;
	buffer=Talloc(sizeof(POINTER_QUEUE)+sizeof(void *)*size);
	if(buffer==NULL)
		return NULL;
	queue=(POINTER_QUEUE *)buffer;
	Memset(queue,0,sizeof(POINTER_QUEUE)+sizeof(void *)*size);
	queue->buffer=(void **)(buffer+sizeof(POINTER_QUEUE));
	queue->size=size;
	queue->head=-1;
	return queue;
}
예제 #7
0
void * Palloc(int size,void * base)
{
	switch(	alloc_pointer_type(base))
	{
		case ALLOC_TEMP:
			return Talloc(size);
		case ALLOC_STATIC:
			return Salloc(size);
		case ALLOC_DYNAMIC:
			return Dalloc(size,base);
		case ALLOC_CACHE:
			return Calloc(size);
		default:
			return NULL;
	}	
}
예제 #8
0
int test(void) {
	struct timeval start, end, total;
	recordid rids[TESTS];
	long commited[TESTS];
	long aborted[TESTS];
	long temp;
	int i, j, xid = Tbegin();

	for( i = 0; i < TESTS; i++ ) {
		rids[i] = Talloc(xid, sizeof(long));
		commited[i] = random();
		aborted[i] = random();
		Tset(xid, rids[i], &commited[i]);
	}

	gettimeofday(&start, NULL);
	Tcommit(xid);
	gettimeofday(&end, NULL);
	timersub(&end, &start, &total);
	printf("commit %u: %ld.%ld\n", TESTS, total.tv_sec, total.tv_usec);

	for( j = 0; j < 10; j++ ) {

		xid = Tbegin();

		for( i = 0; i < TESTS*j; i++ ) {
			Tset(xid, rids[random() % TESTS], &aborted[i%TESTS]);
		}

		gettimeofday(&start, NULL);
		Tabort(xid);
		gettimeofday(&end, NULL);
		timersub(&end, &start, &total);
		printf("abort %u: %ld.%ld\n", TESTS*j, total.tv_sec, total.tv_usec);

		xid = Tbegin();
		for( i = 0; i < TESTS; i++ ) {
			Tread( xid, rids[i], &temp );
			if( temp != commited[i] )
				return -1;
		}
		Tabort(xid);
	}

	return 0;
}
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);
}
예제 #10
0
파일: bLSM.cpp 프로젝트: Bathtor/bLSM
recordid bLSM::allocTable(int xid)
{
    table_rec = Talloc(xid, sizeof(tbl_header));
    mergeStats * stats = 0;
    //create the big tree
    tree_c2 = new diskTreeComponent(xid, internal_region_size, datapage_region_size, datapage_size, stats, 10);

    //create the small tree
    tree_c1 = new diskTreeComponent(xid, internal_region_size, datapage_region_size, datapage_size, stats, 10);

    merge_mgr = new mergeManager(this);
    merge_mgr->set_c0_size(max_c0_size);
    merge_mgr->new_merge(0);

    tree_c0 = new memTreeComponent::rbtree_t;
    tbl_header.merge_manager = merge_mgr->talloc(xid);
    tbl_header.log_trunc = 0;
    update_persistent_header(xid);

    return table_rec;
}
예제 #11
0
파일: test1.c 프로젝트: baskard/stasis
int test(int argc, char **argv) {
	int xid;
	int writeVals[NUM_TRIALS];
	int readVals[NUM_TRIALS];
	recordid recs[NUM_TRIALS];

	int i;
	int failed = 0;

	printf("\nRunning %s\n", __FILE__);

	xid = Tbegin();

	for (i = 0; i < NUM_TRIALS; i++) {
		writeVals[i] = rand();

		recs[i] = Talloc(xid, sizeof(int));

		Tset(xid, recs[i], &writeVals[i]);
	}

	Tcommit(xid);
	xid = Tbegin();

	for (i = 0; i < NUM_TRIALS; i++) {
		Tread(xid, recs[i], &readVals[i]);

		if (VERBOSE) 
			printf("value set is %d, value read is %d\n", writeVals[i], readVals[i]); 

		if (writeVals[i] != readVals[i]) 
			failed = 1;
	}

	Tcommit(xid);

	printf("%s\n\n", failed ? "****FAILED****" : "PASSED");

	return failed;
}
    AFILE *
fakefp(uint base,uint span,DEBFILE *pdf)
{
    uint n, mlen;
    uchar modname[CCHMAXPATH];
    AFILE *fp;

    strcpy(modname,pdf->DebFilePtr->fn);

    mlen = sprintf( modname, "Code Segment %04X (%04X thru %04X)",
            SelOf(base), OffOf(base), OffOf(base) + (uint)span - 1 );
    n = SizeOfAFILE(mlen);
    fp = (AFILE *) Talloc(n);
    fp->pdf = pdf;
    fp->mseg = base;
    fp->topoff=base;                  /* off of base for top disasm disp     */
    fp->mid = FAKEMID;
    fp->shower = showA;
    memcpy( fp->filename + 1, modname,
           (fp->filename[0] = ( uchar )mlen) + 1 );

    return( fp );
}
예제 #13
0
static void stasis_linked_list_insert_helper(int xid, recordid list, const byte * key, int keySize, const byte * value, int valueSize) {
  stasis_linkedList_entry * entry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize);

  Tread(xid, list, entry);
  if(!entry->next.size) {
    memcpy(entry+1, key, keySize);
    memcpy(((byte*)(entry+1))+keySize, value, valueSize);
    entry->next.page = 0;
    entry->next.slot = 0;
    entry->next.size = -1;
    Tset(xid, list, entry);
  } else {
    stasis_linkedList_entry * newEntry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize);
    memcpy(newEntry + 1, key, keySize);
    memcpy(((byte*)(newEntry+1))+keySize, value, valueSize);
    newEntry->next = entry->next;
    recordid newRid = Talloc(xid, sizeof(stasis_linkedList_entry) + keySize + valueSize);
    Tset(xid, newRid, newEntry);
    entry->next = newRid;
    Tset(xid, list, entry);
    free(newEntry);
  }
  free(entry);
}
 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;
}
void ParseEspChildOptions( int          argc,
                           char       **argv,
                           ESP_PARMS    *pEspParms,
                           CONNECTION  *pConnection)
{
 char          ParmString[512];
 int           i;
 char         *pOption;
 char         *cp;
 int           len;


 /****************************************************************************/
 /* - set any default options.                                               */
 /****************************************************************************/
 pConnection->DbgOrEsp = _ESP;

 pEspParms->EspFlags.IsParentEsp    = FALSE;

 /****************************************************************************/
 /* - Build a string of tokens delimited by a single blank.                  */
 /****************************************************************************/
 ParmString[0] = '\0';
 for( i=1 ; i<argc; i++)
 {
  strcat(ParmString,argv[i]);
  strcat(ParmString," ");
 }
 strcat(ParmString,"\0");

 /****************************************************************************/
 /* - Scan the parm block and pull off the options and program name.         */
 /****************************************************************************/
 pOption = strtok(ParmString," ");
 do
 {
  printf("\n%s", pOption);fflush(0);
  switch( *pOption )
  {
   case '/':
    switch( tolower(*(pOption + 1)) )
    {
     case 'a':
      /***********************************************************************/
      /* - Parse the com port.                                               */
      /***********************************************************************/
      pConnection->ComPort = EspParseComPort( *(pOption+2) );
      break;

     case 'r':
      pConnection->ConnectType    = ASYNC;
      break;

     case '+': /* Joe's private option */
      pEspParms->EspFlags.Verbose = TRUE;
      break;

     case 'n':
      /***********************************************************************/
      /* - connect using netbios.                                            */
      /* - get the logical adapter name.                                     */
      /***********************************************************************/
      pConnection->ConnectType    = _NETBIOS;
      len = strlen(pOption+2);
      if( len != 0 )
      {
       if( len > ( MAX_LSN_NAME - LSN_RES_NAME ) )
        len = MAX_LSN_NAME - LSN_RES_NAME;
       cp = Talloc(len + 1);
       strncpy( cp, pOption+2, len );
       pConnection->pLsnName = cp;
      }
      break;                                                            /*919*/

     case 't':
     {
      /***********************************************************************/
      /* - connect using sockets.                                            */
      /***********************************************************************/
      pConnection->ConnectType = SOCKET;
      len = strlen(pOption+2);
      cp  = Talloc(len + 1);

      strncpy( cp, pOption+2, len );

      pConnection->pLsnName = cp;
     }
     break;

     case 'c':
      /***********************************************************************/
      /* - handle the /child= option which MUST be argv[1];                  */
      /***********************************************************************/
      break;


     case 'b':
      /***********************************************************************/
      /* - This option tells the probe that child processes are going to     */
      /*   be debugged. It should only show up when esp is spawned           */
      /*   internally when specifying the /b option on the sd386             */
      /*   invocation line. Note that esp does not have an explicit          */
      /*   /b invocation option.                                             */
      /***********************************************************************/
      pConnection->ConnectType = LOCAL_PIPE;
      break;

     case 's':
      /***********************************************************************/
      /* - Set the shared heap memory handle.                                */
      /***********************************************************************/
      if( strstr( pOption+1, "shr" ) )
      {
       ULONG *pshrmem;

       pshrmem = (ULONG*)atol( strchr( pOption+1, '=' ) + 1 );
       SetShrMem( pshrmem );
      }
      break;

     case 'h':
      /***********************************************************************/
      /* - Set the start address of the shared heap.                         */
      /***********************************************************************/
      if( strstr( pOption+1, "heap" ) )
      {
       ULONG *heap;

       heap = (ULONG*)atol( strchr( pOption+1, '=' ) + 1 );
       SetShrHeap( heap );
      }
      else if( strstr( pOption+1, "handle" ) )
      {
       pEspParms->handle = (LHANDLE)atol( strchr( pOption+1, '=' ) + 1 );
      }
      break;

     case 'd':
     {
      int descriptor;
      /***********************************************************************/
      /* - Get the base socket descriptor if using sockets.                  */
      /***********************************************************************/
      descriptor = (int)atol( strchr( pOption+1, '=' ) + 1 );
      SockSetDescriptor(descriptor);
     }
     break;

     case 'q':
      /***********************************************************************/
      /* - Set the queue name for sending messages.                          */
      /***********************************************************************/
      if( strstr( pOption+1, "qname" ) )
      {
       char *pQueName;

       pQueName = strchr( pOption+1, '=' ) + 1 ;
       SetEspQueName( pQueName );
      }
      break;

     /************************************************************************/
     /* - handle invalid "/" option.                                         */
     /************************************************************************/
     default:
      break;

    }
    break;

   default:
    break;
  }
  pOption = strtok(NULL," " );
 }
 while( pOption );
}
void ParseOptions( int          argc,
                   char       **argv,
                   ESP_PARMS    *pEspParms,
                   CONNECTION  *pConnection)
{
 char          ParmString[512];
 char          FileSpec[CCHMAXPATH];
 int           i;
 char         *pOption;
 char         *cp;
 char         *cpo;
 int           len;

 /****************************************************************************/
 /* - If user entered no arguments, go to case help.                         */
 /****************************************************************************/
 if( argc == 1 )
   goto casehelp;

 /****************************************************************************/
 /* - set any default options.                                               */
 /****************************************************************************/
 pConnection->DbgOrEsp = _ESP;

 pEspParms->EspFlags.IsParentEsp    = TRUE;

 /****************************************************************************/
 /* - Build a string of tokens delimited by a single blank.                  */
 /****************************************************************************/
 ParmString[0] = '\0';
 for( i=1 ; i<argc; i++)
 {
  strcat(ParmString,argv[i]);
  strcat(ParmString," ");
 }
 strcat(ParmString,"\0");

 /****************************************************************************/
 /* - Scan the parm block and pull off the options and program name.         */
 /****************************************************************************/
 pOption = strtok(ParmString," ");
 do
 {
  switch( *pOption )
  {
   case '/':
    switch( tolower(*(pOption + 1)) )
    {
 casehelp:
     /************************************************************************/
     /* - handle the help options.                                           */
     /************************************************************************/
     case 'h':
     case '?':
      SayMsg(HELP_INVOCATION_ESP);
      break;

     case 'a':
      /***********************************************************************/
      /* - Parse the com port.                                               */
      /***********************************************************************/
      pConnection->ComPort = EspParseComPort( *(pOption+2) );
      break;

     case 'r':
     pConnection->ConnectType = ASYNC;
     {
     /************************************************************************/
     /* - parse off the speed option.                                        */
     /************************************************************************/
      switch( *(pOption + 2) )
      {
       case '0':
        pConnection->BitRate = 300;
        break;

       case '1':
        pConnection->BitRate = 1200;
        break;

       case '2':
        pConnection->BitRate = 2400;
        break;

       case '3':
        pConnection->BitRate = 4800;
        break;

       case '4':
        pConnection->BitRate = 9600;
        break;

       case '5':
        pConnection->BitRate = 19200;
        break;

       case '6':
        pConnection->BitRate = 38400;
        break;

       default:
        /*********************************************************************/
        /* - assume online and already connected.                            */
        /*********************************************************************/
        pConnection->BitRate = 0;
        break;
      }
     }
     break;

caseo:
     case 'o':
      pConnection->modem = TRUE;
      /***********************************************************************/
      /* - Pull off the program name.                                        */
      /***********************************************************************/
      cpo = pOption + 2;
      if( strlen(cpo) != 0 )
      {
       for( cp=FileSpec; (*cpo != ' ') && (*cpo != 0); )
        *cp++ = toupper(*cpo++);
       *cp = '\0';
       pConnection->pModemFile = Talloc(strlen(FileSpec)+1);
       strcpy(pConnection->pModemFile,FileSpec);
      }
      break;

     case '+': /* Joe's private option */
      pEspParms->EspFlags.Verbose = TRUE;
      break;

     case '!':
      pEspParms->EspFlags.UseDebug  = TRUE;
      break;

     case 'n':
      /***********************************************************************/
      /* - connect using netbios.                                            */
      /* - get the logical adapter name.                                     */
      /***********************************************************************/
      pConnection->ConnectType = _NETBIOS;
      len = strlen(pOption+2);
      if( len != 0 )
      {
       if( len > ( MAX_LSN_NAME - LSN_RES_NAME ) )
        len = MAX_LSN_NAME - LSN_RES_NAME;
       cp = Talloc(len + 1);
       strncpy( cp, pOption+2, len );
       pConnection->pLsnName = cp;
      }
      break;

     case 't':
     {
      /***********************************************************************/
      /* - connect using sockets.                                            */
      /***********************************************************************/
      pConnection->ConnectType = SOCKET;
      len = strlen(pOption+2);
      cp  = Talloc(len + 1);

      strncpy( cp, pOption+2, len );

      pConnection->pLsnName = cp;
     }
     break;

     case 'b':
      /***********************************************************************/
      /* - This option tells the probe that child processes are going to     */
      /*   be debugged. It should only show up in the call to parse          */
      /*   invocation options when the "parent" probe is spawned by the      */
      /*   debugger which only happens when debugging child(multiple)        */
      /*   processes on a single machine using local pipes.                  */
      /***********************************************************************/
      pConnection->ConnectType = LOCAL_PIPE;
      break;


     /************************************************************************/
     /* - handle invalid "/" option.                                         */
     /************************************************************************/
     default:
      printf("\n Invalid Option");
       goto casehelp;


    }
    break;

   default:
    printf("\n Invalid Option");
    goto casehelp;
  }
  pOption = strtok(NULL," " );
 }
 while( pOption );
}
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;
}
uint Cua_ActiveProcsMenu( AFILE **fpp )                                 /*701*/
{                                                                       /*701*/
  int     i, rc, MaxSymLen, SymLen, LongSymLen;                    /*811  701*/
  uint    key;                                                          /*701*/
  uchar   *cp, *buf, *SaveBuffer = NULL;                                /*701*/
  DEBFILE *pdf;                                                         /*701*/
  DIALOGCHOICE  *chptr;                                                 /*701*/
  CALLSTACKPARAM ClstkParam;                                            /*701*/
  int     buflen;
  int     ScrollBar;                                                    /*701*/

  for( ;; )                                                             /*701*/
  {                                                                     /*701*/
    chptr = &Dia_Clstk_Choices;                                         /*701*/

    MaxSymLen = VideoCols - 6;                                          /*811*/
    buflen = ( (NActFrames + 1)*(MaxSymLen+2) ) + 1 ;
    cp = buf = Talloc( buflen);                                    /*811  701*/

    LongSymLen = 0;                                                     /*811*/
    SymLen    = 0;                                                      /*811*/
    for( i = (short)NActFrames; --i >= 0;  )                            /*701*/
    {                                                                   /*701*/
     pdf = FindExeOrDllWithAddr( ActFaddrs[i] );                        /*701*/
     if(pdf != NULL )
      FormatProcName( cp, ActFaddrs[i], ActScopes[i], pdf,              /*824*/
                               ActCSAtrs[i], MaxSymLen);                /*824*/
     else
      sprintf(cp,"%08X Invalid Frame Address",ActFaddrs[i]);

     SymLen = strlen(cp);                                               /*824*/
     if( SymLen > MaxSymLen )                                           /*824*/
     {                                                                  /*824*/
      SymLen = MaxSymLen;                                               /*824*/
      cp[SymLen] = '\0';                                                /*824*/
     }                                                                  /*824*/
     if( SymLen > LongSymLen )                                          /*824*/
      LongSymLen = SymLen;                                              /*824*/
     cp += SymLen + 1;                                                  /*824*/
    }                                                                   /*824*/
    /* 906 if terminating check was removed */                          /*701*/
    {                                                                   /*824*/

     pdf = FindExeOrDllWithAddr( GetExecAddr() );                       /*901*/
     if( pdf != NULL )
      FormatProcName( cp, GetExecAddr(), ExecScope, pdf,                /*901*/
                           AppPTB.CSAtr, MaxSymLen);                    /*824*/
     else
      sprintf(cp,"%08X Invalid Frame Address",GetExecAddr() );
     SymLen = strlen(cp);                                               /*824*/
     if( SymLen > MaxSymLen )                                           /*824*/
     {                                                                  /*824*/
      SymLen = MaxSymLen;                                               /*824*/
      cp[SymLen] = '\0';                                                /*824*/
     }                                                                  /*824*/
     if( SymLen > LongSymLen )                                          /*824*/
      LongSymLen = SymLen;                                              /*824*/
    }                                                                   /*824*/

    chptr->entries = NActFrames + 1;
    chptr->labels  = buf;

    if( chptr->entries > 10 )
    {
      chptr->MaxRows = 10;
      Dia_Clstk.length = chptr->MaxRows + 8;
      ScrollBar = TRUE;
    }
    else
    {
      Dia_Clstk.length = chptr->entries + 8;
      chptr->MaxRows = chptr->entries;
      ScrollBar = FALSE;
    }

    /*************************************************************************/
    /* At this point, LongSymLen <= MaxSymLen.                               */
    /*************************************************************************/
    Dia_Clstk.width = LongSymLen + 6;
    if( Dia_Clstk.width < 36 )
      Dia_Clstk.width = 36;
    Dia_Clstk.row = (VideoRows - Dia_Clstk.length) / 2;
    Dia_Clstk.col = (VideoCols - Dia_Clstk.width) / 2;
    Dia_Clstk.Buttons[0].row = Dia_Clstk.row + chptr->MaxRows + 4;
    Dia_Clstk.Buttons[0].col = Dia_Clstk.col + 5;
    Dia_Clstk.Buttons[1].row = Dia_Clstk.row + chptr->MaxRows + 4;
    Dia_Clstk.Buttons[1].col = Dia_Clstk.col + Dia_Clstk.width - 16;
    Dia_Clstk.Buttons[2].row = Dia_Clstk.row + chptr->MaxRows + 5;
    Dia_Clstk.Buttons[2].col = Dia_Clstk.col + 5;
    Dia_Clstk.Buttons[3].row = Dia_Clstk.row + chptr->MaxRows + 5;
    Dia_Clstk.Buttons[3].col = Dia_Clstk.col + Dia_Clstk.width - 16;
    Dia_Clstk.Buttons[4].row = Dia_Clstk.row + chptr->MaxRows + 6;
    Dia_Clstk.Buttons[4].col = Dia_Clstk.col + 5;
    Dia_Clstk.Buttons[5].row = Dia_Clstk.row + chptr->MaxRows + 6;
    Dia_Clstk.Buttons[5].col = Dia_Clstk.col + Dia_Clstk.width - 16;

    if( SaveBuffer )
    {
      RemoveMsgBox( "Unwinding...", SaveBuffer );
      SaveBuffer = NULL;
    }
    DisplayDialog( &Dia_Clstk, ScrollBar );
    rc = 0;
    ClstkParam.rc = &rc;
    ClstkParam.fpp= fpp;
    key = ProcessDialog( &Dia_Clstk, &Dia_Clstk_Choices, ScrollBar,
                         (void *)&ClstkParam );
    RemoveDialog( &Dia_Clstk );

    if( rc != RECIRCULATE )
      return( key );
    else
    {
      SaveBuffer = SayMsgBox4( "Unwinding..." );
      if( key == key_a || key == key_A )
      {
        SetShowAll( TRUE );
        SetActFrames();
        SetShowAll( FALSE );
      }
      else
      {
        SetActFrames();
      }
    }
  }
}
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;
}
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 );
}
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 VioInit( )
{
 APIRET      rc;
 UCHAR     **cpp;
 UINT        vlen;
 UINT        row;
 VIOMODEINFO md;

 memset(&md, 0, sizeof(md) );
 md.cb = sizeof(md);

 if( VioGetMode(&md, 0) )
 {
  printf( "Vio error" );
  exit(0);
 }

 VideoRows = md.row;
 VideoCols = md.col;
 MaxPer    = VideoRows - 2 ;            /* max # of lines of Code            */
 MaxData   = VideoRows * 2 / 3;         /* max # of rows for data window     */
 MinPer    = MaxPer - MaxData;          /* min # of lines of Code            */
 ProRow    = VideoRows - 3;             /* screen row for prompt (0..N)      */
 MenuRow   = VideoRows - 3;             /* screen row for menu bar (0..N)    */
 FnameRow  = VideoRows - 2;             /* screen row for file name (0..N)   */
 HelpRow   = VideoRows - 1;             /* screen row for menu help (0..N)   */
 MsgRow    = VideoRows - 1;             /* screen row for messages (0..N)    */
 LinesPer  = MaxPer - TopLine;          /* current # of lines per screen     */
                                        /* for source                        */
 VideoMap  = vaColor;

 if( md.color == 1 )
  VideoMap = vaMono;


    rc = VioGetBuf((PULONG)&VideoPtr, (PUSHORT)&vlen, 0);
    if( rc != 0 ){
        printf( "VioGetBuf() returned %d\n", rc );
        panic(OOquit);
    }
    if( ! HiddenCursor.attr ){
        rc = VioGetCurType(&NormalCursor,0);
        if( rc != 0 ){
            printf( "VioGetCurType() returned %d\n", rc );
            panic(OOquit);  }

        /*********************************************************************/
        /* If the cursor is in insert mode when we enter here then convert   */
        /* the parms of cursorinfo into a normal mode cursor.                */
        /*********************************************************************/
        if ((NormalCursor.cEnd - NormalCursor.yStart) > 2)
          NormalCursor.yStart = NormalCursor.cEnd -
                           ((NormalCursor.cEnd - NormalCursor.yStart - 1) / 4);
        NormalCursor.yStart -= 1;                                       /*112*/
        memcpy( &InsertCursor, &NormalCursor, sizeof(InsertCursor) );   /*100*/
        InsertCursor.yStart = 0;
        memcpy( &HiddenCursor, &NormalCursor, sizeof(HiddenCursor) );   /*100*/
        HiddenCursor.attr = -1;
    }

    /*************************************************************************/
    /* - Allocate memory for screen bounds                                400*/
    /* - set the bounds to the video cols                                 400*/
    /*************************************************************************/
    BoundPtr = Talloc(VideoRows);                                   /*521 518*/
    if (BoundPtr)                                                       /*518*/
       memset(BoundPtr,VideoCols,VideoRows);                            /*518*/
    else                                                                /*518*/
    {                                                                   /*518*/
        printf( "malloc failed\n");                                     /*518*/
        panic(OOquit);                                                  /*518*/
    }                                                                   /*518*/

    VioStartOffSet = 1;
    TopLine = 1;
    MenuRow  = 0;
    LinesPer = MaxPer - TopLine;
    InitDataWinCsr();
    AccessMouse();

    HideCursor();
    ClrScr( 0, VideoRows-1, vaBptOk );
    cpp = banner;
    for( row = BANNER_ROW; *cpp; cpp++,row++ )
    {
     putrc( row, (VideoCols-strlen(*cpp)) / 2, *cpp );
    }
}
 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);
}
예제 #24
0
int proc_key_recover(void * sub_proc,void * recv_msg)
{
	
	int ret;
	DB_RECORD * record;
	struct trust_filecrypt_info * filecrypt_info;
	struct trust_filecrypt_info * decrypt_info;
	struct trust_encdata_info *  encdata_info;
	struct vTPM_wrappedkey * key_struct;
	void * send_msg;
	struct types_pair * types;
	ret=message_get_record(recv_msg,&filecrypt_info,0);
	if(filecrypt_info==NULL)
		return -EINVAL;				
	
	if(!Isemptyuuid(filecrypt_info->encdata_uuid))
	{
		memdb_store(filecrypt_info,DTYPE_TRUST_DEMO,SUBTYPE_FILECRYPT_INFO,NULL);
		send_msg=message_create(DTYPE_MESSAGE,SUBTYPE_TYPES,NULL);
		if(send_msg==NULL)
			return -EINVAL;
		types=Talloc(sizeof(*types));
		if(types==NULL)
			return -EINVAL;
		types->type=DTYPE_TRUST_DEMO;
		types->subtype=SUBTYPE_FILECRYPT_INFO;
		message_add_record(send_msg,types);
		ex_module_sendmsg(sub_proc,send_msg);	
	}	
	else if(!Isemptyuuid(filecrypt_info->cipher_uuid))
	{
		record=memdb_find_first(DTYPE_TRUST_DEMO,SUBTYPE_FILECRYPT_INFO,"cipher_uuid",filecrypt_info->cipher_uuid);
		if(record==NULL)
			return -EINVAL;
		decrypt_info=record->record;

		record=memdb_find_first(DTYPE_TRUST_DEMO,SUBTYPE_ENCDATA_INFO,"uuid",decrypt_info->encdata_uuid);
		if(record==NULL)
			return -EINVAL;
		encdata_info=record->record;

		record=memdb_find_first(DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,"uuid",encdata_info->enckey_uuid);
		if(record==NULL)
			return -EINVAL;
		key_struct=record->record;

//		send_msg=message_create(DTYPE_TRUST_DEMO,SUBTYPE_FILECRYPT_INFO,recv_msg);
//		if(send_msg==NULL)
//			return -EINVAL;
//		message_add_record(send_msg,decrypt_info);
//		ex_module_sendmsg(sub_proc,send_msg);

		send_msg=message_create(DTYPE_TRUST_DEMO,SUBTYPE_ENCDATA_INFO,recv_msg);
		if(send_msg==NULL)
			return -EINVAL;
		message_add_record(send_msg,encdata_info);
		ex_module_sendmsg(sub_proc,send_msg);

		send_msg=message_create(DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,recv_msg);
		if(send_msg==NULL)
			return -EINVAL;
		message_add_record(send_msg,key_struct);
		ex_module_sendmsg(sub_proc,send_msg);
	}

	return 0;
}
예제 #25
0
int proc_key_store(void * sub_proc,void * sock)
{
	int ret=0;
	BYTE uuid[DIGEST_SIZE];
	struct vTPM_wrappedkey    * key_record;	
	struct vTPM_wrappedkey    * pubkey_record;	
	struct trust_demo_keyinfo * keyinfo;
	struct trust_demo_keyinfo * pubkeyinfo;
	void * send_msg;
	void * recv_msg;
	struct types_pair * types;

	// get keyinfo record
	keyinfo= slot_sock_removerecord(sock,DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO);
	if(keyinfo==NULL)
		return -EINVAL;

	// get WEAPPED_KEY message
	recv_msg=slot_sock_removemessage(sock,DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY);
	if(recv_msg==NULL)
		return -EINVAL;

	ret=message_get_record(recv_msg,&key_record,0);
	if(key_record==NULL)
		return -EINVAL;				

	Memcpy(keyinfo->uuid,key_record->uuid,DIGEST_SIZE);
	memdb_store(keyinfo,DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO,NULL);


	//memdb_store(key_record,DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,NULL);
	
	send_msg=message_create(DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,recv_msg);
	if(send_msg==NULL)
		return -EINVAL;
	message_add_record(send_msg,key_record);
	ex_module_sendmsg(sub_proc,send_msg);	

	// get PUBLIC_KEY message
	recv_msg=slot_sock_removemessage(sock,DTYPE_TESI_KEY_STRUCT,SUBTYPE_PUBLIC_KEY);
	if(recv_msg==NULL)
		return -EINVAL;

	ret=message_get_record(recv_msg,&pubkey_record,0);
	if(pubkey_record==NULL)
		return -EINVAL;				


	send_msg=message_create(DTYPE_TESI_KEY_STRUCT,SUBTYPE_PUBLIC_KEY,recv_msg);
	if(send_msg==NULL)
		return -EINVAL;
	message_add_record(send_msg,pubkey_record);
	ex_module_sendmsg(sub_proc,send_msg);	

	

	// build a public key_info struct 
/*
	Memcpy(pubkeyinfo,keyinfo,sizeof(*pubkey_info));
	Memcpy(pubkeyinfo->uuid,pubkey_record->uuid,DIGEST_SIZE);
	keyinfo->ispubkey=1;
	send_msg=message_create(DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO,NULL);
	if(send_msg==NULL)
		return -EINVAL;
	message_add_record(send_msg,keyinfo);
	ex_module_sendmsg(sub_proc,send_msg);	
*/

	send_msg=message_create(DTYPE_MESSAGE,SUBTYPE_TYPES,NULL);
	if(send_msg==NULL)
		return -EINVAL;
	types=Talloc(sizeof(*types));
	if(types==NULL)
		return -EINVAL;
	types->type=DTYPE_TRUST_DEMO;
	types->subtype=SUBTYPE_KEY_INFO;
	message_add_record(send_msg,types);
	types=Talloc(sizeof(*types));
	if(types==NULL)
		return -EINVAL;
	types->type=DTYPE_TESI_KEY_STRUCT;
	types->subtype=SUBTYPE_WRAPPED_KEY;
	message_add_record(send_msg,types);
	types=Talloc(sizeof(*types));
	if(types==NULL)
		return -EINVAL;
	types->type=DTYPE_TESI_KEY_STRUCT;
	types->subtype=SUBTYPE_PUBLIC_KEY;
	message_add_record(send_msg,types);
	types=Talloc(sizeof(*types));
	if(types==NULL)
		return -EINVAL;
	types->type=DTYPE_TRUST_DEMO;
	types->subtype=SUBTYPE_ENCDATA_INFO;
	message_add_record(send_msg,types);
	ex_module_sendmsg(sub_proc,send_msg);	
	return 0;
}
예제 #26
0
파일: test3.c 프로젝트: baskard/stasis
int test(int argc, char **argv) {
  int xids[NUM_TRIALS];
  int initVals[NUM_TRIALS];
  int writeVals[NUM_TRIALS];
  int readVals[NUM_TRIALS];
  int commits[NUM_TRIALS];
  int i;
  recordid recs[NUM_TRIALS];
  int failed = 0;

  printf("\nRunning %s\n", __FILE__);

  for (i = 0; i < NUM_TRIALS; i++) {
    xids[i] = Tbegin();
    initVals[i] = rand();
    recs[i] = Talloc(xids[i], sizeof(int));
    Tset(xids[i], recs[i], &initVals[i]);
    Tcommit(xids[i]);
  }

  

  for (i = 0; i < NUM_TRIALS; i++) {
    xids[i] = Tbegin();
    commits[i] = 0;
    writeVals[i] = rand();
  }

  for (i = 0; i < NUM_TRIALS; i++) {
    Tset(xids[i], recs[i], &writeVals[i]);
  }
  
  for (i = 0; i < NUM_TRIALS; i++) {
    if (rand() % 2) { 
      Tcommit(xids[i]);
      commits[i] = 1;
    } else {
      Tabort(xids[i]);
   }
  }

  for (i = 0; i < NUM_TRIALS; i++) {
      Tread(xids[i], recs[i], &readVals[i]);
  }


  for (i = 0; i < NUM_TRIALS; i++) {
    if (VERBOSE) {
      if (commits[i])
         printf("xid %d commited value %d, and read %d\n", xids[i], writeVals[i], readVals[i]);
      else
         printf("xid %d aborted while setting value %d, and read %d and should've read %d\n", xids[i], writeVals[i], readVals[i], initVals[i]);
          
    }
    
  if (commits[i]) {
     if (writeVals[i] != readVals[i])
        failed = 1;
  } else {
     if (initVals[i] != readVals[i])
        failed = 1;    
  }  
}  
  
  printf("%s\n\n", failed ? "****FAILED****" : "PASSED");

  return failed;
}
 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;
 }
}
예제 #28
0
파일: inc_dec.c 프로젝트: Zhoutall/stasis
int test() {
  int i;
  int xid, writeVal, readVal;
  recordid rec;
  
  printf("\nRunning test1\n");
  

  writeVal = 10;
  
  xid = Tbegin();

  rec = Talloc(xid, sizeof(int));

  Tset(xid, rec, &writeVal);
  Tread(xid, rec, &readVal);
  
  printf("value set is %d, value read is %d\n", writeVal, readVal);
    
  Tcommit(xid);

  xid = Tbegin();
  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tabort(xid);
  printf("aborting\n");
  xid = Tbegin();

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);
  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);
  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  for (i = 0; i < 10; i++) {
    Tdecrement(xid, rec);
    printf("calling Tdecrement\n");
    
    Tread(xid, rec, &readVal);
    printf("value read is %d\n", readVal);
  }

  Tcommit(xid);
  printf("committing\n");
  xid = Tbegin();

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  
  

  printf("\n");
  return 0;

}
예제 #29
0
int test() {
  int xid;
  char *handle_in = "jkit";
  char *name_in = "Jimmy Kittiyachavalit";
  int phone_in = 8821417;
  
  char *handle_out = (char *)malloc(strlen(handle_in)+1);
  char *name_out = (char *)malloc(strlen(name_in)+1);
  int phone_out;
  
  recordid r_name, r_handle, r_phone;
  
  xid = Tbegin();
  
  r_handle = Talloc(xid, strlen(handle_in)+1);
  r_name = Talloc(xid, strlen(name_in)+1);
  r_phone = Talloc(xid, sizeof(int));

  Tset(xid, r_handle, handle_in);
  printf("set handle to [%s]\n", handle_in);
  Tset(xid, r_name, name_in);
  printf("set name to [%s]\n", name_in);
  Tset(xid, r_phone, &phone_in);
  printf("set name to [%d]\n", phone_in);
  
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
    
  
  Tcommit(xid);



  xid = Tbegin();
  handle_in = "tikj";
  name_in = "tilavahcayittik ymmij";
  phone_in = 3142116;
  handle_out = (char *)malloc(strlen(handle_in)+1);
  name_out = (char *)malloc(strlen(name_in)+1);
  phone_out = 0;
  Tset(xid, r_handle, handle_in);
  printf("set handle to [%s]\n", handle_in);
  Tset(xid, r_name, name_in);
  printf("set name to [%s]\n", name_in);
  Tset(xid, r_phone, &phone_in);
  printf("set name to [%d]\n", phone_in);
  
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
  
  printf("aborted the transaction\n");  

  Tabort(xid);

  xid = Tbegin();
  handle_out = (char *)malloc(strlen(handle_in)+1);
  name_out = (char *)malloc(strlen(name_in)+1);
  phone_out = 0;
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
  

  Tcommit(xid);
  
  return 0;
}
예제 #30
0
파일: strings.c 프로젝트: Zhoutall/stasis
int test() {
	int xid;
	int NUM_TRIALS=100;
	recordid rec;

	/* counters */
	int i;
	char c;

	/* used for making the random strings*/
	double r;
	int start, end;

	/* used to make a long string */	
	char first_printable_ascii = ' ';
	char last_printable_ascii = '~';
	int ascii_length = (int)(last_printable_ascii - first_printable_ascii);
	char *ASCII = (char *)malloc(sizeof(char) * ascii_length);

	/* an array of strings */
	char **strings = (char **)malloc(sizeof(char*) * NUM_TRIALS);

	/* output buffer */
	char *out_buffer = (char *)malloc(sizeof(char) * ascii_length);


	srand(SEED);

	/* create the long string from which random strings will be made */
	for (c = 0; c < ascii_length; c++) {
		ASCII[(int)c] = first_printable_ascii + c;
	}

	for (i = 0; i < NUM_TRIALS; i++) {

		r = ((double)rand()/(double)((double)RAND_MAX+1)); /* returns [0, 1)*/
		r = r*ascii_length;
		start = (int)r; /* an int in the rand [0, ascii_length) */
			
		r = ((double)rand()/(double)((double)RAND_MAX+1)); /* returns [0, 1)*/
		r = r*ascii_length;
		end = (int)r; /* an int in the rand [0, ascii_length) */
	
		if (start == end) {
			i--;
			continue;
		}

		if (end < start) {
			int swap = start;
			start = end;
			end = swap;
		}
		

		strings[i] = (char *)malloc(sizeof(char) * (end - start) + 1);
		strncpy(strings[i], ASCII + start, end-start);
		strings[i][end-start-1] = '\0'; /* make the string null terminated */
		
	}

	for (i = 0; i < NUM_TRIALS; i++) {
		xid = Tbegin();
		rec = Talloc(xid, sizeof(char)*(strlen(strings[i]) +1));
		Tset(xid, rec, strings[i]);

		Tread(xid, rec, out_buffer);
			
		if (VERBOSE) {
			printf("xid %d set rid (%d, %d) to [%s], and read [%s]\n", xid, rec.page, rec.slot, strings[i], out_buffer);
		}		
		assert(strcmp(strings[i], out_buffer) == 0); 
		Tcommit(xid);
	}
	
	return 0;
}