Automatically distill headers from other project

catch_inc.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
 
dir_cur=`pwd`
dir_inc=original_inc
dir_src=/path/to/other/project
 
withly()
{
	[ -e $2 ] && $*
}
 
withoutly()
{
	[ -e $2 ] || $*
}
 
withly rm inc.makefile1
withly rm Makefile
 
if [ x$1 == xclean ] ; then
	withly rm inc.makefile
	withly rm ${dir_inc} -Rf
	exit 0
fi
 
withoutly mkdir ${dir_inc}
withoutly touch inc.makefile
 
while [ 1 ] ; do
	cat inc.makefile | sort | uniq > inc.makefile1
	cp inc.makefile1 inc.makefile
	cat inc.makefile | sed ':t;N;s/\n//;b t' | sed 's/\//\\\//g' | sed 's/\ /\\\ /g' > inc.makefile1
	sed "s/@original_includes@/`cat inc.makefile1`/g" Makefile.pat > Makefile
	lost_header=`make 2>&1 | grep "#include" | awk '{if ($2 == "|" && $3 == "#include") print $4}' | awk -F\" '{print $2}'`
	if [ x${lost_header} == x ] ; then
		break
	fi
	found_header=`cd ${dir_src}; find . -name ${lost_header} | head -n 1`
	echo ${found_header}
	found_header=${found_header##./}
	( cd ${dir_src}; cp --path ${found_header} ${dir_cur}/${dir_inc}/ )
	found_header=`dirname ${found_header}`
	echo "-I${dir_inc}/${found_header} " | cat >> inc.makefile
done

For an example, pattern file Makefile.pat is as

1
2
3
4
...
CFLAGS=-g -Iinclude @original_includes@
LDFLAGS=-pthread -lm
...

from which the catch_inc.sh script can generate Makefile like

1
2
3
4
...
CFLAGS=-g -Iinclude -Ioriginal_inc/subdir/in/other/project/inc1 -Ioriginal_inc/subdir/in/other/project/common/inc2
LDFLAGS=-pthread -lm
...

refer to:
https://www.cnblogs.com/liqiu/p/4506508.html

生成pcap文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include <stdio.h>
#include <sys/unistd.h>
#include <pcap/pcap.h>
 
typedef struct pcap_log_t pcap_log_t;
struct pcap_log_t {
    pcap_t* pd;
    pcap_dumper_t* pdumper;
};
 
pcap_log_t* pcap_log_init()
{
	char path[256];
	pcap_log_t* pcap = (pcap_log_t*)malloc(sizeof(*pcap));
	memset(pcap, 0, sizeof(*pcap));
 
	pcap->pd = pcap_open_dead(/* DLT_RAW */ 1, 65535 /* snaplen */);
 
	sprintf(path, "/tmp/pcap_%d.pcap", gettid());
	pcap->pdumper = pcap_dump_open(pcap->pd, path);
	return pcap;
}
 
void pcap_log_write(pcap_log_t* pcap, char* packet, int len)
{
	struct pcap_pkthdr hdr;
	hdr.ts.tv_sec = 0;
	hdr.ts.tv_usec = 0;
	hdr.caplen = len;
	hdr.len = len;
 
	pcap_dump((u_char*)pcap->pdumper, &hdr, (const u_char*)packet);
	pcap_dump_flush(pcap->pdumper);
}
 
void pcap_log_fini(pcap_log_t* pcap)
{
	pcap_dump_close(pcap->pdumper);
	pcap_close(pcap->pd);
 
	free(pcap);
}
 
int main()
{
	pcap_log_t* pcap = pcap_log_init();
/*	while (...) {
		// packet is raw data from mac layer 
		pcap_log_write(pcap, packet, len);
	}
*/	pcap_log_fini(pcap);
	return 0;
}

refer to:
https://blog.csdn.net/u014260236/article/details/51035484/

error C2504: '_IMsoDispObj' : base class undefined

原因是mso.dll库中的定义没导入,对于装的是Office 2013的环境,正确写法是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#import "C:\\Program Files (x86)\\Common Files\\microsoft shared\\OFFICE15\\MSO.DLL" rename("RGB", "MSRGB")
 
using namespace Office;
 
#import "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" raw_interfaces_only, \
rename("Reference", "ignorethis"), rename("VBE", "JOEVBE")
 
using namespace VBIDE;
 
#import "C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE" exclude("IFont", "IPicture") \
rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "JOEVBE"), \
rename("ReplaceText", "JOEReplaceText"), rename("CopyFile","JOECopyFile"), \
rename("FindText", "JOEFindText"), rename("NoPrompt", "JOENoPrompt")
 
using namespace Excel;
 
#include "CApplication.h"
#include "CWorkbooks.h"
#include "CWorkbook.h"
#include "CWorksheets.h"
#include "CWorksheet.h"
#include "CRange.h"
#include "CFont0.h"
 
//下面再写导出Excel文件的逻辑。

同时还要把这包含的Type Lib几个头文件的开头的import语句都删掉。
还要把CRange.h里的DialogBox函数注释掉。
就可以了。

还有,导出Excel文件用这种COM进程间通讯的方式最大缺点是慢,当导出条数很大时尤为明显,最好的方法是写一个C#子程序调npoi库。现在都是win7以上了,做成安装包时不需要要用户先安装.net framework之类的库。

refer to: http://blog.sina.com.cn/s/blog_7c5bff15010117cb.html