common.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include "Config.h"
  6. //------------------------------------------------------------------------------
  7. void trim(char *s)
  8. {
  9. int i = 0, j, k, l = 0;
  10. while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
  11. i++;
  12. }
  13. j = strlen(s) - 1;
  14. while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
  15. j--;
  16. }
  17. if (i == 0 && j == strlen(s) - 1) { }
  18. else if (i == 0) { s[j + 1] = '\0'; }
  19. else {
  20. for (k = i; k <= j; k++) { s[l++] = s[k]; }
  21. s[l] = '\0';
  22. }
  23. }
  24. int mystrcmp(char *p1, char *p2)
  25. {
  26. while (*p1 == *p2) {
  27. if (*p1 == '\0' || *p2 == '\0') {
  28. break;
  29. }
  30. p1++;
  31. p2++;
  32. }
  33. if (*p1 == '\0' && *p2 == '\0') {
  34. return (PASS);
  35. } else {
  36. return (FAIL);
  37. }
  38. }
  39. void substr(char *dest, const char *src, uint32_t start, uint32_t cnt)
  40. {
  41. strncpy(dest, src + start, cnt);
  42. dest[cnt] = 0;
  43. }
  44. void split(char **arr, char *str, const char *del)
  45. {
  46. char *s = strtok(str, del);
  47. while (s != NULL) {
  48. *arr++ = s;
  49. s = strtok(NULL, del);
  50. }
  51. }