int main(int argc, char **argv) { glutInit(&argc, argv); InitDisplay(); // setup haptic renderer InitHL(); HandleMenuCommand('d'); // reset the surface properties to default //mPS.StartConstructingSystem(); //mDesign = true; ConstructSurface(mSurfaceParticles); mPause = false; // create pulldown menus CreateMenus(); /* The GLUT main loop won't return control, so we need to perform cleanup using an exit handler. */ atexit(exitHandler); // turn over control to GLUT glutMainLoop(); return 0; }
short sendmacro(struct WindRec *tw, short n) /* send macro number n */ // RAB BetterTelnet 2.0b5 - changed to support new macro system { char temp[20]; unsigned char *s, *first, *p; unsigned char myipnum[4]; Handle mh, ph; short i, num, pos, escape, length; char *plabel; Str255 password; unsigned long startTicks; // Invalid number if (n < 0 || n >= NUM_MACROS) { return -1; } // first we actually have to GET the macro (2.0b5) // we use getmacrointohandle for this i = -1; if (tw->sessmacros.handle) i = getmacrointohandle(&tw->sessmacros, n, &mh); if (i == -1) i = getmacrointohandle(&TelInfo->newMacros, n, &mh); if (i == -1) return 0; // Empty macro, so do nothing // if (gMacros[n] == nil) { // return 0; // } // HLock(gMacros[n]); // mp = (unsigned char *)*gMacros[n]; s = (unsigned char *)*mh; ph = myNewHandle(GetHandleSize(mh) + 256); if (!ph) return 0; // ouch HLock(ph); first = p = (unsigned char *)*ph; netgetip(myipnum); // totally revised - we parse as we go (RAB BetterTelnet 2.0b5) // this has the pleasant side effect of getting rid of the use of 254 and 255 as special // characters, so we can use them in macros now - you can now send telnet options from a macro! num = 0; pos = 0; escape = 0; while ( *s) { if (escape == 1 && (((*s < '0' || *s > '9') && pos) || pos >= 3)) { // do this ONCE - // it's a kludge to do this in each case *p++=num; pos = 0; escape = 0; // now the rest of the code will take care of whatever char this was } if (escape == 1) { escape = 0; switch (*s) { case 'i': SendStringAsIfTyped(tw, (char *)first, p-first); sprintf(temp,"%d.%d.%d.%d", myipnum[0], myipnum[1], myipnum[2], myipnum[3]); SendStringAsIfTyped(tw, temp, strlen(temp)); first = p = (unsigned char *)*ph; break; case '#': SendStringAsIfTyped(tw, (char *)first, p-first); sprintf(temp,"%d", VSgetlines(tw->vs)); SendStringAsIfTyped(tw, temp, strlen(temp)); first = p = (unsigned char *)*ph; break; case 'n': *p++='\012'; break; case 'r': *p++='\015'; break; case 't': *p++='\t'; break; case '"': *p++='\"'; break; case '\\': *p++='\\'; break; case 'k': escape = 2; break; case 'w': // switch to window num if ( s[1] >= '1' && s[1] <= '9') { HandleMenuCommand( (connMenu << 16 | FIRST_CNXN_ITEM) + s[1] - '1', 0 ); ++s; } break; default: if (*s <='9' && *s >='0' && pos <3) { num= num*8+( *s -'0'); pos++; escape=1; } else { // if (pos ==0 && num==0) { *p++='\\'; *p++=*s; // } // else { // *p++=num; // pos= 0; // s--; /* back up the buffer. */ // } } break; } } else if (escape == 2) { if (*s == '{') { escape = 3; plabel = NULL; } else { escape = 0; } } else if (escape == 3) { if (*s != '}') { if ( plabel == NULL ) plabel = s; } else { *s = 0; if (plabel && SSH2PasswordDialog(plabel, password, NULL)) { SendStringAsIfTyped(tw, (char *)first, p-first); // better wait for echo off... startTicks = TickCount(); while (TickCount() - startTicks < 30) { ssh2_sched(); DoNetEvents(); } first = p = (unsigned char *)*ph; SendStringAsIfTyped(tw, (char *)password + 1, password[0]); } else { // malformed macro, or pasword cancel first = p = (unsigned char *)*ph; break; } escape = 0; } } else { if (*s=='\\') { num=0; pos=0; escape=1; } else *p++=*s; } s++; } if (pos >0) *p++=num; SendStringAsIfTyped(tw, (char *)first, p-first); DisposeHandle(mh); DisposeHandle(ph); return 0; }
/* Function: HandleKeyboard Usage: HandleKeyboard(key, x, y) --------------------------------------------------------------------------- Handles some useful keyboard shortcuts. */ void HandleKeyboard(unsigned char key, int x, int y) { if (key == 27) key = 'q'; // escape HandleMenuCommand(key); }