Changes nmsexec() to accept a structure containing it's multiple arguments. This made

more sense than passing a growing list of arguments.

	modified:   src/main.c
	modified:   src/nms.c
	modified:   src/nms.h
	modified:   src/sneakers.c
This commit is contained in:
Brian Barto 2016-04-20 17:08:35 -04:00
parent f91d5601c4
commit 9959d6f98f
4 changed files with 23 additions and 7 deletions

View File

@ -4,6 +4,7 @@
int main(void) { int main(void) {
char *input; char *input;
NMSArgs args = INIT_NMSARGS;
// Geting input // Geting input
int c, inSize = 0; int c, inSize = 0;
@ -14,8 +15,11 @@ int main(void) {
input[inSize] = '\0'; input[inSize] = '\0';
} }
// Set needed args
args.src = input;
// Display characters // Display characters
nmsexec(input, NULL); nmsexec(&args);
// Don't forget to free the allocated memory! // Don't forget to free the allocated memory!
free(input); free(input);

View File

@ -54,7 +54,7 @@ char getMaskChar(void);
* displaying a menu. * displaying a menu.
* *
*/ */
char nmsexec(char *src, char *returnOptions) { char nmsexec(NMSArgs *args) {
struct winpos *list_pointer = NULL; struct winpos *list_pointer = NULL;
struct winpos *start; // Always points to start of list struct winpos *start; // Always points to start of list
struct winpos *temp; // Used for free()ing the list struct winpos *temp; // Used for free()ing the list
@ -85,7 +85,7 @@ char nmsexec(char *src, char *returnOptions) {
// Geting input // Geting input
n = 0; n = 0;
while ((c = src[n++]) != '\0') { while ((c = args->src[n++]) != '\0') {
if (c == NEWLINE) { if (c == NEWLINE) {
++y; ++y;
x = 0; x = 0;
@ -231,8 +231,8 @@ char nmsexec(char *src, char *returnOptions) {
// If stdin is set to the keyboard, user must press a key to continue // If stdin is set to the keyboard, user must press a key to continue
if (isatty(STDIN_FILENO)) { if (isatty(STDIN_FILENO)) {
ret = getch(); ret = getch();
if (returnOptions != NULL && strlen(returnOptions) > 0) if (args->return_opts != NULL && strlen(args->return_opts) > 0)
while (index(returnOptions, ret) == NULL) while (index(args->return_opts, ret) == NULL)
ret = getch(); ret = getch();
} else } else
sleep(2); sleep(2);

View File

@ -1,9 +1,16 @@
#ifndef NMS_H #ifndef NMS_H
#define NMS_H 1 #define NMS_H 1
#define INIT_NMSARGS { .src = NULL, .return_opts = NULL }
typedef struct {
char *src;
char *return_opts;
} NMSArgs;
// Function prototypes // Function prototypes
// Display the characters stored in the display queue // Display the characters stored in the display queue
char nmsexec(char *, char *); char nmsexec(NMSArgs *);
#endif #endif

View File

@ -22,6 +22,7 @@ int main(void) {
char *menu6 = "[6] Remote Operator Logon/Logoff"; char *menu6 = "[6] Remote Operator Logon/Logoff";
char *foot1Center = "================================================================"; char *foot1Center = "================================================================";
char *foot2Center = "[ ] Select Option or ESC to Abort"; char *foot2Center = "[ ] Select Option or ESC to Abort";
NMSArgs args = INIT_NMSARGS;
// Get terminal dimentions (needed for centering) // Get terminal dimentions (needed for centering)
struct winsize w; struct winsize w;
@ -153,8 +154,12 @@ int main(void) {
} }
strcat(display, foot2Center); strcat(display, foot2Center);
// Set needed args
args.src = display;
args.return_opts = "123456";
// Display characters // Display characters
input = nmsexec(display, "123456"); input = nmsexec(&args);
switch (input) { switch (input) {
case '1': case '1':