📄 refs.cpp
字号:
// A.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "REFs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define _in_file_TAG "-I"
#define _out_file_TAG "-O"
#define _help1_TAG "-H"
#define _help2_TAG "-?"
#define _help3_TAG "?"
#define _help4_TAG "--H"
#define _help5_TAG "/?"
#define _help6_TAG "/H"
char** lpCommandLine;
char* defaultInput="dir.lst";
char* inFile=NULL;
char* outFile=NULL;
char* dirName=NULL;
char* titleName=NULL;
BOOL bInFile=FALSE;
BOOL bOutFile=FALSE;
BOOL bHelp=FALSE;
FILE* fin;
FILE* fout;
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
int i, Index;
char buffer[1024];
char Title[1024];
char Author[1024];
char Proceeding[1024];
short int Pages[2];
int Volume=0;
char *check;
char spaces[]=" ";
//Read and write .INI file for settings.
CString strSummary = "Summary";
CString strStringItem = "My String Item";
CString strRuntime_H = "Runtime_H";
CString strRuntime_L = "Runtime_L";
CString strHistory = "History";
CString strHistoryEntry = "Entries";
CString strCmdString;
char strDate[128], strTime[128];
unsigned nValue_H, nValue_L;
CWinApp* pApp = AfxGetApp();
nValue_H = pApp->GetProfileInt(strSummary, strRuntime_H, -1);
nValue_L = pApp->GetProfileInt(strSummary, strRuntime_L, -1);nValue_L--;
nValue_L++;
if(nValue_L == 0) nValue_H++;
pApp->WriteProfileInt(strSummary, strRuntime_H, nValue_H);
pApp->WriteProfileInt(strSummary, strRuntime_L, nValue_L+1);
strHistoryEntry.Format("Entry_%04X:%04X", nValue_H, nValue_L);
_tzset();_strtime(strTime);_strdate(strDate);
strCmdString.Format("[%s - %s] %s", strDate, strTime, pApp->m_lpCmdLine);
pApp->WriteProfileString(strHistory, strHistoryEntry, strCmdString);
//End of .INI processing
for(i=1; i<argc; i++)
{
if(!bHelp && (strstr(strupr(argv[i]), _help1_TAG) != NULL ||
strstr(strupr(argv[i]), _help2_TAG) != NULL ||
strstr(strupr(argv[i]), _help3_TAG) != NULL ||
strstr(strupr(argv[i]), _help4_TAG) != NULL ||
strstr(strupr(argv[i]), _help5_TAG) != NULL ||
strstr(strupr(argv[i]), _help6_TAG) != NULL)){
bHelp=TRUE;
}
if(strstr(strupr(argv[i]), _in_file_TAG) != NULL && !bInFile){
if(strlen(argv[i]) == strlen(_in_file_TAG))
{
inFile=argv[i+1];
i++;
}
else inFile=argv[i]+2;
bInFile = TRUE;
}
if(strstr(strupr(argv[i]), _out_file_TAG) != NULL && !bOutFile){
if(strlen(argv[i]) == strlen(_out_file_TAG))
{
outFile=argv[i+1];
i++;
}
else outFile=argv[i]+2;
bOutFile = TRUE;
}
if(bOutFile && bInFile) break;
}
if(argc==1 || bHelp)
{
CString str;
str.Format("本程序用于处理IEEE搜索结果,提出作者、标题、页号。\n调用方法:"\
"\n%s -I <infile> -O <outfile>\n\n其中:\n"\
"-I 指定输入文件,未指定时,使用缺省值:标准输入设备,其中的输入文件请从"\
"浏览器复制并粘贴到纯文本编辑器中保存。\n"\
"-O 指定输出文件名,", argv[0]);
MessageBox(NULL, (LPCTSTR) str, "Fatal Error: No input filename is given!", MB_OK);
return FALSE;
}
if(!bInFile){
fin=stdin;
}
else if((fin = fopen(inFile, "rt")) == NULL)
{
AfxMessageBox("Fatal Error: Cannot open the input file for reading!\nProgram Abort.");
return FALSE;
}
if(!bOutFile){
cerr<<"Warning: No output file specified! Use stdout as default output\n";
fout=stdout;
}
else if((fout = fopen(outFile, "wt")) == NULL)
{
AfxMessageBox("Fatal Error: Cannot open the output file for writing!\nProgram Abort.");
fcloseall();
return FALSE;
}
/* Beginning of processing title line.....*/
#define WORD_LENGTH 30
do{
if(fgets(buffer, sizeof(buffer)-2, fin) == NULL){
if(!feof(fin))
AfxMessageBox("Error occured! Program aborted!");
return(-1);
}
else{
char *p=Title;
char *pp;
int count=0;
i=sscanf(buffer, "%d", &Index);
printf("\rReferences[%d]", Index);
sscanf(buffer, "%s", p);
pp=buffer+strlen(p)+2;
do{
i=sscanf(pp, "%s", p);
pp=pp+strlen(p)+1;
p=p+WORD_LENGTH;
count=count+i;
}while(i>0);
p=Title;
for(i=0; i<count; i++){
sprintf(Title+strlen(Title), " %s", p+WORD_LENGTH*(i+1));
}
}/* End of processing title line.....*/
/* Beginning of processing Author line.....*/
if(fgets(buffer, sizeof(buffer)-2, fin) == NULL){
AfxMessageBox("Error occured! Program aborted!");
return(-1);
}
else{
char *p=Author;
char *pp=buffer;
int wc=0, NumberOfAuthor=0, AuthorIndex[30];
wc=0;
do{
while(isspace(*pp) && pp<buffer+strlen(buffer)) pp++;
while(*pp != ';' && pp<buffer+strlen(buffer)) *(p++)=*pp++;
wc++;
*p=0;
p=Author+WORD_LENGTH*(wc);
pp++;
}while(pp<buffer+strlen(buffer));
for(i=0; i<wc-1; i++){
int comma;
CString temp, firstName, lastName;
temp=Author+WORD_LENGTH*i;comma=temp.Find(',');
firstName=temp.Left(comma);
lastName=temp.Mid(comma+1);lastName.TrimLeft();
sprintf(Author+strlen(Author)*(i!=0), "%s", lastName);
if(firstName.GetLength())sprintf(Author+strlen(Author), " %s, ", firstName);
else sprintf(Author+strlen(Author), ", ");
}
}/* End of processing Author line.....*/
/* Beginning of processing Proceeding line.....*/
if(fgets(Proceeding, sizeof(buffer)-2, fin) == NULL){
AfxMessageBox("Error occured! Program aborted!");
return(-1);
}
else{
CString tmp=Proceeding;
tmp.TrimRight();
sprintf(Proceeding, "%s", (char *) (LPCTSTR) tmp);
}
/* End of processing Proceeding line.....*/
/* Beginning of processing Pages line.....*/
if(fgets(buffer, sizeof(buffer)-2, fin) == NULL){
AfxMessageBox("Error occured! Program aborted!");
return(-1);
}
else{
i=sscanf(buffer, "Pages:%u - %u vol.%d", &Pages[0], &Pages[1], &Volume);
if( i >= 2) Pages[1]=Pages[1];
}/* End of processing Pages line.....*/
if(Volume >0)
fprintf(fout, "%s%s, %s, pp. %d-%d, vol.%d\n", Author, Title, Proceeding, Pages[0], Pages[1], Volume);
else
fprintf(fout, "%s%s, %s, pp. %d-%d\n", Author, Title, Proceeding, Pages[0], Pages[1]);
/* Ignore 5 lines */
int _SWITCH_;
int _PreSwitch_=-1;
#define CHECK_EOF \
{\
CString tmp;\
tmp.Format("%s", buffer);\
tmp.TrimLeft();\
sprintf(buffer, "%s", (char*)((LPCSTR)tmp));\
if(check == NULL){\
_SWITCH_ = -1;\
break;\
}\
else{\
if(buffer[0] =='\n' || strlen(buffer) == 0){\
_SWITCH_ = 0;/*Blank line */\
}else if(buffer[0] == '['){\
_SWITCH_ = 1;/*Abstract Link line */\
}else if(buffer[0] == '-'){\
_SWITCH_ = 2;/*Dashed line */\
}\
}\
}
check=fgets(buffer, sizeof(buffer)-2, fin); CHECK_EOF;
do{
/*switch(_SWITCH_){
case 0:check=fgets(buffer, sizeof(buffer)-2, fin); _PreSwitch_ = _SWITCH_; CHECK_EOF; break;
case 1:check=fgets(buffer, sizeof(buffer)-2, fin); _PreSwitch_ = _SWITCH_; CHECK_EOF; break;
case 2:check=fgets(buffer, sizeof(buffer)-2, fin); _PreSwitch_ = _SWITCH_; CHECK_EOF; if(_SWITCH_ == 0) {_SWITCH_ = -1; }break;
}
*/
check=fgets(buffer, sizeof(buffer)-2, fin);
if(check == NULL) _SWITCH_ = -1;
if(buffer[0] == '-' && buffer[1] == '-' && check != NULL) _SWITCH_ = -1;
}while(_SWITCH_ != -1);
/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
/* Display operating system-style date and time. */
}while(1);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -