uint8 DreamGenContext::getnumber(const Frame *charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16* offset) { uint8 totalWidth = 0; uint8 charCount = 0; while (true) { uint8 wordTotalWidth, wordCharCount; uint8 done = getnextword(charSet, string, &wordTotalWidth, &wordCharCount); string += wordCharCount; if (done == 1) { //endoftext ax = totalWidth + wordTotalWidth - 10; if (ax < maxWidth) { totalWidth += wordTotalWidth; charCount += wordCharCount; } if (centered) { ax = (maxWidth & 0xfe) + 2 + 20 - totalWidth; ax /= 2; } else { ax = 0; } *offset += ax; return charCount; } ax = totalWidth + wordTotalWidth - 10; if (ax >= maxWidth) { //gotoverend if (centered) { ax = (maxWidth & 0xfe) - totalWidth + 20; ax /= 2; } else { ax = 0; } *offset += ax; return charCount; } totalWidth += wordTotalWidth; charCount += wordCharCount; } }
//process a line at a time //this is the heart of the program //it takes a line and adds all declared variables to a binary tree //comments and strings are ignored struct tnode *processline(char *line, struct tnode *root) { while(*line != '\0' && *line != '\n') { while(isspace(*line)) //skip whitespace line++; if(ignore) line += ignoreend(line); //process if ignore should be switched to 0 else { int c = specialchar(line); //see if line has any special characters if(c == BREAK) break; else if(c == CONTINUE) { line++; continue; } if(isalnum(*line)) { line += getnextword(line); if(istype(word)) { line += getnextvar(line); if(*line == '(') { //if var is actually a function line++; while(*line != ')' && *line != '\0') line++; } else //var is a variable not a function if(var[0] != '\0') root = addtree(root, var); //add variable to binary tree } } else //if character is not alphanumeric line++; } } return root; }