[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] Add bc
From:       Gavin Howard <gavin.d.howard () gmail ! com>
Date:       2018-10-29 15:12:22
Message-ID: CAF=dzRM4wMvvh9iAySrYTAmbgwYO2fiAUu48WOxcayxt-A3V6w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello,

Since my first attempt to send a patch to add my bc to busybox failed
because it was too big, I thought that I would send it in pieces. This is
the first patch (which is at the bottom of the email), and it is for
removing the current dc, which will be replaced by a complete dc that is
combined with my bc.

Also, I have included the "make bloatcheck" output for bc, dc, and both, in
that order, below.

bc:

function                                             old     new   delta
.rodata                                           150820  156540   +5720
bc_program_exec                                        -    4457   +4457
bc_vm_run                                              -    2237   +2237
bc_lib                                                 -    1878   +1878
bc_parse_expr                                          -    1470   +1470
bc_num_k                                               -    1304   +1304
bc_num_print                                           -    1139   +1139
bc_num_parse                                           -    1063   +1063
bc_lex_token                                           -    1053   +1053
bc_num_sqrt                                            -     959    +959
bc_num_d                                               -     821    +821
bc_program_init                                        -     787    +787
bc_parse_for                                           -     743    +743
bc_num_p                                               -     725    +725
bc_args                                                -     643    +643
bc_parse_endBody                                       -     561    +561
bc_vm_process                                          -     529    +529
bc_program_assign                                      -     509    +509
bc_parse_stmt                                          -     488    +488
bc_lex_number                                          -     432    +432
bc_err_msgs                                            -     432    +432
bc_parse_func                                          -     419    +419
bc_parse_incdec                                        -     416    +416
bc_num_m                                               -     409    +409
bc_program_num                                         -     399    +399
bc_num_a                                               -     378    +378
bc_read_line                                           -     374    +374
bc_parse_while                                         -     372    +372
bc_read_file                                           -     370    +370
bc_parse_name                                          -     357    +357
bc_args_lopt                                           -     352    +352
bc_parse_auto                                          -     327    +327
bc_program_binOpPrep                                   -     318    +318
bc_num_r                                               -     312    +312
bc_vm_posixError                                       -     304    +304
bc_parse_create                                        -     300    +300
bc_num_s                                               -     300    +300
bc_parse_if                                            -     295    +295
bc_num_cmp                                             -     295    +295
bc_program_addFunc                                     -     284    +284
bc_parse_return                                        -     274    +274
bc_program_search                                      -     270    +270
bc_parse_operator                                      -     269    +269
bc_num_divmod                                          -     268    +268
bc_parse_call                                          -     261    +261
bc_parse_loopExit                                      -     251    +251
bc_parse_print                                         -     244    +244
bc_parse_reset                                         -     241    +241
bc_parse_else                                          -     233    +233
bc_num_printDigits                                     -     229    +229
bc_program_reset                                       -     223    +223
bc_parse_scale                                         -     222    +222
bc_vm_error                                            -     221    +221
bc_parse_string                                        -     221    +221
bc_lex_kws                                             -     220    +220
bc_num_binary                                          -     212    +212
bc_lex_identifier                                      -     211    +211
bc_parse_params                                        -     209    +209
bc_parse_number                                        -     206    +206
bc_parse_builtin                                       -     205    +205
bc_parse_rightParen                                    -     195    +195
bc_map_insert                                          -     195    +195
bc_array_expand                                        -     195    +195
bc_parse_minus                                         -     192    +192
bc_program_free                                        -     188    +188
bc_num_rem                                             -     184    +184
bc_parse_pushName                                      -     173    +173
bc_array_copy                                          -     164    +164
bc_parse_pushIndex                                     -     158    +158
bc_copyright                                           -     155    +155
bc_func_insert                                         -     147    +147
bc_vec_concat                                          -     143    +143
bc_num_split                                           -     142    +142
bc_lex_name                                            -     138    +138
bc_parse_read                                          -     134    +134
bc_parse_body                                          -     133    +133
bc_parse_text                                          -     127    +127
bc_func_init                                           -     122    +122
bc_vec_string                                          -     121    +121
bc_lex_string                                          -     119    +119
bc_num_printHex                                        -     117    +117
bc_program_prep                                        -     113    +113
bc_num_ulong2num                                       -     110    +110
bc_vm_sig                                              -     104    +104
bc_lex_comment                                         -     103    +103
bc_num_shift                                           -     101    +101
bc_vm_info                                             -      99     +99
bcg                                                    -      96     +96
bc_parse_parse                                         -      94     +94
bc_main                                                -      91     +91
bc_num_ulong                                           -      89     +89
bc_program_name                                        -      87     +87
bc_num_retireMul                                       -      87     +87
bc_veco_find                                           -      84     +84
bc_array_init                                          -      83     +83
bc_num_extend                                          -      80     +80
bc_num_sub                                             -      78     +78
bc_parse_noElse                                        -      77     +77
bc_num_add                                             -      75     +75
bc_vec_push                                            -      74     +74
bc_num_compare                                         -      74     +74
bc_lex_next                                            -      74     +74
bc_vec_grow                                            -      73     +73
bc_num_init                                            -      72     +72
bc_lex_whitespace                                      -      72     +72
bc_num_copy                                            -      71     +71
bc_map_index                                           -      69     +69
bc_num_printNewline                                    -      67     +67
bc_num_expand                                          -      66     +66
bc_vec_npop                                            -      65     +65
bc_vec_expand                                          -      64     +64
bc_num_subArrays                                       -      64     +64
bc_program_binOpRetire                                 -      62     +62
bc_vm_free                                             -      61     +61
bc_parse_exprs                                         -      60     +60
bc_parse_free                                          -      59     +59
bc_err_ids                                             -      57     +57
bc_errs                                                -      56     +56
bc_program_index                                       -      55     +55
bc_vec_init                                            -      54     +54
bc_parse_startBody                                     -      54     +54
bc_parse_addFunc                                       -      54     +54
bc_num_mul                                             -      52     +52
bc_num_mod                                             -      52     +52
bc_num_div                                             -      52     +52
bc_parse_ops                                           -      50     +50
bc_lex_text                                            -      50     +50
bc_num_clean                                           -      49     +49
bc_program_ops                                         -      48     +48
bc_result_free                                         -      46     +46
bc_program_retire                                      -      45     +45
bc_lex_lineComment                                     -      42     +42
bc_program_len                                         -      41     +41
bc_num_truncate                                        -      37     +37
bc_sig_msg                                             -      34     +34
bc_num_ten                                             -      34     +34
bc_lex_assign                                          -      28     +28
bc_func_free                                           -      28     +28
bc_num_one                                             -      27     +27
bc_num_pow                                             -      24     +24
bc_parse_expression                                    -      23     +23
packed_usage                                       32742   32764     +22
bc_vec_free                                            -      22     +22
bc_program_ready_msg                                   -      22     +22
bc_num_zero                                            -      21     +21
bc_lex_init                                            -      20     +20
bc_vec_item_rev                                        -      19     +19
bc_parse_init                                          -      19     +19
bc_warn_fmt                                            -      17     +17
bc_num_hex_digits                                      -      17     +17
bc_parse_next_rel                                      -      16     +16
bc_parse_next_read                                     -      16     +16
bc_parse_next_print                                    -      16     +16
bc_parse_next_param                                    -      16     +16
bc_parse_next_for                                      -      16     +16
bc_parse_next_expr                                     -      16     +16
bc_parse_next_elem                                     -      16     +16
bc_err_fmt                                             -      15     +15
bc_id_cmp                                              -      11     +11
bc_string_free                                         -       8      +8
bc_program_stdin_name                                  -       8      +8
bc_program_exprs_name                                  -       8      +8
bc_num_free                                            -       8      +8
bc_lib_name                                            -       8      +8
bc_id_free                                             -       8      +8
bc_args_env_name                                       -       8      +8
applet_main                                         3120    3128      +8
bc_func_read                                           -       7      +7
bc_func_main                                           -       7      +7
bc_err_line                                            -       7      +7
bc_program_scale                                       -       5      +5
bc_name                                                -       3      +3
applet_names                                        2692    2695      +3
applet_install_loc                                   195     196      +1
------------------------------------------------------------------------------
(add/remove: 170/0 grow/shrink: 5/0 up/down: 46767/0)       Total: 46767
bytes
   text    data     bss     dec     hex filename
 972633   17543    1888 992064   f2340 busybox_old
1018028   18535    1984 1038547   fd8d3 busybox_unstripped

dc:

function                                             old     new   delta
bc_program_exec                                        -    5368   +5368
.rodata                                           150820  153944   +3124
bc_vm_run                                              -    1779   +1779
bc_num_k                                               -    1304   +1304
bc_num_parse                                           -    1063   +1063
bc_num_sqrt                                            -     959    +959
bc_program_init                                        -     836    +836
bc_num_d                                               -     821    +821
bc_num_printNum                                        -     752    +752
bc_num_p                                               -     725    +725
bc_program_print                                       -     673    +673
bc_num_modexp                                          -     600    +600
bc_vm_process                                          -     529    +529
bc_args                                                -     515    +515
dc_parse_token                                         -     461    +461
bc_lex_number                                          -     432    +432
bc_num_m                                               -     409    +409
bc_program_num                                         -     399    +399
bc_program_pushVar                                     -     380    +380
bc_num_a                                               -     378    +378
bc_num_print                                           -     375    +375
bc_read_line                                           -     374    +374
bc_read_file                                           -     370    +370
dc_lex_tokens                                          -     364    +364
dc_lex_token                                           -     355    +355
bc_args_lopt                                           -     352    +352
bc_err_msgs                                            -     344    +344
dc_parse_insts                                         -     332    +332
bc_program_binOpPrep                                   -     318    +318
bc_num_r                                               -     312    +312
dc_lex_string                                          -     300    +300
bc_parse_create                                        -     300    +300
bc_num_s                                               -     300    +300
bc_num_cmp                                             -     295    +295
dc_parse_string                                        -     290    +290
bc_program_addFunc                                     -     284    +284
bc_program_search                                      -     270    +270
bc_num_divmod                                          -     268    +268
bc_parse_reset                                         -     241    +241
bc_num_printDigits                                     -     229    +229
bc_program_reset                                       -     223    +223
bc_vm_error                                            -     221    +221
bc_num_binary                                          -     212    +212
bc_parse_number                                        -     206    +206
dc_parse_expr                                          -     203    +203
dc_parse_mem                                           -     201    +201
bc_program_free                                        -     200    +200
bc_map_insert                                          -     195    +195
bc_array_expand                                        -     195    +195
bc_program_assignStr                                   -     194    +194
dc_lex_register                                        -     190    +190
bc_num_rem                                             -     184    +184
dc_parse_cond                                          -     183    +183
bc_parse_pushName                                      -     173    +173
packed_usage                                       32742   32907    +165
bc_parse_pushIndex                                     -     158    +158
bc_copyright                                           -     155    +155
bc_vec_concat                                          -     143    +143
bc_num_split                                           -     142    +142
bc_lex_name                                            -     138    +138
bc_result_copy                                         -     135    +135
bc_parse_text                                          -     127    +127
bc_func_init                                           -     122    +122
bc_vec_string                                          -     121    +121
bc_num_printHex                                        -     117    +117
bc_program_prep                                        -     113    +113
bc_num_ulong2num                                       -     110    +110
bc_vm_sig                                              -     104    +104
bc_num_shift                                           -     101    +101
bc_vm_info                                             -      99     +99
dc_parse_register                                      -      93     +93
dc_main                                                -      91     +91
bc_num_ulong                                           -      89     +89
bcg                                                    -      88     +88
bc_program_name                                        -      87     +87
bc_num_retireMul                                       -      87     +87
bc_veco_find                                           -      84     +84
bc_array_init                                          -      83     +83
bc_num_extend                                          -      80     +80
bc_num_sub                                             -      78     +78
bc_num_add                                             -      75     +75
bc_vec_push                                            -      74     +74
bc_num_compare                                         -      74     +74
bc_lex_next                                            -      74     +74
bc_vec_grow                                            -      73     +73
bc_num_init                                            -      72     +72
bc_lex_whitespace                                      -      72     +72
bc_num_copy                                            -      71     +71
bc_num_printNewline                                    -      67     +67
bc_num_expand                                          -      66     +66
bc_vec_npop                                            -      65     +65
bc_vec_expand                                          -      64     +64
bc_num_subArrays                                       -      64     +64
bc_program_binOpRetire                                 -      62     +62
bc_vm_free                                             -      61     +61
bc_parse_free                                          -      59     +59
bc_program_index                                       -      55     +55
bc_vec_init                                            -      54     +54
bc_parse_addFunc                                       -      54     +54
dc_parse_parse                                         -      53     +53
dc_lex_regs                                            -      52     +52
bc_num_mul                                             -      52     +52
bc_num_mod                                             -      52     +52
bc_num_div                                             -      52     +52
bc_lex_text                                            -      50     +50
bc_num_clean                                           -      49     +49
bc_program_ops                                         -      48     +48
bc_errs                                                -      48     +48
bc_err_ids                                             -      47     +47
bc_result_free                                         -      46     +46
bc_program_retire                                      -      45     +45
bc_lex_lineComment                                     -      42     +42
bc_program_len                                         -      41     +41
bc_num_printChar                                       -      41     +41
bc_num_truncate                                        -      37     +37
bc_num_ten                                             -      34     +34
dc_sig_msg                                             -      31     +31
bc_func_free                                           -      28     +28
bc_num_one                                             -      27     +27
bc_num_pow                                             -      24     +24
bc_num_stream                                          -      23     +23
bc_vec_free                                            -      22     +22
bc_program_ready_msg                                   -      22     +22
bc_num_zero                                            -      21     +21
bc_lex_init                                            -      20     +20
dc_parse_init                                          -      19     +19
bc_vec_item_rev                                        -      19     +19
bc_num_hex_digits                                      -      17     +17
bc_err_fmt                                             -      15     +15
bc_id_cmp                                              -      11     +11
bc_string_free                                         -       8      +8
bc_program_stdin_name                                  -       8      +8
bc_program_exprs_name                                  -       8      +8
bc_num_free                                            -       8      +8
bc_id_free                                             -       8      +8
applet_main                                         3120    3128      +8
bc_func_read                                           -       7      +7
bc_func_main                                           -       7      +7
bc_err_line                                            -       7      +7
bc_program_scale                                       -       5      +5
dc_name                                                -       3      +3
applet_names                                        2692    2695      +3
applet_install_loc                                   195     196      +1
------------------------------------------------------------------------------
(add/remove: 139/0 grow/shrink: 5/0 up/down: 35895/0)       Total: 35895
bytes
   text    data     bss     dec     hex filename
 972633   17543    1888 992064   f2340 busybox_old
1008399   18431    1976 1028806   fb2c6 busybox_unstripped

both:

function                                             old     new   delta
.rodata                                           150820  157638   +6818
bc_program_exec                                        -    6470   +6470
bc_vm_run                                              -    2245   +2245
bc_lib                                                 -    1878   +1878
bc_parse_expr                                          -    1470   +1470
bc_num_k                                               -    1304   +1304
bc_num_parse                                           -    1063   +1063
bc_lex_token                                           -    1053   +1053
bc_num_sqrt                                            -     959    +959
bc_program_init                                        -     836    +836
bc_num_d                                               -     821    +821
bc_num_printNum                                        -     752    +752
bc_parse_for                                           -     743    +743
bc_num_p                                               -     725    +725
bc_program_print                                       -     673    +673
bc_args                                                -     668    +668
bc_num_modexp                                          -     600    +600
bc_program_assign                                      -     592    +592
bc_parse_endBody                                       -     561    +561
bc_vm_process                                          -     529    +529
bc_parse_stmt                                          -     488    +488
dc_parse_token                                         -     461    +461
bc_err_msgs                                            -     440    +440
bc_lex_number                                          -     432    +432
bc_program_copyToVar                                   -     429    +429
bc_parse_func                                          -     419    +419
bc_parse_incdec                                        -     416    +416
bc_num_m                                               -     409    +409
bc_program_num                                         -     399    +399
bc_program_pushVar                                     -     380    +380
bc_num_a                                               -     378    +378
bc_num_print                                           -     375    +375
bc_read_line                                           -     374    +374
bc_parse_while                                         -     372    +372
bc_read_file                                           -     370    +370
dc_lex_tokens                                          -     364    +364
bc_parse_name                                          -     357    +357
dc_lex_token                                           -     355    +355
bc_args_lopt                                           -     352    +352
dc_parse_insts                                         -     332    +332
bc_parse_auto                                          -     327    +327
bc_program_binOpPrep                                   -     318    +318
bc_num_r                                               -     312    +312
bc_vm_posixError                                       -     304    +304
dc_lex_string                                          -     300    +300
bc_parse_create                                        -     300    +300
bc_num_s                                               -     300    +300
bc_parse_if                                            -     295    +295
bc_num_cmp                                             -     295    +295
dc_parse_string                                        -     290    +290
bc_program_addFunc                                     -     284    +284
bc_parse_return                                        -     274    +274
bc_program_search                                      -     270    +270
bc_parse_operator                                      -     269    +269
bc_num_divmod                                          -     268    +268
bc_parse_call                                          -     261    +261
bc_parse_loopExit                                      -     251    +251
bc_parse_print                                         -     244    +244
bc_parse_reset                                         -     241    +241
bc_parse_else                                          -     233    +233
bc_num_printDigits                                     -     229    +229
bc_program_reset                                       -     223    +223
bc_parse_scale                                         -     222    +222
bc_vm_error                                            -     221    +221
bc_parse_string                                        -     221    +221
bc_lex_kws                                             -     220    +220
bc_num_binary                                          -     212    +212
bc_lex_identifier                                      -     211    +211
bc_parse_params                                        -     209    +209
bc_parse_number                                        -     206    +206
bc_parse_builtin                                       -     205    +205
dc_parse_expr                                          -     203    +203
dc_parse_mem                                           -     201    +201
bc_program_free                                        -     200    +200
bc_parse_rightParen                                    -     195    +195
bc_map_insert                                          -     195    +195
bc_array_expand                                        -     195    +195
bc_program_assignStr                                   -     194    +194
bc_parse_minus                                         -     192    +192
dc_lex_register                                        -     190    +190
bc_num_rem                                             -     184    +184
dc_parse_cond                                          -     183    +183
packed_usage                                       32742   32921    +179
bc_parse_pushName                                      -     173    +173
bc_array_copy                                          -     164    +164
bc_parse_pushIndex                                     -     158    +158
bc_copyright                                           -     155    +155
bc_func_insert                                         -     147    +147
bc_vec_concat                                          -     143    +143
bc_num_split                                           -     142    +142
bc_lex_name                                            -     138    +138
bc_result_copy                                         -     135    +135
bc_parse_read                                          -     134    +134
bc_parse_body                                          -     133    +133
bc_parse_text                                          -     127    +127
bc_func_init                                           -     122    +122
bc_vec_string                                          -     121    +121
bc_lex_string                                          -     119    +119
bc_num_printHex                                        -     117    +117
bc_program_prep                                        -     113    +113
bc_num_ulong2num                                       -     110    +110
bcg                                                    -     104    +104
bc_vm_sig                                              -     104    +104
bc_lex_comment                                         -     103    +103
bc_num_shift                                           -     101    +101
bc_vm_info                                             -      99     +99
bc_parse_parse                                         -      94     +94
dc_parse_register                                      -      93     +93
dc_main                                                -      91     +91
bc_main                                                -      91     +91
bc_num_ulong                                           -      89     +89
bc_program_name                                        -      87     +87
bc_num_retireMul                                       -      87     +87
bc_veco_find                                           -      84     +84
bc_array_init                                          -      83     +83
bc_num_extend                                          -      80     +80
bc_num_sub                                             -      78     +78
bc_parse_noElse                                        -      77     +77
bc_num_add                                             -      75     +75
bc_vec_push                                            -      74     +74
bc_num_compare                                         -      74     +74
bc_lex_next                                            -      74     +74
bc_vec_grow                                            -      73     +73
bc_num_init                                            -      72     +72
bc_lex_whitespace                                      -      72     +72
bc_num_copy                                            -      71     +71
bc_map_index                                           -      69     +69
bc_num_printNewline                                    -      67     +67
bc_num_expand                                          -      66     +66
bc_vec_npop                                            -      65     +65
bc_vec_expand                                          -      64     +64
bc_num_subArrays                                       -      64     +64
bc_program_binOpRetire                                 -      62     +62
bc_vm_free                                             -      61     +61
bc_parse_exprs                                         -      60     +60
bc_parse_free                                          -      59     +59
bc_err_ids                                             -      59     +59
bc_errs                                                -      56     +56
bc_program_index                                       -      55     +55
bc_vec_init                                            -      54     +54
bc_parse_startBody                                     -      54     +54
bc_parse_addFunc                                       -      54     +54
dc_parse_parse                                         -      53     +53
dc_lex_regs                                            -      52     +52
bc_num_mul                                             -      52     +52
bc_num_mod                                             -      52     +52
bc_num_div                                             -      52     +52
bc_parse_ops                                           -      50     +50
bc_lex_text                                            -      50     +50
bc_num_clean                                           -      49     +49
bc_program_ops                                         -      48     +48
bc_result_free                                         -      46     +46
bc_program_retire                                      -      45     +45
bc_lex_lineComment                                     -      42     +42
bc_program_len                                         -      41     +41
bc_num_printChar                                       -      41     +41
bc_num_truncate                                        -      37     +37
bc_sig_msg                                             -      34     +34
bc_num_ten                                             -      34     +34
dc_sig_msg                                             -      31     +31
bc_lex_assign                                          -      28     +28
bc_func_free                                           -      28     +28
bc_num_one                                             -      27     +27
bc_num_pow                                             -      24     +24
bc_parse_expression                                    -      23     +23
bc_num_stream                                          -      23     +23
bc_vec_free                                            -      22     +22
bc_program_ready_msg                                   -      22     +22
bc_num_zero                                            -      21     +21
bc_lex_init                                            -      20     +20
dc_parse_init                                          -      19     +19
bc_vec_item_rev                                        -      19     +19
bc_parse_init                                          -      19     +19
bc_warn_fmt                                            -      17     +17
bc_num_hex_digits                                      -      17     +17
bc_parse_next_rel                                      -      16     +16
bc_parse_next_read                                     -      16     +16
bc_parse_next_print                                    -      16     +16
bc_parse_next_param                                    -      16     +16
bc_parse_next_for                                      -      16     +16
bc_parse_next_expr                                     -      16     +16
bc_parse_next_elem                                     -      16     +16
applet_main                                         3120    3136     +16
bc_err_fmt                                             -      15     +15
bc_id_cmp                                              -      11     +11
bc_string_free                                         -       8      +8
bc_program_stdin_name                                  -       8      +8
bc_program_exprs_name                                  -       8      +8
bc_num_free                                            -       8      +8
bc_lib_name                                            -       8      +8
bc_id_free                                             -       8      +8
bc_args_env_name                                       -       8      +8
bc_func_read                                           -       7      +7
bc_func_main                                           -       7      +7
bc_err_line                                            -       7      +7
applet_names                                        2692    2698      +6
bc_program_scale                                       -       5      +5
dc_name                                                -       3      +3
bc_name                                                -       3      +3
applet_install_loc                                   195     196      +1
------------------------------------------------------------------------------
(add/remove: 196/0 grow/shrink: 5/0 up/down: 55925/0)       Total: 55925
bytes
   text    data     bss     dec     hex filename
 972633   17543    1888 992064   f2340 busybox_old
1026266   18543    1992 1046801   ff911 busybox_unstripped

Patch:

From 6b9c6e3a7f0d9f8193aa6d1337939be86cb41e7a Mon Sep 17 00:00:00 2001
From: Gavin Howard <yzena.tech@gmail.com>
Date: Mon, 29 Oct 2018 08:56:48 -0600
Subject: [PATCH] Remove dc

---
 miscutils/dc.c | 304 -------------------------------------------------
 1 file changed, 304 deletions(-)
 delete mode 100644 miscutils/dc.c

diff --git a/miscutils/dc.c b/miscutils/dc.c
deleted file mode 100644
index b922a7184..000000000
--- a/miscutils/dc.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Licensed under GPLv2 or later, see file LICENSE in this source tree.
- */
-//config:config DC
-//config: bool "dc (4.2 kb)"
-//config: default y
-//config: help
-//config: Dc is a reverse-polish desk calculator which supports unlimited
-//config: precision arithmetic.
-//config:
-//config:config FEATURE_DC_LIBM
-//config: bool "Enable power and exp functions (requires libm)"
-//config: default y
-//config: depends on DC
-//config: help
-//config: Enable power and exp functions.
-//config: NOTE: This will require libm to be present for linking.
-
-//applet:IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP))
-
-//kbuild:lib-$(CONFIG_DC) += dc.o
-
-//usage:#define dc_trivial_usage
-//usage:       "EXPRESSION..."
-//usage:
-//usage:#define dc_full_usage "\n\n"
-//usage:       "Tiny RPN calculator. Operations:\n"
-//usage:       "+, add, -, sub, *, mul, /, div, %, mod,
"IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n"
-//usage:       "p - print top of the stack (without popping),\n"
-//usage:       "f - print entire stack,\n"
-//usage:       "o - pop the value and set output radix (must be 10, 16, 8
or 2).\n"
-//usage:       "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' ->
16"
-//usage:
-//usage:#define dc_example_usage
-//usage:       "$ dc 2 2 + p\n"
-//usage:       "4\n"
-//usage:       "$ dc 8 8 \\* 2 2 + / p\n"
-//usage:       "16\n"
-//usage:       "$ dc 0 1 and p\n"
-//usage:       "0\n"
-//usage:       "$ dc 0 1 or p\n"
-//usage:       "1\n"
-//usage:       "$ echo 72 9 div 8 mul p | dc\n"
-//usage:       "64\n"
-
-#include "libbb.h"
-#include "common_bufsiz.h"
-#include <math.h>
-
-#if 0
-typedef unsigned data_t;
-#define DATA_FMT ""
-#elif 0
-typedef unsigned long data_t;
-#define DATA_FMT "l"
-#else
-typedef unsigned long long data_t;
-#define DATA_FMT "ll"
-#endif
-
-
-struct globals {
- unsigned pointer;
- unsigned base;
- double stack[1];
-} FIX_ALIASING;
-enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) /
sizeof(double) };
-#define G (*(struct globals*)bb_common_bufsiz1)
-#define pointer   (G.pointer   )
-#define base      (G.base      )
-#define stack     (G.stack     )
-#define INIT_G() do { \
- setup_common_bufsiz(); \
- base = 10; \
-} while (0)
-
-
-static void check_under(void)
-{
- if (pointer == 0)
- bb_error_msg_and_die("stack underflow");
-}
-
-static void push(double a)
-{
- if (pointer >= STACK_SIZE)
- bb_error_msg_and_die("stack overflow");
- stack[pointer++] = a;
-}
-
-static double pop(void)
-{
- check_under();
- return stack[--pointer];
-}
-
-static void add(void)
-{
- push(pop() + pop());
-}
-
-static void sub(void)
-{
- double subtrahend = pop();
-
- push(pop() - subtrahend);
-}
-
-static void mul(void)
-{
- push(pop() * pop());
-}
-
-#if ENABLE_FEATURE_DC_LIBM
-static void power(void)
-{
- double topower = pop();
-
- push(pow(pop(), topower));
-}
-#endif
-
-static void divide(void)
-{
- double divisor = pop();
-
- push(pop() / divisor);
-}
-
-static void mod(void)
-{
- data_t d = pop();
-
- push((data_t) pop() % d);
-}
-
-static void and(void)
-{
- push((data_t) pop() & (data_t) pop());
-}
-
-static void or(void)
-{
- push((data_t) pop() | (data_t) pop());
-}
-
-static void eor(void)
-{
- push((data_t) pop() ^ (data_t) pop());
-}
-
-static void not(void)
-{
- push(~(data_t) pop());
-}
-
-static void set_output_base(void)
-{
- static const char bases[] ALIGN1 = { 2, 8, 10, 16, 0 };
- unsigned b = (unsigned)pop();
-
- base = *strchrnul(bases, b);
- if (base == 0) {
- bb_error_msg("error, base %u is not supported", b);
- base = 10;
- }
-}
-
-static void print_base(double print)
-{
- data_t x, i;
-
- x = (data_t) print;
- if (base == 10) {
- if (x == print) /* exactly representable as unsigned integer */
- printf("%"DATA_FMT"u\n", x);
- else
- printf("%g\n", print);
- return;
- }
-
- switch (base) {
- case 16:
- printf("%"DATA_FMT"x\n", x);
- break;
- case 8:
- printf("%"DATA_FMT"o\n", x);
- break;
- default: /* base 2 */
- i = MAXINT(data_t) - (MAXINT(data_t) >> 1);
- /* i is 100000...00000 */
- do {
- if (x & i)
- break;
- i >>= 1;
- } while (i > 1);
- do {
- bb_putchar('1' - !(x & i));
- i >>= 1;
- } while (i);
- bb_putchar('\n');
- }
-}
-
-static void print_stack_no_pop(void)
-{
- unsigned i = pointer;
- while (i)
- print_base(stack[--i]);
-}
-
-static void print_no_pop(void)
-{
- check_under();
- print_base(stack[pointer-1]);
-}
-
-struct op {
- const char name[4];
- void (*function) (void);
-};
-
-static const struct op operators[] = {
-#if ENABLE_FEATURE_DC_LIBM
- {"**",  power},
- {"exp", power},
- {"pow", power},
-#endif
- {"%",   mod},
- {"mod", mod},
- {"and", and},
- {"or",  or},
- {"not", not},
- {"eor", eor},
- {"xor", eor},
- {"+",   add},
- {"add", add},
- {"-",   sub},
- {"sub", sub},
- {"*",   mul},
- {"mul", mul},
- {"/",   divide},
- {"div", divide},
- {"p", print_no_pop},
- {"f", print_stack_no_pop},
- {"o", set_output_base},
-};
-
-/* Feed the stack machine */
-static void stack_machine(const char *argument)
-{
- char *end;
- double number;
- const struct op *o;
-
- next:
- number = strtod(argument, &end);
- if (end != argument) {
- argument = end;
- push(number);
- goto next;
- }
-
- /* We might have matched a digit, eventually advance the argument */
- argument = skip_whitespace(argument);
-
- if (*argument == '\0')
- return;
-
- o = operators;
- do {
- char *after_name = is_prefixed_with(argument, o->name);
- if (after_name) {
- argument = after_name;
- o->function();
- goto next;
- }
- o++;
- } while (o != operators + ARRAY_SIZE(operators));
-
- bb_error_msg_and_die("syntax error at '%s'", argument);
-}
-
-int dc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int dc_main(int argc UNUSED_PARAM, char **argv)
-{
- INIT_G();
-
- argv++;
- if (!argv[0]) {
- /* take stuff from stdin if no args are given */
- char *line;
- while ((line = xmalloc_fgetline(stdin)) != NULL) {
- stack_machine(line);
- free(line);
- }
- } else {
- do {
- stack_machine(*argv);
- } while (*++argv);
- }
- return EXIT_SUCCESS;
-}
-- 
2.17.1

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr">Hello,<div><br></div><div>Since my first attempt to send a patch to add my \
bc to busybox failed because it was too big, I thought that I would send it in \
pieces. This is the first patch (which is at the bottom of the email), and it is for \
removing the current dc, which will be replaced by a complete dc that is combined \
with my bc.</div><div><br></div><div>Also, I have included the &quot;make \
bloatcheck&quot; output for bc, dc, and both, in that order, \
below.</div><div><br></div><div>bc:</div><div><br></div><div><div>function            \
old     new   delta</div><div>.rodata                                           \
150820  156540   +5720</div><div>bc_program_exec                                      \
-    4457   +4457</div><div>bc_vm_run                                              -  \
2237   +2237</div><div>bc_lib                                                 -    \
1878   +1878</div><div>bc_parse_expr                                          -    \
1470   +1470</div><div>bc_num_k                                               -    \
1304   +1304</div><div>bc_num_print                                           -    \
1139   +1139</div><div>bc_num_parse                                           -    \
1063   +1063</div><div>bc_lex_token                                           -    \
1053   +1053</div><div>bc_num_sqrt                                            -     \
959    +959</div><div>bc_num_d                                               -     \
821    +821</div><div>bc_program_init                                        -     \
787    +787</div><div>bc_parse_for                                           -     \
743    +743</div><div>bc_num_p                                               -     \
725    +725</div><div>bc_args                                                -     \
643    +643</div><div>bc_parse_endBody                                       -     \
561    +561</div><div>bc_vm_process                                          -     \
529    +529</div><div>bc_program_assign                                      -     \
509    +509</div><div>bc_parse_stmt                                          -     \
488    +488</div><div>bc_lex_number                                          -     \
432    +432</div><div>bc_err_msgs                                            -     \
432    +432</div><div>bc_parse_func                                          -     \
419    +419</div><div>bc_parse_incdec                                        -     \
416    +416</div><div>bc_num_m                                               -     \
409    +409</div><div>bc_program_num                                         -     \
399    +399</div><div>bc_num_a                                               -     \
378    +378</div><div>bc_read_line                                           -     \
374    +374</div><div>bc_parse_while                                         -     \
372    +372</div><div>bc_read_file                                           -     \
370    +370</div><div>bc_parse_name                                          -     \
357    +357</div><div>bc_args_lopt                                           -     \
352    +352</div><div>bc_parse_auto                                          -     \
327    +327</div><div>bc_program_binOpPrep                                   -     \
318    +318</div><div>bc_num_r                                               -     \
312    +312</div><div>bc_vm_posixError                                       -     \
304    +304</div><div>bc_parse_create                                        -     \
300    +300</div><div>bc_num_s                                               -     \
300    +300</div><div>bc_parse_if                                            -     \
295    +295</div><div>bc_num_cmp                                             -     \
295    +295</div><div>bc_program_addFunc                                     -     \
284    +284</div><div>bc_parse_return                                        -     \
274    +274</div><div>bc_program_search                                      -     \
270    +270</div><div>bc_parse_operator                                      -     \
269    +269</div><div>bc_num_divmod                                          -     \
268    +268</div><div>bc_parse_call                                          -     \
261    +261</div><div>bc_parse_loopExit                                      -     \
251    +251</div><div>bc_parse_print                                         -     \
244    +244</div><div>bc_parse_reset                                         -     \
241    +241</div><div>bc_parse_else                                          -     \
233    +233</div><div>bc_num_printDigits                                     -     \
229    +229</div><div>bc_program_reset                                       -     \
223    +223</div><div>bc_parse_scale                                         -     \
222    +222</div><div>bc_vm_error                                            -     \
221    +221</div><div>bc_parse_string                                        -     \
221    +221</div><div>bc_lex_kws                                             -     \
220    +220</div><div>bc_num_binary                                          -     \
212    +212</div><div>bc_lex_identifier                                      -     \
211    +211</div><div>bc_parse_params                                        -     \
209    +209</div><div>bc_parse_number                                        -     \
206    +206</div><div>bc_parse_builtin                                       -     \
205    +205</div><div>bc_parse_rightParen                                    -     \
195    +195</div><div>bc_map_insert                                          -     \
195    +195</div><div>bc_array_expand                                        -     \
195    +195</div><div>bc_parse_minus                                         -     \
192    +192</div><div>bc_program_free                                        -     \
188    +188</div><div>bc_num_rem                                             -     \
184    +184</div><div>bc_parse_pushName                                      -     \
173    +173</div><div>bc_array_copy                                          -     \
164    +164</div><div>bc_parse_pushIndex                                     -     \
158    +158</div><div>bc_copyright                                           -     \
155    +155</div><div>bc_func_insert                                         -     \
147    +147</div><div>bc_vec_concat                                          -     \
143    +143</div><div>bc_num_split                                           -     \
142    +142</div><div>bc_lex_name                                            -     \
138    +138</div><div>bc_parse_read                                          -     \
134    +134</div><div>bc_parse_body                                          -     \
133    +133</div><div>bc_parse_text                                          -     \
127    +127</div><div>bc_func_init                                           -     \
122    +122</div><div>bc_vec_string                                          -     \
121    +121</div><div>bc_lex_string                                          -     \
119    +119</div><div>bc_num_printHex                                        -     \
117    +117</div><div>bc_program_prep                                        -     \
113    +113</div><div>bc_num_ulong2num                                       -     \
110    +110</div><div>bc_vm_sig                                              -     \
104    +104</div><div>bc_lex_comment                                         -     \
103    +103</div><div>bc_num_shift                                           -     \
101    +101</div><div>bc_vm_info                                             -      \
99     +99</div><div>bcg                                                    -      96 \
+96</div><div>bc_parse_parse                                         -      94     \
+94</div><div>bc_main                                                -      91     \
+91</div><div>bc_num_ulong                                           -      89     \
+89</div><div>bc_program_name                                        -      87     \
+87</div><div>bc_num_retireMul                                       -      87     \
+87</div><div>bc_veco_find                                           -      84     \
+84</div><div>bc_array_init                                          -      83     \
+83</div><div>bc_num_extend                                          -      80     \
+80</div><div>bc_num_sub                                             -      78     \
+78</div><div>bc_parse_noElse                                        -      77     \
+77</div><div>bc_num_add                                             -      75     \
+75</div><div>bc_vec_push                                            -      74     \
+74</div><div>bc_num_compare                                         -      74     \
+74</div><div>bc_lex_next                                            -      74     \
+74</div><div>bc_vec_grow                                            -      73     \
+73</div><div>bc_num_init                                            -      72     \
+72</div><div>bc_lex_whitespace                                      -      72     \
+72</div><div>bc_num_copy                                            -      71     \
+71</div><div>bc_map_index                                           -      69     \
+69</div><div>bc_num_printNewline                                    -      67     \
+67</div><div>bc_num_expand                                          -      66     \
+66</div><div>bc_vec_npop                                            -      65     \
+65</div><div>bc_vec_expand                                          -      64     \
+64</div><div>bc_num_subArrays                                       -      64     \
+64</div><div>bc_program_binOpRetire                                 -      62     \
+62</div><div>bc_vm_free                                             -      61     \
+61</div><div>bc_parse_exprs                                         -      60     \
+60</div><div>bc_parse_free                                          -      59     \
+59</div><div>bc_err_ids                                             -      57     \
+57</div><div>bc_errs                                                -      56     \
+56</div><div>bc_program_index                                       -      55     \
+55</div><div>bc_vec_init                                            -      54     \
+54</div><div>bc_parse_startBody                                     -      54     \
+54</div><div>bc_parse_addFunc                                       -      54     \
+54</div><div>bc_num_mul                                             -      52     \
+52</div><div>bc_num_mod                                             -      52     \
+52</div><div>bc_num_div                                             -      52     \
+52</div><div>bc_parse_ops                                           -      50     \
+50</div><div>bc_lex_text                                            -      50     \
+50</div><div>bc_num_clean                                           -      49     \
+49</div><div>bc_program_ops                                         -      48     \
+48</div><div>bc_result_free                                         -      46     \
+46</div><div>bc_program_retire                                      -      45     \
+45</div><div>bc_lex_lineComment                                     -      42     \
+42</div><div>bc_program_len                                         -      41     \
+41</div><div>bc_num_truncate                                        -      37     \
+37</div><div>bc_sig_msg                                             -      34     \
+34</div><div>bc_num_ten                                             -      34     \
+34</div><div>bc_lex_assign                                          -      28     \
+28</div><div>bc_func_free                                           -      28     \
+28</div><div>bc_num_one                                             -      27     \
+27</div><div>bc_num_pow                                             -      24     \
+24</div><div>bc_parse_expression                                    -      23     \
+23</div><div>packed_usage                                       32742   32764     \
+22</div><div>bc_vec_free                                            -      22     \
+22</div><div>bc_program_ready_msg                                   -      22     \
+22</div><div>bc_num_zero                                            -      21     \
+21</div><div>bc_lex_init                                            -      20     \
+20</div><div>bc_vec_item_rev                                        -      19     \
+19</div><div>bc_parse_init                                          -      19     \
+19</div><div>bc_warn_fmt                                            -      17     \
+17</div><div>bc_num_hex_digits                                      -      17     \
+17</div><div>bc_parse_next_rel                                      -      16     \
+16</div><div>bc_parse_next_read                                     -      16     \
+16</div><div>bc_parse_next_print                                    -      16     \
+16</div><div>bc_parse_next_param                                    -      16     \
+16</div><div>bc_parse_next_for                                      -      16     \
+16</div><div>bc_parse_next_expr                                     -      16     \
+16</div><div>bc_parse_next_elem                                     -      16     \
+16</div><div>bc_err_fmt                                             -      15     \
+15</div><div>bc_id_cmp                                              -      11     \
+11</div><div>bc_string_free                                         -       8      \
+8</div><div>bc_program_stdin_name                                  -       8      \
+8</div><div>bc_program_exprs_name                                  -       8      \
+8</div><div>bc_num_free                                            -       8      \
+8</div><div>bc_lib_name                                            -       8      \
+8</div><div>bc_id_free                                             -       8      \
+8</div><div>bc_args_env_name                                       -       8      \
+8</div><div>applet_main                                         3120    3128      \
+8</div><div>bc_func_read                                           -       7      \
+7</div><div>bc_func_main                                           -       7      \
+7</div><div>bc_err_line                                            -       7      \
+7</div><div>bc_program_scale                                       -       5      \
+5</div><div>bc_name                                                -       3      \
+3</div><div>applet_names                                        2692    2695      \
+3</div><div>applet_install_loc                                   195     196      \
+1</div><div>------------------------------------------------------------------------------</div><div>(add/remove: \
170/0 grow/shrink: 5/0 up/down: 46767/0)       Total: 46767 bytes</div><div>   \
text<span style="white-space:pre">	</span>   data<span \
style="white-space:pre">	</span>    bss<span style="white-space:pre">	</span>    \
dec<span style="white-space:pre">	</span>    hex<span \
style="white-space:pre">	</span>filename</div><div> 972633<span \
style="white-space:pre">	</span>  17543<span style="white-space:pre">	</span>   \
1888<span style="white-space:pre">	</span> 992064<span \
style="white-space:pre">	</span>  f2340<span \
style="white-space:pre">	</span>busybox_old</div><div>1018028<span \
style="white-space:pre">	</span>  18535<span style="white-space:pre">	</span>   \
1984<span style="white-space:pre">	</span>1038547<span \
style="white-space:pre">	</span>  fd8d3<span \
style="white-space:pre">	</span>busybox_unstripped</div></div><div><br></div><div>dc:</div><div><br></div><div><div>function \
old     new   delta</div><div>bc_program_exec                                        \
-    5368   +5368</div><div>.rodata                                           150820  \
153944   +3124</div><div>bc_vm_run                                              -    \
1779   +1779</div><div>bc_num_k                                               -    \
1304   +1304</div><div>bc_num_parse                                           -    \
1063   +1063</div><div>bc_num_sqrt                                            -     \



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic