📄 findurl.cpp
字号:
/* * If content is NULL, find out wheather INDEX_FILE includes the URL. * Otherwise, read the corresponding page of the URL. * */#include "Tse.h"#include "Url.h"int FindUrl(const char *url, char **content){ FILE *fpfile,*fpindex; char *buffer,file[URL_LEN+1]; int offsett, offset2; if(content){ fpfile = fopen(DATA_FILE_NAME.c_str(),"r"); if(fpfile == NULL) return -1; } fpindex = fopen(INDEX_FILE_NAME.c_str(),"r"); if(fpindex == NULL) return -1; while(!feof(fpindex)){ fscanf(fpindex, "%d %s", &offsett, file); //cout << "offset: " << offsett << endl; //cout << "url: " << file << endl; if( strlen(url) > strlen(file) ){ if( strncmp(url, file, strlen(url)) ){ continue; } }else{ if( strncmp(url, file, strlen(file)) ){ continue; } } if(content == NULL){ fclose(fpindex); return 0; } fseek( fpfile, offsett, 0 ); fscanf( fpindex, "%d", &offset2 ); offset2 = offset2 - offsett; buffer = ( char* )malloc( offset2+1 ); if(buffer == NULL){ fclose(fpfile); fclose(fpindex); return -1; } memset(buffer,0,offset2+1); fread(buffer, 1, offset2, fpfile); if(content == NULL) free(buffer); else *content = buffer; if(content) fclose(fpfile); fclose(fpindex); return 0; } if(content) fclose(fpfile); fclose(fpindex); return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -