/** * Compares two FileItems. * * Based on 'ustricmp' of Allegro. It makes sure that eg "foo.bar" * comes before "foo-1.bar", and also that "foo9.bar" comes before * "foo10.bar". */ int FileItem::compare(const FileItem& that) const { if (IS_FOLDER(this)) { if (!IS_FOLDER(&that)) return -1; } else if (IS_FOLDER(&that)) return 1; { int c1, c2; int x1, x2; char *t1, *t2; const char* s1 = this->displayname.c_str(); const char* s2 = that.displayname.c_str(); for (;;) { c1 = utolower(ugetxc(&s1)); c2 = utolower(ugetxc(&s2)); if ((c1 >= '0') && (c1 <= '9') && (c2 >= '0') && (c2 <= '9')) { x1 = ustrtol(s1 - ucwidth(c1), &t1, 10); x2 = ustrtol(s2 - ucwidth(c2), &t2, 10); if (x1 != x2) return x1 - x2; else if (t1 - s1 != t2 - s2) return (t2 - s2) - (t1 - s1); s1 = t1; s2 = t2; } else if (c1 != c2) { if (!c1) return -1; else if (!c2) return 1; else if (c1 == '.') return -1; else if (c2 == '.') return 1; return c1 - c2; } if (!c1) return 0; } } return -1; }
/** Renders a string. @see uaf_render_char, as this one does no more than * a series of calls to it. */ static void uaf_render(AL_CONST FONT *f, AL_CONST char *text, int fg, int bg, BITMAP *bmp, int x, int y) { AL_CONST char* p = text; int ch = 0; while( (ch = ugetxc(&p)) ) { x += f->vtable->render_char(f, ch, fg, bg, bmp, x, y); } }
/* ustrfilecmp: * ustricmp for filenames: makes sure that eg "foo.bar" comes before * "foo-1.bar", and also that "foo9.bar" comes before "foo10.bar". */ static int ustrfilecmp(AL_CONST char *s1, AL_CONST char *s2) { int c1, c2; int x1, x2; char *t1, *t2; for(;;) { c1 = utolower(ugetxc(&s1)); c2 = utolower(ugetxc(&s2)); if((c1 >= '0') && (c1 <= '9') && (c2 >= '0') && (c2 <= '9')) { x1 = ustrtol(s1 - ucwidth(c1), &t1, 10); x2 = ustrtol(s2 - ucwidth(c2), &t2, 10); if(x1 != x2) return x1 - x2; else if(t1 - s1 != t2 - s2) return (t2 - s2) - (t1 - s1); s1 = t1; s2 = t2; } else if(c1 != c2) { if(!c1) return -1; else if(!c2) return 1; else if(c1 == '.') return -1; else if(c2 == '.') return 1; return c1 - c2; } if(!c1) return 0; } }
/** Calculates a string width in pixels using char_length routine. * Copied verbatim from allegro sources, src/font.c; function length() * @param f The 'this' pointer. * @param text The text. * @return String width in pixels. */ static int uaf_text_length(AL_CONST FONT *f, AL_CONST char *text) { int ch = 0, w = 0; AL_CONST char* p = text; ASSERT(text); ASSERT(f); while( (ch = ugetxc(&p)) ) { w += f->vtable->char_length(f, ch); } return w; }