nameparse.c 514 B

12345678910111213141516171819
  1. #include "nameparse.h"
  2. int nameparse(unsigned char *s,const char *x)
  3. {
  4. long long pos;
  5. long long j;
  6. if (!x) return 0;
  7. for (pos = 0;pos < 256;++pos) s[pos] = 0;
  8. pos = 0;
  9. while (*x) {
  10. if (*x == '.') { ++x; continue; }
  11. for (j = 0;x[j];++j) if (x[j] == '.') break;
  12. if (j > 63) return 0;
  13. if (pos < 0 || pos >= 256) return 0; s[pos++] = j;
  14. while (j > 0) { if (pos < 0 || pos >= 256) return 0; s[pos++] = *x++; --j; }
  15. }
  16. if (pos < 0 || pos >= 256) return 0; s[pos++] = 0;
  17. return 1;
  18. }