Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- void replaceEnd(char *save_buf, const char* add, const char* what)
- {
- unsigned int j;
- int flag = 0;
- char temp[256];
- //int i = (strlen(save_buf) - 1);
- int a = strlen(what) - 1;
- //printf("AS %s \n", what[a]);
- for ( int i = (strlen(save_buf) - 1); i > 0; i--)
- {
- if (save_buf[i] == what[a])
- {
- flag = 1;
- }
- if (flag && save_buf[i] == what[a - 1])
- {
- strncpy(temp, save_buf, i);
- for (j = 0; j < strlen(add); j++)
- {
- temp[i + j] = add[j];
- }
- temp[i + j] = '\0';
- strcpy(save_buf,temp);
- //printf("End [%s] \n", temp);
- //cout << temp << endl;
- break;
- }
- }
- }
- int findHost(char* buf,int k)
- {
- const char *delim = "\n";
- char* token;
- char tmp[1000000];
- //char* tmp;
- int cntReplaces = 0;
- fprintf(stdout,"MIHAELA Buf before change: [%s]\n", buf);
- token = strtok(buf, delim);
- while (token != NULL )
- {
- fprintf(stdout,"MIHAELA token before [%s]\n", token);
- //if (findAndReplace(token, "Host\\s*\\(\\s*", "IF NOT Host_Shell(" )>0)
- if (k>0)
- {
- fprintf(stdout,"MIHAELA what 1 [%s]\n\n", token);
- //findAndReplace(token, "\\s*\\)\\s*;", ") THEN RAISE Form_Trigger_Failure; END IF;");
- replaceEnd(token, ") THEN RAISE Form_Trigger_Failure; END IF;", ");");
- //fprintf(stdout,"MIHAELA changed line [%s]\n", token);
- fprintf(stdout,"MIHAELA what 2 [%s]\n\n", token);
- cntReplaces++;
- printf("Replace %d\n",cntReplaces);
- fprintf(stdout,"MIHAELA tmp XX [%s]\nXX\n", token);
- }
- strncat(tmp, token,strlen(token));
- strcat(tmp, "\n");
- token = strtok(NULL, delim);
- }
- memcpy(buf, tmp, strlen(tmp));
- memset(tmp, 0, sizeof(tmp));
- buf[strlen(buf)]= '\0';
- fprintf(stdout,"MIHAELA [%s]\n", buf);
- fprintf(stdout,"MIHAELA replaces [%d]\n", cntReplaces);
- return cntReplaces;
- }
- int main()
- {
- char buf[1000] = "Host(Get_Variable('IMX_HOME')||'/bin/mail_notify.sh > /dev/null 2>&1');]sazdxfc\n Host(Get_Variable('IMX_HOME')||'/bin/mailctl status -s > /dev/null');]";
- findHost(buf,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement