Ejemplo n.º 1
0
static void tri_test(void)
{
  mesh* m;
  point pts[3];
  ment v[3];
  ment e;
  unsigned i;
  double A;
  double l[3];
  double s;
  m = mesh_new();
  pts[0] = point_new(-1,0,0);
  pts[1] = point_new( 1,0,0);
  pts[2] = point_new( 0,my_sqrt(3),0);
  for (i = 0; i < 3; ++i)
    v[i] = ment_new(m, VERTEX, 0);
  for (i = 0; i < 3; ++i)
    mesh_set_point(m, v[i], pts[i]);
  e = ment_new(m, TRIANGLE, v);
  A = triangle_area(ment_triangle(m, e));
  debug("area: %e\n", A);
  s = 0;
  for (i = 0; i < 3; ++i) {
    mesh_down(m, e, EDGE, i, v);
    l[i] = line_len(verts_line(m, v));
    debug("length: %e\n", l[i]);
    s += l[i] * l[i];
  }
  s /= 3;
  debug("condition bound: %e\n", A / s);
  debug("quality: %e\n", ment_quality(m, e));
  mesh_free(m);
}
Ejemplo n.º 2
0
static void put_newline(proc_entry *t){
    unsigned int l;
    put("\n",1);
    l = line_len(t);
    if (line.len < l) die_print(); /* XXX */
    line.len = l;
    if (buffer_put(buffer_1small, line.s, line.len) == -1) die_print();
    return;
}
Ejemplo n.º 3
0
gboolean line_add_arg(struct irc_line *l, const char *arg)
{
	if (line_len(l) + strlen(arg) + 1 > IRC_MAXLINELEN)
		return FALSE;

	/* Check to see if this argument fits on the current line */
	l->args[l->argc] = g_strdup(arg);

	if (l->args[l->argc] == NULL)
		return FALSE;

	l->args = g_realloc(l->args, (((++l->argc)+2) * sizeof(char *)));

	if (l->args == NULL)
		return FALSE;

	l->args[l->argc] = NULL;

	return TRUE;
}
Ejemplo n.º 4
0
static bool pass1( FILE *fin, char **helpstr )
{
    char            buffer[ BUFFER_SIZE ];
    int             buflen;
    long            fpos;
    a_helpnode      *h;
    a_helpnode      **hn;
    char            *ptr;
    int             cmp;
    char            *namebuff;
    unsigned        namebuff_len;
    int             count;
    int             len;
    unsigned        topic_len;
    unsigned        desc_len;

    namebuff = NULL;
    namebuff_len = 0;
    topic_len = strlen( DEFTOPIC );
    desc_len = strlen( DESCRIPTION );

    printf( "Pass One:\n" );
    fpos = 0;
    while( !feof( fin ) ) {
        fpos = ftell( fin );
        fgetstring( buffer, BUFFER_SIZE, fin );
        if( memcmp( buffer, DEFTOPIC, topic_len ) == 0 ) {
            if( helpstr[0] != NULL ) {
                PrintError( "more than one DEFTOPIC found\n" );
            } else {
                if( !GenStrings || !GenIndex ) {
                    PrintError( "DEFTOPIC string ignored with this format.\n" );
                }
                if( GenStrings ) {
                    ptr = find_str( &buffer[topic_len] );
                    helpstr[0] = HelpMemAlloc( strlen( ptr ) + 1 );
                    strcpy( helpstr[0], ptr);
                }
            }
        } else if( memcmp( buffer, DESCRIPTION, desc_len ) == 0 ) {
            if( helpstr[1] != NULL ) {
                PrintError( "more than one DESCRIPTION found\n" );
            } else {
                if( !GenStrings || !GenIndex ) {
                    PrintError( "DESCRIPTION string ignored with this format.\n" );
                }
                if( GenStrings ) {
                    ptr = find_str( &buffer[desc_len] );
                    helpstr[1] = HelpMemAlloc( strlen( ptr ) + 1 );
                    strcpy( helpstr[1], ptr );
                }
            }
        } else if( memcmp( buffer, "::::", 4 ) == 0 )
            break;
    }
    while( !feof( fin ) ) {
        h = (a_helpnode *)HelpMemAlloc( sizeof( a_helpnode ) );
        h->fpos = fpos;
        buflen = strlen( buffer );
        if( buffer[ buflen-1 ] == '\n' ) {
            buffer[ buflen-1 ] = '\0';
        }
        h->maxrow = 0;
        h->maxcol = 0;
        h->row = -1;
        h->col = -1;
        h->lines = -1;
        ptr = &buffer[4];
        if( *ptr == '"' ) {
            ptr ++;
            while( *ptr != '\0' && *ptr != '"' ) {
                if( *ptr == HELP_ESCAPE )
                    ptr++;
                ptr++;
            }
            len = ptr - &buffer[5];
            if( namebuff_len <= len ) {
                HelpMemFree( namebuff );
                namebuff = HelpMemAlloc( len + 1 );
                namebuff_len = len + 1;
            }
            memcpy( namebuff, &buffer[5], len );
            namebuff[len] = '\0';
            if( *ptr == '"' )
                ++ptr;
        } else {
            for( ; *ptr != '\0'  &&  !isspace(*ptr); ++ptr )
                ;
            while( *ptr != '\0'  &&  !isspace(*ptr) ) {
                if( *ptr == HELP_ESCAPE )
                    ptr++;
                ptr++;
            }
            len = ptr - &buffer[4];
            if( namebuff_len <= len ) {
                HelpMemFree( namebuff );
                namebuff = HelpMemAlloc( len + 1 );
                namebuff_len = len + 1;
            }
            memcpy( namebuff, &buffer[4], len );
            namebuff[len] = '\0';
        }
        while( isspace( *ptr ) )
            ++ptr;
        if( *ptr != '\0' ) {
            count = sscanf( ptr, "%d %d %d %d %d",
                    &h->maxrow, &h->maxcol, &h->row, &h->col,
                    &h->lines );
            if( count != 2  && count != 4  &&  count != 5 ) {
                PrintError( "invalid help topic line '%s'\n", buffer );
            }
        }
        h->name = strdup( namebuff );
        if( Verbose ) {
            printf( "   %s\n", h->name );
        }
        for( hn=&HelpNodes; *hn != NULL; hn=&(*hn)->next ) {
            cmp = stricmp( h->name, (*hn)->name );
            if( cmp == 0 ) {
                PrintError( "Duplicate Help Topic '%s'\n", h->name );
            }
            if( cmp <= 0 ) {
                h->next = *hn;
                *hn = h;
                break;
            }
        }
        if( *hn == NULL ) {
            h->next = NULL;
            *hn = h;
        }
        if( h->row == -1 ) {
            h->row = 0;
            h->col = 0;
        }
        h->maxcol = 0;
        h->maxrow = 0;
        h->lines = 0;
        while( !feof( fin ) ) {
            fpos = ftell( fin );
            fgetstring( buffer, BUFFER_SIZE, fin );
            if( memcmp( buffer, "::::", 4 ) == 0 )
                break;
            if( strnicmp( buffer, ":eh", 3 ) == 0
                || strnicmp( buffer, ":et", 3 ) == 0 ) {
                h->lines = 0;
            } else if( strnicmp( buffer, ":h", 2 ) == 0
                    || strnicmp( buffer, ":t", 2 ) == 0  ) {
            } else {
                buflen = line_len( buffer );
                if( buflen - 1 > h->maxcol ){
                    h->maxcol = buflen - 1;
                }
                h->lines += 1;
                h->maxrow += 1;
            }
        }
    }
    HelpMemFree( namebuff );
    return( TRUE );
}