mirror of
https://github.com/Hamlib/Hamlib.git
synced 2024-09-21 10:27:18 +00:00
Adding func_chk.c to test balancing of ENTERFUNC and RETURNFUNC/RETURNFUNC2 statements
This commit is contained in:
parent
b3d93cc231
commit
c5a5276b15
49
tests/func_chk.c
Normal file
49
tests/func_chk.c
Normal file
@ -0,0 +1,49 @@
|
||||
/* this can change for balanced ENTERFUNC/RETURNFUNC statements */
|
||||
/* RETURNFUNC2 is used when ENTERFUNC is not used in a function */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buf[4096];
|
||||
char buf2[4096];
|
||||
FILE *fp = fopen(argv[1], "r");
|
||||
int linenum = 0;
|
||||
int enterfunc = 0;
|
||||
int infunc = 0;
|
||||
int retval = 0;
|
||||
retval = 0;
|
||||
|
||||
while (fgets(buf, sizeof(buf), fp))
|
||||
{
|
||||
++linenum;
|
||||
buf[16] = 0;
|
||||
|
||||
if (strstr(buf, "ENTERFUNC;")) { enterfunc = 1; }
|
||||
|
||||
if (enterfunc && strstr(buf, "RETURNFUNC2"))
|
||||
{
|
||||
printf("Line#%d need RETURNFUNC %s\n", linenum, argv[1]);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
strcpy(buf2, buf);
|
||||
buf2[15] = 0; // truncate the string
|
||||
|
||||
if (!enterfunc && strstr(buf2, "RETURNFUNC("))
|
||||
{
|
||||
printf("Line#%d need RETURNFUNC2 %s\n", linenum, argv[1]);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
if (strstr(buf2, "RETURNFUNC("))
|
||||
{
|
||||
if (enterfunc == 0) { printf("Line#%d no matching ENTERFUNC %s\n", linenum, argv[1]); }
|
||||
|
||||
enterfunc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return retval;
|
||||
}
|
Loading…
Reference in New Issue
Block a user