1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/*
TiMidity++ -- MIDI to WAVE converter and player
Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Macintosh interface for TiMidity
by T.Nogami <t-nogami@happy.email.ne.jp>
mac_util.c
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mac_util.h"
OSErr GetFullPath( const FSSpec* spec, Str255 fullPath)
{
CInfoPBRec myPB;
Str255 dirName;
OSErr myErr;
fullPath[0] = '\0';
BlockMoveData(spec->name, fullPath, spec->name[spec->name[0]]+1 );
myPB.dirInfo.ioNamePtr = dirName;
myPB.dirInfo.ioVRefNum = spec->vRefNum;
myPB.dirInfo.ioDrParID = spec->parID;
myPB.dirInfo.ioFDirIndex = -1;
do{
myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID;
myErr = PBGetCatInfoSync(&myPB);
dirName[0]++;
dirName[ dirName[0] ]=':';
if( dirName[0]+fullPath[0]>=254 ){ fullPath[0]=0; return 1; }
BlockMoveData(fullPath+1, dirName+dirName[0]+1, fullPath[0]);
dirName[0]+=fullPath[0];
BlockMoveData(dirName, fullPath, dirName[0]+1);
}while( !(myPB.dirInfo.ioDrDirID == fsRtDirID) );
return noErr;
}
void StopAlertMessage(Str255 s)
{
ParamText(s,"\p","\p","\p");
StopAlert(128,0);
}
void LDeselectAll(ListHandle lHandle)
{
Cell cell={0,0};
while(LGetSelect(true, &cell, lHandle)){
LSetSelect(false, cell, lHandle);
}
}
void TEReadFile(char* filename, TEHandle te)
{
FILE *in;
//clear TE
TESetSelect(0, (**te).teLength, te);
TEDelete(te);
//read
if( (in=fopen(filename, "rb"))==0 ){
char *s="No document.";
TEInsert(s, strlen(s), te);
}else{
char buf[80];
int len;
while(fgets( buf, 80, in)){
len=strlen(buf);
if( buf[len-1]==0xA ){
buf[len-1]=0xD; //len--;
}
TEInsert(buf, len, te);
}
fclose(in);
}
}
/***********************/
#pragma mark -
void SetDialogItemValue(DialogPtr dialog, short item, short value)
{
short itemType;
ControlHandle itemHandle;
Rect itemRect;
GetDialogItem(dialog, item, &itemType, (Handle*)&itemHandle, &itemRect);
SetControlValue(itemHandle, value);
}
short GetDialogItemValue(DialogPtr dialog, short item )
{
short itemType;
ControlHandle itemHandle;
Rect itemRect;
GetDialogItem(dialog, item, &itemType, (Handle*)&itemHandle, &itemRect);
return GetControlValue(itemHandle);
}
void SetDialogTEValue(DialogRef dialog, short item, int value)
{
Str255 s;
NumToString(value, s);
mySetDialogItemText(dialog, item, s);
}
int GetDialogTEValue(DialogRef dialog, short item )
{
Str255 s;
myGetDialogItemText(dialog, item, s);
return atof(p2cstr(s));
}
short ToggleDialogItem(DialogPtr dialog, short item )
{
short itemType, value;
ControlHandle itemHandle;
Rect itemRect;
GetDialogItem(dialog, item, &itemType, (Handle*)&itemHandle, &itemRect);
value=GetControlValue(itemHandle);
SetControlValue(itemHandle, !value);
return !value;
}
void myGetDialogItemText(DialogPtr theDialog, short itemNo, Str255 s)
{
short itemType;
Handle item;
Rect box;
GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
GetDialogItemText(item, s);
}
void mySetDialogItemText(DialogRef theDialog, short itemNo, const Str255 text)
{
short itemType;
Handle item;
Rect box;
GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
SetDialogItemText(item, text);
}
void SetDialogControlTitle(DialogRef theDialog, short itemNo, const Str255 text)
{
short itemType;
Handle item;
Rect box;
GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
SetControlTitle((ControlRef)item, text);
}
void SetDialogItemHilite(DialogRef dialog, short item, short value)
{
short itemType;
ControlRef itemHandle;
Rect itemRect;
GetDialogItem(dialog, item, &itemType, (Handle *)&itemHandle, &itemRect);
HiliteControl(itemHandle, value);
}
// ************************************************
void mac_TransPathSeparater(const char str[], char out[])
{
int i;
for( i=0; str[i]!=0; i++ ){
if( str[i]=='/' ){
out[i]=':';
} else {
out[i]=str[i];
}
}
}
#if 0
char** sys_errlist_()
{
static char s[80];
static char* ps=s;
static char** ret=&ps;
/* if( errno==ENOENT ) strcpy(s,"File not Found.");
else */ /* ENOENT vanished at CWPro2 */
if( errno==ENOSPC )
strcpy(s,"Out of Space.");
else
snprintf(s, 80, "error no.%d", errno);
return(ret-errno);
}
#endif /*0*/
// **************************************************
#pragma mark -
/* special fgets */
/* allow \r as return code */
char* mac_fgets( char buf[], int n, FILE* file)
{
int c,i;
if( n==0 ) return 0;
for( i=0; i<n-1; ){
buf[i++]=c=fgetc(file);
if( c=='\n' || c=='\r' || c==EOF ) break;
}
buf[i]=0;
if( i>0 && buf[i-1]==EOF ){ buf[i-1]=0; i--; }
if( i==0 && c==EOF && feof(file) ) return 0;
if( i==1 && buf[0]=='\n' ){ /* probably dos LF (Unix blank line?)*/
return mac_fgets( buf, n, file);
}
else if( buf[i-1]=='\n' ){ /*unix*/
return buf;
}
else if( buf[i-1]=='\r' ){ /*mac or dos*/
buf[i-1]='\n';
return buf;
}
return buf; /* for safty*/
}
void *mac_memchr (const void *s, int c, size_t n)
{
char* buf=(char*)s;
int i;
for( i=0; i<n; i++ ){
if( buf[i]==c || (c=='\n' && buf[i]=='\r') ){
return buf+i;
}
}
return 0;
}
void p2cstrcpy(char* dst, ConstStr255Param src)
{
int i;
for( i=0; i<src[0]; i++){
dst[i]=src[i+1];
}
dst[i]=0;
}
int mac_strcasecmp(const char *s1, const char *s2)
{
int c1,c2,i;
for( i=0; ; i++){
if( !s1[i] && !s2[i] ) return 0; //equal
if( !s1[i] || !s2[i] ) return 1;
c1= ( isupper(s1[i]) ? tolower(s1[i]) : s1[i] );
c2= ( isupper(s2[i]) ? tolower(s2[i]) : s2[i] );
if( c1 != c2 ) return 1;
}
return 0; //equal
}
#define CHAR_CASECMP(c1,c2) ((isupper(c1)?tolower(c1):(c1))!=(isupper(c2)?tolower(c2):(c2)))
int mac_strncasecmp(const char *s1, const char *s2, size_t n )
{
char c1,c2;
int i;
for( i=0; i<n; i++){
if( !s1[i] && !s2[i] ) return 0; //equal
if( !s1[i] || !s2[i] ) return 1;
c1= ( isupper(s1[i]) ? tolower(s1[i]) : s1[i] );
c2= ( isupper(s2[i]) ? tolower(s2[i]) : s2[i] );
if( c1 != c2 ) return 1;
}
return 0; //equal
}
#define min(a,b) (((a) < (b)) ? (a) : (b))
int strtailcasecmp(const char *s1, const char *s2)
{
int len1, len2, cmplen,
i, i1,i2;
len1=strlen(s1); len2=strlen(s2);
cmplen= min(len1,len2);
for( i=0, i1=len1-1, i2=len2-1; i<cmplen; i++, i1--, i2--){
if( CHAR_CASECMP(s1[i1],s2[i2])!=0 ){
return 1; //differ
}
}
return 0; //equal
}
|