-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutdoc.cpp
More file actions
40 lines (36 loc) · 729 Bytes
/
cutdoc.cpp
File metadata and controls
40 lines (36 loc) · 729 Bytes
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
#include<iostream>
#include<unistd.h>
using namespace std;
int atoi(char * t)
{
int c=0;
for(int i=0;*(t+i)!='\0';i++) c*=10,c+=*(t+i)-'0';
return c;
}
char* itoa(int i)
{
string s="";
while(i) s=(char)(i%10+'0')+s,i/=10;
return (char *)s.data();
}
int main(int argv,char **args)
{
string s;
if(argv==2)
{
s="cat ",s+=args[1];
system((char *)s.data());
}
if(argv==3) cout<<'?';
if(argv==4)
{
s="tail -n ",s+=args[2],s+=" ",s+=args[1],s+=" > ",s+=".tmp.",s+=args[1];
system((char *)s.data());
s="head -n ",s+=itoa(atoi(args[3])-atoi(args[2])),s+=" .tmp.",s+=args[1];
system((char *)s.data());
cout<<endl;
s="rm ",s+=".tmp.",s+=args[1],s+=" >/dev/null";
system((char *)s.data());
}
return 0;
}