示例#1
0
void CSharpFlatCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n";

	out <<
		"   _keys = " << vCS() << "<<1;\n"
		"   _conds = " << CO() << "[" << vCS() << "];\n"
//		"	_keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n"
//		"	_conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n"
		"\n"
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	if (_slen > 0 && " << CK() << "[_keys] <=" 
			<< GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1])\n"
		"		_cond = " << C() << "[_conds+" << GET_WIDE_KEY() << " - " << 
			CK() << "[_keys]];\n"
		"	else\n"
		"		_cond = 0;"
		"\n";
	/*  XXX This version of the code doesn't work because Mono is weird.  Works
	 *  fine in Microsoft's csc, even though the bug report filed claimed it
	 *  didn't.
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	_cond = _slen > 0 && " << CK() << "[_keys] <=" 
			<< GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1] ?\n"
		"		" << C() << "[_conds+" << GET_WIDE_KEY() << " - " << CK() 
			<< "[_keys]] : 0;\n"
		"\n";
		*/
	out <<
		"	switch ( _cond ) {\n";
	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId + 1 << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << "		}\n";
		out << "		break;\n";
	}

	SWITCH_DEFAULT();

	out <<
		"	}\n";
}
示例#2
0
void CSharpTabCodeGen::COND_TRANSLATE()
{
    out <<
        "	_widec = " << GET_KEY() << ";\n"
        "	_klen = " << CL() << "[" << vCS() << "];\n"
        "	_keys = " << CAST(keysType) << " ("<< CO() << "[" << vCS() << "]*2);\n"
        "	if ( _klen > 0 ) {\n"
        "		" << signedKeysType << " _lower = _keys;\n"
        "		" << signedKeysType << " _mid;\n"
        "		" << signedKeysType << " _upper = " << CAST(signedKeysType) <<
        " (_keys + (_klen<<1) - 2);\n"
        "		while (true) {\n"
        "			if ( _upper < _lower )\n"
        "				break;\n"
        "\n"
        "			_mid = " << CAST(signedKeysType) <<
        " (_lower + (((_upper-_lower) >> 1) & ~1));\n"
        "			if ( " << GET_WIDE_KEY() << " < " << CK() << "[_mid] )\n"
        "				_upper = " << CAST(signedKeysType) << " (_mid - 2);\n"
        "			else if ( " << GET_WIDE_KEY() << " > " << CK() << "[_mid+1] )\n"
        "				_lower = " << CAST(signedKeysType) << " (_mid + 2);\n"
        "			else {\n"
        "				switch ( " << C() << "[" << CO() << "[" << vCS() << "]"
        " + ((_mid - _keys)>>1)] ) {\n";

    for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
        GenCondSpace *condSpace = csi;
        out << "	case " << condSpace->condSpaceId << ": {\n";
        out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
            KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
            " - " << KEY(keyOps->minKey) << "));\n";

        for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
            out << TABS(2) << "if ( ";
            CONDITION( out, *csi );
            Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
            out << " ) _widec += " << condValOffset << ";\n";
        }

        out <<
            "		break;\n"
            "	}\n";
    }

    SWITCH_DEFAULT();

    out <<
        "				}\n"
        "				break;\n"
        "			}\n"
        "		}\n"
        "	}\n"
        "\n";
}
示例#3
0
void TabCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n"
		"	_klen = " << CL() << "[" << vCS() << "];\n"
		"	_keys = " << ARR_OFF( CK(), "(" + CO() + "[" + vCS() + "]*2)" ) << ";\n"
		"	if ( _klen > 0 ) {\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
		"		while (1) {\n"
		"			if ( _upper < _lower )\n"
		"				break;\n"
		"\n"
		"			_mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
		"			if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
		"				_upper = _mid - 2;\n"
		"			else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
		"				_lower = _mid + 2;\n"
		"			else {\n"
		"				switch ( " << C() << "[" << CO() << "[" << vCS() << "]"
							" + ((_mid - _keys)>>1)] ) {\n";

	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << 
			"		break;\n"
			"	}\n";
	}

	SWITCH_DEFAULT();

	out << 
		"				}\n"
		"				break;\n"
		"			}\n"
		"		}\n"
		"	}\n"
		"\n";
}
示例#4
0
U64 getHex(void)
{
   char c, str[20];
   int i = 0;
   U64 val;

   printf(": ");
   while ((c = GET_KEY()) != NEWLINE) {
      if (c == BACKSPACE) {
         if (i)
            i--;
         else putchar(' ');
         printf(" \b");
      }
      else if (ishex(c))
         str[i++] = c;
      else Gripe();
      if (i > 16) {
         putchar(7);
         break;
      }
   }
   str[i] = 0;
   val = htoll(str);
   return (val);
}
示例#5
0
void getAnyKey(void)
{
   int c;

   printf(pressAnyKey);
   c = GET_KEY();
}
示例#6
0
void flushKbd(void)
{
   int c;

   while (kbhit())
      c = GET_KEY();
}
示例#7
0
U32 less(U32 position)
{
   int c;

   if (!position)
      printf(lessq);

   while (1) {

      if (position)
         printf("\033[16;18H\033[K Show more? "); /* tools only */

      c = GET_KEY();
      if (c == 'Y' || c == ' ' ||
          c == 'y' || c == '\n') {
          if (!position)
             printf(nl);
          return (YES);
      }
      else if (c == 'q' || c == 'n' ||
               c == 'Q' || c == 'N')
         break;
      else Gripe();
   }

   if (position)
      printf(prompt);

   return (NO);
}
示例#8
0
U32 getDec(void)
{
   char c, str[20];
   int i = 0;
   U32 val;

   printf(": ");
   while ((c = GET_KEY()) != NEWLINE) {
      if (c == BACKSPACE) {
         if (i)
            i--;
         else putchar(' ');
         printf(" \b");
      }
      else if (isdigit(c))
         str[i++] = c;
      else Gripe();
      if (i > 10) {
         putchar(7);
         break;
      }
   }
   str[i] = 0;
   val = atoi(str);
   return (val);
}
示例#9
0
std::wostream &CSharpGotoCodeGen::STATE_GOTOS()
{
	for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
		if ( st == redFsm->errState )
			STATE_GOTO_ERROR();
		else {
			/* Writing code above state gotos. */
			GOTO_HEADER( st );

			if ( st->stateCondVect.length() > 0 ) {
				out << L"	_widec = " << GET_KEY() << L";\n";
				emitCondBSearch( st, 1, 0, st->stateCondVect.length() - 1 );
			}

			/* Try singles. */
			if ( st->outSingle.length() > 0 )
				emitSingleSwitch( st );

			/* Default case is to binary search for the ranges, if that fails then */
			if ( st->outRange.length() > 0 )
				emitRangeBSearch( st, 1, 0, st->outRange.length() - 1 );

			/* Write the default transition. */
			TRANS_GOTO( st->defTrans, 1 ) << L"\n";
		}
	}
	return out;
}
示例#10
0
void getReturn(void)
{
   int c;

   printf(pressReturn);
   while (1) {
      c = GET_KEY();
      if (c == '\n') break;
      Gripe();
   }
}
示例#11
0
文件: find.c 项目: dpt/DPTLib
list_t *list_find(list_t *anchor, size_t keyloc, int key)
{
  list_t *e;

#define GET_KEY(element, offset) (*((int *) ((char *) element + offset)))

  for (e = anchor; e != NULL; e = e->next)
    if (GET_KEY(e, keyloc) == key)
      return e;

  return NULL;
}
示例#12
0
void FlatCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n";

	out <<
		"	_keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n"
		"	_conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n"
		"\n"
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	_cond = _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= _keys[1] ?\n"
		"		_conds[" << GET_WIDE_KEY() << " - _keys[0]] : 0;\n"
		"\n";

	out <<
		"	switch ( _cond ) {\n";
	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId + 1 << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << "		}\n";
		out << "		break;\n";
	}

	SWITCH_DEFAULT();

	out <<
		"	}\n";
}
void Play_UI_Browe(USER* user)
{
	auto p = 1;
	system("cls");
	auto KeyMaX = EntKeyPlay_Perst_CompNewKeys() - 1;
	Play_UI_LookByPage(p);
	char k[15];
	strcpy_s(k, 15, GET_KEY());
	while (strcmp(k, "Esc") != 0)
	{
		if (strcmp(k, "Right") == 0 && p <= KeyMaX / 5)
		{
			Play_UI_LookByPage(++p);
		}
		if (strcmp(k, "Left") == 0 && p > 1)
		{
			Play_UI_LookByPage(--p);
		}
		strcpy_s(k, 15, GET_KEY());
	}
	Play_UI_MgtEntry(user);
}
示例#14
0
void *run_thread(void *tid) {
	int i, id = (int)(long) tid;
	struct timespec start, end;
	int iters = shared.num_iters;

	pthread_barrier_wait(&shared.barrier);

	tracepoint(tl, start_test_thread, id);
	clock_gettime(CLOCK_MONOTONIC, &start);
	for (i = 0; i < iters; i++) {
		int r = rand() % DATA_SIZE_FULL;
		if ((rand() % 100) < 80) {
			cache_get(shared.cache, GET_KEY(r));
		} else {
			cache_put(shared.cache, GET_KEY(r), GET_VAL(r));
		}
	}
	clock_gettime(CLOCK_MONOTONIC, &end);
	tracepoint(tl, end_test_thread, id, ELAPSED_TIME(start, end));

	//~ printf("%d\n", id);
	pthread_exit(NULL);
}
示例#15
0
void CSharpGotoCodeGen::COND_TRANSLATE( GenStateCond *stateCond, int level )
{
	GenCondSpace *condSpace = stateCond->condSpace;
	out << TABS(level) << L"_widec = " << CAST(WIDE_ALPH_TYPE()) << L"(" <<
			KEY(condSpace->baseKey) << L" + (" << GET_KEY() << 
			L" - " << KEY(keyOps->minKey) << L"));\n";

	for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
		out << TABS(level) << L"if ( ";
		CONDITION( out, *csi );
		Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
		out << L" ) _widec += " << condValOffset << L";\n";
	}
}
示例#16
0
/*
 * Prompts the user with str and returns
 * YES or NO
 */
int AskYN(char *str)
{
   int c;

   printf("%s (Y/N) ", str);
   while (1) {
      c = GET_KEY();
      if (c == 'y' || c == 'Y')
         return (YES);
      else if (c == 'n' || c == 'N' || c == NEWLINE)
         break;
      else Gripe();
   }
   return (NO);
}
示例#17
0
void DefaultRenderFrontend::PrintHelpScreens()
{
#ifdef GET_KEY_EXISTS
	char c;
	int n, x, ok;

	Print_Usage(-1);

	for (n = 0; ; )
	{
		BannerPrintf("\n");
		BannerPrintf("[ Press 0 for general help, 1 to %d for help screen. Press 'q' to quit. ]", MAX_HELP_PAGE);

		do
		{
			ok = false;

			GET_KEY(x);

			c = (char)x;

			if((c >= '0') && (c <= '0' + MAX_HELP_PAGE))
			{
				ok = true;

				n = (int)c - (int)'0';
			}
			else if((c == 'q') || (c == 'Q'))
				ok = true;
		}
		while(!ok);

		BannerPrintf("\n");

		if((c == 'q') || (c == 'Q'))
			break;

		Print_Usage(n);
	}

#else
	int n;

	for (n = -1; n <= MAX_HELP_PAGE; n++)
		PrintUsage(n);
#endif
}
示例#18
0
static stm_blk * _lookup(ptst_t *ptst, stm_tx *tx, stm_blk *sb, setkey_t k) {
    stm_blk *pb;
    node_t  *p;

    set_t * s = (set_t*) READ_OBJ(sb);
    pb = GET_ROOT(s);
    while ( pb != NULL ) {
        p = READ_OBJ(pb);
        //assert(GET_KEY(p)+100==GET_VALUE(p));
        int cmp = k - GET_KEY(p);
        if (cmp == 0) {

            return pb;
        }
        pb = (cmp < 0) ? GET_LEFT(p) : GET_RIGHT(p);

    }
    return NULL;
}
示例#19
0
U32 ImpatientWheel(U32 prt)
{
   int c = 0;

   if (kbhit()) {
      c = GET_KEY();
      if (c == ESC) {
         /*
          * Eat all keystrokes, user may have
          * been hammering escape key trying
          * to get out.
          */
         flushKbd();
         sheSaidQuit = YES;
         return (1);
      }
      else Gripe();
   }
   wheel(prt);
   return (0);
}
示例#20
0
/*****************************************************************************
 *
 *					OpenUSBByName
 *
 ****************************************************************************/
status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
{
	unsigned int alias;
	struct libusb_device_handle *dev_handle;
	char infofile[FILENAME_MAX];
#ifndef __APPLE__
	unsigned int device_vendor, device_product;
#endif
	int interface_number = -1;
	int i;
	static int previous_reader_index = -1;
	libusb_device **devs, *dev;
	ssize_t cnt;
	list_t plist, *values, *ifdVendorID, *ifdProductID, *ifdFriendlyName;
	int rv;
	int claim_failed = FALSE;
	int return_value = STATUS_SUCCESS;

	DEBUG_COMM3("Reader index: %X, Device: %s", reader_index, device);

#ifndef __APPLE__
	/* device name specified */
	if (device)
	{
		char *dirname;

		/* format: usb:%04x/%04x, vendor, product */
		if (strncmp("usb:", device, 4) != 0)
		{
			DEBUG_CRITICAL2("device name does not start with \"usb:\": %s",
				device);
			return STATUS_UNSUCCESSFUL;
		}

		if (sscanf(device, "usb:%x/%x", &device_vendor, &device_product) != 2)
		{
			DEBUG_CRITICAL2("device name can't be parsed: %s", device);
			return STATUS_UNSUCCESSFUL;
		}

		/* format usb:%04x/%04x:libudev:%d:%s
		 * with %d set to
		 * 01 (or whatever the interface number is)
		 * and %s set to
		 * /dev/bus/usb/008/004
		 */
		if ((dirname = strstr(device, "libudev:")) != NULL)
		{
			/* convert the interface number */
			interface_number = atoi(dirname + 8 /* "libudev:" */);
			DEBUG_COMM2("interface_number: %d", interface_number);
		}
	}
#endif

	/* is the reader_index already used? */
	if (usbDevice[reader_index].dev_handle != NULL)
	{
		DEBUG_CRITICAL2("USB driver with index %X already in use",
			reader_index);
		return STATUS_UNSUCCESSFUL;
	}

	/* Info.plist full patch filename */
	(void)snprintf(infofile, sizeof(infofile), "%s/%s/Contents/Info.plist",
		PCSCLITE_HP_DROPDIR, BUNDLE);
	DEBUG_INFO2("Using: %s", infofile);

	rv = bundleParse(infofile, &plist);
	if (rv)
		return STATUS_UNSUCCESSFUL;

#define GET_KEY(key, values) \
	rv = LTPBundleFindValueWithKey(&plist, key, &values); \
	if (rv) \
	{ \
		DEBUG_CRITICAL2("Value/Key not defined for " key " in %s", infofile); \
		return_value = STATUS_UNSUCCESSFUL; \
		goto end1; \
	} \
	else \
		DEBUG_INFO2(key ": %s", (char *)list_get_at(values, 0));

	/* general driver info */
	GET_KEY("ifdManufacturerString", values)
	GET_KEY("ifdProductString", values)
	GET_KEY("Copyright", values)

	if (NULL == ctx)
	{
		rv = libusb_init(&ctx);
		if (rv != 0)
		{
			DEBUG_CRITICAL2("libusb_init failed: %d", rv);
			return_value = STATUS_UNSUCCESSFUL;
			goto end1;
		}
	}

	cnt = libusb_get_device_list(ctx, &devs);
	if (cnt < 0)
	{
		DEBUG_CRITICAL("libusb_get_device_list() failed\n");
		return_value = STATUS_UNSUCCESSFUL;
		goto end1;
	}

#define GET_KEYS(key, values) \
	rv = LTPBundleFindValueWithKey(&plist, key, values); \
	if (rv) \
	{ \
		DEBUG_CRITICAL2("Value/Key not defined for " key " in %s", infofile); \
		return_value = STATUS_UNSUCCESSFUL; \
		goto end2; \
	}

	GET_KEYS("ifdVendorID", &ifdVendorID)
	GET_KEYS("ifdProductID", &ifdProductID);
	GET_KEYS("ifdFriendlyName", &ifdFriendlyName)

	/* The 3 lists do not have the same size */
	if  ((list_size(ifdVendorID) != list_size(ifdProductID))
		|| (list_size(ifdVendorID) != list_size(ifdFriendlyName)))
	{
		DEBUG_CRITICAL2("Error parsing %s", infofile);
		return_value = STATUS_UNSUCCESSFUL;
		goto end1;
	}

	/* for any supported reader */
	for (alias=0; alias<list_size(ifdVendorID); alias++)
	{
		unsigned int vendorID, productID;
		char *friendlyName;

		vendorID = strtoul(list_get_at(ifdVendorID, alias), NULL, 0);
		productID = strtoul(list_get_at(ifdProductID, alias), NULL, 0);
		friendlyName = list_get_at(ifdFriendlyName, alias);

#ifndef __APPLE__
		/* the device was specified but is not the one we are trying to find */
		if (device
			&& (vendorID != device_vendor || productID != device_product))
			continue;
#else
		/* Leopard puts the friendlyname in the device argument */
		if (device && strcmp(device, friendlyName))
			continue;
#endif

		/* for every device */
		i = 0;
		while ((dev = devs[i++]) != NULL)
		{
			struct libusb_device_descriptor desc;
			struct libusb_config_descriptor *config_desc;
			uint8_t bus_number = libusb_get_bus_number(dev);
			uint8_t device_address = libusb_get_device_address(dev);

			int r = libusb_get_device_descriptor(dev, &desc);
			if (r < 0)
			{
				DEBUG_INFO3("failed to get device descriptor for %d/%d",
					bus_number, device_address);
				continue;
			}

			if (desc.idVendor == vendorID && desc.idProduct == productID)
			{
				int already_used;
				const struct libusb_interface *usb_interface = NULL;
				int interface;
				int num = 0;
				const unsigned char *device_descriptor;
#if defined(USE_COMPOSITE_AS_MULTISLOT) || defined(__APPLE__)
				int readerID = (vendorID << 16) + productID;
#endif

#ifdef USE_COMPOSITE_AS_MULTISLOT
				static int static_interface = 1;

				/* simulate a composite device as when libudev is used */
				if ((GEMALTOPROXDU == readerID)
					|| (GEMALTOPROXSU == readerID))
				{
						/*
						 * We can't talk to the two CCID interfaces
						 * at the same time (the reader enters a
						 * dead lock). So we simulate a multi slot
						 * reader. By default multi slot readers
						 * can't use the slots at the same time. See
						 * TAG_IFD_SLOT_THREAD_SAFE
						 *
						 * One side effect is that the two readers
						 * are seen by pcscd as one reader so the
						 * interface name is the same for the two.
						 *
	* So we have:
	* 0: Gemalto Prox-DU [Prox-DU Contact_09A00795] (09A00795) 00 00
	* 1: Gemalto Prox-DU [Prox-DU Contact_09A00795] (09A00795) 00 01
	* instead of
	* 0: Gemalto Prox-DU [Prox-DU Contact_09A00795] (09A00795) 00 00
	* 1: Gemalto Prox-DU [Prox-DU Contactless_09A00795] (09A00795) 01 00
						 */

					/* the CCID interfaces are 1 and 2 */
					interface_number = static_interface;
				}
#endif
				/* is it already opened? */
				already_used = FALSE;

				DEBUG_COMM3("Checking device: %d/%d",
					bus_number, device_address);
				for (r=0; r<CCID_DRIVER_MAX_READERS; r++)
				{
					if (usbDevice[r].dev_handle)
					{
						/* same bus, same address */
						if (usbDevice[r].bus_number == bus_number
							&& usbDevice[r].device_address == device_address)
							already_used = TRUE;
					}
				}

				/* this reader is already managed by us */
				if (already_used)
				{
					if ((previous_reader_index != -1)
						&& usbDevice[previous_reader_index].dev_handle
						&& (usbDevice[previous_reader_index].bus_number == bus_number)
						&& (usbDevice[previous_reader_index].device_address == device_address)
						&& usbDevice[previous_reader_index].ccid.bCurrentSlotIndex < usbDevice[previous_reader_index].ccid.bMaxSlotIndex)
					{
						/* we reuse the same device
						 * and the reader is multi-slot */
						usbDevice[reader_index] = usbDevice[previous_reader_index];
						/* the other slots do not have the same data rates */
						if ((GEMCOREPOSPRO == usbDevice[reader_index].ccid.readerID)
							|| (GEMCORESIMPRO == usbDevice[reader_index].ccid.readerID))
						{
							usbDevice[reader_index].ccid.arrayOfSupportedDataRates = SerialCustomDataRates;
							usbDevice[reader_index].ccid.dwMaxDataRate = 125000;
						}

						*usbDevice[reader_index].nb_opened_slots += 1;
						usbDevice[reader_index].ccid.bCurrentSlotIndex++;
						usbDevice[reader_index].ccid.dwSlotStatus =
							IFD_ICC_PRESENT;
						DEBUG_INFO2("Opening slot: %d",
							usbDevice[reader_index].ccid.bCurrentSlotIndex);
						goto end;
					}
					else
					{
						/* if an interface number is given by HAL we
						 * continue with this device. */
						if (-1 == interface_number)
						{
							DEBUG_INFO3("USB device %d/%d already in use."
								" Checking next one.",
								bus_number, device_address);
							continue;
						}
					}
				}

				DEBUG_COMM3("Trying to open USB bus/device: %d/%d",
					bus_number, device_address);

				r = libusb_open(dev, &dev_handle);
				if (r < 0)
				{
					DEBUG_CRITICAL4("Can't libusb_open(%d/%d): %d",
						bus_number, device_address, r);

					continue;
				}

again:
#ifdef __APPLE__
				/* Some early Gemalto Ezio CB+ readers have
				 * bDeviceClass, bDeviceSubClass and bDeviceProtocol set
				 * to 0xFF (proprietary) instead of 0x00.
				 *
				 * So on Mac OS X the reader configuration is not done
				 * by the OS/kernel and we do it ourself.
				 */
				if (GEMALTO_EZIO_CBP == readerID)
				{
					r = libusb_set_configuration(dev_handle, 1);
					if (r < 0)
					{
						(void)libusb_close(dev_handle);
						DEBUG_CRITICAL4("Can't set configuration on %d/%d: %d",
							bus_number, device_address, r);
						continue;
					}
				}
#endif

				r = libusb_get_active_config_descriptor(dev, &config_desc);
				if (r < 0)
				{
					(void)libusb_close(dev_handle);
					DEBUG_CRITICAL4("Can't get config descriptor on %d/%d: %d",
						bus_number, device_address, r);
					continue;
				}

				usb_interface = get_ccid_usb_interface(config_desc, &num);
				if (usb_interface == NULL)
				{
					(void)libusb_close(dev_handle);
					if (0 == num)
						DEBUG_CRITICAL3("Can't find a CCID interface on %d/%d",
							bus_number, device_address);
					interface_number = -1;
					continue;
				}

				device_descriptor = get_ccid_device_descriptor(usb_interface);
				if (NULL == device_descriptor)
				{
					(void)libusb_close(dev_handle);
					DEBUG_CRITICAL3("Unable to find the device descriptor for %d/%d",
						bus_number, device_address);
					return_value = STATUS_UNSUCCESSFUL;
					goto end2;
				}

				interface = usb_interface->altsetting->bInterfaceNumber;
				if (interface_number >= 0 && interface != interface_number)
				{
					/* an interface was specified and it is not the
					 * current one */
					DEBUG_INFO3("Found interface %d but expecting %d",
						interface_number, interface);
					DEBUG_INFO3("Wrong interface for USB device %d/%d."
						" Checking next one.", bus_number, device_address);

					/* check for another CCID interface on the same device */
					num++;

					goto again;
				}

				r = libusb_claim_interface(dev_handle, interface);
				if (r < 0)
				{
					(void)libusb_close(dev_handle);
					DEBUG_CRITICAL4("Can't claim interface %d/%d: %d",
						bus_number, device_address, r);
					claim_failed = TRUE;
					interface_number = -1;
					continue;
				}

				DEBUG_INFO4("Found Vendor/Product: %04X/%04X (%s)",
					desc.idVendor, desc.idProduct, friendlyName);
				DEBUG_INFO3("Using USB bus/device: %d/%d",
					bus_number, device_address);

				/* check for firmware bugs */
				if (ccid_check_firmware(&desc))
				{
					(void)libusb_close(dev_handle);
					return_value = STATUS_UNSUCCESSFUL;
					goto end2;
				}

#ifdef USE_COMPOSITE_AS_MULTISLOT
				/* use the next interface for the next "slot" */
				static_interface++;

				/* reset for a next reader */
				if (static_interface > 2)
					static_interface = 1;
#endif

				/* Get Endpoints values*/
				(void)get_end_points(config_desc, &usbDevice[reader_index], num);

				/* store device information */
				usbDevice[reader_index].dev_handle = dev_handle;
				usbDevice[reader_index].bus_number = bus_number;
				usbDevice[reader_index].device_address = device_address;
				usbDevice[reader_index].interface = interface;
				usbDevice[reader_index].real_nb_opened_slots = 1;
				usbDevice[reader_index].nb_opened_slots = &usbDevice[reader_index].real_nb_opened_slots;
				usbDevice[reader_index].polling_transfer = NULL;

				/* CCID common informations */
				usbDevice[reader_index].ccid.real_bSeq = 0;
				usbDevice[reader_index].ccid.pbSeq = &usbDevice[reader_index].ccid.real_bSeq;
				usbDevice[reader_index].ccid.readerID =
					(desc.idVendor << 16) + desc.idProduct;
				usbDevice[reader_index].ccid.dwFeatures = dw2i(device_descriptor, 40);
				usbDevice[reader_index].ccid.wLcdLayout =
					(device_descriptor[51] << 8) + device_descriptor[50];
				usbDevice[reader_index].ccid.bPINSupport = device_descriptor[52];
				usbDevice[reader_index].ccid.dwMaxCCIDMessageLength = dw2i(device_descriptor, 44);
				usbDevice[reader_index].ccid.dwMaxIFSD = dw2i(device_descriptor, 28);
				usbDevice[reader_index].ccid.dwDefaultClock = dw2i(device_descriptor, 10);
				usbDevice[reader_index].ccid.dwMaxDataRate = dw2i(device_descriptor, 23);
				usbDevice[reader_index].ccid.bMaxSlotIndex = device_descriptor[4];
				usbDevice[reader_index].ccid.bCurrentSlotIndex = 0;
				usbDevice[reader_index].ccid.readTimeout = DEFAULT_COM_READ_TIMEOUT;
				usbDevice[reader_index].ccid.arrayOfSupportedDataRates = get_data_rates(reader_index, config_desc, num);
				usbDevice[reader_index].ccid.bInterfaceProtocol = usb_interface->altsetting->bInterfaceProtocol;
				usbDevice[reader_index].ccid.bNumEndpoints = usb_interface->altsetting->bNumEndpoints;
				usbDevice[reader_index].ccid.dwSlotStatus = IFD_ICC_PRESENT;
				usbDevice[reader_index].ccid.bVoltageSupport = device_descriptor[5];
				usbDevice[reader_index].ccid.sIFD_serial_number = NULL;
				usbDevice[reader_index].ccid.gemalto_firmware_features = NULL;
				if (desc.iSerialNumber)
				{
					unsigned char serial[128];
					int ret;

					ret = libusb_get_string_descriptor_ascii(dev_handle,
							desc.iSerialNumber, serial,
							sizeof(serial));
					if (ret > 0)
						usbDevice[reader_index].ccid.sIFD_serial_number
							= strdup((char *)serial);
				}

				usbDevice[reader_index].ccid.sIFD_iManufacturer = NULL;
				if (desc.iManufacturer)
				{
					unsigned char iManufacturer[128];
					int ret;

					ret = libusb_get_string_descriptor_ascii(dev_handle,
							desc.iManufacturer, iManufacturer,
							sizeof(iManufacturer));
					if (ret > 0)
						usbDevice[reader_index].ccid.sIFD_iManufacturer
							= strdup((char *)iManufacturer);
				}

				usbDevice[reader_index].ccid.IFD_bcdDevice = desc.bcdDevice;
				goto end;
			}
		}
	}
end:
	if (usbDevice[reader_index].dev_handle == NULL)
	{
		/* does not work for libusb <= 1.0.8 */
		/* libusb_exit(ctx); */
		if (claim_failed)
			return STATUS_COMM_ERROR;
		return STATUS_NO_SUCH_DEVICE;
	}

	/* memorise the current reader_index so we can detect
	 * a new OpenUSBByName on a multi slot reader */
	previous_reader_index = reader_index;

end2:
	/* free the libusb allocated list & devices */
	libusb_free_device_list(devs, 1);

end1:
	/* free bundle list */
	bundleRelease(&plist);

	return return_value;
} /* OpenUSBByName */
示例#21
0
void CSharpGotoCodeGen::emitCondBSearch( RedStateAp *state, int level, int low, int high )
{
	/* Get the mid position, staying on the lower end of the range. */
	int mid = (low + high) >> 1;
	GenStateCond **data = state->stateCondVect.data;

	/* Determine if we need to look higher or lower. */
	bool anyLower = mid > low;
	bool anyHigher = mid < high;

	/* Determine if the keys at mid are the limits of the alphabet. */
	bool limitLow = data[mid]->lowKey == keyOps->minKey;
	bool limitHigh = data[mid]->highKey == keyOps->maxKey;

	if ( anyLower && anyHigher ) {
		/* Can go lower and higher than mid. */
		out << TABS(level) << L"if ( " << GET_KEY() << L" < " << 
				KEY(data[mid]->lowKey) << L" ) {\n";
		emitCondBSearch( state, level+1, low, mid-1 );
		out << TABS(level) << L"} else if ( " << GET_KEY() << L" > " << 
				KEY(data[mid]->highKey) << L" ) {\n";
		emitCondBSearch( state, level+1, mid+1, high );
		out << TABS(level) << L"} else {\n";
		COND_TRANSLATE(data[mid], level+1);
		out << TABS(level) << L"}\n";
	}
	else if ( anyLower && !anyHigher ) {
		/* Can go lower than mid but not higher. */
		out << TABS(level) << L"if ( " << GET_KEY() << L" < " << 
				KEY(data[mid]->lowKey) << L" ) {\n";
		emitCondBSearch( state, level+1, low, mid-1 );

		/* if the higher is the highest in the alphabet then there is no
		 * sense testing it. */
		if ( limitHigh ) {
			out << TABS(level) << L"} else {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
		else {
			out << TABS(level) << L"} else if ( " << GET_KEY() << L" <= " << 
					KEY(data[mid]->highKey) << L" ) {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
	}
	else if ( !anyLower && anyHigher ) {
		/* Can go higher than mid but not lower. */
		out << TABS(level) << L"if ( " << GET_KEY() << L" > " << 
				KEY(data[mid]->highKey) << L" ) {\n";
		emitCondBSearch( state, level+1, mid+1, high );

		/* If the lower end is the lowest in the alphabet then there is no
		 * sense testing it. */
		if ( limitLow ) {
			out << TABS(level) << L"} else {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
		else {
			out << TABS(level) << L"} else if ( " << GET_KEY() << L" >= " << 
					KEY(data[mid]->lowKey) << L" ) {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
	}
	else {
		/* Cannot go higher or lower than mid. It's mid or bust. What
		 * tests to do depends on limits of alphabet. */
		if ( !limitLow && !limitHigh ) {
			out << TABS(level) << L"if ( " << KEY(data[mid]->lowKey) << L" <= " << 
					GET_KEY() << L" && " << GET_KEY() << L" <= " << 
					KEY(data[mid]->highKey) << L" ) {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
		else if ( limitLow && !limitHigh ) {
			out << TABS(level) << L"if ( " << GET_KEY() << L" <= " << 
					KEY(data[mid]->highKey) << L" ) {\n";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
		else if ( !limitLow && limitHigh ) {
			out << TABS(level) << L"if ( " << KEY(data[mid]->lowKey) << L" <= " << 
					GET_KEY() << L" )\n {";
			COND_TRANSLATE(data[mid], level+1);
			out << TABS(level) << L"}\n";
		}
		else {
			/* Both high and low are at the limit. No tests to do. */
			COND_TRANSLATE(data[mid], level);
		}
	}
}
示例#22
0
VOID
BlpRebootDOS(
    IN PCHAR BootSectorImage OPTIONAL
    )

/*++

Routine Description:

    Loads up the bootstrap sectors and executes them (thereby rebooting
    into DOS or OS/2)

Arguments:

    BootSectorImage - If specified, supplies name of file on the C: drive
        that contains the boot sector image. In this case, this routine
        will return if that file cannot be opened (for example, if it's
        a directory).  If not specified, then default to \bootsect.dos,
        and this routine will never return.

Return Value:

    None.

--*/

{
    ULONG SectorId;
    ARC_STATUS Status;
    ULONG Read;
    ULONG DriveId;
    ULONG BootType;
    LARGE_INTEGER SeekPosition;
    extern UCHAR BootPartitionName[];

    //
    // HACKHACK John Vert (jvert)
    //     Some SCSI drives get really confused and return zeroes when
    //     you use the BIOS to query their size after the AHA driver has
    //     initialized.  This can completely tube OS/2 or DOS.  So here
    //     we try and open both BIOS-accessible hard drives.  Our open
    //     code is smart enough to retry if it gets back zeros, so hopefully
    //     this will give the SCSI drives a chance to get their act together.
    //
    Status = ArcOpen("multi(0)disk(0)rdisk(0)partition(0)",
                     ArcOpenReadOnly,
                     &DriveId);
    if (Status == ESUCCESS) {
        ArcClose(DriveId);
    }

    Status = ArcOpen("multi(0)disk(0)rdisk(1)partition(0)",
                     ArcOpenReadOnly,
                     &DriveId);
    if (Status == ESUCCESS) {
        ArcClose(DriveId);
    }

    //
    // Load the boot sector at address 0x7C00 (expected by Reboot callback)
    //
    Status = ArcOpen(BootPartitionName,
                     ArcOpenReadOnly,
                     &DriveId);
    if (Status != ESUCCESS) {
        BlPrint(BlFindMessage(BL_REBOOT_IO_ERROR),BootPartitionName);
        while (1) {
            GET_KEY();
        }
    }
    Status = BlOpen( DriveId,
                     BootSectorImage ? BootSectorImage : "\\bootsect.dos",
                     ArcOpenReadOnly,
                     &SectorId );

    if (Status != ESUCCESS) {
        if(BootSectorImage) {
            //
            // The boot sector image might actually be a directory.
            // Return to the caller to attempt standard boot.
            //
            BlClose(DriveId);
            return;
        }
        BlPrint(BlFindMessage(BL_REBOOT_IO_ERROR),BootPartitionName);
        while (1) {
        }
    }

    Status = BlRead( SectorId,
                     (PVOID)0x7c00,
                     SECTOR_SIZE,
                     &Read );

    if (Status != ESUCCESS) {
        BlPrint(BlFindMessage(BL_REBOOT_IO_ERROR),BootPartitionName);
        while (1) {
        }
    }

    //
    // The FAT boot code is only one sector long so we just want
    // to load it up and jump to it.
    //
    // For HPFS and NTFS, we can't do this because the first sector
    // loads the rest of the boot sectors -- but we want to use
    // the boot code in the boot sector image file we loaded.
    //
    // For HPFS, we load the first 20 sectors (boot code + super and
    // space blocks) into d00:200.  Fortunately this works for both
    // NT and OS/2.
    //
    // For NTFS, we load the first 16 sectors and jump to d00:256.
    // If the OEM field of the boot sector starts with NTFS, we
    // assume it's NTFS boot code.
    //

    //
    // Try to read 8K from the boot code image.
    // If this succeeds, we have either HPFS or NTFS.
    //
    SeekPosition.QuadPart = 0;
    BlSeek(SectorId,&SeekPosition,SeekAbsolute);
    BlRead(SectorId,(PVOID)0xd000,SECTOR_SIZE*16,&Read);

    if(Read == SECTOR_SIZE*16) {

        if(memcmp((PVOID)0x7c03,"NTFS",4)) {

            //
            // HPFS -- we need to load the super block.
            //
            BootType = 1;       // HPFS

            SeekPosition.QuadPart = 16*SECTOR_SIZE;
            ArcSeek(DriveId,&SeekPosition,SeekAbsolute);
            ArcRead(DriveId,(PVOID)0xf000,SECTOR_SIZE*4,&Read);

        } else {

            //
            // NTFS -- we've loaded everything we need to load.
            //
            BootType = 2;   // NTFS
        }
    } else {

        BootType = 0;       // FAT
    }

    //
    // DX must be the drive to boot from
    //

    _asm {
        mov dx, 0x80
    }
    REBOOT(BootType);

}
示例#23
0
ULONG
BlpPresentMenu(
    IN PMENU_OPTION MenuOption,
    IN ULONG NumberSelections,
    IN ULONG Default,
    IN LONG Timeout
    )

/*++

Routine Description:

    Displays the menu of boot options and allows the user to select one
    by using the arrow keys.

Arguments:

    MenuOption - Supplies array of menu options

    NumberSelections - Supplies the number of entries in the MenuOption array.

    Default - Supplies the index of the default operating system choice.

    Timeout - Supplies the timeout (in seconds) before the highlighted
              operating system choice is booted.  If this value is -1,
              the menu will never timeout.

Return Value:

    ULONG - The index of the operating system choice selected.

--*/

{
    ULONG i;
    ULONG Selection;
    ULONG StartTime;
    ULONG LastTime;
    ULONG BiasTime=0;
    ULONG CurrentTime;
    LONG SecondsLeft;
    ULONG EndTime;
    ULONG Key;
    ULONG MaxLength;
    ULONG CurrentLength;
    PCHAR SelectOs;
    PCHAR MoveHighlight;
    PCHAR TimeoutCountdown;
    PCHAR EnabledKd;
    PCHAR p;
    BOOLEAN Moved;

    //
    // Get the strings we'll need to display.
    //
    SelectOs = BlFindMessage(BL_SELECT_OS);
    MoveHighlight = BlFindMessage(BL_MOVE_HIGHLIGHT);
    TimeoutCountdown = BlFindMessage(BL_TIMEOUT_COUNTDOWN);
    EnabledKd = BlFindMessage(BL_ENABLED_KD_TITLE);
    if ((SelectOs == NULL)      ||
        (MoveHighlight == NULL) ||
        (EnabledKd == NULL)     ||
        (TimeoutCountdown==NULL)) {

        return(Default);
    }

    p=strchr(TimeoutCountdown,'\r');
    if (p!=NULL) {
        *p='\0';
    }
    p=strchr(EnabledKd,'\r');
    if (p!=NULL) {
        *p='\0';
    }

    if (NumberSelections<=1) {

        //
        // No menu if there's only one choice.
        //

        return(0);
    }
    if (Timeout==0) {

        //
        // If the timeout is zero, immediately boot the default
        //

        return(Default);
    }

    //
    // Find the longest string in the selections, so we know how long to
    // make the highlight bar.
    //

    MaxLength=0;
    for (i=0; i<NumberSelections; i++) {
        CurrentLength = strlen(MenuOption[i].Title);
        if (MenuOption[i].EnableDebug == TRUE) {
            CurrentLength += strlen(EnabledKd);
        }
        if (CurrentLength > MAX_TITLE_LENGTH) {
            //
            // This title is too long to fit on one line, so we have to
            // truncate it.
            //
            if (MenuOption[i].EnableDebug == TRUE) {
                MenuOption[i].Title[MAX_TITLE_LENGTH - strlen(EnabledKd)] = '\0';
            } else {
                MenuOption[i].Title[MAX_TITLE_LENGTH] = '\0';
            }
            CurrentLength = MAX_TITLE_LENGTH;
        }
        if (CurrentLength > MaxLength) {
            MaxLength = CurrentLength;
        }
    }

    Selection = Default;
    StartTime = GET_COUNTER();
    EndTime = StartTime + (Timeout * 182) / 10;
    BlPrint("OS Loader V4.50\n");
    TextSetCurrentAttribute(0x07);
    Moved = TRUE;
    do {
        TextSetCursorPosition(0,2);
        BlPrint(SelectOs);

        if(Moved) {
            for (i=0; i<NumberSelections; i++) {
                TextSetCursorPosition(0,5+i);
                if (i==Selection) {
                    TextFillAttribute(0x70,MaxLength+8);
                    TextSetCurrentAttribute(0x70);
                }
                BlPrint( "    %s", MenuOption[i].Title);

                if (MenuOption[i].EnableDebug == TRUE) {
                    BlPrint(EnabledKd);
                }
                TextSetCurrentAttribute(0x07);
            }
            Moved = FALSE;
        } else {
            TextSetCursorPosition(0,5+NumberSelections-1);
        }
        BlPrint(MoveHighlight);
        if (Timeout != -1) {
            LastTime = CurrentTime;
            CurrentTime = GET_COUNTER();

            //
            // deal with wraparound at midnight
            // We can't do it the easy way because there are not exactly
            // 18.2 * 60 * 60 * 24 tics/day.  (just approximately)
            //
            if (CurrentTime < StartTime) {
                if (BiasTime == 0) {
                    BiasTime = LastTime + 1;
                }
                CurrentTime += BiasTime;
            }
            BlPrint(TimeoutCountdown);

            SecondsLeft = ((LONG)(EndTime - CurrentTime) * 10) / 182;

            if (SecondsLeft < 0) {

                //
                // Note that if the user hits the PAUSE key, the counter stops
                // and, as a result, SecondsLeft can become < 0.
                //

                SecondsLeft = 0;
            }

            BlPrint(" %d \n",SecondsLeft);
        } else {
            BlPrint("                                                                      \n");
        }

        //
        // Poll for a key stroke.  Any key disables the countdown
        // timer.
        //

        Key = GET_KEY();
        if (Key != 0) {
            Timeout = -1;
        }

        if ( (Key==UP_ARROW) ||
             (Key==DOWN_ARROW) ||
             (Key==HOME_KEY) ||
             (Key==END_KEY)
           ) {
            Moved = TRUE;
            TextSetCursorPosition(0,5+Selection);
            TextFillAttribute(0x07,MaxLength+8);
            if (Key==DOWN_ARROW) {
                Selection = (Selection+1) % NumberSelections;
            } else if (Key==UP_ARROW) {
                Selection = (Selection == 0) ? (NumberSelections-1)
                                             : (Selection - 1);
            } else if (Key==HOME_KEY) {
                Selection = 0;
            } else if (Key==END_KEY) {
                Selection = NumberSelections-1;
            }
        }

    } while ( ((Key&(ULONG)0xff) != ENTER_KEY) &&
              ((CurrentTime < EndTime) || (Timeout == -1)) );

    return(Selection);
}
示例#24
0
文件: entry.c 项目: chunhualiu/OpenNT
BOOLEAN
BlDetectHardware(
    IN ULONG DriveId,
    IN PCHAR LoadOptions
    )

/*++

Routine Description:

    Loads and runs NTDETECT.COM to populate the ARC configuration tree.
    NTDETECT is assumed to reside in the root directory.

Arguments:

    DriveId - Supplies drive id where NTDETECT is located.

    LoadOptions - Supplies Load Options string to ntdetect.

Return Value:

    TRUE - NTDETECT successfully run.

    FALSE - Error

--*/

{
    ARC_STATUS Status;
    PCONFIGURATION_COMPONENT_DATA TempFwTree;
    ULONG TempFwHeapUsed;
    extern BOOLEAN FwDescriptorsValid;
    ULONG FileSize;
    ULONG DetectFileId;
    FILE_INFORMATION FileInformation;
    PUCHAR DetectionBuffer;
    PUCHAR Options;
    UCHAR Buffer[100];
    LARGE_INTEGER SeekPosition;
    ULONG Read;

    //
    // Now check if we have ntdetect.com in the root directory, if yes,
    // we will load it to predefined location and transfer control to
    // it.
    //

#if defined(ELTORITO)
    if (ElToritoCDBoot) {
        // we assume ntdetect.com is in the x86 directory
        Status = BlOpen( DriveId,
                         "\\x86\\ntdetect.com",
                         ArcOpenReadOnly,
                         &DetectFileId );
    } else {
#endif
    Status = BlOpen( DriveId,
                     "\\ntdetect.com",
                     ArcOpenReadOnly,
                     &DetectFileId );
#if defined(ELTORITO)
    }
#endif

    DetectionBuffer = (PUCHAR)DETECTION_LOADED_ADDRESS;

    if (Status != ESUCCESS) {
#if DBG
        BlPrint("Error opening NTDETECT.COM, status = %x\n", Status);
        BlPrint("Press any key to continue\n");
        while (!GET_KEY()) {
        }
#endif
        return(FALSE);
    }

    //
    // Determine the length of the ntdetect.com file
    //

    Status = BlGetFileInformation(DetectFileId, &FileInformation);
    if (Status != ESUCCESS) {
        BlClose(DetectFileId);
#if DBG
        BlPrint("Error getting NTDETECT.COM file information, status = %x\n", Status);
        BlPrint("Press any key to continue\n");
        while (!GET_KEY()) {
        }
#endif
        return(FALSE);
    }

    FileSize = FileInformation.EndingAddress.LowPart;
    if (FileSize == 0) {
        BlClose(DetectFileId);
#if DBG
        BlPrint("Error: size of NTDETECT.COM is zero.\n");
        BlPrint("Press any key to continue\n");
        while (!GET_KEY()) {
        }
#endif
        return(FALSE);
    }

    SeekPosition.QuadPart = 0;
    Status = BlSeek(DetectFileId,
                    &SeekPosition,
                    SeekAbsolute);
    if (Status != ESUCCESS) {
        BlClose(DetectFileId);
#if DBG
        BlPrint("Error seeking to start of NTDETECT.COM file\n");
        BlPrint("Press any key to continue\n");
        while (!GET_KEY()) {
        }
#endif
        return(FALSE);
    }
    Status = BlRead( DetectFileId,
                     DetectionBuffer,
                     FileSize,
                     &Read );

    BlClose(DetectFileId);
    if (Status != ESUCCESS) {
#if DBG
        BlPrint("Error reading from NTDETECT.COM\n");
        BlPrint("Read %lx bytes\n",Read);
        BlPrint("Press any key to continue\n");
        while (!GET_KEY()) {
        }
#endif
        return(FALSE);
    }

    //
    // We need to pass NTDETECT pointers < 1Mb, so
    // use local storage off the stack.  (which is
    // always < 1Mb.
    //

    if (LoadOptions) {
        strcpy(Buffer, LoadOptions);
        Options = Buffer;
    } else {
        Options = NULL;
    }
    DETECT_HARDWARE((ULONG)(TEMPORARY_HEAP_START - 0x10) * PAGE_SIZE,
                    (ULONG)0x10000,         // Heap Size
                    (PVOID)&TempFwTree,
                    (PULONG)&TempFwHeapUsed,
                    (PCHAR)Options,
                    (ULONG)(LoadOptions ? strlen(LoadOptions) : 0)
                    );
    FwConfigurationTree = TempFwTree;
    FwHeapUsed = TempFwHeapUsed;
    FwDescriptorsValid = FALSE;

    return(TRUE);
}
示例#25
0
文件: entry.c 项目: chunhualiu/OpenNT
VOID
NtProcessStartup(
    IN PBOOT_CONTEXT BootContextRecord
    )
/*++

Routine Description:

    Main entry point for setup loader. Control is transferred here by the
    start-up (SU) module.

Arguments:

    BootContextRecord - Supplies the boot context, particularly the
        ExternalServicesTable.

Returns:

    Does not return. Control eventually passed to the kernel.


--*/
{
    ARC_STATUS Status;

    //
    // Initialize the boot loader's video
    //

    DoGlobalInitialization(BootContextRecord);

    BlFillInSystemParameters(BootContextRecord);

    if (BootContextRecord->FSContextPointer->BootDrive == 0) {

        //
        // Boot was from A:
        //

        strcpy(BootPartitionName,"multi(0)disk(0)fdisk(0)");

        //
        // To get around an apparent bug on the BIOS of some MCA machines
        // (specifically the NCR 386sx/MC20 w/ BIOS version 1.04.00 (3421),
        // Phoenix BIOS 1.02.07), whereby the first int13 to floppy results
        // in a garbage buffer, reset drive 0 here.
        //

        GET_SECTOR(0,0,0,0,0,0,NULL);

#if defined(ELTORITO)
    } else if (BlIsElToritoCDBoot(BootContextRecord->FSContextPointer->BootDrive)) {

        //
        // Boot was from El Torito CD
        //

        sprintf(BootPartitionName, "multi(0)disk(0)cdrom(%u)", BootContextRecord->FSContextPointer->BootDrive);
        ElToritoCDBoot = TRUE;
#endif

    } else {

        //
        // Find the partition we have been booted from.  Note that this
        // is *NOT* necessarily the active partition.  If the system has
        // Boot Mangler installed, it will be the active partition, and
        // we have to go figure out what partition we are actually on.
        //
        BlGetActivePartition(BootPartitionName);

    }

    //
    // Initialize the memory descriptor list, the OS loader heap, and the
    // OS loader parameter block.
    //

    Status = BlMemoryInitialize();
    if (Status != ESUCCESS) {
        BlPrint("Couldn't initialize memory\n");
        while (1) {
        }
    }

    //
    // Initialize the OS loader I/O system.
    //

    Status = BlIoInitialize();
    if (Status != ESUCCESS) {
        BlPrint("Couldn't initialize I/O\n");
    }

    //
    // Call off to regular startup code
    //
    BlStartup(BootPartitionName);

    //
    // we should never get here!
    //
    do {
        GET_KEY();
    } while ( 1 );

}
void Schedule_UI_Mod(USER * user)
{
	system("cls");
	BIOS_GOTO_BOX(22, 100, 5, 25);
	BIOS_GOTO_BOX(22, 100, 8, 7);
	TTMS_GotoXY(52, 6);
	printf_s("请输入要修改的ID:");
	int ID;
	scanf_s("%d", &ID);
	auto *schedule = Schedule_Srv_FetchByID(ID);
	if (schedule)
	{
		BIOS_GOTO_BOX(22, 100, 23, 22);
		BIOS_GOTO_BOX(58, 58, 8, 22);
		TTMS_GotoXY(35, 24);
		printf_s("请在右方对信息进行修改,若不需要修改请原封不动移过去");
		int NewStartTime_Day, NewStartTime_Month, NewStartTime_Year, NewStartTime_Hour, NewStartTime_Minute, NewStudioID, NewPlayID,NewSeatCountMax;
		char  key[15];
		TTMS_GotoXY(52, 6);
		printf_s("    第%d号演出计划        ", schedule->data.id);
		TTMS_GotoXY(25, 9);
		printf_s("放映厅ID: %d", schedule->data.studio_id);
		TTMS_GotoXY(25, 11);
		printf_s("剧目ID: %d", schedule->data.play_id);
		TTMS_GotoXY(25, 13);
		printf_s("计划开始时间:%d年%d月%d日%d时%d分", schedule->time.daytime.year, schedule->time.daytime.month, schedule->time.daytime.day, schedule->time.hour, schedule->time.minute);
		TTMS_GotoXY(25, 15);
		printf_s("最多座位数(票数): %d", schedule->data.seat_count);
		TTMS_GotoXY(60, 9);
		printf_s("修改后:");
		TTMS_GotoXY(60, 11);
		printf_s("修改后: ");
		TTMS_GotoXY(60, 13);
		printf_s("修改后: ");
		TTMS_GotoXY(60, 15);
		printf_s("修改后: ");
		TTMS_GotoXY(67, 9);
		scanf_s("%d", &NewStudioID);
		TTMS_GotoXY(67, 11);
		scanf_s("%d", &NewPlayID);
		TTMS_GotoXY(67, 13);
		scanf_s("%d%d%d%d%d", &NewStartTime_Year, &NewStartTime_Month,&NewStartTime_Day, &NewStartTime_Hour, &NewStartTime_Minute);
		TTMS_GotoXY(67, 15);
		scanf_s("%d", &NewSeatCountMax);
		schedule->data.play_id = NewPlayID;
		schedule->data.studio_id = NewStudioID;
		schedule->time.daytime.year = NewStartTime_Year;
		schedule->time.daytime.month = NewStartTime_Month;
		schedule->time.daytime.day = NewStartTime_Day;
		schedule->time.hour = NewStartTime_Hour;
		schedule->time.minute = NewStartTime_Minute;
		schedule->data.seat_count = NewSeatCountMax;
		TTMS_GotoXY(35, 24);
		printf_s("                                                       ");
		TTMS_GotoXY(52, 24);
		printf_s("Enter确认修改,Esc取消");
		strcpy_s(key, 15, GET_KEY());
		if (strcmp(key, "Enter") == 0)
		{
			Schedule_Srv_Mod(schedule);
			TTMS_GotoXY(35, 24);
			printf_s("                                                     ");
			TTMS_GotoXY(50, 24);
			printf_s("修改成功,任意键退出!");
			_getch();
			Schedule_UI_MgtEntry(user);
		}
		if (strcmp(key, "Esc") == 0)
		{
			TTMS_GotoXY(35, 24);
			printf_s("                                                    ");
			TTMS_GotoXY(50, 24);
			printf_s("取消成功,任意键退出!");
			_getch();
			Schedule_UI_MgtEntry(user);
		}
	}
	else
	{
		TTMS_GotoXY(35, 24);
		printf_s("                                                       ");
		TTMS_GotoXY(50, 24);
		printf_s("无此剧目,按任意键退出");
		_getch();
		Schedule_UI_MgtEntry(user);
	}
}
示例#27
0
文件: bnxt_tc.c 项目: Lyude/linux
static int bnxt_tc_parse_flow(struct bnxt *bp,
			      struct tc_cls_flower_offload *tc_flow_cmd,
			      struct bnxt_tc_flow *flow)
{
	struct flow_dissector *dissector = tc_flow_cmd->dissector;
	u16 addr_type = 0;

	/* KEY_CONTROL and KEY_BASIC are needed for forming a meaningful key */
	if ((dissector->used_keys & BIT(FLOW_DISSECTOR_KEY_CONTROL)) == 0 ||
	    (dissector->used_keys & BIT(FLOW_DISSECTOR_KEY_BASIC)) == 0) {
		netdev_info(bp->dev, "cannot form TC key: used_keys = 0x%x",
			    dissector->used_keys);
		return -EOPNOTSUPP;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
		struct flow_dissector_key_control *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_CONTROL);

		addr_type = key->addr_type;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_BASIC)) {
		struct flow_dissector_key_basic *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_BASIC);
		struct flow_dissector_key_basic *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_BASIC);

		flow->l2_key.ether_type = key->n_proto;
		flow->l2_mask.ether_type = mask->n_proto;

		if (key->n_proto == htons(ETH_P_IP) ||
		    key->n_proto == htons(ETH_P_IPV6)) {
			flow->l4_key.ip_proto = key->ip_proto;
			flow->l4_mask.ip_proto = mask->ip_proto;
		}
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
		struct flow_dissector_key_eth_addrs *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ETH_ADDRS);
		struct flow_dissector_key_eth_addrs *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ETH_ADDRS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_ETH_ADDRS;
		ether_addr_copy(flow->l2_key.dmac, key->dst);
		ether_addr_copy(flow->l2_mask.dmac, mask->dst);
		ether_addr_copy(flow->l2_key.smac, key->src);
		ether_addr_copy(flow->l2_mask.smac, mask->src);
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_VLAN)) {
		struct flow_dissector_key_vlan *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_VLAN);
		struct flow_dissector_key_vlan *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_VLAN);

		flow->l2_key.inner_vlan_tci =
		   cpu_to_be16(VLAN_TCI(key->vlan_id, key->vlan_priority));
		flow->l2_mask.inner_vlan_tci =
		   cpu_to_be16((VLAN_TCI(mask->vlan_id, mask->vlan_priority)));
		flow->l2_key.inner_vlan_tpid = htons(ETH_P_8021Q);
		flow->l2_mask.inner_vlan_tpid = htons(0xffff);
		flow->l2_key.num_vlans = 1;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
		struct flow_dissector_key_ipv4_addrs *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV4_ADDRS);
		struct flow_dissector_key_ipv4_addrs *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV4_ADDRS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_IPV4_ADDRS;
		flow->l3_key.ipv4.daddr.s_addr = key->dst;
		flow->l3_mask.ipv4.daddr.s_addr = mask->dst;
		flow->l3_key.ipv4.saddr.s_addr = key->src;
		flow->l3_mask.ipv4.saddr.s_addr = mask->src;
	} else if (dissector_uses_key(dissector,
				      FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
		struct flow_dissector_key_ipv6_addrs *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV6_ADDRS);
		struct flow_dissector_key_ipv6_addrs *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV6_ADDRS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_IPV6_ADDRS;
		flow->l3_key.ipv6.daddr = key->dst;
		flow->l3_mask.ipv6.daddr = mask->dst;
		flow->l3_key.ipv6.saddr = key->src;
		flow->l3_mask.ipv6.saddr = mask->src;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_PORTS)) {
		struct flow_dissector_key_ports *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_PORTS);
		struct flow_dissector_key_ports *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_PORTS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_PORTS;
		flow->l4_key.ports.dport = key->dst;
		flow->l4_mask.ports.dport = mask->dst;
		flow->l4_key.ports.sport = key->src;
		flow->l4_mask.ports.sport = mask->src;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ICMP)) {
		struct flow_dissector_key_icmp *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ICMP);
		struct flow_dissector_key_icmp *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ICMP);

		flow->flags |= BNXT_TC_FLOW_FLAGS_ICMP;
		flow->l4_key.icmp.type = key->type;
		flow->l4_key.icmp.code = key->code;
		flow->l4_mask.icmp.type = mask->type;
		flow->l4_mask.icmp.code = mask->code;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
		struct flow_dissector_key_control *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_CONTROL);

		addr_type = key->addr_type;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
		struct flow_dissector_key_ipv4_addrs *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS);
		struct flow_dissector_key_ipv4_addrs *mask =
				GET_MASK(tc_flow_cmd,
					 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS;
		flow->tun_key.u.ipv4.dst = key->dst;
		flow->tun_mask.u.ipv4.dst = mask->dst;
		flow->tun_key.u.ipv4.src = key->src;
		flow->tun_mask.u.ipv4.src = mask->src;
	} else if (dissector_uses_key(dissector,
				      FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS)) {
		return -EOPNOTSUPP;
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
		struct flow_dissector_key_keyid *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_KEYID);
		struct flow_dissector_key_keyid *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_KEYID);

		flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_ID;
		flow->tun_key.tun_id = key32_to_tunnel_id(key->keyid);
		flow->tun_mask.tun_id = key32_to_tunnel_id(mask->keyid);
	}

	if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_PORTS)) {
		struct flow_dissector_key_ports *key =
			GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_PORTS);
		struct flow_dissector_key_ports *mask =
			GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_PORTS);

		flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_PORTS;
		flow->tun_key.tp_dst = key->dst;
		flow->tun_mask.tp_dst = mask->dst;
		flow->tun_key.tp_src = key->src;
		flow->tun_mask.tp_src = mask->src;
	}

	return bnxt_tc_parse_actions(bp, &flow->actions, tc_flow_cmd->exts);
}
示例#28
0
文件: igor.cpp 项目: Attnam/ivan
int main(int, char**)
{
  festring OldDirectory;
  std::ifstream IConfigFile("igor.cfg");

  if(IConfigFile.is_open())
    {
      char ch;

      while(IConfigFile.get(ch))
        OldDirectory << ch;
    }

  IConfigFile.close();
  std::cout << "Where is the graphics directory? ";

  if(OldDirectory.GetSize())
    std::cout << '[' << OldDirectory.CStr() << "] ";

  festring Directory;
  char ch;

  while((ch = getchar()) != '\n')
    Directory << ch;

  if(Directory.IsEmpty())
    Directory = OldDirectory;

  if(!Directory.IsEmpty() && Directory[Directory.GetSize() - 1] != '/')
    Directory << '/';

  std::ofstream OConfigFile("igor.cfg");
  OConfigFile << Directory.CStr();
  OConfigFile.close();

  graphics::Init();
  graphics::SetMode("IGOR 1.203", 0, v2(800, 600), 1, 0, false);
  graphics::LoadDefaultFont(Directory + "Font.png");
  DOUBLE_BUFFER->ClearToColor(0);

  rawbitmap* CBitmap;
  felist List(CONST_S("Choose file to edit:"));
  List.AddEntry(CONST_S("Char.png"), LIGHT_GRAY);
  List.AddEntry(CONST_S("Humanoid.png"), LIGHT_GRAY);
  List.AddEntry(CONST_S("Item.png"), LIGHT_GRAY);
  List.AddEntry(CONST_S("GLTerra.png"), LIGHT_GRAY);
  List.AddEntry(CONST_S("OLTerra.png"), LIGHT_GRAY);
  ushort Selected;
  festring FileName;
  List.SetPos(v2(300, 250));
  List.SetWidth(200);

  while((Selected = List.Draw()) & FELIST_ERROR_BIT)
    if(Selected == ESCAPED)
      return 0;

  switch(Selected)
    {
    case 0: FileName = CONST_S("Char.png"); break;
    case 1: FileName = CONST_S("Humanoid.png"); break;
    case 2: FileName = CONST_S("Item.png"); break;
    case 3: FileName = CONST_S("GLTerra.png"); break;
    case 4: FileName = CONST_S("OLTerra.png"); break;
    }

  CBitmap = new rawbitmap(Directory + FileName);
  bitmap CursorBitmap(Directory + "Cursor.png");
  CursorBitmap.ActivateFastFlag();
  v2 Cursor(0, 0);
  int k = 0;
  Selected = 0;
  packcol16 Color[4] = { static_cast<packcol16>(MakeRGB16(47, 131, 95)),
                         static_cast<packcol16>(MakeRGB16(123, 0, 127)),
                         static_cast<packcol16>(MakeRGB16(0, 131, 131)),
                         static_cast<packcol16>(MakeRGB16(175, 131, 0)) };
  std::vector<v2> DrawQueue;
  uchar TempBuffer[256];
  blitdata B1 = { DOUBLE_BUFFER,
                  { 0, 0 },
                  { RES.X - STRETCH * 16 - 10, RES.Y - STRETCH * 16 - 10 },
                  { TILE_SIZE, TILE_SIZE },
                  { STRETCH } };
  blitdata B2 = { DOUBLE_BUFFER,
                  { 0, 0 },
                  { RES.X - STRETCH * 32 - 20, RES.Y - STRETCH * 16 - 10 },
                  { TILE_SIZE, TILE_SIZE },
                  { STRETCH } };
  blitdata B3 = { DOUBLE_BUFFER,
                  { 0, 0 },
                  { 0, 0 },
                  { TILE_SIZE, TILE_SIZE },
                  { 0 },
                  TRANSPARENT_COLOR };

  for(;;)
    {
      static v2 MoveVector[] = { v2(0, -16), v2(-16, 0), v2(0, 16), v2(16, 0) };
      static int Key[] = { 'w', 'a', 's', 'd' };

      int c;

      for(c = 0; c < 4; ++c)
        {
          if(Key[c] == k)
            {
              v2 NewPos = Cursor + MoveVector[c];

              if(NewPos.X >= 0 && NewPos.X <= CBitmap->GetSize().X - 16 && NewPos.Y >= 0 && NewPos.Y <= CBitmap->GetSize().Y - 16)
                Cursor = NewPos;

              break;
            }

          if((Key[c]&~0x20) == k)
            {
              v2 NewPos = Cursor + (MoveVector[c] << 2);

              if(NewPos.X >= 0 && NewPos.X <= CBitmap->GetSize().X - 16 && NewPos.Y >= 0 && NewPos.Y <= CBitmap->GetSize().Y - 16)
                Cursor = NewPos;

              break;
            }
        }

      if(k >= 0x31 && k <= 0x34)
        Selected = k - 0x31;
      else if(k == '+')
        CBitmap->AlterGradient(Cursor, TILE_V2, Selected, 1, false);
      else if(k == '-')
        CBitmap->AlterGradient(Cursor, TILE_V2, Selected, -1, false);
      else if(k == '>')
        CBitmap->AlterGradient(Cursor, TILE_V2, Selected, 1, true);
      else if(k == '<')
        CBitmap->AlterGradient(Cursor, TILE_V2, Selected, -1, true);
      else if(k == KEY_UP)
        CBitmap->Roll(Cursor, TILE_V2, v2(0, -1), TempBuffer);
      else if(k == KEY_DOWN)
        CBitmap->Roll(Cursor, TILE_V2, v2(0, 1), TempBuffer);
      else if(k == KEY_RIGHT)
        CBitmap->Roll(Cursor, TILE_V2, v2(1, 0), TempBuffer);
      else if(k == KEY_LEFT)
        CBitmap->Roll(Cursor, TILE_V2, v2(-1, 0), TempBuffer);
      else if(k == '=')
        {
          FONT->Printf(DOUBLE_BUFFER, v2(10, 460), RED, "Select col to swap with [1-4/ESC]");
          graphics::BlitDBToScreen();

          for(k = GET_KEY(); k != 0x1B; k = GET_KEY())
            if(k >= 0x31 && k <= 0x34)
              {
                CBitmap->SwapColors(Cursor, TILE_V2, Selected, k - 0x31);
                break;
              }
        }
      else if(k == 0x1B)
        {
          FONT->Printf(DOUBLE_BUFFER, v2(10, 460), RED, "Save? [y/n/c]");
          graphics::BlitDBToScreen();

          for(;;)
            {
              k = GET_KEY();

              if(k == 'y' || k == 'Y')
                {
                  CBitmap->Save(Directory + FileName);
                  delete CBitmap;
                  return 0;
                }

              if(k == 'n' || k == 'N')
                {
                  delete CBitmap;
                  return 0;
                }

              if(k == 'c' || k == 'C')
                break;
            }
        }
      else if(k == 'p')
        {
          std::vector<v2>::iterator i = std::find(DrawQueue.begin(), DrawQueue.end(), Cursor);

          if(i == DrawQueue.end())
            DrawQueue.push_back(Cursor);
          else
            DrawQueue.erase(i);
        }
      else if(k == 'c')
        DrawQueue.clear();

      DOUBLE_BUFFER->ClearToColor(0);
      DOUBLE_BUFFER->Fill(0, 0, CBitmap->GetSize(), 0xF81F);
      CBitmap->MaskedBlit(DOUBLE_BUFFER, v2(0, 0), v2(0, 0), CBitmap->GetSize(), Color);
      DOUBLE_BUFFER->DrawRectangle(RES.X - STRETCH * 16 - 12, RES.Y - STRETCH * 16 - 12, RES.X - 9, RES.Y - 9, DARK_GRAY, true);
      DOUBLE_BUFFER->DrawRectangle(RES.X - STRETCH * 32 - 22, RES.Y - STRETCH * 16 - 12, RES.X - STRETCH * 16 - 19, RES.Y - 9, DARK_GRAY, true);
      B1.Src = Cursor;
      DOUBLE_BUFFER->StretchBlit(B1);
      FONT->Printf(DOUBLE_BUFFER, v2(10, 480), WHITE, "Control cursor: wasd and WASD");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 490), WHITE, "Select m-col: 1-4");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 500), WHITE, "Safely alter gradient: ±");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 510), WHITE, "Power alter gradient: <>");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 520), WHITE, "Swap m-cols: =");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 530), WHITE, "Push to / pop from draw queue: p");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 540), WHITE, "Clear draw queue: c");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 550), WHITE, "Roll picture: arrow keys");
      FONT->Printf(DOUBLE_BUFFER, v2(10, 570), WHITE, "MColor selected: %d", Selected + 1);
      FONT->Printf(DOUBLE_BUFFER, v2(10, 580), WHITE, "Current position: (%d, %d)", Cursor.X, Cursor.Y);

      for(c = 0; c < DrawQueue.size(); ++c)
        {
          B2.Src = DrawQueue[c];
          DOUBLE_BUFFER->StretchBlit(B2);
          B3.Dest = DrawQueue[c];
          CursorBitmap.NormalMaskedBlit(B3);
        }

      B3.Dest = Cursor;
      CursorBitmap.NormalMaskedBlit(B3);
      graphics::BlitDBToScreen();
      k = GET_KEY();
    }

  return 1;
}
示例#29
0
static LONG HPReadBundleValues(void)
{
	LONG rv;
	DIR *hpDir;
	struct dirent *currFP = NULL;
	char fullPath[FILENAME_MAX];
	char fullLibPath[FILENAME_MAX];
	int listCount = 0;

	hpDir = opendir(PCSCLITE_HP_DROPDIR);

	if (NULL == hpDir)
	{
		Log1(PCSC_LOG_ERROR, "Cannot open PC/SC drivers directory: " PCSCLITE_HP_DROPDIR);
		Log1(PCSC_LOG_ERROR, "Disabling USB support for pcscd.");
		return -1;
	}

	/* allocate a first array */
	driverSize = DRIVER_TRACKER_INITIAL_SIZE;
	driverTracker = calloc(driverSize, sizeof(*driverTracker));
	if (NULL == driverTracker)
	{
		Log1(PCSC_LOG_CRITICAL, "Not enough memory");
		return -1;
	}

#define GET_KEY(key, values) \
	rv = LTPBundleFindValueWithKey(&plist, key, values); \
	if (rv) \
	{ \
		Log2(PCSC_LOG_ERROR, "Value/Key not defined for " key " in %s", \
			fullPath); \
		continue; \
	}

	while ((currFP = readdir(hpDir)) != 0)
	{
		if (strstr(currFP->d_name, ".bundle") != 0)
		{
			unsigned int alias;
			list_t plist, *values;
			list_t *manuIDs, *productIDs, *readerNames;
			char *CFBundleName;
			char *libraryPath;

			/*
			 * The bundle exists - let's form a full path name and get the
			 * vendor and product ID's for this particular bundle
			 */
			(void)snprintf(fullPath, sizeof(fullPath), "%s/%s/Contents/Info.plist",
				PCSCLITE_HP_DROPDIR, currFP->d_name);
			fullPath[sizeof(fullPath) - 1] = '\0';

			rv = bundleParse(fullPath, &plist);
			if (rv)
				continue;

			/* get CFBundleExecutable */
			GET_KEY(PCSCLITE_HP_LIBRKEY_NAME, &values)
			libraryPath = list_get_at(values, 0);
			(void)snprintf(fullLibPath, sizeof(fullLibPath),
				"%s/%s/Contents/%s/%s",
				PCSCLITE_HP_DROPDIR, currFP->d_name, PCSC_ARCH,
				libraryPath);
			fullLibPath[sizeof(fullLibPath) - 1] = '\0';

			GET_KEY(PCSCLITE_HP_MANUKEY_NAME, &manuIDs)
			GET_KEY(PCSCLITE_HP_PRODKEY_NAME, &productIDs)
			GET_KEY(PCSCLITE_HP_NAMEKEY_NAME, &readerNames)

			/* Get CFBundleName */
			rv = LTPBundleFindValueWithKey(&plist, PCSCLITE_HP_CFBUNDLE_NAME,
				&values);
			if (rv)
				CFBundleName = NULL;
			else
				CFBundleName = strdup(list_get_at(values, 0));

			/* while we find a nth ifdVendorID in Info.plist */
			for (alias=0; alias<list_size(manuIDs); alias++)
			{
				char *value;

				/* variables entries */
				value = list_get_at(manuIDs, alias);
				driverTracker[listCount].manuID = strtol(value, NULL, 16);

				value = list_get_at(productIDs, alias);
				driverTracker[listCount].productID = strtol(value, NULL, 16);

				driverTracker[listCount].readerName = strdup(list_get_at(readerNames, alias));

				/* constant entries for a same driver */
				driverTracker[listCount].bundleName = strdup(currFP->d_name);
				driverTracker[listCount].libraryPath = strdup(fullLibPath);
				driverTracker[listCount].CFBundleName = CFBundleName;

#ifdef DEBUG_HOTPLUG
				Log2(PCSC_LOG_INFO, "Found driver for: %s",
					driverTracker[listCount].readerName);
#endif
				listCount++;
				if (listCount >= driverSize)
				{
					int i;

					/* increase the array size */
					driverSize += DRIVER_TRACKER_SIZE_STEP;
#ifdef DEBUG_HOTPLUG
					Log2(PCSC_LOG_INFO,
						"Increase driverTracker to %d entries", driverSize);
#endif
					driverTracker = realloc(driverTracker,
						driverSize * sizeof(*driverTracker));
					if (NULL == driverTracker)
					{
						Log1(PCSC_LOG_CRITICAL, "Not enough memory");
						driverSize = -1;
						return -1;
					}

					/* clean the newly allocated entries */
					for (i=driverSize-DRIVER_TRACKER_SIZE_STEP; i<driverSize; i++)
					{
						driverTracker[i].manuID = 0;
						driverTracker[i].productID = 0;
						driverTracker[i].bundleName = NULL;
						driverTracker[i].libraryPath = NULL;
						driverTracker[i].readerName = NULL;
						driverTracker[i].CFBundleName = NULL;
					}
				}
			}
			bundleRelease(&plist);
		}
	}

	driverSize = listCount;
	(void)closedir(hpDir);

#ifdef DEBUG_HOTPLUG
	Log2(PCSC_LOG_INFO, "Found drivers for %d readers", listCount);
#endif

	return 0;
} /* HPReadBundleValues */