// ddiff/dpatch - manipulate differences between debian packages.
// Copyright 2000 Tom Rothamel <tom-ddiff@onegeek.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "genfile.h"

// buf must be at least l+1 bytes long.
char *extrstr(char *buf, char *src, int l) {
	memcpy(buf, src, l);
	buf[l] = 0;
	return buf;
}

// l must be < 20.
int extrint(char *src, int l) {
	char buf[20];
	extrstr(buf, src, l);
	return atoi(buf);
}

// l must be < 20.
int extroct(char *src, int l) {
	char buf[20];
	char *s;
	int o = 0;

	extrstr(buf, src, l);
	s = buf;
	
	while (*s) {
		if (*s == ' ') {
			s++;
			continue;
		}
		if (*s < '0') return o;
		if (*s > '7') return o;
		o *= 8;
		o += *s - '0';
		s++;
	}

	return o;
}

// l must be < 20.
long extrlong(char *src, int l) {
	char buf[20];
	extrstr(buf, src, l);
	return atol(buf);
}
