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