56 lines
986 B
C++
56 lines
986 B
C++
#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;
|
|
}
|
|
|
|
|