Changeset 1837 for trunk/gsdl/lib


Ignore:
Timestamp:
2001-01-15T15:21:43+13:00 (23 years ago)
Author:
sjboddie
Message:

Made a few cosmetic changes to the "Administration" pages and added the
ability to view the last 100 lines of the usage log. This meant making a
change to the file_tail() function to allow for the very long lines that
occur in the log file.

Location:
trunk/gsdl/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/fileutil.cpp

    r1815 r1837  
    337337}
    338338
    339 // This is a fairly quick and nasty attempt at doing a "tail" on
    340 // a file (i.e. returning the last numlines lines of filename).
    341 // It has one important limitation in that it expects lines to be
    342 // 256 characters long on average.
    343 // This of course makes it possible that it won't return numlines
    344 // lines if there are some very long lines.
    345 // It also makes it fairly inefficient as it always reads in
    346 // numlines*256 characters which is much more than generally
    347 // necessary.
     339// This is a fairly quick and nasty attempt at doing a "tail" on a file
     340// (i.e. returning the last numlines lines of filename).  It has one
     341// important limitation in that it expects lines to be linelength
     342// characters long on average.  This of course makes it possible that it
     343// won't return numlines lines if there are some lines that are longer than
     344// linelength.  It also makes it fairly inefficient as it always reads in
     345// numlines*linelength characters when it most often doesn't need them all.
    348346// For current needs it's fine though.
    349 text_t file_tail (const text_t &filename, int numlines) {
     347// -- Pass a linelength of 0 to use the default linelength (256 chars).
     348text_t file_tail (const text_t &filename, int numlines, int linelength) {
    350349
    351350  if (numlines < 1) numlines = 1;
    352   streampos numchars = 256*numlines;
     351  if (linelength == 0) linelength = 256;
     352 
     353  streampos numchars = linelength*numlines;
    353354
    354355  text_tarray lines;
     
    356357
    357358  char *filenamec = filename.getcstr();
    358   char linec[256];
     359  char linec[linelength];
    359360  ifstream file_in (filenamec);
    360361  delete filenamec;
     
    366367
    367368    while (!file_in.eof()) {
    368       file_in.getline (linec, 256);
     369      file_in.getline (linec, linelength);
    369370      ret.setcstr(linec);
    370371      text_t::const_iterator here = ret.begin();
  • trunk/gsdl/lib/fileutil.h

    r1739 r1837  
    5656bool file_copy (const text_t &fromfile, const text_t &tofile);
    5757
    58 text_t file_tail (const text_t &filename, int numlines);
     58text_t file_tail (const text_t &filename, int numlines, int linelength);
    5959
    6060// returns true if directory created successfully
Note: See TracChangeset for help on using the changeset viewer.