Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. char* scale(char *line, const char *type, float wsp)
  4. {
  5. int number = 0, i = 0;
  6. char *newLine[512], *wsk = line;
  7. char integer_string[5];
  8.  
  9. number = atoi(type) * wsp;
  10. type = strstr(line, "</int>");
  11.  
  12. do { i++; } while(!isdigit(*wsk++));
  13.  
  14. sprintf(integer_string, "%d", number);
  15. strncpy(newLine, line, i-1);
  16. strcat(newLine, integer_string);
  17. strcat(newLine, type);
  18. return newLine;
  19. }
  20.  
  21. char* findAttributeAdnSave(char *line)
  22. {
  23. int number = 0;
  24. const char *type = 0;
  25. char *newLine[512];
  26.  
  27. char *wsk = line;
  28. int i = 0;
  29. char integer_string[5];
  30.  
  31. if ((type = strstr(line, "itemWidth")) || (type = strstr(line, "xOffset"))) {
  32. type += 16;
  33. return scale(line, type, 1.5);
  34. } else if ((type = strstr(line, "itemHeight")) || (type = strstr(line, "yOffset"))) {
  35. type += 17;
  36. number = atoi(type) * 1.5;
  37. type = strstr(line, "</int>");
  38.  
  39. do { i++; } while(!isdigit(*wsk++));
  40.  
  41. sprintf(integer_string, "%d", number);
  42. strncpy(newLine, line, i-1);
  43. strcat(newLine, integer_string);
  44. strcat(newLine, type);
  45. return newLine;
  46. } else if ((type = strstr(line, "fontSize")) || (type = strstr(line, "titleFontSize"))) {
  47. type += 15;
  48. number = atoi(type) * 2.35;
  49. type = strstr(line, "</int>");
  50.  
  51. do { i++; } while(!isdigit(*wsk++));
  52.  
  53. sprintf(integer_string, "%d", number);
  54. strncpy(newLine, line, i-1);
  55. strcat(newLine, integer_string);
  56. strcat(newLine, type);
  57. return newLine;
  58. } else {
  59. strncpy(newLine, line, 512);
  60. }
  61.  
  62. return newLine;
  63. }
  64.  
  65. int main()
  66. {
  67. FILE *in, *out;
  68. char bufor[512];
  69.  
  70. if ((in = fopen("testowyxml.txt", "r")) == NULL)
  71. {
  72. fprintf(stderr, "Blad otwarcia pliku.\n");
  73. return -1;
  74. }
  75.  
  76. out = fopen("out.xml", "w");
  77.  
  78. while (feof(in) == 0)
  79. {
  80. fgets(bufor, 512, in);
  81. fputs(findAttributeAdnSave(bufor), out);
  82. }
  83.  
  84. fclose(in);
  85. fclose(out);
  86. printf("Created!");
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement