/[gcl]/gcl/o/format.c
ViewVC logotype

Diff of /gcl/o/format.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by camm, Sun Feb 9 22:35:18 2003 UTC revision 1.8 by camm, Sat Feb 15 00:38:28 2003 UTC
# Line 24  Foundation, 675 Mass Ave, Cambridge, MA Line 24  Foundation, 675 Mass Ave, Cambridge, MA
24  */  */
25    
26  #include "include.h"  #include "include.h"
27    
28    static int
29    fmt_thousand(int,int,bool,bool,int);
30    
31    static void
32    fmt_exponent1(int);
33    
34    static void
35    fmt_write_numeral(int,int);
36    
37    static void
38    fmt_write_ordinal(int,int);
39    
40    static int
41    fmt_nonillion(int,int,bool,bool,int);
42    
43    static void
44    fmt_roman(int,int,int,int,int);
45    
46    static void
47    fmt_integer(object,bool,bool,int,int,int,int);
48    
49    static void
50    fmt_semicolon(bool,bool);
51    
52    static void
53    fmt_up_and_out(bool,bool);
54    
55    static void
56    fmt_justification(volatile bool,bool);
57    
58    static void
59    fmt_iteration(bool,bool);
60    
61    static void
62    fmt_conditional(bool,bool);
63    
64    static void
65    fmt_case(bool,bool);
66    
67    static void
68    fmt_indirection(bool,bool);
69    
70    static void
71    fmt_asterisk(bool,bool);
72    
73    static void
74    fmt_tabulate(bool,bool);
75    
76    static void
77    fmt_newline(bool,bool);
78    
79    static void
80    fmt_tilde(bool,bool);
81    
82    static void
83    fmt_bar(bool,bool);
84    
85    static void
86    fmt_ampersand(bool,bool);
87    
88    static void
89    fmt_percent(bool,bool);
90    
91    static void
92    fmt_dollars_float(bool,bool);
93    
94    static void
95    fmt_general_float(bool,bool);
96    
97    static void
98    fmt_exponential_float(bool,bool);
99    
100    static void
101    fmt_fix_float(bool,bool);
102    
103    static void
104    fmt_character(bool,bool);
105    
106    static void
107    fmt_plural(bool,bool);
108    
109    static void
110    fmt_radix(bool,bool);
111    
112    static void
113    fmt_hexadecimal(bool,bool);
114    
115    static void
116    fmt_octal(bool,bool);
117    
118    static void
119    fmt_binary(bool,bool);
120    
121    static void
122    fmt_error(char *);
123    
124    static void
125    fmt_ascii(bool, bool);
126    
127    static void
128    fmt_S_expression(bool, bool);
129    
130    static void
131    fmt_decimal(bool, bool);
132    
133    
134  object sSAindent_formatted_outputA;  object sSAindent_formatted_outputA;
135    
136    
# Line 129  int fmt_spare_spaces; Line 236  int fmt_spare_spaces;
236  int fmt_line_length;  int fmt_line_length;
237    
238    
239  int  static int
240  fmt_tempstr(int s)  fmt_tempstr(int s)
241  {  {
242          return(fmt_temporary_string->st.st_self[s]);          return(fmt_temporary_string->st.st_self[s]);
243  }  }
244    
245  int  static int
246  ctl_advance(void)  ctl_advance(void)
247  {  {
248          if (ctl_index >= ctl_end)          if (ctl_index >= ctl_end)
# Line 143  ctl_advance(void) Line 250  ctl_advance(void)
250          return(ctl_string[ctl_index++]);          return(ctl_string[ctl_index++]);
251  }  }
252    
253  object  static object
254  fmt_advance(void)  fmt_advance(void)
255  {  {
256          if (fmt_index >= fmt_end)          if (fmt_index >= fmt_end)
# Line 152  fmt_advance(void) Line 259  fmt_advance(void)
259  }  }
260    
261    
262  void  static void
263  format(object fmt_stream0, int ctl_origin0, int ctl_end0)  format(object fmt_stream0, int ctl_origin0, int ctl_end0)
264  {  {
265          int c, i, n;          int c, i, n;
# Line 397  DIRECTIVE: Line 504  DIRECTIVE:
504    
505    
506    
507  int  static int
508  fmt_skip(void)  fmt_skip(void)
509  {  {
510          int c, level = 0;          int c, level = 0;
# Line 446  DIRECTIVE: Line 553  DIRECTIVE:
553  }  }
554    
555    
556  void  static void
557  fmt_max_param(int n)  fmt_max_param(int n)
558  {  {
559          if (fmt_nparam > n)          if (fmt_nparam > n)
560                  fmt_error("too many parameters");                  fmt_error("too many parameters");
561  }  }
562    
563  void  static void
564  fmt_not_colon(bool colon)  fmt_not_colon(bool colon)
565  {  {
566          if (colon)          if (colon)
567                  fmt_error("illegal :");                  fmt_error("illegal :");
568  }  }
569    
570  void  static void
571  fmt_not_atsign(bool atsign)  fmt_not_atsign(bool atsign)
572  {  {
573          if (atsign)          if (atsign)
574                  fmt_error("illegal @");                  fmt_error("illegal @");
575  }  }
576    
577  void  static void
578  fmt_not_colon_atsign(bool colon, bool atsign)  fmt_not_colon_atsign(bool colon, bool atsign)
579  {  {
580          if (colon && atsign)          if (colon && atsign)
581                  fmt_error("illegal :@");                  fmt_error("illegal :@");
582  }  }
583    
584  void  static void
585  fmt_set_param(int i, int *p, int t, int v)  fmt_set_param(int i, int *p, int t, int v)
586  {  {
587          if (i >= fmt_nparam || FMT_PARAM[i].fmt_param_type == fmt_null)          if (i >= fmt_nparam || FMT_PARAM[i].fmt_param_type == fmt_null)
# Line 486  fmt_set_param(int i, int *p, int t, int Line 593  fmt_set_param(int i, int *p, int t, int
593  }        }      
594    
595    
596  void  static void
597  fmt_ascii(bool colon, bool atsign)  fmt_ascii(bool colon, bool atsign)
598  {  {
599          int mincol, colinc, minpad, padchar;          int mincol, colinc, minpad, padchar;
# Line 524  fmt_ascii(bool colon, bool atsign) Line 631  fmt_ascii(bool colon, bool atsign)
631          }          }
632  }  }
633    
634  void  static void
635  fmt_S_expression(bool colon, bool atsign)  fmt_S_expression(bool colon, bool atsign)
636  {  {
637          int mincol, colinc, minpad, padchar;          int mincol, colinc, minpad, padchar;
# Line 562  fmt_S_expression(bool colon, bool atsign Line 669  fmt_S_expression(bool colon, bool atsign
669          }          }
670  }  }
671    
672  void  static void
673  fmt_decimal(bool colon, bool atsign)  fmt_decimal(bool colon, bool atsign)
674  {  {
675          int mincol, padchar, commachar;          int mincol, padchar, commachar;
# Line 575  fmt_decimal(bool colon, bool atsign) Line 682  fmt_decimal(bool colon, bool atsign)
682                      10, mincol, padchar, commachar);                      10, mincol, padchar, commachar);
683  }  }
684    
685  void  static void
686  fmt_binary(bool colon, bool atsign)  fmt_binary(bool colon, bool atsign)
687  {  {
688          int mincol, padchar, commachar;          int mincol, padchar, commachar;
# Line 588  fmt_binary(bool colon, bool atsign) Line 695  fmt_binary(bool colon, bool atsign)
695                      2, mincol, padchar, commachar);                      2, mincol, padchar, commachar);
696  }  }
697    
698  void  static void
699  fmt_octal(bool colon, bool atsign)  fmt_octal(bool colon, bool atsign)
700  {  {
701          int mincol, padchar, commachar;          int mincol, padchar, commachar;
# Line 601  fmt_octal(bool colon, bool atsign) Line 708  fmt_octal(bool colon, bool atsign)
708                      8, mincol, padchar, commachar);                      8, mincol, padchar, commachar);
709  }  }
710    
711  void  static void
712  fmt_hexadecimal(bool colon, bool atsign)  fmt_hexadecimal(bool colon, bool atsign)
713  {  {
714          int mincol, padchar, commachar;          int mincol, padchar, commachar;
# Line 614  fmt_hexadecimal(bool colon, bool atsign) Line 721  fmt_hexadecimal(bool colon, bool atsign)
721                      16, mincol, padchar, commachar);                      16, mincol, padchar, commachar);
722  }  }
723    
724  void  static void
725  fmt_radix(bool colon, bool atsign)  fmt_radix(bool colon, bool atsign)
726  {  {
727          int radix, mincol, padchar, commachar;          int radix, mincol, padchar, commachar;
# Line 695  fmt_radix(bool colon, bool atsign) Line 802  fmt_radix(bool colon, bool atsign)
802          fmt_integer(x, colon, atsign, radix, mincol, padchar, commachar);          fmt_integer(x, colon, atsign, radix, mincol, padchar, commachar);
803  }        }      
804    
805  void  static void
806  fmt_integer(object x, bool colon, bool atsign, int radix, int mincol, int padchar, int commachar)  fmt_integer(object x, bool colon, bool atsign, int radix, int mincol, int padchar, int commachar)
807  {  {
808          int l, l1;          int l, l1;
# Line 752  fmt_integer(object x, bool colon, bool a Line 859  fmt_integer(object x, bool colon, bool a
859          }          }
860  }  }
861    
862  int  static int
863  fmt_nonillion(int s, int i, bool b, bool o, int t)  fmt_nonillion(int s, int i, bool b, bool o, int t)
864  {  {
865          int j;          int j;
# Line 773  fmt_nonillion(int s, int i, bool b, bool Line 880  fmt_nonillion(int s, int i, bool b, bool
880          return(fmt_thousand(s, i, b, o, t));          return(fmt_thousand(s, i, b, o, t));
881  }                }              
882    
883  int  static int
884  fmt_thousand(int s, int i, bool b, bool o, int t)  fmt_thousand(int s, int i, bool b, bool o, int t)
885  {  {
886          if (i == 3 && fmt_tempstr(s) > '0') {          if (i == 3 && fmt_tempstr(s) > '0') {
# Line 830  fmt_thousand(int s, int i, bool b, bool Line 937  fmt_thousand(int s, int i, bool b, bool
937          return(b);          return(b);
938  }  }
939                    
940  void  static void
941  fmt_write_numeral(int s, int i)  fmt_write_numeral(int s, int i)
942  {  {
943          writestr_stream(fmt_numeral[fmt_tempstr(s) - '0' + i], fmt_stream);          writestr_stream(fmt_numeral[fmt_tempstr(s) - '0' + i], fmt_stream);
944  }  }
945    
946  void  static void
947  fmt_write_ordinal(int s, int i)  fmt_write_ordinal(int s, int i)
948  {  {
949          writestr_stream(fmt_ordinal[fmt_tempstr(s) - '0' + i], fmt_stream);          writestr_stream(fmt_ordinal[fmt_tempstr(s) - '0' + i], fmt_stream);
950  }  }
951    
952  void  static void
953  fmt_roman(int i, int one, int five, int ten, int colon)  fmt_roman(int i, int one, int five, int ten, int colon)
954  {  {
955          int j;          int j;
# Line 865  fmt_roman(int i, int one, int five, int Line 972  fmt_roman(int i, int one, int five, int
972          }          }
973  }  }
974    
975  void  static void
976  fmt_plural(bool colon, bool atsign)  fmt_plural(bool colon, bool atsign)
977  {  {
978          fmt_max_param(0);          fmt_max_param(0);
# Line 886  fmt_plural(bool colon, bool atsign) Line 993  fmt_plural(bool colon, bool atsign)
993                          writec_stream('s', fmt_stream);                          writec_stream('s', fmt_stream);
994  }  }
995    
996  void  static void
997  fmt_character(bool colon, bool atsign)  fmt_character(bool colon, bool atsign)
998  {  {
999          object x;          object x;
# Line 907  fmt_character(bool colon, bool atsign) Line 1014  fmt_character(bool colon, bool atsign)
1014                  writec_stream(fmt_tempstr(i), fmt_stream);                  writec_stream(fmt_tempstr(i), fmt_stream);
1015  }  }
1016    
1017  void  static void
1018  fmt_fix_float(bool colon, bool atsign)  fmt_fix_float(bool colon, bool atsign)
1019  {  {
1020          int w, d, k, overflowchar, padchar;          int w, d, k, overflowchar, padchar;
# Line 1064  OVER: Line 1171  OVER:
1171          return;          return;
1172  }  }
1173    
1174  int  static int
1175  fmt_exponent_length(int e)  fmt_exponent_length(int e)
1176  {  {
1177          int i;          int i;
# Line 1078  fmt_exponent_length(int e) Line 1185  fmt_exponent_length(int e)
1185          return(i);          return(i);
1186  }  }
1187    
1188  void  static void
1189  fmt_exponent(int e)  fmt_exponent(int e)
1190  {  {
1191          if (e == 0) {          if (e == 0) {
# Line 1090  fmt_exponent(int e) Line 1197  fmt_exponent(int e)
1197          fmt_exponent1(e);          fmt_exponent1(e);
1198  }  }
1199                    
1200  void  static void
1201  fmt_exponent1(int e)  fmt_exponent1(int e)
1202  {  {
1203          if (e == 0)          if (e == 0)
# Line 1099  fmt_exponent1(int e) Line 1206  fmt_exponent1(int e)
1206          writec_stream('0' + e%10, fmt_stream);          writec_stream('0' + e%10, fmt_stream);
1207  }  }
1208    
1209  void  static void
1210  fmt_exponential_float(bool colon, bool atsign)  fmt_exponential_float(bool colon, bool atsign)
1211  {  {
1212          int w, d, e, k, overflowchar, padchar, exponentchar;          int w, d, e, k, overflowchar, padchar, exponentchar;
# Line 1303  OVER: Line 1410  OVER:
1410          return;          return;
1411  }  }
1412    
1413  void  static void
1414  fmt_general_float(bool colon, bool atsign)  fmt_general_float(bool colon, bool atsign)
1415  {  {
1416          int w, d, e, k, overflowchar, padchar, exponentchar;          int w, d, e, k, overflowchar, padchar, exponentchar;
# Line 1395  fmt_general_float(bool colon, bool atsig Line 1502  fmt_general_float(bool colon, bool atsig
1502          vs_reset;          vs_reset;
1503  }  }
1504    
1505  void  static void
1506  fmt_dollars_float(bool colon, bool atsign)  fmt_dollars_float(bool colon, bool atsign)
1507  {  {
1508          int d, n, w, padchar;          int d, n, w, padchar;
# Line 1482  fmt_dollars_float(bool colon, bool atsig Line 1589  fmt_dollars_float(bool colon, bool atsig
1589          vs_reset;          vs_reset;
1590  }  }
1591    
1592  void  static void
1593  fmt_percent(bool colon, bool atsign)  fmt_percent(bool colon, bool atsign)
1594  {  {
1595          int n, i;          int n, i;
# Line 1499  fmt_percent(bool colon, bool atsign) Line 1606  fmt_percent(bool colon, bool atsign)
1606          }          }
1607  }  }
1608    
1609  void  static void
1610  fmt_ampersand(bool colon, bool atsign)  fmt_ampersand(bool colon, bool atsign)
1611  {  {
1612          int n;          int n;
# Line 1517  fmt_ampersand(bool colon, bool atsign) Line 1624  fmt_ampersand(bool colon, bool atsign)
1624          fmt_indents = 0;          fmt_indents = 0;
1625  }  }
1626    
1627  void  static void
1628  fmt_bar(bool colon, bool atsign)  fmt_bar(bool colon, bool atsign)
1629  {  {
1630          int n;          int n;
# Line 1530  fmt_bar(bool colon, bool atsign) Line 1637  fmt_bar(bool colon, bool atsign)
1637                  writec_stream('\f', fmt_stream);                  writec_stream('\f', fmt_stream);
1638  }  }
1639    
1640  void  static void
1641  fmt_tilde(bool colon, bool atsign)  fmt_tilde(bool colon, bool atsign)
1642  {  {
1643          int n;          int n;
# Line 1543  fmt_tilde(bool colon, bool atsign) Line 1650  fmt_tilde(bool colon, bool atsign)
1650                  writec_stream('~', fmt_stream);                  writec_stream('~', fmt_stream);
1651  }  }
1652    
1653  void  static void
1654  fmt_newline(bool colon, bool atsign)  fmt_newline(bool colon, bool atsign)
1655  {  {
1656    
# Line 1558  fmt_newline(bool colon, bool atsign) Line 1665  fmt_newline(bool colon, bool atsign)
1665          }          }
1666  }  }
1667    
1668  void  static void
1669  fmt_tabulate(bool colon, bool atsign)  fmt_tabulate(bool colon, bool atsign)
1670  {  {
1671          int colnum, colinc;          int colnum, colinc;
# Line 1594  fmt_tabulate(bool colon, bool atsign) Line 1701  fmt_tabulate(bool colon, bool atsign)
1701          }          }
1702  }  }
1703    
1704  void  static void
1705  fmt_asterisk(bool colon, bool atsign)  fmt_asterisk(bool colon, bool atsign)
1706  {  {
1707          int n;          int n;
# Line 1618  fmt_asterisk(bool colon, bool atsign) Line 1725  fmt_asterisk(bool colon, bool atsign)
1725          }          }
1726  }        }      
1727    
1728  void  static void
1729  fmt_indirection(bool colon, bool atsign) {  fmt_indirection(bool colon, bool atsign) {
1730          object s, l;          object s, l;
1731          fmt_old;          fmt_old;
# Line 1661  fmt_indirection(bool colon, bool atsign) Line 1768  fmt_indirection(bool colon, bool atsign)
1768          }          }
1769  }  }
1770    
1771  void  static void
1772  fmt_case(bool colon, bool atsign)  fmt_case(bool colon, bool atsign)
1773  {  {
1774          VOL object x;          VOL object x;
# Line 1729  fmt_case(bool colon, bool atsign) Line 1836  fmt_case(bool colon, bool atsign)
1836                  longjmp(*fmt_jmp_bufp, up_colon);                  longjmp(*fmt_jmp_bufp, up_colon);
1837  }  }
1838    
1839  void  static void
1840  fmt_conditional(bool colon, bool atsign)  fmt_conditional(bool colon, bool atsign)
1841  {  {
1842          int i, j, k;          int i, j, k;
# Line 1818  fmt_conditional(bool colon, bool atsign) Line 1925  fmt_conditional(bool colon, bool atsign)
1925          }          }
1926  }        }      
1927    
1928  void  static void
1929  fmt_iteration(bool colon, bool atsign) {  fmt_iteration(bool colon, bool atsign) {
1930          int i,n;          int i,n;
1931          VOL int j;          VOL int j;
# Line 1943  fmt_iteration(bool colon, bool atsign) { Line 2050  fmt_iteration(bool colon, bool atsign) {
2050    
2051  #define FORMAT_DIRECTIVE_LIMIT 100  #define FORMAT_DIRECTIVE_LIMIT 100
2052    
2053  void  static void
2054  fmt_justification(volatile bool colon, bool atsign)  fmt_justification(volatile bool colon, bool atsign)
2055  {  {
2056          int mincol, colinc, minpad, padchar;          int mincol, colinc, minpad, padchar;
# Line 2043  fmt_justification(volatile bool colon, b Line 2150  fmt_justification(volatile bool colon, b
2150  }  }
2151    
2152    
2153  void  static void
2154  fmt_up_and_out(bool colon, bool atsign)  fmt_up_and_out(bool colon, bool atsign)
2155  {  {
2156          int i, j, k;          int i, j, k;
# Line 2072  fmt_up_and_out(bool colon, bool atsign) Line 2179  fmt_up_and_out(bool colon, bool atsign)
2179  }  }
2180    
2181    
2182  void  static void
2183  fmt_semicolon(bool colon, bool atsign)  fmt_semicolon(bool colon, bool atsign)
2184  {  {
2185          fmt_not_atsign(atsign);          fmt_not_atsign(atsign);
# Line 2084  fmt_semicolon(bool colon, bool atsign) Line 2191  fmt_semicolon(bool colon, bool atsign)
2191  }  }
2192    
2193  DEFUNO_NEW("FORMAT",object,fLformat,LISP  DEFUNO_NEW("FORMAT",object,fLformat,LISP
2194         ,2,F_ARG_LIMIT,NONE,OO,OO,OO,OO,Lformat,(object strm, object control,...),"")         ,2,F_ARG_LIMIT,NONE,OO,OO,OO,OO,void,Lformat,(object strm, object control,...),"")
2195  {       va_list ap;  {       va_list ap;
2196          VOL int nargs= VFUN_NARGS;          VOL int nargs= VFUN_NARGS;
2197          VOL object x = OBJNULL;          VOL object x = OBJNULL;
# Line 2155  L: Line 2262  L:
2262    
2263  /*  object c_apply_n(long int (*fn) (), int n, object *x); */  /*  object c_apply_n(long int (*fn) (), int n, object *x); */
2264    
2265  void  static void
2266  fmt_error(char *s)  fmt_error(char *s)
2267  {  {
2268          vs_push(make_simple_string(s));          vs_push(make_simple_string(s));

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26