Skip to contentSkip to conversation

Replace magic numbers by constants

PATCH In review Carles Pina i Estany 3 participants 8 messages Aug 17, 2008 – Aug 20, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replace magic numbers by constants

Hello,

When I did the Home/End keys patch I noticied that in normal/menu.c there was some magic numbers (and some constants was already defined, in include/grub/term.h (actually, reading the ChangeLog was committed by Robert Millan on 2008-02-05)

I'm sending a patch to change the magic numbers by constants.

ChangeLog:
--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants.
--------

Thanks,

PS: thanks Felix for committing the previous patch

Signature · 2 lines
Carles Pina i Estany		GPG id: 0x17756391
	http://pinux.info
menu.c +2 -2
Index: normal/menu.c
===================================================================
@@ -421,7 +421,7 @@
 		print_entries (menu, first, offset);
 	      break;
 
-	    case 16:
+	    case GRUB_TERM_UP:
 	    case '^':
 	      if (offset > 0)
 		{
@@ -438,7 +438,7 @@
 		}
 	      break;
 	      
-	    case 14:
+	    case GRUB_TERM_DOWN:
 	    case 'v':
 	      if (menu->size > first + offset + 1)
 		{
#1 lore raw

Hi,

Quoted 5 lines · Carles Pina i Estany

When I did the Home/End keys patch I noticied that in normal/menu.c there was some magic numbers (and some constants was already defined, in include/grub/term.h (actually, reading the ChangeLog was committed by Robert Millan on 2008-02-05)

Quoted 7 lines

I'm sending a patch to change the magic numbers by constants.

ChangeLog:
--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants.

Can you be more specific about what you replace?

Thanks,
Marco

#2 lore raw

Hi,

Quoted 11 lines · Marco Gerards

Hi,

Quoted 7 lines · Carles Pina i Estany

When I did the Home/End keys patch I noticied that in normal/menu.c there was some magic numbers (and some constants was already defined, in include/grub/term.h (actually, reading the ChangeLog was committed by Robert Millan on 2008-02-05)

I'm sending a patch to change the magic numbers by constants.

Quoted 7 lines
Quoted 5 lines

ChangeLog:
--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants.

Can you be more specific about what you replace?

sure:

--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants (16 by GRUB_TERM_UP and 14 by GRUB_TERM_DOWN)
--------

Signature · 2 lines
Carles Pina i Estany		GPG id: 0x17756391
	http://pinux.info
#3 lore raw
Quoted 4 lines · Carles Pina i Estany

2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants (16 by GRUB_TERM_UP and 14 by GRUB_TERM_DOWN)

When reading the subject I thought it was the other way around. Would something like:

"replace hardcoded numbers with macros"

or

"macroify numbers"

etc, make it more clear?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw

Hello,

Quoted 6 lines · Robert Millan
Quoted 4 lines · Carles Pina i Estany

2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Change magic numbers by constants (16 by GRUB_TERM_UP and 14 by GRUB_TERM_DOWN)

Quoted 8 lines

When reading the subject I thought it was the other way around. Would something like:

"replace hardcoded numbers with macros"

or

"macroify numbers"

Ok:

--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Replace hardcoded numbers with macros (16 for GRUB_TERM_UP and 14 for GRUB_TERM_DOWN)
--------

Quoted 1 line

etc, make it more clear?

An English note: In my previous mail I've confused "change ... by" with "change ... for" :-)

Thanks,

Signature · 2 lines
Carles Pina i Estany		GPG id: 0x17756391
	http://pinux.info
#5 lore raw

Hola,

Quoted 14 lines · Carles Pina i Estany
Quoted 8 lines

When reading the subject I thought it was the other way around. Would something like:

"replace hardcoded numbers with macros"

or

"macroify numbers"

Ok:

--------
2008-08-17 Carles Pina i Estany <[email protected]>

Quoted 8 lines

* menu/normal.c (run_menu): Replace hardcoded numbers with macros (16 for GRUB_TERM_UP and 14 for GRUB_TERM_DOWN)
--------

Quoted 1 line

etc, make it more clear?

An English note: In my previous mail I've confused "change ... by" with "change ... for" :-)

any other change is needed? (patch or changelog) or patch is not needed and then i will forget about it :-)

Signature · 2 lines
Carles Pina i Estany		GPG id: 0x17756391
	http://pinux.info
#6 lore raw
In reply to Carles Pina i Estany
Quoted 8 lines · Carles Pina i Estany

Ok:

--------
2008-08-17 Carles Pina i Estany <[email protected]>

* menu/normal.c (run_menu): Replace hardcoded numbers with macros (16 for GRUB_TERM_UP and 14 for GRUB_TERM_DOWN)
--------

Thanks, I checked this in.

Btw, were you going to add support for PageUp / PageDown as well? :-)

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#7 lore raw

Hi,

Quoted 6 lines · Robert Millan
Quoted 5 lines · Carles Pina i Estany

Ok:

--------
2008-08-17 Carles Pina i Estany <[email protected]>

Quoted 7 lines
Quoted 3 lines

* menu/normal.c (run_menu): Replace hardcoded numbers with macros (16 for GRUB_TERM_UP and 14 for GRUB_TERM_DOWN)
--------

Thanks, I checked this in.

Btw, were you going to add support for PageUp / PageDown as well? :-)

Yes, that was my plan.

Today (probably) I will write a proposal of how would behave (how much lines would scroll, which physical line number would be the new selected -last one of the screen, first one-). When we agree (if we do :-) ) I will write the patch (hopefully on weekend).

I will also start a new mailing thread.

Signature · 2 lines
Carles Pina i Estany		GPG id: 0x17756391
	http://pinux.info