FILE *choose_mac_file(char *file_name,char action) { StandardFileReply reply; SFTypeList type_list; short num_types; FILE *the_file; /* start out by using StandardGetFile to get the file name and stuff */ num_types = -1; type_list[0] = 'YhMp'; StandardGetFile(nil, num_types, type_list, &reply); if (!reply.sfGood) { strcpy(file_name,"User Cancelled"); return 0; } /* now open the file */ strcpy(file_name,(char *)reply.sfFile.name); PtoCstr((unsigned char *)file_name); the_file = fopen_mac(reply.sfFile.vRefNum,reply.sfFile.parID, file_name,(char *)"r",action); return the_file; }
void gp_init (void) { extern char *gs_lib_default_path; extern char *gs_init_file; #if 0 /*...Initialize Ghostscript's default library paths and initialization file...*/ { int i; char **p; for (i = iGSLibPathStr, p = &gs_lib_default_path; i <= iGSInitFileStr; i++, p = &gs_init_file) { GetIndString (string, MACSTRS_RES_ID, i); (void) PtoCstr (string); *p = malloc ((size_t) (strlen ((char *) string) + 1)); strcpy (*p, (char *) string); } } #endif }
LVAL xsopen_resfile() { char *name; int fn; name = (char *) getstring(xlgastring()); xllastarg(); CtoPstr(name); fn = OpenResFile(name); PtoCstr(name); return((fn >= 0) ? cvfixnum((FIXTYPE) fn) : NIL); }
static int SFReadHdr(FILE *file, SFSTRUCT *snd, int infoBmax) /* utility to sample the header of an opened file, at most infoBmax info byts */ { int chans,dsize,infoSize; long len; float srate; char *info; char *fname; int err,i; if(infoBmax < SFDFLTBYTS) infoBmax = SFDFLTBYTS; infoBmax = infoBmax&-4; /* round down to multiple of four */ infoSize = infoBmax; if( (fname = FindFname(file)) == NULL) return(SFerror = SFE_NOPEN); /* couldn't find a pathname for this */ CtoPstr(fname); err = MacReadHeader(fname,0,&chans,&srate,&dsize,&info,&infoSize); /* will only read into info for infoSize byts, updates infoSize to avai bts */ /* len = MacFileLen(fname,0); if(len < 0) /* couldn't read file length */ /* printf("SFRdHdr: len read failed\n"); */ len = file->len; /* cheat by using THINK_C's internal record... */ PtoCstr(fname); if(err&7) /* just bottom 3 bits critical - optional info */ return(SFerror = SFE_NSF); /* reading mac header failed */ if(infoSize < SFDFLTBYTS) infoSize = SFDFLTBYTS; /* don't rock the boat */ if(infoBmax > infoSize) infoBmax = infoSize; /* actual bts in buf */ snd->magic = SFMAGIC; snd->headBsize = sizeof(SFSTRUCT) + infoSize - SFDFLTBYTS; snd->dataBsize = len; snd->channels = chans; snd->samplingRate = srate; if(dsize == 1) snd->format = SFMT_CHAR; else if(dsize == 4) snd->format = SFMT_FLOAT; else snd->format = SFMT_SHORT; for(i=0; i<infoBmax; ++i) snd->info[i] = info[i]; return(SFerror = SFE_OK); }
void LCD_doreadpict(Lcd *x) /*read in a 'PICT' selected by the user*/ { Point wher; SFReply reply; SFTypeList myFileTypes; short numFileTypes; OSErr err; QDProcsPtr savedProcs; long longCount,myEOF,filePos; short vol,refNum; long length; Atom a; short i; GrafPort *thePort; Symbol *file; EnterCallback(); wher.h = 20; wher.v = 20; numFileTypes = 1; /*display 'PICT's*/ myFileTypes[0] = 'PICT'; if (!x->fn[0]) { SFGetFile(wher,"\p",0L,numFileTypes,myFileTypes,0L,&reply); vol=reply.vRefNum; if (reply.good) { for (i=0;i<=reply.fName[0];i++) x->fn[i]=reply.fName[i]; PtoCstr((Byte *)x->fn); file=gensym(x->fn); SETSYM(&a,file); outlet_anything (x->file_outlet,ps_pictname,1,&a); CtoPstr(x->fn); } }
static int SFWriteHdr(FILE *file, SFSTRUCT *snd, int infoBmax) /* Utility to write out header to open file infoBmax optionally limits the number of info chars to write. infoBmax = 0 => write out all bytes implied by .headBsize field infoBmax >= SFDFLTBYS => write out only infoBmax infobytes */ { int chans,dsize,infoSize; float srate; char *info; char *fname; int err,i; if(snd->magic != SFMAGIC) return(SFerror = SFE_NSF); if(infoBmax >= SFDFLTBYTS && infoBmax < SFInfoSize(snd) ) infoSize = infoBmax; else infoSize = SFInfoSize(snd); chans = snd->channels; srate = snd->samplingRate; if(snd->format == SFMT_CHAR || snd->format == SFMT_ALAW || snd->format == SFMT_ULAW) dsize = 1; else if(snd->format == SFMT_LONG || snd->format == SFMT_FLOAT) dsize = 4; else dsize = 2; /* default short */ info = snd->info; if( (fname = FindFname(file)) == NULL) return(SFerror = SFE_NOPEN); /* couldn't find a pathname for this */ CtoPstr(fname); err=MacAddHeader(fname,0/*vref*/,chans,srate,dsize,info,infoSize); MacSetCreator(fname,0/*vref*/); /* make an Sd2 file */ PtoCstr(fname); if(err) return(SFerror = SFE_WRERR); else return(SFerror = SFE_OK); }
int SFRdXInfo(FILE *file, SFSTRUCT *psnd, int done) /* fetch any extra info bytes needed in view of read header Passes open file handle, existing sound struct already read 'done' bytes; rest inferred from structure */ { int chans,dsize,infoSize; long len; float srate; char *info; char *fname; int err,i; int rem; if( (fname = FindFname(file)) == NULL) return(SFerror = SFE_NOPEN); /* couldn't find a pathname for this */ CtoPstr(fname); infoSize = SFInfoSize(psnd); /* reread whole of info */ err = MacReadHeader(fname,0,&chans,&srate,&dsize,psnd->info,&infoSize); PtoCstr(fname); if(err) return(SFerror = SFE_NOPEN); /* reading mac header failed */ else return(SFerror = SFE_OK); }
char *macFindFile(char *fileName, Str255 message, Str255 defaultname, Integer readWrite, Integer ntypes, OSType * types, Integer * volume) { SFTypeList myTypes; Point p; Integer numTypes; Integer vRefNum = (volume != (Integer *) 0) ? *volume : 0; LongInt dirID; int i; WHERE("macFindFile"); if (fileName[0] == '\0') { /* Use standard file dialog box */ SetPt(&p, 82, 90); DeactivateWindow(); /*unhighlight front window*/ if (readWrite == WRITEIT) { /* write */ DialogEdit = true; NDialogButtons = 2; ButtonChars[0] = 's'; ButtonChars[1] = 'n'; SFPPutFile(p, message, defaultname, NullDialogHookPtr, &Reply, putDlgID, MyDialogFilterPtr); } /*if (readWrite == WRITEIT)*/ else {/* read */ if(ntypes == 0) { numTypes = 0; myTypes[numTypes++] = 'TEXT'; myTypes[numTypes++] = 'ttro'; if(types != (OSType *) 0) { myTypes[numTypes++] = types[0]; } } else { numTypes = (ntypes <= 4) ? ntypes : 4; /*play it safe*/ for(i = 0;i < numTypes; i++) { myTypes[i] = types[i]; } } DialogEdit = false; NDialogButtons = 2; ButtonChars[0] = 'o'; /* Open */ ButtonChars[1] = 'n'; /* Cancel */ SFPGetFile(p, message, NullFileFilterPtr, numTypes, myTypes, NullDialogHookPtr, &Reply, getDlgID, MyDialogFilterPtr); } /*if (readWrite == WRITEIT){}else{}*/ macUpdate((WindowPtr) 0); if (!Reply.good) { /* cancelled */ return (0); } vRefNum = Reply.vRefNum; if (volume != (Integer *) 0) { *volume = vRefNum; } PtoCstr((unsigned char *) Reply.fName); strcpy(FileName, (char *) Reply.fName); CtoPstr((char *) Reply.fName); fileName = FileName; } /*if (fileName[0] == '\0')*/ else if (volume != (Integer *) 0 && vRefNum == 0 && HGetVol((StringPtr) 0, &vRefNum, &dirID) == noErr) { *volume = vRefNum; } if (vRefNum != 0) { SetVol(0L, vRefNum); } return (fileName); } /*macFindFile()*/
long iniMacros(void) { #ifndef MACINTOSH int i; for (i = 0; macros[i].name; i++) { if (!installMacro(macros[i].text, macros[i].name, strlen(macros[i].text))) { goto errorExit; } } #else /*MACINTOSH*/ Integer id = IDBASE, id1; Integer i, count = CountResources(MACROTYPE); char *prefix = NAMEPREFIX; Integer prefixLength = strlen(prefix); Str255 resName; char *name = (char *) resName; ResType type; unsigned char **text; /* examine all resources of the wanted type If the name starts with prefix, install it as long as it is not the name of the dummy last macro */ for(i=1; i<= count; i++) { text = (unsigned char **) GetIndResource(MACROTYPE, i); if (ResError() != noErr) { break; } GetResInfo((Handle) text, &id1, &type, resName); if (ResError() != noErr) { goto errorExit; } PtoCstr((unsigned char *) name); if (strncmp(prefix, name, prefixLength) == 0 && strcmp(name + prefixLength, ENDNAME) != 0) { HLock((Handle) text); /* first two characters of *text give number of characters */ if (!installMacro((char *) (*text) + 2, name + prefixLength, (*text)[0] * 256 + (*text)[1])) { goto errorExit; } HUnlock((Handle) text); } ReleaseResource((Handle) text); } /*while(1)*/ #endif /*MACINTOSH*/ return (1); errorExit: return (0); } /*iniMacros()*/