-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaker.c
More file actions
191 lines (166 loc) · 4.24 KB
/
maker.c
File metadata and controls
191 lines (166 loc) · 4.24 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#define NUM 20
#define NAME 256
#define TRANS 32
#define MAILL 60
#define INFO 1024
#define EASY 1
#define COMPLEX 2
typedef struct complex
{
int flag;
char *str;
char *auther;
char *maill;
char *info;
char *path;
}head;
void trans(char *str)
{
int size;
int iloop;
size=strlen(str);
for(iloop=0;iloop<size;iloop++)
{
if(str[iloop]>='a' && str[iloop]<='z')
str[iloop]=str[iloop]-TRANS;
}
}
#if 1
int maker(head *p) //传进来的文件名以;隔开
{
int iloop,jloop;
int count=0;
int num=0;
int flag=0;
char name[NUM][NAME]={{0}};
char buf[NAME]={0};
FILE *fd;
DIR *dir_p;
for(iloop=0;;iloop++)//分离名字
{
for(jloop=0;;jloop++)
{
if(p->str[jloop+count]=='\0')
{
flag=1;
count=0;
break;
}
if(p->str[jloop+count]==';')
{
count+=jloop+1;
break;
}
name[iloop][jloop]=p->str[jloop+count];
}
num++;
if(flag==1)//外层for循环跳出
{
flag=0;
break;
}
}
if((dir_p=opendir(p->path))==NULL)
{
printf("Can't find the path, please firstly determine it presence\n");
return 1;
}
closedir(dir_p);
for(iloop=0;iloop<num;iloop++)
{
/*创建c文件*/
memset(buf,0,sizeof(buf));
if(p->path[strlen(p->path)-1]!='/')
p->path[strlen(p->path)]='/';
sprintf(buf,"%s%s.c",p->path,name[iloop]);
fd=fopen(buf,"w+");
fprintf(fd,"/*FileName:%s.c*/\n",name[iloop]);
if(p->flag==COMPLEX)
{
fprintf(fd,"/*Auther:%s*/\n",strlen(p->auther)==0?NULL:p->auther);
fprintf(fd,"/*E-maill:%s*/\n",strlen(p->maill)==0?NULL:p->maill);
fprintf(fd,"/*Infomation:%s*/\n",strlen(p->info)==0?NULL:p->info);
}
fputs("#include <stdio.h>\n\n",fd);
fputs("int main(int argc, const char *argv[])\n",fd);
fputs("{\n\n\treturn 0\n}",fd);
fclose(fd);
/*创建头文件*/
memset(buf,0,sizeof(buf));
if(p->path[strlen(p->path)-1]!='/')
p->path[strlen(p->path)]='/';
sprintf(buf,"%s%s.h",p->path,name[iloop]);
fd=fopen(buf,"w+");
fprintf(fd,"/*FileName:%s.h*/\n",name[iloop]);
if(p->flag==COMPLEX)
{
fprintf(fd,"/*Auther:%s*/\n",strlen(p->auther)==0?NULL:p->auther);
fprintf(fd,"/*E-maill:%s*/\n",strlen(p->maill)==0?NULL:p->maill);
fprintf(fd,"/*Infomation:%s*/\n",strlen(p->info)==0?NULL:p->info);
}
trans(name[iloop]);
fprintf(fd,"#ifndef %s_H\n#define %s_H\n\n\n#endif",name[iloop],name[iloop]);
fclose(fd);
}
return 0;
}
#endif
int menu(head *p)
{
printf("Please input file path:\n");
read(0,p->path,NAME);
p->path[strlen(p->path)-1]=0;
printf("Please input file name:(more files are aparted by ';')\n");
read(0,p->str,NAME);
p->str[strlen(p->str)-1]=0;
printf("Please input file auther:\n");
read(0,p->auther,NAME);
p->auther[strlen(p->auther)-1]=0;
printf("Please input E-maill:\n");
read(0,p->maill,MAILL);
p->maill[strlen(p->maill)-1]=0;
printf("Please input file infmation:(less than 1024 bit)\n");
read(0,p->info,INFO);
p->info[strlen(p->info)-1]=0;
return 1;
}
int main(int argc, const char *argv[])
{
int num;
int iloop;
head *p=NULL;
p=malloc(sizeof(head));
p->str=(char *)malloc(NAME);
p->auther=(char *)malloc(NAME);
p->maill=(char *)malloc(MAILL);
p->info=(char *)malloc(INFO);
p->path=(char *)malloc(NAME);
if(argc>=2)
{
p->flag=EASY;
num=argc-1;
for(iloop=0;iloop<num;iloop++)
{
strcpy(p->str,argv[iloop+1]);
//printf("%s\n",p->str);
maker(p);
memset(p->str,0,NAME);
}
}
#if 1
else
{
p->flag=COMPLEX;
menu(p);
maker(p);
}
#endif
return 0;
}