/* Demo CodeSurfer */
#include "hello.h"

Message *top = NULL;  /* Pointer to top stack item, or NULL. */

int main(void){
  int french = 0, english = 0;  /* # of messages in each language. */

  say("Bonjour",     &french);
  say("Hello World", &english);
  say("Au Revoir",   &french);
  say("Goodbye",     &english);  

  /* Print stacked messages in reverse order. */
  while (top != NULL) { 
     printf("%s\n", top->msg); 
     top = top->next;
  }

#ifdef DEBUG
  print_hello_world();
#endif

  printf("French: %d; English: %d\n", french, english);
}
 
/* Push every other MSG in a given LANGUAGE into a stack. */
void say(char *msg, int *language) {
  if (*language % 2 == 0) push(msg); 
  *language = *language + 1;
}

/* Push MSG into a stack. */
void push(char *msg) { 
  Message *new = (Message*)malloc(sizeof(Message));
  new->msg = msg; 
  new->next = top; 
  top = new;
}

/* Print "Hello World". */
void print_hello_world(void) { printf("Hello World"); }

