Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu User (http://www.linux-archive.org/ubuntu-user/)
-   -   We don't need the command names anymore. (http://www.linux-archive.org/ubuntu-user/479051-we-dont-need-command-names-anymore.html)

Chris Lumens 01-20-2011 05:20 PM

We don't need the command names anymore.
 
Since we're just running every command handling function and letting the
function decide whether it need to do anything, there's no need for the
command names and special structure. Instead, just keep an array of
function pointers to iterate.
---
loader/kickstart.c | 51 ++++++++++++++++++++++-----------------------------
1 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/loader/kickstart.c b/loader/kickstart.c
index d10d037..3374432 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -64,11 +64,6 @@ static PyObject *constantsMod;
/* boot flags */
extern uint64_t flags;

-struct ksCommandNames {
- char * name;
- void (*setupData) (struct loaderData_s *loaderData, PyObject *handler);
-} ;
-
static void setDisplayMode(struct loaderData_s * loaderData, PyObject *handler);
static void setSELinux(struct loaderData_s * loaderData, PyObject *handler);
static void setShutdown(struct loaderData_s * loaderData, PyObject *handler);
@@ -85,27 +80,25 @@ static void setKickstartNfs(struct loaderData_s * loaderData, PyObject *handler)
static void setKickstartUrl(struct loaderData_s * loaderData, PyObject *handler);
static void loadKickstartModule(struct loaderData_s * loaderData, PyObject *handler);

-struct ksCommandNames ksTable[] = {
- { "cdrom", setKickstartCD },
- { "cmdline", setDisplayMode },
- { "device", loadKickstartModule },
- { "driverdisk", useKickstartDD },
- { "graphical", setDisplayMode },
- { "halt", setShutdown },
- { "harddrive", setKickstartHD },
- { "keyboard", setKickstartKeyboard },
- { "lang", setKickstartLanguage },
- { "mediacheck", setMediaCheck },
- { "network", setKickstartNetwork },
- { "nfs", setKickstartNfs },
- { "poweroff", setShutdown },
- { "selinux", setSELinux },
- { "shutdown", setShutdown },
- { "text", setDisplayMode },
- { "updates", setUpdates },
- { "url", setKickstartUrl },
- { "vnc", setVnc },
- { NULL, NULL }
+typedef void (*commandFunc_t)(struct loaderData_s *loaderData, PyObject *handler);
+
+commandFunc_t ksTable[] = {
+ &loadKickstartModule,
+ &setDisplayMode,
+ &setKickstartCD,
+ &setKickstartHD,
+ &setKickstartKeyboard,
+ &setKickstartLanguage,
+ &setKickstartNetwork,
+ &setKickstartNfs,
+ &setKickstartUrl,
+ &setMediaCheck,
+ &setSELinux,
+ &setShutdown,
+ &setUpdates,
+ &setVnc,
+ &useKickstartDD,
+ NULL
};

/* INTERNAL PYTHON INTERFACE FUNCTIONS */
@@ -1010,7 +1003,7 @@ int runKickstart(struct loaderData_s * loaderData, const char *file) {

/* call readKickstart */
if (processedFile) {
- struct ksCommandNames *cmd;
+ commandFunc_t *cmd;

if (!readKickstart(parser, processedFile))
goto quit;
@@ -1019,8 +1012,8 @@ int runKickstart(struct loaderData_s * loaderData, const char *file) {
* every element of the ksTable and run its function. The functions
* themselves will decide if they should do anything or not.
*/
- for (cmd = ksTable; cmd->name; cmd++)
- cmd->setupData(loaderData, handler);
+ for (cmd = ksTable; *cmd != NULL; cmd++)
+ (*cmd)(loaderData, handler);
}

rc = 1;
--
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

David Cantrell 01-24-2011 11:51 PM

We don't need the command names anymore.
 
Ack.

On Thu, 20 Jan 2011, Chris Lumens wrote:


Since we're just running every command handling function and letting the
function decide whether it need to do anything, there's no need for the
command names and special structure. Instead, just keep an array of
function pointers to iterate.
---
loader/kickstart.c | 51 ++++++++++++++++++++++-----------------------------
1 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/loader/kickstart.c b/loader/kickstart.c
index d10d037..3374432 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -64,11 +64,6 @@ static PyObject *constantsMod;
/* boot flags */
extern uint64_t flags;

-struct ksCommandNames {
- char * name;
- void (*setupData) (struct loaderData_s *loaderData, PyObject *handler);
-} ;
-
static void setDisplayMode(struct loaderData_s * loaderData, PyObject *handler);
static void setSELinux(struct loaderData_s * loaderData, PyObject *handler);
static void setShutdown(struct loaderData_s * loaderData, PyObject *handler);
@@ -85,27 +80,25 @@ static void setKickstartNfs(struct loaderData_s * loaderData, PyObject *handler)
static void setKickstartUrl(struct loaderData_s * loaderData, PyObject *handler);
static void loadKickstartModule(struct loaderData_s * loaderData, PyObject *handler);

-struct ksCommandNames ksTable[] = {
- { "cdrom", setKickstartCD },
- { "cmdline", setDisplayMode },
- { "device", loadKickstartModule },
- { "driverdisk", useKickstartDD },
- { "graphical", setDisplayMode },
- { "halt", setShutdown },
- { "harddrive", setKickstartHD },
- { "keyboard", setKickstartKeyboard },
- { "lang", setKickstartLanguage },
- { "mediacheck", setMediaCheck },
- { "network", setKickstartNetwork },
- { "nfs", setKickstartNfs },
- { "poweroff", setShutdown },
- { "selinux", setSELinux },
- { "shutdown", setShutdown },
- { "text", setDisplayMode },
- { "updates", setUpdates },
- { "url", setKickstartUrl },
- { "vnc", setVnc },
- { NULL, NULL }
+typedef void (*commandFunc_t)(struct loaderData_s *loaderData, PyObject *handler);
+
+commandFunc_t ksTable[] = {
+ &loadKickstartModule,
+ &setDisplayMode,
+ &setKickstartCD,
+ &setKickstartHD,
+ &setKickstartKeyboard,
+ &setKickstartLanguage,
+ &setKickstartNetwork,
+ &setKickstartNfs,
+ &setKickstartUrl,
+ &setMediaCheck,
+ &setSELinux,
+ &setShutdown,
+ &setUpdates,
+ &setVnc,
+ &useKickstartDD,
+ NULL
};

/* INTERNAL PYTHON INTERFACE FUNCTIONS */
@@ -1010,7 +1003,7 @@ int runKickstart(struct loaderData_s * loaderData, const char *file) {

/* call readKickstart */
if (processedFile) {
- struct ksCommandNames *cmd;
+ commandFunc_t *cmd;

if (!readKickstart(parser, processedFile))
goto quit;
@@ -1019,8 +1012,8 @@ int runKickstart(struct loaderData_s * loaderData, const char *file) {
* every element of the ksTable and run its function. The functions
* themselves will decide if they should do anything or not.
*/
- for (cmd = ksTable; cmd->name; cmd++)
- cmd->setupData(loaderData, handler);
+ for (cmd = ksTable; *cmd != NULL; cmd++)
+ (*cmd)(loaderData, handler);
}

rc = 1;



--
David Cantrell <dcantrell@redhat.com>
Supervisor, Installer Engineering Team
Red Hat, Inc. | Honolulu, HI | UTC-10

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


All times are GMT. The time now is 09:27 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.