Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance logging and parse cli arguments #10

Merged
merged 31 commits into from
Oct 13, 2022

Conversation

mormod
Copy link
Contributor

@mormod mormod commented Oct 10, 2022

In this pull request, a rudimentary version of a debug window will be implemented. This resolves (part of) #3.

This pull request adds a nicer way to log to the console as well as the ability to take command line arguments via flags and optional parameters. Using this, flags for setting the debug level

-d <0..4> (default: 4)

as well as setting the frequency of the emulated CPU

-f <1-1000000> (default: 1000000)

which previously was a mandatory argument, were introduced. New usage is thus:

cretro [-d <0..4>] [-f <1-1000000>] <ROM>

Logging levels are:

  • 0: DEBUG
  • 1: INFO
  • 2: WARNING
  • 3: ERROR
  • 4: FATAL

@mormod mormod changed the title feat: implement a rudimentary debug window feat: implement a rudimentary debug window (#8) Oct 10, 2022
@mormod mormod changed the title feat: implement a rudimentary debug window (#8) feat: implement a rudimentary debug window Oct 10, 2022
@benzammour benzammour linked an issue Oct 10, 2022 that may be closed by this pull request
@benzammour benzammour marked this pull request as draft October 10, 2022 23:28
src/debug.c Outdated Show resolved Hide resolved
src/debug.h Outdated Show resolved Hide resolved
@mormod
Copy link
Contributor Author

mormod commented Oct 12, 2022

As of now, I implemented a nicer way to log debug messages. This is part of the debugging experience, but has not really much to do with a debug window. I would suggest to merge this (anyway should you want to) without having implemented the actual window, such that that task can be done cleanly in a new PR. @benzammour

Title and description can be changed accordingly.

src/cli.c Outdated Show resolved Hide resolved
src/cli.c Outdated Show resolved Hide resolved
src/cli.c Outdated Show resolved Hide resolved
src/cli.h Outdated Show resolved Hide resolved
src/debug.h Outdated Show resolved Hide resolved
@benzammour benzammour changed the title feat: implement a rudimentary debug window feat: enhance logging and parse cli arguments Oct 12, 2022
@benzammour benzammour marked this pull request as ready for review October 12, 2022 20:25
@marcluque
Copy link
Contributor

I think that debug.c/.h should be renamed to something like log oder logging since debug might suggest that it deals with the debug window. A distinction like debug_logging and debug_window could be possible too.

src/cli.c Outdated Show resolved Hide resolved
src/cli.c Show resolved Hide resolved
src/cpu.c Outdated Show resolved Hide resolved
src/cpu.c Outdated Show resolved Hide resolved
src/cpu.c Outdated Show resolved Hide resolved
src/cpu.c Outdated Show resolved Hide resolved
src/debug.h Outdated Show resolved Hide resolved
@marcluque
Copy link
Contributor

I think that maybe the getopt switch case could parse all arguments. That would make the parsing more consistent. The check whether required parameters are present could then be done afterwards. This could ofc be paired with the suggestion I made above to check whether argc >= 2.

@mormod
Copy link
Contributor Author

mormod commented Oct 13, 2022

I think that maybe the getopt switch case could parse all arguments. That would make the parsing more consistent. The check whether required parameters are present could then be done afterwards. This could ofc be paired with the suggestion I made above to check whether argc >= 2.

As far as I'm aware, getopt shall only be used to parse optional arguments. Since frequency and rom_path are not optional, these should not be parsed directly by getopt. In addition, getopt is configured using a parsing string in the format "ab:c::", which would mean

  • a is an optional flag without arguments,
  • bis an optional flag with a mandatory argument
  • cis an optional flag with an optional argument.

If frequency and path to ROM shall be parsed by getopts, we would have to introduce flags for those arguments, making them optional. This, however, would only make sense for the frequency, but not for the path to ROM, as this emulator is quite useless without a ROM loaded.

@marcluque
Copy link
Contributor

I see 🤔 Making frequency an option sounds like a good idea while keeping the ROM path, as you suggested, an argument

src/cli.c Outdated Show resolved Hide resolved
src/cli.c Outdated Show resolved Hide resolved
src/cli.c Outdated Show resolved Hide resolved
src/cli.c Outdated Show resolved Hide resolved
src/logging.c Outdated Show resolved Hide resolved
@benzammour benzammour merged commit 14cc709 into benzammour:main Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants