-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathll2lpath-internal.c
116 lines (103 loc) · 3.64 KB
/
ll2lpath-internal.c
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
// todo переписать все нахрен с использованием <dirent.h> и <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
#include <errno.h>
void readuntilspace(char * * ps)
{
while(**ps && !isspace(**ps))
(*ps)++;
}
void readspaces(char * * ps)
{
while(**ps && isspace(**ps))
(*ps)++;
}
#define MYBUFSIZ 10000
#define ifnot(arg) if(!(arg))
int main(int argc, char * argv[])
{
setlocale(LC_ALL,"");
char curpath[MYBUFSIZ];
char str[MYBUFSIZ];
FILE * out, * sapid, * in;
ifnot(out=fopen(argv[1],"w"))
{ fprintf(stderr,"can not open file %s",argv[1]); exit(1); }
ifnot(sapid=fopen(argv[2],"w"))
{ fprintf(stderr,"can not open file %s",argv[2]); exit(1); }
in=stdin;
int dir_count=0;
#define RID_PRINT 100
while(!feof(in))
{
fgets(curpath,MYBUFSIZ,in);
curpath[strlen(curpath)-1]='\0';
curpath[strlen(curpath)-1]='\0';
dir_count++;
if(dir_count%RID_PRINT==0){
if(dir_count/RID_PRINT==1)
fprintf(stderr,"progress begin\n");
fprintf(stderr,"%s\n",curpath);
}
// printf("curpath = \"%s\"\n",curpath);
bool dot_files = false;
int i;
for(i=3; i<argc; i++)
if(strlen(curpath)>2 && strstr(curpath+2,argv[i])==curpath+2){
dot_files=true;
break;
}
fgets(str,MYBUFSIZ,in);//итого кол-во файлов - игнорируем
while(fgets(str,MYBUFSIZ,in)){
if(isspace(*str))break;
char * p=str;
if(*p=='d' || *p=='l') continue;
if(*p!='-') {
char type=*p;
readuntilspace(&p); readspaces(&p); //printf("after 1 readuntilspace p = \"%s\" \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 2 readuntilspace p = %s \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 3 readuntilspace p = %s \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 4 readuntilspace p = %s \n",p);
int err=0;
errno=0;
long long s = strtoll(p,&p,10); readspaces(&p); //printf("size=%d\n",s);
if(errno){ fprintf(stderr,"size of file is overflow\n"); err=1; }
errno=0;
long long date = strtoll(p,&p,10); readspaces(&p);
if(errno){ fprintf(stderr,"date of file is overflow\n"); err=1; }
if(p[strlen(p)-1]=='\n') p[strlen(p)-1]='\0';
if(err) fprintf(stderr,"%s/%s\n",curpath,p);
//printf("add %10.10d %s/%s\n",s,curpath,p); //!!!
//sdp.insert(make_pair(s,make_pair(date,string(curpath)+'/'+string(p))));
fprintf(sapid,"%c\t%lld\t%lld\t%s/%s\n",type,s,date,curpath,p);
}
else{
readuntilspace(&p); readspaces(&p); //printf("after 1 readuntilspace p = \"%s\" \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 2 readuntilspace p = %s \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 3 readuntilspace p = %s \n",p);
readuntilspace(&p); readspaces(&p); //printf("after 4 readuntilspace p = %s \n",p);
int err=0;
errno=0;
long long s = strtoll(p,&p,10); readspaces(&p); //printf("size=%d\n",s);
if(errno){ fprintf(stderr,"size of file is overflow\n"); err=1; }
errno=0;
long long date = strtoll(p,&p,10); readspaces(&p);
if(errno){ fprintf(stderr,"date of file is overflow\n"); err=1; }
if(p[strlen(p)-1]=='\n') p[strlen(p)-1]='\0';
if(err) fprintf(stderr,"%s/%s\n",curpath,p);
//printf("add %10.10d %s/%s\n",s,curpath,p); //!!!
//sdp.insert(make_pair(s,make_pair(date,string(curpath)+'/'+string(p))));
if(!dot_files)
fprintf(out,"%lld\t%lld\t%s/%s\n",s,date,curpath,p);
}
}
// getchar();
}
if(dir_count>=RID_PRINT)
fprintf(stderr,"progress end\n");
fclose(in);
fclose(out);
fclose(sapid);
}