Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

nanomud-terminal.c File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <winsock.h>
#include <richedit.h>
#include <assert.h>
#include "NanoMud.h"

Include dependency graph for nanomud-terminal.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  sel

Defines

#define ATTR_CLEAR   0x0000D800UL
#define USIZE   (sizeof(unsigned long))

Typedefs

typedef termbuf TBuf

Functions

int add_term (TERMBUF *term, char *line)
void check_url (TERMBUF *term)
void chop_line (TERMBUF *ter)
void ClearTerminal ()
void do_nasty (void)
void do_update_paint (HDC hdc, int left, int top, int right, int bottom)
void do_url (const char *url)
void export_to_html (void)
TERMBUFfetch_line (unsigned long int idx)
void fix_line (TERMBUF *line1, TERMBUF *line2)
void FlushBuffer (char *buffer, int colour2, int bKcolour2)
void FreeTerm (void)
char * get_line (int num)
int GetWindowWrap (HWND hwnd)
u_short in_cksum (u_short *addr, int len)
void interp_mouse (int rws, int cls, int state)
void log_html (const char *str, int colour)
void lookupseq (char *seq, char *ret[2])
TERMBUFnew_line (void)
TERMBUFnew_term (char *buffer)
TERMBUFnew_termbuffer (void)
void parse_ansi (TERMBUF *ter, BOOL is_logging_html)
void ParseLines (unsigned char *readbuff)
void realize_lines (char *lline)
TERMBUFreplace_line (unsigned long int line, TERMBUF *tbuf)
void scroll_term (long int pos, long int to)
void set_mouse_pos (int y, int x)
void set_scroll (unsigned long int t, unsigned long int s, unsigned long int p)
char * strip_ansi (const char *str)
void terminal_initialize ()
void terminal_resize ()
void update_scroll (void)
void update_term (void)
BOOL wraps (char *buf)

Variables

ansi_table a_table []
long int bufcount
COLORREF colours
int cols
long int curdis
long int curpos
bool found = FALSE
HDC hdc
TERMBUFhold_buf
BOOL holding = FALSE
char holdline [811920]
BUFFERinbuf
bool is_scrolling
int lastnumber = 0
poss pos
PAINTSTRUCT ps
int rows
char str_empty [1]
TBufterm_screen [100]
SDATAthis_session
bool update_line
int wwrap


Define Documentation

#define ATTR_CLEAR   0x0000D800UL
 

Definition at line 71 of file nanomud-terminal.c.

#define USIZE   (sizeof(unsigned long))
 

Definition at line 76 of file nanomud-terminal.c.


Typedef Documentation

typedef struct termbuf TBuf
 

Definition at line 54 of file nanomud-terminal.c.


Function Documentation

int add_term TERMBUF term,
char *  line
 

Definition at line 759 of file nanomud-terminal.c.

References termbuffer::buf, termbuffer::buf_attrib, termbuffer::buf_col_back, termbuffer::buf_col_fore, termbuffer::buffer, FALSE, fix_line(), GiveError(), GREY, hold_buf, holding, malloc, new_line(), parse_ansi(), str_dup(), str_search(), strip_ansi(), and TERMBUF.

Referenced by realize_lines().

00760 {
00761      
00762     TERMBUF *term_back = new_line();
00763     if (term_back == NULL)
00764         GiveError("...",FALSE);
00765     
00766     int chunk = strlen(strip_ansi(line)) + 1;
00767     
00768     
00769     term_back->buffer = str_dup(line);
00770     term_back->buf = malloc(chunk);
00771     term_back->buf_col_back = malloc(chunk);
00772     term_back->buf_col_fore = malloc(chunk);
00773     term_back->buf_attrib   = malloc(chunk);
00774     memset(term_back->buf_col_back, 0 , chunk);
00775     memset(term_back->buf_col_fore, GREY , chunk);
00776     //memset(term_back->buf_col_fore, 17 , strlen(line));
00777     
00778         
00779     if (holding == TRUE)
00780     {
00781         holding = FALSE;
00782         fix_line(hold_buf, term_back);
00783     }
00784         
00785     if (!str_search(&line[strlen(line)-7]))
00786     {
00787         hold_buf = term_back;
00788         holding = TRUE;
00789     }
00790     parse_ansi(term_back, FALSE);
00791     
00792     //parse_ansi(term_back->buf, TRUE); /* Comment/uncomment this line for HTML parsing.*/
00793     //check_url(term_back);
00794 
00795         
00796    
00797 }

Here is the call graph for this function:

void check_url TERMBUF term  ) 
 

Definition at line 1615 of file nanomud-terminal.c.

References termbuffer::buf, do_url(), fnmatch(), is_operator(), pos, str_dup(), TERMBUF, and poss::y.

Referenced by interp_mouse().

01616 {
01617     char *buffer = str_dup(term->buf);
01618     char *point = buffer;
01619     int i;
01620     char sp[] = " ";
01621     char *tok;
01622     
01623     for (i=1;*point;point++,i++)
01624     {
01625         if (i==pos.y)
01626         {
01627             break;
01628         }
01629         else
01630         {
01631             continue;
01632         }
01633     }
01634     
01635     for (;*point;point--,i--)
01636     {
01637         if (*point == ' ')
01638             break;            
01639         continue;
01640     }
01641     point = NULL;
01642     tok = strtok(&buffer[i], sp);
01643     
01644     if (tok == NULL)
01645         return;
01646     if (is_operator(&tok[strlen(tok)-1])) 
01647     {
01648         tok[strlen(tok)-1] = '\0';
01649     }    
01650     
01651         
01652     if (fnmatch("*http://*.*", tok, 0) == 0 || fnmatch("*https://*.*", tok, 0) == 0 ||
01653         fnmatch("*ftp://*.*", tok, 0) == 0 || fnmatch("*www.*", tok, 0) == 0)
01654     {
01655         do_url(tok);
01656         return;
01657     }
01658 }

Here is the call graph for this function:

void chop_line TERMBUF ter  ) 
 

Definition at line 686 of file nanomud-terminal.c.

References termbuffer::buf, termbuffer::buf_attrib, termbuffer::buf_col_back, termbuffer::buf_col_fore, termbuffer::buffer, cols, malloc, new_line(), termbuffer::not_finished, termbuffer::processed, str_dup(), and TERMBUF.

Referenced by parse_ansi().

00687 {
00688     TERMBUF *cline;
00689     int chunk;
00690     
00691     if (strlen(ter->buf) > cols)
00692     {
00693         cline = new_line();
00694         chunk = strlen(ter->buf) - cols;
00695         
00696         cline->buf = str_dup(&ter->buf[cols]);
00697         cline->buf_col_back = malloc(chunk+4);
00698         cline->buf_col_fore = malloc(chunk+4);
00699         cline->buf_attrib   = malloc(chunk+4);
00700 
00701         memset(cline->buf_col_back, 0, chunk);
00702         memset(cline->buf_col_fore, 0, chunk);
00703         memcpy(cline->buf_col_back, &ter->buf_col_back[cols], chunk+1);
00704         memcpy(cline->buf_col_fore, &ter->buf_col_fore[cols], chunk+1);
00705         memcpy(cline->buf_attrib, &ter->buf_attrib[cols], chunk+1);
00706         
00707 
00708         ter->buf[cols] = '\0';
00709         ter->buf_col_back[cols] = '\0';
00710         ter->buf_col_fore[cols] = '\0';
00711         ter->buf_attrib[cols] = '\0';
00712         cline->buf[chunk+1] = '\0';
00713         cline->buf_col_fore[chunk] = '\0';
00714         cline->buf_col_back[chunk] = '\0';
00715         cline->buf_attrib[chunk] = '\0';
00716         ter->processed = TRUE;
00717         cline->processed = TRUE;
00718         cline->not_finished = ter->not_finished;
00719         ter->buffer = NULL;
00720         cline->buffer = NULL;
00721 
00722 
00723     }
00724     
00725             
00726 }

Here is the call graph for this function:

void ClearTerminal void   ) 
 

Definition at line 1160 of file nanomud-terminal.c.

References hdc, termbuf::hdc, hf, mudrect, and tbuf.

01161 {
01162   return;
01163   int runner=0;
01164   int runner2=0;
01165   char clr[700];
01166   hdc = tbuf->hdc;
01167   extern RECT mudrect;
01168   extern  HFONT hf;
01169   SelectObject(hdc, hf);
01170   SetBkColor(hdc,RGB(0,0,0)); 
01171   memset(clr, ' ', 700);
01172   for (runner=0;runner<=700;runner++)
01173   {
01174           ExtTextOut(hdc, 0,runner, ETO_CLIPPED, &mudrect, clr, 700, NULL);
01175           runner +=12;
01176           
01177   }
01178   tbuf->x_end = 0;
01179   tbuf->y_end =0;
01180 
01181   return;
01182   
01183 }

void do_nasty void   ) 
 

Definition at line 613 of file nanomud-terminal.c.

References give_term_debug(), GiveError(), nasty, read_string(), realize_lines(), and str_dup().

Referenced by WindowProcedure().

00614 {
00615     
00616          FILE *fp;     
00617          DWORD start,end;
00618          char buf[32000];
00619          char buff[1000];
00620          char *buffer=NULL;
00621          int rawr=0;
00622          unsigned long int meh=0;
00623          MSG messages;
00624          char buf2[100];
00625          int ret;
00626          unsigned char bleh[310002];
00627          if ((fp = fopen("asd.txt", "r")) == NULL)
00628          {
00629              GiveError("Bleh",1);
00630              return;
00631          }
00632          //nasty = TRUE;
00633          start = GetTickCount();
00634          while ((ret = read_string(buf, fp)) > -1)
00635          {
00636              buf[ret -1] = '\0';
00637              strcat(buf, "\n");
00638              realize_lines(str_dup(&buf[0]));
00639              meh++;
00640              bleh[0] = '\0';
00641              buf[0] = '\0';
00642           }
00643           nasty = FALSE;
00644           end = GetTickCount();
00645           give_term_debug("%d lines read and parsed in %d miliseconds.", meh, (int) end-start);
00646           fclose(fp);
00647                 
00648 }

Here is the call graph for this function:

void do_update_paint HDC  hdc,
int  left,
int  top,
int  right,
int  bottom
 

Definition at line 1564 of file nanomud-terminal.c.

References bufcount, curdis, FALSE, fetch_line(), free_context(), hdc, parse_ansi(), rows, and tbuf.

Referenced by WindowProcedure().

01565 {
01566     
01567     int i,j,x,k=0;
01568     int viewing;
01569 
01570     top -=3;
01571     bottom +=3;
01572     if (top < 0)
01573         top = 0;
01574     if (bottom > rows)
01575         bottom = rows;
01576     if (right > cols)
01577         right = cols;
01578     if (left < 0)
01579         left = 0;
01580     j = (bufcount <= rows) ? 1 : (bufcount - rows);
01581     
01582 
01583     
01584     if (curdis < 0)
01585     {
01586         viewing = bufcount - -curdis;
01587         
01588         
01589         for (i = viewing - rows + top, k = 0, x=top;i <= viewing - rows + bottom;i++,k++,x++)
01590         {
01591            
01592             
01593             tbuf->y_end = x*13;
01594             tbuf->x_end = 0;
01595             parse_ansi(fetch_line(i),FALSE);
01596 
01597 
01598         }
01599         
01600     }
01601     else
01602     { 
01603         for (i = top+j,x=top;i <= (bufcount <= rows? bottom : bottom + j);i++,x++)
01604         {
01605             tbuf->y_end = x*13;
01606             tbuf->x_end = 0;
01607             parse_ansi(fetch_line(i), FALSE);
01608         }
01609     }
01610     free_context(hdc);
01611 
01612     return;
01613 }

Here is the call graph for this function:

void do_url const char *  url  ) 
 

Definition at line 1659 of file nanomud-terminal.c.

Referenced by check_url(), and WindowProcedure().

01660 {
01661     ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
01662     return;
01663 }

void export_to_html void   ) 
 

Definition at line 943 of file nanomud-terminal.c.

References termbuffer::buf, termbuffer::buf_col_back, termbuffer::buf_col_fore, fetch_line(), log_html(), and TERMBUF.

Referenced by WindowProcedure().

00944 {
00945     int i,j,k=0;
00946     TERMBUF *temp;
00947     char *point;
00948     char buf[1000]="";
00949     char buf2[1000]="";
00950     char *buffer;
00951     buffer = buf2;
00952     int color;
00953     int bkcolor;
00954     
00955     for (k=1;k<=bufcount;k++)
00956     {
00957         temp = fetch_line(k);
00958         point = temp->buf;
00959                 
00960         j = strlen(temp->buf);
00961 
00962         for (i = 0; i<=j;i++,point++)
00963         {
00964             
00965             if (!*point)
00966             {
00967                 log_html("\n", -1);
00968                 break;
00969             }    
00970             *buffer = *point;
00971             
00972             if (*point == '<')
00973             {
00974                 strcat(buf, "&#60;");
00975             }
00976             else if (*point == '>')
00977             {
00978                 strcat(buf, "&#62;");
00979             }
00980             else
00981             {
00982                 strcat(buf, buffer);
00983             }    
00984             color = temp->buf_col_fore[i];
00985 
00986             if (temp->buf_col_fore[i] == temp->buf_col_fore[i+1] &&
00987                 temp->buf_col_back[i] == temp->buf_col_back[i+1])
00988             {
00989                 buf2[0] = '\0';
00990                 continue;
00991             }
00992             
00993             bkcolor = temp->buf_col_back[i];
00994             
00995             log_html(buf, color);
00996             //FlushBuffer(buf, colour,bKcolour);
00997             buf[0] = '\0';
00998             buf2[0] = '\0';
00999           
01000         }
01001         
01002     }
01003 }        

Here is the call graph for this function:

TERMBUF* fetch_line unsigned long int  idx  ) 
 

Definition at line 669 of file nanomud-terminal.c.

References bufcount, LOG(), TERMBUF, session_data::termlist, and this_session.

Referenced by do_update_paint(), export_to_html(), FreeTerm(), get_line(), interp_mouse(), ParseLines(), replace_line(), and update_term().

00670 {
00671     if (idx > bufcount)
00672         return NULL;
00673     else
00674     {
00675         if (this_session->termlist[idx] == NULL)
00676         {
00677             LOG("Error! Fetchline tried to grab an invalid line of %d with a max count of %d", idx, bufcount);
00678             return NULL;
00679         }    
00680         else
00681             return this_session->termlist[idx];//->buf;
00682     }
00683 }

Here is the call graph for this function:

void fix_line TERMBUF line1,
TERMBUF line2
 

Definition at line 1417 of file nanomud-terminal.c.

References termbuffer::buf, GiveError(), hold_buf, LOG(), TERMBUF, TRUE, and update_term().

Referenced by add_term().

01418 {
01419     
01420     int i;
01421     char buf[5000]="";
01422     char buf2[5000]="";
01423     char temp[5000]="";
01424     char *buffer;
01425     char *point;
01426     buffer = buf2;
01427     
01428     
01429     
01430     if (line1 == NULL || line2 == NULL)
01431     {
01432         LOG("%s, %d, Line1/2 NULL", __FILE__, __LINE__);
01433         return;
01434     }
01435     
01436     /* Line1 should be the first line that we want to append TO.
01437      * Line2 is the line we should want to grab FROM to append with.
01438      * simple enough?
01439      */
01440     
01441     if (strlen(line1->buf) >= 2480)
01442     {
01443         GiveError("In fix_line, Terminal.c, Line1 is too large to edit. You should NOT see this error.", TRUE);
01444         return;
01445     }
01446     
01447     point = line2->buf;
01448     for (i=0;;point++,i++)
01449     {
01450 
01451         if (*point == '\0')
01452             break;
01453         if (*point == 'm')
01454         {
01455             *buffer = *point;
01456             strcat(buf, buffer);
01457             buffer[0] = '\0';
01458             break;
01459         }
01460         *buffer = *point;
01461         strcat(buf, buffer);
01462         buffer[0] = '\0';
01463     }
01464 
01465     strcat(line1->buf, buf);
01466     i++;
01467 
01468     memcpy(temp, &line2->buf[i], strlen(&line2->buf[i]));
01469     memcpy(line2->buf, temp, strlen(temp));
01470     hold_buf = NULL;
01471     update_term();
01472 
01473 }

Here is the call graph for this function:

void FlushBuffer char *  buffer,
int  colour2,
int  bKcolour2
 

Definition at line 1024 of file nanomud-terminal.c.

References BLACK, BLUE, C_BLACK, C_BLUE, C_CYAN, C_GREEN, C_MAGENTA, C_RED, C_WHITE, C_YELLOW, CYAN, GREEN, GREY, hdc, termbuf::hdc, hf, MAGENTA, MudMain, mudrect, nasty, ps, RED, tbuf, TRUE_BLACK, WHITE, wwrap, and YELLOW.

Referenced by parse_ansi(), set_mouse_pos(), term_test_2(), and WindowProcedure().

01025 {
01026 
01027   if (buffer[0] == '\0')
01028       return;  
01029   if (nasty == TRUE)
01030       return;
01031   int runner=0;
01032   int runner2=0;
01033   PAINTSTRUCT ps;
01034   RECT trc;
01035   RECT mudrect;
01036   GetClientRect(MudMain, &mudrect);
01037   mudrect.bottom -= 20;
01038   extern  HFONT hf;
01039   int wrap;
01040   HDC hdc = tbuf->hdc;
01041   
01042 
01043 
01044   BeginPaint(MudMain, &ps);
01045   SelectObject(hdc, hf);
01046   
01047   
01048   EndPaint(MudMain, &ps);
01049  
01050  switch(bKcolour2)
01051  {
01052     case RED:        SetBkColor(hdc, RGB(255,0  ,0  )); break;
01053     case BLUE:       SetBkColor(hdc, RGB(0  ,0  ,255)); break;
01054     case GREEN:      SetBkColor(hdc, RGB(0  ,255,0  )); break;
01055     case BLACK:      SetBkColor(hdc, RGB(75 ,75 ,75 )); break;
01056     case YELLOW:     SetBkColor(hdc, RGB(255,255,0  )); break;
01057     case MAGENTA:    SetBkColor(hdc, RGB(255,0  ,255)); break;
01058     case CYAN:       SetBkColor(hdc, RGB(0  ,255,255)); break;
01059     case WHITE:      SetBkColor(hdc, RGB(255,255,255)); break;
01060     case C_RED:      SetBkColor(hdc, RGB(128,0  ,0  )); break;
01061     case C_BLUE:     SetBkColor(hdc, RGB(0  ,0  ,128)); break;
01062     case C_GREEN:    SetBkColor(hdc, RGB(0  ,192,0  )); break;
01063     case C_BLACK:    SetBkColor(hdc, RGB(128,128,128)); break;
01064     case C_YELLOW:   SetBkColor(hdc, RGB(128,128,0  )); break;
01065     case C_MAGENTA:  SetBkColor(hdc, RGB(128,0  ,128)); break;
01066     case C_CYAN:     SetBkColor(hdc, RGB(0  ,127,128)); break;
01067     case C_WHITE:    SetBkColor(hdc, RGB(128,128,128)); break;
01068     case GREY:       SetBkColor(hdc, RGB(192,192,192)); break;
01069     case TRUE_BLACK: SetBkColor(hdc, RGB(0  ,0  ,0  )); break;
01070     default:         SetBkColor(hdc, RGB(0  ,0  ,0  )); break;
01071 
01072   }
01073 
01074  switch(colour2)
01075  {
01076     case RED:        SetTextColor(hdc, RGB(255,0  ,0  )); break;
01077     case BLUE:       SetTextColor(hdc, RGB(0  ,0  ,255)); break;
01078     case GREEN:      SetTextColor(hdc, RGB(0  ,255,0  )); break;
01079     case BLACK:      SetTextColor(hdc, RGB(75 ,75 ,75 )); break;
01080     case YELLOW:     SetTextColor(hdc, RGB(255,255,0  )); break;
01081     case MAGENTA:    SetTextColor(hdc, RGB(255,0  ,255)); break;
01082     case CYAN:       SetTextColor(hdc, RGB(0  ,255,255)); break;
01083     case WHITE:      SetTextColor(hdc, RGB(255,255,255)); break;
01084     case C_RED:      SetTextColor(hdc, RGB(128,0  ,0  )); break;
01085     case C_BLUE:     SetTextColor(hdc, RGB(0  ,0  ,128)); break;
01086     case C_GREEN:    SetTextColor(hdc, RGB(0  ,192,0  )); break;
01087     case C_BLACK:    SetTextColor(hdc, RGB(128,128,128)); break;
01088     case C_YELLOW:   SetTextColor(hdc, RGB(128,128,0  )); break;
01089     case C_MAGENTA:  SetTextColor(hdc, RGB(128,0  ,128)); break;
01090     case C_CYAN:     SetTextColor(hdc, RGB(0  ,127,128)); break;
01091     case C_WHITE:    SetTextColor(hdc, RGB(128,128,128)); break;
01092     case GREY:       SetTextColor(hdc, RGB(192,192,192)); break;
01093     case TRUE_BLACK: SetTextColor(hdc, RGB(0  ,0  ,0  )); break;
01094     default:         SetTextColor(hdc, RGB(192,192,192)); break;
01095 
01096   }
01097 
01098 
01099 
01100   wrap = ((tbuf->x_end == 0 ? 8 : tbuf->x_end) / 8)  + (strlen(buffer));
01101   if (wrap  > wwrap)
01102   {
01103   
01104       int to_wrap=1;
01105       int len = strlen(buffer);
01106       int tbuf_x = ((tbuf->x_end == 0 ? 8 : tbuf->x_end) / 8);
01107       int i=0;
01108       char pad[strlen(buffer)];
01109       to_wrap =  wwrap - tbuf_x;
01110       
01111       ExtTextOut(hdc, tbuf->x_end, tbuf->y_end, ETO_CLIPPED, &mudrect, buffer, to_wrap, NULL);
01112       tbuf->x_end =0;
01113       tbuf->y_end +=13;
01114       char to_send[strlen(buffer)];
01115       strcat(to_send, "    ");
01116       strcat(to_send, &buffer[to_wrap]);
01117       
01118       buffer[0] = '\0';
01119 
01120         return;
01121    }
01122    else
01123    {
01124        ExtTextOut(hdc, tbuf->x_end,tbuf->y_end,ETO_CLIPPED,&mudrect, buffer, strlen(buffer),NULL);
01125 
01126 
01127        tbuf->x_end += (strlen(buffer) > 1 ? strlen(buffer) * 8 : 8);
01128        buffer[0] = '\0';
01129    }
01130    
01131    return;
01132    
01133 
01134 
01135 }

void FreeTerm void   ) 
 

Definition at line 1005 of file nanomud-terminal.c.

References termbuffer::buf, termbuffer::buf_col_back, termbuffer::buf_col_fore, termbuffer::buffer, fetch_line(), free, TERMBUF, session_data::termlist, and this_session.

Referenced by WindowProcedure().

01006 {
01007     int i;
01008     TERMBUF *rem;
01009     for (i=1;i<= bufcount;i++)
01010     {
01011        rem = fetch_line(i);
01012        free (rem->buf);
01013        free (rem->buffer);
01014        free (rem->buf_col_back);
01015        free (rem->buf_col_fore);
01016        free (rem);
01017        
01018     }
01019    free(this_session->termlist);
01020 }       

Here is the call graph for this function:

char* get_line int  num  ) 
 

Definition at line 811 of file nanomud-terminal.c.

References termbuffer::buf, bufcount, curdis, fetch_line(), LOG(), rows, str_dup(), and TERMBUF.

00812 {
00813 
00814     if (bufcount == 1 && num > 1)
00815         return;
00816     int view, i,j;
00817     if (num == 0)
00818         return NULL;
00819     int nt;
00820     nt = (num == 0 ? 1 : num);
00821     num = nt;
00822     TERMBUF *temp;
00823     temp = 0;
00824     view = bufcount - -curdis;
00825     
00826     view -= rows;
00827     view += num;
00828     view -= 1;
00829     
00830     if (view == 0)
00831         view = 1;
00832     if (view > bufcount)
00833         view = bufcount;
00834     
00835     
00836     LOG("View: %d, rows: %d, bufcount: %d, num: %d, curdis: %d", view, rows, bufcount, num,curdis);
00837     if (num > bufcount || view > bufcount)
00838         return NULL;
00839     if (curdis < 0)
00840         temp = fetch_line(view);
00841     else if (num <= bufcount)
00842         temp = fetch_line(num);
00843     
00844     return str_dup(temp->buf);
00845 }    

Here is the call graph for this function:

int GetWindowWrap HWND  hwnd  ) 
 

Definition at line 1298 of file nanomud-terminal.c.

References srect.

Referenced by terminal_initialize(), terminal_resize(), and wraps().

01299 {
01300     int screen_width;
01301     RECT srect;
01302     int remainder;
01303     int font_width = 8;
01304     GetClientRect(hwnd, &srect);
01305     screen_width = srect.right;
01306     
01307     if ((screen_width % font_width) == 0)
01308         remainder = (screen_width - (screen_width % 8)) / font_width;
01309     else
01310         remainder = (screen_width / 8);
01311     return remainder;
01312 }

u_short in_cksum u_short *  addr,
int  len
 

Definition at line 144 of file nanomud-net.c.

00145 {
00146     register int nleft = len;
00147     register u_short *w = addr;
00148     register u_short answer;
00149     register int sum = 0;
00150 
00151     /*
00152      *  Our algorithm is simple, using a 32 bit accumulator (sum),
00153      *  we add sequential 16 bit words to it, and at the end, fold
00154      *  back all the carry bits from the top 16 bits into the lower
00155      *  16 bits.
00156      */
00157     while( nleft > 1 )  {
00158         sum += *w++;
00159         nleft -= 2;
00160     }
00161 
00162     /* mop up an odd byte, if necessary */
00163     if( nleft == 1 ) {
00164         u_short u = 0;
00165 
00166         *(u_char *)(&u) = *(u_char *)w ;
00167         sum += u;
00168     }
00169 
00170     /*
00171      * add back carry outs from top 16 bits to low 16 bits
00172      */
00173     sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
00174     sum += (sum >> 16);         /* add carry */
00175     answer = ~sum;              /* truncate to 16 bits */
00176     return (answer);
00177 }

void interp_mouse int  rws,
int  cls,
int  state
 

Definition at line 1530 of file nanomud-terminal.c.

References termbuffer::buf, bufcount, check_url(), fetch_line(), tbuf, and TERMBUF.

Referenced by WindowProcedure().

01531 {
01532     char buf2[200];
01533     char *buf;
01534     buf = buf2;
01535     int j;
01536     //rws++;
01537     j = (bufcount <= rows) ? 1 : (bufcount - rows);
01538     tbuf->y_end = rws * 13;
01539     tbuf->x_end = 0;
01540     rws = rws + j;
01541     TERMBUF *temp;
01542     temp = fetch_line(rws);
01543     if (!temp)
01544         return;
01545     
01546     memcpy(buf2, temp->buf, strlen(temp->buf));
01547     buf2[strlen(temp->buf)] = '\0';
01548     check_url(temp);
01549     
01550        
01551 
01552 //    FlushBuffer(buf, BLACK, CYAN);
01553     tbuf->y_end=0;
01554     tbuf->x_end = 0;
01555     buf2[0] = '\0';
01556     buf = NULL;
01557     
01558     return;
01559 }

Here is the call graph for this function:

void log_html const char *  str,
int  colour
 

Definition at line 1475 of file nanomud-terminal.c.

References BLACK, BLUE, C_BLACK, C_BLUE, C_CYAN, C_GREEN, C_MAGENTA, C_RED, C_WHITE, C_YELLOW, colour, CYAN, free, GiveError(), GREEN, GREY, html_log, LOG(), MAGENTA, RED, str_dup(), TRUE, WHITE, and YELLOW.

Referenced by export_to_html().

01476 {
01477     FILE *fp;
01478     char ccode[50]="";
01479     char *code;
01480     code = ccode;
01481     
01482     if (str[strlen(str)] != '\0')
01483         GiveError("Well shit.",TRUE);
01484     if ((fp = fopen(html_log, "a")) == NULL)
01485     {
01486         LOG("Unable to open html logfile.");
01487         return;
01488     }
01489     
01490     switch(colour)
01491     {
01492         case RED:       code = str_dup("#FF0000"); break;
01493         case BLUE:      code = str_dup("#0000FF"); break;
01494         case GREEN:     code = str_dup("#00FF00"); break;
01495         case BLACK:     code = str_dup("#999999"); break;
01496         case YELLOW:    code = str_dup("#FFFF00"); break;
01497         case MAGENTA:   code = str_dup("#FF00FF"); break;
01498         case CYAN:      code = str_dup("#00FFFF"); break;
01499         case WHITE:     code = str_dup("#FFFFFF"); break;
01500         case C_RED:     code = str_dup("#990000"); break;
01501         case C_BLUE:    code = str_dup("#000099"); break;
01502         case C_GREEN:   code = str_dup("#00CC00"); break;
01503         case C_BLACK:   code = str_dup("#808080"); break;
01504         case C_YELLOW:  code = str_dup("#808000"); break;
01505         case C_MAGENTA: code = str_dup("#800080"); break;
01506         case C_CYAN:    code = str_dup("#008080"); break;
01507         case C_WHITE:   code = str_dup("#808080"); break;
01508         case GREY:      code = str_dup("#C0C0C0"); break;
01509         case -1:        code = str_dup("");        break;
01510         default:        code = str_dup("#C0C0C0"); break;
01511     }
01512     
01513     if (colour == -1)
01514     {
01515         fprintf(fp, "\n");
01516     }
01517     else
01518     {
01519         fprintf(fp, "<font color=%s>%s</font>", code, str);
01520     }    
01521     fclose (fp);
01522     free(code);
01523 
01524   
01525 
01526 
01527 
01528 }

Here is the call graph for this function:

void lookupseq char *  seq,
char *  ret[2]
 

Definition at line 211 of file nanomud-terminal.c.

References a_table, and ansi_table::seq.

00212 {
00213     int ii;
00214     
00215     for (ii=0;a_table[ii].seq != NULL;ii++)
00216     {
00217         if (!strcmp(seq, a_table[ii].seq))
00218         {
00219             
00220         }
00221     }
00222     
00223 }

TERMBUF* new_line void   ) 
 

Definition at line 732 of file nanomud-terminal.c.

References bufcount, GiveError(), malloc, termbuffer::processed, replace_line(), TERMBUF, session_data::termlist, this_session, and TRUE.

Referenced by add_term(), and chop_line().

00733 {
00734     
00735     TERMBUF *templine=0;
00736     int err;
00737     
00738     templine = (TERMBUF *)malloc(sizeof(*templine));
00739     if (templine == NULL)
00740         GiveError("Wow..something went wrong there! Place: TERMBUF * new_line(void) module: nanomud-terminal.c", TRUE);
00741     
00742     bufcount+=1;
00743     if (bufcount > 1000009)
00744     {
00745         bufcount = 1000009;
00746         replace_line(1, NULL);
00747     }
00748     
00749     
00750     
00751     this_session->termlist[bufcount] = templine;
00752     
00753     templine->processed = FALSE;
00754         
00755     return templine;
00756 }

Here is the call graph for this function:

TERMBUF* new_term char *  buffer  ) 
 

Definition at line 1315 of file nanomud-terminal.c.

References backfree, termbuffer::buffer, malloc, and TERMBUF.

01316 {
01317     TERMBUF *p;
01318     
01319     p = NULL;
01320     p = malloc(sizeof(TERMBUF));
01321     //p->buffer = str_dup(buffer);
01322     memcpy(p->buffer, buffer, sizeof(buffer));
01323 //    p->prev = p;
01324 //    p->next = backfree;
01325     backfree = p;
01326     return p;
01327 }

TERMBUF* new_termbuffer void   ) 
 

Definition at line 1328 of file nanomud-terminal.c.

References backfirst, backfree, malloc, and TERMBUF.

01329 {
01330     
01331     static TERMBUF trbuf;
01332     TERMBUF * pBack;
01333     
01334     if (backfree == NULL)
01335     {
01336         pBack = malloc(sizeof(*pBack));
01337         
01338     }
01339     else
01340     {
01341 
01342         
01343         pBack = backfree;
01344 //        backfree = backfree->next;
01345         backfirst = pBack;
01346     }
01347     
01348     *pBack = trbuf;
01349    
01350     
01351     
01352     
01353 
01354     return pBack;
01355 }

void parse_ansi TERMBUF ter,
BOOL  is_logging_html
 

Definition at line 228 of file nanomud-terminal.c.

References a_table, ansi_table::back, bKcolour, BOOL, termbuffer::buf, termbuffer::buf_col_back, termbuffer::buf_col_fore, termbuffer::buffer, chop_line(), colour, cols, FlushBuffer(), ansi_table::fore, termbuffer::not_finished, termbuffer::processed, ansi_table::seq, tbuf, TERMBUF, and TRUE_BLACK.

Referenced by add_term(), do_update_paint(), ParseLines(), and update_term().

00229 {
00230   if (!ter)
00231   return;
00232   
00233   char *point= ter->buffer;
00234   
00235   char buf[6000]="";
00236   char buf2[6000]="";
00237   char *buffer;
00238   buffer = buf2;
00239   BOOL blink;
00240   BOOL reverse;
00241   int where=0;
00242   char abuf[10000]="";
00243   int seq[2];
00244   int ts;
00245   char stab[10000]="";
00246   char tm[10];
00247   int i,j;
00248   int b=0;
00249   is_logging_html = FALSE;
00250   BOOL match=FALSE;
00251 
00252 
00253   if (ter->processed == TRUE)
00254   {
00255       if (!ter->buf)
00256             return;
00257   
00258       j = strlen(ter->buf);
00259       point = ter->buf;
00260        
00261       for (i = 0;*point, i<=j;i++,point++)
00262       {
00263           
00264        
00265           *buffer = *point;
00266           memcpy(&buf[b], buffer,sizeof(buffer));
00267           
00268           b++;
00269           colour = ter->buf_col_fore[i];
00270 
00271           if (ter->buf_col_fore[i] == ter->buf_col_fore[i+1] &&
00272               ter->buf_col_back[i] == ter->buf_col_back[i+1])
00273           {
00274 
00275               buf2[0] = '\0';
00276               continue;
00277           }
00278           
00279           bKcolour = ter->buf_col_back[i];
00280     
00281           buf[b+1] = '\0';
00282           FlushBuffer(buf, colour,bKcolour );
00283           buf[0] = '\0';
00284           buf2[0] = '\0';
00285           b=0;
00286           
00287       }
00288       
00289 
00290       if (i < cols)
00291       {
00292           
00293           char pad[2000]="";
00294           for (j=0;j< (cols - i); j++)
00295               pad[j] = '.';
00296           pad[j] = '\0';
00297           FlushBuffer(pad, TRUE_BLACK, TRUE_BLACK);
00298       }
00299       else if (i == 0)
00300       {
00301           char pad[cols];
00302           for (j=0;j<cols;j++)
00303               pad[j] = ' ';
00304           pad[cols-1] = '\0';
00305           FlushBuffer(pad,TRUE_BLACK, TRUE_BLACK);
00306       }        
00307       if (ter->not_finished == FALSE)     
00308           return;
00309   }
00310   if (!ter->buffer)
00311       return;
00312   else
00313       point = ter->buffer;
00314   
00315   for (;*point;point++)
00316   {
00317 
00318 
00319     /* Hack to keep junk chars off the screen */
00320     if ((*point < ' ' || *point > '~') && (*point != '\e' && *point != '\n' && *point != '\r'
00321         && *point != '\t' && *point != '\a' && *point != '\0'))
00322         continue;
00323     
00324     if (*point == '\e')
00325     {
00326         
00327         while (*point != 'm' && *point)
00328         {
00329             *buffer = *point;
00330             strcat(abuf, buffer);
00331             *++point;
00332         }
00333         strcat(abuf, "m");
00334         match = FALSE;
00335     
00336         for (i=0;a_table[i].seq != NULL;i++)
00337         {
00338             if (!strcmp(abuf, a_table[i].seq))
00339             {
00340                 
00341                 seq[0] = a_table[i].fore;
00342                 seq[1] = a_table[i].back;
00343                 match = TRUE;
00344                 break;
00345             }
00346             else
00347             {
00348 
00349                 seq[0] = 0;
00350                 seq[1] = 0;
00351             }    
00352             
00353             
00354         }
00355 //        if (match == FALSE)
00356             //LOG("UNdefine refence to %s", abuf);
00357         
00358         
00359         
00360         if (seq[0] == -2)
00361         {
00362             bKcolour = TRUE_BLACK;
00363             ter->buf_col_back[where] = bKcolour ;
00364             colour = GREY;
00365             ter->buf_col_fore[where] = colour ;
00366             abuf[0] = '\0';
00367             seq[0] = 0;    
00368             seq[1] = 0;
00369             abuf[0] = '\0';
00370 
00371             continue;
00372             
00373         }
00374         else if (seq[0] == -1)
00375         {
00376             
00377             bKcolour = colour;
00378             ter->buf_col_back[where] = bKcolour;
00379             colour = TRUE_BLACK;
00380             ter->buf_col_fore[where] = colour;
00381             abuf[0] = '\0';
00382             seq[0] = 0;    
00383             seq[1] = 0;
00384             abuf[0] = '\0';
00385 
00386             continue;
00387