#include <stdio.h>
#include <string.h>

/* Rule declarations */
#define ALLOW         1
#define DENY          0

/* Type declarations */
#define HOST          10
#define PROTOCOL      11
#define SERVICE       12

/* All_whatever declarations */
#define ANY_HOST      255.255.255.255
#define ANY_PROTOCOL  -1
#define ANY_SERVICE   -1

int main(void) {
  FILE *fp;
  char buf[100], addr[16], proto[16], service[16];
  int rule;
  fp = fopen("tmp", "r");
  
  fscanf(fp, "%s", buf);
  while (!(feof(fp))) {

    if(strcmp(buf, "deny") == 0) {
      printf("DENY ");
      rule = DENY;
    } else if (strcmp(buf, "allow") == 0) {
      printf("ALLOW ");
      rule = ALLOW;
    } else
      return -1;

    fscanf(fp, "%s\n", buf);

    if (strcmp(buf, "host") == 0) {
      fscanf(fp, "%s\n", buf);
      strcpy(addr, buf);
      printf("HOST %s ", addr);

      /* Read in the next token */
      fscanf(fp, "%s\n", buf);
    }

    if (strcmp(buf, "protocol") == 0) {
      fscanf(fp, "%s\n", buf);
      strcpy(proto, buf);
      printf("PROTOCOL %s ", proto);

      /* Read in the next token */
      fscanf(fp, "%s\n", buf);
    }
    
    if (strcmp(buf, "service") == 0) {
      fscanf(fp, "%s\n", buf);
      strcpy(service, buf);
      printf("SERVICE %s ", service);

      /* Read in the next token */
      fscanf(fp, "%s\n", buf);

    } else if (strcmp(buf, "port") == 0) {
      fscanf(fp, "%s\n", buf);
      /* The buffer now has the TCP service in it */
      printf("PORT %s ", buf);

      /* Read in the next token */
      fscanf(fp, "%s\n", buf);
    }
    printf("\n");
  }

  return 0;
}

