Skip to content

Commit

Permalink
examples-code-check.c: Report on missing defined function return types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed May 30, 2024
1 parent c830c15 commit 70469f2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions man/examples-code-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
int is_number_func = 0;
int is_inline_func = 0;
int is_struct_func = 0;
int is_ptr = 0;
const char *func_start = NULL;
int is_struct = 0;
unsigned int i;

if (strncmp(buffer, "*void ", sizeof("*void ")-1) == 0) {
if (strncmp(buffer, "*void *", sizeof("*void *")-1) == 0) {
func_start = &buffer[sizeof("*void *")-1];
is_ptr = 1;
} else {
is_void_func = 1;
func_start = &buffer[sizeof("*void ")-1];
Expand All @@ -254,6 +256,7 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
strlen(number_list[i])) == 0) {
if (buffer[1 + strlen(number_list[i])] == '*') {
func_start = &buffer[2 + strlen(number_list[i])];
is_ptr = 1;
} else {
is_number_func = 1;
func_start = &buffer[1 + strlen(number_list[i])];
Expand All @@ -267,6 +270,7 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
strlen(pointer_list[i])) == 0) {
if (buffer[1 + strlen(pointer_list[i])] == '*') {
func_start = &buffer[2 + strlen(pointer_list[i])];
is_ptr = 1;
} else {
is_struct_func = i + 1;
func_start = &buffer[1 + strlen(pointer_list[i])];
Expand Down Expand Up @@ -330,6 +334,19 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
len = strlen(outbuf);
if (len > 3 && ((outbuf[len-3] == ';' && outbuf[len-2] == '*') ||
(outbuf[len-3] == '*' && outbuf[len-2] == ';'))) {
if (!is_inline_func && !is_void_func && !is_number_func && !is_struct_func && !is_struct &&
!is_ptr) {
char *lcp = strchr(buffer, ' ');

if (lcp)
*lcp = '\000';
fprintf(stderr,
"man/examples-code-check.c: Function return type '%s' undefined in ptr_list[] or number_list[]\n",
&buffer[1]);
if (lcp)
*lcp = ' ';
exit_code = 1;
}
if (is_inline_func) {
strcpy(&outbuf[len-3], ";\n");
}
Expand Down

0 comments on commit 70469f2

Please sign in to comment.