Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void replaceEnd(char *save_buf, const char* add, const char* what)
  12. {
  13. unsigned int j;
  14. int flag = 0;
  15. char temp[256];
  16. //int i = (strlen(save_buf) - 1);
  17. int a = strlen(what) - 1;
  18.  
  19. //printf("AS %s \n", what[a]);
  20. for ( int i = (strlen(save_buf) - 1); i > 0; i--)
  21. {
  22. if (save_buf[i] == what[a])
  23. {
  24. flag = 1;
  25. }
  26.  
  27. if (flag && save_buf[i] == what[a - 1])
  28. {
  29. strncpy(temp, save_buf, i);
  30. for (j = 0; j < strlen(add); j++)
  31. {
  32. temp[i + j] = add[j];
  33. }
  34. temp[i + j] = '\0';
  35.  
  36.  
  37. strcpy(save_buf,temp);
  38. //printf("End [%s] \n", temp);
  39. //cout << temp << endl;
  40. break;
  41. }
  42. }
  43. }
  44.  
  45. int findHost(char* buf,int k)
  46. {
  47. const char *delim = "\n";
  48. char* token;
  49. char tmp[1000000];
  50. //char* tmp;
  51. int cntReplaces = 0;
  52.  
  53. fprintf(stdout,"MIHAELA Buf before change: [%s]\n", buf);
  54.  
  55. token = strtok(buf, delim);
  56.  
  57. while (token != NULL )
  58. {
  59. fprintf(stdout,"MIHAELA token before [%s]\n", token);
  60. //if (findAndReplace(token, "Host\\s*\\(\\s*", "IF NOT Host_Shell(" )>0)
  61. if (k>0)
  62. {
  63. fprintf(stdout,"MIHAELA what 1 [%s]\n\n", token);
  64.  
  65. //findAndReplace(token, "\\s*\\)\\s*;", ") THEN RAISE Form_Trigger_Failure; END IF;");
  66. replaceEnd(token, ") THEN RAISE Form_Trigger_Failure; END IF;", ");");
  67.  
  68. //fprintf(stdout,"MIHAELA changed line [%s]\n", token);
  69. fprintf(stdout,"MIHAELA what 2 [%s]\n\n", token);
  70. cntReplaces++;
  71. printf("Replace %d\n",cntReplaces);
  72.  
  73. fprintf(stdout,"MIHAELA tmp XX [%s]\nXX\n", token);
  74. }
  75.  
  76. strncat(tmp, token,strlen(token));
  77. strcat(tmp, "\n");
  78.  
  79. token = strtok(NULL, delim);
  80. }
  81.  
  82. memcpy(buf, tmp, strlen(tmp));
  83. memset(tmp, 0, sizeof(tmp));
  84. buf[strlen(buf)]= '\0';
  85.  
  86. fprintf(stdout,"MIHAELA [%s]\n", buf);
  87. fprintf(stdout,"MIHAELA replaces [%d]\n", cntReplaces);
  88.  
  89. return cntReplaces;
  90. }
  91.  
  92.  
  93.  
  94. int main()
  95. {
  96. 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');]";
  97. findHost(buf,0);
  98.  
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement