home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
online
/
source
/
c
/
compilers
/
Tickle-4.0.sit.hqx
/
Tickle-4.0
/
src
/
asd.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
7KB
|
302 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#ifdef MPW3
# pragma segment ASD
#endif
#ifndef THINK_C_PRECOMPILED
#include <Types.h>
#include <Quickdraw.h>
#include <StandardFile.h>
#include <fcntl.h>
#include <stdio.h>
#include "defines.h"
#endif /*THINK_C_PRECOMPILED*/
#include <errno.h>
#include "asd.h"
#include "tcl.h"
char *
asd_entry_name(id)
int id;
{
char *idname = "UNKNOWN";
switch (id)
{
case ASDID_DATA_FORK: idname = "Data Fork"; break;
case ASDID_RSRC_FORK: idname = "Resource Fork"; break;
case ASDID_NAME_FORK: idname = "Filename"; break;
case ASDID_CMNT_FORK: idname = "Comment"; break;
case ASDID_MICN_FORK: idname = "Monochrome Icon"; break;
case ASDID_CICN_FORK: idname = "Color Icon"; break;
case ASDID_INFO_FORK: idname = "Information"; break;
case ASDID_FNDR_FORK: idname = "Finder Information"; break;
case ASDID_DATA_PATH: idname = "File Path"; break;
}
return idname;
}
#ifdef TCLAPPL
SF_asd_info()
{
Point mypoint;
SFReply asdreply;
SFTypeList mytypes;
FILE *asdfile;
int i, result = SUCCESS;
long bytes;
asd_fndr_fork finder;
asd_hdr header;
asd_entry entry;
UInitCursor();
mypoint.h = mypoint.v = 75;
mytypes[0] = 'TEXT';
MyGetFile( mypoint, "\pSelect ASD File:", NULL,
(CheckOption()?-1:1), mytypes, NULL, &asdreply );
if (asdreply.good)
{
p2cstr(asdreply.fName);
Feedback("Apple Single/Double Information for '%s'", asdreply.fName);
SetVol(NULL, asdreply.vRefNum);
asdfile = fopen(asdreply.fName, "r");
if (asdfile == NULL)
{
Feedback("Error #%d opening Apple Single/Double file '%s'",
errno, asdreply.fName);
return FAILURE;
}
bytes = fread(&header, 1, sizeof(asd_hdr), asdfile);
if (bytes != sizeof(asd_hdr))
{
Feedback("Error #%d reading Apple Single/Double header bytes.", errno);
result = FAILURE;
}
else if ( header.magic != MAGIC_APPLE_SINGLE &&
header.magic != MAGIC_APPLE_DOUBLE )
{
Feedback("File is not in Apple Single/Double format. magic x%08lX",
header.magic);
result = FAILURE;
}
else
{
print_asd_hdr(&header);
for ( i = 0 ; i < header.entries ; i++ )
{
fread(&entry, sizeof(asd_entry), 1, asdfile);
print_asd_entry(&entry);
switch (entry.id)
{
case ASDID_FNDR_FORK:
get_asd_fndr_data(asdfile, &entry, &finder);
print_asd_fndr(&finder);
break;
}
}
}
fclose(asdfile);
}
return result;
}
print_asd_entry(entry)
asd_entry *entry;
{
Feedback("Entry ID %d <%s>", entry->id, asd_entry_name(entry->id));
Feedback("Entry offset %ld length %ld", entry->offset, entry->length);
}
print_asd_fndr(finder)
asd_fndr_fork *finder;
{
Feedback("Type '%4.4s' Creator '%4.4s'", &finder->fdType, &finder->fdCreator);
Feedback("Flags x%2.2x Folder %d", finder->fdFlags, finder->fdFldr);
Feedback("Loc[0] %d Loc[1] %d", finder->fdLocation[0], finder->fdLocation[1]);
}
print_asd_hdr(hdr)
asd_hdr *hdr;
{
Feedback("Apple %s Format.",
(hdr->magic == MAGIC_APPLE_SINGLE) ? "Single" : "Double");
Feedback("Version 0x%08lx", hdr->version);
if (hdr->version == 0x00010000)
Feedback("File system '%16.16s'", hdr->filesys);
Feedback("Entries %d", hdr->entries);
}
#endif
asd_seek_a_name(asdfile, name)
FILE *asdfile;
char *name;
{
#pragma unused (asdfile, name)
}
get_asd_fndr_data(fp, entry, finder)
FILE *fp;
asd_entry *entry;
asd_fndr_fork *finder;
{
int position;
position = ftell(fp);
fseek(fp, entry->offset, SEEK_SET);
fread((char *)finder, 1, sizeof(asd_fndr_fork), fp);
fseek(fp, position, SEEK_SET);
}
int
Cmd_ASD_info(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
FILE *asdfile;
int i, result = SUCCESS;
long bytes;
asd_hdr header;
asd_entry entry;
#pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" asdfilename\"", (char *) NULL);
return TCL_ERROR;
}
asdfile = fopen(argv[1], "r");
if (asdfile == NULL)
{
Tcl_AppendResult(interp, "error opening file \"", argv[1],
"\"", Tcl_PosixError(interp), (char *) NULL);
return TCL_ERROR;
}
bytes = fread(&header, 1, sizeof(asd_hdr), asdfile);
if (bytes != sizeof(asd_hdr))
{
Tcl_AppendResult(interp, "error reading asd header data", (char *) NULL);
return TCL_ERROR;
}
else if ( header.magic != MAGIC_APPLE_SINGLE &&
header.magic != MAGIC_APPLE_DOUBLE )
{
Tcl_AppendResult(interp, "error file \"", argv[1],
"\" is not in Apple Single/Double format", (char *) NULL);
return TCL_ERROR;
}
else
{
append_asd_hdr(interp, &header);
for ( i = 0 ; i < header.entries ; i++ )
{
fread(&entry, sizeof(asd_entry), 1, asdfile);
append_asd_entry(asdfile, interp, &entry);
}
//Tcl_AppendResult(interp, "}", NULL);
}
fclose(asdfile);
return TCL_OK;
}
append_asd_hdr(interp, hdr)
Tcl_Interp *interp;
asd_hdr *hdr;
{
char version[32];
char filesys[64];
char entries[32];
sprintf(version, "0x%08lX", hdr->version);
sprintf(filesys, "\"%.16s\"", hdr->filesys);
sprintf(entries, "%d", hdr->entries);
Tcl_AppendResult(interp,
( (hdr->magic == MAGIC_APPLE_SINGLE) ? "Single " : "Double " ),
filesys, " ", version, " ", entries,
NULL);
}
append_asd_fndr(interp, finder)
Tcl_Interp *interp;
asd_fndr_fork *finder;
{
char type[8], creator[8];
char flags[32];
char folder[32];
sprintf(type, "\"%4.4s\"", &finder->fdType);
sprintf(creator, "\"%4.4s\"", &finder->fdCreator);
sprintf(flags, "0x%04X", finder->fdFlags);
sprintf(folder, "%d", finder->fdFldr);
Tcl_AppendResult(interp,
"{", type, " ", creator, " ", flags, " ", folder, "}",
NULL);
}
append_asd_entry(asdfile, interp, entry)
FILE *asdfile;
Tcl_Interp *interp;
asd_entry *entry;
{
char id[256];
char offset[256];
char length[256];
asd_fndr_fork finder;
sprintf(id, "%d", entry->id);
sprintf(offset, "%d", entry->offset);
sprintf(length, "%d", entry->length);
Tcl_AppendResult(interp, " {", id, " \"",
asd_entry_name(entry->id), "\" ",
offset, " ", length, " ",
NULL);
switch (entry->id)
{
case ASDID_FNDR_FORK:
get_asd_fndr_data(asdfile, entry, &finder);
append_asd_fndr(interp, &finder);
break;
default:
Tcl_AppendResult(interp, "{}", NULL);
break;
}
Tcl_AppendResult(interp, "}", NULL);
}