void PerformanceCounter::printStatistics() { const String desc (getStatisticsAndReset().toString()); Logger::outputDebugString (desc); appendToFile (outputFile, desc); }
int main(int argc, const char * argv[]) { int oct = 0600; char *fileLink = "hwk3-4.txt"; setRights(oct); writeToFile(fileLink); oct = 0660; setRights(oct); appendToFile(fileLink); referenceFile(fileLink); return 0; }
// Destructor ~NumericFile() { // Perform an action based on the value of closingAction switch (closingAction) { case FileCloseAction::OUTPUT: // Output the contents to 'fileName' { outputToFile(); break; } case FileCloseAction::APPEND: // Append the contents to 'fileName' { appendToFile(); break; } } }
int main(int argc, char const* argv[]) { struct timeval timeout; /*struct*/ fd_set master_set, working_set; // no struct cause of deb? int rc, on = 1; int max_sd; int file_not_received = 1; int charsWritten = 0; //const char *message = "Hello World"; struct filePkg recvChunk = {}; // initialize to zero /*char recvMessage[256];*/ //struct netCommand recvCommand; // clear file to remove old garbage clearFile("out.txt"); // Init struckt for Metadata struct fileStatus fileStatus; fileStatus.protocolVersion = -1; fileStatus.size = -1; // Declare Communication Information int sfd; struct sockaddr_in6 address; // IPv6 address.sin6_family = AF_INET6; address.sin6_addr = in6addr_any; address.sin6_port = htons(PORT); //int addrlen = sizeof(address); struct netCommand command; command.protocolVersion = 1; command.command = READ; command.offset = 2; command.length = 12; strncpy(command.fname, "foo.txt", MAXFNLEN); do { sfd = socket(PF_INET6, SOCK_STREAM, 0); if (sfd == -1) { perror("Unable to open socket"); exit(1); } // Make socket reuseable rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)); if (rc < 0) { perror("setsockopt() failed"); close(sfd); exit(1); } // Make socket non-blocking //rc = ioctl(sfd, FIONBIO, (char *) &on); //if (rc < 0) { // perror("ioctl() failed"); // close(sfd); // exit(1); //} rc = connect(sfd, (struct sockaddr *) &address, sizeof(address)); if (rc < 0) { perror("connect() failed"); close(sfd); exit(1); } // Add socket to listen filedescriptor set FD_ZERO(&master_set); max_sd = sfd; FD_SET(sfd, &master_set); /* Sending Back what's going on */ //sendto(sfd, message, strlen(message) + 1, 0, //(struct sockaddr *) &address, (socklen_t) addrlen); // init timeval struct, cause linux updates it timeout.tv_sec = 10; // 3 Mins timeout.tv_usec = 0; // is this val even necessary? // save master fd_set to working fd_set memcpy(&working_set, &master_set, sizeof(master_set)); if (fileStatus.size == -1) { command.protocolVersion = 1; command.command = STATUS; command.offset = 0; command.length = 0; strncpy(command.fname, "foo.txt", MAXFNLEN); } else { command.protocolVersion = 1; command.command = READ; command.offset = charsWritten; command.length = 99; strncpy(command.fname, "foo.txt", MAXFNLEN); } // sending the request //sendto(sfd, // &command, // sizeof(command), // 0, // (struct sockaddr *) &address, // (socklen_t) addrlen // ); write(sfd, &command, sizeof(command)); // use select to wait for response //printf("%s\n", "Waiting for select()"); rc = select( max_sd + 1, // highest numbered FD + 1 &working_set, // Set of read FDs NULL, // Set of write FDs NULL, // Set of exception FDs &timeout // Minimum wait interval ); //recvfrom(sfd, &recvCommand, sizeof(recvCommand), 0, //(struct sockaddr *) &address, (socklen_t *) &addrlen); if (rc < 0) { perror("select() has failed!"); break; } if (rc == 0) { perror("select() has reached the timeout"); continue; } // select must have a FD ready, since we're only watching sfd // we consider it the ready FD if (FD_ISSET(sfd, &working_set)) { if (command.command == STATUS) { //recvfrom(sfd, // &fileStatus, // sizeof(fileStatus), // 0, // (struct sockaddr *) &address, // (socklen_t *) &addrlen // ); read(sfd, &fileStatus, sizeof(fileStatus)); printf("size is %d\n", fileStatus.size); } else if(command.command == READ) { //recvfrom(sfd, // &recvChunk, // sizeof(recvChunk), // 0, // (struct sockaddr *) &address, // (socklen_t *) &addrlen // ); read(sfd, &recvChunk, sizeof(recvChunk)); printf("Got Msg: %s\n", recvChunk.text); printf("Of size: %d\n", recvChunk.strLength); printf("filepos: %d\n", recvChunk.filePos); printf("goteof : %d\n", recvChunk.gotEOF); charsWritten = recvChunk.filePos + recvChunk.strLength; appendToFile("out.txt", recvChunk.filePos, recvChunk.text, recvChunk.strLength ); } } close(sfd); file_not_received++; sleep(1); } while (!recvChunk.gotEOF || charsWritten < fileStatus.size); //printf("%s\n", receivemsg); return 0; }
PerformanceCounter::PerformanceCounter (const String& name, int runsPerPrintout, const File& loggingFile) : runsPerPrint (runsPerPrintout), startTime (0), outputFile (loggingFile) { stats.name = name; appendToFile (outputFile, "**** Counter for \"" + name + "\" started at: " + Time::getCurrentTime().toString (true, true)); }
int main(int argc, char *argv[]) { // start application QString str = QString("\n\n%1: Field"). arg(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz")); QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); QDir("/").mkpath(location); appendToFile(location, str); // register message handler // TODO: qInstallMsgHandler(logOutput); ArgosApplication a(argc, argv); // QApplication a(argc, argv); #ifdef VERSION_BETA bool beta = true; #else bool beta = false; #endif a.setWindowIcon(icon("field")); a.setApplicationVersion(versionString(VERSION_MAJOR, VERSION_MINOR, VERSION_SUB, VERSION_GIT, VERSION_YEAR, VERSION_MONTH, VERSION_DAY, beta)); a.setOrganizationName("hpfem.org"); a.setOrganizationDomain("hpfem.org"); a.setApplicationName("Field"); #ifdef Q_WS_MAC // don't show icons in menu a.setAttribute(Qt::AA_DontShowIconsInMenus, true); #endif // parameters QStringList args = QCoreApplication::arguments(); if (args.count() == 2) { if (args.contains( "--help") || args.contains("/help")) { cout << "field [fileName (*.fld; *.py) | -run fileName (*.py) | --help | --verbose]" << endl; exit(0); return 0; } } QSettings settings; // first run if (settings.value("General/GUIStyle").value<QString>().isEmpty()) { QString styleName = ""; QStringList styles = QStyleFactory::keys(); #ifdef Q_WS_X11 // kde 3 if (getenv("KDE_FULL_SESSION") != NULL) styleName = "Plastique"; // kde 4 if (getenv("KDE_SESSION_VERSION") != NULL) { if (styles.contains("Oxygen")) styleName = "Oxygen"; else styleName = "Plastique"; } // gtk+ if (styleName == "") styleName = "GTK+"; #endif #ifdef Q_WS_WIN if (styles.contains("WindowsVista")) styleName = "WindowsVista"; else if (styles.contains("WindowsXP")) styleName = "WindowsXP"; else styleName = "Windows"; #endif #ifdef Q_WS_MAC styleName = "Aqua"; #endif settings.setValue("General/GUIStyle", styleName); } // setting gui style setGUIStyle(settings.value("General/GUIStyle").value<QString>()); // language QString locale = settings.value("General/Language", QLocale::system().name()).value<QString>(); setLanguage(locale); // init indicator (ubuntu - unity, windows - overlay icon, macosx - ???) Indicator::init(); MainWindow w; w.show(); return a.exec(); }
void encodeMessage() { char *strStripped = getCompressedKey("lyrics.txt"); if (strStripped == NULL) { return; } printf("%s\n", strStripped); char *buffer = getFileContent("inputMessage.txt"); if (buffer == NULL) { return; } printf("%s\n", buffer); Codepoint points[strlen(buffer)]; int k = 0, l = 0, i = 0, isWithinDist = 0; for (i = 0; i < strlen(buffer); i++) { if (isalpha(buffer[i])) { for (k = 0; k < strlen(strStripped); k++) { if (l > 0 && ((abs(points[l - 1].point - k) < d) || (points[l - 1].point + k) < d)) { isWithinDist = 1; continue; } isWithinDist = 0; if (tolower(buffer[i]) == strStripped[k]) { points[l].code[0] = tolower(buffer[i]); points[l].isUpper = isupper(buffer[i]); points[l].isAlpha = 1; sprintf(points[l].pointChar, "%d", k); points[l++].point = k; break; } } if (isWithinDist) { printf("Unable to satisfy the d condition!\n"); return; } if (k >= strlen(strStripped)) { printf("Unable to encode using the current key!\n" "No matching position found for char '%c'\n", buffer[i]); return; } } else { char c[10] = {buffer[i]}; strcpy(points[l].pointChar, c); points[l].isUpper = 0; points[l].isAlpha = 0; points[l++].point = -1; } } int j = 0; remove("encodedText.txt"); for (; j < l; j++) { appendToFile("encodedText.txt", points[j]); } printf("\n"); free(buffer); }