]> git.pond.sub.org Git - empserver/blob - src/lib/subs/show.c
Update known contributors comments
[empserver] / src / lib / subs / show.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  show.c: General show routines
29  * 
30  *  Known contributors to this file:
31  *     Julian Onions, 1988
32  *     Jeff Bailey, 1990
33  *     Steve McClure, 1996
34  *     Ron Koenderink, 2005
35  *     Markus Armbruster, 2006-2008
36  */
37
38 #include <config.h>
39
40 #if defined(_WIN32)
41 #include <Windows.h>
42 #endif
43
44 #include <math.h>
45 #include "file.h"
46 #include "game.h"
47 #include "item.h"
48 #include "land.h"
49 #include "nat.h"
50 #include "news.h"
51 #include "nuke.h"
52 #include "optlist.h"
53 #include "plane.h"
54 #include "player.h"
55 #include "product.h"
56 #include "prototypes.h"
57 #include "sect.h"
58 #include "server.h"
59 #include "ship.h"
60
61 static char *fmttime2822(time_t);
62
63 struct look_list {
64     union {
65         struct lchrstr *lp;
66         struct plchrstr *pp;
67         struct mchrstr *mp;
68     } l_u;
69     int tech;
70 };
71
72 /*
73  * Change this if there are ever more than 200 ships, plane or land
74  * unit types.
75  */
76 static struct look_list lookup_list[200];
77 static int lookup_list_cnt = 0;
78
79 static void
80 sort_lookup_list(void)
81 {
82     struct natstr *np = getnatp(player->cnum);
83     struct look_list tmp;
84     int i;
85     int j;
86
87     if (!(np->nat_flags & NF_TECHLISTS))
88         return;
89     for (i = 0; i < lookup_list_cnt; i++) {
90         for (j = i; j < lookup_list_cnt; j++) {
91             if (lookup_list[j].tech < lookup_list[i].tech) {
92                 tmp = lookup_list[j];
93                 lookup_list[j] = lookup_list[i];
94                 lookup_list[i] = tmp;
95             }
96         }
97     }
98 }
99
100 static void
101 make_new_list(int tlev, int type)
102 {
103     struct plchrstr *pp;
104     struct lchrstr *lp;
105     struct mchrstr *mp;
106
107     lookup_list_cnt = 0;
108     if (type == EF_PLANE) {
109         for (pp = plchr; pp->pl_name; pp++) {
110             if (pp->pl_tech > tlev)
111                 continue;
112             lookup_list[lookup_list_cnt].l_u.pp = pp;
113             lookup_list[lookup_list_cnt].tech = pp->pl_tech;
114             lookup_list_cnt++;
115         }
116     } else if (type == EF_SHIP) {
117         for (mp = mchr; mp->m_name; mp++) {
118             if (mp->m_tech > tlev)
119                 continue;
120             lookup_list[lookup_list_cnt].l_u.mp = mp;
121             lookup_list[lookup_list_cnt].tech = mp->m_tech;
122             lookup_list_cnt++;
123         }
124     } else if (type == EF_LAND) {
125         for (lp = lchr; lp->l_name; lp++) {
126             if (lp->l_tech > tlev)
127                 continue;
128             lookup_list[lookup_list_cnt].l_u.lp = lp;
129             lookup_list[lookup_list_cnt].tech = lp->l_tech;
130             lookup_list_cnt++;
131         }
132     } else
133         return;
134
135     sort_lookup_list();
136 }
137
138 void
139 show_bridge(int tlev)
140 {
141     if (tlev < buil_bt)
142         return;
143     pr("Bridges require %g tech, %d hcm, 0 workers,\n",
144        buil_bt, buil_bh);
145     pr("%d available workforce, and cost $%g\n",
146        (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
147        buil_bc);
148 }
149
150 void
151 show_tower(int tlev)
152 {
153     if (tlev < buil_tower_bt)
154         return;
155     pr("Bridge Towers require %g tech, %d hcm, 0 workers,\n",
156        buil_tower_bt, buil_tower_bh);
157     pr("%d available workforce, and cost $%g\n",
158        (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
159        buil_tower_bc);
160 }
161
162 void
163 show_nuke_stats(int tlev)
164 {
165     show_nuke_capab(tlev);
166 }
167
168 void
169 show_nuke_build(int tlev)
170 {
171     struct nchrstr *np;
172     int avail;
173
174     pr("%13s lcm hcm  oil  rad avail tech res $\n", "");
175
176     for (np = nchr; np->n_name; np++) {
177         avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
178         if (np->n_tech > tlev)
179             continue;
180         pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
181            np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
182            np->n_rad, avail, np->n_tech,
183            drnuke_const > MIN_DRNUKE_CONST ?
184                 ceil(np->n_tech * drnuke_const) : 0.0,
185            np->n_cost);
186     }
187 }
188
189 void
190 show_nuke_capab(int tlev)
191 {
192     struct nchrstr *np;
193     int i, j;
194     char *p;
195
196     pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
197
198     for (np = nchr; np->n_name; np++) {
199         if (np->n_tech > tlev)
200             continue;
201         pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
202            np->n_name, np->n_blast, np->n_dam,
203            np->n_weight, np->n_tech,
204            drnuke_const > MIN_DRNUKE_CONST ?
205                 ceil(np->n_tech * drnuke_const) : 0.0,
206            np->n_cost);
207         for (i = j = 0; i < 32; i++) {
208             if (!(np->n_flags & bit(i)))
209                 continue;
210             if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
211                 if (j++ > 0)
212                     pr(" ");
213                 pr("%s", p);
214             }
215         }
216         pr("\n");
217     }
218 }
219
220 void
221 show_ship_build(int tlev)
222 {
223     struct mchrstr *mp;
224     int n;
225
226     pr("%25s lcm hcm avail tech $\n", "");
227     make_new_list(tlev, EF_SHIP);
228     for (n = 0; n < lookup_list_cnt; n++) {
229         mp = (struct mchrstr *)lookup_list[n].l_u.mp;
230         /* Can't show trade ships unless it's turned on */
231         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
232             continue;
233
234         pr("%-25.25s %3d %3d %5d %4d $%d\n",
235            mp->m_name, mp->m_lcm, mp->m_hcm,
236            SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
237     }
238 }
239
240 void
241 show_ship_stats(int tlev)
242 {
243     struct mchrstr *mp;
244     int scount;
245
246     pr("%25s      s  v  s  r  f  l  p  h  x", "");
247     if (opt_FUEL)
248         pr("  fuel");
249     pr("\n");
250
251     pr("%25s      p  i  p  n  i  n  l  e  p", "");
252     if (opt_FUEL)
253         pr("   c/u");
254     pr("\n");
255
256     pr("%25s def  d  s  y  g  r  d  n  l  l", "");
257     if (opt_FUEL)
258         pr("      ");
259     pr("\n");
260
261
262     make_new_list(tlev, EF_SHIP);
263     for (scount = 0; scount < lookup_list_cnt; scount++) {
264         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
265         /* Can't show trade ships unless it's turned on */
266         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
267             continue;
268
269         pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
270            mp->m_name, m_armor(mp, tlev), m_speed(mp, tlev),
271            m_visib(mp, tlev), mp->m_vrnge,
272            m_frnge(mp, tlev), m_glim(mp, tlev));
273
274         pr("%2d ", mp->m_nland);
275         pr("%2d ", mp->m_nplanes);
276         pr("%2d ", mp->m_nchoppers);
277         pr("%2d ", mp->m_nxlight);
278         if (opt_FUEL)
279             pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
280         pr("\n");
281     }
282 }
283
284 void
285 show_ship_capab(int tlev)
286 {
287     struct mchrstr *mp;
288     i_type i;
289     int j;
290     int scount;
291     int n;
292     char *p;
293
294     pr("%25s cargos & capabilities\n", "");
295
296     make_new_list(tlev, EF_SHIP);
297     for (scount = 0; scount < lookup_list_cnt; scount++) {
298         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
299         /* Can't show trade ships unless it's turned on */
300         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
301             continue;
302
303         pr("%-25.25s ", mp->m_name);
304
305         for (i = I_NONE + 1; i <= I_MAX; ++i)
306             if (mp->m_item[i])
307                 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
308         pr(" ");
309         for (j = n = 0; j < 32; j++) {
310             if (!(mp->m_flags & bit(j)))
311                 continue;
312             if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
313                 if (n++ > 0)
314                     pr(" ");
315                 pr("%s", p);
316             }
317         }
318         pr("\n");
319     }
320 }
321
322 void
323 show_plane_stats(int tlev)
324 {
325     struct plchrstr *pp;
326     int pcount;
327
328     pr("%25s acc load att def ran fuel stlth\n", "");
329     make_new_list(tlev, EF_PLANE);
330     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
331         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
332         pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
333            pp->pl_name, pl_acc(pp, tlev), pl_load(pp, tlev),
334            pl_att(pp, tlev), pl_def(pp, tlev), pl_range(pp, tlev),
335            pp->pl_fuel);
336         pr("%4d%% ", pp->pl_stealth);
337         pr("\n");
338     }
339 }
340
341 void
342 show_plane_capab(int tlev)
343 {
344     struct plchrstr *pp;
345     int i;
346     int pcount;
347     int n;
348     char *p;
349
350     pr("%25s capabilities\n", "");
351     make_new_list(tlev, EF_PLANE);
352     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
353         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
354         pr("%-25.25s  ", pp->pl_name);
355
356         for (i = n = 0; i < 32; i++) {
357             if (!(pp->pl_flags & bit(i)))
358                 continue;
359             if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
360                 if (n++ > 0)
361                     pr(" ");
362                 pr("%s", p);
363             }
364         }
365         pr("\n");
366     }
367 }
368
369 void
370 show_plane_build(int tlev)
371 {
372     struct plchrstr *pp;
373     int pcount;
374
375     pr("%25s lcm hcm crew avail tech $\n", "");
376     make_new_list(tlev, EF_PLANE);
377     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
378         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
379         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
380            pp->pl_name, pp->pl_lcm,
381            pp->pl_hcm, pp->pl_crew,
382            PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
383     }
384 }
385
386 void
387 show_land_build(int tlev)
388 {
389     struct lchrstr *lp;
390     int n;
391
392     pr("%25s lcm hcm guns avail tech $\n", "");
393     make_new_list(tlev, EF_LAND);
394     for (n = 0; n < lookup_list_cnt; n++) {
395         lp = (struct lchrstr *)lookup_list[n].l_u.lp;
396         if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
397             continue;
398         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
399            lp->l_name, lp->l_lcm,
400            lp->l_hcm,
401            lp->l_gun,
402            LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
403     }
404 }
405
406 void
407 show_land_capab(int tlev)
408 {
409     struct lchrstr *lcp;
410     int lcount;
411     i_type i;
412     int j, n;
413     char *p;
414
415     pr("%25s capabilities\n", "");
416
417     make_new_list(tlev, EF_LAND);
418     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
419         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
420         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
421             continue;
422
423         pr("%-25s ", lcp->l_name);
424
425         for (i = I_NONE + 1; i <= I_MAX; ++i)
426             if (lcp->l_item[i])
427                 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
428         pr(" ");
429         for (j = n = 0; j < 32; j++) {
430             if (!(lcp->l_flags & bit(j)))
431                 continue;
432             if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
433                 if (n++ > 0)
434                     pr(" ");
435                 pr("%s", p);
436             }
437         }
438         pr("\n");
439     }
440 }
441
442 void
443 show_land_stats(int tlev)
444 {
445     struct lchrstr *lcp;
446     int lcount;
447
448     pr("%25s              s  v  s  r  r  a  f  a  a        x  l\n", "");
449     pr("%25s              p  i  p  a  n  c  i  m  a  f  f  p  n\n", "");
450     pr("%25s att def vul  d  s  y  d  g  c  r  m  f  c  u  l  d\n", "");
451
452     make_new_list(tlev, EF_LAND);
453     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
454         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
455         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
456             continue;
457
458         pr("%-25s %1.1f %1.1f %3d ",
459            lcp->l_name,
460            l_att(lcp, tlev), l_def(lcp, tlev), l_vul(lcp, tlev));
461         pr("%2d %2d %2d %2d ",
462            l_spd(lcp, tlev), lcp->l_vis, lcp->l_spy, lcp->l_rad);
463         pr("%2d %2d %2d %2d %2d ",
464            l_frg(lcp, tlev), l_acc(lcp, tlev), l_dam(lcp, tlev),
465            lcp->l_ammo, lcp->l_aaf);
466         pr("%2d %2d %2d %2d ",
467            lcp->l_fuelc, lcp->l_fuelu, lcp->l_nxlight, lcp->l_nland);
468
469         pr("\n");
470     }
471 }
472
473 void
474 show_sect_build(int foo)
475 {
476     int x, first;
477
478     first = 1;
479     for (x = 0; dchr[x].d_name; x++) {
480         if (dchr[x].d_mnem == 0)
481             continue;
482         if (dchr[x].d_cost < 0)
483             continue;
484         if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
485             (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
486             if (first) {
487                 pr("sector type    cost to des    cost for 1%% eff   lcms for 1%%    hcms for 1%%\n");
488                 first = 0;
489             }
490             pr("%-14c %-14d %-17d %-14d %d\n",
491                dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
492                dchr[x].d_lcms, dchr[x].d_hcms);
493         }
494     }
495
496     first = 1;
497     for (x = 0; intrchr[x].in_name; x++) {
498         if (!intrchr[x].in_enable)
499             continue;
500         if (first)
501             pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
502                "       type          lcms    hcms    mobility    $$$$\n");
503         pr("%-20s %4d    %4d    %8d    %4d\n",
504            intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
505            intrchr[x].in_mcost, intrchr[x].in_dcost);
506         first = 0;
507     }
508 }
509
510 void
511 show_sect_stats(int foo)
512 {
513     int x, first = 1;
514     struct natstr *natp;
515
516     natp = getnatp(player->cnum);
517     for (x = 0; dchr[x].d_name; x++) {
518         if (dchr[x].d_mnem == 0)
519             continue;
520         if (first) {
521             pr("                        mob cost   max   max   --  packing bonus  --   max\n");
522             pr("  sector type            0%% 100%%   off   def   mil  uw civ bar other   pop\n");
523             first = 0;
524         }
525         pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
526         if (dchr[x].d_mob0 < 0)
527             pr("  no way ");
528         else
529             pr(" %3.1f  %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
530         pr("  %5.2f %5.2f   %3d %3d %3d %3d %5d %5d\n",
531            dchr[x].d_ostr, dchr[x].d_dstr,
532            ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
533            ichr[I_UW].i_pkg[dchr[x].d_pkg],
534            ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
535            ichr[I_BAR].i_pkg[dchr[x].d_pkg],
536            ichr[I_LCM].i_pkg[dchr[x].d_pkg],
537            max_population(natp->nat_level[NAT_RLEV], x, 100));
538     }
539 }
540
541 void
542 show_sect_capab(int foo)
543 {
544     int x, first = 1, i, j;
545     char *tmpstr;
546
547     for (x = 0; dchr[x].d_name; x++) {
548         if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
549             continue;
550         if (first) {
551             pr("                                                 --- level ---          reso \n");
552             pr("  sector type             product use1 use2 use3 level min lag eff%% $$$ dep c\n");
553             first = 0;
554         }
555
556         j = dchr[x].d_prd;
557
558         pr("%c %-23s %-7s ",
559            dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
560         (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
561         for (i = 0; i < 3; i++) {
562             if (i < MAXPRCON
563                 && pchr[j].p_camt[i]
564                 && pchr[j].p_ctype[i] > I_NONE
565                 && pchr[j].p_ctype[i] <= I_MAX) {
566                 pr("%2d %c ", pchr[j].p_camt[i],
567                    ichr[pchr[j].p_ctype[i]].i_name[0]);
568             } else {
569                 pr("     ");
570             }
571         }
572         switch (pchr[j].p_nlndx) {
573         case NAT_TLEV:
574             tmpstr = "tech";
575             break;
576         case NAT_ELEV:
577             tmpstr = "edu";
578             break;
579         case NAT_RLEV:
580             tmpstr = "res";
581             break;
582         case NAT_HLEV:
583             tmpstr = "hap";
584             break;
585         default:
586             tmpstr = " ";
587             break;
588         }
589         pr("%-5s %3d %3d %4d %3d %3d %c",
590            tmpstr,
591            pchr[j].p_nlmin,
592            pchr[j].p_nllag,
593            dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
594            pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
595
596         pr("\n");
597     }
598 }
599
600 void
601 show_item(int tlev)
602 {
603     struct ichrstr *ip;
604
605     pr("item value sell lbs    packing     melt  item\n");
606     pr("mnem                in rg wh ur bk deno  name\n");
607
608     for (ip = ichr; ip->i_name; ip++) {
609         pr("   %c %5d %4s %3d %2d %2d %2d %2d %2d %4d  %s\n",
610            ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
611            ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
612            ip->i_pkg[UPKG], ip->i_pkg[BPKG],
613            ip->i_melt_denom, ip->i_name);
614     }
615 }
616
617 void
618 show_news(int tlev)
619 {
620     int i, j;
621     
622     pr("id category           good will\n");
623     pr("    messsages\n");
624
625     for (i = 1; i < N_MAX_VERB + 1; i++) {
626         if (rpt[i].r_newspage == N_NOTUSED)
627             continue;
628         pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
629             page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
630         for (j = 0; j < NUM_RPTS; j++)
631             pr("    %s\n", rpt[i].r_newstory[j]);
632     }
633 }
634
635 /*
636  * Show update policy and up to N scheduled updates.
637  */
638 void
639 show_updates(int n)
640 {
641     struct gamestr *game = game_tick_tick();
642     int demand = 0;
643     int i;
644
645     pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
646        game->game_turn, game->game_tick);
647
648     if (update_time[0]) {
649         if (update_demand == UPD_DEMAND_SCHED) {
650             pr("Demand updates occur according to schedule:\n");
651             demand = 1;
652         } else
653             pr("Updates occur according to schedule:\n");
654         for (i = 0; i < n && update_time[i]; i++)
655             pr("%3d.  %s\n", game->game_turn + i,
656                fmttime2822(update_time[i]));
657         if (update_window) {
658             pr("Updates occur within %d seconds after the scheduled time\n",
659                update_window);
660         }
661     } else
662         pr("There are no updates scheduled.\n");
663
664     if (update_demand == UPD_DEMAND_ASYNC) {
665         pr("Demand updates occur right after the demand is set.\n");
666         if (*update_demandtimes != 0) {
667             pr("Demand updates are allowed during: %s\n",
668                update_demandtimes);
669         }
670         demand = 1;
671     }
672
673     if (demand) {
674         pr("Demand updates require %d country(s) to want one.\n",
675            update_wantmin);
676     }
677
678     if (updates_disabled())
679         pr("\nUPDATES ARE DISABLED!\n");
680 }
681
682 /*
683  * Return T formatted according to RFC 2822.
684  * The return value is statically allocated and overwritten on
685  * subsequent calls.
686  */
687 static char *
688 fmttime2822(time_t t)
689 {
690     static char buf[32];
691 #if defined(_WIN32)
692     size_t n;
693     int nn;
694     TIME_ZONE_INFORMATION tzi;
695     long time_offset;
696     struct tm *time;
697     
698     time = localtime(&t);
699
700     n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time);
701     if (CANT_HAPPEN(n == 0)) {
702         buf[0] = 0;
703         return buf;
704     }
705     GetTimeZoneInformation(&tzi);
706     time_offset = -(tzi.Bias +
707         (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
708
709     nn = _snprintf(buf + n, sizeof(buf) - n, " %+03d%02d",
710         time_offset/60, abs(time_offset) % 60);
711     if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf)))
712         buf[0] = 0;
713 #else
714     size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
715                      localtime(&t));
716     if (CANT_HAPPEN(n == 0))
717         buf[0] = 0;
718 #endif
719     return buf;
720 }