void do_client() { char obuffer[1024] = {0}, ibuffer[1024] = {0}; int obuffer_offset = 0, stop = 0; fflush (stdout); /* get anything out of the buffer */ conio_init(); show_buffer (obuffer, obuffer_offset); do { if (net_query (chan)) { int col = 10; int x = net_receive (chan, ibuffer, 1024, NULL); if (x<0) strcpy (ibuffer, "!!! (local) error reading packet"); else ibuffer[x] = 0; switch (ibuffer[0]) { case '*': col = 9; break; case '+': case '-': col = 11; break; case '!': col = 12; break; } write_to_window (ibuffer, col); show_buffer (obuffer, obuffer_offset); if (!strcmp (ibuffer, "*** go away")) stop = 1; if (!strcmp (ibuffer, "*** server shutting down")) stop = 1; } if (conio_kbhit()) { char ch = conio_getch(); switch (ch) { case 7: case 8: if (obuffer_offset) obuffer[--obuffer_offset] = 0; show_buffer (obuffer, obuffer_offset); break; case 13: net_send (chan, obuffer, strlen (obuffer)); obuffer[obuffer_offset = 0] = 0; show_buffer (obuffer, obuffer_offset); break; default: obuffer[obuffer_offset] = ch; obuffer[++obuffer_offset] = 0; show_buffer (obuffer, obuffer_offset); break; } } } while (!stop); erase_buffer(); conio_exit(); }
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; }