void readNonechoString(char *buf, int len, char const *prompt) { std::cout << prompt; std::cout.flush(); setRawMode(true); try { nonechoLoop(buf, len); } catch (...) { setRawMode(false); // make sure it gets reset throw; } setRawMode(false); std::cout << "\n"; std::cout.flush(); }
void QFont::setRawName(const QString &name) { detach(); // from qfontdatabase_x11.cpp extern bool qt_fillFontDef(const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc); if (!qt_fillFontDef(qt_fixXLFD(name.toLatin1()), &d->request, d->dpi, 0)) { qWarning("QFont::setRawName: Invalid XLFD: \"%s\"", name.toLatin1().constData()); setFamily(name); setRawMode(true); } else { resolve_mask = QFont::AllPropertiesResolved; } }
/*! Sets a font by its system specific name. The function is particularly useful under X, where system font settings (for example X resources) are usually available in XLFD (X Logical Font Description) form only. You can pass an XLFD as \a name to this function. A font set with setRawName() is still a full-featured QFont. It can be queried (for example with italic()) or modified (for example with setItalic()) and is therefore also suitable for rendering rich text. If Qt's internal font database cannot resolve the raw name, the font becomes a raw font with \a name as its family. Note that the present implementation does not handle wildcards in XLFDs well, and that font aliases (file \c fonts.alias in the font directory on X11) are not supported. \sa rawName(), setRawMode(), setFamily() */ void QFont::setRawName( const QString &name ) { detach(); // from qfontdatabase_x11.cpp extern bool qt_fillFontDef( const QCString &xlfd, QFontDef *fd, int screen ); if ( ! qt_fillFontDef( qt_fixXLFD( name.latin1() ), &d->request, d->screen ) ) { #ifdef QT_CHECK_STATE qWarning("QFont::setRawName(): Invalid XLFD: \"%s\"", name.latin1()); #endif // QT_CHECK_STATE setFamily( name ); setRawMode( TRUE ); } else { d->mask = QFontPrivate::Complete; } }
/*! Activates the raw mode to read keys in an non blocking way. */ void vpKeyboard::init() { setRawMode(true); }
/*! Stops the raw mode. */ void vpKeyboard::end() { setRawMode(false); }
int main(int argc, char **argv) { nonportFail = testingFail; char s[4]; s[0] = '-'; s[1] = 'l'; s[2] = 's'; s[3] = 0; if (0!=strcmp(s, "-ls")) { printf("strcmp failed!\n"); return 4; } // process arguments bool interactive = false; for (int i=1; i<argc; i++) { if (0==strcmp("-ls", argv[i])) { // do an ls, and bail applyToCwdContents(printIt); return 0; } else if (0==strcmp("-noninteractive", argv[i])) { // don't do the interactive stuff interactive = false; } else { printf("unknown option: %s\n", argv[i]); return 2; } } // trying to figure out why backspace sometimes gives ^? crap // (turns out Konsole sometimes sends ^? in response to BS, // even when the option looks unchecked) //char buf[80]; //printf("type stuff and try backspace: "); //gets(buf); //printf("%s (%d chars)\n", buf, strlen(buf)); //return 0; long startTime = getMilliseconds(); if (interactive) { printf("Type some characters; you should see each\n" "character echoed once as you type it (q to stop):\n"); setRawMode(true); char ch; do { ch = getConsoleChar(); printf("%c", ch); } while (ch != 'q'); setRawMode(false); printf("\n\nYou typed for %ld milliseconds\n", getMilliseconds() - startTime); } limitFileAccess("chmod.test"); printf("if the current dir contains a file called " "chmod.test, I just attempted to limit\n" "its access to just the owner\n"); createDirectory("test.dir"); // test chdir, which also implicitly tests mkdir bool didFirst=false; if (!changeDirectory("test.dir") || (didFirst=true, false) || !changeDirectory("..")) { printf("failed while trying to chdir to %s\n", (didFirst? ".." : "test.dir")); } // more straightforward if (!fileOrDirectoryExists("test.dir")) { printf("test.dir didn't get created?\n"); } printf("what's more, I just tried to mkdir & chdir test.dir\n"); // test ensurePath if (!ensurePath("test.dir/a/b/c/d", false /*isDirectory*/)) { printf("ensurePath test.dir/a/b/c/d failed\n"); } // try to list partial directory contents printf("listing of first 10 files in this directory:\n"); { int count = 0; applyToCwdContents(printFirst10, &count); } // test date function { int m, d, y; getCurrentDate(m, d, y); printf("I think the date is (m/d/yyyy): %d/%d/%d\n", m, d, y); } // test sleep (mostly just to make sure it doesn't segfault) printf("sleeping for 1 second...\n"); portableSleep(1); // test user name char buf[80]; getCurrentUsername(buf, 80); printf("current user name is: %s\n", buf); if (interactive) { // test nonecho reading printf("Type something and press Enter; it won't be echoed (yet):\n"); readNonechoString(buf, 80, " > "); printf("You typed: %s\n", buf); } // test random stuff printf("hasSystemCryptoRandom: "); if (!hasSystemCryptoRandom()) { printf("no\n"); } else { printf("yes\n"); printf("three random numbers: %u %u %u\n", getSystemCryptoRandom(), getSystemCryptoRandom(), getSystemCryptoRandom()); } printf("testing nprintf...\n"); nprintfVector("simple"); nprintfVector("a %s more", "little"); nprintfVector("some %4d more %s complicated %c stuff", 33, "yikes", 'f'); nprintfVector("%f", 3.4); printf("nonport works\n"); return 0; }