home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / next / programm / 7076 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.4 KB  |  84 lines

  1. Path: sparky!uunet!hela.iti.org!usc!news.aero.org!strauss
  2. From: strauss@aero.org (Daryll J. Strauss)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Confused by filters
  5. Date: 6 Nov 1992 20:22:06 GMT
  6. Organization: The Aerospace Corporation
  7. Lines: 70
  8. Distribution: world
  9. Message-ID: <1dek5eINN2d5@news.aero.org>
  10. NNTP-Posting-Host: armadillo.aero.org
  11. Summary: How do I convert types via pastboard?
  12. Keywords: fitlers pasteboard 3.0
  13.  
  14. I am trying to write an rtf to ascii converter using pasteboards and
  15. filters under 3.0. If you've got a solution that produces good output
  16. I'd also like hear about it, (rtf-ascii from 2.x was pretty ugly) but I
  17. really want to understand why this code doesn't work.
  18.  
  19. So, I figured I would take the name of an rtf file on the command line
  20. and produce ascii on standard out. The process would be to open a new
  21. pasteboard by filtering the filename, check if this new pasteboard
  22. contains the ascii type, grab the data from the pasteboard, and then
  23. print it out. This isn't working. I get a new unique pasteboard with
  24. ascii available, but reading the data from the pasteboard returns nil.
  25. Nil is defined to mean either 1) the data changed out from under me. I
  26. don't think this is possible, because it is a private pasteboard 2) The
  27. owner of the pasteboard didn't respond to the conversion request. I
  28. don't think this should happen, because the converter is NeXT provided
  29. and seems to work for other applications such as Edit.
  30.  
  31. The code is included below. I don't see the flaw in my reasoning, can
  32. anyone provide some insight?
  33.  
  34.                     Thanks In Advance,
  35.                         - |Daryll
  36. //
  37. // File: rta.m
  38. // Compile: cc -o rta -g rta.m -lNeXT_s
  39. // Run: rta junk.rtf
  40. //
  41. #import <appkit/appkit.h>
  42. #import <stdio.h>
  43.  
  44. BOOL
  45. RTF_To_ASCII(const char *filename)
  46. {
  47.     Pasteboard *board;
  48.     char *data;
  49.     int i, length;
  50.     NXAtom prefers[] = {NXAsciiPboardType};
  51.     
  52.     board = [Pasteboard newByFilteringFile:filename];
  53.     if ([board findAvailableTypeFrom:prefs num:1]!=NXAsciiPboardType) {
  54.         fprintf(stderr, "Couldn't convert to Ascii\n");
  55.         [board free];
  56.         return(FALSE);
  57.     }
  58.     if ([board readType:NXAsciiPboardType data:&data length:&length]) {
  59.         for (i = 0; i < length; i++) putchar(data[i]);
  60.         [board deallocatePasteboardData:data length:length];
  61.         [board free];
  62.         return(TRUE);
  63.     } else {
  64.         fprintf(stderr, "Couldn't read pasteboard data\n");
  65.         [board free];
  66.         return(FALSE);
  67.     }
  68. }
  69.  
  70. main(int argc, const char* argv[])
  71. {
  72.     if (argc<2) {
  73.         fprintf(stderr, "usage: %s in\n", argv[0]);
  74.         exit(1);
  75.     }
  76.     RTF_To_ASCII(argv[1]);
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.