macutils.mm 858 B

1234567891011121314151617181920212223242526272829
  1. #import <Cocoa/Cocoa.h>
  2. #define MAXSTRLEN 260
  3. inline char *s_strncpy(char *d, const char *s, size_t m) { strncpy(d,s,m); d[m-1] = 0; return d; };
  4. inline char *s_strcat(char *d, const char *s) { size_t n = strlen(d); return s_strncpy(d+n,s,MAXSTRLEN-n); };
  5. void mac_pasteconsole(char *commandbuf)
  6. {
  7. NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
  8. NSString *type = [pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]];
  9. if (type != nil) {
  10. NSString *contents = [pasteboard stringForType:type];
  11. if (contents != nil)
  12. s_strcat(commandbuf, [contents cStringUsingEncoding:NSASCIIStringEncoding]); // 10.4+
  13. }
  14. }
  15. /*
  16. * 0x1040 = 10.4
  17. * 0x1050 = 10.5
  18. * 0x1060 = 10.6
  19. */
  20. int mac_osversion()
  21. {
  22. SInt32 MacVersion;
  23. Gestalt(gestaltSystemVersion, &MacVersion);
  24. return MacVersion;
  25. }