int gdb_rx_mem(unsigned char *addr, size_t size) { unsigned char *p; void *prev; void *wctx; jmp_buf jb; size_t cnt; int ret; unsigned char c; if (size * 2 != gdb_rxsz) return (-1); wctx = gdb_begin_write(); prev = kdb_jmpbuf(jb); ret = setjmp(jb); if (ret == 0) { p = addr; cnt = size; while (cnt-- > 0) { c = (C2N(gdb_rxp[0]) << 4) & 0xf0; c |= C2N(gdb_rxp[1]) & 0x0f; *p++ = c; gdb_rxsz -= 2; gdb_rxp += 2; } kdb_cpu_sync_icache(addr, size); } (void)kdb_jmpbuf(prev); gdb_end_write(wctx); return ((ret == 0) ? 1 : 0); }
void ti_dial_predict_load(const char * fn) { FILE * fp; char buf[120]; ti_dial_predict_clear(); fp = fopen(fn, "r"); if (fp) { while (fgets(buf, 120, fp)) { if (strlen(buf)>=7 && !(buf[0]=='#' && buf[1]=='#')) { strncpy(ti_dial_predict[C2N(buf[0])][C2N(buf[1])], &buf[2], 5); } } fclose(fp); } }
int gdb_rx_varhex(uintmax_t *vp) { uintmax_t v; int c, neg; c = gdb_rx_char(); neg = (c == '-') ? 1 : 0; if (neg == 1) c = gdb_rx_char(); if (!isxdigit(c)) { gdb_rxp -= ((c == -1) ? 0 : 1) + neg; gdb_rxsz += ((c == -1) ? 0 : 1) + neg; return (-1); } v = 0; do { v <<= 4; v += C2N(c); c = gdb_rx_char(); } while (isxdigit(c)); if (c != -1) { gdb_rxp--; gdb_rxsz++; } *vp = (neg) ? -v : v; return (0); }
int gdb_rx_begin(void) { int c, cksum; gdb_rxp = NULL; do { /* * Wait for the start character, ignore all others. * XXX needs a timeout. */ while ((c = gdb_getc()) != '$') ; /* Read until a # or end of buffer is found. */ cksum = 0; gdb_rxsz = 0; while (gdb_rxsz < sizeof(gdb_rxbuf) - 1) { c = gdb_getc(); if (c == '#') break; gdb_rxbuf[gdb_rxsz++] = c; cksum += c; } gdb_rxbuf[gdb_rxsz] = 0; cksum &= 0xff; /* Bail out on a buffer overflow. */ if (c != '#') { gdb_cur->gdb_putc('-'); return (ENOSPC); } c = gdb_getc(); cksum -= (C2N(c) << 4) & 0xf0; c = gdb_getc(); cksum -= C2N(c) & 0x0f; gdb_cur->gdb_putc((cksum == 0) ? '+' : '-'); if (cksum != 0) printf("GDB: packet `%s' has invalid checksum\n", gdb_rxbuf); } while (cksum != 0); gdb_rxp = gdb_rxbuf; return (0); }
int next_num(int num) { char num_str[10]; int index, len, i, least_idx, least_num; int num_array[9], tmp; memset(num_str, 0, 10); sprintf(num_str, "%d", num); len = strlen(num_str); for (i = 0; i < len; i++) { num_array[i] = C2N(num_str[i]); } for (i = 0; i < len - 1; i++) { if (num_array[i] < num_array[i + 1]) index = i; } for (i = index + 1, least_num = 9; i < len; i++) { if (num_array[i] < least_num && num_array[i] > num_array[index]) { least_idx = i; least_num = num_array[i]; } } tmp = num_array[index]; num_array[index] = num_array[least_idx]; num_array[least_idx] = tmp; quick_sort(num_array, index + 1, len - 1); for (i = 0; i < len; i++) { num_str[i] = N2C(num_array[i]); } return atoi(num_str); }
int ti_dial_get_char(int w) { if (w<0) { w = ti_dial_charlist_pos; } switch (ti_dial_mode) { case -2: case -1: case 9: case 11: return ti_dial_cmstring[w]; break; case 0: return ti_dial_charlist[w]; break; case 1: return ti_dial_charlist_n[w]; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: switch (w) { case 32: return 'a'; break; case 33: return 'A'; break; case 34: return '0'; break; case 35: return '@'; break; case 36: return 228; break; case 37: return 196; break; case 38: return 169; break; case 39: return 'M'; break; default: return ti_dial_flchars[ti_dial_mode-2][w]; break; } break; case 10: if (w == 0) { return ' '; } else if (w<6) { int c = ti_dial_predict[C2N(ti_dial_ppchar)][C2N(ti_dial_pchar)][w-1]; if (!c) c = ti_dial_predict[10][C2N(ti_dial_pchar)][w-1]; if (!c) c = ti_dial_predict[C2N(ti_dial_ppchar)][10][w-1]; if (!c) c = ti_dial_predict[10][10][w-1]; return c; } else { int c = ti_dial_predict[C2N(ti_dial_ppchar)][C2N(ti_dial_pchar)][0]; if (!c) c = ti_dial_predict[10][C2N(ti_dial_pchar)][0]; if (!c) c = ti_dial_predict[C2N(ti_dial_ppchar)][10][0]; if (!c) c = ti_dial_predict[10][10][0]; w -= 6; if (strchr(ti_dial_numberstarters,c) || isdigit(c)) { if (w<10) { return ti_dial_number[w]; } else { w -= 10; } if (w<23) { return ti_dial_stuff1[w]; } else { w -= 23; } if (w<26) { return ti_dial_eta_lc[w]; } else { w -= 26; } if (w<26) { return ti_dial_eta_uc[w]; } else { w -= 26; } if (w<10) { return ti_dial_stuff2[w]; } else { w -= 10; } return ' '; } else if (isupper(c)) { if (w<26) { return ti_dial_eta_uc[w]; } else { w -= 26; } if (w<26) { return ti_dial_eta_lc[w]; } else { w -= 26; } if (w<23) { return ti_dial_stuff1[w]; } else { w -= 23; } if (w<10) { return ti_dial_number[w]; } else { w -= 10; } if (w<10) { return ti_dial_stuff2[w]; } else { w -= 10; } return ' '; } else { if (w<26) { return ti_dial_eta_lc[w]; } else { w -= 26; } if (w<26) { return ti_dial_eta_uc[w]; } else { w -= 26; } if (w<23) { return ti_dial_stuff1[w]; } else { w -= 23; } if (w<10) { return ti_dial_number[w]; } else { w -= 10; } if (w<10) { return ti_dial_stuff2[w]; } else { w -= 10; } return ' '; } } break; } return 0; }
const char * color_space_name(color_space space) { #define C2N(a) case a: return #a switch (space) { C2N(B_RGB24); C2N(B_RGB32); C2N(B_RGBA32); C2N(B_RGB32_BIG); C2N(B_RGBA32_BIG); C2N(B_GRAY8); C2N(B_GRAY1); C2N(B_RGB16); C2N(B_RGB15); C2N(B_RGBA15); C2N(B_CMAP8); default: return "Unknown!"; }; #undef C2N };
BOOL CWedApp::InitInstance() { CString str; char *ptr; //SetDialogBkColor(0x00ff0000, 0xffffff); WaitCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT); NormalCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); GetModuleFileName(AfxGetInstanceHandle(), approot, MAX_PATH); CTime ct = CTime::GetCurrentTime(); CString datestr = ct.Format("%A, %B %d, %Y - %I:%M %p"); C2N(); P2N("\r\nStarted WED application at %s\r\n", datestr); //P2N("AppRoot=%s\r\n", approot); //CString desktop; //GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, desktop); //desktop += "wed"; //P2N("Desktop special: %s\r\n", desktop); // Create initial desktop xcpt folder //if(access(desktop, 0) == -1) // { // P2N("Making %s\r\n", desktop); // //message("Created desktop folder."); // _mkdir(desktop); // } ptr = strrchr(approot, '\\'); if(ptr) *(ptr+1) = '\0'; //dataroot = (CString)approot + "wed\\"; GetSpecialFolder(CSIDL_PERSONAL, dataroot); dataroot += "WedData\\"; P2N("Wed user data directory: %s\r\n", dataroot); if(access(dataroot, 0)) { if(mkdir(dataroot)) { //P2N("Cannot create data root dir\r\n"); } } ////////////////////////////////////////////////////////////////////// // Create data dirs str = dataroot; str += "data"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create data dir\r\n"); } } str = dataroot; str += "macros"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create macro dir\r\n"); } } str = dataroot; str += "holdings"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create holders dir\r\n"); } } str = dataroot; str += "coco"; // Check if coco dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create coco dir\r\n"); } } str = dataroot; str += "backup"; // Check if state dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create state dir\r\n"); } } str = dataroot; str += "template"; // Check if state dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create template dir\r\n"); } } //P2N("Started Application: %s %s\r\n", // m_pszAppName, approot); getcwd(str.GetBuffer(MAX_PATH), MAX_PATH); str.ReleaseBuffer(); //P2N("Initial dir: %s\r\n", str); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox("Failed OLE library init, OLE functions will not be available"); } AfxEnableControlContainer(); #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("RobotMonkeySoftware")); LoadStdProfileSettings(6); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. pDocTemplate = new CMultiDocTemplate( IDR_WEDTYPE, RUNTIME_CLASS(CWedDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CWedView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; // Global m_pMainWnd = pMainFrame; // Get resources we need: // 1. Fonts CString fontname = GetProfileString(strConfig, strFontName, "Courier"); int size = GetProfileInt(strConfig, strFontSize, 10); int weight = GetProfileInt(strConfig, strFontWeight, 0); int italic = GetProfileInt(strConfig, strFontItalic, 0); if(!ff.CreateFont(size, 0, 0, 0, weight, italic, 0, 0, 0, 0, 0, 0, FIXED_PITCH, fontname)) { AfxMessageBox("Cannot set font"); } if(!ff.GetLogFont(&fflf)) { AfxMessageBox("Cannot get font parameters"); } // 2. Printer fonts if(!pp.CreateFont(80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FF_MODERN, "system")) { MessageBox(NULL, "Cannot set font", "Wed", 0); } if(!pp.GetLogFont(&pplf)) { MessageBox(NULL, "Cannot get font parameters", "Wed", 0); } // Get colors bgcol = GetProfileInt(strConfig, strColorBg, bgcol); fgcol = GetProfileInt(strConfig, strColorFg, fgcol); selcol = GetProfileInt(strConfig, strColorSel , selcol ); cselcol = GetProfileInt(strConfig, strColorCSel, cselcol); cadd = GetProfileInt(strConfig, strColorAdd , cadd ); cdel = GetProfileInt(strConfig, strColorDel , cdel ); cchg = GetProfileInt(strConfig, strColorChg , cchg ); comm = GetProfileInt(strConfig, strColorComm, comm ); srcc = GetProfileInt(strConfig, strColorSrc , srcc ); clng = GetProfileInt(strConfig, strColorLong, clng ); // Bimaps caret.LoadBitmap(IDB_BITMAP1); backwrap = GetProfileInt(strConfig, strBackWrap , 0); Tab2Space = GetProfileInt(strConfig, strTab2Space, 0); tabstop = GetProfileInt(strConfig, strTabStop, 4); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if(cmdInfo.m_strFileName != "") { comline = TRUE; OpenDocumentFile(cmdInfo.m_strFileName); } else { // DON'T display a new MDI child window during startup!!! cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; } // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // Key settings // Figure out last usage time ... int last = GetProfileInt(strConfig, "strLastUsage", 0); use = GetProfileInt(strConfig, "strUsage", 0); //P2N("Usage count %d \r\n", use); // First time ever, display initial file if(!use) { OpenDocumentFile("Welcome.txt"); comline = TRUE; if(currentedit) { } } use++; CTime tt = CTime::GetCurrentTime(); CTimeSpan t(tt.GetTime() - (time_t)last); //P2N("Time diff of last fire %d -- %d \r\n", // t.GetTotalSeconds(), (int)tt.GetTime()); YieldToWin() ; // Show sign banner only if more then 60 seconds passed //if(t.GetTotalSeconds() > 60) { spp.Create(IDD_DIALOG5, NULL); spp.Show(); } YieldToWin() ; //if(GetKeyState(VK_SHIFT)) // { // AfxMessageBox("SHIFT HELD on startup\r\n"); // return(TRUE); // } // The main window has been initialized ... // Show and update it. m_nCmdShow = GetProfileInt(strConfig, "WindowState", 1); pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); int num = GetProfileInt(strSection, strIntItem, 0); // De-serialize hash map CMap < int, int&, CString, CString& > HashMap; CFile cf; CString fname; fname.Format("%s%s", dataroot, "macros\\hashes.000"); if( cf.Open( fname, CFile::modeRead)) { CArchive ar( &cf, CArchive::load); HashMap.Serialize(ar); } else { //P2N("Cannot open hash map file: %s\r\n", fname); } POSITION rpos; rpos = HashMap.GetStartPosition(); while(rpos) { int key; CString val; HashMap.GetNextAssoc(rpos, key, val); //P2N("In Hashlist: %x %s\r\n", key, val); } if(!comline) { // Reopen old documents: CString buf2, file; for(int count1 = 1; count1 <= num; count1++) { CWedDoc *doc = NULL; buf2.Format("%d", count1); file = GetProfileString(strSection, strStringItem + buf2); //P2N("Reloading file: '%s' at %s\r\n", file, buf2); // Empty file, no action if(file == "") continue; doc = (CWedDoc*)OpenDocumentFile(file); if(YieldToWinEx()) break; //P2N("After Reloading file: %s at %s\r\n", file, buf2); if(doc) { ASSERT_VALID(doc); // Document had an error if(doc->ssel.m_err) break; int lrow, lcol; lrow = GetProfileInt(strSection, strStringItem + buf2 + "row", 0); lcol = GetProfileInt(strSection, strStringItem + buf2 + "col", 0); // Update cursor positions ... POSITION pos = doc->GetFirstViewPosition(); for(;;) { if(!pos) break; CWedView *cv = (CWedView*)doc->GetNextView(pos); if(cv) { ASSERT_VALID(cv); cv->row = lrow; cv->col = lcol; cv->SyncCaret(); YieldToWin() ; } } // This happens after load, set it again doc->UpdateAllViews(NULL); } } // Try figure out last current directory int idx; if( (idx = file.ReverseFind('\\')) != -1) { file = file.Left(idx + 1); } P2N("CWedApp::InitInstance Chdir: '%s'\r\n", file); _chdir(file); targdir = srcdir = file; } message ("Loading macros ..."); LoadMacros(); message ("Loading holdings ..."); LoadHoldings(); message(""); return TRUE; }
#include <stdio.h> #include <string.h> #include <OS.h> #include <Drivers.h> // for B_SET_(NON)BLOCKING_IO typedef struct commands_info { int op; const char *name; } commands_info; #define C2N(op) { op, #op } commands_info g_commands_info[] = { C2N(NET_STACK_SOCKET), C2N(NET_STACK_BIND), C2N(NET_STACK_RECVFROM), C2N(NET_STACK_RECV), C2N(NET_STACK_SENDTO), C2N(NET_STACK_SEND), C2N(NET_STACK_LISTEN), C2N(NET_STACK_ACCEPT), C2N(NET_STACK_CONNECT), C2N(NET_STACK_SHUTDOWN), C2N(NET_STACK_GETSOCKOPT), C2N(NET_STACK_SETSOCKOPT), C2N(NET_STACK_GETSOCKNAME), C2N(NET_STACK_GETPEERNAME), C2N(NET_STACK_SYSCTL), C2N(NET_STACK_SELECT),