Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. #include "Header.h"
  2. #include<stdio.h>
  3.  
  4. AT_DATA at;
  5.  
  6. int parser(char ch,bool special)
  7. {
  8. static uint8_t state = 0;
  9. static uint32_t line_index, string_index;
  10. int i;
  11. switch (state)
  12. {
  13. case 0:
  14. line_index = 0;
  15. string_index = 0;
  16.  
  17. //printf("Matricea inainte:\n");
  18. //for (i = 0; i < at.line_count; i++) {
  19. // printf("%s ", (char*)at.str[i]);
  20. //}
  21. //printf("\n");
  22.  
  23. at.str[0][0] = '\0';
  24.  
  25. //printf("Matricea dupa:\n");
  26. //for (i = 0; i < at.line_count; i++) {
  27. // printf("%s ",(char*)at.str[i]);
  28. //}
  29. //printf("\n");
  30.  
  31. at.line_count = 0;
  32.  
  33. if (ch == 0x0D)
  34. {
  35. state = 1;
  36. }
  37. break;
  38.  
  39. case 1:
  40. if (ch == 0x0A)
  41. {
  42. state = 2;
  43. }
  44. else {
  45. line_index = 0;
  46. string_index = 0;
  47. return -state;
  48. }
  49. break;
  50. case 2:
  51. if (special) {
  52. if (ch != 0x0D && ch != '+') {
  53. at.str[line_index][string_index++] = ch;
  54. state = 11;
  55. }
  56. else {
  57. line_index = 0;
  58. string_index = 0;
  59. return -state;
  60. }
  61. }
  62. else{
  63. if (ch == 'E')
  64. {
  65. state = 3;
  66. }
  67. else {
  68. if (ch == 'O')
  69. {
  70. state = 10;
  71. }
  72. else {
  73. if (ch == '+')
  74. {
  75. state = 11;
  76. }
  77. else {
  78. line_index = 0;
  79. string_index = 0;
  80. return -state;
  81. }
  82. }
  83. }
  84. }
  85. break;
  86. case 3:
  87. if (ch == 'R')
  88. {
  89. state = 4;
  90. }
  91. else {
  92. line_index = 0;
  93. string_index = 0;
  94. return -state;
  95. }
  96. break;
  97. case 4:
  98. if (ch == 'R')
  99. {
  100. state = 5;
  101. }
  102. else {
  103. line_index = 0;
  104. string_index = 0;
  105. return -state;
  106. }
  107. break;
  108. case 5:
  109. if (ch == 'O')
  110. {
  111. state = 6;
  112. }
  113. else {
  114. line_index = 0;
  115. string_index = 0;
  116. return -state;
  117. }
  118. break;
  119. case 6:
  120. if (ch == 'R')
  121. {
  122. state = 7;
  123. at.ok = false;
  124. }
  125. else {
  126. line_index = 0;
  127. string_index = 0;
  128. return -state;
  129. }
  130. break;
  131. case 7:
  132. if (ch == 0x0D)
  133. {
  134. state = 8;
  135. }
  136. else {
  137. line_index = 0;
  138. string_index = 0;
  139. return -state;
  140. }
  141. break;
  142. case 8:
  143. if (ch == 0x0A)
  144. {
  145. state = 9;
  146. }
  147. else {
  148. line_index = 0;
  149. string_index = 0;
  150. return -state;
  151. }
  152. break;
  153. case 9:
  154. {
  155. if (at.ok == false) {
  156. state = 0;
  157. return 1;
  158. }
  159. else {
  160. state = 0;
  161. return 1;
  162. }
  163. }
  164. case 10:
  165. if (ch == 'K')
  166. {
  167. state = 7;
  168. at.ok = true;
  169. }
  170. else {
  171. line_index = 0;
  172. string_index = 0;
  173. return -state;
  174. }
  175. break;
  176. case 11:
  177. if (ch != 0x0D)
  178. {
  179. if (string_index < STR_SIZE) {
  180. state = 11;
  181. at.str[line_index][string_index++] = ch;
  182. }
  183. else {
  184. state = 11;
  185. }
  186. }
  187. else
  188. {
  189. if (ch == 0x0D)
  190. {
  191. if (line_index < MAX_LINE) {
  192. at.str[line_index++][string_index] = '\0';
  193. string_index = 0;
  194. at.line_count++;
  195. state = 12;
  196. }
  197. else {
  198. state = 12;
  199. }
  200. }
  201. else {
  202. line_index = 0;
  203. string_index = 0;
  204. return -state;
  205. }
  206. }
  207. break;
  208. case 12:
  209. if (ch == 0x0A)
  210. {
  211. state = 13;
  212. }
  213. else {
  214. line_index = 0;
  215. string_index = 0;
  216. return -state;
  217. }
  218. break;
  219. case 13:
  220. if (special) {
  221. if (ch == 0x0D)
  222. {
  223. state = 14;
  224. }
  225. else {
  226. line_index = 0;
  227. string_index = 0;
  228. return -state;
  229. }
  230. }
  231. else{
  232. if (ch == '+')
  233. {
  234. state = 11;
  235. }
  236. else
  237. {
  238. if (ch == 0x0D)
  239. {
  240. state = 14;
  241. }
  242. else {
  243. line_index = 0;
  244. string_index = 0;
  245. return -state;
  246. }
  247. }
  248. }
  249. break;
  250. case 14:
  251. if (ch == 0x0A)
  252. {
  253. state = 15;
  254. }
  255. break;
  256. case 15:
  257. if (ch == 'O')
  258. {
  259. state = 16;
  260. }
  261. else {
  262. if (ch == 'E')
  263. {
  264. state = 17;
  265. }
  266. else {
  267. line_index = 0;
  268. string_index = 0;
  269. return -state;
  270. }
  271. }
  272. break;
  273. case 16:
  274. if (ch == 'K')
  275. {
  276. state = 7;
  277. at.ok = true;
  278. }
  279. else {
  280. line_index = 0;
  281. string_index = 0;
  282. return -state;
  283. }
  284. break;
  285. case 17:
  286. if (ch == 'R')
  287. {
  288. state = 18;
  289. }
  290. else {
  291. line_index = 0;
  292. string_index = 0;
  293. return -state;
  294. }
  295. break;
  296. case 18:
  297. if (ch == 'R')
  298. {
  299. state = 19;
  300. }
  301. else {
  302. line_index = 0;
  303. string_index = 0;
  304. return -state;
  305. }
  306. break;
  307. case 19:
  308. if (ch == 'O')
  309. {
  310. state = 20;
  311. }
  312. else {
  313. line_index = 0;
  314. string_index = 0;
  315. return -state;
  316. }
  317. break;
  318. case 20:
  319. if (ch == 'R')
  320. {
  321. state = 7;
  322. at.ok = false;
  323. }
  324. else {
  325. line_index = 0;
  326. string_index = 0;
  327. return -state;
  328. }
  329. break;
  330. }
  331. return 2;
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement