#include "BufPkr.h" using namespace std; BufPkr::BufPkr(unsigned int sz_in, bool verbose) { cerr << "BufPkr called\n"; sz = sz_in; try { buf = new u_char[sz]; line = new char[2*sz]; doit(verbose); } catch (bad_alloc) { cerr << "*** BufPkr: Memory exhausted ***\n"; exit(1); } } void BufPkr::doit(bool verbose) { const char *WS = " \t\n"; int seqnum = 0; cerr << "pack called. verbose = " << verbose << "\n"; while ( cin.getline(line, sz)) { char *word[sz/sizeof(char *)]; char *p = line; int nwords = 0; if (cin.gcount() == (sz-1)) { cerr << "*** Ooops, line is full.\n"; exit(1); } cout << line << endl; memset(buf, '\0', sz); nwords = 0; while ( (word[nwords] = strtok(p, WS)) != NULL) { cout << "\t" << word[nwords] << endl; ++nwords; p = NULL; } pack(seqnum, nwords, word); fflush(stdout); if (verbose) printHex(seqnum, nwords); ++seqnum; if (strcmp(word[0], "quit") == 0) break; } } void BufPkr::pack(int seqnum, int nwords, char *word[]) { u_char **str_ptr = (u_char **) buf; u_char *str; cerr << "pack called.\n"; *((int *)buf) = seqnum; str_ptr = (u_char **) (buf+sizeof(seqnum)); str = buf+(nwords+1)*sizeof(char *); for (int i=0; i