#include "../fileio/fileglob.h"
#include "globals.h"
#include "masks.h"

unsigned char getb();

unsigned long get4(bp)
char *bp;
{
    register int i;
    long value = 0;

    for(i = 0; i < 4; i++) {
	value <<= 8;
	value |= (*bp & BYTEMASK);
	bp++;
    }
    return value;
}

unsigned short get2(bp)
char *bp;
{
    register int i;
    int value = 0;

    for(i = 0; i < 2; i++) {
	value <<= 8;
	value |= (*bp & BYTEMASK);
	bp++;
    }
    return value;
}

unsigned short get2b(fp)
FILE *fp;
{
    return ((getb(fp) & BYTEMASK) << 8) | (getb(fp) & BYTEMASK);
}

unsigned char getb(fp)
FILE *fp;
{
    int c;

    bytes_read += 1;
    c = getc(fp);
    if(c == EOF) {
	printf("Premature EOF\n");
	exit(1);
    }
    return c & BYTEMASK;
}

void copy(d, s, n)
char *d, *s;
int n;
{
    while(--n >= 0) {
	*d++ = *s++;
    }
}

int do_query()
{
    char *tp, temp[10];

    printf("? ");
    (void) fflush(stdout);
    (void) read(2, temp, sizeof(temp));
    temp[sizeof(temp)] = 0;
    tp = temp;
    while(*tp != 0) {
	if(*tp == 'y' || *tp == 'Y') {
	    return 1;
	} else {
	    tp++;
	}
    }
    return 0;
}

