-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implements getopt for avr #9174
Conversation
ad35c17
to
d8a6703
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for trying to tackle a quite old issue :)
I did a rough review of your change and you should reformat the files using uncrustify to be compliant with RIOT standards.
There are also other changes that are unrelated/not needed (mainly the removal of the stm32 header file).
.gitattributes
Outdated
@@ -5,3 +5,5 @@ | |||
# when the heading is exactly 7 characters long. | |||
*.md conflict-marker-size=100 | |||
*.txt conflict-marker-size=100 | |||
*.c text eof=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unrelated. Please provide those files in a separate PR if really required on your side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this to get LF after every line. Please do let me know if there is any other way of getting rid of the trailing whitespace error. Thanks!
cpu/atmega_common/getopt.c
Outdated
char opt; | ||
optarg = NULL; | ||
|
||
if(optind < 1 || optind > argc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot's of style issues, you can run uncrustify to format your files with a RIOT compliant style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do! Thanks
cpu/atmega_common/include/getopt.h
Outdated
extern "C" { | ||
#endif | ||
|
||
typedef struct{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct is not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry for being extra lost but I am fairly new to Open Source. I went through all the dev recommendations but didn't find the location where to document it?
cpu/atmega_common/include/getopt.h
Outdated
int optopt; | ||
} opt_t; | ||
|
||
static const opt_t def_opt = {NULL,1,1,-1}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not documented
cpu/atmega_common/include/getopt.h
Outdated
* @param[in] argv The array containing all the arguments. | ||
* @param[in] optstring The string of expected options. | ||
* | ||
* @return ASCII value of the option if option was succesfully found, '?' or ':' when unknown option is found or argument is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is too long and should be split
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Thanks!
doc/doxygen/riot.doxyfile
Outdated
@@ -826,6 +826,7 @@ EXCLUDE_PATTERNS = */board/*/tools/* \ | |||
*/cpu/msp430_common/include/sys/*.h \ | |||
*/cpu/native/osx-libc-extra \ | |||
*/cpu/x86/include/* \ | |||
*/cpu/atmega_common/include/getopt.h \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ?
Also, please provide a more telling commit message for your commit. It should tell what module got change and what the change entails (ideally <72 characters, at most 100). Our usual format would be something like
Also nice to have (but not mandatory): some more detailed description about the change:
|
@aabadie Thanks for all the helpful comments. I have fixed most issues. just need to document the struct. Please let me know where and how, couldn't find the relevant doc. Thanks!! |
cpu/atmega_common/include/getopt.h
Outdated
extern "C" { | ||
#endif | ||
|
||
typedef struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To document this, just add a doxygen @brief
before the struct. Each attribute must be document as well. See here for an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for applying the changes fast @virajsahai.
I have found other minor things. See below.
Do you know a way for testing this ? Maybe @miri64 has an idea.
cpu/atmega_common/getopt.c
Outdated
} | ||
} | ||
return c; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a missing newline at the end of this file.
cpu/atmega_common/include/getopt.h
Outdated
* @param[in] argv The array containing all the arguments. | ||
* @param[in] optstring The string of expected options. | ||
* | ||
* @return ASCII value of the option if option was succesfully found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on successfully
cpu/atmega_common/include/getopt.h
Outdated
* @param[in] optstring The string of expected options. | ||
* @param[out] r The per call struct for holding return args and other options. | ||
* | ||
* @return ASCII value of the option if option was succesfully found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on successfully
cpu/atmega_common/include/getopt.h
Outdated
* @return ASCII value of the option if option was succesfully found. | ||
* '?' or ':' when unknown option is found or argument is missing. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this blank line can be removed
cpu/atmega_common/include/getopt.h
Outdated
* @return ASCII value of the option if option was succesfully found. | ||
* '?' or ':' when unknown option is found or argument is missing. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this blank line can be removed
fa96102
to
f21e76a
Compare
@aabadie i have done some generic testing with some edge cases but haven't done the real deal. It'd be great if someone can advise on that. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have done some generic testing with some edge cases but haven't done the real deal. It'd be great if someone can advise on that.
What do you mean with "generic testing" ? I don't know either how this could be tested. Pinging @miri64, maybe you have a better idea ?
Otherwise, I have remaining style comments, mainly because of too long lines that can be split to fit into 80 characters length.
cpu/atmega_common/getopt.c
Outdated
* @file getopt.c | ||
* @brief Implementation of getopt lib. | ||
* | ||
* This implements the getopt and getopt_r functionality. getopt_r has a few caveats, make sure to use it correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be split
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, it should be removed, it's a copy-paste of the one in the header file.
cpu/atmega_common/getopt.c
Outdated
return -1; | ||
} | ||
|
||
if (*argv[optind] != '-' || !(argv[optind] + 1) || *(argv[optind] + 1) == '\0' || *(argv[optind] + 1) == '-') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be split
cpu/atmega_common/getopt.c
Outdated
return -1; | ||
} | ||
|
||
if (*argv[r->optind] != '-' || !(argv[r->optind] + 1) || *(argv[r->optind] + 1) == '\0' || *(argv[r->optind] + 1) == '-') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be split
cpu/atmega_common/include/getopt.h
Outdated
* @file header | ||
* @brief Implementation of getopt lib. | ||
* | ||
* This implements the getopt and getopt_r functionality. getopt_r has a few caveats, make sure to use it correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be split
cpu/atmega_common/include/getopt.h
Outdated
/*INIT_OPT_T_PTR is used to initalize an opt_t* variable, INIT_OPT_T for opt_t. */ | ||
/*To change options, edit the fields of opt_t and call getopt_r*/ | ||
|
||
#define INIT_OPT_T_PTR &(opt_t){ NULL, 1, 1, -1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those defines should be documented
Not sure why I specifically was summoned for this, but if you have test cases, please provide them as an application in |
because you opened #3355 ;) |
f21e76a
to
7b25b9d
Compare
7b25b9d
to
c35577c
Compare
@aabadie by generic testing, I meant testing the logic completeness in edge cases. I don't know how to test after integrating. |
@aabadie any updates?? |
I don't understand this, sorry. What edge cases ? How do you do that ? Do you have a RIOT specific application for that ? |
@aabadie No..i don't have a riot specific application for that. It would be great if you could point me to someone who can help with the testing. And I tested the code as a regular c code on my pc..for cases when double colons are there..empty string passed etc. |
@aabadie any updates? |
@virajsahai, I'm not sure but I think it would be nice to add a dedicated test application with shell and calls to the getopt function. It would be great to have other maintainers opinion on this. @gebart @kaspar030 @miri64 , what do you think ? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
Implemented getopt for atmega
Issues/PRs references
Fixes #3355