🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
1 messages
1 total messages Started by Daryll J. Strauss Fri, 06 Nov 1992 20:22
Confused by filters
#1332
Author: Daryll J. Strauss
Date: Fri, 06 Nov 1992 20:22
64 lines
2578 bytes
I am trying to write an rtf to ascii converter using pasteboards and
filters under 3.0. If you've got a solution that produces good output
I'd also like hear about it, (rtf-ascii from 2.x was pretty ugly) but I
really want to understand why this code doesn't work.

So, I figured I would take the name of an rtf file on the command line
and produce ascii on standard out. The process would be to open a new
pasteboard by filtering the filename, check if this new pasteboard
contains the ascii type, grab the data from the pasteboard, and then
print it out. This isn't working. I get a new unique pasteboard with
ascii available, but reading the data from the pasteboard returns nil.
Nil is defined to mean either 1) the data changed out from under me. I
don't think this is possible, because it is a private pasteboard 2) The
owner of the pasteboard didn't respond to the conversion request. I
don't think this should happen, because the converter is NeXT provided
and seems to work for other applications such as Edit.

The code is included below. I don't see the flaw in my reasoning, can
anyone provide some insight?

					Thanks In Advance,
						- |Daryll
//
// File: rta.m
// Compile: cc -o rta -g rta.m -lNeXT_s
// Run: rta junk.rtf
//
#import <appkit/appkit.h>
#import <stdio.h>

BOOL
RTF_To_ASCII(const char *filename)
{
	Pasteboard *board;
	char *data;
	int i, length;
	NXAtom prefers[] = {NXAsciiPboardType};
	
	board = [Pasteboard newByFilteringFile:filename];
	if ([board findAvailableTypeFrom:prefs num:1]!=NXAsciiPboardType) {
		fprintf(stderr, "Couldn't convert to Ascii\n");
		[board free];
		return(FALSE);
	}
	if ([board readType:NXAsciiPboardType data:&data length:&length]) {
		for (i = 0; i < length; i++) putchar(data[i]);
		[board deallocatePasteboardData:data length:length];
		[board free];
		return(TRUE);
	} else {
		fprintf(stderr, "Couldn't read pasteboard data\n");
		[board free];
		return(FALSE);
	}
}

main(int argc, const char* argv[])
{
	if (argc<2) {
		fprintf(stderr, "usage: %s in\n", argv[0]);
		exit(1);
	}
	RTF_To_ASCII(argv[1]);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads