home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "ICAPI.h"
- #include "ICKeys.h"
-
- void InitToolbox(void);
-
- void InitToolbox()
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- /******************************************************************************
- *
- * Internet Config stuff
- *
- * Get Internet Config Prefs
- */
- Boolean InitICMappings( ICInstance *inst, Handle *ICmappings )
- {
- Boolean ICErr = true;
-
- if ( *ICmappings != nil )
- return ICErr;
-
- if (!ICStart(inst, '????'))
- { // init the sucker
- if (!ICFindConfigFile(*inst, 0, nil))
- { // locate the config file
- if (!ICBegin(*inst, icReadOnlyPerm))
- { // open up the file for reading
- ICAttr attr = 0;
-
- ICErr = false;
-
- if (!ICGetPrefHandle(*inst, (ConstStr255Param)kICMapping, &attr, ICmappings))
- {
- HUnlock(*ICmappings);
- }
- else
- {
- /* Can't get ICmappings */
- ICErr = true;
- }
- ICEnd(*inst); // all done
- }
- }
- }
-
- if((ICErr)&&(*ICmappings != nil))
- {
- DisposeHandle(*ICmappings);
- *ICmappings = nil;
-
- ICStop(*inst);
- }
-
- return ICErr;
- }
-
- void DisposeICMappings( ICInstance *inst, Handle *ICmappings )
- {
- if(*ICmappings != nil)
- {
- DisposeHandle(*ICmappings);
- *ICmappings = nil;
-
- ICStop(*inst);
- }
- }
-
- /******************************************************************************
- *
- * main
- *
- */
-
- main()
- {
- OSErr oserr;
- ICInstance ICinst;
- Handle ICmappings = nil;
- OSType Type;
- OSType Creator;
- char Description[256];
- short Binary;
- short MacFile;
- long pos = 0;
- ICMapEntry entry;
- StandardFileReply reply;
- short r;
- long i;
- Handle header;
-
-
- InitToolbox();
-
-
- if (noErr == InitICMappings( &ICinst, &ICmappings ))
- {
- StandardPutFile("\pSave as…","\pafpfile", &reply);
- if ( reply.sfGood )
- {
- if ( reply.sfReplacing )
- FSDelete( reply.sfFile.name, reply.sfFile.vRefNum );
-
- FSpCreate( &reply.sfFile, 'ttxt', 'TEXT', reply.sfScript);
- FSpOpenDF( &reply.sfFile, fsCurPerm, &r );
-
- if ( nil != (header = GetResource('TEXT', 128)))
- {
- i=GetHandleSize(header);
-
- FSWrite(r,&i, *header);
- ReleaseResource(header);
- }
- while ( noErr == ( oserr = ICGetMapEntry( ICinst, ICmappings, pos, &entry)))
- {
- pos += entry.total_length;
-
- if ( 0!= (i = (long)entry.extension[0]))
- {
- FSWrite(r, &i, &entry.extension[1]);
-
- if (entry.flags & ICmap_binary_mask)
- {
- i = 4;
- FSWrite(r, &i, "\tRaw");
- }
- else
- {
- i = 6;
- FSWrite(r, &i, "\tAscii");
- }
-
- i = 2;
- FSWrite(r, &i, "\t'");
-
- i = sizeof (OSType );
- FSWrite(r, &i, &entry.file_creator);
-
-
- i = 3;
- FSWrite(r, &i, "'\t'");
-
- i = sizeof (OSType );
- FSWrite(r, &i, &entry.file_type);
-
- i = 3;
- FSWrite(r, &i, "'\t\"");
- i = (long)entry.entry_name[0];
- FSWrite(r, &i, &entry.entry_name[1]);
-
-
- i = 2;
- FSWrite(r, &i, "\"\r");
- }
-
- }
- if ( nil != (header = GetResource('TEXT', 129)))
- {
- i=GetHandleSize(header);
-
- FSWrite(r,&i, *header);
- ReleaseResource(header);
- }
-
- FSClose( r );
- }
- DisposeICMappings( &ICinst, &ICmappings );
- }
- }
-
-