Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

My browser

Name: Anonymous 2010-02-20 14:04


/*        Interface to hypertext object        HText.c
**        =============================
*/

#include <ctype.h>
#include "HTUtils.h"
#include "HTString.h"
#include "HText.h"
#include "HyperText.h"

/*    Exports
*/
PUBLIC HText * HTMainText = 0;        /* Equivalent of main window */
PUBLIC HTParentAnchor * HTMainAnchor = 0;    /* Anchor for HTMainText */


/*            Creation Method
**            ---------------
*/
PUBLIC HText *    HText_new ARGS1(HTParentAnchor *,anchor)
{
    HTLine * line;
    HText * self = (HText *) malloc(sizeof(*self));
    if (!self) return self;
   
    if (!loaded_texts) loaded_texts = HTList_new();
    HTList_addObject(loaded_texts, self);
    if (HTList_count(loaded_texts) >= LOADED_LIMIT) {
        if (TRACE) fprintf(stderr, "GridText: Freeing off cached doc.\n");
        HText_free((HText *)HTList_removeFirstObject(loaded_texts));
    }
   
    line = self->last_line = (HTLine *)malloc(LINE_SIZE(MAX_LINE));
    line->next = line->prev = line;
    line->offset = line->size = 0;
    self->lines = self->chars = 0;
    self->title = 0;
    self->first_anchor = self->last_anchor = 0;
    self->style = &default_style;
    self->top_of_screen = 0;
    self->node_anchor = anchor;
    self->last_anchor_number = 0;    /* Numbering of them for references */
    self->stale = YES;
   
    HTAnchor_setDocument(anchor, (HyperDoc *)self);

    clear_screen();
    HTMainText = self;
    HTMainAnchor = anchor;
    self->display_on_the_fly = DISPLAY_LINES;
   
    if (!space_string) {    /* Make a blank line */
        char *p;
    space_string = (char *)malloc(HTScreenWidth+1);
        for (p=space_string; p<space_string+HTScreenWidth; p++)
            *p = ' ';         /* Used for printfs later */
        space_string[HTScreenWidth] = '\0';
    }
   
    return self;
}


/*    Free Entire Text
**    ----------------
*/
PUBLIC void     HText_free ARGS1(HText *,self)
{
    HTAnchor_setDocument(self->node_anchor, (HyperDoc *)0);
   
    while(YES) {        /* Free off line array */
        HTLine * l = self->last_line;
    l->next->prev = l->prev;
    l->prev->next = l->next;    /* Unlink l */
    self->last_line = l->prev;
    free(l);
    if (l == self->last_line) break;    /* empty */
    };
   
    while(self->first_anchor) {        /* Free off anchor array */
        TextAnchor * l = self->first_anchor;
    self->first_anchor = l->next;
    free(l);
    }
    free(self);
}

/*        Display Methods
**        ---------------
*/
/*    Clear the screen (on screen-mode systems)
**    ----------------
*/
PUBLIC void clear_screen NOARGS
{
#ifdef VM
#ifdef NEWLIB
    int newlib_ncmd = 2;
    char newlib_cmd[2][80];

    memset(newlib_cmd, ' ', sizeof(newlib_cmd));
    strncpy(newlib_cmd[0], "clear", 5);        /* Clear screen */
    strncpy(newlib_cmd[1], "quit", 4);        /* Leave newlib */
    newlib(newlib_cmd, &newlib_ncmd);        /* Execute command */
   
#else        /* not NEWLIB - real VM */
    system("CLRSCRN");                /* Clear screen */
#endif        /* not NEWLIB */
#else        /* Not VM */
    /* Do nothing */
#endif        /* Not VM */
    if (HTMainText) HTMainText->stale = YES;
}


/*    Output a line
**    -------------
*/
PRIVATE void display_line ARGS1(HTLine *,line)
{
   printf("%s%s\n", SPACES(line->offset), line->data);
  
}

/*    Output the title line
**    ---------------------
*/
PRIVATE void display_title ARGS1(HText *,text)
{
    CONST char * title = HTAnchor_title(text->node_anchor);
    char percent[20], format[20];
    if (text->lines > (DISPLAY_LINES-1)) {
#ifdef NOPE
    sprintf(percent, " (p%d of %d)",
        (text->top_of_screen/(DISPLAY_LINES-1)) + 1,
        (text->lines-1)/(DISPLAY_LINES-1) + 1);
    sprintf(percent, " (%d%%)",
        100*(text->top_of_screen+DISPLAY_LINES-1)/    /* Seen */
            (text->lines));                /* Total */
#else
    sprintf(percent, " (%d/%d)",
        text->top_of_screen+DISPLAY_LINES-1,    /* Seen */
        text->lines);                /* Total */
#endif
    } else {
    percent[0] = 0;    /* Null string */
    }

    sprintf(format, "%%%d.%ds%%s\n",    /* Generate format string */
            HTScreenWidth-strlen(percent),
            HTScreenWidth-strlen(percent));
    if (TRACE) fprintf(stderr, "FORMAT IS `%s'\n", format);
    printf(format, title, percent);
}


/*    Fill the screen with blank after the file
**    --------------------------
*/
PRIVATE void fill_screen ARGS1(int,n)
{
    if (n<=0) return;
    if (!interactive) return;
#ifndef VIOLA   
    printf("%s\n", end_mark);
    n--;
   
    for (; n; n--) {
        printf("\n");
    }
#endif
}


/*    Output a page
**    -------------
*/
PRIVATE void display_page ARGS2(HText *,text, int,line_number)
{
    HTLine * line = text->last_line->prev;
    int i;
    CONST char * title = HTAnchor_title(text->node_anchor);
    int lines_of_text = title ? DISPLAY_LINES-1 : DISPLAY_LINES;
    int last_screen = text->lines - lines_of_text;

/*    Constrain the line number to be within the document
*/
    if (text->lines <= lines_of_text) line_number = 0;
    else if (line_number>last_screen) line_number = last_screen;
    else if (line_number < 0) line_number = 0;
   
    for(i=0,  line = text->last_line->next;        /* Find line */
        i<line_number && (line!=text->last_line);
    i++, line=line->next) /* Loop */;

    while((line!=text->last_line) && (line->size==0)) {    /* Skip blank lines */
        line = line->next;
        line_number ++;
    }

/*    Can we just scroll to it?
*/
    if (!text->stale && (line_number>=text->top_of_screen) &&
        (line_number < text->top_of_screen + DISPLAY_LINES)) {    /* Yes */
    lines_of_text = line_number - text->top_of_screen;
    line = text->next_line;
        text->top_of_screen = line_number;
    } else {
    clear_screen();                        /* No */
        text->top_of_screen = line_number;
    if (title) display_title(text);
    }
   
   
 /*    print it
 */
    if (line) {
      for(i=0;
      i< lines_of_text && (line != text->last_line); i++)  {
        display_line(line);
    line = line->next;
      }
      fill_screen(lines_of_text - i);
    }

    text->next_line = line;    /* Line after screen */
    text->stale = NO;        /* Display is up-to-date */
}


/*            Object Building methods
**            -----------------------
**
**    These are used by a parser to build the text in an object
*/
PUBLIC void HText_beginAppend ARGS1(HText *,text)
{
    text->permissible_split = 0;
    text->in_line_1 = YES;
}


/*    Add a new line of text
**    ----------------------
**
** On entry,
**
**    split    is zero for newline function, else number of characters
**        before split.
**    text->display_on_the_fly
**        may be set to indicate direct output of the finished line.
** On exit,
**        A new line has been made, justified according to the
**        current style. Text after the split (if split nonzero)
**        is taken over onto the next line.
**
**        If display_on_the_fly is set, then it is decremented and
**        the finished line is displayed.
*/
#define new_line(text) split_line(text, 0)

PRIVATE void split_line ARGS2(HText *,text, int,split)
{
    HTStyle * style = text->style;
    int spare;
    int indent = text->in_line_1 ? text->style->indent1st
                     : text->style->leftIndent;
   
/*    Make new line
*/
    HTLine * line = (HTLine *) malloc(LINE_SIZE(MAX_LINE));
    HTLine * previous = text->last_line;
   
    text->lines++;
   
    previous->next->prev = line;
    line->prev = previous;
    line->next = previous->next;
    previous->next = line;
    text->last_line = line;
    line->size = 0;
    line->offset = 0;

/*    Split at required point
*/

Name: Anonymous 2010-02-20 14:59

>>2
lol i'd like to see you do better cum breath, oh wait thats right you cant code shit apart from fibs and factorials, back to /pr/ dipshit

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List