+/* here we parse "special" arguments that start with '*'
+ * '*' itself means a random 64 bit number, but this can be qualified as
+ *
+ * '*' a random 64 bit number
+ * '...%y' modulo y
+ * '.../y' align the number as an integer multiple of y (( x = (x/y)*y))
+ * '...+y' add 'y'
+ *
+ * Examples :
+ * '*' : random 64 bit number
+ * '*%1024' : random number between 0 and 1023
+ * '* /1024' : random 64 bit number aligned to n*1024
+ * '*%1024/2 : random even number between 0 and 1023
+ */
+uint64_t parse_special(const char *fmt)
+{
+ char q;
+ uint64_t num;
+ uint64_t val;
+
+ num = random();
+ num = (num <<32) | random();
+
+ fmt++;
+ while (*fmt != '\0') {
+ q = *fmt++;
+ val = strtoll(fmt, NULL, 0);
+ if (val == 0) {
+ printf("Illegal value in random number qualifier. Can not be zero\n");
+ return num;
+ }
+
+ switch (q) {
+ case '/':
+ num = (num/val)*val;
+ break;
+ case '%':
+ num = num%val;
+ break;
+ case '+':
+ num = num+val;
+ break;
+ default:
+ printf("Unknown qualifier '%c' for randum number qualifier\n", q);
+ }
+
+ /* skip until the next token */
+ while (*fmt != '\0') {
+ switch (*fmt) {
+ case '0'...'9':
+ case 'a'...'f':
+ case 'A'...'F':
+ case 'x':
+ case 'X':
+ fmt++;
+ continue;
+ }
+ break;
+ }
+ }
+
+ return num;
+}