Re: [OT?] write C program with UTF16LE

2004-03-15 Thread Chuck Swiger
Adam Bozanich wrote:
On Mon, 15 Mar 2004, Matthew Seaman wrote:
Errr... no.  Not even if you're using the Linux devtools to create a
Linux executable.  You're using the FreeBSD system libc.  Same API,
different code, different licencing terms.
Yep, one look at /usr/include/stdio.h proves you right.  Thanks... I (obviously)
didn't realize that.
Now I'm very curious.  If BSD has it's own C api, did it at one time have
it's own compiler?  If so, what happened to it?
Well, one can track down the original C compiler written by Kernighan & 
Ritchie.  Somewhere around 1981, one can also find references to PCC, the 
"Portable C Compiler" by Aho & Johnson, which has largely been replaced by 
GNU's gcc since then.  There's been some effort recently to make FreeBSD go 
using Intel's icc, as well.

Does gcc have to know about the different syscall calling conventions?
GCC has to know about the local architecture's calling conventions.  GCC does 
not need to know anything special about the system call interface defined by 
the kernel and libc.

--
-Chuck
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: [OT?] write C program with UTF16LE

2004-03-15 Thread Adam Bozanich

On Mon, 15 Mar 2004, Matthew Seaman wrote:

> On Mon, Mar 15, 2004 at 02:28:17AM -0800, Adam Bozanich wrote:
> > On Mon, 15 Mar 2004, Zhang Weiwu wrote:
>
> > > but I am the kind of newbie don't know if I am using glibc at all. When I
> > > just write
> > > #include 
> > > Am i using the stdio.h from glibc?
>
> > Yes, on FreeBSD you are using GNU's libc
>
> Errr... no.  Not even if you're using the Linux devtools to create a
> Linux executable.  You're using the FreeBSD system libc.  Same API,
> different code, different licencing terms.
>

Yep, one look at /usr/include/stdio.h proves you right.  Thanks... I (obviously)
didn't realize that.

Now I'm very curious.  If BSD has it's own C api, did it at one time have
it's own compiler?  If so, what happened to it?

Does gcc have to know about the different syscall calling conventions?

I'm trying to look through /usr/src/lib/ right now, but I don't understand
most of what is going on.

Thanks a lot,
-Adam


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: [OT?] write C program with UTF16LE

2004-03-15 Thread Matthew Seaman
On Mon, Mar 15, 2004 at 02:28:17AM -0800, Adam Bozanich wrote:
> On Mon, 15 Mar 2004, Zhang Weiwu wrote:

> > but I am the kind of newbie don't know if I am using glibc at all. When I
> > just write
> > #include 
> > Am i using the stdio.h from glibc?

> Yes, on FreeBSD you are using GNU's libc

Errr... no.  Not even if you're using the Linux devtools to create a
Linux executable.  You're using the FreeBSD system libc.  Same API,
different code, different licencing terms.

But it makes no practical difference to the task at hand.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature


Re: [OT?] write C program with UTF16LE

2004-03-15 Thread Adam Bozanich


On Mon, 15 Mar 2004, Adam Bozanich wrote:
>
>

Sorry, There is an error here.  fgets() reads the number you specify minus
one chars, then null terminates the string.  these lines:

>
> char  delbuf[CHUNKSIZE];
> char  chunks[CHUNKSIZE * MAX_CHUNK_COUNT];
>

Should be:

 char  delbuf[CHUNKSIZE + 1];
 char  chunks[CHUNKSIZE * MAX_CHUNK_COUNT + 1 ];

-Adam


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: [OT?] write C program with UTF16LE

2004-03-15 Thread Adam Bozanich


On Mon, 15 Mar 2004, Zhang Weiwu wrote:

> Hello. Although I write some php/perl script, I don't write C program. Now
> I have a very large text file in UTF16LE format, the rule is strings are
> seperated by numbers. Say
>
> 0300 6100 6200 6300 0400 6700 5400 9800 7400 0300 
>
> Leading 0300 means the following 3 characters (6 bytes) is a string, and
> the next 0400 means the following 4 characters makes another string.
>

Here's an example using the fgets function.  see 'man fgets'.  There are
probably a bunch of ways to go about this, but this one is nice and
simple.

#include

#define CHUNKSIZE 5  /* 4 characters and a space */

/* max number of encoded chars if you are using 2 decimal places for the count*/
#define MAX_CHUNK_COUNT 99

int main(int argc, char **argv) {

char  delbuf[CHUNKSIZE];
char  chunks[CHUNKSIZE * MAX_CHUNK_COUNT];

int  chunk_count;

while(fgets(delbuf,CHUNKSIZE+1,stdin) != NULL)
{
/* you may not want to destroy this */
delbuf[2] = '\0';
chunk_count = atoi(delbuf);

if(fgets(chunks, (CHUNKSIZE * chunk_count) + 1 , stdin) == NULL){
fprintf(stderr,"can't read all of the string\n");
break;
}

fprintf(stdout,"\n%s",chunks);
}
exit(0);
}


This worked for the numbers you gave, but I'm sure that you need to add
some better error handling and what not.  You probably also don't want
to trash the buffer holding the string length.

Try running with this:

./a.out < inputfile > outputfile

> but I am the kind of newbie don't know if I am using glibc at all. When I
> just write
> #include 
> Am i using the stdio.h from glibc?
>

Yes, on FreeBSD you are using GNU's libc

I hope this gives you some ideas, good luck!

-Adam

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


[OT?] write C program with UTF16LE

2004-03-14 Thread Zhang Weiwu
Hello. Although I write some php/perl script, I don't write C program. Now 
I have a very large text file in UTF16LE format, the rule is strings are 
seperated by numbers. Say

0300 6100 6200 6300 0400 6700 5400 9800 7400 0300 

Leading 0300 means the following 3 characters (6 bytes) is a string, and 
the next 0400 means the following 4 characters makes another string.

I need to read the file and replace every number-style string seperator 
with a linefeed. I decide to use C, it is a good chance to start some 
practice on C. The old getc() I learnt from school is not my cup of tea, 
because I always need to do two getcs at once, and for the seperators I 
need to do getc()+getc()*256. What is the best practics to deal with such 
number/UTF16 mixed text? 

I googled around and find some tutorials, most i18n toturials think I'm 
already a C expert:( I find the glibc manual looks good learning resource, 
but I am the kind of newbie don't know if I am using glibc at all. When I 
just write 
#include 
Am i using the stdio.h from glibc?

I think simply point me a tutorial that fits me will do me more help.

Thank you.

_
与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn  

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"