/***************************************LCKG
*                                          *
*           $VER: FileIdent 1.12           *
*                                          *
*        (C) Copyright 1993,1994           *
*                                          *
*           sTRIDER sYNDIcATE              *
*                                          *
*          All Rights Reserved             *
*                                          *
* Desc.:                                   *
* Example of using the FileID.library      *
*                                          *
* Do what U want with the source.          *
* Note the copyright of the FileID.library *
*                                          *
* ---------------------------------------- *
* Name    : FileIdent                      *
* Filename: FileIdent.c                    *
* Version : 1.12                           *
* Part    : FileIdent (1)                  *
* Parts   : 1                              *
* Begin   : 07-Nov-94 20:50:01             *
* Date    : 08-Nov-94 19:31:46             *
*******************************************/

char *VerStr="$VER: FileIdent 1.12 bY sTRIDER sYNDIcATE";

/* includes ----------------------------------------------------------------- */

#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <clib/exec_protos.h>
#include <proto/FileID.h>

/* structs for FileID.library ----------------------------------------------- */

struct FI_FileInfo	*MyFileInfo;
struct FileIDBase		*FileIDBase;

/* prototypes --------------------------------------------------------------- */

void ShutDown(int);

/* main --------------------------------------------------------------------- */

void main(int argc, char *argv[])
{
	int		error=0;
	char	str[102],
				str2[102];

		/* try to open FileID.library v6.0 */

	if(!(FileIDBase=(struct FileIDBase *)OpenLibrary("FileID.library",6L)))
	ShutDown(1); /* Shutdown if fail opening the FileID.library */

		/* Allocate FileInfo (needed for the Library because of structs) */

	MyFileInfo=(struct FI_FileInfo *)FIAllocFileInfo();

	printf("\n[33mFileIdent 1.12 [0m(C) Copyright 1993,1994 by sTRIDER oF sYNDIcATE.\n\nFile identify with use of the [33mFileID.library v6.0\n[0m(C) Copyright 1993,1994 BLOODROCK of SYNDICATE.\n");
	if(argc==1) {                            /* If no argument ask for Filename */
		printf("\nGive Path and Filename>: ");
		gets(str);
		if(str[0]=='"' && str[strlen(str)-1]=='"') strmid(str,str2,2,strlen(str)-2);
		else strcpy(str2,str);
		if(!(error=FIIdentifyFromName((struct FI_FileInfo *)MyFileInfo,str2))) {
			printf("\n%-40s %s %d %d %d %d %d",str2,MyFileInfo->FI_Description,MyFileInfo->FI_ID,MyFileInfo->FI_GlobalFileClass,MyFileInfo->FI_DLPackNum,MyFileInfo->FI_DLPackType,MyFileInfo->FI_PackFlags);
		} else printf("\nFileID Error no. %d. %s",error,MyFileInfo->FI_Description);
	} else if(argc>1) {
		int lv=1;
		while(lv<argc) {
			if(!(error=FIIdentifyFromName((struct FI_FileInfo *)MyFileInfo,argv[lv]))) {
				printf("\n%-40s %s %d %d %d %d %d",argv[lv],MyFileInfo->FI_Description,MyFileInfo->FI_ID,MyFileInfo->FI_GlobalFileClass,MyFileInfo->FI_DLPackNum,MyFileInfo->FI_DLPackType,MyFileInfo->FI_PackFlags);
			} else printf("\nFileID Error no. %d. %s",error,MyFileInfo->FI_Description);
			lv++;
		}
	}
	ShutDown(error);
}

/* procedures --------------------------------------------------------------- */

void ShutDown(int error)
{
	if(error>0) {
		printf("\nError %d! ",error);
		if(error==1) printf("\nCan't open FileID.library");
	}

		/* Free allocated memory */

	if(MyFileInfo) FIFreeFileInfo((struct FI_FileInfo *)MyFileInfo);

		/* Close FileID.library v6.0 */

	if(FileIDBase) CloseLibrary((struct Library *)FileIDBase);

	printf("\n\n");
	exit(0);
}

/* EOF ---------------------------------------------------------------------- */
