Beispiel #1
0
size_t
strftime(char * const s, const size_t maxsize, const char *const format,
	 const struct tm *const t)
{
	char *	p;
	int	warn;

	tzset();
#ifdef LOCALE_HOME
	localebuf.mon[0] = 0;
#endif /* defined LOCALE_HOME */
	warn = IN_NONE;
	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
	if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
		(void) fprintf(stderr, "\n");
		if (format == NULL)
			(void) fprintf(stderr, "NULL strftime format ");
		else	(void) fprintf(stderr, "strftime format \"%s\" ",
				format);
		(void) fprintf(stderr, "yields only two digits of years in ");
		if (warn == IN_SOME)
			(void) fprintf(stderr, "some locales");
		else if (warn == IN_THIS)
			(void) fprintf(stderr, "the current locale");
		else	(void) fprintf(stderr, "all locales");
		(void) fprintf(stderr, "\n");
	}
#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
	if (p == s + maxsize)
		return 0;
	*p = '\0';
	return p - s;
}
bool CMenu::_ExitTo(void)
{
	SetupInput();
	_showExitTo();

	while(!m_exit)
	{
		_mainLoopCommon();
		if(BTN_A_PRESSED)
		{
			if(m_btnMgr.selected(m_homeBtnExitToHBC))
			{
				exitHandler(EXIT_TO_HBC);
				break;
			}
			else if(m_btnMgr.selected(m_homeBtnExitToMenu))
			{
				exitHandler(EXIT_TO_MENU);
				break;
			}
			else if(m_btnMgr.selected(m_homeBtnExitToPriiloader))
			{
				exitHandler(EXIT_TO_PRIILOADER);
				break;
			}
			else if(m_btnMgr.selected(m_homeBtnExitToBootmii))
			{
				exitHandler(EXIT_TO_BOOTMII);
				break;
			}
			else if(m_btnMgr.selected(m_homeBtnExitToNeek))
			{
				if(!Load_Neek2o_Kernel())
				{
					error(_fmt("errneek1", L"Cannot launch neek2o. Verify your neek2o setup"));
					exitHandler(PRIILOADER_DEF);
				}
				else
				{
					bool nkWiiflow = m_cfg.getBool("NEEK2O", "launchwiiflow", true);
					if(nkWiiflow)
						exitHandler(EXIT_TO_WFNK2O);
					else
						exitHandler(EXIT_TO_SMNK2O);
				}
				break;
			}
		}
		else if(BTN_HOME_PRESSED)
		{
			exitHandler(WIIFLOW_DEF);
			break;
		}
		else if(BTN_B_PRESSED)
			break;
	}
	_hideExitTo();
	return m_exit;
}
Beispiel #3
0
size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *t) {
  char *p;

  p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize);
  if (p == s + maxsize) return 0;
  *p = '\0';
  return p - s;
}
Beispiel #4
0
static void
compile_stmt(CueCodeGenerator *cg, CueAstStmt *stmt)
{
    switch (stmt->type) {
        case CUE_AST_STMT_USE:
            {
                break;
            }
        case CUE_AST_STMT_EXPR:
            {
                compile_expr(cg, stmt->v.expr.value);
                _fmt(cg, ";\n");
                break;
            }
        case CUE_AST_STMT_RET:
            {
                _fmt(cg, "return");
                if (stmt->v.ret.value) {
                    _fmt(cg, " (");
                    compile_expr(cg, stmt->v.ret.value);
                    _fmt(cg, ")");
                }
                _fmt(cg, ";\n");
                break;
            }
        case CUE_AST_STMT_FUNC_DECL:
            {
                CueListNode *node;

                _fmt(cg, "int\n"); /* TODO return types :) */
                _fmt(cg, "_%s__%s(void)", _join(cg->pool, "_", cg->ns), stmt->v.func_decl.name);
                _fmt(cg, "{\n");
                cg->indent++;
                node = stmt->v.func_decl.body->head;
                while (node != NULL) {
                    compile_stmt(cg, (CueAstStmt*)node->data);
                    node = node->next;
                }
                cg->indent--;
                _fmt(cg, "}\n\n");
                break;
            }
        default:
            fprintf(stderr, "unknown stmt type: %d\n", stmt->type);
    };
}
Beispiel #5
0
static void
compile_expr(CueCodeGenerator *cg, CueAstExpr *expr)
{
    switch (expr->type) {
        case CUE_AST_EXPR_NAME:
            {
                _fmt(cg, "%s", expr->v.name.id);
                break;
            }
        case CUE_AST_EXPR_STR:
            {
                _fmt(cg, "%s", expr->v.str.value);
                break;
            }
        case CUE_AST_EXPR_INTEGER:
            {
                _fmt(cg, "%s", expr->v.integer.value);
                break;
            }
        case CUE_AST_EXPR_BOOLEAN:
            {
                _fmt(cg, "%d", expr->v.boolean.value ? 1 : 0);
                break;
            }
        case CUE_AST_EXPR_GET_ATTR:
            {
                _fmt(cg, "(");
                compile_expr(cg, expr->v.get_attr.target);
                _fmt(cg, ")->%s", expr->v.get_attr.attr);
                break;
            }
        case CUE_AST_EXPR_CALL:
            {
                CueListNode *node = expr->v.call.args->head;
                compile_expr(cg, expr->v.call.target);
                _fmt(cg, "(");
                while (node != NULL) {
                    compile_expr(cg, (CueAstExpr*)node->data);
                    if (node->next) _fmt(cg, ", ");
                    node = node->next;
                }
                _fmt(cg, ")");
                break;
            }
    };
}
Beispiel #6
0
size_t
pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
{
	char	   *p;
	enum warn	warn = IN_NONE;

	p = _fmt(format, t, s, s + maxsize, &warn);
	if (p == s + maxsize)
		return 0;
	*p = '\0';
	return p - s;
}
Beispiel #7
0
size_t
R_strftime(char * const s, const size_t maxsize, const char *const format,
	   const stm *const t)
{
    char *p;
    R_tzset();

    p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize);
    if (p == s + maxsize)
	return 0;
    *p = '\0';
    return p - s;
}
Beispiel #8
0
size_t
pg_strftime(char *s, size_t maxsize, const char *format,
			const struct pg_tm * t)
{
	char	   *p;
	int			warn;

	warn = IN_NONE;
	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
	if (p == s + maxsize)
		return 0;
	*p = '\0';
	return p - s;
}
Beispiel #9
0
int
cue_code_generator_generate(CueCodeGenerator *cg, CueAstRoot *ast)
{
    int nsdepth = 0;
    CueList *body = ast->v.module.body;
    CueList *package = ast->v.module.package;
    CueList *package_str = cue_list_new(cg->pool);
    CueListNode *cur = cue_list_head(package);

    prelude(cg);
    while (cur != NULL) {
        CueAstExpr *name = cur->data;
        enter_namespace(cg, name->v.name.id);
        cue_list_push(package_str, name->v.name.id);
        cur = cur->next;
        nsdepth++;
    }

    _fmt(cg, "// enter package %s\n\n", _join(cg->pool, ".", package_str));

    cur = body->head;
    while (cur != NULL) {
        compile_stmt(cg, (CueAstStmt*)cur->data);
        cur = cur->next;
    }

    while (nsdepth > 0) {
        leave_namespace(cg);
        nsdepth--;
    }

    _fmt(cg, "// leave package %s\n\n", _join(cg->pool, ".", package_str));

    prologue(cg);

    return 0;
}
Beispiel #10
0
static void
_fmt_call(CueCodeGenerator *cg, const char *fn, ...)
{
    va_list args;
    const char *s;
    CueList *arglist = cue_list_new(cg->pool);

    va_start(args, fn);
    while ((s = va_arg(args, const char *)) != NULL) {
        cue_list_push(arglist, s);
    }
    va_end(args);

    _fmt(cg, "%s(%s)", fn, _join(cg->pool, ", ", arglist));
}
Beispiel #11
0
static void
prologue(CueCodeGenerator *cg)
{
    _fmt(cg, "int\n");
    _fmt(cg, "main(int argc, char **argv)\n");
    _fmt(cg, "{\n");
    _fmt(cg, "_main__main();\n");
    _fmt(cg, "return 0;\n");
    _fmt(cg, "}\n");
}
Beispiel #12
0
static void
prelude(CueCodeGenerator *cg)
{
    _fmt_include(cg, "stdio.h",  1);
    _fmt_include(cg, "stdlib.h", 1);
    _fmt_include(cg, "stdarg.h", 1);
    _fmt_include(cg, "string.h", 1);
    _fmt_include(cg, "memory.h", 1);
    _fmt(cg, "\n");

    _fmt(cg, "typedef struct _Module {\n");
    _fmt(cg, "const char *name;\n");
    _fmt(cg, "} Module;\n\n");

    enter_namespace(cg, "sys");
    {
        enter_func_decl(cg, "printf", "void", "const char *", "...", NULL);
        {
            _fmt(cg, "va_list args;\n");
            _fmt(cg, "va_start(args, arg0);\n");
            _fmt(cg, "vprintf(arg0, args);\n");
            _fmt(cg, "va_end(args);\n");
        }
        leave_func_decl(cg);
        enter_func_decl(cg, "println", "void", "const char *", NULL);
        {
            _fmt(cg, "printf(\"%%s\\n\", arg0);\n");
            /* TODO add this back in when we generate fwd decls */
            /* _fmt(cg, "(sys)->printf(\"%%s\\n\", arg0);\n"); */
        }
        leave_func_decl(cg);
    }
    leave_namespace(cg);

    implement_builtin_module(cg, &sys);
}
Beispiel #13
0
size_t
strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t)
{
    char *	p;
    int	warn;

    //tzset();

    warn = IN_NONE;
    p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);

    if (p == s + maxsize) {
        if (maxsize > 0)
            s[maxsize - 1] = '\0';
        return 0;
    }
    *p = '\0';
    return p - s;
}
Beispiel #14
0
_CRTIMP size_t __cdecl strftime(char *s, size_t maxsize, const char * format,
	const struct tm * t)
#endif
{
	char *	p;
	int	warn;

	//tzset();

	warn = IN_NONE;
	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);

	if (p == s + maxsize) {
		if (maxsize > 0)
			s[maxsize - 1] = '\0';
		return 0;
	}
	*p = '\0';
	return p - s;
}
Beispiel #15
0
size_t
strftime(char *s, size_t maxsize, const char *format, const struct tm *t)
{
	char *	p;
	int	warn;

	tzset();
#ifdef LOCALE_HOME
	localebuf.mon[0] = 0;
#endif /* defined LOCALE_HOME */
	warn = IN_NONE;
	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
	if (p == s + maxsize) {
		if (maxsize > 0)
			s[maxsize - 1] = '\0';
		return 0;
	}
	*p = '\0';
	return p - s;
}
Beispiel #16
0
void systemMessage(int id, const char* fmt, ...)
{
	static char* buf = NULL;
	static int buflen = 80;
	va_list args;
	// auto-conversion of wxCharBuffer to const char * seems broken
	// so save underlying wxCharBuffer (or create one of none is used)
	wxCharBuffer _fmt(wxString(wxGetTranslation(wxString(fmt, wxConvLibc))).utf8_str());

	if (!buf)
	{
		buf = (char*)malloc(buflen);

		if (!buf)
			exit(1);
	}

	while (1)
	{
		va_start(args, fmt);
		int needsz = vsnprintf(buf, buflen, _fmt.data(), args);
		va_end(args);

		if (needsz < buflen)
			break;

		while (buflen <= needsz)
			buflen *= 2;

		free(buf);
		buf = (char*)malloc(buflen);

		if (!buf)
			exit(1);
	}

	wxLogError(wxT("%s"), wxString(buf, wxConvLibc).c_str());
}
Beispiel #17
0
static void
enter_func_decl(CueCodeGenerator *cg, const char *name, const char *return_type, ...)
{
    va_list args;
    int nargs;
    int i;
    const char *arg_type;

    va_start(args, return_type);
    nargs = 0;
    while ((arg_type = va_arg(args, const char *)) != NULL) {
        nargs++;
    }
    va_end(args);

    va_start(args, return_type);
    _fmt(cg, "%s\n", return_type);
    _fmt(cg, "_%s__%s(", _join(cg->pool, "_", cg->ns), name);
    i = 0;
    while ((arg_type = va_arg(args, const char *)) != NULL) {
        char buf[4096];
        sprintf(buf, "arg%d", i++);
        if (strcmp(arg_type, "...") != 0) {
            _fmt(cg, "%s %s", arg_type, buf);
        }
        else {
            _fmt(cg, "...");
        }
        if (i < nargs) _fmt(cg, ", ");
    }
    va_end(args);
    _fmt(cg, ")\n");
    _fmt(cg, "{\n");

    cg->indent++;
}
void CMenu::_textGameInfo(void)
{
	cnt_controlsreq = 0;
	cnt_controls = 0;

	GameTDB m_gametdb;
	m_gametdb.OpenFile(sfmt("%s/wiitdb.xml", m_settingsDir.c_str()).c_str());
	m_gametdb.SetLanguageCode(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str());

	titlecheck = m_gametdb.IsLoaded() && m_gametdb.GetGameXMLInfo(m_cf.getId().c_str(), &gameinfo);
	if(titlecheck)
	{
		gprintf("ID: %s\nTitle: %s\n", gameinfo.GameID.c_str(), gameinfo.Title.c_str());
		m_btnMgr.setText(m_gameinfoLblID, wfmt(L"%s", gameinfo.GameID.c_str()), true);
		m_btnMgr.setText(m_gameinfoLblTitle, wfmt(L"%s", gameinfo.Title.c_str()), true);
		m_btnMgr.setText(m_gameinfoLblSynopsis, wfmt(L"%s", gameinfo.Synopsis.c_str()));
		m_btnMgr.setText(m_gameinfoLblDev, wfmt(_fmt("gameinfo1",L"Developer: %s"), gameinfo.Developer.c_str()), true);
		m_btnMgr.setText(m_gameinfoLblPublisher, wfmt(_fmt("gameinfo2",L"Publisher: %s"), gameinfo.Publisher.c_str()), true);
		m_btnMgr.setText(m_gameinfoLblRegion, wfmt(_fmt("gameinfo3",L"Region: %s"), gameinfo.Region.c_str()), true);

		m_btnMgr.setText(m_gameinfoLblGenre, wfmt(_fmt("gameinfo5",L"Genre: %s"), gameinfo.Genres.c_str()), true);

		int year = gameinfo.PublishDate >> 16;
		int day = gameinfo.PublishDate & 0xFF;
		int month = (gameinfo.PublishDate >> 8) & 0xFF;

		switch(CONF_GetRegion())
		{
			case 0:
			case 4:
			case 5:
				m_btnMgr.setText(m_gameinfoLblRlsdate, wfmt(_fmt("gameinfo4",L"Release Date: %i-%i-%i"), year, month, day), true);
				break;
			case 1:
				m_btnMgr.setText(m_gameinfoLblRlsdate, wfmt(_fmt("gameinfo4",L"Release Date: %i-%i-%i"), month, day, year), true);
				break;
			case 2:
				m_btnMgr.setText(m_gameinfoLblRlsdate, wfmt(_fmt("gameinfo4",L"Release Date: %i-%i-%i"), day, month, year), true);
				break;
		}

		//Ratings
		switch(gameinfo.RatingType)
		{
			case 0:
				//CERO
				if (gameinfo.RatingValue == "A")
					m_rating.fromPNG(cero_a_png);
				else if (gameinfo.RatingValue == "B")
					m_rating.fromPNG(cero_b_png);
				else if (gameinfo.RatingValue == "D")
					m_rating.fromPNG(cero_d_png);
				else if (gameinfo.RatingValue == "C")
					m_rating.fromPNG(cero_c_png);
				else if (gameinfo.RatingValue == "Z")
					m_rating.fromPNG(cero_z_png);
				else
					m_rating.fromPNG(norating_png);
				break;
			case 1:
				//ESRB
				if (gameinfo.RatingValue == "AO")
					m_rating.fromPNG(esrb_ao_png);
				else if (gameinfo.RatingValue == "E")
					m_rating.fromPNG(esrb_e_png);
				else if (gameinfo.RatingValue == "EC")
					m_rating.fromPNG(esrb_ec_png);
				else if (gameinfo.RatingValue == "E10+")
					m_rating.fromPNG(esrb_eten_png);
				else if (gameinfo.RatingValue == "T")
					m_rating.fromPNG(esrb_t_png);
				else if (gameinfo.RatingValue == "M")
					m_rating.fromPNG(esrb_m_png);
				else
					m_rating.fromPNG(norating_png);
				break;
			case 2:
				//PEGI
				if (gameinfo.RatingValue == "3")
					m_rating.fromPNG(pegi_3_png);
				else if (gameinfo.RatingValue == "7")
					m_rating.fromPNG(pegi_7_png);
				else if (gameinfo.RatingValue == "12")
					m_rating.fromPNG(pegi_12_png);
				else if (gameinfo.RatingValue == "16")
					m_rating.fromPNG(pegi_16_png);
				else if (gameinfo.RatingValue == "18")
					m_rating.fromPNG(pegi_18_png);
				else
					m_rating.fromPNG(norating_png);
				break;
			default:
				break;
		}

		m_btnMgr.setTexture(m_gameinfoLblRating, m_rating);

		//Wifi players
		STexture emptyTex;
		if (gameinfo.WifiPlayers == 1)
			m_wifi.fromPNG(wifi1_png);
		else if (gameinfo.WifiPlayers == 2)
			m_wifi.fromPNG(wifi2_png);
		else if (gameinfo.WifiPlayers == 4)
			m_wifi.fromPNG(wifi4_png);
		else if (gameinfo.WifiPlayers == 8)
			m_wifi.fromPNG(wifi8_png);
		else if (gameinfo.WifiPlayers == 10)
			m_wifi.fromPNG(wifi10_png);
		else if (gameinfo.WifiPlayers == 12)
			m_wifi.fromPNG(wifi12_png);
		else if (gameinfo.WifiPlayers == 16)
			m_wifi.fromPNG(wifi16_png);
		else if (gameinfo.WifiPlayers == 18)
			m_wifi.fromPNG(wifi18_png);
		else if (gameinfo.WifiPlayers == 32)
			m_wifi.fromPNG(wifi32_png);

		m_btnMgr.setTexture(m_gameinfoLblWifiplayers, gameinfo.WifiPlayers > 0 ? m_wifi : emptyTex);

		u8	wiimote = 0,
			nunchuk = 0,
			classiccontroller = 0,
			balanceboard = 0,
			dancepad = 0,
			guitar = 0,
			gamecube = 0,
			motionplus = 0,
			drums = 0,
			microphone = 0,
			wheel = 0,
			keyboard = 0,
			zapper = 0,
			x = 0;

		//check required controlls
		for (vector<Accessory>::iterator acc_itr = gameinfo.Accessories.begin(); acc_itr != gameinfo.Accessories.end(); acc_itr++)
		{
			if (!acc_itr->Required) continue;

			if (strcmp((acc_itr->Name).c_str(), "wiimote") == 0)
				wiimote = 1;
			else if (strcmp((acc_itr->Name).c_str(), "nunchuk") == 0)
				nunchuk = 1;
			else if (strcmp((acc_itr->Name).c_str(), "guitar") == 0)
				guitar = 1;
			else if (strcmp((acc_itr->Name).c_str(), "drums") == 0)
				drums = 1;
			else if (strcmp((acc_itr->Name).c_str(), "dancepad") == 0)
				dancepad = 1;
			else if (strcmp((acc_itr->Name).c_str(), "motionplus") == 0)
				motionplus = 1;
			else if (strcmp((acc_itr->Name).c_str(), "microphone") == 0)
				microphone = 1;
			else if (strcmp((acc_itr->Name).c_str(), "balanceboard") == 0)
				balanceboard = 1;
			else if (strcmp((acc_itr->Name).c_str(), "keyboard") == 0)
				keyboard = 1;
		}

		u8 max_controlsReq = ARRAY_SIZE(m_gameinfoLblControlsReq);

		if(wiimote && x < max_controlsReq)
		{
			u8 players = gameinfo.Players;
			if (gameinfo.Players >= 10)
				players = players/10;

			if (players == 1)
				m_controlsreq[x].fromPNG(wiimote1_png);
			else if (players == 2)
				m_controlsreq[x].fromPNG(wiimote2_png);
			else if (players == 3)
				m_controlsreq[x].fromPNG(wiimote3_png);
			else if (players == 4)
				m_controlsreq[x].fromPNG(wiimote4_png);
			else if (players == 8)
				m_controlsreq[x].fromPNG(wiimote8_png);

			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 20, 60);
			x++;
		}
		if(nunchuk && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(nunchukR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(guitar && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(guitarR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(drums && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(drumsR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(motionplus && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(motionplusR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 20, 60);
			x++;
		}
		if(dancepad && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(dancepadR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(microphone && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(microphoneR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(balanceboard && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(balanceboardR_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}
		if(keyboard && x < max_controlsReq)
		{
			m_controlsreq[x].fromPNG(keyboard_png);
			m_btnMgr.setTexture(m_gameinfoLblControlsReq[x] ,m_controlsreq[x], 52, 60);
			x++;
		}

		cnt_controlsreq = x;

		//for(unsigned int i = 0;i<ARRAY_SIZE(m_gameinfoLblControlsReq);i++)
			//m_btnMgr.setTexture(m_gameinfoLblControlsReq[i] ,m_controlsreq[i]);

		//check optional controlls
		wiimote=0,
		nunchuk=0,
		classiccontroller = 0,
		balanceboard = 0,
		dancepad = 0,
		guitar = 0,
		gamecube = 0,
		motionplus = 0,
		drums = 0,
		microphone = 0,
		wheel = 0,
		keyboard = 0,
		zapper = 0,
		x = 0;

		for (vector<Accessory>::iterator acc_itr = gameinfo.Accessories.begin(); acc_itr != gameinfo.Accessories.end(); acc_itr++)
		{
			if (acc_itr->Required) continue;

			if (strcmp((acc_itr->Name).c_str(), "classiccontroller") == 0)
				classiccontroller = 1;
			else if (strcmp((acc_itr->Name).c_str(), "nunchuk") == 0)
				nunchuk = 1;
			else if (strcmp((acc_itr->Name).c_str(), "guitar") == 0)
				guitar = 1;
			else if (strcmp((acc_itr->Name).c_str(), "drums") == 0)
				drums = 1;
			else if (strcmp((acc_itr->Name).c_str(), "dancepad") == 0)
				dancepad = 1;
			else if (strcmp((acc_itr->Name).c_str(), "motionplus") == 0)
				motionplus = 1;
			else if (strcmp((acc_itr->Name).c_str(), "balanceboard") == 0)
				balanceboard = 1;
			else if (strcmp((acc_itr->Name).c_str(), "microphone") == 0)
				microphone = 1;
			else if (strcmp((acc_itr->Name).c_str(), "gamecube") == 0)
				gamecube = 1;
			else if (strcmp((acc_itr->Name).c_str(), "zapper") == 0)
				zapper = 1;
			else if (strcmp((acc_itr->Name).c_str(), "wheel") == 0)
				wheel = 1;
			else if (strcmp((acc_itr->Name).c_str(), "keyboard") == 0)
				keyboard = 1;
 		}

		x = 0;
		u8 max_controls = ARRAY_SIZE(m_gameinfoLblControls);

		if(classiccontroller && x < max_controls)
		{
			m_controls[x].fromPNG(classiccontroller_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(nunchuk && x < max_controls)
		{
			m_controls[x].fromPNG(nunchuk_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(guitar && x < max_controls)
		{
			m_controls[x].fromPNG(guitar_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(drums && x < max_controls)
		{
			m_controls[x].fromPNG(drums_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(dancepad && x < max_controls)
		{
			m_controls[x].fromPNG(dancepad_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(motionplus && x < max_controls)
		{
			m_controls[x].fromPNG(motionplus_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 20, 60);
			x++;
		}
		if(balanceboard && x < max_controls)
		{
			m_controls[x].fromPNG(balanceboard_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(microphone && x < max_controls)
		{
			m_controls[x].fromPNG(microphone_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 48, 60);
			x++;
		}
		if(gamecube && x < max_controls)
		{
			m_controls[x].fromPNG(gcncontroller_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 48, 60);
			x++;
		}
		if(wheel && x < max_controls)
		{
			m_controls[x].fromPNG(wheel_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(keyboard && x < max_controls)
		{
			m_controls[x].fromPNG(keyboard_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}
		if(zapper && x < max_controls)
		{
			m_controls[x].fromPNG(zapper_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 70);
			x++;
		}
		if(microphone && x < max_controls)
		{
			m_controls[x].fromPNG(microphone_png);
			m_btnMgr.setTexture(m_gameinfoLblControls[x] ,m_controls[x], 52, 60);
			x++;
		}

		cnt_controls = x;
		//for(unsigned int i = 0;i<ARRAY_SIZE(m_gameinfoLblControls);i++)
			//m_btnMgr.setTexture(m_gameinfoLblControls[i] ,m_controls[i]);
	}
	else
Beispiel #19
0
static char *_fmt(const char *format, const struct tm *t, char *pt, const char *ptlim) {
  for ( ; *format; ++format) {
    if (*format == '%') {
      if (*format == 'E') {
        format++; // Alternate Era
      } else if (*format == 'O') {
        format++; // Alternate numeric symbols
      }

      switch (*++format) {
        case '\0':
          --format;
          break;

        case 'A':
          pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? "?" : _days[t->tm_wday], pt, ptlim);
          continue;

        case 'a':
          pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? "?" : _days_abbrev[t->tm_wday], pt, ptlim);
          continue;

        case 'B':
          pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? "?" : _months[t->tm_mon], pt, ptlim);
          continue;

        case 'b':
        case 'h':
          pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? "?" : _months_abbrev[t->tm_mon], pt, ptlim);
          continue;

        case 'C':
          pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, "%02d", pt, ptlim);
          continue;

        case 'c':
          pt = _fmt("%a %b %e %H:%M:%S %Y", t, pt, ptlim);
          continue;

        case 'D':
          pt = _fmt("%m/%d/%y", t, pt, ptlim);
          continue;

        case 'd':
          pt = _conv(t->tm_mday, "%02d", pt, ptlim);
          continue;

        case 'e':
          pt = _conv(t->tm_mday, "%2d", pt, ptlim);
          continue;

        case 'F':
          pt = _fmt("%Y-%m-%d", t, pt, ptlim);
          continue;

        case 'H':
          pt = _conv(t->tm_hour, "%02d", pt, ptlim);
          continue;

        case 'I':
          pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, "%02d", pt, ptlim);
          continue;

        case 'j':
          pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
          continue;

        case 'k':
          pt = _conv(t->tm_hour, "%2d", pt, ptlim);
          continue;

        case 'l':
          pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, "%2d", pt, ptlim);
          continue;

        case 'M':
          pt = _conv(t->tm_min, "%02d", pt, ptlim);
          continue;

        case 'm':
          pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
          continue;

        case 'n':
          pt = _add("\n", pt, ptlim);
          continue;

        case 'p':
          pt = _add((t->tm_hour >= 12) ? "pm" : "am", pt, ptlim);
          continue;

        case 'R':
          pt = _fmt("%H:%M", t, pt, ptlim);
          continue;

        case 'r':
          pt = _fmt("%I:%M:%S %p", t, pt, ptlim);
          continue;

        case 'S':
          pt = _conv(t->tm_sec, "%02d", pt, ptlim);
          continue;

        case 's': {
          struct tm  tm;
          char buf[32];
          time_t mkt;

          tm = *t;
          mkt = mktime(&tm);
          sprintf(buf, "%lu", mkt);
          pt = _add(buf, pt, ptlim);
          continue;
        }

        case 'T':
          pt = _fmt("%H:%M:%S", t, pt, ptlim);
          continue;

        case 't':
          pt = _add("\t", pt, ptlim);
          continue;

        case 'U':
          pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7, "%02d", pt, ptlim);
          continue;

        case 'u':
          pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday, "%d", pt, ptlim);
          continue;

        case 'V':   // ISO 8601 week number
        case 'G':   // ISO 8601 year (four digits)
        case 'g': { // ISO 8601 year (two digits)
          int  year;
          int  yday;
          int  wday;
          int  w;

          year = t->tm_year + TM_YEAR_BASE;
          yday = t->tm_yday;
          wday = t->tm_wday;
          while (1) {
            int  len;
            int  bot;
            int  top;

            len = LEAPYEAR(year) ? DAYSPERLYEAR : DAYSPERNYEAR;
            bot = ((yday + 11 - wday) % DAYSPERWEEK) - 3;
            top = bot - (len % DAYSPERWEEK);
            if (top < -3) top += DAYSPERWEEK;
            top += len;
            if (yday >= top) {
              ++year;
              w = 1;
              break;
            }
            if (yday >= bot) {
              w = 1 + ((yday - bot) / DAYSPERWEEK);
              break;
            }
            --year;
            yday += LEAPYEAR(year) ? DAYSPERLYEAR : DAYSPERNYEAR;
          }
          if (*format == 'V') {
            pt = _conv(w, "%02d", pt, ptlim);
          } else if (*format == 'g') {
            pt = _conv(year % 100, "%02d", pt, ptlim);
          } else {
            pt = _conv(year, "%04d", pt, ptlim);
          }
          continue;
        }

        case 'v':
          pt = _fmt("%e-%b-%Y", t, pt, ptlim);
          continue;

        case 'W':
          pt = _conv((t->tm_yday + 7 - (t->tm_wday ? (t->tm_wday - 1) : 6)) / 7, "%02d", pt, ptlim);
          continue;

        case 'w':
          pt = _conv(t->tm_wday, "%d", pt, ptlim);
          continue;

        case 'X':
          pt = _fmt("%H:%M:%S", t, pt, ptlim);
          continue;

        case 'x':
          pt = _fmt("%m/%d/%y", t, pt, ptlim);
          continue;

        case 'y':
          pt = _conv((t->tm_year + TM_YEAR_BASE) % 100, "%02d", pt, ptlim);
          continue;

        case 'Y':
          pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d", pt, ptlim);
          continue;

        case 'Z':
          pt = _add("?", pt, ptlim);
          continue;

        case 'z': {
          long absoff;
          if (_timezone >= 0) {
            absoff = _timezone;
            pt = _add("+", pt, ptlim);
          } else {
            absoff = _timezone;
            pt = _add("-", pt, ptlim);
          }
          pt = _conv(absoff / 3600, "%02d", pt, ptlim);
          pt = _conv((absoff % 3600) / 60, "%02d", pt, ptlim);

          continue;
        }

        case '+':
          pt = _fmt("%a, %d %b %Y %H:%M:%S %z", t, pt, ptlim);
          continue;

        case '%':
        default:
          break;
      }
    }

    if (pt == ptlim) break;
    *pt++ = *format;
  }

  return pt;
}
Beispiel #20
0
static void
_fmt_include(CueCodeGenerator *cg, const char *filename, int sys)
{
    _fmt(cg, "#include %c%s%c\n", sys ? '<' : '"', filename, sys ? '>' : '"');
}
Beispiel #21
0
static char *
_fmt(const char *format, const struct tm *const t, char * pt,
     const char *const ptlim, int *warnp)
{
	for ( ; *format; ++format) {
		if (*format == '%') {
label:
			switch (*++format) {
			case '\0':
				--format;
				break;
			case 'A':
				pt = _add((t->tm_wday < 0 ||
					t->tm_wday >= DAYSPERWEEK) ?
					"?" : Locale->weekday[t->tm_wday],
					pt, ptlim);
				continue;
			case 'a':
				pt = _add((t->tm_wday < 0 ||
					t->tm_wday >= DAYSPERWEEK) ?
					"?" : Locale->wday[t->tm_wday],
					pt, ptlim);
				continue;
			case 'B':
				pt = _add((t->tm_mon < 0 ||
					t->tm_mon >= MONSPERYEAR) ?
					"?" : Locale->month[t->tm_mon],
					pt, ptlim);
				continue;
			case 'b':
			case 'h':
				pt = _add((t->tm_mon < 0 ||
					t->tm_mon >= MONSPERYEAR) ?
					"?" : Locale->mon[t->tm_mon],
					pt, ptlim);
				continue;
			case 'C':
				/*
				** %C used to do a...
				**	_fmt("%a %b %e %X %Y", t);
				** ...whereas now POSIX 1003.2 calls for
				** something completely different.
				** (ado, 1993-05-24)
				*/
				pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
					pt, ptlim);
				continue;
			case 'c':
				{
				int warn2 = IN_SOME;

				pt = _fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
				if (warn2 == IN_ALL)
					warn2 = IN_THIS;
				if (warn2 > *warnp)
					*warnp = warn2;
				}
				continue;
			case 'D':
				pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
				continue;
			case 'd':
				pt = _conv(t->tm_mday, "%02d", pt, ptlim);
				continue;
			case 'E':
			case 'O':
				/*
				** C99 locale modifiers.
				** The sequences
				**	%Ec %EC %Ex %EX %Ey %EY
				**	%Od %oe %OH %OI %Om %OM
				**	%OS %Ou %OU %OV %Ow %OW %Oy
				** are supposed to provide alternate
				** representations.
				*/
				goto label;
			case 'e':
				pt = _conv(t->tm_mday, "%2d", pt, ptlim);
				continue;
			case 'F':
				pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
				continue;
			case 'H':
				pt = _conv(t->tm_hour, "%02d", pt, ptlim);
				continue;
			case 'I':
				pt = _conv((t->tm_hour % 12) ?
					(t->tm_hour % 12) : 12,
					"%02d", pt, ptlim);
				continue;
			case 'j':
				pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
				continue;
			case 'k':
				/*
				** This used to be...
				**	_conv(t->tm_hour % 12 ?
				**		t->tm_hour % 12 : 12, 2, ' ');
				** ...and has been changed to the below to
				** match SunOS 4.1.1 and Arnold Robbins'
				** strftime version 3.0. That is, "%k" and
				** "%l" have been swapped.
				** (ado, 1993-05-24)
				*/
				pt = _conv(t->tm_hour, "%2d", pt, ptlim);
				continue;
#ifdef KITCHEN_SINK
			case 'K':
				/*
				** After all this time, still unclaimed!
				*/
				pt = _add("kitchen sink", pt, ptlim);
				continue;
#endif /* defined KITCHEN_SINK */
			case 'l':
				/*
				** This used to be...
				**	_conv(t->tm_hour, 2, ' ');
				** ...and has been changed to the below to
				** match SunOS 4.1.1 and Arnold Robbin's
				** strftime version 3.0. That is, "%k" and
				** "%l" have been swapped.
				** (ado, 1993-05-24)
				*/
				pt = _conv((t->tm_hour % 12) ?
					(t->tm_hour % 12) : 12,
					"%2d", pt, ptlim);
				continue;
			case 'M':
				pt = _conv(t->tm_min, "%02d", pt, ptlim);
				continue;
			case 'm':
				pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
				continue;
			case 'n':
				pt = _add("\n", pt, ptlim);
				continue;
			case 'p':
				pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
					Locale->pm :
					Locale->am,
					pt, ptlim);
				continue;
			case 'R':
				pt = _fmt("%H:%M", t, pt, ptlim, warnp);
				continue;
			case 'r':
				pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
				continue;
			case 'S':
				pt = _conv(t->tm_sec, "%02d", pt, ptlim);
				continue;
			case 's':
				{
					struct tm	tm;
					char		buf[INT_STRLEN_MAXIMUM(
								time_t) + 1];
					time_t		mkt;

					tm = *t;
					mkt = mktime(&tm);
					if (TYPE_SIGNED(time_t))
						(void) sprintf(buf, "%"PRIdMAX,
							(intmax_t) mkt);
					else	(void) sprintf(buf, "%"PRIuMAX,
							(uintmax_t) mkt);
					pt = _add(buf, pt, ptlim);
				}
				continue;
			case 'T':
				pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
				continue;
			case 't':
				pt = _add("\t", pt, ptlim);
				continue;
			case 'U':
				pt = _conv((t->tm_yday + DAYSPERWEEK -
					t->tm_wday) / DAYSPERWEEK,
					"%02d", pt, ptlim);
				continue;
			case 'u':
				/*
				** From Arnold Robbins' strftime version 3.0:
				** "ISO 8601: Weekday as a decimal number
				** [1 (Monday) - 7]"
				** (ado, 1993-05-24)
				*/
				pt = _conv((t->tm_wday == 0) ?
					DAYSPERWEEK : t->tm_wday,
					"%d", pt, ptlim);
				continue;
			case 'V':	/* ISO 8601 week number */
			case 'G':	/* ISO 8601 year (four digits) */
			case 'g':	/* ISO 8601 year (two digits) */
/*
** From Arnold Robbins' strftime version 3.0: "the week number of the
** year (the first Monday as the first day of week 1) as a decimal number
** (01-53)."
** (ado, 1993-05-24)
**
** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
** "Week 01 of a year is per definition the first week which has the
** Thursday in this year, which is equivalent to the week which contains
** the fourth day of January. In other words, the first week of a new year
** is the week which has the majority of its days in the new year. Week 01
** might also contain days from the previous year and the week before week
** 01 of a year is the last week (52 or 53) of the previous year even if
** it contains days from the new year. A week starts with Monday (day 1)
** and ends with Sunday (day 7). For example, the first week of the year
** 1997 lasts from 1996-12-30 to 1997-01-05..."
** (ado, 1996-01-02)
*/
				{
					int	year;
					int	base;
					int	yday;
					int	wday;
					int	w;

					year = t->tm_year;
					base = TM_YEAR_BASE;
					yday = t->tm_yday;
					wday = t->tm_wday;
					for ( ; ; ) {
						int	len;
						int	bot;
						int	top;

						len = isleap_sum(year, base) ?
							DAYSPERLYEAR :
							DAYSPERNYEAR;
						/*
						** What yday (-3 ... 3) does
						** the ISO year begin on?
						*/
						bot = ((yday + 11 - wday) %
							DAYSPERWEEK) - 3;
						/*
						** What yday does the NEXT
						** ISO year begin on?
						*/
						top = bot -
							(len % DAYSPERWEEK);
						if (top < -3)
							top += DAYSPERWEEK;
						top += len;
						if (yday >= top) {
							++base;
							w = 1;
							break;
						}
						if (yday >= bot) {
							w = 1 + ((yday - bot) /
								DAYSPERWEEK);
							break;
						}
						--base;
						yday += isleap_sum(year, base) ?
							DAYSPERLYEAR :
							DAYSPERNYEAR;
					}
#ifdef XPG4_1994_04_09
					if ((w == 52 &&
						t->tm_mon == TM_JANUARY) ||
						(w == 1 &&
						t->tm_mon == TM_DECEMBER))
							w = 53;
#endif /* defined XPG4_1994_04_09 */
					if (*format == 'V')
						pt = _conv(w, "%02d",
							pt, ptlim);
					else if (*format == 'g') {
						*warnp = IN_ALL;
						pt = _yconv(year, base, 0, 1,
							pt, ptlim);
					} else	pt = _yconv(year, base, 1, 1,
							pt, ptlim);
				}
				continue;
			case 'v':
				/*
				** From Arnold Robbins' strftime version 3.0:
				** "date as dd-bbb-YYYY"
				** (ado, 1993-05-24)
				*/
				pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
				continue;
			case 'W':
				pt = _conv((t->tm_yday + DAYSPERWEEK -
					(t->tm_wday ?
					(t->tm_wday - 1) :
					(DAYSPERWEEK - 1))) / DAYSPERWEEK,
					"%02d", pt, ptlim);
				continue;
			case 'w':
				pt = _conv(t->tm_wday, "%d", pt, ptlim);
				continue;
			case 'X':
				pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
				continue;
			case 'x':
				{
				int	warn2 = IN_SOME;

				pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
				if (warn2 == IN_ALL)
					warn2 = IN_THIS;
				if (warn2 > *warnp)
					*warnp = warn2;
				}
				continue;
			case 'y':
				*warnp = IN_ALL;
				pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
					pt, ptlim);
				continue;
			case 'Y':
				pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
					pt, ptlim);
				continue;
			case 'Z':
#ifdef TM_ZONE
				if (t->TM_ZONE != NULL)
					pt = _add(t->TM_ZONE, pt, ptlim);
				else
#endif /* defined TM_ZONE */
				if (t->tm_isdst >= 0)
					pt = _add(tzname[t->tm_isdst != 0],
						pt, ptlim);
				/*
				** C99 says that %Z must be replaced by the
				** empty string if the time zone is not
				** determinable.
				*/
				continue;
			case 'z':
				{
				long		diff;
				char const *	sign;

				if (t->tm_isdst < 0)
					continue;
#ifdef TM_GMTOFF
				diff = t->TM_GMTOFF;
#else /* !defined TM_GMTOFF */
				/*
				** C99 says that the UT offset must
				** be computed by looking only at
				** tm_isdst. This requirement is
				** incorrect, since it means the code
				** must rely on magic (in this case
				** altzone and timezone), and the
				** magic might not have the correct
				** offset. Doing things correctly is
				** tricky and requires disobeying C99;
				** see GNU C strftime for details.
				** For now, punt and conform to the
				** standard, even though it's incorrect.
				**
				** C99 says that %z must be replaced by the
				** empty string if the time zone is not
				** determinable, so output nothing if the
				** appropriate variables are not available.
				*/
				if (t->tm_isdst == 0)
#ifdef USG_COMPAT
					diff = -timezone;
#else /* !defined USG_COMPAT */
					continue;
#endif /* !defined USG_COMPAT */
				else
#ifdef ALTZONE
					diff = -altzone;
#else /* !defined ALTZONE */
					continue;
#endif /* !defined ALTZONE */
#endif /* !defined TM_GMTOFF */
				if (diff < 0) {
					sign = "-";
					diff = -diff;
				} else	sign = "+";
				pt = _add(sign, pt, ptlim);
				diff /= SECSPERMIN;
				diff = (diff / MINSPERHOUR) * 100 +
					(diff % MINSPERHOUR);
				pt = _conv(diff, "%04d", pt, ptlim);
				}
				continue;
			case '+':
				pt = _fmt(Locale->date_fmt, t, pt, ptlim,
					warnp);
				continue;
			case '%':
			/*
			** X311J/88-090 (4.12.3.5): if conversion char is
			** undefined, behavior is undefined. Print out the
			** character itself as printf(3) also does.
			*/
			default:
				break;
			}
		}
Beispiel #22
0
static void
leave_func_decl(CueCodeGenerator *cg)
{
    cg->indent--;
    _fmt(cg, "}\n\n");
}
Beispiel #23
0
static void
implement_builtin_module(CueCodeGenerator *cg, const CueBuiltinModule *mod)
{
    const CueBuiltinFunc *func;

    _fmt(cg, "typedef struct _%s_Module {\n", mod->name);
    _fmt(cg, "  Module common;\n");
    func = mod->functions;
    while (func->name != NULL) {
        const char **arg_type;
        _fmt(cg, "%s (*%s)(", func->return_type, func->name);
        arg_type = func->arg_types;
        while (*arg_type != NULL) {
            _fmt(cg, "%s", *arg_type);
            arg_type++;
            if (*arg_type) _fmt(cg, ", ");
        }
        _fmt(cg, ");\n");
        func++;
    }
    _fmt(cg, "} %s_Module;\n\n", mod->name);

    _fmt(cg, "static const %s_Module %s_impl = {\n", mod->name, mod->name);
    _fmt(cg, "{ \"%s\" },\n", mod->name);
    func = mod->functions;
    while (func->name != NULL) {
        _fmt(cg, "_%s__%s", mod->name, func->name);
        func++;
        if (func->name) _fmt(cg, ",");
        _fmt(cg, "\n");
    }
    _fmt(cg, "};\n");
    _fmt(cg, "static const %s_Module *%s = &%s_impl;\n", mod->name, mod->name, mod->name);
    _fmt(cg, "\n");
}
Beispiel #24
0
static char *
_fmt(const char *format, const stm *const t, char * pt, const char *const ptlim)
{
    for ( ; *format; ++format) {
	if (*format == '%') {
	    /* Check for POSIX 2008 / GNU modifiers */
	    char pad = '\0'; const char *f; int width = -1;
	    // first look to see if this is %..Y
	    for (f = format+1; *f ; f++)
		if(! (isdigit(*f) || *f == '_' || *f == '+')) break;
	    if (*f == 'Y')  {
		while (1)
		{
		    switch (*++format) {
		    case '0':
		    case '+': // pad with zeroes, and more (not here)
		    case '_': // pad with spaces: GNU extension
			pad = *format;
			continue;
		    default:
			break;
		    }
		    break;
		}
		if (isdigit (*format))
		{
		    width = 0;
		    do
		    {
			if (width > INT_MAX / 10 || 
			    (width == INT_MAX / 10 && *format - '0' > INT_MAX % 10))
			    width = INT_MAX;
			else {width *= 10; width += *format - '0';}
			format++;
		    }
		    while (isdigit (*format));
		}
		--format;
	    }

	label:
	    switch (*++format) {
	    case '\0':
		--format;
		break;

		/* now the locale-dependent cases */
#ifdef HAVE_NL_LANGINFO
	    case 'A':
		pt = _add((t->tm_wday < 0 || t->tm_wday >= 7) ?
			  "?" : nl_langinfo(DAY_1 + t->tm_wday),
			  pt, ptlim);
		continue;
	    case 'a':
		pt = _add((t->tm_wday < 0 || t->tm_wday >= 7) ?
			  "?" : nl_langinfo(ABDAY_1 + t->tm_wday),
			  pt, ptlim);
		continue;
	    case 'B':
		pt = _add((t->tm_mon < 0 || t->tm_mon >= 12) ?
			  "?" : nl_langinfo(MON_1 + t->tm_mon),
			  pt, ptlim);
		continue;
	    case 'b':
	    case 'h':
		pt = _add((t->tm_mon < 0 || t->tm_mon >= 12) ?
			  "?" : nl_langinfo(ABMON_1 + t->tm_mon),
			  pt, ptlim);
		continue;
	    case 'c':
		pt = _fmt(nl_langinfo(D_T_FMT), t, pt, ptlim);
		continue;
	    case 'p':
		pt = _add(nl_langinfo(t->tm_hour < 12 ? AM_STR : PM_STR),
			  pt, ptlim);
		continue;
	    case 'P':
		{
		    char *p = nl_langinfo(t->tm_hour < 12 ? AM_STR : PM_STR),
			*q, buff[20];
		    for (q = buff; *p; ) *q++ = (char) tolower(*p++);
		    *q = '\0'; 
		    pt = _add(buff, pt, ptlim);
		}
		continue;
	    case 'X':
		pt = _fmt(nl_langinfo(T_FMT), t, pt, ptlim);
		continue;
	    case 'x':
		pt = _fmt(nl_langinfo(D_FMT), t, pt, ptlim);
		continue;
#else
	    case 'A':
		pt = _add((t->tm_wday < 0 || t->tm_wday >= 7) ?
			  "?" : orig("%A", t),
			  pt, ptlim);
		continue;
	    case 'a':
		pt = _add((t->tm_wday < 0 || t->tm_wday >= 7) ?
			  "?" : orig("%a", t),
			  pt, ptlim);
		continue;
	    case 'B':
		pt = _add((t->tm_mon < 0 || t->tm_mon >= 12) ?
			  "?" : orig("%B", t),
			  pt, ptlim);
		continue;
	    case 'b':
	    case 'h':
		pt = _add((t->tm_mon < 0 || t->tm_mon >= 12) ?
			  "?" : orig("%b", t),
			  pt, ptlim);
		continue;
	    case 'c':
		// In a C locale this is supposed to be
		// "%a %b %e %T %Y". It is not on Windows ....
#ifdef _WIN32
		pt = _fmt("%a %b %e %T %Y", t, pt, ptlim);
#else
		pt = _fmt(orig("%c", t), t, pt, ptlim);
#endif
		continue;
	    case 'p':
		pt = _add(orig("%p", t), pt, ptlim);
		continue;
	    case 'P':
		{
		    char *p = orig("%p", t), *q, buff[20];
		    for (q = buff; *p; ) *q++ = (char) tolower(*p++);
		    *q = '\0'; 
		    pt = _add(buff, pt, ptlim);
		}
		continue;
	    case 'X':
		pt = _fmt(orig("%X", t), t, pt, ptlim);
		continue;
	    case 'x':
		pt = _fmt(orig("%x", t), t, pt, ptlim);
		continue;
#endif
		/* now the locale-independent ones */
	    case 'C':
		pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0, pt, ptlim);
		continue;
	    case 'D':
		pt = _fmt("%m/%d/%y", t, pt, ptlim);
		continue;
	    case 'd':
		pt = _conv(t->tm_mday, "%02d", pt, ptlim);
		continue;
	    case 'E':
	    case 'O':
		/*
		** C99 locale modifiers.
		** The sequences
		**	%Ec %EC %Ex %EX %Ey %EY
		**	%Od %oe %OH %OI %Om %OM
		**	%OS %Ou %OU %OV %Ow %OW %Oy
		** are supposed to provide alternate
		** representations.
		*/
		goto label;
	    case 'e':
		pt = _conv(t->tm_mday, "%2d", pt, ptlim);
		continue;
	    case 'F':
		pt = _fmt("%Y-%m-%d", t, pt, ptlim);
		continue;
	    case 'H':
		pt = _conv(t->tm_hour, "%02d", pt, ptlim);
		continue;
	    case 'I':
		pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12,
			   "%02d", pt, ptlim);
		continue;
	    case 'j':
		pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
		continue;
	    case 'k':
		pt = _conv(t->tm_hour, "%2d", pt, ptlim);
		continue;
	    case 'l':
		pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12,
			   "%2d", pt, ptlim);
		continue;
	    case 'M':
		pt = _conv(t->tm_min, "%02d", pt, ptlim);
		continue;
	    case 'm':
		pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
		continue;
	    case 'n':
		pt = _add("\n", pt, ptlim);
		continue;
	    case 'R':
		pt = _fmt("%H:%M", t, pt, ptlim);
		continue;
	    case 'r':
		pt = _fmt("%I:%M:%S %p", t, pt, ptlim);
		continue;
	    case 'S':
		pt = _conv(t->tm_sec, "%02d", pt, ptlim);
		continue;
	    case 's':
	    {
		stm  tm = *t;
		char buf[22]; // <= 19 digs + sign + terminator
		int_fast64_t mkt = R_mktime(&tm);
#ifdef _WIN32
		// not ISO C99, so warns
		(void) snprintf(buf, 22, "%I64d", mkt);
#else
		(void) snprintf(buf, 22, "%lld", (long long) mkt);
#endif
		pt = _add(buf, pt, ptlim);
	    }
	    continue;
	    case 'T':
		pt = _fmt("%H:%M:%S", t, pt, ptlim);
		continue;
	    case 't':
		pt = _add("\t", pt, ptlim);
		continue;
	    case 'U':
		pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7,
			   "%02d", pt, ptlim);
		continue;
	    case 'u':
		pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday, "%d", pt, ptlim);
		continue;
	    case 'V':	/* ISO 8601 week number */
	    case 'G':	/* ISO 8601 year (four digits) */
	    case 'g':	/* ISO 8601 year (two digits) */
	    {
		int year, base, yday, wday, w;

		year = t->tm_year;
		base = TM_YEAR_BASE;
		yday = t->tm_yday;
		wday = t->tm_wday;
		for ( ; ; ) {
		    int	len, bot, top;

		    len = isleap_sum(year, base) ? DAYSPERLYEAR : DAYSPERNYEAR;
		    /*
		    ** What yday (-3 ... 3) does
		    ** the ISO year begin on?
		    */
		    bot = ((yday + 11 - wday) % 7) - 3;
		    /*
		    ** What yday does the NEXT
		    ** ISO year begin on?
		    */
		    top = bot - (len % 7);
		    if (top < -3)
			top += 7;
		    top += len;
		    if (yday >= top) {
			++base;
			w = 1;
			break;
		    }
		    if (yday >= bot) {
			w = 1 + ((yday - bot) / 7);
			break;
		    }
		    --base;
		    yday += isleap_sum(year, base) ? DAYSPERLYEAR : DAYSPERNYEAR;
		}
		if (*format == 'V')
		    pt = _conv(w, "%02d", pt, ptlim);
		else if (*format == 'g')
		    pt = _yconv(year, base, 0, 1, pt, ptlim);
		else // %G
		    pt = _yconv(year, base, 1, 1, pt, ptlim);
	    }
	    continue;
	    case 'v':
		pt = _fmt("%e-%b-%Y", t, pt, ptlim);
		continue;
	    case 'W':
		pt = _conv((t->tm_yday + 7 -
			    (t->tm_wday ? (t->tm_wday - 1) : (7 - 1))) / 7,
			   "%02d", pt, ptlim);
		continue;
	    case 'w':
		pt = _conv(t->tm_wday, "%d", pt, ptlim);
		continue;
	    case 'y':
		pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1, pt, ptlim);
		continue;
	    case 'Y':
//		pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1, pt, ptlim);
	    {
		char buf[20] = "%";
		int year = TM_YEAR_BASE + t->tm_year;
		if (pad == '\0') { pad = '0'; width = 4;}
		if (pad == '0' || pad == '+') strcat(buf, "0");
		if (width > 0) sprintf(buf+strlen(buf), "%u", width);
		if (pad == '+' && year > 9999) strcat(buf, "+");
		strcat(buf, "d");
		pt = _conv(year, buf, pt, ptlim);
	    }
	    continue;
	    case 'Z':
#ifdef HAVE_TM_ZONE
		if (t->tm_zone != NULL)
		    pt = _add(t->tm_zone, pt, ptlim);
		else
#endif
		if (t->tm_isdst >= 0)
		    pt = _add(R_tzname[t->tm_isdst != 0], pt, ptlim);
		/*
		** C99 says that %Z must be replaced by the
		** empty string if the time zone is not
		** determinable.
		*/
		continue;
	    case 'z':
	    {
		long  diff;
		char const *sign;

		if (t->tm_isdst < 0)
		    continue;
#ifdef HAVE_TM_GMTOFF
		diff = t->tm_gmtoff;
#else
		diff = R_timegm(t) - R_mktime(t);
#endif
		if (diff < 0) {
		    sign = "-";
		    diff = -diff;
		} else	sign = "+";
		pt = _add(sign, pt, ptlim);
		diff /= SECSPERMIN;
		diff = (diff / MINSPERHOUR) * 100 + (diff % MINSPERHOUR);
		pt = _conv((int) diff, "%04d", pt, ptlim);
	    }
	    continue;
	    case '+':
		pt = _fmt("%a %b %e %H:%M:%S %Z %Y", t, pt, ptlim);
		continue;
	    case '%':
	    default:
		break;
	    }
	}
	if (pt == ptlim)
	    break;
	*pt++ = *format;
    }
    return pt;
}
Beispiel #25
0
static char *
_fmt(const char *format, const struct tm *t, char *pt,
     const char *ptlim)
{
    int Ealternative, Oalternative, PadIndex;
#ifdef __ORCAC__
#define tptr (&_C_time_locale)
#else
    struct lc_time_T *tptr = __get_current_time_locale(__get_locale());
#endif

    for ( ; *format; ++format) {
        if (*format == '%') {
            Ealternative = 0;
            Oalternative = 0;
            PadIndex	 = PAD_DEFAULT;
label:
            switch (*++format) {
            case '\0':
                --format;
                break;
            case 'A':
                pt = _add((t->tm_wday < 0 || t->tm_wday >= DAYSPERWEEK) ?
                          "?" : tptr->weekday[t->tm_wday],
                          pt, ptlim);
                continue;
            case 'a':
                pt = _add((t->tm_wday < 0 || t->tm_wday >= DAYSPERWEEK) ?
                          "?" : tptr->wday[t->tm_wday],
                          pt, ptlim);
                continue;
            case 'B':
                pt = _add((t->tm_mon < 0 ||
                           t->tm_mon >= MONSPERYEAR) ?
                          "?" : (Oalternative ? tptr->alt_month :
                                 tptr->month)[t->tm_mon],
                          pt, ptlim);
                continue;

                continue;
            case 'b':
            case 'h':
                pt = _add((t->tm_mon < 0 || t->tm_mon >= MONSPERYEAR) ?
                          "?" : tptr->mon[t->tm_mon],
                          pt, ptlim);
                continue;
            case 'C':
                /*
                 * %C used to do a...
                 *	_fmt("%a %b %e %X %Y", t);
                 * ...whereas now POSIX 1003.2 calls for
                 * something completely different.
                 * (ado, 1993-05-24)
                 */
                pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
                            pt, ptlim);
                continue;
            case 'c':
                pt = _fmt(tptr->c_fmt, t, pt, ptlim);
                continue;
            case 'D':
                pt = _fmt("%m/%d/%y", t, pt, ptlim);
                continue;
            case 'd':
                pt = _conv(t->tm_mday,
                           fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex],
                           pt, ptlim);
                continue;
            case 'E':
                if (Ealternative || Oalternative)
                    break;
                Ealternative++;
                goto label;
            case 'O':
                /*
                 * C99 locale modifiers.
                 * The sequences
                 *	%Ec %EC %Ex %EX %Ey %EY
                 *	%Od %oe %OH %OI %Om %OM
                 *	%OS %Ou %OU %OV %Ow %OW %Oy
                 * are supposed to provide alternate
                 * representations.
                 *
                 * FreeBSD extension
                 *      %OB
                 */
                if (Ealternative || Oalternative)
                    break;
                Oalternative++;
                goto label;
            case 'e':
                pt = _conv(t->tm_mday,
                           fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex],
                           pt, ptlim);
                continue;
            case 'F':
                pt = _fmt("%Y-%m-%d", t, pt, ptlim);
                continue;
            case 'H':
                pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_HMS][PadIndex],
                           pt, ptlim);
                continue;
            case 'I':
                pt = _conv((t->tm_hour % 12) ?
                           (t->tm_hour % 12) : 12,
                           fmt_padding[PAD_FMT_HMS][PadIndex],
                           pt, ptlim);
                continue;
            case 'j':
                pt = _conv(t->tm_yday + 1,
                           fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex],
                           pt, ptlim);
                continue;
            case 'k':
                /*
                 * This used to be...
                 *	_conv(t->tm_hour % 12 ?
                 *		t->tm_hour % 12 : 12, 2, ' ');
                 * ...and has been changed to the below to
                 * match SunOS 4.1.1 and Arnold Robbins'
                 * strftime version 3.0. That is, "%k" and
                 * "%l" have been swapped.
                 * (ado, 1993-05-24)
                 */
                pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_SHMS][PadIndex],
                           pt, ptlim);
                continue;
#ifdef KITCHEN_SINK
            case 'K':
                /*
                ** After all this time, still unclaimed!
                */
                pt = _add("kitchen sink", pt, ptlim);
                continue;
#endif /* defined KITCHEN_SINK */
            case 'l':
                /*
                 * This used to be...
                 *	_conv(t->tm_hour, 2, ' ');
                 * ...and has been changed to the below to
                 * match SunOS 4.1.1 and Arnold Robbin's
                 * strftime version 3.0. That is, "%k" and
                 * "%l" have been swapped.
                 * (ado, 1993-05-24)
                 */
                pt = _conv((t->tm_hour % 12) ?
                           (t->tm_hour % 12) : 12,
                           fmt_padding[PAD_FMT_SHMS][PadIndex],
                           pt, ptlim);
                continue;
            case 'M':
                pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex],
                           pt, ptlim);
                continue;
            case 'm':
                pt = _conv(t->tm_mon + 1,
                           fmt_padding[PAD_FMT_MONTH][PadIndex],
                           pt, ptlim);
                continue;
            case 'n':
                pt = _add("\n", pt, ptlim);
                continue;
            case 'p':
                pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
                          tptr->pm : tptr->am,
                          pt, ptlim);
                continue;
            case 'R':
                pt = _fmt("%H:%M", t, pt, ptlim);
                continue;
            case 'r':
                pt = _fmt(tptr->ampm_fmt, t, pt, ptlim);
                continue;
            case 'S':
                pt = _conv(t->tm_sec, fmt_padding[PAD_FMT_HMS][PadIndex],
                           pt, ptlim);
                continue;
            case 's':
                pt = _secs(t, pt, ptlim);
                continue;
            case 'T':
                pt = _fmt("%H:%M:%S", t, pt, ptlim);
                continue;
            case 't':
                pt = _add("\t", pt, ptlim);
                continue;
            case 'U':
                pt = _conv((t->tm_yday + DAYSPERWEEK -
                            t->tm_wday) / DAYSPERWEEK,
                           fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
                           pt, ptlim);
                continue;
            case 'u':
                /*
                 * From Arnold Robbins' strftime version 3.0:
                 * "ISO 8601: Weekday as a decimal number
                 * [1 (Monday) - 7]"
                 * (ado, 1993-05-24)
                 */
                pt = _conv((t->tm_wday == 0) ?
                           DAYSPERWEEK : t->tm_wday,
                           "%d", pt, ptlim);
                continue;
            case 'V':	/* ISO 8601 week number */
            case 'G':	/* ISO 8601 year (four digits) */
            case 'g':	/* ISO 8601 year (two digits) */
                /*
                 * From Arnold Robbins' strftime version 3.0: "the week number of the
                 * year (the first Monday as the first day of week 1) as a decimal number
                 * (01-53)."
                 * (ado, 1993-05-24)
                 *
                 * From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
                 * "Week 01 of a year is per definition the first week which has the
                 * Thursday in this year, which is equivalent to the week which contains
                 * the fourth day of January. In other words, the first week of a new year
                 * is the week which has the majority of its days in the new year. Week 01
                 * might also contain days from the previous year and the week before week
                 * 01 of a year is the last week (52 or 53) of the previous year even if
                 * it contains days from the new year. A week starts with Monday (day 1)
                 * and ends with Sunday (day 7). For example, the first week of the year
                 * 1997 lasts from 1996-12-30 to 1997-01-05..."
                 * (ado, 1996-01-02)
                 */
            {
                int	year;
                int	base;
                int	yday;
                int	wday;
                int	w;

                year = t->tm_year;
                base = TM_YEAR_BASE;
                yday = t->tm_yday;
                wday = t->tm_wday;
                for ( ; ; ) {
                    int	len;
                    int	bot;
                    int	top;

                    len = isleap_sum(year, base) ?
                          DAYSPERLYEAR :
                          DAYSPERNYEAR;
                    /*
                     * What yday (-3 ... 3) does
                     * the ISO year begin on?
                     */
                    bot = ((yday + 11 - wday) %
                           DAYSPERWEEK) - 3;
                    /*
                     * What yday does the NEXT
                     * ISO year begin on?
                     */
                    top = bot -
                          (len % DAYSPERWEEK);
                    if (top < -3)
                        top += DAYSPERWEEK;
                    top += len;
                    if (yday >= top) {
                        ++base;
                        w = 1;
                        break;
                    }
                    if (yday >= bot) {
                        w = 1 + ((yday - bot) /
                                 DAYSPERWEEK);
                        break;
                    }
                    --base;
                    yday += isleap_sum(year, base) ?
                            DAYSPERLYEAR :
                            DAYSPERNYEAR;
                }
#ifdef XPG4_1994_04_09
                if ((w == 52 &&
                        t->tm_mon == TM_JANUARY) ||
                        (w == 1 &&
                         t->tm_mon == TM_DECEMBER))
                    w = 53;
#endif /* defined XPG4_1994_04_09 */
                if (*format == 'V')
                    pt = _conv(w, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
                               pt, ptlim);
                else if (*format == 'g') {
                    pt = _yconv(year, base, 0, 1,
                                pt, ptlim);
                } else	pt = _yconv(year, base, 1, 1,
                                        pt, ptlim);
            }
            continue;
            case 'v':
                /*
                 * From Arnold Robbins' strftime version 3.0:
                 * "date as dd-bbb-YYYY"
                 * (ado, 1993-05-24)
                 */
                pt = _fmt("%e-%b-%Y", t, pt, ptlim);
                continue;
            case 'W':
                pt = _conv((t->tm_yday + DAYSPERWEEK -
                            (t->tm_wday ?
                             (t->tm_wday - 1) :
                             (DAYSPERWEEK - 1))) / DAYSPERWEEK,
                           fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
                           pt, ptlim);
                continue;
            case 'w':
                pt = _conv(t->tm_wday, "%d", pt, ptlim);
                continue;
            case 'X':
                pt = _fmt(tptr->X_fmt, t, pt, ptlim);
                continue;
            case 'x':
                pt = _fmt(tptr->x_fmt, t, pt, ptlim);
                continue;
            case 'y':
                pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
                            pt, ptlim);
                continue;
            case 'Y':
                pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
                            pt, ptlim);
                continue;
            case 'Z':
#ifdef TM_ZONE
                if (t->TM_ZONE != NULL)
                    pt = _add(t->TM_ZONE, pt, ptlim);
                else
#endif /* defined TM_ZONE */
                    if (t->tm_isdst >= 0)
                        pt = _add(tzname[t->tm_isdst != 0],
                                  pt, ptlim);
                /*
                 * C99 says that %Z must be replaced by the
                 * empty string if the time zone is not
                 * determinable.
                 */
                continue;
            case 'z':
            {
                int		diff;
                char const *	sign;

                if (t->tm_isdst < 0)
                    continue;
#ifdef TM_GMTOFF
                diff = t->TM_GMTOFF;
#else /* !defined TM_GMTOFF */
                /*
                 * C99 says that the UTC offset must
                 * be computed by looking only at
                 * tm_isdst. This requirement is
                 * incorrect, since it means the code
                 * must rely on magic (in this case
                 * altzone and timezone), and the
                 * magic might not have the correct
                 * offset. Doing things correctly is
                 * tricky and requires disobeying C99;
                 * see GNU C strftime for details.
                 * For now, punt and conform to the
                 * standard, even though it's incorrect.
                 *
                 * C99 says that %z must be replaced by the
                 * empty string if the time zone is not
                 * determinable, so output nothing if the
                 * appropriate variables are not available.
                 */
                if (t->tm_isdst == 0)
#ifdef USG_COMPAT
                    diff = -timezone;
#else /* !defined USG_COMPAT */
                    continue;
#endif /* !defined USG_COMPAT */
                else
#ifdef ALTZONE
                    diff = -altzone;
#else /* !defined ALTZONE */
                    continue;
#endif /* !defined ALTZONE */
#endif /* !defined TM_GMTOFF */
                if (diff < 0) {
                    sign = "-";
                    diff = -diff;
                } else
                    sign = "+";
                pt = _add(sign, pt, ptlim);
                diff /= SECSPERMIN;
                diff = (diff / MINSPERHOUR) * 100 +
                       (diff % MINSPERHOUR);
                pt = _conv(diff,
                           fmt_padding[PAD_FMT_YEAR][PadIndex],
                           pt, ptlim);
            }
            continue;
            case '+':
                pt = _fmt(tptr->date_fmt, t, pt, ptlim);
                continue;
            case '-':
                if (PadIndex != PAD_DEFAULT)
                    break;
                PadIndex = PAD_LESS;
                goto label;
            case '_':
                if (PadIndex != PAD_DEFAULT)
                    break;
                PadIndex = PAD_SPACE;
                goto label;
            case '0':
                if (PadIndex != PAD_DEFAULT)
                    break;
                PadIndex = PAD_ZERO;
                goto label;
            case '%':
            /*
             * X311J/88-090 (4.12.3.5): if conversion char is
             * undefined, behavior is undefined. Print out the
             * character itself as printf(3) also does.
             */
            default:
                break;
            }
        }
Beispiel #26
0
static char *
_fmt(const char * format, const struct tm * const t, char * pt, const char * const ptlim, int * warnp)
{
    for ( ; *format; ++format) {
        if (*format == '%') {
label:
            switch (*++format) {
            case '\0':
                --format;
                break;
            case 'A':
                pt = _add((t->tm_wday < 0 ||
                           t->tm_wday >= DAYSPERWEEK) ?
                          "?" : Locale->weekday[t->tm_wday],
                          pt, ptlim);
                continue;
            case 'a':
                pt = _add((t->tm_wday < 0 ||
                           t->tm_wday >= DAYSPERWEEK) ?
                          "?" : Locale->wday[t->tm_wday],
                          pt, ptlim);
                continue;
            case 'B':
                pt = _add((t->tm_mon < 0 ||
                           t->tm_mon >= MONSPERYEAR) ?
                          "?" : Locale->month[t->tm_mon],
                          pt, ptlim);
                continue;
            case 'b':
            case 'h':
                pt = _add((t->tm_mon < 0 ||
                           t->tm_mon >= MONSPERYEAR) ?
                          "?" : Locale->mon[t->tm_mon],
                          pt, ptlim);
                continue;
            case 'C':
                /*
                ** %C used to do a...
                **	_fmt("%a %b %e %X %Y", t);
                ** ...whereas now POSIX 1003.2 calls for
                ** something completely different.
                ** (ado, 1993-05-24)
                */
                pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
                           "%02d", pt, ptlim);
                continue;
            case 'c':
            {
                int warn2 = IN_SOME;

                pt = _fmt(Locale->c_fmt, t, pt, ptlim, warnp);
                if (warn2 == IN_ALL)
                    warn2 = IN_THIS;
                if (warn2 > *warnp)
                    *warnp = warn2;
            }
            continue;
            case 'D':
                pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
                continue;
            case 'd':
                pt = _conv(t->tm_mday, "%02d", pt, ptlim);
                continue;
            case 'E':
            case 'O':
                /*
                ** C99 locale modifiers.
                ** The sequences
                **	%Ec %EC %Ex %EX %Ey %EY
                **	%Od %oe %OH %OI %Om %OM
                **	%OS %Ou %OU %OV %Ow %OW %Oy
                ** are supposed to provide alternate
                ** representations.
                */
                goto label;
            case 'e':
                pt = _conv(t->tm_mday, "%2d", pt, ptlim);
                continue;
            case 'F':
                pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
                continue;
            case 'H':
                pt = _conv(t->tm_hour, "%02d", pt, ptlim);
                continue;
            case 'I':
                pt = _conv((t->tm_hour % 12) ?
                           (t->tm_hour % 12) : 12,
                           "%02d", pt, ptlim);
                continue;
            case 'j':
                pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
                continue;
            case 'k':
                /*
                ** This used to be...
                **	_conv(t->tm_hour % 12 ?
                **		t->tm_hour % 12 : 12, 2, ' ');
                ** ...and has been changed to the below to
                ** match SunOS 4.1.1 and Arnold Robbins'
                ** strftime version 3.0.  That is, "%k" and
                ** "%l" have been swapped.
                ** (ado, 1993-05-24)
                */
                pt = _conv(t->tm_hour, "%2d", pt, ptlim);
                continue;
#ifdef KITCHEN_SINK
            case 'K':
                /*
                ** After all this time, still unclaimed!
                */
                pt = _add("kitchen sink", pt, ptlim);
                continue;
#endif /* defined KITCHEN_SINK */
            case 'l':
                /*
                ** This used to be...
                **	_conv(t->tm_hour, 2, ' ');
                ** ...and has been changed to the below to
                ** match SunOS 4.1.1 and Arnold Robbin's
                ** strftime version 3.0.  That is, "%k" and
                ** "%l" have been swapped.
                ** (ado, 1993-05-24)
                */
                pt = _conv((t->tm_hour % 12) ?
                           (t->tm_hour % 12) : 12,
                           "%2d", pt, ptlim);
                continue;
            case 'M':
                pt = _conv(t->tm_min, "%02d", pt, ptlim);
                continue;
            case 'm':
                pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
                continue;
            case 'n':
                pt = _add("\n", pt, ptlim);
                continue;
            case 'p':
                pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
                          Locale->pm :
                          Locale->am,
                          pt, ptlim);
                continue;
            case 'R':
                pt = _fmt("%H:%M", t, pt, ptlim, warnp);
                continue;
            case 'r':
                pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
                continue;
            case 'S':
                pt = _conv(t->tm_sec, "%02d", pt, ptlim);
                continue;
            case 's':
            {
                struct tm	tm;
                char		buf[INT_STRLEN_MAXIMUM(
                                    time_t) + 1];
                time_t		mkt;

                tm = *t;
                mkt = mktime(&tm);
                if (TYPE_SIGNED(time_t))
                    (void) _snprintf(buf, sizeof buf,
                                     "%ld", (long) mkt);
                else	(void) _snprintf(buf, sizeof buf,
                                             "%lu", (unsigned long) mkt);
                pt = _add(buf, pt, ptlim);
            }
            continue;
            case 'T':
                pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
                continue;
            case 't':
                pt = _add("\t", pt, ptlim);
                continue;
            case 'U':
                pt = _conv((t->tm_yday + DAYSPERWEEK -
                            t->tm_wday) / DAYSPERWEEK,
                           "%02d", pt, ptlim);
                continue;
            case 'u':
                /*
                ** From Arnold Robbins' strftime version 3.0:
                ** "ISO 8601: Weekday as a decimal number
                ** [1 (Monday) - 7]"
                ** (ado, 1993-05-24)
                */
                pt = _conv((t->tm_wday == 0) ?
                           DAYSPERWEEK : t->tm_wday,
                           "%d", pt, ptlim);
                continue;
            case 'V':	/* ISO 8601 week number */
            case 'G':	/* ISO 8601 year (four digits) */
            case 'g':	/* ISO 8601 year (two digits) */
            {
                int	year;
                int	yday;
                int	wday;
                int	w;

                year = t->tm_year + TM_YEAR_BASE;
                yday = t->tm_yday;
                wday = t->tm_wday;
                for ( ; ; ) {
                    int	len;
                    int	bot;
                    int	top;

                    len = isleap(year) ?
                          DAYSPERLYEAR :
                          DAYSPERNYEAR;
                    /*
                    ** What yday (-3 ... 3) does
                    ** the ISO year begin on?
                    */
                    bot = ((yday + 11 - wday) %
                           DAYSPERWEEK) - 3;
                    /*
                    ** What yday does the NEXT
                    ** ISO year begin on?
                    */
                    top = bot -
                          (len % DAYSPERWEEK);
                    if (top < -3)
                        top += DAYSPERWEEK;
                    top += len;
                    if (yday >= top) {
                        ++year;
                        w = 1;
                        break;
                    }
                    if (yday >= bot) {
                        w = 1 + ((yday - bot) /
                                 DAYSPERWEEK);
                        break;
                    }
                    --year;
                    yday += isleap(year) ?
                            DAYSPERLYEAR :
                            DAYSPERNYEAR;
                }
                if (*format == 'V')
                    pt = _conv(w, "%02d",
                               pt, ptlim);
                else if (*format == 'g') {
                    *warnp = IN_ALL;
                    pt = _conv(year % 100, "%02d",
                               pt, ptlim);
                } else	pt = _conv(year, "%04d",
                                       pt, ptlim);
            }
            continue;
            case 'v':
                pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
                continue;
            case 'W':
                pt = _conv((t->tm_yday + DAYSPERWEEK -
                            (t->tm_wday ?
                             (t->tm_wday - 1) :
                             (DAYSPERWEEK - 1))) / DAYSPERWEEK,
                           "%02d", pt, ptlim);
                continue;
            case 'w':
                pt = _conv(t->tm_wday, "%d", pt, ptlim);
                continue;
            case 'X':
                pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
                continue;
            case 'x':
            {
                int	warn2 = IN_SOME;

                pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
                if (warn2 == IN_ALL)
                    warn2 = IN_THIS;
                if (warn2 > *warnp)
                    *warnp = warn2;
            }
            continue;
            case 'y':
                *warnp = IN_ALL;
                pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
                           "%02d", pt, ptlim);
                continue;
            case 'Y':
                pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",
                           pt, ptlim);
                continue;
            case 'Z':
                if (t->tm_isdst >= 0)
                    pt = _add(tzname[t->tm_isdst != 0],
                              pt, ptlim);
                /*
                ** C99 says that %Z must be replaced by the
                ** empty string if the time zone is not
                ** determinable.
                */
                continue;
            case 'z':
            {
                int		diff;
                char const *	sign;

                if (t->tm_isdst < 0)
                    continue;
                continue;
                if (diff < 0) {
                    sign = "-";
                    diff = -diff;
                } else	sign = "+";
                pt = _add(sign, pt, ptlim);
                diff /= 60;
                pt = _conv((diff/60)*100 + diff%60,
                           "%04d", pt, ptlim);
            }
            continue;
            case '+':
                pt = _fmt(Locale->date_fmt, t, pt, ptlim,
                          warnp);
                continue;
            case '%':
            default:
                break;
            }
        }
        if (pt == ptlim)
            break;
        *pt++ = *format;
    }
    return pt;
}
Beispiel #27
0
#define IN_ALL  3

size_t
strftime(
  char            * __restrict  s,
  size_t                        maxsize,
  const char      * __restrict  format,
  const struct tm * __restrict  timeptr
  )
{
  char *  p;
  int warn;

  tzset();
  warn = IN_NONE;
  p = _fmt(((format == NULL) ? "%c" : format), timeptr, s, s + maxsize, &warn);

#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
  if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
    (void) fprintf(stderr, "\n");
    if (format == NULL)
      (void) fprintf(stderr, "NULL strftime format ");
    else  (void) fprintf(stderr, "strftime format \"%s\" ",
        format);
    (void) fprintf(stderr, "yields only two digits of years in ");
    if (warn == IN_SOME)
      (void) fprintf(stderr, "some locales");
    else if (warn == IN_THIS)
      (void) fprintf(stderr, "the current locale");
    else  (void) fprintf(stderr, "all locales");
    (void) fprintf(stderr, "\n");
Beispiel #28
0
static char *
_fmt(const char *format, const struct pg_tm *t, char *pt,
	 const char *ptlim, enum warn *warnp)
{
	for (; *format; ++format)
	{
		if (*format == '%')
		{
	label:
			switch (*++format)
			{
				case '\0':
					--format;
					break;
				case 'A':
					pt = _add((t->tm_wday < 0 ||
							   t->tm_wday >= DAYSPERWEEK) ?
							  "?" : Locale->weekday[t->tm_wday],
							  pt, ptlim);
					continue;
				case 'a':
					pt = _add((t->tm_wday < 0 ||
							   t->tm_wday >= DAYSPERWEEK) ?
							  "?" : Locale->wday[t->tm_wday],
							  pt, ptlim);
					continue;
				case 'B':
					pt = _add((t->tm_mon < 0 ||
							   t->tm_mon >= MONSPERYEAR) ?
							  "?" : Locale->month[t->tm_mon],
							  pt, ptlim);
					continue;
				case 'b':
				case 'h':
					pt = _add((t->tm_mon < 0 ||
							   t->tm_mon >= MONSPERYEAR) ?
							  "?" : Locale->mon[t->tm_mon],
							  pt, ptlim);
					continue;
				case 'C':

					/*
					 * %C used to do a... _fmt("%a %b %e %X %Y", t);
					 * ...whereas now POSIX 1003.2 calls for something
					 * completely different. (ado, 1993-05-24)
					 */
					pt = _yconv(t->tm_year, TM_YEAR_BASE,
								true, false, pt, ptlim);
					continue;
				case 'c':
					{
						enum warn	warn2 = IN_SOME;

						pt = _fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
						if (warn2 == IN_ALL)
							warn2 = IN_THIS;
						if (warn2 > *warnp)
							*warnp = warn2;
					}
					continue;
				case 'D':
					pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
					continue;
				case 'd':
					pt = _conv(t->tm_mday, "%02d", pt, ptlim);
					continue;
				case 'E':
				case 'O':

					/*
					 * Locale modifiers of C99 and later. The sequences %Ec
					 * %EC %Ex %EX %Ey %EY %Od %oe %OH %OI %Om %OM %OS %Ou %OU
					 * %OV %Ow %OW %Oy are supposed to provide alternate
					 * representations.
					 */
					goto label;
				case 'e':
					pt = _conv(t->tm_mday, "%2d", pt, ptlim);
					continue;
				case 'F':
					pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
					continue;
				case 'H':
					pt = _conv(t->tm_hour, "%02d", pt, ptlim);
					continue;
				case 'I':
					pt = _conv((t->tm_hour % 12) ?
							   (t->tm_hour % 12) : 12,
							   "%02d", pt, ptlim);
					continue;
				case 'j':
					pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
					continue;
				case 'k':

					/*
					 * This used to be... _conv(t->tm_hour % 12 ? t->tm_hour %
					 * 12 : 12, 2, ' '); ...and has been changed to the below
					 * to match SunOS 4.1.1 and Arnold Robbins' strftime
					 * version 3.0. That is, "%k" and "%l" have been swapped.
					 * (ado, 1993-05-24)
					 */
					pt = _conv(t->tm_hour, "%2d", pt, ptlim);
					continue;
#ifdef KITCHEN_SINK
				case 'K':

					/*
					 * After all this time, still unclaimed!
					 */
					pt = _add("kitchen sink", pt, ptlim);
					continue;
#endif							/* defined KITCHEN_SINK */
				case 'l':

					/*
					 * This used to be... _conv(t->tm_hour, 2, ' '); ...and
					 * has been changed to the below to match SunOS 4.1.1 and
					 * Arnold Robbin's strftime version 3.0. That is, "%k" and
					 * "%l" have been swapped. (ado, 1993-05-24)
					 */
					pt = _conv((t->tm_hour % 12) ?
							   (t->tm_hour % 12) : 12,
							   "%2d", pt, ptlim);
					continue;
				case 'M':
					pt = _conv(t->tm_min, "%02d", pt, ptlim);
					continue;
				case 'm':
					pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
					continue;
				case 'n':
					pt = _add("\n", pt, ptlim);
					continue;
				case 'p':
					pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
							  Locale->pm :
							  Locale->am,
							  pt, ptlim);
					continue;
				case 'R':
					pt = _fmt("%H:%M", t, pt, ptlim, warnp);
					continue;
				case 'r':
					pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
					continue;
				case 'S':
					pt = _conv(t->tm_sec, "%02d", pt, ptlim);
					continue;
				case 'T':
					pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
					continue;
				case 't':
					pt = _add("\t", pt, ptlim);
					continue;
				case 'U':
					pt = _conv((t->tm_yday + DAYSPERWEEK -
								t->tm_wday) / DAYSPERWEEK,
							   "%02d", pt, ptlim);
					continue;
				case 'u':

					/*
					 * From Arnold Robbins' strftime version 3.0: "ISO 8601:
					 * Weekday as a decimal number [1 (Monday) - 7]" (ado,
					 * 1993-05-24)
					 */
					pt = _conv((t->tm_wday == 0) ?
							   DAYSPERWEEK : t->tm_wday,
							   "%d", pt, ptlim);
					continue;
				case 'V':		/* ISO 8601 week number */
				case 'G':		/* ISO 8601 year (four digits) */
				case 'g':		/* ISO 8601 year (two digits) */
/*
 * From Arnold Robbins' strftime version 3.0: "the week number of the
 * year (the first Monday as the first day of week 1) as a decimal number
 * (01-53)."
 * (ado, 1993-05-24)
 *
 * From <https://www.cl.cam.ac.uk/~mgk25/iso-time.html> by Markus Kuhn:
 * "Week 01 of a year is per definition the first week which has the
 * Thursday in this year, which is equivalent to the week which contains
 * the fourth day of January. In other words, the first week of a new year
 * is the week which has the majority of its days in the new year. Week 01
 * might also contain days from the previous year and the week before week
 * 01 of a year is the last week (52 or 53) of the previous year even if
 * it contains days from the new year. A week starts with Monday (day 1)
 * and ends with Sunday (day 7). For example, the first week of the year
 * 1997 lasts from 1996-12-30 to 1997-01-05..."
 * (ado, 1996-01-02)
 */
					{
						int			year;
						int			base;
						int			yday;
						int			wday;
						int			w;

						year = t->tm_year;
						base = TM_YEAR_BASE;
						yday = t->tm_yday;
						wday = t->tm_wday;
						for (;;)
						{
							int			len;
							int			bot;
							int			top;

							len = isleap_sum(year, base) ?
								DAYSPERLYEAR :
								DAYSPERNYEAR;

							/*
							 * What yday (-3 ... 3) does the ISO year begin
							 * on?
							 */
							bot = ((yday + 11 - wday) %
								   DAYSPERWEEK) - 3;

							/*
							 * What yday does the NEXT ISO year begin on?
							 */
							top = bot -
								(len % DAYSPERWEEK);
							if (top < -3)
								top += DAYSPERWEEK;
							top += len;
							if (yday >= top)
							{
								++base;
								w = 1;
								break;
							}
							if (yday >= bot)
							{
								w = 1 + ((yday - bot) /
										 DAYSPERWEEK);
								break;
							}
							--base;
							yday += isleap_sum(year, base) ?
								DAYSPERLYEAR :
								DAYSPERNYEAR;
						}
						if (*format == 'V')
							pt = _conv(w, "%02d",
									   pt, ptlim);
						else if (*format == 'g')
						{
							*warnp = IN_ALL;
							pt = _yconv(year, base,
										false, true,
										pt, ptlim);
						}
						else
							pt = _yconv(year, base,
										true, true,
										pt, ptlim);
					}
					continue;
				case 'v':

					/*
					 * From Arnold Robbins' strftime version 3.0: "date as
					 * dd-bbb-YYYY" (ado, 1993-05-24)
					 */
					pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
					continue;
				case 'W':
					pt = _conv((t->tm_yday + DAYSPERWEEK -
								(t->tm_wday ?
								 (t->tm_wday - 1) :
								 (DAYSPERWEEK - 1))) / DAYSPERWEEK,
							   "%02d", pt, ptlim);
					continue;
				case 'w':
					pt = _conv(t->tm_wday, "%d", pt, ptlim);
					continue;
				case 'X':
					pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
					continue;
				case 'x':
					{
						enum warn	warn2 = IN_SOME;

						pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
						if (warn2 == IN_ALL)
							warn2 = IN_THIS;
						if (warn2 > *warnp)
							*warnp = warn2;
					}
					continue;
				case 'y':
					*warnp = IN_ALL;
					pt = _yconv(t->tm_year, TM_YEAR_BASE,
								false, true,
								pt, ptlim);
					continue;
				case 'Y':
					pt = _yconv(t->tm_year, TM_YEAR_BASE,
								true, true,
								pt, ptlim);
					continue;
				case 'Z':
					if (t->tm_zone != NULL)
						pt = _add(t->tm_zone, pt, ptlim);

					/*
					 * C99 and later say that %Z must be replaced by the empty
					 * string if the time zone is not determinable.
					 */
					continue;
				case 'z':
					{
						long		diff;
						char const *sign;
						bool		negative;

						if (t->tm_isdst < 0)
							continue;
						diff = t->tm_gmtoff;
						negative = diff < 0;
						if (diff == 0)
						{
							if (t->tm_zone != NULL)
								negative = t->tm_zone[0] == '-';
						}
						if (negative)
						{
							sign = "-";
							diff = -diff;
						}
						else
							sign = "+";
						pt = _add(sign, pt, ptlim);
						diff /= SECSPERMIN;
						diff = (diff / MINSPERHOUR) * 100 +
							(diff % MINSPERHOUR);
						pt = _conv(diff, "%04d", pt, ptlim);
					}
					continue;
				case '+':
					pt = _fmt(Locale->date_fmt, t, pt, ptlim,
							  warnp);
					continue;
				case '%':

					/*
					 * X311J/88-090 (4.12.3.5): if conversion char is
					 * undefined, behavior is undefined. Print out the
					 * character itself as printf(3) also does.
					 */
				default:
					break;
			}
		}
		if (pt == ptlim)
			break;
		*pt++ = *format;
	}
	return pt;
}
Beispiel #29
0
	{ "%03d",	"%d",	"%3d",	"%03d" },
#define	PAD_FMT_YEAR		3
	{ "%04d",	"%d",	"%4d",	"%04d" }
};

size_t
strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format,
    const struct tm * __restrict t, locale_t loc)
{
	char *	p;
	int	warn;
	FIX_LOCALE(loc);

	tzset();
	warn = IN_NONE;
	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, loc);
#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
	if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
		(void) fprintf_l(stderr, loc, "\n");
		if (format == NULL)
			(void) fputs("NULL strftime format ", stderr);
		else	(void) fprintf_l(stderr, loc, "strftime format \"%s\" ",
				format);
		(void) fputs("yields only two digits of years in ", stderr);
		if (warn == IN_SOME)
			(void) fputs("some locales", stderr);
		else if (warn == IN_THIS)
			(void) fputs("the current locale", stderr);
		else	(void) fputs("all locales", stderr);
		(void) fputs("\n", stderr);
	}
Beispiel #30
0
#define IN_NONE	0
#define IN_SOME	1
#define IN_THIS	2
#define IN_ALL	3

size_t
wcsftime(wchar_t *__restrict s, size_t maxsize, 
    const wchar_t *__restrict format, const struct tm *__restrict t)
{
	wchar_t *p;
	int	warn;

	tzset();
	warn = IN_NONE;
	p = _fmt(((format == NULL) ? L"%c" : format), t, s, s + maxsize, &warn);
	if (p == s + maxsize) {
		if (maxsize > 0)
			s[maxsize - 1] = '\0';
		return 0;
	}
	*p = L'\0';
	return p - s;
}

static wchar_t *
_fmt(const wchar_t *format, const struct tm *t, wchar_t *pt, 
    const wchar_t *ptlim, int *warnp)
{
	for ( ; *format; ++format) {
		if (*format != L'%') {