static size_t build_chat(const char *name, chat_t chat, int start, char *buffer) { size_t len, total; int i; char *p; total = Q_scnprintf(buffer, MAX_CHAT, (chat == CHAT_TEAM) ? "(%s): " : "%s: ", name); for (i = start; i < gi.argc(); i++) { p = gi.argv(i); len = strlen(p); if (!len) continue; if (total + len + 1 >= MAX_CHAT) break; while (*p) { int c = *p++; c &= 127; // strip high bits // don't allow carriage returns, etc if (!Q_isspecial(c)) buffer[total++] = c; } buffer[total++] = ' '; } buffer[total] = 0; return total; }
static size_t Com_FormatTime(char *buffer, size_t size, time_t t) { int sec, min, hour, day; sec = (int)t; min = sec / 60; sec %= 60; hour = min / 60; min %= 60; day = hour / 24; hour %= 24; if (day) { return Q_scnprintf(buffer, size, "%d+%d:%02d.%02d", day, hour, min, sec); } if (hour) { return Q_scnprintf(buffer, size, "%d:%02d.%02d", hour, min, sec); } return Q_scnprintf(buffer, size, "%02d.%02d", min, sec); }
static void BuildList( void ) { int numDirs, numDemos; void **dirlist, **demolist; char *cache, *p; unsigned flags; size_t len; int i; // this can be a lengthy process S_StopAllSounds(); m_demos.menu.status = "Building list..."; SCR_UpdateScreen(); // list files flags = ui_listalldemos->integer ? 0 : FS_TYPE_REAL | FS_PATH_GAME; dirlist = FS_ListFiles( m_demos.browse, NULL, flags | FS_SEARCH_DIRSONLY, &numDirs ); demolist = FS_ListFiles( m_demos.browse, DEMO_EXTENSIONS, flags | FS_SEARCH_EXTRAINFO, &numDemos ); // alloc entries m_demos.list.items = UI_Malloc( sizeof( demoEntry_t * ) * ( numDirs + numDemos + 1 ) ); m_demos.list.numItems = 0; m_demos.list.curvalue = 0; m_demos.list.prestep = 0; m_demos.widest_map = 3; m_demos.widest_pov = 3; m_demos.total_bytes = 0; // start with minimum size m_demos.menu.size( &m_demos.menu ); if( m_demos.browse[0] ) { BuildDir( "..", ENTRY_UP ); } // add directories if( dirlist ) { for( i = 0; i < numDirs; i++ ) { BuildDir( dirlist[i], ENTRY_DN ); } FS_FreeList( dirlist ); } m_demos.numDirs = m_demos.list.numItems; // add demos if( demolist ) { CalcHash( demolist ); if( ( cache = LoadCache( demolist ) ) != NULL ) { p = cache + 32 + 1; for( i = 0; i < numDemos; i++ ) { BuildName( demolist[i], &p ); } FS_FreeFile( cache ); } else { for( i = 0; i < numDemos; i++ ) { BuildName( demolist[i], NULL ); if( ( i & 7 ) == 0 ) { m_demos.menu.size( &m_demos.menu ); SCR_UpdateScreen(); } } } WriteCache(); FS_FreeList( demolist ); } // update status line and sort if( m_demos.list.numItems ) { Change( &m_demos.list.generic ); if( m_demos.list.sortdir ) { m_demos.list.sort( &m_demos.list, m_demos.list.sortcol ); } } // resize columns m_demos.menu.size( &m_demos.menu ); // format our extra status line i = m_demos.list.numItems - m_demos.numDirs; len = Q_scnprintf( m_demos.status, sizeof( m_demos.status ), "%d demo%s, ", i, i == 1 ? "" : "s" ); Com_FormatSizeLong( m_demos.status + len, sizeof( m_demos.status ) - len, m_demos.total_bytes ); SCR_UpdateScreen(); }
static size_t Com_Random_m(char *buffer, size_t size) { return Q_scnprintf(buffer, size, "%d", rand_byte() % 10); }