/* DOS Registry editor */
#include <conio.h>
#include <stdio.h>
#include "registry.c"

int main()
{
  char s[256];
  char s2[1024];
  char s3[1024];
  while (1) {
    clrscr();
    printf("Bad Seal registry editor DOS version 0.2\n(C) 2001 Kostas Michalopoulos aka Bad Sector\n\n");
    printf("1. Create a new key\n");
    printf("2. Delete a key\n");
    printf("3. Create a new link\n");
    printf("4. Set key's data (string)\n");
    printf("5. Set key's data (integer)\n");
    printf("6. Display key's contents\n");
    printf("0. Exit\n");
    printf("\nChoice (0 to 4): ");
    gets(s);
    switch (s[0]) {
      case '1': {
        printf("\nWhere the key will be created? (up to 1023 characters)\n");
        gets(s2);
        if (key_exists(s2)) {
          printf("Enter the name of the new key (up to 127 characters)\n");
          gets(s);
          create_key(s2, s);
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '2': {
        printf("\nEnter key's name to delete\n");
        gets(s2);
        if (key_exists(s2)) {
          delete_key(s2);
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '3': {
        printf("\nWhere the link will be created? (up to 1023 characters)\n");
        gets(s2);
        if (key_exists(s2)) {
          printf("Enter the name of the new link (up to 127 characters)\n");
          gets(s);
          printf("Where the link will be locate? (up to 1023 characters)\n");
          gets(s3);
          if (key_exists(s3)) {
            create_link_key(s2, s, s3);
          } else {
            printf("Destination key not found!!!\nPress Enter ");
            gets(s2);
          };
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '4': {
        printf("\nEnter key's name\n");
        gets(s2);
        if (key_exists(s2)) {
          printf("Enter data (max 255 chars): ");
          gets(s);
          set_key(s2, s);
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '5': {
        printf("\nEnter key's name\n");
        gets(s2);
        if (key_exists(s2)) {
          printf("Enter data (min -2G max +2G): ");
          gets(s);
          set_key_integer(s2, atoi(s));
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '6': {
        printf("\nEnter key's name\n");
        gets(s2);
        cprintf("looking for %s\n", s2);
        if (key_exists(s2)) {
          cprintf("(STRING)  %s\n", get_key(s2));
          cprintf("(INTEGER) %li\n\n", get_key_integer(s2));
          printf("Press Enter ");
          gets(s2);
        } else {
          printf("Key not found!!!\nPress Enter ");
          gets(s2);
        };
      } break;
      case '0': {
        clrscr();
        return 0;
      } break;
    };
  };

  return 0;
}

