/* Copyright (C) 2001-2004 by George Williams */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "macfonts.h" #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4)) #define true 1 #define false 0 int getushort(FILE *f) { int ch1 = getc(f); int ch2 = getc(f); if ( ch2==EOF ) return( EOF ); return( (ch1<<8)|ch2 ); } long getlong(FILE *f) { int ch1 = getc(f); int ch2 = getc(f); int ch3 = getc(f); int ch4 = getc(f); if ( ch4==EOF ) return( EOF ); return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 ); } static void putshort(int val, FILE *f) { putc(val>>8,f); putc(val&0xff,f); } static void dousage(void) { fprintf( stderr, "Usage: setfondname -name=newname font.dfont\n" ); exit(1); } static char *newname; static void NewName(char *name) { if ( name[1]=='-' ) ++name; if ( strcmp(name,"-usage")==0 ) dousage(); else if ( strncmp(name,"-name=",6)==0 ) newname = strdup(name+6); else dousage(); } static void ClearNames(void) { newname = NULL; } /* There's probably only one fond in the file, but there could be more so be */ /* prepared... */ /* http://developer.apple.com/techpubs/mac/Text/Text-269.html */ static void CheckFondList(FILE *f,long rlistpos,int subcnt,long rdata_pos, long name_list) { long start = ftell(f); int i; fseek(f,rlistpos,SEEK_SET); for ( i=0; i33 || header[63]!=0 || header[2+header[1]]!=0 ) return( false ); offset = 128+((header[0x53]<<24)|(header[0x54]<<16)|(header[0x55]<<8)|header[0x56]); return( IsResourceFork(f,offset)); } static int lastch=0, repeat = 0; static void outchr(FILE *binary, int ch) { int i; if ( repeat ) { if ( ch==0 ) { /* no repeat, output a literal 0x90 (the repeat flag) */ lastch=0x90; putc(lastch,binary); } else { for ( i=1; i>16)&0xff); outchr(binary,(val>>8)&0xff); outchr(binary,val&0xff); val = cnt = 0; } } if ( cnt!=0 ) { if ( cnt==1 ) outchr(binary,val<<2); else if ( cnt==2 ) { val<<=4; outchr(binary,(val>>8)&0xff); outchr(binary,val&0xff); } else if ( cnt==3 ) { val<<=6; outchr(binary,(val>>16)&0xff); outchr(binary,(val>>8)&0xff); outchr(binary,val&0xff); } } rewind(binary); ch = getc(binary); /* Name length */ /* skip name */ for ( i=0; i8 || strlen(dpt)>4 ) { char exten[8]; strncpy(exten,dpt,7); exten[4] = '\0'; /* it includes the dot */ if ( dpt-spt>6 ) dpt = spt+6; *dpt++ = '~'; *dpt++ = '1'; strcpy(dpt,exten); } return( IsResourceInFile(buffer)); } int main(int argc, char **argv) { int i, ret = 0; if ( argc==1 ) dousage(); for ( i=1; i