本文整理汇总了C++中DEBUG_PRINTF函数的典型用法代码示例。如果您正苦于以下问题:C++ DEBUG_PRINTF函数的具体用法?C++ DEBUG_PRINTF怎么用?C++ DEBUG_PRINTF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DEBUG_PRINTF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShuDumpShellcode
STATUS
ShuDumpShellcode(
IN PVOID Address
)
{
LPVOID lpStartAddress;
LPVOID lpEndAddress;
CHAR szLogPath[MAX_PATH];
CHAR szShellcodeFile[MAX_PATH];
BYTE *ShellcodeDump;
DWORD dwRead;
DWORD dwWrite;
ERRORINFO err;
HANDLE hShellcodeFile;
STATUS status;
lpStartAddress = Address;
lpEndAddress = Address;
ShellcodeDump = (BYTE *)LocalAlloc(LMEM_ZEROINIT, 2048);
/* IsBadReadPtr sucks so I have to validate memory readability by ReadProcessMemory */
while ( ReadProcessMemory( GetCurrentProcess(),
(LPVOID)((DWORD)lpStartAddress - 4),
ShellcodeDump,
4,
&dwRead)
&& ((DWORD)Address - (DWORD)lpStartAddress) < 0x200 )
{
lpStartAddress = (LPVOID)((DWORD)lpStartAddress - 4);
}
while ( ReadProcessMemory( GetCurrentProcess(),
(LPVOID)((DWORD)lpEndAddress + 4),
ShellcodeDump,
4,
&dwRead)
&& ((DWORD)lpEndAddress - (DWORD)Address) < 0x200)
{
lpEndAddress = (LPVOID)((DWORD)lpEndAddress + 4);
}
sprintf(szShellcodeFile, "\\Shellcode.bin");
strncpy( szLogPath, MCEDP_REGCONFIG.LOG_PATH, MAX_PATH);
strncat(szLogPath, szShellcodeFile, MAX_PATH);
/* Dump shellcode from memory */
ReadProcessMemory( GetCurrentProcess(),
lpStartAddress,
ShellcodeDump,
((DWORD)lpEndAddress - (DWORD)lpStartAddress),
&dwRead);
if ( dwRead != ((DWORD)lpEndAddress - (DWORD)lpStartAddress) )
{
REPORT_ERROR("ReadProcessMemory()", &err);
LocalFree(ShellcodeDump);
return MCEDP_STATUS_INTERNAL_ERROR;
}
hShellcodeFile = CreateFile( szLogPath,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( hShellcodeFile == INVALID_HANDLE_VALUE )
{
REPORT_ERROR("CreateFile()", &err);
LocalFree(ShellcodeDump);
return MCEDP_STATUS_INTERNAL_ERROR;
}
WriteFile( hShellcodeFile,
ShellcodeDump,
dwRead,
&dwWrite,
NULL);
if ( dwRead != dwWrite )
{
REPORT_ERROR("WriteFile()", &err);
LocalFree(ShellcodeDump);
CloseHandle(hShellcodeFile);
return MCEDP_STATUS_INTERNAL_ERROR;
}
DEBUG_PRINTF(LDBG, NULL, "Shellcode Dumped from (0x%p -- 0x%p) Size ( 0x%p )\n", lpStartAddress, lpEndAddress, ((DWORD)lpEndAddress - (DWORD)lpStartAddress));
/* log and dump disassembled version of in-memory shelloce */
status = ShuDisassembleShellcode( lpStartAddress, lpStartAddress, ((DWORD)lpEndAddress - (DWORD)lpStartAddress));
if ( status == MCEDP_STATUS_SUCCESS )
DEBUG_PRINTF(LDBG, NULL, "Shellcode disassembled successfully!\n");
else if ( status == MCEDP_STATUS_PARTIAL_DISASSEMBLE )
DEBUG_PRINTF(LDBG, NULL, "Only a part of Shellcode disassembled successfully!\n");
else
DEBUG_PRINTF(LDBG, NULL, "Faild to disassemble Shellcode!\n");
LocalFree(ShellcodeDump);
//.........这里部分代码省略.........
示例2: freespace_openDevice
LIBFREESPACE_API int freespace_openDevice(FreespaceDeviceId id) {
int idx;
struct FreespaceDeviceStruct* device = freespace_private_getDeviceById(id);
if (device == NULL) {
return FREESPACE_ERROR_NO_DEVICE;
}
if (device->isOpened_) {
// Each device can only be opened once.
return FREESPACE_ERROR_BUSY;
}
for (idx = 0; idx < device->handleCount_; idx++) {
struct FreespaceSubStruct* s = &device->handle_[idx];
if (s->handle_ != NULL) {
// Device was partially (incorrectly) opened.
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_BUSY;
}
if (s->devicePath == NULL) {
// Device was not fully enumerated.
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_NO_DEVICE;
}
DEBUG_WPRINTF(L"Open %s\n", s->devicePath);
s->handle_ = CreateFile(s->devicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
{
DWORD d;
if (!GetHandleInformation(s->handle_, &d)) {
// We do not have the correct handle.
DEBUG_PRINTF("freespace_openDevice failed with code %d\n", GetLastError());
}
}
if (s->handle_ == INVALID_HANDLE_VALUE) {
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_NO_DEVICE;
}
if (!BindIoCompletionCallback(s->handle_, freespace_private_overlappedCallback, 0)) {
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_UNEXPECTED;
}
if (!HidD_SetNumInputBuffers(s->handle_, HID_NUM_INPUT_BUFFERS)) {
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_NO_DEVICE;
}
// Create the read event.
s->readOverlapped_.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (s->readOverlapped_.hEvent == NULL) {
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_UNEXPECTED;
}
s->readOverlapped_.Offset = 0;
s->readOverlapped_.OffsetHigh = 0;
s->readStatus_ = FALSE;
}
device->isOpened_ = TRUE;
// Enable send by initializing all send events.
for (idx = 0; idx < FREESPACE_MAXIMUM_SEND_MESSAGE_COUNT; idx++) {
device->send_[idx].overlapped_.hEvent = NULL;
if (initializeSendStruct(&device->send_[idx]) != FREESPACE_SUCCESS) {
freespace_private_forceCloseDevice(device);
return FREESPACE_ERROR_UNEXPECTED;
}
}
// If async mode has been enabled already, then start the receive
// process going.
if (freespace_instance_->fdAddedCallback_) {
int rc;
rc = initiateAsyncReceives(device);
if (rc != FREESPACE_SUCCESS) {
freespace_private_forceCloseDevice(device);
return rc;
}
}
return FREESPACE_SUCCESS;
}
示例3: freespace_private_read
int freespace_private_read(FreespaceDeviceId id,
uint8_t* message,
int maxLength,
unsigned int timeoutMs,
int* actualLength) {
HANDLE waitEvents[FREESPACE_HANDLE_COUNT_MAX];
int idx;
DWORD bResult;
struct FreespaceDeviceStruct* device = freespace_private_getDeviceById(id);
if (device == NULL) {
return FREESPACE_ERROR_NO_DEVICE;
}
// Start the reads going.
for (idx = 0; idx < device->handleCount_; idx++) {
BOOL bResult;
struct FreespaceSubStruct* s = &device->handle_[idx];
waitEvents[idx] = s->readOverlapped_.hEvent;
// Initiate a ReadFile on anything that doesn't already have
// a ReadFile op pending.
if (!s->readStatus_) {
int lastErr;
bResult = ReadFile(
s->handle_, /* handle to device */
s->readBuffer, /* IN report buffer to fill */
s->info_.inputReportByteLength_, /* input buffer size */
&s->readBufferSize, /* returned buffer size */
&s->readOverlapped_ ); /* long pointer to an OVERLAPPED structure */
lastErr = GetLastError();
if (bResult) {
// Got something immediately, so return it.
*actualLength = min(s->readBufferSize, (unsigned long) maxLength);
memcpy(message, s->readBuffer, *actualLength);
return FREESPACE_SUCCESS;
} else if (lastErr != ERROR_IO_PENDING) {
// Something severe happened to our device!
DEBUG_PRINTF("freespace_read 1: Error on %d : %d\n", idx, lastErr);
return handleDeviceFailure(device, lastErr);
}
s->readStatus_ = TRUE;
}
}
// Wait.
bResult = WaitForMultipleObjects(device->handleCount_, waitEvents, FALSE, timeoutMs);
if (bResult == WAIT_FAILED) {
DEBUG_PRINTF("Error from WaitForMultipleObjects\n");
return FREESPACE_ERROR_IO;
} else if (bResult == WAIT_TIMEOUT) {
return FREESPACE_ERROR_TIMEOUT;
}
// Check which read worked.
for (idx = 0; idx < device->handleCount_; idx++) {
int lastErr;
struct FreespaceSubStruct* s = &device->handle_[idx];
BOOL bResult = GetOverlappedResult(
s->handle_, /* handle to device */
&s->readOverlapped_, /* long pointer to an OVERLAPPED structure */
&s->readBufferSize, /* returned buffer size */
FALSE);
lastErr = GetLastError();
if (bResult) {
// Got something, so report it.
*actualLength = min(s->readBufferSize, (unsigned long) maxLength);
memcpy(message, s->readBuffer, *actualLength);
s->readStatus_ = FALSE;
return FREESPACE_SUCCESS;
} else if (lastErr != ERROR_IO_INCOMPLETE) {
// Something severe happened to our device!
DEBUG_PRINTF("freespace_read 2 : Error on %d : %d\n", idx, lastErr);
return handleDeviceFailure(device, lastErr);
}
}
return FREESPACE_ERROR_IO;
}
示例4: user_task
//.........这里部分代码省略.........
if(dscale_inc < 0.0)
{
red = 255;
blue = 0;
green = 0;
}
else
{
red = 0;
blue = 255;
green = 0;
}
// RGB - YELLOW
tft_drawCircle(windemo, windemo->w/2, windemo->h/2, dscale, tft_color565(red,green,blue));
#endif
degree += deg_inc;
dscale += dscale_inc;
if(degree <= -360)
deg_inc = 4;
if(degree >= 360)
deg_inc = -4;
if(dscale < dscale_max/2)
{
dscale_inc = -dscale_inc;
}
if(dscale > dscale_max)
{
dscale_inc = -dscale_inc;
}
#ifdef WIRECUBE
V.x = degree;
V.y = degree;
V.z = degree;
//time1 = system_get_time();
wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE);
//wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE);
//time2 = system_get_time();
#endif
// Get system voltage 33 = 3.3 volts
adc_sum += system_adc_read();
//adc_sum += system_get_vdd33();
// FIXME atomic access
if(++adc_count == 10)
{
voltage = ((double) adc_sum / 100.0);
adc_count = 0;
adc_sum = 0;
}
// DEBUG_PRINTF("Degree: %d \r\n",(int)degree);
// cube redraw count
count += 1;
tft_set_font(winstats,0);
tft_setpos(winstats,ip_xpos,ip_ypos);
tft_printf(winstats,"%-26s\n", ip_msg);
if(!signal_loop--)
{
signal_loop = 100;
tft_printf(winstats,"CH:%02d, DB:-%02d\n",
wifi_get_channel(),
wifi_station_get_rssi());
signal_loop = 0;
}
tft_setpos(winstats,xpos,ypos);
tft_printf(winstats,"Heap: %d\n", system_get_free_heap_size());
tft_printf(winstats,"Iter:% 9ld, %+7.2f\n", count, degree);
// NTP state machine
ntp_setup();
// get current time
time(&sec);
tft_printf(winstats,"Volt:%2.2f\n%s\n", (float)voltage, ctime(&sec));
#ifdef NETWORK_TEST
poll_network_message(wintest);
#endif
// Buffered get line uses interrupts and queues
if(uart0_gets(buffer,255))
{
DEBUG_PRINTF("Command:%s\n",buffer);
if(!fatfs_tests(buffer))
{
if(!user_tests(buffer))
{
DEBUG_PRINTF("unknow command: %s\n", buffer);
}
}
}
}
示例5: initiateAsyncReceives
static int initiateAsyncReceives(struct FreespaceDeviceStruct* device) {
int idx;
int funcRc = FREESPACE_SUCCESS;
int rc;
struct freespace_message m;
// If no callback or not opened, then don't need to request to receive anything.
if (!device->isOpened_ || (device->receiveCallback_ == NULL && device->receiveMessageCallback_ == NULL)) {
return FREESPACE_SUCCESS;
}
// Initialize a new read operation on all handles that need it.
for (idx = 0; idx < device->handleCount_; idx++) {
struct FreespaceSubStruct* s = &device->handle_[idx];
if (!s->readStatus_) {
for (;;) {
BOOL bResult = ReadFile(
s->handle_, /* handle to device */
s->readBuffer, /* IN report buffer to fill */
s->info_.inputReportByteLength_, /* input buffer size */
&s->readBufferSize, /* returned buffer size */
&s->readOverlapped_ ); /* long pointer to an OVERLAPPED structure */
if (bResult) {
// Got something, so report it.
if (device->receiveCallback_ || device->receiveMessageCallback_) {
if (device->receiveCallback_) {
device->receiveCallback_(device->id_, (char *) (s->readBuffer), s->readBufferSize, device->receiveCookie_, FREESPACE_SUCCESS);
}
if (device->receiveMessageCallback_) {
rc = freespace_decode_message((char *) (s->readBuffer), s->readBufferSize, &m, device->hVer_);
if (rc == FREESPACE_SUCCESS) {
device->receiveMessageCallback_(device->id_, &m, device->receiveMessageCookie_, FREESPACE_SUCCESS);
} else {
device->receiveMessageCallback_(device->id_, NULL, device->receiveMessageCookie_, rc);
DEBUG_PRINTF("freespace_decode_message failed with code %d\n", rc);
}
}
} else {
// If no receiveCallback, then freespace_setReceiveCallback was called to stop
// receives from within the receiveCallback. Bail out to let it do its thing.
return FREESPACE_SUCCESS;
}
} else {
// Error or would block - check below.
break;
}
}
rc = GetLastError();
if (rc == ERROR_IO_PENDING) {
// We got a ReadFile to block, so mark it.
s->readStatus_ = TRUE;
} else {
// Something severe happened to our device!
if (device->receiveCallback_) {
device->receiveCallback_(device->id_, NULL, 0, device->receiveCookie_, rc);
}
if (device->receiveMessageCallback_) {
device->receiveMessageCallback_(device->id_, NULL, device->receiveMessageCookie_, rc);
}
DEBUG_PRINTF("initiateAsyncReceives : Error on %d : %d\n", idx, rc);
return handleDeviceFailure(device, rc);
}
}
}
return funcRc;
}
示例6: statement
/*---------------------------------------------------------------------------*/
static uint8_t statement(void)
{
int token;
string_temp_free();
token = current_token;
/* LET may be omitted.. */
if (token != TOKENIZER_INTVAR && token != TOKENIZER_STRINGVAR)
accept_tok(token);
switch(token) {
case TOKENIZER_QUESTION:
case TOKENIZER_PRINT:
print_statement();
break;
case TOKENIZER_IF:
if_statement();
break;
case TOKENIZER_GO:
go_statement();
return 0;
case TOKENIZER_RETURN:
return_statement();
break;
case TOKENIZER_FOR:
for_statement();
break;
case TOKENIZER_POKE:
poke_statement();
break;
case TOKENIZER_NEXT:
next_statement();
break;
case TOKENIZER_STOP:
stop_statement();
break;
case TOKENIZER_REM:
rem_statement();
break;
case TOKENIZER_DATA:
data_statement();
break;
case TOKENIZER_RANDOMIZE:
randomize_statement();
break;
case TOKENIZER_OPTION:
option_statement();
break;
case TOKENIZER_INPUT:
input_statement();
break;
case TOKENIZER_RESTORE:
restore_statement();
break;
case TOKENIZER_DIM:
dim_statement();
break;
case TOKENIZER_CLS:
cls_statement();
break;
case TOKENIZER_LET:
case TOKENIZER_STRINGVAR:
case TOKENIZER_INTVAR:
let_statement();
break;
default:
DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
syntax_error();
}
return 1;
}
示例7: relation
/*---------------------------------------------------------------------------*/
static void relation(struct typevalue *r1)
{
struct typevalue r2;
int op;
mathexpr(r1);
op = current_token;
DEBUG_PRINTF("relation: token %d\n", op);
/* FIXME: unclear the while is correct here. It's not correct in most
BASIC to write A > B > C, rather relations should be two part linked
with logic */
while(op == TOKENIZER_LT ||
op == TOKENIZER_GT ||
op == TOKENIZER_EQ ||
op == TOKENIZER_NE ||
op == TOKENIZER_LE ||
op == TOKENIZER_GE) {
tokenizer_next();
mathexpr(&r2);
typecheck_same(r1, &r2);
DEBUG_PRINTF("relation: %d %d %d\n", r1->d.i, op, r2.d.i);
if (r1->type == TYPE_INTEGER) {
switch(op) {
case TOKENIZER_LT:
r1->d.i = r1->d.i < r2.d.i;
break;
case TOKENIZER_GT:
r1->d.i = r1->d.i > r2.d.i;
break;
case TOKENIZER_EQ:
r1->d.i = r1->d.i == r2.d.i;
break;
case TOKENIZER_LE:
r1->d.i = r1->d.i <= r2.d.i;
break;
case TOKENIZER_GE:
r1->d.i = r1->d.i >= r2.d.i;
break;
case TOKENIZER_NE:
r1->d.i = r1->d.i != r2.d.i;
break;
}
} else {
int n =*r1->d.p;
if (*r2.d.p < n)
n = *r2.d.p;
n = memcmp(r1->d.p + 1, r2.d.p + 1, n);
if (n == 0) {
if (*r1->d.p > *r2.d.p)
n = 1;
else if (*r1->d.p < *r2.d.p)
n = -1;
}
switch(op) {
case TOKENIZER_LT:
n = (n == -1);
break;
case TOKENIZER_GT:
n = (n == 1);
break;
case TOKENIZER_EQ:
n = (n == 0);
break;
case TOKENIZER_LE:
n = (n != 1);
break;
case TOKENIZER_GE:
n = (n != -1);
break;
case TOKENIZER_NE:
n = (n != 0);
break;
}
r1->d.i = n;
}
op = current_token;
}
r1->type = TYPE_INTEGER;
}
示例8: findSquashers
map<NFAVertex, NFAStateSet> findSquashers(const NGHolder &g, som_type som) {
map<NFAVertex, NFAStateSet> squash;
// Number of bits to use for all our masks. If we're a triggered graph,
// tops have already been assigned, so we don't have to account for them.
const u32 numStates = num_vertices(g);
// Build post-dominator tree.
PostDomTree pdom_tree;
buildPDomTree(g, pdom_tree);
// Build list of vertices by state ID and a set of init states.
vector<NFAVertex> vByIndex(numStates, NFAGraph::null_vertex());
NFAStateSet initStates(numStates);
smgb_cache cache(g);
// Mappings used for SOM mode calculations, otherwise left empty.
unordered_map<NFAVertex, u32> region_map;
vector<DepthMinMax> som_depths;
if (som) {
region_map = assignRegions(g);
som_depths = getDistancesFromSOM(g);
}
for (auto v : vertices_range(g)) {
const u32 vert_id = g[v].index;
DEBUG_PRINTF("vertex %u/%u\n", vert_id, numStates);
assert(vert_id < numStates);
vByIndex[vert_id] = v;
if (is_any_start(v, g) || !in_degree(v, g)) {
initStates.set(vert_id);
}
}
for (u32 i = 0; i < numStates; i++) {
NFAVertex v = vByIndex[i];
assert(v != NFAGraph::null_vertex());
const CharReach &cr = g[v].char_reach;
/* only non-init cyclics can be squashers */
if (!hasSelfLoop(v, g) || initStates.test(i)) {
continue;
}
DEBUG_PRINTF("state %u is cyclic\n", i);
NFAStateSet mask(numStates), succ(numStates), pred(numStates);
buildSquashMask(mask, g, v, cr, initStates, vByIndex, pdom_tree, som,
som_depths, region_map, cache);
buildSucc(succ, g, v);
buildPred(pred, g, v);
const auto &reports = g[v].reports;
for (size_t j = succ.find_first(); j != succ.npos;
j = succ.find_next(j)) {
NFAVertex vj = vByIndex[j];
NFAStateSet pred2(numStates);
buildPred(pred2, g, vj);
if (pred2 == pred) {
DEBUG_PRINTF("adding the sm from %zu to %u's sm\n", j, i);
NFAStateSet tmp(numStates);
buildSquashMask(tmp, g, vj, cr, initStates, vByIndex, pdom_tree,
som, som_depths, region_map, cache);
mask &= tmp;
}
}
for (size_t j = pred.find_first(); j != pred.npos;
j = pred.find_next(j)) {
NFAVertex vj = vByIndex[j];
NFAStateSet succ2(numStates);
buildSucc(succ2, g, vj);
/* we can use j as a basis for squashing if its succs are a subset
* of ours */
if ((succ2 & ~succ).any()) {
continue;
}
if (som) {
/* We cannot use j to add to the squash mask of v if it may
* have an earlier start of match offset. ie for us j as a
* basis for the squash mask of v we require:
* maxSomDist(j) <= minSomDist(v)
*/
/* ** TODO ** */
const depth &max_som_dist_j =
som_depths[g[vj].index].max;
const depth &min_som_dist_v =
som_depths[g[v].index].min;
if (max_som_dist_j > min_som_dist_v ||
max_som_dist_j.is_infinite()) {
/* j can't be used as it may be storing an earlier SOM */
continue;
}
}
const CharReach &crv = g[vj].char_reach;
//.........这里部分代码省略.........
示例9: rtems_ftpfs_open_ctrl_connection
static int rtems_ftpfs_open_ctrl_connection(
rtems_ftpfs_entry *e,
const char *user,
const char *password,
const char *hostname,
uint32_t *client_address,
bool verbose,
const struct timeval *timeout
)
{
int rv = 0;
int eno = 0;
rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
struct in_addr address = { .s_addr = 0 };
struct sockaddr_in sa;
socklen_t size = 0;
/* Create the socket for the control connection */
e->ctrl_socket = socket(AF_INET, SOCK_STREAM, 0);
if (e->ctrl_socket < 0) {
return ENOMEM;
}
/* Set up the server address from the hostname */
if (inet_aton(hostname, &address) == 0) {
/* Try to get the address by name */
struct hostent *he = gethostbyname(hostname);
if (he != NULL) {
memcpy(&address, he->h_addr, sizeof(address));
} else {
return ENOENT;
}
}
rtems_ftpfs_create_address(&sa, address.s_addr, htons(RTEMS_FTPFS_CTRL_PORT));
DEBUG_PRINTF("server = %s\n", inet_ntoa(sa.sin_addr));
/* Open control connection */
rv = connect(
e->ctrl_socket,
(struct sockaddr *) &sa,
sizeof(sa)
);
if (rv != 0) {
return ENOENT;
}
/* Set control connection timeout */
eno = rtems_ftpfs_set_connection_timeout(e->ctrl_socket, timeout);
if (eno != 0) {
return eno;
}
/* Get client address */
size = rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
rv = getsockname(
e->ctrl_socket,
(struct sockaddr *) &sa,
&size
);
if (rv != 0) {
return ENOMEM;
}
*client_address = ntohl(sa.sin_addr.s_addr);
DEBUG_PRINTF("client = %s\n", inet_ntoa(sa.sin_addr));
/* Now we should get a welcome message from the server */
reply = rtems_ftpfs_get_reply(e, NULL, NULL, verbose);
if (reply != RTEMS_FTPFS_REPLY_2) {
return ENOENT;
}
/* Send USER command */
reply = rtems_ftpfs_send_command(e, "USER ", user, verbose);
if (reply == RTEMS_FTPFS_REPLY_3) {
/* Send PASS command */
reply = rtems_ftpfs_send_command(e, "PASS ", password, verbose);
if (reply != RTEMS_FTPFS_REPLY_2) {
return EACCES;
}
/* TODO: Some server may require an account */
} else if (reply != RTEMS_FTPFS_REPLY_2) {
return EACCES;
}
/* Send TYPE command to set binary mode for all data transfers */
reply = rtems_ftpfs_send_command(e, "TYPE I", NULL, verbose);
if (reply != RTEMS_FTPFS_REPLY_2) {
return EIO;
}
return 0;
}
static int rtems_ftpfs_open_data_connection_active(
rtems_ftpfs_entry *e,
uint32_t client_address,
const char *file_command,
const char *filename,
//.........这里部分代码省略.........
示例10: zix_tree_remove
ZIX_API ZixStatus
zix_tree_remove(ZixTree* t, ZixTreeIter* ti)
{
ZixTreeNode* const n = ti;
ZixTreeNode** pp = NULL; // parent pointer
ZixTreeNode* to_balance = n->parent; // lowest node to balance
int8_t d_balance = 0; // delta(balance) for n->parent
DEBUG_PRINTF("*** REMOVE %ld\n", (intptr_t)n->data);
if ((n == t->root) && !n->left && !n->right) {
t->root = NULL;
if (t->destroy) {
t->destroy(n->data);
}
free(n);
--t->size;
assert(t->size == 0);
return ZIX_STATUS_SUCCESS;
}
// Set pp to the parent pointer to n, if applicable
if (n->parent) {
assert(n->parent->left == n || n->parent->right == n);
if (n->parent->left == n) { // n is left child
pp = &n->parent->left;
d_balance = 1;
} else { // n is right child
assert(n->parent->right == n);
pp = &n->parent->right;
d_balance = -1;
}
}
assert(!pp || *pp == n);
int height_change = 0;
if (!n->left && !n->right) {
// n is a leaf, just remove it
if (pp) {
*pp = NULL;
to_balance = n->parent;
height_change = (!n->parent->left && !n->parent->right) ? -1 : 0;
}
} else if (!n->left) {
// Replace n with right (only) child
if (pp) {
*pp = n->right;
to_balance = n->parent;
} else {
t->root = n->right;
}
n->right->parent = n->parent;
height_change = -1;
} else if (!n->right) {
// Replace n with left (only) child
if (pp) {
*pp = n->left;
to_balance = n->parent;
} else {
t->root = n->left;
}
n->left->parent = n->parent;
height_change = -1;
} else {
// Replace n with in-order successor (leftmost child of right subtree)
ZixTreeNode* replace = n->right;
while (replace->left) {
assert(replace->left->parent == replace);
replace = replace->left;
}
// Remove replace from parent (replace_p)
if (replace->parent->left == replace) {
height_change = replace->parent->right ? 0 : -1;
d_balance = 1;
to_balance = replace->parent;
replace->parent->left = replace->right;
} else {
assert(replace->parent == n);
height_change = replace->parent->left ? 0 : -1;
d_balance = -1;
to_balance = replace->parent;
replace->parent->right = replace->right;
}
if (to_balance == n) {
to_balance = replace;
}
if (replace->right) {
replace->right->parent = replace->parent;
}
replace->balance = n->balance;
// Swap node to delete with replace
if (pp) {
*pp = replace;
} else {
//.........这里部分代码省略.........
示例11: buildSquashMask
/**
* Builds a squash mask based on the pdom tree of v and the given char reach.
* The built squash mask is a bit conservative for non-dot cases and could
* be improved with a bit of thought.
*/
static
void buildSquashMask(NFAStateSet &mask, const NGHolder &g, NFAVertex v,
const CharReach &cr, const NFAStateSet &init,
const vector<NFAVertex> &vByIndex, const PostDomTree &tree,
som_type som, const vector<DepthMinMax> &som_depths,
const ue2::unordered_map<NFAVertex, u32> ®ion_map,
smgb_cache &cache) {
DEBUG_PRINTF("build base squash mask for vertex %u)\n",
g[v].index);
vector<NFAVertex> q;
PostDomTree::const_iterator it = tree.find(v);
if (it != tree.end()) {
q.insert(q.end(), it->second.begin(), it->second.end());
}
const u32 v_index = g[v].index;
while (!q.empty()) {
NFAVertex u = q.back();
q.pop_back();
const CharReach &cru = g[u].char_reach;
if ((cru & ~cr).any()) {
/* bail: bad cr on vertex u */
/* TODO: this could be better
*
* we still need to ensure that we record any paths leading to u.
* Hence all vertices R which can reach u must be excluded from the
* squash mask. Note: R != pdom(u) and there may exist an x in (R -
* pdom(u)) which is in pdom(y) where y is in q. Clear ?
*/
mask.set();
return;
}
const u32 u_index = g[u].index;
if (som) {
/* We cannot add a state u to the squash mask of v if it may have an
* earlier start of match offset. ie for us to add a state u to v
* maxSomDist(u) <= minSomDist(v)
*/
const depth &max_som_dist_u = som_depths[u_index].max;
const depth &min_som_dist_v = som_depths[v_index].min;
if (max_som_dist_u.is_infinite()) {
/* it is hard to tell due to the INF if u can actually store an
* earlier SOM than w (state we are building the squash mask
* for) - need to think more deeply
*/
if (mustBeSetBefore(u, v, g, cache)
&& !somMayGoBackwards(u, g, region_map, cache)) {
DEBUG_PRINTF("u %u v %u\n", u_index, v_index);
goto squash_ok;
}
}
if (max_som_dist_u > min_som_dist_v) {
/* u can't be squashed as it may be storing an earlier SOM */
goto add_children_to_queue;
}
}
squash_ok:
mask.set(u_index);
DEBUG_PRINTF("pdom'ed %u\n", u_index);
add_children_to_queue:
it = tree.find(u);
if (it != tree.end()) {
q.insert(q.end(), it->second.begin(), it->second.end());
}
}
if (cr.all()) {
/* the init states aren't in the pdom tree. If all their succ states
* are set (or v), we can consider them post dominated */
/* Note: init states will always result in a later som */
for (size_t i = init.find_first(); i != init.npos;
i = init.find_next(i)) {
/* Yes vacuous patterns do exist */
NFAVertex iv = vByIndex[i];
for (auto w : adjacent_vertices_range(iv, g)) {
if (w == g.accept || w == g.acceptEod) {
DEBUG_PRINTF("skipping %zu due to vacuous accept\n", i);
goto next_init_state;
}
u32 vert_id = g[w].index;
if (w != iv && w != v && !mask.test(vert_id)) {
DEBUG_PRINTF("skipping %zu due to %u\n", i, vert_id);
//.........这里部分代码省略.........
示例12: zix_tree_insert
ZIX_API ZixStatus
zix_tree_insert(ZixTree* t, void* e, ZixTreeIter** ti)
{
DEBUG_PRINTF("**** INSERT %ld\n", (intptr_t)e);
int cmp = 0;
ZixTreeNode* n = t->root;
ZixTreeNode* p = NULL;
// Find the parent p of e
while (n) {
p = n;
cmp = t->cmp(e, n->data, t->cmp_data);
if (cmp < 0) {
n = n->left;
} else if (cmp > 0) {
n = n->right;
} else if (t->allow_duplicates) {
n = n->right;
} else {
if (ti) {
*ti = n;
}
DEBUG_PRINTF("%ld EXISTS!\n", (intptr_t)e);
return ZIX_STATUS_EXISTS;
}
}
// Allocate a new node n
if (!(n = (ZixTreeNode*)malloc(sizeof(ZixTreeNode)))) {
return ZIX_STATUS_NO_MEM;
}
memset(n, '\0', sizeof(ZixTreeNode));
n->data = e;
n->balance = 0;
if (ti) {
*ti = n;
}
bool p_height_increased = false;
// Make p the parent of n
n->parent = p;
if (!p) {
t->root = n;
} else {
if (cmp < 0) {
assert(!p->left);
assert(p->balance == 0 || p->balance == 1);
p->left = n;
--p->balance;
p_height_increased = !p->right;
} else {
assert(!p->right);
assert(p->balance == 0 || p->balance == -1);
p->right = n;
++p->balance;
p_height_increased = !p->left;
}
}
DUMP(t);
// Rebalance if necessary (at most 1 rotation)
assert(!p || p->balance == -1 || p->balance == 0 || p->balance == 1);
if (p && p_height_increased) {
int height_change = 0;
for (ZixTreeNode* i = p; i && i->parent; i = i->parent) {
if (i == i->parent->left) {
if (--i->parent->balance == -2) {
zix_tree_rebalance(t, i->parent, &height_change);
break;
}
} else {
assert(i == i->parent->right);
if (++i->parent->balance == 2) {
zix_tree_rebalance(t, i->parent, &height_change);
break;
}
}
if (i->parent->balance == 0) {
break;
}
}
}
DUMP(t);
++t->size;
#ifdef ZIX_TREE_VERIFY
if (!verify(t, t->root)) {
return ZIX_STATUS_ERROR;
}
#endif
return ZIX_STATUS_SUCCESS;
}
示例13: cmodprint
int cmodprint (MODEL *model){
int i, j, n;
struct MODEL_PATH *parent;
char **names;
FILE *f;
int l;
char *fname;
VECTOR_3D size;
VECTOR_3D centre;
float radius;
float rotate;
char *movetype;
VECTOR_3D min, max;
/* We only want LOD0 */
if (model->path.lod != 1){
return 0;
}
/* We don't want destroyed stuff */
if (strstr (model->path.name, "-destroyed")){
return 0;
}
parent = &model->path;
n = model->path.nr_parents;
names = malloc ((n + 1) * sizeof(char *));
ASSERT_PERROR (names != NULL, "Unable to allocate memory for model path");
memset (names, 0, (n + 1) * sizeof(char *));
parent = &model->path;
l = 0;
for (i = n; i >= 0; i--){
names[i] = parent->name;
DEBUG_PRINTF ("# Parent: %s\n", names[i]);
l += strlen(names[i]) + 1;
parent = parent->parent;
}
DEBUG_PRINTF ("# Length: %d\n", l);
fname = malloc (l + 6);
ASSERT_PERROR (fname != NULL, "Unable to allocate memory for model path");
memset (fname, 0, l + 6);
strcpy (fname, names[0]);
for (i=2; i <= n; i++){
strcat (fname, ".");
strcat (fname, names[i]);
}
strcat (fname, ".cmod");
free (names);
f = fopen (fname, "wb");
ASSERT_PERROR (f != NULL, "Unable to open output file");
DEBUG_PRINTF ("# Starting model\n");
fprintf (f, "#celmodel__ascii\n\n");
fprintf (f, "# name: %s\n", fname);
min = rotate_axis (model->min, model->axis);
max = rotate_axis (model->max, model->axis);
size.x = (model->max.x - model->min.x) / 2;
size.y = (model->max.y - model->min.y) / 2;
size.z = (model->max.z - model->min.z) / 2;
centre.x = model->min.x + size.x;
centre.y = model->min.y + size.y;
centre.z = model->min.z + size.z;
radius = size.x;
radius = (size.y > radius) ? size.y : radius;
radius = (size.z > radius) ? size.z : radius;
switch (model->movetype){
case -1: movetype = "None"; break;
case 0: movetype = "Linear"; break;
case 1: movetype = "Rotate"; break;
case 2: movetype = "Turret"; break;
default: movetype = "Unknown";
}
DEBUG_PRINTF ("# Geometric:\n"
"# radius: %f\n"
"# centre: [ %f %f %f ]\n"
"# Celestia:\n"
"# radius: %f\n"
"# centre: [ %f %f %f ]\n"
"# \n"
"# offset: [ %f %f %f ]\n"
"# axis: [ %f %f %f ]\n"
"# movement: %s\n"
"# Properties:\n",
model->radius,
model->centre.z, model->centre.y, model->centre.x,
radius,
centre.z, centre.y, centre.x,
model->offset.z, model->offset.y, model->offset.x,
model->axis.z, model->axis.y, model->axis.x,
movetype);
rotate = 8.64e24;
#ifdef DEBUGAXIS
if (model->movetype == 1 || model->movetype == 2){
rotate = 3.6;
}
#endif
//.........这里部分代码省略.........
示例14: main_thread
int main_thread(SceSize args, void *argp)
{
struct PsplinkContext *ctx;
int ret;
SceUInt timeout;
SceUID thids[20];
int count;
int intc;
printf("PSPLink USB GDBServer (c) 2k7 TyRaNiD\n");
if(!initialise(args, argp))
{
printf("Usage: usbgdb.prx program [args]\n");
sceKernelExitDeleteThread(0);
}
if(usbAsyncRegister(ASYNC_GDB, &g_endp) < 0)
{
printf("Could not register GDB provider\n");
sceKernelExitDeleteThread(0);
}
usbWaitForConnect();
memset(&g_handler, 0, sizeof(g_handler));
g_handler.size = sizeof(g_handler);
g_handler.membase = g_context.info.text_addr;
g_handler.memtop = g_context.info.text_addr + g_context.info.text_size;
g_handler.mbox = sceKernelCreateMbx("GDBMbx", 0, NULL);
if(g_handler.mbox < 0)
{
printf("Could not create message box\n");
sceKernelExitDeleteThread(0);
}
if(debugRegisterEventHandler(&g_handler) < 0)
{
printf("Could not register event handler\n");
sceKernelExitDeleteThread(0);
}
if(GdbHandleException(&g_context.ctx))
{
while(1)
{
timeout = GDB_POLL_TIMEOUT;
ret = debugWaitDebugEvent(&g_handler, &ctx, &timeout);
if(ret == 0)
{
DEBUG_PRINTF("ctx %p, epc 0x%08X\n", ctx, ctx->regs.epc);
ret = GdbHandleException(ctx);
sceKernelWakeupThread(ctx->thid);
if(ret == 0)
{
break;
}
}
else if(ret == SCE_KERNEL_ERROR_WAIT_TIMEOUT)
{
unsigned char ch;
if(peekDebugChar(&ch) && (ch == 3))
{
DEBUG_PRINTF("Break Issued\n");
intc = pspSdkDisableInterrupts();
count = psplinkReferThreadsByModule(SCE_KERNEL_TMID_Thread, g_context.uid, thids, 20);
if(count > 0)
{
/* We just break the first thread */
/* Could in theory break on the thread which we are interested in ? */
debugBreakThread(thids[0]);
}
pspSdkEnableInterrupts(intc);
/* Should have a fallback if it just wont stop
GdbHandleException(&g_context.ctx);
*/
}
continue;
}
else
{
printf("Error waiting for debug event 0x%08X\n", ret);
break;
}
}
}
debugUnregisterEventHandler(&g_handler);
sceKernelExitDeleteThread(0);
return 0;
}
示例15: expandCyclic
static
bool expandCyclic(NGHolder &h, NFAVertex v) {
DEBUG_PRINTF("inspecting %zu\n", h[v].index);
bool changes = false;
auto v_preds = preds(v, h);
auto v_succs = succs(v, h);
set<NFAVertex> start_siblings;
set<NFAVertex> end_siblings;
CharReach &v_cr = h[v].char_reach;
/* We need to find start vertices which have all of our preds.
* As we have a self loop, it must be one of our succs. */
for (auto a : adjacent_vertices_range(v, h)) {
auto a_preds = preds(a, h);
if (a_preds == v_preds && isutf8start(h[a].char_reach)) {
DEBUG_PRINTF("%zu is a start v\n", h[a].index);
start_siblings.insert(a);
}
}
/* We also need to find full cont vertices which have all our own succs;
* As we have a self loop, it must be one of our preds. */
for (auto a : inv_adjacent_vertices_range(v, h)) {
auto a_succs = succs(a, h);
if (a_succs == v_succs && h[a].char_reach == UTF_CONT_CR) {
DEBUG_PRINTF("%zu is a full tail cont\n", h[a].index);
end_siblings.insert(a);
}
}
for (auto s : start_siblings) {
if (out_degree(s, h) != 1) {
continue;
}
const CharReach &cr = h[s].char_reach;
if (cr.isSubsetOf(UTF_TWO_START_CR)) {
if (end_siblings.find(*adjacent_vertices(s, h).first)
== end_siblings.end()) {
DEBUG_PRINTF("%zu is odd\n", h[s].index);
continue;
}
} else if (cr.isSubsetOf(UTF_THREE_START_CR)) {
NFAVertex m = *adjacent_vertices(s, h).first;
if (h[m].char_reach != UTF_CONT_CR
|| out_degree(m, h) != 1) {
continue;
}
if (end_siblings.find(*adjacent_vertices(m, h).first)
== end_siblings.end()) {
DEBUG_PRINTF("%zu is odd\n", h[s].index);
continue;
}
} else if (cr.isSubsetOf(UTF_FOUR_START_CR)) {
NFAVertex m1 = *adjacent_vertices(s, h).first;
if (h[m1].char_reach != UTF_CONT_CR
|| out_degree(m1, h) != 1) {
continue;
}
NFAVertex m2 = *adjacent_vertices(m1, h).first;
if (h[m2].char_reach != UTF_CONT_CR
|| out_degree(m2, h) != 1) {
continue;
}
if (end_siblings.find(*adjacent_vertices(m2, h).first)
== end_siblings.end()) {
DEBUG_PRINTF("%zu is odd\n", h[s].index);
continue;
}
} else {
DEBUG_PRINTF("%zu is bad\n", h[s].index);
continue;
}
v_cr |= cr;
clear_vertex(s, h);
changes = true;
}
if (changes) {
v_cr |= UTF_CONT_CR; /* we need to add in cont reach */
v_cr.set(0xc0); /* we can also add in the forbidden bytes as we require
* valid unicode data */
v_cr.set(0xc1);
v_cr |= CharReach(0xf5, 0xff);
}
return changes;
}