Advertisement
DanGT

sscanf :v

Jan 28th, 2015
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. dsscanf(string[], format[], {Float,_}:...)
  2. {
  3. if(!string[0] || (string[0] && !string[1]))
  4. return format[0];
  5.  
  6. static
  7. i, // string
  8. p, pos = 0x2, // params
  9. f = 0x0, // format
  10. n, np, v, // 'i', 'd'
  11. d; // 's'
  12.  
  13. for(i = 0x0; string[i] && string[i] <= 0x20; i++) {}
  14. for(p = numargs(); pos < p && string[i]; )
  15. {
  16. switch(format[f++])
  17. {
  18. case '\0':
  19. return 0;
  20.  
  21. case 'i', 'd':
  22. {
  23. n = 0x0,
  24. np = 0x1,
  25. v = string[i];
  26.  
  27. if(v == 0x2d)
  28. np = -1, v = string[++i];
  29.  
  30. for(; (v = string[i]) > 0x20 && v != 0x20; i++)
  31. {
  32. if (0x30 <= v <= 0x39)
  33. n = (n * 0xA) + (v - 0x30);
  34. else
  35. return -1;
  36. }
  37. setarg(pos, 0x0, n * np);
  38. }
  39.  
  40. case 'c':
  41. setarg(pos, 0x0, string[i++]);
  42.  
  43. case 's', 'z':
  44. {
  45. d = 0;
  46.  
  47. if(format[f])
  48. {
  49. for(; (v = string[i++]) && v != 0x20; )
  50. setarg(pos, d++, v);
  51.  
  52. if(!d)
  53. return -1;
  54. }
  55. else
  56. {
  57. for(; (v = string[i++]); )
  58. setarg(pos, d++, v);
  59. }
  60. i--;
  61. setarg(pos, d, '\0');
  62. }
  63.  
  64. default:
  65. continue;
  66. }
  67.  
  68. for(; string[i] && string[i] != 0x20 && string[i] > 0x20; i++) {}
  69. for(; string[i] && (string[i] == 0x20 || string[i] <= 0x20); i++) {}
  70.  
  71. pos++;
  72. }
  73. return 0;
  74. }
  75. // Optimized: DanDRT
  76. // Original: Y_Less
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement