nezachem 616 Practically a Posting Shark

First of all, congratulations. Yacc can recover from shift-reduce, whereas reduce-reduce is lethal.

Now, let's look why it happens. One of the sources of the conflict is

Expression		:	Expression PLUSOP Expression

Consider an expression a + b + c. There are 2 ways to parse it:
1. a + Expression
2. Expression + c
The first path would be shift (accept a as Term, and shift to the rest. The second path is reduce (accept a+b, and reduce it to Expression). Again, you didn't tell it which is correct.

There are 2 ways to overcome such shift-reduces. First, you can use %left and %right directives. Second, introduce more non-terminals, like I did with AdditiveExpression.

Reading my original code, it appears, to me, that if a '(' is seen at any time, then the parser needs to have the sub-tree begin with the top-level non-terminal.

It may even do so. The question, unanswered, is what to do when a ')' is encountered.

PS: You are going to have misterious problems with lines 16 and 19. Better start using %union right away.

nezachem 616 Practically a Posting Shark

I do not quite understand what do you mean by "back to the top level". You'd rather go recursively down, building the same tree. And yes, an expression grammar is inherently recursive.

nezachem 616 Practically a Posting Shark

Usually it is handled with primary expression, for example,

Expression
    : AdditiveExpression
    | PrimaryExpression
;
AdditiveExpression
    : Term
    | Term '+' Expression
;
PrimaryExpression
    : IDENTIFIER
    | NUMERIC_LITERAL
    | '(' Expression ')'
;
nezachem 616 Practically a Posting Shark

I understand, vaguely, what a reduce/reduce conflict is, but I don't understand why I'm getting one in my Yacc Parser. Can anyone help me out?

Expr			: 	LEFTPAR Expr RIGHTPAR			{ };
Term			: 	LEFTPAR Expr RIGHTPAR			{ };
Factor		:	LEFTPAR Expr RIGHTPAR			{ };
End			:	LEFTPAR Expr RIGHTPAR	                { };

How LEFTPAR Expr RIGHTPAR should be reduced? You give 4 ways to do it, and yacc cannot decide.

nezachem 616 Practically a Posting Shark

Your understanding is generally correct.
The only problem is that the script filename is not the last argument ( argv[argc - 1] ) but rather the third:

nezachem@Home ~/tmp/dani/shebang $ ./script -z
argv[0]->/home/nezachem/tmp/dani/shebang/gg
argv[1]->-1 -2 -3 -4
argv[2]->./script
argv[3]->-z
could not open -z

Otherwise I would also add that #! is in fact a magic number, which tells exec() to execute a file by means of an interpreter - exactly as you've described.

PS: some unix variants may parse the "-1 -2 -3 -4" fragment into distinct arguments.

nezachem 616 Practically a Posting Shark

(Also note that the little face in the original example are created automatically by the blog software when I type colon colon asterisk (to indicate data pointer such as : ::*)

You may consider using code tags, such as ::* . In fact, it is a requirement for this forum.

nezachem 616 Practically a Posting Shark

You test 2 conditions (lines 18 and 21). One of them is supposed to filter out incorrect attempts. Another is supposed to accept correct ones. Logically, they should be mutual negations. The way they are written they are not. Hint.
Besides, why do you want to test both?

nezachem 616 Practically a Posting Shark

Take a look at SO_REUSEADDR socket option. For a record, I didn't recommend using it.

nezachem 616 Practically a Posting Shark

I just realized that your biggest problem is at line 27:

struct sk_buff *skb

It should be

struct sk_buff **skb

I hope you figured it out by now.

nezachem 616 Practically a Posting Shark

and also took care about the kfree of allocated modules

Just to make sure: you do kfree_skb(sock_buff) , not just kfree, right?

nezachem 616 Practically a Posting Shark

@nezachem : The skb_copy returns the correct value... I have checked it...

Well you did it. Your code does not.

and as far as kfree_skb of sock buff is concerned ... I m not allocating it any memory by some calls... and hence I don't need to de-allocate the memory it has...

Yes you do. That's what my manpage on skb_copy says:

Returns NULL on failure or the pointer to the buffer on success. The returned buffer has a reference count of 1.

I do not see anything in your code which would decrement the refcount.

nezachem 616 Practically a Posting Shark

I believe you are supposed to kfree_skb when you done with it. And at least check the value returned from skb_copy. Same goes for all other resources you allocate.

nezachem 616 Practically a Posting Shark

Can you elaborate? The cache is "on chip RAM" - It sounds like you're saying that there is another cache* which stores the interrupt vector. Even if this is true, that doesn't explain how having pointers to lists of handlers saves any memory space. Are the lists of handlers stored in a different location other than the cache you're talking about? As far as the gates go, I'm afraid I don't understand. I thought accessing any location in the RAM took the same amount of time.

*when I say "another" cache I mean one other than the cache that is used to bridge the gap between RAM speed being slower than CPU speed.

Anyway, thank you for your reply.

The primary table is stored in an on-chip RAM. It contains pointers to a second tier, which resides at an off-chip RAM. A fetch of an ISR address therefore takes a bus cycle (two, in fact). This is s l o w.

The difference between the RAM used for the primary table, and the cache, is that the primary table is never purged. Caching it means playing a chance game in regard to interrupt latency.

Technically it is correct to say that this table pages are cached yet locked (forever). In any case, the primary table eats up space which otherwise can serve as a true cache. Note that the said space could've also be used for other purposes, such as longer pipeline, larger register file, more execution units, …

nezachem 616 Practically a Posting Shark

A major pro the huge table is a fast dispatch. To make it actually fast, the table shall be stored in an on-chip RAM. This is very expensive gatewise. This is a major con. To minimize gates some designs go to the extreme of a single interrupt vector with a software dispatch. The drawback is larger latency.

A chained table takes less gates in the processor, but is slower due to an extra RAM access.

There are other design considerations of course. Prioritizing them depends on the target application.

nezachem 616 Practically a Posting Shark

Why would I want to do that when all I want is to capture the Esc when pressed at the keyboard (and without pressing the Enter key too)?

To make sure that stdio is capable of handling it.

nezachem 616 Practically a Posting Shark

Sorry but hitting the Esc key does nothing

Now create a file with an escape, and run your program with input redirected from it.

There pressing Esc prints ^[

Yes, that's the way an xterm visualizes escape.

nezachem 616 Practically a Posting Shark

AFAIK ESC can not be detected using standard i/o, such as getchar() and fgets(). Same with other special keys such as function and arrow keys.

Not so. From the standard IO perspective, escape is just a regular character. getchar is perfectly happy to read it, and putchar - to print. You can easily verify that with a help of a trivial cat-like program

while((ch = getchar()) != EOF)
        putchar(ch)

feeding it a file with escape in it.

The problem lies outside the stdio. The offending party is either a console driver, or a framework, or whatever else, which intercepts the escape and interprets it (in case of Windows console, it is a console driver).

If the application is desperate to see the escape, it must configure the offensive driver, replace it or bypass it somehow. How to do it is not addressed by a programming language.

nezachem 616 Practically a Posting Shark

The program will just emit a literal encoded by a backslash escape. It is up to the terminal to interpret it.

nezachem 616 Practically a Posting Shark

You mean create a for(i=0;i<=fdmax;i++){ loop №2 or if (FD_ISSET(i, &write_fds)){? I think that it should be second if there, 'cause this is the place where we exactly check the descriptors.

for(i = 0; i < fdmax; i++) {
    if(FD_ISSET(i, &read_fds) {
        handle_read(i);
    }
    if(FD_ISSET(i, &write_fds) {
        handle_write(i);
    }
}

The separate writing loop is OK as well. It's a matter of taste, really.

nezachem 616 Practically a Posting Shark

I see two problem with this code.

The first one is that send may also block. You need to send data only to those sockets which select reported as being writable. In other words, prepare and pass a write_fds as well, and analyze it in a similar manner.

The second one is that send is not guaranteed that all requested nbytes will be sent. You need to check how many bytes actually went out, and queue the rest of them for the next round.

nezachem 616 Practically a Posting Shark

You should not set a non-blocking node.
Select returns when a requested operation will not block. If a socket is in a non-blocking node, select returns immediately. That defeats the very purpose of select.

nezachem 616 Practically a Posting Shark

Check the logic of the while condition. The loop is skipped only when pizza_establishment is nicks, rays and mikes simultaneously.

nezachem 616 Practically a Posting Shark

//help me i dont know what wrong with list function

There's absolutely nothing wrong with it. What's wrong is how it is called. Look at line 36, and ask yourself what is a type of library[count] .

nezachem 616 Practically a Posting Shark

Hi All,
what is method to get all availabled disk drives and their status. By status I mean whether they are hard disk or CD/DVD or USB?

Practically impossible.

Also how to get list of Drives in *nix?
Thanks a lot

*nixes could be very different. In most important cases parsing /proc/diskstats does what you want.

nezachem 616 Practically a Posting Shark

At run time, things happen one step at a time. Let's trace the execution of your program with n being 2

while n != 1:
    # Python checks that n is not 1, and enters a loop
    if n % 2 == 0:
        # Python checks that n is even and enters the if-clause
        ...
        n = n/2 # [B]n becomes 1[/B]
    if n % 2 != 0:
        # Remember, n is 1, an odd number, so python enters the if-clause
        ...
        n = n*3 + 1 # [B]n becomes 4[/B]
    # while loop goes into next iteration, n is 4
while n != 1:
    # n is 4, enter the loop
    if n % 2 == 0:
        # n is even, enter the if-clause
        ...
        n = n/2 # n becomes 2
    if n % 2 != 0: # n is even, if-clause is not entered.
# Next iteration of while loop. n is 2. Etc, etc, etc
nezachem 616 Practically a Posting Shark

Let's see what happens when n is 2. Your first if condition is true, you divide n by 2 and it becomes 1. Now your second if condition is also true! Welcome to the infinite loop.

nezachem 616 Practically a Posting Shark

Sorry. I trust GetLastError more.

it has been in all of the locations I've tried

What about the locations LoadLibrary tried? Is the file "test.dll" a library?

nezachem 616 Practically a Posting Shark

What does GetLastError() say?

nezachem 616 Practically a Posting Shark

mv can't mass-rename. It can rename a single file, or move a bunch of files into a directory - that's exactly what happened on your second attempt.
For a windows-style mass-rename you need to do something along the lines of (untested)

for f in $filelist; do
    mv $f `echo $f | sed -e 's/S01E0\([1-9]\).*/10\1/'`
done

Don't forget to initialize filelist accordingly. Make sure I didn't mistype anything (I don't have a linux machine right now)

nezachem 616 Practically a Posting Shark

It's nothing to do with bool. At lines 174 and 176 you attempt to compare the value returned by get_accountName to some string. However, get_accountName is declared void ; it returns nothing. The compiler tells you just that.

nezachem 616 Practically a Posting Shark

($ - $$) gives you the offset in the current section, that is, in .data. The way your code is written, the .data section will occupy whole 512 bytes.

You need a simple

times (510 - $) db 0
nezachem 616 Practically a Posting Shark

Can you explain what 4-((double)i) is supposed to do?

nezachem 616 Practically a Posting Shark

Quick and dirty:

static struct List * list_array[MAX_LISTS];

int create_list()
{
    int i;
    for(i = 0; (i < MAX_LISTS) && (list_array[i] != 0); i++)
        ;
    if(i == MAX_LISTS)
        return -1;
    list_array[i] = init_list(); // This is your regular init_list()
    return i;
}

int delete_list(int id)
{
    if(id < 0 || id >= MAX_LIST)
        return -1;
    struct List * list = list_array[i];
    if(list == 0)
        return -1;
    really_delete_list(list); // Your regular memory deallocation etc
    list_array[id] = 0;
    return 0;
}

// etc
nezachem 616 Practically a Posting Shark

The only thing which comes to mind is to use handles (aka descriptors). The handle-based code does not expose a struct list in any form. An init function returns an opaque handle instead. Of course it needs to maintain an internal registry of allocated handles and a handle-to-list map.
As an example of such approach look at the file descriptors and their open/read/write/close system calls.

nezachem 616 Practically a Posting Shark

I was just hoping there was a better way of identifying what a port is running

AFAIK, no.

nezachem 616 Practically a Posting Shark

I got over the frst problem, but what should I need to do in order to handle with case like: printf ("%d\n", lowest_ever (-1));
???

return lowest_num anyway, perhaps?

You still have a small problem though. You shall not call va_arg until you sure there is a next argument. Besides, the call to lowest_ever (-1) sets lowest_num to -1; that is not likely what you want.
To deal with all this I'd restructure it as follows (you've done enough to see the solution):

int lowest_ever (int frst,...)
{
  va_list mylist;
  static int lowest_num=101;
  int  num;
  
  va_start (mylist, frst);		/*Initialize the argument list*/
  for(num = frst; num != -1; num = va_arg(mylist, int)) {
	  if (num <lowest_num)
		  lowest_num = num;
  }  
  va_end (mylist);			/*Clean up */
  return lowest_num;
}
nezachem 616 Practically a Posting Shark

Your code:

static int lowest_num;
  static int  next_num;

Do you listen this well in class too?

Strictly speaking, this is one of the rarest situations where static is called for:

that finds the smallest number in a several unknown function calls

nezachem 616 Practically a Posting Shark

I know this can be done by a command in *nix systems called nmap, i just need to do it in python, and it to be cross platform to lindows.

Question sustains.
Do you have a particular problem with python, or do you need help to understand portmapping in general?

nezachem 616 Practically a Posting Shark
int lowest_ever (int frst,...)
{
...
  while (next_num!=-1)

Man... turn on your logic. Or even better use a debugger. When you call lowest_ever(-1) , what do you think frst would be?

nezachem 616 Practically a Posting Shark

Show me your code.

nezachem 616 Practically a Posting Shark

I just realize you have it static. Of course it wouldn't work. You need

if(frst < lowest_num)
    lowest_num = frst;
nezachem 616 Practically a Posting Shark

to not ignore always the first number in the list

static int lowest_num=frst;

how to handle with call like: lowest_ever ( -1);

if(frst == -1)
    return -1;
nezachem 616 Practically a Posting Shark

Do you know how to do it in any other language?

nezachem 616 Practically a Posting Shark

PIL does not support alpha in BMP files. You need to strip it yourself. Something like (warning: untested):

img = Image.open("file.png")
r, g, b, a = img.split()
img = Image.merge("RGB", (r, g, b))
img.save("file.bmp")
nezachem 616 Practically a Posting Shark

It doesn't look like 8 bit. It looks more like 33 bit.

>>> int("100010101001000010000011111001010", 2)
4649453514

What result do you want?

nezachem 616 Practically a Posting Shark

One more bit of criticism.
YenToGb and GbToYen are practically identical. The only difference is that in one of them a value is multiplied by a factor, while in another it is divided by same factor. When you discovered that something is wrong (for example, a conversion factor changes), you'd have to fix a problem in two places. In programming such situation is called "double maintenance", and should be avoided by all means.
A standard solution is to get rid of one of them, and pass a factor as a parameter:

double convert_currency(factor)
{
    double in, out;
    ....
    std::cin >> in;
    out = in * factor;
    ....
}

and call it as

double factor = 149.2724;
    ....
    convert_currency(factor); // Pounds to yen
    ....
    convert_currency(1.0 / factor); // Yen to pounds

Next, your conversion function does too much. Besides actual conversion, it asks for continuation. It means that the function "knows" in what environment it is called. This is also considered a bad programming practice. Leave the controlling actions for the control loop.

As for your question, you declared your functions as returning int, while they actually return double. So just declare them as double.

nezachem 616 Practically a Posting Shark

I don't think that this implementation can be radically optimized. The Wiki article gives some advices on the speedup (Fourier transforms and image pyramid). Try them.
I'd expect that convolution will yield the best results, however it implies a very good math background. A pyramid could be a fun to program.

nezachem 616 Practically a Posting Shark

Show your code perhaps?

nezachem 616 Practically a Posting Shark

Well, I'll be damned. You're a genius. I would have never have realized that.

I am not a genius. The difference between us is that you have a month of experience, and I have 30 years. Just keep in mind that mental debugging is only allowed to those who reach the third level of enlightenment. Until then you must use a debugger.

nezachem 616 Practically a Posting Shark

Look closely at line 26. You read one character, whereas user entered two of them: don't forget that she hit enter. This enter is consumed at line 18 next time around, which results in an empty username.

PS: do not use ascii codes in comparisons.