#ifndef lint
static char rcsid[] = "$Id: types.c,v 1.4 1993/12/13 04:02:27 genek Exp $";
#endif

#include "../include/config.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef STDLIBH
#include <stdlib.h>
#endif

void typeis();

static void
usage()
{
    fputs("types: usage: typename\n", stderr);
    exit(1);
}

char *pc;
int isunsigned;

void
main(argc, argv)
    int argc;
    char *argv[];
{
    struct stat statbuf;
    int size;

    pc = argv[1];

    if (argc < 2)
	usage();

    if (strcmp(pc, "mode_t") == 0) {
	isunsigned = 1;
	typeis(sizeof(statbuf.st_mode));
    }
    else if (strcmp(pc, "ino_t") == 0) {
	isunsigned = 1;
	typeis(sizeof(statbuf.st_ino));
    }
    else if (strcmp(pc, "nlink_t") == 0) {
	isunsigned = 1;
	typeis(sizeof(statbuf.st_nlink));
    }
    else if (strcmp(pc, "uid_t") == 0) {
	isunsigned = 0;
	typeis(sizeof(statbuf.st_uid));
    }
    else if (strcmp(pc, "gid_t") == 0) {
	isunsigned = 0;
	typeis(sizeof(statbuf.st_gid));
    }
    else if (strcmp(pc, "off_t") == 0) {
	isunsigned = 1;
	typeis(sizeof(statbuf.st_size));
    }

    exit(0);

}

void
typeis(i)
    int i;
{
    int shortlen = sizeof(unsigned short);
    int longlen = sizeof(unsigned long);
    char sign[64];

#ifdef ATT_3B2 		/* ATT 3B2: Thanks Joe Sirrianni */
    strcpy(sign, "unsigned");
#else
    if (isunsigned)
	strcpy(sign, "unsigned");
    else
	strcpy(sign, "signed");
#endif

    if (i == shortlen)
	printf("typedef %s short %s;\n", sign, pc);
    else
	printf("typedef %s long %s;\n", sign, pc);
}
