/* arclynx - simple version of Lynx for Acorn machines
 * (c) 1996 Andrew Wood
 *
 * Header file
 */


/* *********************** standard header includes  *********************** */
#include <stdio.h>
#include <stdlib.h>


/* ******************************* constants ******************************* */
#define MAX_ANCHOR_HREFS    512        /* max no. of links from one document */
#define MAX_ANCHOR_NAMES    512  /* max no. of named anchors in one document */
#define MAX_LIST_DEPTH      10              /* maximum depth of nested lists */
#define MAX_URL_LENGTH      256                   /* maximum size of any URL */
#define MAX_FILENAME_LENGTH 128                /* maximum size of a filename */
#define MAX_TITLE_LENGTH    64              /* maximum document title length */
#define LYNX_TEMP_WORKSPACE 1024              /* size of temporary workspace */
#define LYNX_MAX_LINES      10240                 /* maximum number of lines */
#define LYNX_HISTORY        100            /* size of document history stack */
enum {
 LYNX_NULL,                              /* code for end of line or document */
 LYNX_A_HREF_CODE,                        /* code number for hyperlink start */
 LYNX_A_HREF_END,                           /* code number for hyperlink end */
 LYNX_A_NAME_CODE,                     /* code number for named anchor start */
 LYNX_A_NAME_END,                        /* code number for named anchor end */
 LYNX_BOLD_CODE,                      /* code number for bold text start/end */
 LYNX_ITALIC_CODE,                  /* code number for italic text start/end */
 LYNX_HEADING_CODE,                /* code number for heading text start/end */
 LYNX_SPACES_CODE,                           /* code number to skip n spaces */
 LYNX_NUM_CODES                                   /* number of codes defined */
};
enum {                                                           /* colours: */
 LYNX_COL_BLACK,                                    /* colour code for black */
 LYNX_COL_PLAIN,                               /* colour code for plain text */
 LYNX_COL_BOLD,                                 /* colour code for bold text */
 LYNX_COL_ITALIC,                             /* colour code for italic text */
 LYNX_COL_HEADING,                           /* colour code for heading text */
 LYNX_COL_SELECTED,                       /* colour code for selected anchor */
 LYNX_COL_ANCHOR,                             /* colour code for anchor text */
 LYNX_NUM_COLOURS                               /* number of colours defined */
};
enum {                                             /* file fetching methods: */
 LYNX_METHOD_FILE,                                             /* local file */
 LYNX_METHOD_FTP,                                                  /* ftp:// */
 LYNX_METHOD_HTTP,                                                /* http:// */
 LYNX_METHOD_NEWS,                                                  /* news: */
 LYNX_METHOD_TELNET,                                            /* telnet:// */
 LYNX_METHOD_MAILTO,                                              /* mailto: */
 LYNX_NUM_METHODS                               /* number of methods defined */
};

/* **************************** type definitions *************************** */
typedef struct {                           /* document building information: */
 int anchor_hrefs;       /* number of hyperlink destinations in current file */
 int anchor_names;                 /* number of anchor names in current file */
 int lines;                                         /* number of lines built */
 char **anchor_href;                      /* array of hyperlink destinations */
 char **anchor_name;                                /* array of anchor names */
 char **line;                                        /* array of built lines */
 FILE *fptr;                                           /* input file pointer */
 char *url;                                       /* URL of current document */
 char *filename;                       /* local filename of current document */
 char title[MAX_TITLE_LENGTH];                             /* document title */
 char temporary;               /* flag: if set, filename is a temporary file */
} Build;

typedef struct {                             /* document display information */
 char changed;                               /* flag set if document changed */
 int screen_top;                                         /* current top line */
 int current_link;                                /* currently selected link */
 int top_link;                              /* number of link at top of page */
 int bottom_link;                        /* number of link at bottom of page */
} Display;

typedef struct {                               /* global status information: */
 char finished;                                           /* "finished" flag */
 char *temp;                                          /* temporary workspace */
 int history_pos;                               /* position in history stack */
 char **history;                                            /* history stack */
 Build build;                                         /* built document data */
 Display display;                                /* document displaying data */
} Status;

typedef struct {                             /* terminal screen information: */
 int width,height;                      /* screen width, height (characters) */
 char *data;                                         /* characters on screen */
 char *colour;                                   /* colour of each character */
 int c,x,y;                               /* current colour and x,y position */
} Screen;

/* ************************** function prototypes ************************** */
void lynx_main(Status *);                 /* main program loop (in a_main.c) */
void lynx_fetch(Status *,char *);             /* fetch a file (in a_fetch.c) */
void lynx_parse(Status *);                  /* parse document (in a_parse.c) */
void lynx_history_push(Status *,char *); /* add URL to history (in a_hist.c) */
char *lynx_history_pop(Status *);   /* remove URL from history (in a_hist.c) */
void lynx_initialise(Status *);                  /* initialise (in a_init.c) */
void lynx_finalise(Status *);                      /* finalise (in a_init.c) */
void lynx_clear_document(Build *);  /* clear previous document (in a_init.c) */

void lynx_debug(Status *);          /* write a debugging file (in a_debug.c) */

void string_lowercase(char *);        /* convert to lower case (in a_misc.c) */
int string_length(char *);       /* count printable characters (in a_misc.c) */
int word_length(char *);    /* count number of letters in word (in a_misc.c) */
char *word_lterm(char *);/*return copy, lowercase & terminated (in a_misc.c) */

void awterm_initialise(void);       /* initialise terminal i/o (in a_term.c) */
void awterm_finalise(void);         /* close down terminal i/o (in a_term.c) */
Screen *awterm_workspace(void);      /* return pointer to data (in a_term.c) */
void awterm_status(char *);                 /* set status line (in a_term.c) */
void awterm_info(char *);                     /* set info line (in a_term.c) */
void awterm_input(char *,char *);                /* input line (in a_term.c) */
void awterm_clear(void);                       /* clear screen (in a_term.c) */
int awterm_readkey(void);        /* read key press, -1 if none (in a_term.c) */
int awterm_getch(void);                  /* wait for key press (in a_term.c) */
void awterm_move(int,int);                    /* move to (x,y) (in a_term.c) */
void awterm_colour(int);                      /* change colour (in a_term.c) */
void awterm_pause(void);                  /* pause for a while (in a_term.c) */
void awterm_char(int);                      /* print character (in a_term.c) */
