terminal-simulator
terminal-simulator copied to clipboard
curious about this section of code
I'm just poking around the code and am wondering why there's a mix of case and if / else if structures here? https://github.com/larsbrinkhoff/terminal-simulator/blob/85854592cbca9c2e24c7473f82c102c76af8e0e7/common/sdl.c#L326-L354
The case statements select between various event types. The if statements check other properties of the events.
Hrm.. So, the case is switched on ev.type and the if statements are all if ev.type == something, so wouldn't you just add case statements for those?
Sorry, brushing up on my c skills, it's been awhile :) making sure I understand.
also totally lost trying to figure out what these are doing?
https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L13-L14
https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L56-L57
https://github.com/larsbrinkhoff/terminal-simulator/blob/d5e3ae99850865ccf52c7285d32eedc89442df63/vt100/cpu.c#L478
It looks like a function definition prototype and also an array definition.. and seems to be accessed both ways as well?
Ok, I think I figured this out. device_in and device_out are arrays of 256 pointers to functions to handle each port, right? Very tricky :)
also totally lost trying to figure out what these are doing?
https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L13-L14
https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L56-L57
https://github.com/larsbrinkhoff/terminal-simulator/blob/d5e3ae99850865ccf52c7285d32eedc89442df63/vt100/cpu.c#L478
It looks like a function definition prototype and also an array definition.. and seems to be accessed both ways as well?
So, the case is switched on ev.type and the if statements are all if ev.type == something, so wouldn't you just add case statements for those?
Oh, in the default case? Yes, maybe so!
Ok, I think I figured this out. device_in and device_out are arrays of 256 pointers to functions to handle each port, right?
Yes, that's right. I don't think it's overly tricky. It's mostly that C syntax make the definitions look strange.