what does "NYI" refer to in the comments of OpenCascade source code - opencascade

I noticed it first in BRepCheck_Analyzer.hxx:
class BRepCheck_Analyzer
{
public:
DEFINE_STANDARD_ALLOC
//! Constructs a shape validation object defined by the shape S.
//! <S> is the shape to control. <GeomControls> If
//! False only topological informaions are checked.
//! The geometricals controls are
//! For a Vertex :
//! BRepCheck_InvalidToleranceValue NYI
//! For an Edge :
//! BRepCheck_InvalidCurveOnClosedSurface,
//! BRepCheck_InvalidCurveOnSurface,
//! BRepCheck_InvalidSameParameterFlag,
//! BRepCheck_InvalidToleranceValue NYI
and my guess is "Not Yet Implemented", but it appears throughout the code base and some cases those make less sense for those references. It comes up a lot in french comments, maybe it's something else in that language, or it's an author's initials?
For example, BRepCheck_InvalidToleranceValue is noted as NYI above, but it does seem to be used.

I guess that you are pretty right in your assumptions - NYI over the code looks like somebody's acronym / nickname:
// NYI 971219 : on ne tient pas compte de l'orientation de E = arete-mere de l'interference I
...
// NYI XPU: 16-05-97: INTPATCH -> the parametrization of a point on a
// periodized curve is INSUFFICIENT : parVP on line can be either 0.
// or period.
Before wide adoption of modern code versioning systems like SVN/git, it was a common practice to put an acronym, bug number and date of modifications into the code.
These comments might be 20+ years old, so it would be difficult and not very useful to figure out who might be a real author.

Related

Controlling a keypad with same I/O in C

i have a problem that i have been at for over a day now, and i can not solve this with my skills.
So the problem is as follows. I am trying to get an output from a 4x4 keypad, which would not be a problem but input and output are on the same pins. I know that the 74hc573 should keep the information after LE goes low, but i just can not figure out how to read output from 74hc541 without giving new information to the previous chip, because then the state changes again. At the moment i can only read the keys diagonally, because input and output match in that case.
The schematic of the whole circuit can be seen here:
and the problematic part here:
I have tried many different way in C to make it work, but the best I can do is diagonally from 1 to C because of the shared I/O.
Hope you guys can give a tip and help me understand this.
and my code, it is only the part that should take care of getting the output.
while(1)
{
for(i=0;i<4;i++)
{
P3_7=0;
P3_6=1;
in=((0b11110111>>i)&0b00001111);
//in=0b11110111;
*keypad=in;
*led=in;
P3_7=0;
P3_6=0;
*keypad=0x00;
P3_7=1;
out=*keypad;
P3_7 would be RD and P3_6 would be WR, havent given them proper defines yet
Modified code
while(1)
{
for(i=0;i<4;i++)
{
P3_7=0;
P3_6=1;
in=((0b11110111>>i)&0b00001111);
*keypad=in;
*led=*keypad;
vardelay(100);
P3_7=0;
P3_6=0;
*keypad=0xff;
P3_7=1;
out=(*keypad&0b00001111);
if (in==0b1101&&out==0b1101)
{
P3_7=1;
P3_6=1;
lcd_senddata('5');
}
else if(in==0b1110&&out==0b1101)
{
P3_7=1;
P3_6=1;
lcd_senddata('2');
}
When clicking '5' it prints both 5 and 2. And i am not sure why
The key is being able to control the LE pin. Latch Q1 on, then disable the LE. Scan A1-A4 to test buttons 1, 2, 3 and F. The state Q1-4 shouldn't change during the scan if LE is low. Then enable LE, switch to Q2, disable LE and scan the next row, and so on.
Turns out i was over thinking it, I had to simply write and read from the same address. That is all. a simple code like this, will work
if (*keypad=0b11111101)
{
out=*keypad;
if (out==0b11111110)
lcd_senddata('4');
else if (out==0b11111101)
lcd_senddata('5');
else if (out==0b11111011)
lcd_senddata('6');
else if (out==0b11110111)
lcd_senddata('E');

keyboard interrupt handler giving null value

I am learning Linux Kernel Module programming(Interrupt Handler) and using the tutorial (http://tldp.org/LDP/lkmpg/2.6/html/) exact module link(http://tldp.org/LDP/lkmpg/2.6/html/x1256.html).
In the tutorial I am getting error when I used
INIT_WORK(&task, got_char, &scancode);
The error was "error: macro "INIT_WORK" passed 3 arguments, but takes just 2"
So I found one solution and use the below line
INIT_WORK(&task, got_char);
It's working fine but the output I am getting is null. I am expecting the key number from the keyboard.
Any body have any idea ?
If it is not clear please let me know I will try to interpret more.
Thanks
Add a structure like follows,
struct getchar_info {
/* Other info ... */
struct work_struct work;
unsigned int scancode;
/* Other info ... */
};
static struct getchar_info gci; /* Statically declare or use kmalloc() */
Change got_char() to,
static void got_char(struct work_struct *work)
{
struct getchar_info *info = container_of(work, struct getchar_info, work);
info->scancode = my_val;
/* ... */
Initialize it like INIT_WORK(&gci.work, got_char);
This is a common Linux kernel paradigm or design pattern. The work queue code needs to manage this structure pointer so it is easy to provide to your got_char routine. Your driver must allocate it as part of a larger structure (it is inheritence in OO terms; it looks like composition as 'C' only supports that). The container_of is like a C++ dynamic_cast<> (with single inheritance in case any C++ gurus are looking). It lets you get the composed structure from the sub-structure.

CoreText. How Do I Calculate the Bounding Box of an Attributed String?

In CoreText it is easy ask: "for a given rectangle how much of this attributed string will fit?".
CTFrameGetVisibleStringRange(rect).length
Will return where in the string the next run of text should begin.
My question is: "given an attributed string and a width, what rect height do I need to completely bound the attributed string?".
Does the CoreText framework provide tools to do this?
Thanks,
Doug
What you need is CTFramesetterSuggestFrameSizeWithConstraints(), you can use it like so:
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attributedString)); /*Create your framesetter based in you NSAttrinbutedString*/
CGFloat widthConstraint = 500; // Your width constraint, using 500 as an example
CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(
framesetter, /* Framesetter */
CFRangeMake(0, text.length), /* String range (entire string) */
NULL, /* Frame attributes */
CGSizeMake(widthConstraint, CGFLOAT_MAX), /* Constraints (CGFLOAT_MAX indicates unconstrained) */
NULL /* Gives the range of string that fits into the constraints, doesn't matter in your situation */
);
CGFloat suggestedHeight = suggestedSize.height;
EDIT
//IMPORTANT: Release the framesetter, even with ARC enabled!
CFRelease(frameSetter);
As ARC releases only Objective-C objects, and CoreText deals with C, very likely you can have a memory leak here. If your NSAttributedString is small and you do it once, you shouldn't have any bad consequences. But in a case you have a loop to calculate, let's say, 50 heights of big/complex NSAttributedStrings, and you don't release the CTFramesetterRef, you can have serious memory leaks. Check the tutorial linked for more information on memory leaks and debugging with instruments.
So the solution for this problem is to add CFRelease(frameSetter);

Personal Preprocessor Directives

Being a C novice I would like to hear what Macro "define"s developers are using. I've been thinking about putting these in a header to skip verbosity I've become used to:
#define TS_ typedef struct {
#define _TS(x) } x;
#define I(x)_ { int i; for ( i = 1; i <= x; i++ ) {
#define _I } }
Can I add \n \t etc within these macros? As I would like to pass on my sourcecode minus the extra include:
#define TS_ typedef struct {\n
#define _TS(x) } x;\n
#define I(x)_ { int i;\n\tfor ( i = 1; i <= x; i++ ) {\n
#define _I \t}\n}\n
Would these work?
ie: Can I use the proprocessor to replace my sourcecode with my personal include to formatted source without the include ?
Links to good preprocessor tips and tricks also appreciated.
Before you get started, do not use macro names that begin with an underscore - these are reserved for compiler and standard library writers, and must not be used in your own code.
Additionally, I would say that the macros you suggest are all very bad ideas, because they hide from the reader what is going on. The only justification for them seems to be to save you a very small amount of typing. Generally, you should only be using macros when there is no sensible alternative. In this case there is one - simply write the code.
You can put whitespace in by escaping the newline
#define SOMETHING whatever\
This is part of the macro
But as others have said it's not really a great way to to do this.
It would be much better to look into editor macros so you could type the shortcut and have the editor expand it.
You are headed into a wrong path. DO NOT make up your own cpp directives that are unfamiliar to others - this will make your code hard to understand, and at some point maintain.
Try to find some good C code to read - good C code does not use these things, for a good reason.
DON'T DO IT. Nobody else will be able to read your code.
As a cautionary example, check out Steve Bourne's original sources for the Bourne shell, where he used macros to write the code in a kind of pidgin Algol style.
You could do this, but this sort of "personal language" is not generally used in the C world, especially if you expect anybody else to read your code in the future.
If you're doing this just for yourself, then feel free to #define whatever you want, but expect that once you start working with (or for) anybody else, you won't be able to continue using this sort of thing.
Using C macros unnecessarily can lead you into a world of pain, especially if you attempt to use it to expand code. There are uses for C macros, but this is not it.
Edit: I realize that my answer is tangential to your question, but I thought I should mention this since you say you are a C novice. Search for "C macro pitfalls" to get a full list of reasons why not to use macros. It's been previously discussed here.
In general, I strongly agree with the other respondents who tell you not to define your own macros purely for the sake of saving typing. The obfuscation is not worth it. Also, the particular macros you suggest are heinous. However, in Stroustrup's 1st Ed, he does something I rather like (sometimes):
#define Kase break; case
I became accustomed to the Python elif construct, so I often define the following:
#define elif(test) else if(test)
My purpose in doing this isn't to reduce typing, it's to keep indentation logical while maintaining consistent code width (I don't let my code go wider than 80 characters). I say this because to me this...
if(...) ...
else if(...) ...
else ...
...should be...
if(...)
{
...
}
else
if(...)
{
...
}
else
{
...
}
With my macro this becomes:
if(...)
{
...
}
elif(...)
{
...
}
else
{
...
}
It is always better to pass the loop variable to the macro.
A block - a macro has certain optimization problems. All compilers do not guarantee an optimized obj code for the "block scope" variables.
for example, the following code, when compiled with out any optimization options to gcc, prints two separate addresses for &i. And the same code when compiled with -O2 option will print the same address in both the blocks.
{
int i;
printf("address of i in first block is %u\n", &i);
}
{
int i;
printf("address of i in sec block is %u\n", &i);
}
Naming the language constructs appropriately makes the code more readable.
I like your idea, if you put it in the following way.
#define GREEN 1
#define YELLOW 2
#define RED 3
# define NUM_COLORS 3
#define COLOR_ITER (color,i) \
for(i=GREEN, color = colors[i]; \
i < NUM_COLORS; \
color = colors[++i])
int colors[3] = {GREEN, YELLOW, RED};
int
fun () {
int j;
color_t clr;
COLOR_ITER(clr, j) {
paint(clr);
}
}
Here, regardless of how it is written, the macro, COLOR_ITER, by its name, implies that you are looping for all available colors and doing "something" for each color. And this is a very easy-to-use macro.
And your quesion
Can I use the proprocessor to replace my sourcecode with my personal include to formatted source without the include ?
As everybody explained preprocessor will not help you in this case.
You can use your editor commands to automatically format your code, as you type it.

Building a lexer in C

I want to build a lexer in C and I am following the dragon book, I can understand the state transitions but how to implement them?
Is there a better book?
The fact that I have to parse a string through a number of states so that I can tell whether the string is acceptable or not!
You can implement simple state transitions with a single state variable, for example if you want to cycle through the states start->part1->part2->end then you can use an enum to keep track of the current state and use a switch statement for the code you want to run in each state.
enum state { start=1, part1, part2, end} mystate;
// ...
mystate = start;
do {
switch (mystate) {
case start:
// ...
case part1:
// ...
case part2:
// ...
if (part2_end_condition) mystate = end; // state++ will also work
// Note you could also set the state back to part1 on some condition here
// which creates a loop
break;
}
} while (mystate != end);
For more complex state transitions that depend on several variables, you should use tables/arrays like this:
var1 var2 var_end next_state
0 0 0 state1
0 1 0 state2
1 0 0 state3
1 1 0 state4
-1 -1 1 state_end // -1 represents "doesn't matter" here
G'day,
Assuming you mean The Dragon book on compiler design, I'd recommend having a look around this page on compiler tools.
The page itself is quite small but has links through to various excellent resources on lexical analysers.
HTH
cheers,
There's more than one way to do it. Every regular expression corresponds directly to a simple structured program. For example, an expression for numbers could be this:
// regular expression
digit* [.digit*]
and the corresponding C code would be:
// corresponding code
while(DIGIT(*pc)) pc++;
if (*pc=='.'){
pc++;
while(DIGIT(*pc)) pc++;
}
The transition-table way of building lexers is, in my opinion, needlessly complicated, and obviously runs slower.
If you're looking for a more modern treatment than the dragon book(s) : Andrew W. Appel and Maia Ginsburg, Modern Compiler Implementation in C, Cambridge University Press, 2008.
Chapter 2 is focused on Lexical Analysis : Lexical tokens, Regular expressions, Finite automata; Nondeterministic Finite Automata; Lexical analyzer generators
Look at the Table of Contents
The program flex (a clone of lex) will create a lexer for you.
Given an input file with the lexer rules, it will produce a C file with an implementation of a lexer for those rules.
You can thus check the output of flex for how to write a lexer in C. That is, if you don't just want to use flex's lexer...

Resources