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, int lline, char *file)
void blink_term (void)
void check_url (TERMBUF *term)
void chop_line (TERMBUF *ter)
void ClearTerminal ()
void do_nasty (void)
void do_peek (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 free_line (TERMBUF *rem)
void FreeTerm (void)
char * get_line (int num)
char * get_time (void)
unsigned long int get_x (int x)
int GetWindowWrap (HWND hwnd)
void handle_selection (void)
u_short in_cksum (u_short *addr, int len)
void interp_mouse (int rws, int cls, int state)
BOOL is_same (unsigned long a, unsigned long b)
void log_html (const char *str, int colour)
TERMBUFnew_line (int line, char *file)
void parse_ansi (TERMBUF *ter, BOOL is_logging_html)
void ParseLines (unsigned char *readbuff)
unsigned long int precache_file (char *str)
void realize_lines_internal (char *lline, int line, char *file)
TERMBUFreplace_line (unsigned long int line, TERMBUF *tbuf)
char * ret_string (TERMBUF *ter, char str[])
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

unsigned 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 [50000]
BUFFERinbuf
bool is_scrolling
int last_colour
int lastnumber = 0
poss pos
PAINTSTRUCT ps
int rows
BOOL sent_efont = FALSE
char str_empty [1]
SDATAthis_session
bool update_line
int wwrap


Define Documentation

#define ATTR_CLEAR   0x0000D800UL
 

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

#define USIZE   (sizeof(unsigned long))
 

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


Typedef Documentation

typedef struct termbuf TBuf
 

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


Function Documentation

int add_term TERMBUF term,
char *  line,
int  lline,
char *  file
 

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

References termbuffer::buffer, FALSE, get_time(), GiveError(), termbuffer::has_blink, termbuffer::len, termbuffer::line, termbuffer::ln, malloc, new_line(), termbuffer::not_finished, termbuffer::processed, termbuffer::stamp, str_dup(), strip_ansi(), TERMBUF, and total_alloc.

Referenced by realize_lines_internal().

01754 {
01755     extern unsigned long int total_alloc;
01756 
01757     TERMBUF *term_back = new_line(lline,file);
01758 
01759     if (term_back == NULL)
01760         GiveError("...",FALSE);
01761 
01762     term_back->buffer = str_dup(line);
01763     term_back->line = malloc(strlen(strip_ansi(line)) * sizeof(unsigned long));
01764     term_back->has_blink = FALSE;
01765     term_back->processed = FALSE;
01766     term_back->not_finished = TRUE;
01767     term_back->ln = bufcount;
01768 
01769     term_back->len = 0;
01770     total_alloc += sizeof(term_back);
01771     sprintf(term_back->stamp, "%s", get_time());
01772     
01773 
01774 
01775     
01776         
01777     //parse_ansi(term_back, FALSE);
01778     //free(term_back->buffer);
01779     //term_back->buffer = NULL;
01780     
01781         
01782     return 0;   
01783 }

Here is the call graph for this function:

void blink_term void   ) 
 

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

References blinked, BOOL, bufcount, fetch_line(), FlushBuffer(), termbuffer::has_blink, termbuffer::len, termbuffer::line, tbuf, and TERMBUF.

Referenced by WindowProcedure().

00596 {
00597  
00598     return;
00599     int i=0;
00600     int runner=0;
00601     unsigned int bar=0;
00602     unsigned int bstart=0;
00603     unsigned int bstop = 0;
00604     unsigned int scount=0;
00605     int ccolour=0;
00606     int bkcolour=0;
00607     int x=0;
00608     int y=0;
00609     char str[100000];
00610     BOOL found_blink = FALSE;
00611     TERMBUF *temp;
00612     unsigned long cf=0;
00613     unsigned long oatr=0;
00614     
00615     
00616     i = bufcount - rows;
00617 
00618     if (i < rows)
00619         i = 0;
00620 
00621     found_blink = FALSE;
00622     /* FIXME: Re-write this. It's sloppy. Poorly coded and ugly as hell. */
00623     for (runner=0,i=(bufcount <= rows) ? 1 : ((bufcount - rows)) ;runner<=rows; i++,runner++)
00624     {
00625         temp = fetch_line(i);
00626 
00627 
00628         if (temp == NULL)
00629             continue;
00630         if (temp->has_blink == FALSE)
00631             continue;
00632 
00633         scount = temp->len;
00634 
00635 
00636          /*This line DOES have a blink SOMEWHERE in it. Let's find it. */
00637 
00638         for (bar=0;bar<= scount;bar++)
00639         {
00640             
00641             if ((temp->line[bar] & AT_BLINK) && found_blink == FALSE) 
00642             {
00643              
00644 
00645 
00646                 found_blink = TRUE;
00647                 bstart = bar;
00648                 bstop = bstart;
00649                 oatr = temp->line[bar];
00650                 continue;
00651             }
00652             
00653             if ((temp->line[bar] & AT_BLINK) && (found_blink == TRUE) && (temp->line[bar] == oatr))
00654             {
00655                 
00656 
00657                 if (temp->line[bar] != oatr) 
00658                     continue;
00659             }
00660 
00661             else if (!(temp->line[bar] & AT_BLINK) && found_blink == TRUE)
00662             {
00663                 bstop = bar - 1 ;
00664 
00665             }
00666             
00667             if ((!(temp->line[bar] & AT_BLINK) && found_blink == TRUE) || temp->line[bar] != oatr)
00668             {
00669 
00670                 
00671                 /* end of blink sequence. Let's format it up and set our
00672                  * start/end stuff and throw it into the flushbuffer */
00673                  found_blink = FALSE;
00674                  tbuf->y_end = (runner * 13); 
00675                  tbuf->x_end = bstart * 8;
00676                  str[0] = '\0';
00677 
00678 
00679                  for (y=0,x=bstart;x<=bstop;x++,y++)
00680                  {
00681                      str[y] = ((temp->line[x] & CH_MASK) >> CH_SHIFT);
00682                      str[y+1] = '\0';
00683                  }
00684                  /* We really should turn this huge hunk of if statements into
00685                   * it's own function. It'll save some space and headaches, I 
00686                   * think. Especially when we need to change a part of it. */
00687 
00688                  str[bstop-bstart+1] = '\0';
00689                  
00690                  if (blinked == FALSE) /* text is 'vis' */
00691                  {
00692 
00693                     cf = temp->line[bstop];
00694                     
00695                     if (cf == def_attr)
00696                     {
00697                         ccolour = GREY;
00698                     }
00699                     else
00700                     {
00701                         ccolour = ((cf & FG_MASK) >> FG_SHIFT);
00702                     }    
00703                     if (ccolour == 0)
00704                         ccolour = GREY;
00705 
00706 
00707                     if ((cf & ATBOLD))
00708                     {
00709                         ccolour +=10;
00710                     }    
00711 
00712                     if (ccolour == 8)
00713                     {
00714                         ccolour = GREY;
00715                     }    
00716                     else if (ccolour == 9)
00717                     {
00718                         ccolour = TRUE_BLACK;
00719                     }    
00720                     if (ccolour != GREY)
00721                         ccolour +=30;
00722 
00723                     if ((cf & ATREVER))
00724                     {
00725 
00726                         bkcolour = ccolour;
00727                         ccolour = TRUE_BLACK;
00728                     }
00729                     else
00730                     {
00731                         
00732                         bkcolour = TRUE_BLACK;
00733                     }
00734 
00735                   //  FlushBuffer(str, ccolour,bkcolour);
00736                      FlushBuffer(str, bkcolour, bkcolour);
00737 
00738                  }    
00739                  else
00740                  {
00741                     cf = temp->line[bstop];
00742                     
00743                     if (cf == def_attr)
00744                     {
00745                         ccolour = GREY;
00746                     }
00747                     else
00748                     {
00749                         ccolour = ((cf & FG_MASK) >> FG_SHIFT);
00750                     }    
00751                     if (ccolour == 0)
00752                         ccolour = GREY;
00753 
00754 
00755                     if ((cf & ATBOLD))
00756                     {
00757                         ccolour +=10;
00758                     }    
00759 
00760                     if (ccolour == 8)
00761                     {
00762                         ccolour = GREY;
00763                     }    
00764                     else if (ccolour == 9)
00765                     {
00766                         ccolour = TRUE_BLACK;
00767                     }    
00768                     if (ccolour != GREY)
00769                         ccolour +=30;
00770 
00771                     if (cf & ATREVER)
00772                     {
00773 
00774                         bkcolour = ccolour;
00775                         ccolour = TRUE_BLACK;
00776                     }
00777                     else
00778                     {
00779                         bkcolour = TRUE_BLACK;
00780                     }
00781 
00782                     FlushBuffer(str, ccolour,bkcolour);
00783 
00784                  }
00785                  str[0] = '\0';
00786                  
00787             }
00788         }
00789     }
00790                      
00791                      
00792                      
00793                      
00794                  
00795                      
00796         
00797     
00798 }    

Here is the call graph for this function:

void check_url TERMBUF term  ) 
 

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

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

Referenced by interp_mouse().

02515 {
02516     return;
02517     char *buffer = str_dup(term->buffer);
02518     char *point = buffer;
02519     int i;
02520     char sp[] = " ";
02521     char *tok;
02522     
02523     for (i=1;*point;point++,i++)
02524     {
02525         if (i==pos.y)
02526         {
02527             break;
02528         }
02529         else
02530         {
02531             continue;
02532         }
02533     }
02534     
02535     for (;*point;point--,i--)
02536     {
02537         if (*point == ' ')
02538             break;            
02539         continue;
02540     }
02541     point = NULL;
02542     tok = strtok(&buffer[i], sp);
02543     
02544     if (tok == NULL)
02545         return;
02546     if (is_operator(&tok[strlen(tok)-1])) 
02547     {
02548         tok[strlen(tok)-1] = '\0';
02549     }    
02550     
02551         
02552     if (fnmatch("*http://*.*", tok, 0) == 0 || fnmatch("*https://*.*", tok, 0) == 0 ||
02553         fnmatch("*ftp://*.*", tok, 0) == 0 || fnmatch("*www.*", tok, 0) == 0)
02554     {
02555         do_url(tok);
02556         return;
02557     }
02558 }

Here is the call graph for this function:

void chop_line TERMBUF ter  ) 
 

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

References termbuffer::buffer, cols, termbuffer::has_blink, termbuffer::len, termbuffer::line, termbuffer::ln, malloc, new_line(), termbuffer::not_finished, termbuffer::processed, and TERMBUF.

Referenced by parse_ansi().

01078 {
01079 return;
01080     TERMBUF *t;
01081     int i = 0;
01082     int j = 0;
01083     
01084     
01085     if (ter->len > cols)
01086     {
01087         t = new_line(__LINE__, __FILE__); // I hate that.
01088         t->line = malloc((((ter->len - cols)+2) * sizeof(unsigned long )) * 2);
01089         t->has_blink = ter->has_blink;
01090         t->processed = ter->processed;
01091         t->not_finished = ter->not_finished;
01092 //        t->buffer = ter->buffer;
01093         t->buffer= NULL;
01094         t->ln = bufcount;
01095         t->len = ter->len - cols;
01096         i = (ter->len - cols);
01097 
01098         for (j=0;i <= ter->len;i++,j++)
01099         {
01100             if (i > ter->len)
01101                 break;
01102             t->line[j] = ter->line[i];
01103         }
01104         ter->line[cols] = 0;
01105         ter->len = cols;
01106         if (t->len > cols)
01107             chop_line(t);
01108 
01109     }
01110 //          update_term();
01111         
01112         
01113     
01114             
01115 }

Here is the call graph for this function:

void ClearTerminal void   ) 
 

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

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

02100 {
02101   return;
02102   int runner=0;
02103 
02104   char clr[700];
02105   hdc = tbuf->hdc;
02106   extern RECT mudrect;
02107   extern  HFONT hf;
02108   SelectObject(hdc, hf);
02109   SetBkColor(hdc,RGB(0,0,0)); 
02110   memset(clr, ' ', 700);
02111   for (runner=0;runner<=700;runner++)
02112   {
02113           ExtTextOut(hdc, 0,runner, ETO_CLIPPED, &mudrect, clr, 700, NULL);
02114           runner +=12;
02115           
02116   }
02117   tbuf->x_end = 0;
02118   tbuf->y_end =0;
02119 
02120   return;
02121   
02122 }

void do_nasty void   ) 
 

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

References FALSE, give_term_debug(), GiveError(), MudMain, nasty, precache_file(), read_string(), and realize_lines.

Referenced by WindowProcedure().

00964 {
00965     
00966          FILE *fp;     
00967          DWORD start,end;
00968          char buf[32000];
00969          //char buff[32000];
00970 
00971 
00972 
00973 
00974          char title[500];
00975          unsigned long int meh=0;
00976 
00977 
00978          int ret;
00979 
00980 
00981          unsigned char bleh[310002];
00982          unsigned long int precache=0,percent=0,pmin=0;
00983 
00984          int tt=0;
00985          
00986          precache = precache_file("code.txt"); //return number of lines for percentage.
00987 
00988          give_term_debug("%d:%d",precache, percent);
00989          
00990          
00991          if ((fp = fopen("code.txt", "r")) == NULL)
00992          {
00993              GiveError("Unable to open test file. Bailing.",FALSE);
00994              return;
00995          }
00996  
00997          start = GetTickCount();
00998          nasty = TRUE;
00999          while ((ret = read_string(buf, fp)) > -1)
01000          {
01001              buf[ret ] = '\0';
01002              buf[ret -1] = '\n';
01003              pmin++;
01004              percent = (pmin * 100) / precache;
01005              if (tt == percent)
01006              {
01007                  
01008                  sprintf(title, "Importing file, %d%s done. (line: %lu of %lu)", (int)percent > 100 ? 100 : (int)percent, "%", pmin, precache);
01009                  SendMessage(MudMain, WM_SETTEXT, /*strlen(buf)-2*/0,(LPARAM)(LPCSTR) title);
01010                  tt = percent + 20;
01011              }    
01012              
01013 
01014              realize_lines(buf); // pass it off to the line-adder-thingie.
01015              //do_peek();
01016 
01017              meh++;                                                                              
01018              bleh[0] = '\0';
01019              buf[0] = '\0';
01020 
01021           }
01022           
01023           nasty = FALSE;
01024           end = GetTickCount();
01025           give_term_debug("%d lines read and parsed in %d miliseconds.", meh, (int) end-start);
01026           fclose(fp);
01027           
01028               
01029                 
01030 }

Here is the call graph for this function:

void do_peek void   ) 
 

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

02598 {
02599     MSG msg;
02600     PeekMessage(&msg,NULL,0,0, PM_REMOVE);
02601     TranslateMessage(&msg);
02602     DispatchMessage(&msg);
02603 }

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

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

References BLUE, bufcount, cols, seltext::cstart, seltext::cstop, curdis, FALSE, fetch_line(), FlushBuffer(), free_context(), hdc, termbuffer::len, seltext::lstart, seltext::lstop, nasty, parse_ansi(), ret_string(), rows, seltext::selected, selection, tbuf, TERMBUF, TRUE, and TRUE_BLACK.

Referenced by WindowProcedure().

01193 {
01194     if (nasty == TRUE)
01195         return;
01196     int i,j,x,k=0;
01197     int viewing;
01198     top -=3;
01199     bottom +=3;
01200     if (top < 0)
01201         top = 0;
01202     if (bottom > rows)
01203         bottom = rows;
01204     if (right > cols)
01205         right = cols;
01206     if (left < 0)
01207         left = 0;
01208     unsigned long int start,stop,cstart,cstop;
01209     TERMBUF * tt;
01210     char t[100000];
01211     int ii,jj;
01212     start = selection->lstart;
01213     stop = selection->lstop;
01214     cstart = selection->cstart;
01215     cstop = selection->cstop;
01216 
01217     
01218     j = (bufcount <= rows) ? 1 : (bufcount - rows);
01219 
01220 
01221     
01222     if (curdis < 0) // Scrollback.
01223     {
01224         viewing = bufcount - -curdis;
01225        
01226         for (i = viewing - rows + top, k = 0, x=top;i <= viewing - rows + bottom;i++,k++,x++)
01227         {
01228            
01229             
01230 
01231             tbuf->y_end = x*13;
01232             tbuf->x_end = 0;
01233             if (i == bufcount)
01234                 return;
01235           
01236             t[0] = '\0';
01237             if (stop < start)
01238             {
01239                 
01240                 start = selection->lstop;
01241                 stop = selection->lstart;
01242 
01243                 cstart = selection->cstop;
01244                 cstop = selection->cstart;
01245                 
01246             }
01247             /* All the code in this if statement (and the nested if's, too) are
01248              * for the selection code. Again, as with a few other functions,
01249              * this should be thrown into it's own function to keep down on code.
01250              * So with that, I'll throw in a FIXME: so that i'll fix it eventually.*/
01251              
01252             if ((i >= start && i <= stop) && selection->selected) 
01253             {
01254                 
01255 
01256                 if (start == stop)
01257                 {
01258                     tt = fetch_line(i); 
01259                     if (tt == NULL) 
01260                         continue; 
01261                     parse_ansi(tt,0);
01262                     ret_string(tt,t);
01263                     tbuf->x_end = (cstart+1) * 8;
01264                     t[cstop+1] = '\0';
01265                     FlushBuffer(&t[cstart+1], TRUE_BLACK,BLUE);
01266                     ii = tt->len;
01267                     tbuf->x_end = ii * 8+13;                    
01268                 }
01269                 else if (i == start)
01270                 {
01271                     memset(t, '\0', 1000);
01272                     tt = fetch_line(i); 
01273                     if (tt == NULL) 
01274                         continue; 
01275 
01276                     parse_ansi(tt,0);
01277                     ret_string(tt, t);
01278                     tbuf->x_end = (cstart+1) * 8;
01279                     FlushBuffer(&t[cstart+1],  TRUE_BLACK,BLUE);
01280                     ii = tt->len;
01281                     tbuf->x_end = ii * 8+13;
01282                     
01283                 }
01284                 else if (i == stop)
01285                 {
01286                     
01287                     tt = fetch_line(i); 
01288                     if (tt == NULL) 
01289                         continue; 
01290 
01291                     parse_ansi(tt,0);
01292                     ret_string(tt, t);
01293                     tbuf->x_end = 0;
01294                     t[cstop+1] = '\0';
01295                     FlushBuffer(t,  TRUE_BLACK,BLUE);
01296                     ii = tt->len;
01297                     tbuf->x_end = ii * 8+13;
01298                     
01299                 }
01300                
01301                 else
01302                 {
01303                     tt = fetch_line(i); 
01304                     if (tt == NULL) 
01305                         continue; 
01306 
01307                     ret_string(tt, t);
01308                     tbuf->x_end = 0;
01309                     FlushBuffer(t,  TRUE_BLACK,BLUE);
01310                     ii = tt->len;
01311                     tbuf->x_end = ii * 8+13;
01312                 }
01313                 
01314                 if (ii < cols)
01315                  {
01316            
01317                      char pad[2000]="";
01318                      for (jj=0;jj< (cols - ii); jj++)
01319                          pad[jj] = '.';
01320                      pad[jj] = '\0';
01321                      FlushBuffer(pad, TRUE_BLACK, TRUE_BLACK);
01322                  }
01323                  else if (ii == 0)
01324                  {
01325                      char pad[cols];
01326                      for (jj=0;jj<cols;jj++)
01327                          pad[jj] = ' ';
01328                      pad[cols-1] = '\0';
01329                      FlushBuffer(pad,TRUE_BLACK, TRUE_BLACK);
01330                  }
01331                     
01332                     
01333 
01334             }
01335             else
01336                 parse_ansi(fetch_line(i),TRUE);
01337         
01338 
01339         }
01340         
01341     }
01342     else
01343     { 
01344         for (i = top+j,x=top;i <= (bufcount <= rows? bottom : bottom + j);i++,x++)
01345         {
01346             tbuf->y_end = x*13;
01347             tbuf->x_end = 0;
01348             if (i == bufcount)
01349                 return;
01350           
01351             t[0] = '\0';
01352             if (stop < start)
01353             {
01354                 
01355                 start = selection->lstop;
01356                 stop = selection->lstart;
01357 
01358                 cstart = selection->cstop;
01359                 cstop = selection->cstart;
01360                 
01361             }
01362             /* All the code in this if statement (and the nested if's, too) are
01363              * for the selection code. Again, as with a few other functions,
01364              * this should be thrown into it's own function to keep down on code.
01365              * So with that, I'll throw in a FIXME: so that i'll fix it eventually.*/
01366                 
01367             if ((i >= start && i <= stop) && selection->selected)
01368             {
01369                 
01370 
01371                 if (start == stop)
01372                 {
01373                     tt = fetch_line(i); 
01374                     if (tt == NULL) 
01375                         continue; 
01376 
01377                     parse_ansi(tt,0);
01378                     ret_string(tt,t);
01379                     tbuf->x_end = (cstart+1) * 8;
01380                     t[cstop+1] = '\0';
01381                     FlushBuffer(&t[cstart+1], TRUE_BLACK,BLUE);
01382                     ii = tt->len;
01383                     tbuf->x_end = ii * 8+13;                    
01384                 }
01385                 else if (i == start)
01386                 {
01387                     memset(t, '\0', 1000);
01388                     tt = fetch_line(i); 
01389                     if (tt == NULL) 
01390                         continue; 
01391 
01392                     parse_ansi(tt,0);
01393                     ret_string(tt, t);
01394                     tbuf->x_end = (cstart+1) * 8;
01395                     FlushBuffer(&t[cstart+1],  TRUE_BLACK,BLUE);
01396                     ii = tt->len;
01397                     tbuf->x_end = ii * 8+13;
01398                     
01399                 }
01400                 else if (i == stop)
01401                 {
01402                     
01403                     tt = fetch_line(i); 
01404                     if (tt == NULL) 
01405                         continue; 
01406 
01407                     parse_ansi(tt,0);
01408                     ret_string(tt, t);
01409                     tbuf->x_end = 0;
01410                     t[cstop+1] = '\0';
01411                     FlushBuffer(t,  TRUE_BLACK,BLUE);
01412                     ii = tt->len;
01413                     tbuf->x_end = ii * 8+13;
01414                     
01415                 }
01416                
01417                 else
01418                 {
01419                     tt = fetch_line(i); 
01420                     if (tt == NULL) 
01421                         continue; 
01422 
01423                     ret_string(tt, t);
01424                     tbuf->x_end = 0;
01425                     FlushBuffer(t,  TRUE_BLACK,BLUE);
01426                     ii = tt->len;
01427                     tbuf->x_end = ii * 8+13;
01428                 }
01429                 
01430                 if (ii < cols)
01431                  {
01432            
01433                      char pad[2000]="";
01434                      for (jj=0;jj< (cols - ii); jj++)
01435                          pad[jj] = '.';
01436                      pad[jj] = '\0';
01437                      FlushBuffer(pad, TRUE_BLACK, TRUE_BLACK);
01438                  }
01439                  else if (ii == 0)
01440                  {
01441                      char pad[cols];
01442                      for (jj=0;jj<cols;jj++)
01443                          pad[jj] = ' ';
01444                      pad[cols-1] = '\0';
01445                      FlushBuffer(pad,TRUE_BLACK, TRUE_BLACK);
01446                  }
01447                     
01448                     
01449 
01450             }
01451             else
01452                 parse_ansi(fetch_line(i), FALSE);
01453         }
01454     }
01455     free_context(hdc);
01456 
01457     return;
01458 }

Here is the call graph for this function:

void do_url const char *  url  ) 
 

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

Referenced by check_url().

02563 {
02564     ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
02565     return;
02566 }

void export_to_html void   ) 
 

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

References fetch_line(), GREEN, log_html(), MudMain, and TERMBUF.

Referenced by WindowProcedure().

01842 {
01843      int i,j,k=0;
01844     TERMBUF *temp;
01845     char *point;
01846     char buf[100000]="";
01847     char buf2[10000]="";
01848     char *buffer;
01849     char pbuf[5000];
01850     buffer = buf2;
01851     int color;
01852 
01853     unsigned long int percent=0;
01854     unsigned long int pmin;
01855     unsigned long attr_f;
01856     
01857     //percent = bufcount / 100;
01858     
01859     
01860     log_html("<title>Nanomud exported log</title>\n<body bgcolor=\"black\"><font face=\"Courier New\"><pre>\n\n",-1);
01861     for (k=1;k<=bufcount;k++)
01862     {
01863         percent = (100 * k) / bufcount;
01864         temp = fetch_line(k);
01865 //        point = temp->buf;
01866         if (k % 500 == 0)
01867         {        
01868             sprintf(pbuf,"Exporting buffer to html, %d%s done. LINE: %d", (int)percent,"%", k);
01869             SendMessage(MudMain, WM_SETTEXT, /*strlen(buf)-2*/0,(LPARAM)(LPCSTR) pbuf);
01870             pmin = percent + 1;
01871             pbuf[0] = '\0';
01872         }    
01873         
01874 //        if (temp->buf == NULL)
01875             continue;
01876         strcat(buf, "\n");
01877         log_html("", -1);
01878 
01879                 
01880 //        j = strlen(temp->buf);
01881 
01882         for (i = 0; i<=j;i++,point++)
01883         {
01884             
01885             *buffer = *point;
01886             buffer[1] = '\0';
01887             
01888             switch(*point)
01889             {
01890                 case '<':
01891                     strcat(buf, "&#60;");
01892                     break;
01893                 case '>':
01894                     strcat(buf, "&#62;");                    
01895                     break;
01896                 default:
01897                     strcat(buf,buffer);
01898                     break;
01899             }    
01900 
01901 //            attr_f = temp->attrib[i];
01902 
01903             if (attr_f == def_attr)
01904             {
01905                 color = GREY;
01906             }
01907             else
01908             {
01909                 color = ((attr_f & FG_MASK) >> FG_SHIFT);
01910             }    
01911             if (color == 0)
01912                 color = GREY;
01913 
01914 
01915             if ((attr_f & ATBOLD))
01916             {
01917                 color +=10;
01918             }    
01919   
01920             if (color == 8)
01921             {
01922                 color = GREY;
01923             }    
01924             else if (color == 9)
01925             {
01926                 color = TRUE_BLACK;
01927             }    
01928             if (color != GREY)
01929                 color +=30;
01930 
01931 //            if (temp->attrib[i+1] == attr_f && strlen(buf) < 2000)
01932   //              continue;
01933             {
01934                 log_html(buf, color);
01935                 buf[0] = '\0';
01936                 buf2[0] = '\0';
01937             }
01938                 
01939           
01940         }
01941         
01942     }
01943     log_html("\n</pre>\n\n<b>Exported with Nanomud! <a href=\"http://www.nanobit.net\">www.nanobit.net</a></b></font></font></body>", GREEN);
01944 }        

Here is the call graph for this function:

TERMBUF* fetch_line unsigned long int  idx  ) 
 

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

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

Referenced by blink_term(), do_update_paint(), export_to_html(), get_line(), handle_selection(), interp_mouse(), ParseLines(), replace_line(), update_term(), and WindowProcedure().

01057 {
01058     if (idx > bufcount)
01059         return NULL;
01060     else
01061     {
01062         if (this_session->termlist[idx] == NULL)
01063         {
01064             LOG("Error! Fetchline tried to grab an invalid line of %d with a max count of %d", idx, bufcount);
01065             return NULL;  
01066         }    
01067         else
01068             return this_session->termlist[idx];
01069     }
01070 }

Here is the call graph for this function:

void fix_line TERMBUF line1,
TERMBUF line2
 

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

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

02336 {
02337 return;    
02338     int i;
02339     char buf[5000]="";
02340     char buf2[5000]="";
02341     char *buffer;
02342     char *point;
02343     buffer = buf2;
02344     
02345     
02346     
02347     if (line1 == NULL || line2 == NULL)
02348     {
02349         LOG("%s, %d, Line1/2 NULL", __FILE__, __LINE__);
02350         return;
02351     }
02352     
02353     /* Line1 should be the first line that we want to append TO.
02354      * Line2 is the line we should want to grab FROM to append with.
02355      * simple enough?
02356      */
02357     
02358     if (line1->len >= 2480)
02359     {
02360         GiveError("In fix_line, Terminal.c, Line1 is too large to edit. You should NOT see this error.", TRUE);
02361         return;
02362     }
02363     
02364 //    point = line2->buf;
02365     for (i=0;;point++,i++)
02366     {
02367 
02368         if (*point == '\0')
02369             break;
02370         if (*point == 'm')
02371         {
02372             *buffer = *point;
02373             strcat(buf, buffer);
02374             buffer[0] = '\0';
02375             break;
02376         }
02377         *buffer = *point;
02378         strcat(buf, buffer);
02379         buffer[0] = '\0';
02380     }
02381 
02382 //    strcat(line1->buf, buf);
02383     i++;
02384 
02385 //    memcpy(temp, &line2->buf[i], strlen(&line2->buf[i]));
02386 //    memcpy(line2->buf, temp, strlen(temp));
02387     hold_buf = NULL;
02388     update_term();
02389 
02390 }

Here is the call graph for this function:

void FlushBuffer char *  buffer,
int  colour2,
int  bKcolour2
 

Definition at line 1993 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, RED, tbuf, TRUE_BLACK, WHITE, and YELLOW.

Referenced by blink_term(), do_update_paint(), parse_ansi(), set_mouse_pos(), term_test_2(), update_term(), and WindowProcedure().

01994 {
01995 
01996   if (buffer[0] == '\0')
01997       return;  
01998   if (nasty == TRUE)
01999       return;
02000 
02001   RECT mudrect;
02002   GetClientRect(MudMain, &mudrect);
02003 
02004   extern  HFONT hf;
02005   HDC hdc = tbuf->hdc;
02006   
02007   SelectObject(hdc, hf);
02008  
02009  switch(bKcolour2)
02010  {
02011     case RED:        SetBkColor(hdc, RGB(255,0  ,0  )); break;
02012     case BLUE:       SetBkColor(hdc, RGB(0  ,0  ,255)); break;
02013     case GREEN:      SetBkColor(hdc, RGB(0  ,255,0  )); break;
02014     case BLACK:      SetBkColor(hdc, RGB(75 ,75 ,75 )); break;
02015     case YELLOW:     SetBkColor(hdc, RGB(255,255,0  )); break;
02016     case MAGENTA:    SetBkColor(hdc, RGB(255,0  ,255)); break;
02017     case CYAN:       SetBkColor(hdc, RGB(0  ,255,255)); break;
02018     case WHITE:      SetBkColor(hdc, RGB(255,255,255)); break;
02019     case C_RED:      SetBkColor(hdc, RGB(128,0  ,0  )); break;
02020     case C_BLUE:     SetBkColor(hdc, RGB(0  ,0  ,128)); break;
02021     case C_GREEN:    SetBkColor(hdc, RGB(0  ,192,0  )); break;
02022     case C_BLACK:    SetBkColor(hdc, RGB(128,128,128)); break;
02023     case C_YELLOW:   SetBkColor(hdc, RGB(128,128,0  )); break;
02024     case C_MAGENTA:  SetBkColor(hdc, RGB(128,0  ,128)); break;
02025     case C_CYAN:     SetBkColor(hdc, RGB(0  ,127,128)); break;
02026     case C_WHITE:    SetBkColor(hdc, RGB(128,128,128)); break;
02027     case GREY:       SetBkColor(hdc, RGB(192,192,192)); break;
02028     case TRUE_BLACK: SetBkColor(hdc, RGB(0  ,0  ,0  )); break;
02029     default:         SetBkColor(hdc, RGB(0  ,0  ,0  )); break;
02030 
02031   }
02032 
02033  switch(colour2)
02034  {
02035     case RED:        SetTextColor(hdc, RGB(255,0  ,0  )); break;
02036     case BLUE:       SetTextColor(hdc, RGB(0  ,0  ,255)); break;
02037     case GREEN:      SetTextColor(hdc, RGB(0  ,255,0  )); break;
02038     case BLACK:      SetTextColor(hdc, RGB(75 ,75 ,75 )); break;
02039     case YELLOW:     SetTextColor(hdc, RGB(255,255,0  )); break;
02040     case MAGENTA:    SetTextColor(hdc, RGB(255,0  ,255)); break;
02041     case CYAN:       SetTextColor(hdc, RGB(0  ,255,255)); break;
02042     case WHITE:      SetTextColor(hdc, RGB(255,255,255)); break;
02043     case C_RED:      SetTextColor(hdc, RGB(128,0  ,0  )); break;
02044     case C_BLUE:     SetTextColor(hdc, RGB(0  ,0  ,128)); break;
02045     case C_GREEN:    SetTextColor(hdc, RGB(0  ,192,0  )); break;
02046     case C_BLACK:    SetTextColor(hdc, RGB(128,128,128)); break;
02047     case C_YELLOW:   SetTextColor(hdc, RGB(128,128,0  )); break;
02048     case C_MAGENTA:  SetTextColor(hdc, RGB(128,0  ,128)); break;
02049     case C_CYAN:     SetTextColor(hdc, RGB(0  ,127,128)); break;
02050     case C_WHITE:    SetTextColor(hdc, RGB(128,128,128)); break;
02051     case GREY:       SetTextColor(hdc, RGB(192,192,192)); break;
02052     case TRUE_BLACK: SetTextColor(hdc, RGB(0  ,0  ,0  )); break;
02053     default:         SetTextColor(hdc, RGB(192,192,192)); break;
02054 
02055   }
02056 
02057 
02058 
02059        ExtTextOut(hdc, tbuf->x_end,tbuf->y_end,ETO_CLIPPED,0, buffer, strlen(buffer),NULL);
02060 
02061 
02062        tbuf->x_end += (strlen(buffer) > 1 ? strlen(buffer) * 8 : 8);
02063        buffer[0] = '\0';
02064    
02065    return;
02066    
02067 
02068 
02069 }

void free_line TERMBUF rem  ) 
 

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

References termbuffer::buffer, free, termbuffer::line, and TERMBUF.

Referenced by FreeTerm(), and replace_line().

01949 {
01950 
01951     if (rem)
01952     {
01953         free(rem->buffer);
01954         free(rem->line);
01955         free(rem);
01956 
01957     }
01958 }

void FreeTerm void   ) 
 

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

References bufcount, free, free_line(), malloc, session_data::max_buffer, MudMain, TERMBUF, session_data::termlist, this_session, and TRUE.

Referenced by WindowProcedure().

01964 {
01965  
01966     int i;
01967     TERMBUF *rem;
01968 
01969     for (i=0;i<= bufcount;i++)
01970     {
01971         rem = this_session->termlist[i];
01972         free_line(rem);
01973        
01974     }
01975     for (i=0;i<=bufcount;i++)
01976     {
01977         this_session->termlist[i] = NULL;
01978     }    
01979     bufcount =0;
01980     free (this_session->termlist);
01981     this_session->termlist = (TERMBUF **)malloc(this_session->max_buffer * sizeof(*this_session->termlist));
01982     RECT r;
01983     GetClientRect (MudMain, &r);
01984     InvalidateRect(MudMain,&r, TRUE);
01985 }       

Here is the call graph for this function:

char* get_line int  num  ) 
 

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

References bufcount, curdis, fetch_line(), LOG(), rows, and TERMBUF.

01801 {
01802     return 0;
01803     int view;
01804     if (bufcount == 1 && num > 1)
01805         return NULL;
01806 
01807     if (num == 0)
01808         return NULL;
01809     int nt;
01810     nt = (num == 0 ? 1 : num);
01811     num = nt;
01812     TERMBUF *temp;
01813     temp = 0;
01814     view = bufcount - -curdis;
01815     
01816     view -= rows;
01817     view += num;
01818     view -= 1;
01819     
01820     if (view == 0)
01821         view = 1;
01822     if (view > bufcount)
01823         view = bufcount;
01824     
01825     
01826     LOG("View: %d, rows: %d, bufcount: %d, num: %d, curdis: %d", view, rows, bufcount, num,curdis);
01827     if (num > bufcount || view > bufcount)
01828         return NULL;
01829     if (curdis < 0)
01830         temp = fetch_line(view);
01831     else if (num <= bufcount)
01832         temp = fetch_line(num);
01833     
01834     //return str_dup(temp->buf);
01835 }    

Here is the call graph for this function:

char* get_time void   ) 
 

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

Referenced by add_term(), check_ping(), and WinMain().

02608 {
02609     
02610     static char stamp[25];
02611     time_t tv;
02612     struct tm * ttv;
02613     tv = time (0);
02614     ttv = localtime(&tv);
02615     
02616     sprintf(stamp, "%02d:%02d:%02d", ttv->tm_hour,ttv->tm_min,ttv->tm_sec);
02617     return stamp;
02618     
02619 }

unsigned long int get_x int  x  ) 
 

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

References bufcount, curdis, curpos, and rows.

Referenced by WindowProcedure().

01164 {
01165     int curpos;
01166     int viewing;
01167 
01168         
01169     if (curdis < 0)  // Viewing scroll back
01170     {
01171 
01172         curpos = curdis;
01173         viewing = bufcount - -curdis;
01174         return (viewing - rows) + x;
01175 
01176     }
01177     else // Not scrollback.
01178     {
01179         curpos =  curdis;
01180         return ((bufcount <= rows ? 1 : (bufcount - rows)) + x);
01181     }
01182 
01183 
01184     
01185 }

int GetWindowWrap HWND  hwnd  ) 
 

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

References srect.

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

02251 {
02252     int screen_width;
02253     RECT srect;
02254     int remainder;
02255     int font_width = 8;
02256     GetClientRect(hwnd, &srect);
02257     screen_width =