int main2(void) { double *clipx, *clipy, *subjectx, *subjecty; int lclip, lsubject; readFromStdin(&clipx, &clipy, &subjectx, &subjecty, &lclip, &lsubject); double *polysx, *polysy; int * origin; int *lengths, inside, nl,nlp, i,j; clip(clipx, clipy, lclip, subjectx, subjecty, lsubject, &polysx, &polysy, &origin, &lengths, &nl, &nlp, &inside, POLYGON_INTERSECTION); int v = 0; for (i = 0; i < nl; i++) { printf("Polígono %d\n", i+1); printf("--------------------------\n"); for (j = 0; j < lengths[i]; j++) { printf("x=%.5f, y=%.5f, o=%d\n", polysx[v], polysy[v], origin[v]); v++; } } free(clipx); free(clipy); free(subjectx); free(subjecty); free(polysx); free(polysy); free(origin); return 0; }
void K3b::TocFileWriter::writeDataSource( int trackIndex, QTextStream& t ) { if( readFromStdin() ) t << "\"-\" "; else t << "\"" << m_filenames[trackIndex] << "\" "; }
void Options::parseCommandLine() { QCommandLineParser parser; parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument("files", "Files to compile.", "[files...]"); QCommandLineOption include(QStringList() << "i" << "include", "Include directories.", "include", ""); parser.addOption(include); QCommandLineOption errorLimit("error-limit", "Stop after N errors. [Default: 20]", "N", "20"); parser.addOption(errorLimit); QCommandLineOption outputFile(QStringList() << "o" << "out", "Output to file or stdout if empty.", "file", ""); parser.addOption(outputFile); QCommandLineOption outputType(QStringList() << "e" << "emit", "Specify the type of output. [Default: obj]\n type=obj|llvm|ast", "type", "obj"); parser.addOption(outputType); QCommandLineOption readFromStdin("stdin", "Read from stdin."); parser.addOption(readFromStdin); parser.process(*QCoreApplication::instance()); m_files = parser.positionalArguments(); m_includeDirs = parser.values(include); m_errorLimit = parser.value(errorLimit).toInt(); m_outputFile = parser.value(outputFile); m_outputType = parser.value(outputType); if (m_outputType != "obj" && m_outputType != "llvm" && m_outputType != "ast") m_outputType = "obj"; m_readFromStdin = parser.isSet(readFromStdin); if (m_files.isEmpty() && !m_readFromStdin) parser.showHelp(); }
static void connectClient(const char *dev) { fd_set master; fd_set read_fds; FD_ZERO(&master); FD_ZERO(&read_fds); signal(SIGHUP, exit_handler); signal(SIGINT, exit_handler); signal(SIGQUIT, exit_handler); signal(SIGPIPE, exit_handler); signal(SIGTSTP, exit_handler); signal(SIGTERM, exit_handler); int stdi; struct ttyRaw* tty_in; stdi = STDIN_FILENO; if (!isatty(stdi)) { return; } tty_in = setTty(stdi, 0); int stdo; struct ttyRaw* tty_out; stdo = STDOUT_FILENO; if (!isatty(stdo)) { closeTty(tty_in); return; } tty_out = setTty(stdo, 0); int clientfd; clientfd = createClientSocket(dev); if (clientfd < 0) { closeTty(tty_out); closeTty(tty_in); return; } FD_SET(tty_in->fd,&master); FD_SET(clientfd, &master); int fdmax = 0; fdmax = (clientfd > tty_in->fd) ? clientfd : tty_in->fd; for(;;) { if (sigexit) { break; } read_fds = master; if (select(fdmax + 1, &read_fds, NULL, NULL, NULL) == -1) { perror("mTerm_client: select error"); break; } if (FD_ISSET(stdi, &read_fds)) { if (!readFromStdin(clientfd, tty_in->fd)) { break; } } if (FD_ISSET(clientfd, &read_fds)) { if (!writeToStdout(clientfd,tty_out->fd)) { break; } } } closeTty(tty_out); closeTty(tty_in); close(clientfd); }
int main (int argc, char const *argv[]) { int optionChoosen = 0, read = 0; while (1) { printf("Изберете начин на работа \n"); printf("1 - Четене от файл, изход във файл \n"); printf("2 - Четене от файл, изход на екрана \n"); printf("3 - Четене от клавиатура, изход на екрана \n"); printf("4 - Четене от клавиатура, във файл \n"); read = scanf("%d", &optionChoosen); if (read > 0) { if ((optionChoosen > 0) && (optionChoosen < 5)) { printf("Вие избрахте опция %d\n", optionChoosen); break; } else { printf("Няма такава опция\n"); } } else { printf("Неправилен вход\n"); } FLUSH; } switch (optionChoosen) { case 1: if (argc >= 3) { int fileLength = strlen(argv[1]); if ( (argv[1][fileLength - 2] == '.') && ( (argv[1][fileLength - 1] == 'c') || (argv[1][fileLength - 1] == 'C') ) ) { readFromFile(argv[1], argv[2]); } else { printf("Въведете файл с разишернието на езика C\n"); return 0; } } else { printf("Не сте въвели файлове за четене и писане\n"); return 0; } break; case 2: if (argc >= 2) { int fileLength = strlen(argv[1]); if ( (argv[1][fileLength - 2] == '.') && ( (argv[1][fileLength - 1] == 'c') || (argv[1][fileLength - 1] == 'C') ) ) { readFromFile(argv[1], NULL); } else { printf("Въведете файл с разишернието на езика C\n"); return 0; } } else { printf("Не сте въвели файл за четене\n"); return 0; } break; case 3: readFromStdin(NULL); break; case 4: if (argc >= 2) { readFromStdin(argv[1]); } else { printf("Не сте въвели файл за писане\n"); return 0; } break; }; return 0; }
bool K3b::TocFileWriter::save( QTextStream& t ) { writeHeader(t); if( !m_cdText.isEmpty() ) writeGlobalCdText(t); // // see if we have multiple sessions // int sessions = 1; for( K3b::Device::Toc::iterator it = m_toc.begin(); it != m_toc.end(); ++it ) { if( (*it).session() > 1 ) sessions = (*it).session(); } if( m_sessionToWrite > sessions ) m_sessionToWrite = 1; // // We can only hide the first track if both the first and the second track are // audio tracks. // We also can only hide the first track in the first session. // bool hideFirstTrack = m_hideFirstTrack; if( m_toc.count() < 2 || m_toc[0].type() != K3b::Device::Track::TYPE_AUDIO || m_toc[1].type() != K3b::Device::Track::TYPE_AUDIO || (sessions > 1 && m_sessionToWrite != 1 ) ) hideFirstTrack = false; // the dataStart will be the offset in case we do not write the first session K3b::Msf dataStart; int trackIndex = 0; if( hideFirstTrack ) { const K3b::Device::Track& hiddenTrack = m_toc[0]; const K3b::Device::Track& track = m_toc[1]; t << "// Track number 1 (hidden) and track number 2 (as track 1)" << endl; t << "TRACK AUDIO" << endl; if( track.copyPermitted() ) t << "COPY" << endl; else t << "NO COPY" << endl; if( track.preEmphasis() ) t << "PRE_EMPHASIS" << endl; else t << "NO PRE_EMPHASIS" << endl; if( !m_cdText.isEmpty() ) writeTrackCdText( m_cdText[0], t ); // the "hidden" file will be used as pregap for the "first" track t << "AUDIOFILE "; writeDataSource( 0, t ); if( readFromStdin() ) t << hiddenTrack.firstSector().toString(); else t << " 0"; t << " " << hiddenTrack.length().toString() << endl; t << "START" << endl; // use the whole hidden file as pregap // now comes the "real" first track t << "AUDIOFILE "; writeDataSource( 1, t ); if( readFromStdin() ) t << track.firstSector().toString() << " "; else t << "0 "; // no index 0 for the last track. Or should we allow this??? if( m_toc.count() == 2 ) t << track.length().toString(); else t << track.realAudioLength().toString(); t << endl << endl; trackIndex+=2; } else { // // Seek to the first track to write. // In case we hid the first track above it was the first track anyway. // while( m_toc[trackIndex].session() < m_sessionToWrite && m_toc[trackIndex].session() > 0 ) ++trackIndex; dataStart = m_toc[trackIndex].firstSector(); } kDebug() << "(K3b::TocFileWriter) using offset of: " << dataStart.toString(); while( trackIndex < m_toc.count() ) { if( m_toc[trackIndex].session() == 0 || m_toc[trackIndex].session() == m_sessionToWrite ) writeTrack( trackIndex, dataStart, t ); trackIndex++; } return ( t.status() == QTextStream::Ok ); }
void K3b::TocFileWriter::writeTrack( int index, const K3b::Msf& offset, QTextStream& t ) { const K3b::Device::Track& track = m_toc[index]; t << "// Track number " << (index+1) << endl; if( track.type() == K3b::Device::Track::TYPE_AUDIO ) { t << "TRACK AUDIO" << endl; if( track.copyPermitted() ) t << "COPY" << endl; else t << "NO COPY" << endl; if( track.preEmphasis() ) t << "PRE_EMPHASIS" << endl; else t << "NO PRE_EMPHASIS" << endl; if( !m_cdText.isEmpty() ) writeTrackCdText( m_cdText[index], t ); // // cdrdao sees the pregap as part of the current track and not as part of // the previous like it really is. // if( index == 0 ) { if( (track.firstSector()-offset) > 0 ) { // // the first track is the only track K3b does not generate null-pregap data for // since cdrecord does not allow this. So We just do it here the same way and tell // cdrdao to create the first pregap for us // t << "PREGAP " << (track.firstSector()-offset).toString() << endl; } } else { const K3b::Device::Track& lastTrack = m_toc[index-1]; // // the pregap data // if( lastTrack.index0() > 0 ) { t << "AUDIOFILE "; writeDataSource( index-1, t ); if( readFromStdin() ) t << (lastTrack.firstSector() + lastTrack.index0() - offset).toString(); else t << (lastTrack.index0() - offset).toString(); t << " " << (lastTrack.length() - lastTrack.index0()).toString() << endl << "START" << endl; } } // // The track data // t << "AUDIOFILE "; writeDataSource( index, t ); if( readFromStdin() ) t << (track.firstSector() - offset).toString() << " "; else t << "0 "; // no index 0 for the last track. Or should we allow this??? if( index == m_toc.count()-1 ) t << track.length().toString(); else t << track.realAudioLength().toString(); t << endl; } else { if( track.mode() == K3b::Device::Track::XA_FORM1 ) t << "TRACK MODE2_FORM1" << endl; else if( track.mode() == K3b::Device::Track::XA_FORM2 ) t << "TRACK MODE2_FORM2" << endl; else t << "TRACK MODE1" << endl; if( !m_cdText.isEmpty() && !m_toc.contentType() != K3b::Device::DATA ) { // // insert fake cdtext // cdrdao does not work without it and it seems not to do any harm. // t << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE " << "\"\"" << endl << " PERFORMER " << "\"\"" << endl << " ISRC " << "\"\"" << endl << " ARRANGER " << "\"\"" << endl << " SONGWRITER " << "\"\"" << endl << " COMPOSER " << "\"\"" << endl << " MESSAGE " << "\"\"" << endl << " }" << endl << "}" << endl; } if( readFromStdin() ) t << "DATAFILE \"-\" " << track.length().toString() << endl; else t << "DATAFILE \"" << m_filenames[index] << "\"" << endl; t << endl; } t << endl; }