>>2030
okay, let me try to break this down…
1.It assigns q, p, and a to the copy of the character array L. All pointers.
1.a. I have no fucking idea what you're doing with i, but whatever. It get's assigned to 0 right after.
2.I'm assuming the 3 is meant to stand for the level of the of each character. Like you can divide 5 into 3 sections: The top, the top middle, and the middle bottom.
3. Then you go through the first argument, which is your input string.
4.a. If it sees that it's not a digit, it says "fuck this" and skips the number
(b). 48 is essentially '0', so it takes the character you're currently on and makes it an integer.
then it adds 10*i to it for some reason, multiplies it by four too.
The length of L is 40 characters, so this might have to something with it.
And then adds it to a, moving you down L/a by some amount.
If i is 1, it moves you to the second line. If i is 2, it moves you to the third line.
5.a.
Note that the digit q is on is a numerical character, so even though they're all less than 5, it will always be greater than 48.
It shifts the character q is on down by '0' again, giving you character of value 0, 1, 2, or 4 numerically.
"Line" of character q is pointing too (since it's not really separated by an '\n' character): i.
"position" of character q is pointing too: 40*i + 4c, where c is the number p is pointing to (our input line). It's not the position, but the actual character.
b.If it is even, which every 4th character is, it will break out of the for loop.
c. Now we have to break down this clusterfuck…
*q&1* checks if the number is 1, since 2, and 4 have the first bit as 0. If it is, it puts a space there.
If not (value of *q is, 2, 4):
checks if *q is 2. If it is, it puts a '_'. If not, a '|'
Then it goes on too the next character.
So how does this shit translate to printing a string of numbers LED clock style?
Well imagine each number as a 3x3 grid. In each square of the grid, you can either have a '_' or a '|'.
What the string L does is it gives a assigns a value to each of those values the square can be.
So a '|' is a 4, a '_' is a 2, a ' ' is a 1. The 0 represents the end of the grid for the number.
L stores all the possible values of a number for a given position on the grid of a given number.
So given the number six, all the values of six would be located at positions 20-22 on lines 0 and 2, excluding the 0s.
Mapping the values 1, 2 or 4 to the character values will give you all the characters for the LED representation of six.
-The program goes through line i, 0 <= i < 3.
-for every character in the input
-assuming it's an integer, it moves it the position on L where the values of the ith row are located.
-Then it subtracts the element at the position by '0' if it hasn't already done it. If it ends up being zero, it get's out of the loop.
-Then, depending on the value at the position, it maps it to a ' ', '_' or a '|' and prints it.
-It repeats that 3 times until it hits a 0 character.
-Then it goes to the next character input of p, going until it goes through the whole line.
-prints a newline character.
-Then it prints the middle section and the bottom section. After that i = 3 so it's done
I'm not going back to read all the shit I just wrote.
This is the most evil fucking code I've ever seen.
There's no point to all this mapping bullshit, since it stores every character 0, 1, 2, 4 as a char, which takes up just as much space as ' '. '_' or '|'.
I haven't finished reading K&R2, but maybe they could have used bitfields?
But even then those are ints, which use up more space than characters.