blob: 43bbf032e39604502bf01f03ae8e7d1003b9b305 (
plain)
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
|
#include "pattern_replace.h"
#include <sys/types.h>//fstat
#include <sys/ioctl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
void print_help(void)
{
printf("Escape $ with \\$\n");
printf("-i Input Text");
printf("-f Find What\n");
printf("-r Replace With\n");
}
int main(int argc, char ** argv)
{
const char* find=NULL, *replacement=NULL, *input=NULL;
int oc=0;
if(argc<6)
{
print_help();
return -1;
}
while((oc=getopt(argc,argv,"f:r:i:"))!=-1)
{
switch(oc)
{
case 'f':
find=strdup(optarg);
break;
case 'r':
replacement=strdup(optarg);
break;
case 'i':
input=strdup(optarg);
break;
default:
printf("Invalid parameter.\n");
print_help();
return -1;
}
}
char* output=NULL;
size_t output_sz=0;
simple_replace(find, replacement, input, strlen(input),&output, &output_sz, 1);
printf("Subject: %s\n", input);
printf("Subsitute: %s\n", output);
free(output);
return 0;
}
|