int main (int argc, char* const argv[]) { int socket_fd; struct sockaddr_in name; struct hostent* hostinfo; /* Create the socket. */ socket_fd = socket (PF_INET, SOCK_STREAM, 0); /* Store the server's name in the socket address. */ name.sin_family = AF_INET; /* Convert from strings to numbers. */ hostinfo = gethostbyname (argv[1]); if (hostinfo == NULL) return 1; else name.sin_addr = *((struct in_addr *) hostinfo->h_addr); /* Web servers use port 80. */ name.sin_port = htons (80); /* Connect to the Web server */ if (connect (socket_fd, &name, sizeof (struct sockaddr_in)) == -1) { perror ("connect"); return 1; } /* Retrieve the server's home page. */ get_home_page (socket_fd); return 0; }
int main (int argc, char *argv[]) { /* These have been moved from global to local variables */ /* this reduces binary size and improves code structure. RP */ /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */ char home_page[20] = "index.htm"; char help_page[20] = "help.htm"; char base_dir[257]; char *showcommand = 0; char *oldscreen; int oldcursorx = wherex (), oldcursory = wherey (); int i; /* counter for loop */ int forcemono = 0, fancyscheme = 0; int AsciiExtendedChars = 1; int codepage = 0; cat = catopen("htmlhelp", 0); if (getenv ("HELPPATH") == NULL) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* default location */ if (lang_add(base_dir, home_page) != 0) { char testpath[257]; get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* bookshelf location */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); /* try same dir as exe */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { *base_dir = '\0'; /* try current dir */ strcpy(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); } } } } } else { strcpy (base_dir, getenv ("HELPPATH")); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, getenv ("HELPPATH")); if (base_dir[0] != '\0') { if (base_dir[strlen(base_dir)-1] != '\\' && base_dir[strlen(base_dir)-1] != '/'); strcat (base_dir, "\\"); } } } if (getenv ("HELPCMD")) { if (strstr (getenv ("HELPCMD"), "/A")) AsciiExtendedChars = 0; if (strstr (getenv ("HELPCMD"), "/M")) forcemono = 1; if (strstr (getenv ("HELPCMD"), "/F1")) fancyscheme = 1; if (strstr (getenv ("HELPCMD"), "/F2")) fancyscheme = 2; } for (i = 1; i < argc; i++) { if (argv[i][0] == '/') { switch (argv[i][1]) { default: printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); break; case '?': show_usage (); return 0; case 'a': case 'A': if (argv[i][2] == 0) AsciiExtendedChars = 0; break; case 'c': case 'C': codepage = atoi(argv[i]+2); if (codepage == 0) { printf("%s (/Cnnn)\n", hcatCodepagePlease); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } break; case 'f': case 'F': fancyscheme = atoi(argv[i] + 2); if (fancyscheme < 1 || fancyscheme > 2) fancyscheme = 1; break; case 'h': case 'H': if (argv[i][2] == 0) /* Only put /h or /H */ { printf ("%s\n", hcatInvArg); printf ("%s\n", hcatHowGetUsage); return 0; } else { strncpy(help_page, argv[i] + 2, 14); } break; case 'l': case 'L': strcat (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); break; case 'm': case 'M': if (argv[i][2] == '\0') forcemono = 1; else { printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); return 0; } break; case 'o': /* Override index file path/name */ case 'O': strcpy (base_dir, argv[i] + 2); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); } } } else if (showcommand == 0) { showcommand = malloc (strlen (argv[i]) + 11); if (!showcommand) { printf ("%s\n", hcatMemErr); return 0; } sprintf (showcommand, "#%s", argv[i]); } else { printf ("%s\n", hcat2ManyTopics); printf ("%s\n", hcatHowGetUsage); return 0; } } if (fancyscheme && forcemono) { printf ("%s\n", hcatFwithN); printf ("%s\n", hcatHowGetUsage); return 0; } /* detect (or force) the codepage to select UTF-8 and entity substition support */ if (selectCodepage(codepage) != codepage && codepage > 0) { printf("%s\n", hcatCodepageNotSupported); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } /* initialise user interface */ conio_init (forcemono); if (forcemono == 0) { oldscreen = malloc (W * H * 2); if (oldscreen) save_window (X, Y, W, H, oldscreen); } if (MonoOrColor == COLOR_MODE && fancyscheme == 0) { TEXT_COLOR = C_TEXT_COLOR; BOLD_COLOR = C_BOLD_COLOR; ITALIC_COLOR = C_ITALIC_COLOR; BORDER_BOX_COLOR = C_BORDER_COLOR; BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR; LINK_COLOR = C_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 1) { TEXT_COLOR = F1_TEXT_COLOR; BOLD_COLOR = F1_BOLD_COLOR; ITALIC_COLOR = F1_ITALIC_COLOR; BORDER_BOX_COLOR = F1_BORDER_COLOR; BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR; LINK_COLOR = F1_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 2) { TEXT_COLOR = F2_TEXT_COLOR; BOLD_COLOR = F2_BOLD_COLOR; ITALIC_COLOR = F2_ITALIC_COLOR; BORDER_BOX_COLOR = F2_BORDER_COLOR; BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR; LINK_COLOR = F2_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR; } else { TEXT_COLOR = M_TEXT_COLOR; BOLD_COLOR = M_BOLD_COLOR; ITALIC_COLOR = M_ITALIC_COLOR; BORDER_BOX_COLOR = M_BORDER_COLOR; BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR; LINK_COLOR = M_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR; } if (AsciiExtendedChars == 0) { strcpy (Border22f, "+-+( )+-+"); strcpy (Border22if, "+-+( )+-+"); BarBlock1 = '.'; BarBlock2 = '#'; } show_mouse (); move_mouse (80, 25); drawmenu (); html_view (showcommand, base_dir, home_page, help_page); free (showcommand); hide_mouse (); if ((oldscreen != 0) && (forcemono == 0)) { load_window (X, Y, W, H, oldscreen); free (oldscreen); } conio_exit (); gotoxy (oldcursorx, oldcursory); return 0; }
int html_view_internal (struct eventState *pes, char *base_dir, char *home_page) { int i; if (pes->link_text != 0) { statusbar (hcatStatusLooking); if (*pes->link_text == '#') { char *anchor; if (strnicmp (pes->link_text + 1, HTMLHELP_INTERNAL_SEARCHLINK, strlen (HTMLHELP_INTERNAL_SEARCHLINK)) == 0) { /* Internal search engine link */ anchor = pes->body_start + atoi (pes->link_text + strlen (HTMLHELP_INTERNAL_SEARCHLINK) + 1); } else { sprintf (pes->text_holder, "<a name=\"%.*s\"", link_length (pes->link_text + 1), pes->link_text + 1); anchor = strstr (pes->body_start, pes->text_holder); } if (anchor) { /* Locate start of line. */ while (anchor != pes->body_start && *anchor != '\n') anchor--; if (*anchor == '\n') anchor++; /* Move to this line, just near top of screen */ if (!pes->first_time) addBookmark(pes); pes->seek_base = anchor; pes->seek_cnt = -1; pes->clink = 0; /* RP - Added 5.3.2 */ pes->link_text = 0; *pes->text_holder = 0; statusbar (NULL); return NAVIGATE_DONT; } else { int triedasfile = 0; int tryexact = 1; sprintf (pes->text_holder, "%.*s", link_length (pes->link_text + 1), pes->link_text + 1); strlwr (pes->text_holder); write_string (TEXT_COLOR, X + strlen(hcatStatusLooking) + 3, TY, hcatStatusEscape); do { pes->p = pes->body_start; while ((pes->p = strstr (pes->p, "<a")) != 0) { static struct event ev; get_event (&ev, EV_KEY | EV_NONBLOCK); if (ev.ev_type == EV_KEY && ev.key == 27) { pes->link_text = 0; show_error(hcatUserAborted); return NAVIGATE_DONT; } pes->p = strchr (pes->p, '>'); if (pes->p) { ++(pes->p); if ((strnicmp(pes->p, pes->text_holder, strlen (pes->text_holder)) == 0) && (pes->p[strlen(pes->text_holder)] == '<' || !tryexact)) { while (pes->p != pes->body_start && strncmp (pes->p, "<a", 2)) pes->p--; pes->p = strstr (pes->p, "href="); if (pes->p != 0) { pes->p += 6; if (*pes->p == '\"') pes->p++; if (*pes->p == '#') break; if (prepare_link (pes)) { if (tryexact == 0) show_error(hcatNoExactFound); return NAVIGATE_LINK; } } } } } if (triedasfile == 0) { int undostrcat = strlen (base_dir); if (base_dir[strlen (base_dir) - 1] != '\\' && base_dir[0] != 0) strcat (base_dir, "\\"); strcat (base_dir, pes->text_holder); if (checkForFile (base_dir)) { /* Didn't work */ base_dir[undostrcat] = '\0'; } else { if (pes->first_time) pes->hidden = 1; get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); return NAVIGATE_HOME; } triedasfile = 1; } else { /* don't try to match end with the < */ if (tryexact) { tryexact = 0; } else { pes->p = pes->text_holder + strlen (pes->text_holder) - 1; if (*pes->p > 'a') --(*pes->p); else *pes->p = 0; } } } while (*(pes->text_holder) != 0); } statusbar (NULL); sprintf (pes->text_holder, "%s '%.*s'", hcatCouldntFind, link_length (pes->link_text + 1), pes->link_text + 1); show_error (pes->text_holder); pes->link_text = 0; *(pes->text_holder) = 0; return NAVIGATE_DONT; } else if (prepare_link (pes)) return NAVIGATE_LINK; pes->link_text = 0; } if (pes->first_time) { drawmenu(); save_window (X, Y, W, H, pes->screen_buf); pes->first_time = 0; } if (pes->seek_cnt != 0) { if (pes->seek_cnt <= 0) { i = -pes->seek_cnt; pes->p = pes->seek_base - 1; if (*pes->p == '\n') pes->p--; for (; (pes->p != pes->body_start); pes->p--) if (*pes->p == '\n') { i--; if (i == 0) { pes->p++; break; } } pes->top = pes->p; } else if (pes->seek_cnt > 0) { i = pes->seek_cnt; pes->p = pes->seek_base; for (; pes->p != pes->body_end; pes->p++) if (*pes->p == '\n') { i--; if (i == 0) { pes->p++; break; } } if (pes->p == pes->body_end) { pes->seek_base = pes->body_end - 1; pes->seek_cnt = -1; return NAVIGATE_DONT; } pes->top = pes->p; } pes->seek_cnt = 0; } if (pes->maxtop != 0) pes->barpos = ((pes->top - pes->body_start) * BARLEN) / pes->maxtop; else pes->barpos = BARLEN - 1; if (pes->barpos >= BARLEN || pes->barpos < 0) /* <0 fix - RP */ pes->barpos = BARLEN - 1; if (pes->bar_hooked) { pes->seek_base = pes->top; if (pes->forced_barpos == 0) { pes->top = pes->body_start; pes->barpos = 0; } else if (pes->forced_barpos == BARLEN - 1 && pes->barpos != pes->forced_barpos) { pes->old_barpos = pes->barpos; pes->seek_base = pes->body_end; pes->seek_cnt = -N; return NAVIGATE_DONT; } else if (pes->forced_barpos < pes->barpos && pes->forced_barpos < pes->old_barpos) { pes->old_barpos = pes->barpos; pes->seek_cnt = -1; return NAVIGATE_DONT; } else if (pes->forced_barpos > pes->barpos && pes->forced_barpos > pes->old_barpos) { pes->old_barpos = pes->barpos; pes->seek_cnt = +1; return NAVIGATE_DONT; } } pes->old_barpos = pes->barpos; if (pes->top != pes->old_top) pes->force_redraw = 1; /* ------ Display processing ------------------------------------ */ displayProcess (pes); /* ------ Event processing -------------------------------------- */ return processEvents (pes); }