如何在使用夹板工具检查源代码时包含头文件?

时间:2022-04-10 15:07:16

I created 2 C program source code files and one header file which just contains a function declaration.

我创建了两个C程序源代码文件和一个头文件,其中包含一个函数声明。

mypattern.h

mypattern.h

 #include<stdio.h>
void pattern_check(char *,int,char *);

pattern_main.c

pattern_main.c

    #include<mypattern.h>
int main(int argc,char *argv[])
{
 int i,max,flag=1;
 char *p,*cmd="end";
 if(argc!=3)
 {
  printf("usage : Invalid no of arguments\n");
  return 0;
 }
 max=atoi(argv[1]);
 char elements[max][15];
 printf("\nEnter the %d input strings :\n",max);
 for(i=0;i<max;i++)
 {
   p=elements[i];
  // printf("%u\n",p);
   scanf("%s",p);
//   printf("%s-->%u\n",p,p);
  if(*p==*cmd)
  {
   flag=0;
   max=i;
   break;
  }
 }
 if(flag)
 p=p-(sizeof(char)*((max-1)*15));
 else
 p=p-(sizeof(char)*((max)*15));
 pattern_check(p,max,argv[2]);
 return 0;
}

pattern_search.c

pattern_search.c

  #include<mypattern.h>
void pattern_check(char *elements,int max,char *pattern)
{
 int i,count=0,len=0;
 char *ptr,*ch,*pat[max],*output=NULL;
// printf("\nPattern : %s\n",pattern);
 for(i=0;i<max;i++)
 {
 // printf("\nfor loop %d\n",i);
  ptr=elements+(i*15);
  //printf("%u-->%s\n",ptr,ptr);
  ch=strstr(ptr,pattern);
  if(ch!=NULL)
  {
   pat[count]=(char *)malloc(sizeof(char));
   if(pat[count]==NULL)
   {
    printf("\nMalloc failed\n");
    return;
   }
   strcpy(pat[count],ptr);
  // printf("\nCount : %d\n",count);
  // printf("\n%s-->%u\n",pat[count],pat[count]);
  count++;
  }
 }
 printf("Pattern mateched elements :\n");
 for(i=0;i<count;i++)
 {  printf("\n-->%s\n",pat[i],pat[i]);
    len+=strlen(pat[i]);
 }
// printf("\nFinal length : %d\n",len);
  output=malloc(sizeof(char)*(len+1));
  if(NULL==output)
  {
   printf("Malloc failed \n");
   return;
  }
 for(i=count-1;i>=0;i--)
  strncat(output,pat[i],strlen(pat[i]));
 printf("\nFinal concatended string output : %s\n\n",output);
 free(output);
}

While checking this code with splint tool on linux,

在linux上用夹板工具检查代码时,

 splint pattern_main.c

I am getting the following error:

我得到了以下错误:

pattern_main.c:1:22: Cannot find include file mypattern.h on search path:
                        /usr/include;/usr/include
  Preprocessing error. (Use -preproc to inhibit warning)
Preprocessing error for file: /user/gur29597/mysourcecode/Memory_pgm/pattern_main.c
*** Cannot continue.

How can i make it correct?

我怎样才能使它正确呢?

2 个解决方案

#1


1  

Use #include "mypattern.h" with double-quotes, not angles, and/or pass include directories with some -I arguments to gcc. And don't forget to use -Wall flag to GCC to get all warnings! To understand which headers are included, use -H or produce the preprocessed form with gcc -C -E pattern_main.c

使用“mypattern # include。用双引号,而不是角度和/或通过包含有一些-I参数的目录。并且不要忘记使用-Wall标志来得到所有的警告!要理解其中包含哪些头,请使用-H或用gcc -C -E pattern_main.c生成预处理表单。

#2


7  

You can try either of the 2 solutions (Basile has already mentioned it but in the response it is mentioned as for gcc but it hold for splint as well):
1. Use #include "mypattern.h" instead of #include <mypattern.h>. This will prompt splint to check the header in the current directory as well.
2. Use -I<path_to_header> option with splint. Something on these lines:
splint pattern_main.c -I./ or

你可以尝试这两个方案中的任何一个(Basile已经提到过了,但是在回应中提到了gcc,但是它也适用于夹板):1。使用“mypattern # include。而不是#include 。这将促使夹板检查当前目录中的标题。2。使用-I 选项与夹板。在这些线上的东西:夹板图案。c - i。/或

splint pattern_main.c -I`pwd`

You can find the details regarding adding header inclusion path for splint in their manual. Check out section 14.3 on the following link
Hope this helps!

您可以在他们的手册中找到关于夹板添加标题包含路径的细节。请查看下面链接的第14.3节,希望这对您有帮助!

#1


1  

Use #include "mypattern.h" with double-quotes, not angles, and/or pass include directories with some -I arguments to gcc. And don't forget to use -Wall flag to GCC to get all warnings! To understand which headers are included, use -H or produce the preprocessed form with gcc -C -E pattern_main.c

使用“mypattern # include。用双引号,而不是角度和/或通过包含有一些-I参数的目录。并且不要忘记使用-Wall标志来得到所有的警告!要理解其中包含哪些头,请使用-H或用gcc -C -E pattern_main.c生成预处理表单。

#2


7  

You can try either of the 2 solutions (Basile has already mentioned it but in the response it is mentioned as for gcc but it hold for splint as well):
1. Use #include "mypattern.h" instead of #include <mypattern.h>. This will prompt splint to check the header in the current directory as well.
2. Use -I<path_to_header> option with splint. Something on these lines:
splint pattern_main.c -I./ or

你可以尝试这两个方案中的任何一个(Basile已经提到过了,但是在回应中提到了gcc,但是它也适用于夹板):1。使用“mypattern # include。而不是#include 。这将促使夹板检查当前目录中的标题。2。使用-I 选项与夹板。在这些线上的东西:夹板图案。c - i。/或

splint pattern_main.c -I`pwd`

You can find the details regarding adding header inclusion path for splint in their manual. Check out section 14.3 on the following link
Hope this helps!

您可以在他们的手册中找到关于夹板添加标题包含路径的细节。请查看下面链接的第14.3节,希望这对您有帮助!