string mktex_var_expand P1C(const_string, src) { const_string s; string ret; fn_type expansion; expansion = fn_init (); /* Copy everything but variable constructs. */ for (s = src; *s; s++) { if (IS_VAR_START (*s)) { s++; /* Three cases: `$VAR', `${VAR}', `$<anything-else>'. */ if (IS_VAR_CHAR (*s)) { /* $V: collect name constituents, then expand. */ const_string var_end = s; do { var_end++; } while (IS_VAR_CHAR (*var_end)); var_end--; /* had to go one past */ expand (&expansion, s, var_end); s = var_end; } else if (IS_VAR_BEGIN_DELIMITER (*s)) { /* ${: scan ahead for matching delimiter, then expand. */ const_string var_end = ++s; while (*var_end && !IS_VAR_END_DELIMITER (*var_end)) var_end++; if (! *var_end) { WARNING1 ("%s: No matching } for ${", src); s = var_end - 1; /* will incr to null at top of loop */ } else { expand (&expansion, s, var_end - 1); s = var_end; /* will incr past } at top of loop*/ } } else { /* $<something-else>: error. */ WARNING2 ("%s: Unrecognized variable construct `$%c'", src, *s); /* Just ignore those chars and keep going. */ } } else fn_1grow (&expansion, *s); } fn_1grow (&expansion, 0); ret = FN_STRING (expansion); return ret; }
//class platform_spec platform_spec::co_initializer::co_initializer() : ole32_(::LoadLibrary(L"OLE32.DLL")) { if(ole32_) { typedef HRESULT (__stdcall *CoInitializeEx_t)(LPVOID, DWORD); CoInitializeEx_t fn_init = reinterpret_cast<CoInitializeEx_t>(::GetProcAddress(ole32_, "CoInitializeEx")); if(0 == fn_init) { ::FreeLibrary(ole32_); ole32_ = 0; throw std::runtime_error("Nana.PlatformSpec.Co_initializer: Can't locate the CoInitializeEx()."); } else fn_init(0, COINIT_APARTMENTTHREADED | /*COINIT_DISABLE_OLE1DDE =*/0x4); } else throw std::runtime_error("Nana.PlatformSpec.Co_initializer: No Ole32.DLL Loaded."); }
string kpathsea_var_expand (kpathsea kpse, const_string src) { const_string s; string ret; fn_type expansion; expansion = fn_init (); /* Copy everything but variable constructs. */ for (s = src; *s; s++) { if (IS_VAR_START (*s)) { s++; /* Three cases: `$VAR', `${VAR}', `$<anything-else>'. */ if (IS_VAR_CHAR (*s)) { /* $V: collect name constituents, then expand. */ const_string var_end = s; do { var_end++; } while (IS_VAR_CHAR (*var_end)); var_end--; /* had to go one past */ if (!expand (kpse, &expansion, s, var_end)) { /* If no expansion, include the literal $x construct, so filenames containing dollar signs can be read. The first +1 is to get the full variable name, the other +1 is to get the dollar sign; we've moved past it. */ fn_grow (&expansion, s - 1, var_end - s + 1 + 1); } s = var_end; } else if (IS_VAR_BEGIN_DELIMITER (*s)) { /* ${: scan ahead for matching delimiter, then expand. */ const_string var_end = ++s; while (*var_end && !IS_VAR_END_DELIMITER (*var_end)) { #if defined(WIN32) if (kpathsea_IS_KANJI(kpse, var_end)) var_end++; #endif var_end++; } if (! *var_end) { WARNING1 ("kpathsea: %s: No matching } for ${", src); s = var_end - 1; /* will incr to null at top of loop */ } else { expand (kpse, &expansion, s, var_end - 1); s = var_end; /* will incr past } at top of loop*/ } } else { /* $<something-else>: warn, but preserve characters; again, so filenames containing dollar signs can be read. */ WARNING2 ("kpathsea: %s: Unrecognized variable construct `$%c'", src, *s); fn_grow (&expansion, s - 1, 2); /* moved past the $ */ } } else fn_1grow (&expansion, *s); } fn_1grow (&expansion, 0); ret = FN_STRING (expansion); return ret; }
int ant_usb_find_nodes(ant_cb_foundnode *found_node, void *user) { libusb_device **list; struct libusb_device_descriptor desc; antusb_t *usbant; ssize_t count, i; int ret, usbidx, found = 0; int (*fn_init)(antusb_t *usbant); devlist_t *devlist; if (!opendevices) { DBG("initialising libusb\n"); ret = libusb_init(&_usb); if (ret) { ERR("failed to init libusb\n"); _usb = NULL; goto out; } #if DEBUG == 1 libusb_set_debug(_usb, 3); #endif } count = libusb_get_device_list(_usb, &list); if (count < 0) goto out; for (i = 0; i < count; i++) { for (devlist = opendevices; devlist; devlist = devlist->next) { if (devlist->dev == list[i]) break; } if (devlist) { DBG("skipping open device\n"); continue; } ret = libusb_get_device_descriptor(list[i], &desc); if (ret) { ERR("failed to get device descriptor\n"); continue; } fn_init = NULL; for (usbidx = 0; usbidx < ARRAY_LENGTH(usb_devices); usbidx++) { if (desc.idVendor != usb_devices[usbidx].vid) continue; if (desc.idProduct != usb_devices[usbidx].pid) continue; fn_init = usb_devices[usbidx].init; break; } if (!fn_init) continue; usbant = calloc(1, sizeof(*usbant)); if (!usbant) goto dev_err; snprintf(usbant->ant.name, sizeof(usbant->ant.name), "antusb%d", _id++); usbant->ant.destroy = ant_usb_destroy; usbant->ant.read = ant_usb_read; usbant->ant.write = ant_usb_write; ret = libusb_open(list[i], &usbant->dev); if (ret) goto dev_err; if (libusb_kernel_driver_active(usbant->dev, 0)) { usbant->attached = 1; libusb_detach_kernel_driver(usbant->dev, 0); } ret = libusb_claim_interface(usbant->dev, 0); if (ret) { ERR("failed to claim interface"); } ret = fn_init(usbant); if (ret) goto dev_err; /* add to open device list */ devlist = malloc(sizeof(*devlist)); devlist->dev = list[i]; devlist->usbant = usbant; devlist->prev = NULL; devlist->next = opendevices; if (devlist->next) devlist->next->prev = devlist; opendevices = devlist; found++; found_node(&usbant->ant, user); continue; dev_err: ERR("failed to init device\n"); if (usbant) usbant->ant.destroy(&usbant->ant); } out: libusb_free_device_list(list, 1); if (!opendevices && _usb) { DBG("opened no devices, cleaning up libusb\n"); libusb_exit(_usb); } return found; }