bool ColumnTextParser::loadFromFile(const std::string& Filename) { std::string StrLine; if (m_Contents.size()> 0 ) m_Contents.clear(); m_LinesCount = 0; m_ColsCount = 0; // check if file exists if (!openfluid::tools::Filesystem::isFile(Filename)) return false; std::ifstream FileContent(Filename.c_str()); // check if file is "openable" if (!FileContent) return false; // parse and loads file contents while(std::getline(FileContent,StrLine)) { if (!isCommentLineStr(StrLine) && !isEmptyLineStr(StrLine)) m_Contents.push_back(ColumnTextParser::tokenizeLine(StrLine)); } return checkContents(); }
int main(int argc, char *argv[]) { if (argc < 3) { // Check that there is an appropriate amount of arguements for usage fprintf(stderr,"usage %s plaintextfile keytextfile portno\n", argv[0]); exit(0); } FILE *cipherTextFP,*keyTextFP; // File pointers /* Open files */ cipherTextFP= fopen(argv[1],"r"); keyTextFP = fopen(argv[2],"r"); /* ERROR out if files don't open */ if(cipherTextFP==NULL)error("ERROR opening plaintext file for input",2); if(keyTextFP==NULL)error("ERROR opening keytext file for input",2); /* This if statement checks that the key file is at least as big as the ptext file */ if(fSize(cipherTextFP)>fSize(keyTextFP))error("ERROR cipherText is larger than keyText",2); /* These if statements employ checkContents to check file for bad chars */ if(checkContents(cipherTextFP))error("ERROR cipherText contains bad char data",2); if(checkContents(keyTextFP))error("ERROR cipherText contains bad char data",2); /* Setup socket */ int sockfd = sockSetup(atoi(argv[3])); /* Authorize server by listening for one time code */ sendAuth(sockfd,"decAck"); // exit if not correct server /* Transmit key and ptext files */ sendFile(cipherTextFP,sockfd); sendFile(keyTextFP,sockfd); /* close open files */ fclose(cipherTextFP); fclose(keyTextFP); /* Receive decoded text */ char pText[290000]; receive(pText,sockfd); close(sockfd); printf("%s\n", pText); return (0); }
bool ColumnTextParser::setFromString(const std::string& Contents, unsigned int ColumnsNbr) { /** @internal The string is tokenized. The number of tokens must be modulo number of columns */ std::vector<std::string>::iterator it; bool IsOK = true; std::vector<std::string> Tokens = ColumnTextParser::tokenizeString(Contents); if (Tokens.size() % ColumnsNbr == 0) { if (m_Contents.size() > 0) m_Contents.clear(); std::vector<std::string> LineStr; it = Tokens.begin(); while (it != Tokens.end() && IsOK) { // add to the current line LineStr.push_back(*it); if (LineStr.size() == ColumnsNbr) { // if current line has ColumnsNbr columns, it is added to the contents m_Contents.push_back(LineStr); LineStr.clear(); } ++it; } // more tokens processed but not a complete line. not good! if (LineStr.size() != 0 && LineStr.size() != ColumnsNbr) { IsOK = false; } } else IsOK = false; return IsOK && checkContents(); }
/*! * Check whether this is a Psion TextEd file */ UT_Confidence_t IE_Imp_Psion_TextEd_Sniffer::recognizeContents(const char * szBuf, UT_uint32 iNumbytes) { return checkContents(szBuf,iNumbytes,psiconv_texted_file); }