RE: PB Save As ASCII? - solved
RE: PB Save As ASCII? - solved
- Subject: RE: PB Save As ASCII? - solved
- From: "Todd Blanchard" <email@hidden>
- Date: Thu, 14 Feb 2002 15:02:21 -0800
- Thread-topic: PB Save As ASCII?
Although in a totally lame way. This used to work on the old OSX Server
- you could use text edit or PB and save as *all* the available
encodings. Now it seems to want to protect you from data loss (although
in this case - data loss is entirely the point).
For those suggesting Non-lossy ASCII, it just gives you a different
illegal character.
In desperation I did this:
#include <stdio.h>
int main(int argc, char** argv)
{
FILE *in=0, *out=0;
int c;
if(argv == 3)
{
in = fopen(argv[1],"r");
out = fopen(argv[2],"w");
while((c=getc(in))!=EOF){ if(c < 128) putc(out); else
putc(' '); }
fclose(in); fclose(out);
}
return 0;
}
Holy freakin cow.
-----Original Message-----
From: Ondra Cada [
mailto:email@hidden]
Sent: Thursday, February 14, 2002 12:47 PM
To: Todd Blanchard
Cc: Cocoa-dev
Subject: Re: PB Save As ASCII?
Todd,
>
>>>>> Todd Blanchard (TB) wrote at Thu, 14 Feb 2002 09:22:12 -0800:
TB> This sucks. I'm going to have to retype the whole 2 pages of code
by
TB> hand because no utility I can find will save the text as lossy
ascii.
Although I completely share your sentiment of things which are so
foolproof
to be actually next to unuseable, I guess you could do this in
*considerably*
shorter time:
24 /tmp> cat > q.m
#import <Foundation/Foundation.h>
void main() {
id p=[NSAutoreleasePool new];
id d=[NSData dataWithContentsOfFile:@"contacts.vcf"];
id s=[[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
d=[s dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[d writeToFile:@"/tmp/contacts.vcf" atomically:NO];
}
25 /tmp> cc -framework Foundation q.m && ./a.out
q.m: In function `main':
q.m:2: warning: return type of `main' is not `int'
26 /tmp>
using, of course, the name of your offending file and appropriate
encoding
instead of mine "contacts.vcf" and NSUTF8StringEncoding which I used so
as
the test did anything for real...
And naturally, if your file is saveable into any one-byte encoding (say,
ISO
L2), you can use much simpler "tr -d '\200-\377' < infile > outfile" in
a
fraction of even those few minutes needed for the above ;))))
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.