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

View File

@ -54,7 +54,7 @@ char getMaskChar(void);
* displaying a menu.
*
*/
char nmsexec(char *src, char *returnOptions) {
char nmsexec(NMSArgs *args) {
struct winpos *list_pointer = NULL;
struct winpos *start; // Always points to start of list
struct winpos *temp; // Used for free()ing the list
@ -85,7 +85,7 @@ char nmsexec(char *src, char *returnOptions) {
// Geting input
n = 0;
while ((c = src[n++]) != '\0') {
while ((c = args->src[n++]) != '\0') {
if (c == NEWLINE) {
++y;
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 (isatty(STDIN_FILENO)) {
ret = getch();
if (returnOptions != NULL && strlen(returnOptions) > 0)
while (index(returnOptions, ret) == NULL)
if (args->return_opts != NULL && strlen(args->return_opts) > 0)
while (index(args->return_opts, ret) == NULL)
ret = getch();
} else
sleep(2);

View File

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

View File

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