是时候上传一个自己的一个十分简便的辅助编译程序,我也不知道为什么要做,但是控制不住!!!
#include "head.h"
/*
*This program is just use for hujian's program.
*And this peogram is do some easy work for hujian
*You can look up the source code and copy this code
*to your project or just use this program in your project
*And you also can change or rewrite this code in your
*computer environment to reach your aim.
*Author:hujian in nankai university
*Time:2016/3/12
*/
/*this is the scanf str length*/
static int lengthofscanfarray=0;
/*this array will return the result string ,you can get str in this array*/
static char* hujian_array[HJ_BUFFER_EX];
/*get asc time(real),if time is not null,stored the time*/
char* hujian_time(char* timepp)
{
time_t timep;
time(&timep);
if(timepp!=NULL){
sprintf(timepp,"%s",asctime(gmtime(&timep)));
}
return asctime(gmtime(&timep));
}
/*retun the new file pointer*/
FILE* hujian_newfile(const char* filepath,const char* flag)
{
FILE* hujian_fp=fopen(filepath,flag);
return hujian_fp;
}
/*new dir*/
void hujian_newdir(char* filepath)
{
char* cmd;
sprintf(cmd,"mkdir %s",filepath);
}
/*rm file*/
void hujian_rmfile(const char* filepath)
{
char* cmd;
sprintf(cmd,"rm %s",filepath);
system(cmd);
}
/*rm dir*/
void hujian_rmdir(const char* filepath)
{
char* cmd;
sprintf(cmd,"rmdir %s",filepath);
system(cmd);
}
/*
get the string
hujian hujian hujian
=>res[0]="hujian"
=>res[1]="hujian"
=>res[2]="hujian"
....
*/
int hujian_scan(char* source,char** res)
{
int i,cnt=0;
for(i=0;i<strlen(source);i++){
if(source[i]==' '||source[i]=='\n'){
cnt++;
}
}
if(cnt==1){
strcpy(res[0],source);
return 1;
}
else{/*cnt>1*/
int k;
for(k=0;k<cnt;k++){
char* str="";
for(i=0;i<strlen(source);i++){
if(source[i]!=' '||source[i]!='\n'){
*str++=source[i];
}else{
*str++='\0';
break;
}
}
sprintf(res[k],"%s",str);
}
}
return cnt;
}
int main(int argc,char** argv)
{
system("clear");
/*just for two params,like this =>hujian progectname*/
if(argc<2||argc>5){
printf("\tUsage:hujian+filename [-d] [-p] [-g] [-e]<attachement>\n\t[-d] means you want to delete the log file\n\t[-p] means you want to print the detials in your workconsole\n\t[-g] means your peogram is c++ file\n\t[-e]<attement> means you will add some other file<-lrt etc.>\n");
exit(EXIT_FAILURE);
}
int hujian_i;
int index,c,dflag=0,pflag=0,gflag=0;
char attach[HJ_BUFFER_EX]
if(argc>2){
if(argc==3){
if(strcmp("-p",argv[2])==0){
pflag=1;
}
else if(strcmp("-d",argv[2])==0){
dflag=1;
}
else{
gflag=1;
}
}
else if(argc==4){/*argc==4*/
for(hujian_i=2;hujian_i<=3;hujian_i++){
if(strcmp(argv[hujian_i],"-p")==0){
pflag=1;
}if(strcmp(argv[hujian_i],"-d")==0){
dflag=1;
}if(strcmp(argv[hujian_i],"-g")==0){
gflag=1;
}
}
}
else if(argc==5){/*argc==5*/
for(hujian_i=2;hujian_i<=4;hujian_i++){
if(strcmp(argv[hujian_i],"-p")==0){
pflag=1;
}if(strcmp(argv[hujian_i],"-d")==0){
dflag=1;
}if(strcmp(argv[hujian_i],"-g")==0){
gflag=1;
}
}
}
else if(argc==6){
for()
}
}
/*the param is ok,and we can compiler the code for user*/
char resname[HJ_BUFFER_F];
sprintf(resname,"%s.exe",argv[1]);
char hujian_ppp[HJ_BUFFER_EX];
char* f="gcc ";
if(gflag){
f="g++";
}
char hujianhujian[HJ_BUFFER_EX];
sprintf(hujianhujian,"%s %s -o %s",f,argv[1],resname);
//start to complire
system(hujianhujian);
//log this time
FILE* hujian_fp;
//hujian_fp=fopen("/home/hujian/桌面/hujian_log","a");
hujian_fp=hujian_newfile("/home/hujian/桌面/hujian_log","a");
time_t timep;
time(&timep);
fprintf(hujian_fp,"done ->%s on time->%s\n",hujianhujian,hujian_time(NULL));
fclose(hujian_fp);
if(dflag){
//system("rm /home/hujian/桌面/hujian_log");
hujian_rmfile("/home/hujian/桌面/hujian_log");
}
if(pflag){
printf("\n\t|-------detials---------------------------|");
printf("\n\t|--argc:%d",argc);
printf("\n\t|--argv:");
int ppp;
for(ppp=0;ppp<argc;ppp++){
printf("\n\targv[%d]=%s",ppp,argv[ppp]);
}
printf("\n\t|--input filename:%s",argv[1]);
printf("\n\t|--option:[d,%d],[p,%d],[g,%d]",dflag,pflag,gflag);
printf("\n\t|--output:%s",hujianhujian);
printf("\n\t|--Time:%s",hujian_time(NULL));
printf("\t|-----------------------------------------|\n");
}
exit(EXIT_SUCCESS);
}