🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1332

Confused by filters

#1332
From: 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]);
}
Technical Details
Message-ID: <1dek5eINN2d5@news.aero.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!hela.iti.org!usc!news.aero.org!strauss

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!hela.iti.org!usc!news.aero.org!strauss
From: strauss@aero.org (Daryll J. Strauss)
Newsgroups: comp.sys.next.programmer
Subject: Confused by filters
Date: 6 Nov 1992 20:22:06 GMT
Organization: The Aerospace Corporation
Lines: 70
Distribution: world
Message-ID: <1dek5eINN2d5@news.aero.org>
NNTP-Posting-Host: armadillo.aero.org
Summary: How do I convert types via pastboard?
Keywords: fitlers pasteboard 3.0