"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "qftp-0.98/conf.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 <stdlib.h>
    8 #include <string.h>
    9 #include <unistd.h>
   10 #include <stdio.h>
   11 
   12 #include "conf.h"
   13 
   14 Conf::Conf()
   15 {
   16 	setdef();
   17 }
   18 
   19 Conf::Conf(Conf &cf)
   20 {
   21 	opts = cf.opts;
   22 }
   23 
   24 Conf::Conf(Conf &cf, int argc, char *argv[], char *valid)
   25 {
   26 	Parse(cf, argc, argv, valid);
   27 }
   28 
   29 void Conf::Parse(Conf &cf, int argc, char *argv[], char *valid)
   30 {
   31 	char ign;
   32 	int i;
   33 
   34 	opts = cf.opts;
   35 
   36 	argi = 0;
   37 	ign = 0;
   38 	for (i = 1;i < argc;i++) {
   39 		if (argv[i][0] == '-') {
   40 			int j = 1;
   41 			ign = 0;
   42 			while (argv[i][j]) {
   43 				if (strchr("yu", argv[i][j])) {
   44 					ign = 1;
   45 					argptr = argv[i + 1];
   46 				}
   47 				if (strchr(valid, argv[i][j]))
   48 					set(argv[i][j]);
   49 				j++;
   50 			}
   51 		} else if (!ign) {
   52 			if (argv[i][0])
   53 				arg.push_back(argv[i]);
   54 		} else
   55 			ign = 0;
   56 	}
   57 }
   58 
   59 void Conf::Reset()
   60 {
   61 	argi = 0;
   62 }
   63 
   64 char *Conf::GetNext()
   65 {
   66 	if (argi < arg.size())
   67 		return arg[argi++];
   68 	else
   69 		return NULL;
   70 }
   71 
   72 int Conf::Args()
   73 {
   74 	return arg.size();
   75 }
   76 
   77 void Conf::print()
   78 {
   79 	printf("(b) Background:       %d\n", opts.bg);
   80 	printf("(z) Un(g)zip (view):  %d\n", opts.proc);
   81 	printf("(f) Force:            %d\n", opts.force);
   82 	printf("(c) Continue (reget): %d\n", opts.cont);
   83 	printf("(m) Preserve mtime:   %d\n", opts.mod);
   84 	printf("(l) Long Listing:     %d\n", opts.longl);
   85 	printf("(r) Reverse sort:     %d\n", opts.rev);
   86 	printf("(s) Sort by size:     %d\n", opts.size);
   87 	printf("(t) Sort by time:     %d\n", opts.time);
   88 	printf("(a) Anonymous:        %d\n", opts.anon);
   89 	printf("(y) Retry:Sleep   %2d:%2d\n", opts.retry, opts.retrsl);
   90 	printf("(n) Forget host&user: %d\n", opts.noinf);
   91 	printf("(e) Recursive:        %d\n", opts.rec);
   92 	printf("(q) Quiet:            %d\n", opts.quiet);
   93 	printf("(u) User:Pass         %s\n", opts.user);
   94 }
   95 
   96 void Conf::setdef()
   97 {
   98 	argptr = "";
   99 	set('B');
  100 	set('z');
  101 	set('m');
  102 	set('F');
  103 	set('C');
  104 	set('L');
  105 	set('A');
  106 	set('Y');
  107 	set('N');
  108 	set('E');
  109 	set('Q');
  110 	set('U');
  111 	set('S');
  112 	set('T');
  113 	set('R');
  114 }
  115 
  116 void Conf::set(char c, char *s = NULL)
  117 {
  118 	char *p;
  119 	if (s)
  120 		argptr = s;
  121 	switch (c) {
  122 	case 'B':
  123 	case 'b': opts.bg = (c & 0x20) >> 5; break;
  124 	case 'Z':
  125 	case 'z': opts.proc = (c & 0x20) >> 5; break;
  126 	case 'F':
  127 	case 'f': opts.force = (c & 0x20) >> 5; break;
  128 	case 'C':
  129 	case 'c': opts.cont = (c & 0x20) >> 5; break;
  130 	case 'L':
  131 	case 'l': opts.longl = (c & 0x20) >> 5; break;
  132 	case 'A':
  133 	case 'a': opts.anon = (c & 0x20) >> 5; break;
  134 	case 'Y':
  135 		opts.retry = 0; opts.retrsl = 0; break;
  136 	case 'y':
  137 		opts.retry = atoi(argptr);
  138 		if ((p = strchr(argptr, ':'))) {
  139 			opts.retrsl = atoi(p + 1);
  140 		}
  141 		break;
  142 	case 'N':
  143 	case 'n': opts.noinf = (c & 0x20) >> 5; break;
  144 	case 'E':
  145 	case 'e': opts.rec = (c & 0x20) >> 5; break;
  146 	case 'Q':
  147 	case 'q': opts.quiet = (c & 0x20) >> 5; break;
  148 	case 'U': *opts.user = 0; break;
  149 	case 'u': strcpy(opts.user, argptr); break;
  150 	case 'S':
  151 	case 's': opts.size = (c & 0x20) >> 5; break;
  152 	case 'T':
  153 	case 't': opts.time = (c & 0x20) >> 5; break;
  154 	case 'R':
  155 	case 'r': opts.rev = (c & 0x20) >> 5; break;
  156 	case 'M':
  157 	case 'm': opts.mod = (c & 0x20) >> 5; break;
  158 
  159 	}
  160 }
  161 
  162 
  163 struct config *Conf::Get()
  164 {
  165 	return &opts;
  166 }
  167 
  168 
  169 
  170