"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "qftp-0.98/flist.cc" of archive qftp-0.98.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  *  qftp
    3  *  Copyright (C) 1997,1998 Peter Strand
    4  *  Distributed under the GNU Pulic Licence
    5  */
    6 
    7 #include <algo.h>
    8 
    9 
   10 #include <string.h>
   11 #include <stdlib.h>
   12 
   13 #include "flist.h"
   14 
   15 Entry::Entry()
   16 {
   17 	wd = name = date = user = group = NULL;
   18 	type = perm = size = -1;
   19 }
   20 
   21 DirList::DirList()
   22 {
   23 	islong = 0;
   24 	iter = ents.begin();
   25 }
   26 
   27 
   28 void DirList::Flush()
   29 {
   30 	ents.clear();
   31 	iter = ents.begin();
   32 }
   33 
   34 void DirList::Reset()
   35 {
   36 	iter = ents.begin();
   37 }
   38 
   39 void DirList::Add(Entry &e)
   40 {
   41 	ents.push_back(e);
   42 }
   43 
   44 
   45 void DirList::AddAt(Entry &e, int i)
   46 {
   47 	ents[i] = e;
   48 }
   49 
   50 
   51 int DirList::GetNext(Entry &e)
   52 {
   53 	if (iter == ents.end())
   54 		return 0;
   55 	e = *iter++;
   56 	return 1;
   57 }
   58 
   59 int DirList::GetAt(Entry &e, int i)
   60 {
   61 	if ((unsigned)i >= ents.size())
   62 		return 0;
   63 	e = ents[i];
   64 	return 1;
   65 }
   66 
   67 int DirList::GetWidest()
   68 {
   69 	vector<Entry>::iterator wi = ents.begin();
   70 	int n = 0, i;
   71 	while (wi != ents.end()) {
   72 		i = strlen((*wi).name);
   73 		if (i > n)
   74 			n = i;
   75 		wi++;
   76 	}
   77 	return n;
   78 }
   79 
   80 void DirList::Sort(int what, int dir) {
   81 	switch (what) {
   82 	case 0:
   83 		if (dir)
   84 			sort(ents.rbegin(), ents.rend(), cmpn);
   85 		else
   86 			sort(ents.begin(), ents.end(), cmpn);
   87 		break;
   88 	case 1:
   89 		if (dir)
   90 			sort(ents.rbegin(), ents.rend(), cmpd);
   91 		else
   92 			sort(ents.begin(), ents.end(), cmpd);
   93 		break;
   94 	case 2:
   95 		if (dir)
   96 			sort(ents.rbegin(), ents.rend(), cmps);
   97 		else
   98 			sort(ents.begin(), ents.end(), cmps);
   99 		break;
  100 	}
  101 }
  102 
  103 
  104 
  105 
  106 
  107