[Tinycc-devel] How to use char "\"

2014-09-30 Thread JFC Morfin

May be not the right place to ask?
I am trying to port my old bcc32 libraries under tcc.

I have a problem with the char "\". For example in the line:

   strpbrk (file_name,"\*?")

ir order to know if i have a simple file name, tcc tells me "unknown 
escape sequence".


When I want use as a char both text[i]='\' and text[i]='\\' do not 
work. Since I am there working on text strings I cannot equate '\' to 
ascii 28 first.


Thank you for your help.
jfc


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Thomas Preud'homme
Le mardi 30 septembre 2014, 11:56:43 JFC Morfin a écrit :
> May be not the right place to ask?

It's ok but you should have created a new mail instead of replying to an email 
and changing the subject.

> I am trying to port my old bcc32 libraries under tcc.
> 
> I have a problem with the char "\". For example in the line:
> 
> strpbrk (file_name,"\*?")
> 
> ir order to know if i have a simple file name, tcc tells me "unknown
> escape sequence".

The manpage doesn't say that the strings accept escape sequence. Is it even 
defined in the standard? Sounds like a bug in TinyCC.

> 
> When I want use as a char both text[i]='\' and text[i]='\\' do not
> work. Since I am there working on text strings I cannot equate '\' to
> ascii 28 first.

'\' should be correct. What is the error you get?

Best regards,

Thomas

signature.asc
Description: This is a digitally signed message part.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Daniel Glöckner
Hi,

On Wed, Oct 01, 2014 at 12:06:24AM +0800, Thomas Preud'homme wrote:
> > I have a problem with the char "\". For example in the line:
> > 
> > strpbrk (file_name,"\*?")
> > 
> > ir order to know if i have a simple file name, tcc tells me "unknown
> > escape sequence".
> 
> The manpage doesn't say that the strings accept escape sequence. Is it even 
> defined in the standard? Sounds like a bug in TinyCC.

Thomas, C does support the escape sequences \a, \b, \f, \n, \r, \t,
\v, \', \", \?, \\, \<3octal>, \x<2hex>, \u<4hex>, and \U<8hex>.
I guess BCC probably interpreted \* as \\*.

> > When I want use as a char both text[i]='\' and text[i]='\\' do not
> > work. Since I am there working on text strings I cannot equate '\' to
> > ascii 28 first.
> 
> '\' should be correct. What is the error you get?

'\\' should be correct. What is the error you get?

Best regards,

  Daniel

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Jefsey

Thank you all.

The problem the I have is that I am quite rusty at my C and TCC is 
new to me :-)


1. First thing is that I use "tcc .c" and I do not know how to 
get more than one kind of error at a time? Is there a way to have all 
the compilation errors one shot in a file ?
2. the "\\" for "\" seems to work (does not report error. "\." now 
complain, but not if I enter '.', as if \ was only an escape for \ 
except when followed by n as in \n.

3. The error I am reported now is that "isascii" us an unknopwn symbol.

It seems that I have to fish difficulty after difficulty?
Best
jfc


At 18:46 30/09/2014, Daniel Glöckner wrote:

Hi,

On Wed, Oct 01, 2014 at 12:06:24AM +0800, Thomas Preud'homme wrote:
> > I have a problem with the char "\". For example in the line:
> >
> > strpbrk (file_name,"\*?")
> >
> > ir order to know if i have a simple file name, tcc tells me "unknown
> > escape sequence".
>
> The manpage doesn't say that the strings accept escape sequence. 
Is it even

> defined in the standard? Sounds like a bug in TinyCC.

Thomas, C does support the escape sequences \a, \b, \f, \n, \r, \t,
\v, \', \", \?, \\, \<3octal>, \x<2hex>, \u<4hex>, and \U<8hex>.
I guess BCC probably interpreted \* as \\*.

> > When I want use as a char both text[i]='\' and text[i]='\\' do not
> > work. Since I am there working on text strings I cannot equate '\' to
> > ascii 28 first.
>
> '\' should be correct. What is the error you get?

'\\' should be correct. What is the error you get?

Best regards,

  Daniel

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Evan Langlois

Thomas,

On Tue, Sep 30, 2014 at 11:06 AM, Thomas Preud'homme 
 wrote:


 strpbrk (file_name,"\*?")
 
 ir order to know if i have a simple file name, tcc tells me "unknown

 escape sequence".


The manpage doesn't say that the strings accept escape sequence. Is 
it even 
defined in the standard? Sounds like a bug in TinyCC.


I believe the compiler is supposed to perform all C escapes on quoted 
strings during compile time, converting them to the proper sequences 
before passing it to strpbrk.


However, strpbrk doesn't accept a regex or shell globs.  I don't see 
why you would be checking for '*' or '?' in a filename!


If TCC says \* is an unknown escape sequence then that looks like 
exactly what it should be doing.  There is no such escape.


Try basename() instead.

As for text[i]='\\', I'm betting when he says "do not work" its a 
run-time error due to a bug in his code, not a TCC bug.





___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Evan Langlois

Jefsey,

On Tue, Sep 30, 2014 at 12:29 PM, Jefsey  wrote:

Thank you all.

The problem the I have is that I am quite rusty at my C and TCC is 
new to me :-)


1. First thing is that I use "tcc .c" and I do not know how to 
get more than one kind of error at a time? Is there a way to have all 
the compilation errors one shot in a file ?


tcc file.c >output.txt

or maybe you want to read it

tcc file.c | tee output.txt | less



2. the "\\" for "\" seems to work (does not report error. "\." now 
complain, but not if I enter '.', as if \ was only an escape for \ 
except when followed by n as in \n.


Uhmm ... and what escape is \. supposed to be?  You are confusing C 
escapes with regular expressions I think.  

3. The error I am reported now is that "isascii" us an unknopwn 
symbol.


Did you include  ??  
Check out :

   man isascii

Test your code with gcc please.  If it compiles under gcc and then 
fails under tcc, then this is the proper list.  If it won't compile 
under gcc, then perhaps stackoverflow would be a better place for help.



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread JFC Morfin

Hi! Evan,

At 19:30 30/09/2014, Evan Langlois wrote:
However, strpbrk doesn't accept a regex or shell globs.  I don't see 
why you would be checking for '*' or '?' in a filename!


This is to check it is a real file name, and not a regex.

If TCC says \* is an unknown escape sequence then that looks like 
exactly what it should be doing.  There is no such escape.
As for text[i]='\\', I'm betting when he says "do not work" its a 
run-time error due to a bug in his code, not a TCC bug.


The question is not about bugs. These are ten years old libraries 
used millions of time but compiled under Borland. There are 
differences between compilers. The question is only to understand them.



On Tue, Sep 30, 2014 at 12:29 PM, Jefsey  wrote:
Thank you all. The problem the I have is that I am quite rusty at 
my C and TCC is new to me :-) 1. First thing is that I use "tcc 
.c" and I do not know how to get more than one kind of error at 
a time? Is there a way to have all the compilation errors one shot in a file ?


tcc file.c >output.txt


Thx.
1. What  I suspect is that TCC only reports a kind of compilation 
error at a time not all of them.
For example when I tried to address the "\" issue, it did not report 
on "isascii".
Is there a way to tell TCC to continue trying to compile even after 
"blocking" errors. This was by default in BCC and several others.


2. Sometimes you can have the kind of report above not displayed on 
the screen but directly sent in a file (because it may be rather 
long). Just asking.


Uhmm ... and what escape is \. supposed to be?  You are confusing C 
escapes with regular expressions I think.


This depends on compilers. In other compiler or environnement you 
must escape more things. In BCC these escapes are required



3. The error I am reported now is that "isascii" us an unknopwn symbol.


Did you include  ??


Sure. And isascii is documented there.

Test your code with gcc please.  If it compiles under gcc and then 
fails under tcc, then this is the proper list.  If it won't compile 
under gcc, then perhaps stackoverflow would be a better place for help.


My choice of TCC is to avoid GCC :-) There are declaration 
discrepancies and they have used some function names I also used. If 
I could stay with tcc it would be simpler.


Take care and thanks
jfc


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Evan Langlois

JFC,

I used TCC all the time to test little code snippets.  I write test 
cases as shell scripts in C, and use TCC's compile-on-the-fly feature.  
I've not run into problems with it really, even when doing some pretty 
weird bit-level hackery.


On Tue, Sep 30, 2014 at 2:18 PM, JFC Morfin  wrote:


The question is not about bugs. These are ten years old libraries 
used millions of time but compiled under Borland. There are 
differences between compilers. The question is only to understand 
them.


Borland isn't known for its standards compliance.  My guess is that 
Borland wasn't handling the escape sequences properly and ignoring 
unknown ones or something.  The standard specifically states that its 
supposed to throw up a warning if it finds an unknown escape.  Now you 
have TCC and GCC and they are doing it right, and your having problems. 
BTW, according to the standard, ? should be escaped as well.  So \*? 
becomes "\\*\?"


And off-topic, but you mentioned your code handled regex's.  Google has 
a lightning fast regex implementation.  Its missing back references or 
something, but the speed is pretty amazing.   I forget the name of the 
lib, but you can Google it.   Maybe I'll see if it compiles under TCC :)



Thx.
1. What  I suspect is that TCC only reports a kind of compilation 
error at a time not all of them.
For example when I tried to address the "\" issue, it did not report 
on "isascii".
Is there a way to tell TCC to continue trying to compile even after 
"blocking" errors. This was by default in BCC and several others.


There shouldn't have been any problem with isascii().  Works fine for 
me.


2. Sometimes you can have the kind of report above not displayed on 
the screen but directly sent in a file (because it may be rather 
long). Just asking.


This is Unix.  We have tools for handling output like that and for 
processing it.  Windows doesn't.




Uhmm ... and what escape is \. supposed to be?  You are confusing C 
escapes with regular expressions I think.


This depends on compilers. In other compiler or environnement you 
must escape more things. In BCC these escapes are required


Uhmm ... you seem awfully sure of that.  But there is such a thing as 
standards and following them will help.  Again, TCC isn't doing 
anything wrong.  You can find a list of the standard C escapes 
anywhere.  Wikipedia and my outdated ANSI C list show the same list and 
I know wikipedia is pretty current, so the standard hasn't likely 
changed much.




Sure. And isascii is documented there.


Tried a minimal test case?

Test your code with gcc please.  If it compiles under gcc and then 
fails under tcc, then this is the proper list.  If it won't compile 
under gcc, then perhaps stackoverflow would be a better place for 
help.


My choice of TCC is to avoid GCC :-) There are declaration 
discrepancies and they have used some function names I also used. If 
I could stay with tcc it would be simpler.


Perhaps you missed my point.  You can try the LLVM compiler to 
determine if your problems are your own or tcc's.  Your issues are all 
that your code is radically non-standard.  Yes, tcc has a number of 
short-comings, but it handles simple string escapes and generic 
functions like isascii() just fine.  Perhaps Borland doesn't.


Also, if you are attempting to make tcc your main compiler, then 
realize that tcc doesn't optimize nearly as well as GCC or LLVM.  But 
... if you are going to embed a C compiler into another program to 
"script" it in C, or want to write shell scripts in C  with 
#!/usr/bin/tcc -run  then tcc is really awesome.  If avoiding gcc is 
your only reason for using tcc, you may be disappointed.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread arnold
Evan Langlois  wrote:

> And off-topic, but you mentioned your code handled regex's.  Google has 
> a lightning fast regex implementation.  Its missing back references or 
> something, but the speed is pretty amazing.   I forget the name of the 
> lib, but you can Google it.   Maybe I'll see if it compiles under TCC :)

It's called RE2, and is written in C++, so tcc won't handle it.

Arnold

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread grischka

JFC Morfin wrote:
The question is not about bugs. These are ten years old libraries used 
millions of time but compiled under Borland. There are differences 
between compilers. The question is only to understand them.


And the answer is that there is no difference.  Under any compiler

strpbrk (file_name,"\*?")

will not detect a backslash in 'file_name'.

--- gr


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Evan Langlois




It's called RE2, and is written in C++, so tcc won't handle it.



Aww ... now I'm sad!   Thanks for the info though.  I wonder what sort 
of hackery it would take to get GCC to compile it and then get tcc to 
link with it.  I know its possible, but you have to work around the 
name mangling.  


I guess its not terribly important.

Thanks!
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Charles Gordon
On 30 sept. 2014, at 18:46, Daniel Glöckner  wrote:

> Hi,
> 
> On Wed, Oct 01, 2014 at 12:06:24AM +0800, Thomas Preud'homme wrote:
>>> I have a problem with the char "\". For example in the line:
>>> 
>>>strpbrk (file_name,"\*?")
>>> 
>>> ir order to know if i have a simple file name, tcc tells me "unknown
>>> escape sequence".
>> 
>> The manpage doesn't say that the strings accept escape sequence. Is it even 
>> defined in the standard? Sounds like a bug in TinyCC.
> 
> Thomas, C does support the escape sequences \a, \b, \f, \n, \r, \t,
> \v, \', \", \?, \\, \<3octal>, \x<2hex>, \u<4hex>, and \U<8hex>.

More precisely, and contrary to popular belief, \x. 
 Standard C specifies this.
“\023” is a string with only one character.

> I guess BCC probably interpreted \* as \\*.

BCC should interpret “\*” as “*”, otherwise it is a non standard behavior.
The code fragment probably attempts to catch forbidden characters in file_name.
\ is the ominous path separator in the MSDOS/Windows world (/ can be used as 
well in Windows and in MSDOS)
The correct string for this should have been “\\*?"
To port this code to unix, you should change the string to “/*?”
and to make it somewhat more portable, you might want to change it to “/\\*?”
But this code is obsolete anyway: note that the restriction on * and ? in 
filenames does not exist in most unix file systems, nor probably in Windows and 
Mac modern file systems.
wildcard expansion is actually a feature of the command line interpreter (aka 
shell), and of some very specific file searching APIs in Windows.

Chqrlie


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Charles Gordon
On 30 sept. 2014, at 21:18, JFC Morfin  wrote:
> 
> At 19:30 30/09/2014, Evan Langlois wrote:
> 
>> Uhmm ... and what escape is \. supposed to be?  You are confusing C escapes 
>> with regular expressions I think.
> 
> This depends on compilers. In other compiler or environnement you must escape 
> more things. In BCC these escapes are required

Quite unlikely.  Neither \* not \. have ever been seen in correct C code,  
Borland or else.
You must be confusing C character escapes with Perl or Shell regular 
expressions where both . and * have a special meaning and must be escaped to 
match the actual character.

>> Test your code with gcc please.  If it compiles under gcc and then fails 
>> under tcc, then this is the proper list.  If it won't compile under gcc, 
>> then perhaps stackoverflow would be a better place for help.
> 
> My choice of TCC is to avoid GCC :-) There are declaration discrepancies and 
> they have used some function names I also used. If I could stay with tcc it 
> would be simpler.

Porting old code to a modern compiler or OS is not for the faint of heart.
If your C is rusty, as it shows given your questions, you are going down a 
rough road…
If you cannot compile with gcc, first fix that.  You probably defined some 
string functions that conflict with those of the glibc.  Try using some of the 
gcc flags that prevent builtins or enforce strict standard conformance.
You can also hide the glibc functions by defining macros before the #include 
lines and undefine them afterwards.

Good luck!

Chqrlie.


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Charles Gordon
On 30 sept. 2014, at 21:47, Evan Langlois  wrote:

On Tue, Sep 30, 2014 at 2:18 PM, JFC Morfin  wrote:
>> 
>> The question is not about bugs. These are ten years old libraries used 
>> millions of time but compiled under Borland. There are differences between 
>> compilers. The question is only to understand them.
> 
> Borland isn't known for its standards compliance.  My guess is that Borland 
> wasn't handling the escape sequences properly and ignoring unknown ones or 
> something.  The standard specifically states that its supposed to throw up a 
> warning if it finds an unknown escape.  Now you have TCC and GCC and they are 
> doing it right, and your having problems.  BTW, according to the standard, ? 
> should be escaped as well.  So \*? becomes "\\*\?”

Not exactly:  the C Standard *allows* ? to be escaped as \?, it does not 
specify that it should be.
Similarly, ‘ can be escaped as \’ in strings and “ can be escaped as \” in 
character constants,
but there is no obligation and aside from style and consistency of the source 
code, it makes no difference in the code generated.
But why did the standard folks allow ? to be escaped as \? might you wonder…
Because of another ominous standard deviance: trigraphs!
Imagine you have a date template that looks like this:  “??/??/??”
It looks pretty harmless, but with trigraph conversion, it translates as “\\??”
Modern compilers disable trigraphs by default or give warnings when the occur. 
To avoid trigraph expansion, there are 2 solutions: 
- use escape sequences as this  “\?\?/\?\?/\?\?”  (stylish but unreadable)
- break the string in 3 parts (or more):  e.g.  “??” “/??” “/??"
The good news is tcc does not support trigraphs at all, but try gcc and clang 
on this ;-)

Chqrlie.



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Evan Langlois


Not exactly:  the C Standard *allows* ? to be escaped as \?, it does 
not specify that it should be.


Hmm .. I stand corrected!  OK - so if it sees \? its ? and if it sees ? 
it checks to see if its a trigraph, and if it sees \??= then it cries.



Imagine you have a date template that looks like this:  “??/??/??”
It looks pretty harmless, but with trigraph conversion, it translates 
as “\\??”


As I read this I was thinking .. why would they escape a question mark? 
And then
I saw the word trigraphs and thought .. what were trigraphs again?  And 
then I looked it up and went .. OH YEAH!  Not only have I never needed 
them, but I don't even understand WHEN I would need them.  Apparently, 
I will never need them and it doesn't matter.  If I haven't used em in 
25 years, its not gonna happen.


The good news is tcc does not support trigraphs at all, but try gcc 
and clang on this ;-)


That is good news!  If it supported them I would hack the code out of 
the source to make my copy a little bit smaller.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Charles Gordon
On 30 sept. 2014, at 23:09, Evan Langlois  wrote:

> 
>> 
>> It's called RE2, and is written in C++, so tcc won't handle it.
>> 
> 
> Aww ... now I'm sad!   Thanks for the info though.  I wonder what sort of 
> hackery it would take to get GCC to compile it and then get tcc to link with 
> it.  I know its possible, but you have to work around the name mangling.  

The kind that would turn tinycc into hugecc, and a terribly important amount of 
work !

Yet it would still fall short of add regex support to tinycc at the source 
level.

Specifying regular expressions as C strings is horrible: you have to escape all 
\ characters, which makes them even more obscure.


Chqrlie.



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread Charles Gordon
On 30 sept. 2014, at 23:58, Evan Langlois  wrote:

>> Not exactly:  the C Standard *allows* ? to be escaped as \?, it does not 
>> specify that it should be.
> 
> Hmm .. I stand corrected!  OK - so if it sees \? its ? and if it sees ? it 
> checks to see if its a trigraph, and if it sees \??= then it cries.

To prevent trigraph expansion, the second ? should be escaped.

\??= would trigger the warning "unsupported escape sequence '\#’”  because 
trigraph expansion occurs before escape sequence conversion.

None of this is relevant in tcc, but it is still part of the C standard.
A more recent and less problematic oddity in the C standard syntax is digraphs.
Good news!  tcc does not support digraphs either!

Chqrlie.








___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to use char "\"

2014-09-30 Thread JFC Morfin

Hi!
Sorry for rising the matter. I suppose that Charles is right.

At 23:27 30/09/2014, Charles Gordon wrote:

Porting old code to a modern compiler or OS is not for the faint of heart.


Yes. I thought my old code was robust enough (it 
cam from QNX and I ported it under DOS/Window 
using Borland years ago and it ran without problem for decades).


If your C is rusty, as it shows given your 
questions, you are going down a rough road…
If you cannot compile with gcc, first fix 
that.  You probably defined some string 
functions that conflict with those of the 
glibc.  Try using some of the gcc flags that 
prevent builtins or enforce strict standard conformance.


So, it seems I have to rewrite it and test it 
step by step. If I read you correctly (I am not a 
developper, just a user developping my own 
operational tools as a powefull enough function 
library) my best bet is to rewrite for it. I 
suppose I will enjoy adding a few things.


From what you say, I should  go for gcc 
compatibility under windows to be sure it 
compiles with TCC and probably everywhere.


You can also hide the glibc functions by 
defining macros before the #include lines and undefine them afterwards.


Yeap. But I think I will try to offer me a 
refurbished library as a Xmas C gift :-)


btw, would you know a clean and clear uptodate C 
documentation including internetworking tools?


Thx to every one
jfc 



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel