=================================================================== RCS file: /home/cvs/OpenXM/src/cfep/MyOpenGLCommand.m,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -p -r1.1.1.1 -r1.4 --- OpenXM/src/cfep/MyOpenGLCommand.m 2006/03/03 23:31:12 1.1.1.1 +++ OpenXM/src/cfep/MyOpenGLCommand.m 2006/03/08 04:58:14 1.4 @@ -25,12 +25,15 @@ } -(void)print { int i; - NSLog(@"command=%s, opCode=%d, [",command,opCode); + NSLog(@"command=%@s, opCode=%d, [",command,opCode); for (i=0; i<4; i++) NSLog(@"%f,",f4[i]); NSLog(@"; "); for (i=0; i<4; i++) NSLog(@"%d,",i4[i]); NSLog(@"]\n"); } +-(NSString *)toString { + return [NSString stringWithFormat: @"%@[%d], %f, %f, %f, %f; %d, %d, %d, %d",command,opCode,f4[0],f4[1],f4[2],f4[3],i4[0],i4[1],i4[2],i4[3]]; +} +(MyOpenGLCommand *)allocAndCompile: (NSString *)cmd by: (id) sender { MyOpenGLCommand *c; c=[[MyOpenGLCommand alloc] init]; @@ -69,9 +72,24 @@ }else if ([s compare: @"glColor4f"] == NSOrderedSame) { opCode = CFEPglColor4f; fargc = 4; iargc = 0; endGroup = NO; + }else if ([s compare: @"glClear"] == NSOrderedSame) { + opCode = CFEPglClear; fargc = 0; iargc = 1; endGroup = YES; + + }else if ([s compare: @"glClearColor"] == NSOrderedSame) { + opCode = CFEPglClearColor; fargc = 4; iargc = 0; endGroup = YES; + + }else if ([s compare: @"glClearDepth"] == NSOrderedSame) { + opCode = CFEPglClearDepth; fargc = 1; iargc = 0; endGroup = YES; + }else if ([s compare: @"glEnd"] == NSOrderedSame) { opCode = CFEPglEnd; fargc = 0; iargc = 0; endGroup = YES; + }else if ([s compare: @"glFlush"] == NSOrderedSame) { + opCode = CFEPglFlush; fargc = 0; iargc = 0; endGroup = YES; + + }else if ([s compare: @"glPointSize"] == NSOrderedSame) { + opCode = CFEPglPointSize; fargc = 1; iargc = 0; endGroup = NO; + }else if ([s compare: @"glRectf"] == NSOrderedSame) { opCode = CFEPglRectf; fargc = 4; iargc = 0; endGroup = YES; @@ -115,6 +133,8 @@ return nil; } // Format glxxxpfqi fargc=p, iargc=q. Example: glxxx4f1i, 0.1,0.2,0.3,0.4,34 + command = s; + [command retain]; // bug. How to release? if (fargc > 0) { for (i=1; i< min(n,fargc+1); i++) { x = [a objectAtIndex: i]; @@ -145,7 +165,6 @@ -(int *) getI4 { return i4; } -(NSArray *)getArgv { return argv; } - @end /* Code to test MyFloat put in compile: @@ -279,5 +298,48 @@ static int debugMyUtil = 0; NSLog(@"mytest=%@\n",[MyUtil arrayOfStringFrom: @" [1, 2,3, 4,5]"]); NSLog(@"mytest=%@\n",[MyUtil arrayOfStringFrom: @"[[1],2,[[3,[4]]],5]"]); // There is a bug. Output is 1,2,... */ + ++(NSString *)pruneThings: (NSString *)ss { + int n,i, start,end; + unichar c; + unichar s[SMAX]; + NSString *ans; + n = [ss length]; + if (n >= SMAX-1) { + NSLog(@"Too big string for pruneThings.\n"); + return nil; + } + start = 0; end = n-1; + for (i=0; i 0x20) break; + } + for (i=n-1; i>=0; i--) { + c = [ss characterAtIndex: i]; + end = i; + if (c > 0x20) break; + } + if (start > end) return nil; + for (i=0; i<= end-start ; i++) { + s[i] = [ss characterAtIndex: (start+i)]; + s[i+1] =0; + } + ans = [NSString stringWithCharacters: s length: (end-start+1)]; + return ans; +} + ++(id)attributedStringWithPath: (NSString *)path { + NSFileWrapper *theWrapper; + NSTextAttachment *theAttachment; + NSAttributedString *aStr; + theWrapper = [[NSFileWrapper alloc] initWithPath: path]; + if (!theWrapper) NSLog(@"theWrapper is nil. Path=[%@]\n",path); + if (!theWrapper) return nil; + theAttachment = [[NSTextAttachment alloc] initWithFileWrapper:theWrapper]; + aStr = [NSAttributedString attributedStringWithAttachment:theAttachment]; + return aStr; // How should I do autorelease? +} + -@end +@end \ No newline at end of file