示例#1
0
文件: print.c 项目: McIkye/tools
/*
 * print --
 *	Prints archive members on stdout - if member names given only
 *	print those members, otherwise print all members.
 */
int
print(char **argv)
{
	off_t size;
	CF cf;
	FILE *afp;
	char *file;
	int all;

	afp = open_archive(O_RDONLY);

	/* Read from an archive, write to stdout; pad on read. */
	SETCF(afp, archive, stdout, "stdout", 0);
	for (all = !*argv; get_arobj(afp);) {
		if (!strncmp(chdr.name, AR_NAMTAB, sizeof(AR_NAMTAB) - 1)) {
			size = ftello(afp);
			get_namtab(afp);
			(void)fseeko(afp, size, SEEK_SET);
			skip_arobj(afp);
			continue;
		}

		if (all)
			file = chdr.name;
		else if (!(file = files(argv))) {
			skip_arobj(afp);
			continue;
		}
		if (options & AR_V) {
			(void)printf("\n<%s>\n\n", file);
			(void)fflush(stdout);
		}
		copy_ar(&cf, chdr.size);
		if (!all && !*argv)
			break;
	}
	close_archive(afp);

	if (*argv) {
		orphans(argv);
		return (1);
	}
	return (0);
}
int main() {
 QString fn_zone_net = "net.zone-latest";
 QString fn_zone_com = "net.zone-latest";
 QString fn_orphans = "../output/orphans.txt";

 QFile f_orphans(fn_orphans);
 if(!f_orphans.open(QIODevice::ReadOnly)) {
  QTextStream(stdout) << "Could not open orphans.txt" << endl;
  return 1;
 }

 QFile f_zone_net(fn_orphans);
 if(!f_zone_net.open(QIODevice::ReadOnly)) {
  QTextStream(stdout) << "Could not open .net zone-file" << endl;
  return 1;
 }

 QFile f_zone_com(fn_orphans);
 if(!f_zone_net.open(QIODevice::ReadOnly)) {
  QTextStream(stdout) << "Could not open .net zone-file" << endl;
  return 1;
 }

 QTextStream orphans(&forphans);

 QString outputfile_name="temp/outside_nodedup.txt";
 QFile outputfile( outputfile_name );
 if ( outputfile.open(QIODevice::ReadWrite) ) {
   QTextStream output( &outputfile );
   while (!data.atEnd()) {
     QString line = data.readLine();
     if ((!(line.at(0)==';'))&&(!line.isEmpty())) {
       QStringList record = line.split(" ");
       if ((record.count()>2)&&(record.at(1).compare("NS")==0)) {
         //When we reach this we know it's an NS record.
         amount++;
         QString domain = record.at(0)+".NET"; //Add .NET to get complete domains for use in the next step
         QString server = record.at(2);
         if (server.endsWith(".")) { //Inside pointing records end without a dot
           server.chop(1); //Remove the dot at the end
           outside++;
           QUrl server_url;
           QString tld;
           QString registerabledomain;
           server_url.setHost(server);
           tld = server_url.topLevelDomain();
           QString t1 = server;
           t1.chop(tld.length()); //Remove tld
           QStringList t2 = t1.split(".");
           t1 = t2.at(t2.count()-1);
           registerabledomain = t1+tld;
           server = server.toLower();
           tld = tld.toLower();
           registerabledomain = registerabledomain.toLower();
           output << server << "|" << tld << "|" << registerabledomain << endl;
         } else {
           inside++;
           //Aaand... ignore!
         }
       }
     }
     c++;
     if (c>10000000) {
       c = 0;
       QTextStream(stdout) << "[" << QString::number(inside) << "/" << QString::number(outside) << "]" << endl;
     }
   }
 }
 file.close();
 outputfile.close();

 //Done!
 QTextStream(stdout) << "Amount of NS records: " << QString::number(amount) << endl;
 QTextStream(stdout) << "Inside: " << QString::number(inside) << endl;
 QTextStream(stdout) << "Outside: " << QString::number(outside) << endl;
 return 0;
}
示例#3
0
文件: extract.c 项目: McIkye/tools
/*
 * extract --
 *	Extract files from the named archive - if member names given only
 *	extract those members otherwise extract all members.  If 'o' option
 *	selected modify date of newly created file to be same as archive
 *	members date otherwise date is time of extraction.  Does not modify
 *	archive.
 */
int
extract(char **argv)
{
	struct timeval tv[2];
	struct stat sb;
	CF cf;
	off_t size;
	FILE *afp;
	char *file;
	int all, eval, tfd;

	eval = 0;
	tv[0].tv_usec = tv[1].tv_usec = 0;

	afp = open_archive(O_RDONLY);

	/* Read from an archive, write to disk; pad on read. */
	SETCF(afp, archive, 0, 0, 0);
	for (all = !*argv; get_arobj(afp);) {
		if (!strncmp(chdr.name, AR_NAMTAB, sizeof(AR_NAMTAB) - 1)) {
			size = ftello(afp);
			get_namtab(afp);
			(void)fseeko(afp, size, SEEK_SET);
			skip_arobj(afp);
			continue;
		}

		if (all)
			file = chdr.name;
		else if (!(file = files(argv))) {
			skip_arobj(afp);
			continue;
		}

		if (options & AR_U && !stat(file, &sb) &&
		    sb.st_mtime > chdr.date)
			continue;

		if (options & AR_CC) {
			/* -C means do not overwrite existing files */
			if ((tfd = open(file, O_WRONLY|O_CREAT|O_EXCL,
			    S_IWUSR)) < 0) {
				skip_arobj(afp);
				eval = 1;
				continue;
			}
		} else {
			if ((tfd = open(file, O_WRONLY|O_CREAT|O_TRUNC,
			    S_IWUSR)) < 0) {
				warn("open: %s", file);
				skip_arobj(afp);
				eval = 1;
				continue;
			}
		}

		if (options & AR_V)
			(void)printf("x - %s\n", file);

		if (!(cf.wfp = fdopen(tfd, "w")))
			err(1, "fdopen: %s", file);
		cf.wname = file;
		copy_ar(&cf, chdr.size);

		if (fchmod(tfd, (mode_t)chdr.mode)) {
			warn("chmod: %s", file);
			eval = 1;
		}
		if (options & AR_O) {
			tv[0].tv_sec = tv[1].tv_sec = chdr.date;
			if (futimes(tfd, tv)) {
				warn("utimes: %s", file);
				eval = 1;
			}
		}
		(void)fclose(cf.wfp);
		if (!all && !*argv)
			break;
	}
	close_archive(afp);

	if (*argv) {
		orphans(argv);
		return (1);
	}
	return (0);
}