Ejemplo n.º 1
0
static void print_data(
    Mif_Boolean_t dcop,          /* Is this the operating point data */
    double        step,          /* The analysis step if dcop */
    char          **node_value,  /* The array of values to be printed */
    int           nargs)         /* The size of the value array */
{

    int  i, preci;
    char step_str[100];

    /* If option numdgt is set, use it for printout precision. */
    if (cp_numdgt > 0)
        preci = cp_numdgt;
    else
        preci = 9;

    if(dcop)
        strcpy(step_str, "DCOP            ");
    else
        sprintf(step_str, "%.*e", preci, step);

    out_printf("%s", step_str);
    for(i = 0; i < nargs; i++)
        out_printf("    %s", node_value[i]);
    out_printf("\n");
}
Ejemplo n.º 2
0
void file_build1( PATHNAME * const f, string * file )
{
    if ( DEBUG_SEARCH )
    {
        out_printf( "build file: " );
        if ( f->f_root.len )
            out_printf( "root = '%.*s' ", f->f_root.len, f->f_root.ptr );
        if ( f->f_dir.len )
            out_printf( "dir = '%.*s' ", f->f_dir.len, f->f_dir.ptr );
        if ( f->f_base.len )
            out_printf( "base = '%.*s' ", f->f_base.len, f->f_base.ptr );
        out_printf( "\n" );
    }

    /* Start with the grist. If the current grist is not surrounded by <>'s, add
     * them.
     */
    if ( f->f_grist.len )
    {
        if ( f->f_grist.ptr[ 0 ] != '<' )
            string_push_back( file, '<' );
        string_append_range(
            file, f->f_grist.ptr, f->f_grist.ptr + f->f_grist.len );
        if ( file->value[ file->size - 1 ] != '>' )
            string_push_back( file, '>' );
    }
}
Ejemplo n.º 3
0
void object_done()
{
#ifdef BJAM_NEWSTR_NO_ALLOCATE
    unsigned i;
    for ( i = 0; i < strhash.num; ++i )
    {
        while ( strhash.data[ i ] )
        {
            struct hash_item * item = strhash.data[ i ];
            strhash.data[ i ] = item->header.next;
            BJAM_FREE( item );
        }
    }
#else
    /* Reclaim string blocks. */
    while ( strblock_chain )
    {
        strblock * const n = strblock_chain->next;
        BJAM_FREE( strblock_chain );
        strblock_chain = n;
    }
#endif

    string_set_done( &strhash );

    if ( DEBUG_MEM )
    {
        out_printf( "%dK in strings\n", strtotal / 1024 );
        if ( strcount_in != strcount_out )
            out_printf( "--- %d strings of %d dangling\n", strcount_in -
                strcount_out, strcount_in );
    }
}
Ejemplo n.º 4
0
void send_recv(int i, int sockfd)
{
  char msg_buf[MSG_SIZE];
  char send_buf[BUFSIZE];
  char recv_buf[BUFSIZE];
  int nbyte_recvd, code;
  
  if (i == 0){
    in_scan(msg_buf);
    code = parseString(msg_buf, send_buf);

    if (code == PARSE_QUIT) {
      exit(0);
    }
    else if(code == PARSE_OK){
      send(sockfd, send_buf, strlen(send_buf), 0);
    }
    else{
      out_printf("%s\n", "Parse error");
    }
  }
  else {
    nbyte_recvd = recv(sockfd, recv_buf, BUFSIZE, 0);
    recv_buf[nbyte_recvd] = '\0';
    
    out_printf("%s\n" , recv_buf);
    fflush(stdout);
  }
}
Ejemplo n.º 5
0
static void HANDLE_INT_CST_LOW(tree node, char* name, unsigned int value, int depth, bool print, char* acc, char* id, tree target)
{ 
  if(print)
    {
      if(node == target)
        out_printf("$%s%s=%u\n", space(depth), acc, (uint32_t)value);
      else
        out_printf("%s%s=%u\n", space(depth), acc, (uint32_t)value);
    }
}
Ejemplo n.º 6
0
void list_print( LIST * l )
{
    LISTITER iter = list_begin( l ), end = list_end( l );
    if ( iter != end )
    {
        out_printf( "%s", object_str( list_item( iter ) ) );
        iter = list_next( iter );
        for ( ; iter != end; iter = list_next( iter ) )
            out_printf( " %s", object_str( list_item( iter ) ) );
    }
}
Ejemplo n.º 7
0
LIST * list_push_back( LIST * head, OBJECT * value )
{
    unsigned int size = list_length( head );
    unsigned int i;

    if ( DEBUG_LISTS )
        out_printf( "list > %s <\n", object_str( value ) );

    /* If the size is a power of 2, reallocate. */
    if ( size == 0 )
    {
        head = list_alloc( 1 );
    }
    else if ( ( ( size - 1 ) & size ) == 0 )
    {
        LIST * l = list_alloc( size + 1 );
        memcpy( l, head, sizeof( LIST ) + size * sizeof( OBJECT * ) );
        list_dealloc( head );
        head = l;
    }

    list_begin( head )[ size ] = value;
    head->impl.size = size + 1;

    return head;
}
Ejemplo n.º 8
0
static void update_dependants( TARGET * t )
{
    TARGETS * q;

    for ( q = t->dependants; q; q = q->next )
    {
        TARGET * p = q->target;
        char fate0 = p->fate;

        /* If we have already at least begun visiting it and we are not already
         * rebuilding it for other reasons.
         */
        if ( ( fate0 != T_FATE_INIT ) && ( fate0 < T_FATE_BUILD ) )
        {
            p->fate = T_FATE_UPDATE;

            if ( DEBUG_FATE )
            {
                out_printf( "fate change  %s from %s to %s (as dependant of %s)\n",
                        object_str( p->name ), target_fate[ (int) fate0 ], target_fate[ (int) p->fate ], object_str( t->name ) );
            }

            /* If we are done visiting it, go back and make sure its dependants
             * get rebuilt.
             */
            if ( fate0 > T_FATE_MAKING )
                update_dependants( p );
        }
    }
    /* Make sure that rebuilds can be chained. */
    force_rebuilds( t );
}
Ejemplo n.º 9
0
static void time_enter( void * closure, OBJECT * target, int const found,
    timestamp const * const time )
{
    int item_found;
    BINDING * b;
    struct hash * const bindhash = (struct hash *)closure;

    target = path_as_key( target );

    b = (BINDING *)hash_insert( bindhash, target, &item_found );
    if ( !item_found )
    {
        b->name = object_copy( target );
        b->flags = 0;
    }

    timestamp_copy( &b->time, time );
    b->progress = found ? BIND_FOUND : BIND_SPOTTED;

    if ( DEBUG_BINDSCAN )
        out_printf( "time ( %s ) : %s\n", object_str( target ), time_progress[
            b->progress ] );

    object_free( target );
}
Ejemplo n.º 10
0
/*-------------------------------------------------------------------------
 * Function:    ptr_walk1
 *
 * Purpose:     Print memory cast as a pointer type.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec  6 1996
 *
 * Modifications:
 *
 *   Mark C. Miller, Tue Sep  8 15:40:51 PDT 2009
 *   Added RETRIEVE op case.
 *-------------------------------------------------------------------------
 */
static void
ptr_walk1 (obj_t _self, void *mem, int operation, walk_t *wdata) {

   obj_ptr_t    *self = MYCLASS(_self);
   void         *ptr;
   out_t        *f;

   ptr = *((void**)mem);
   switch (operation) {
   case WALK_PRINT:
      f = (wdata && wdata->f) ? wdata->f : OUT_STDOUT;
      if (!ptr) {
         out_printf (f, "NULL");
      } else {
         obj_walk1 (self->sub, ptr, operation, wdata);
      }
      break;

   case WALK_RETRIEVE:
      if (!ptr) return;
      obj_walk1 (self->sub, ptr, operation, wdata);
      break;

   default:
      abort();
   }
}
Ejemplo n.º 11
0
static void finish_module(Context* ctx) {
  if (!ctx->temp_buf.size)
    return;

  out_printf(&ctx->js_buf, "var m = createModule([\n");
  OutputBuffer* module_buf = &ctx->temp_buf;
  const uint8_t* p = module_buf->start;
  const uint8_t* end = module_buf->start + module_buf->size;
  while (p < end) {
    out_printf(&ctx->js_buf, " ");
    const uint8_t* line_end = p + DUMP_OCTETS_PER_LINE;
    for (; p < line_end; ++p)
      out_printf(&ctx->js_buf, "%4d,", *p);
    out_printf(&ctx->js_buf, "\n");
  }
  out_printf(&ctx->js_buf, "]);\nrunTests(m);\n");
}
Ejemplo n.º 12
0
void out_action
(
    char const * const action,
    char const * const target,
    char const * const command,
    char const * const out_d,
    char const * const err_d,
    int const exit_reason
)
{
    /* Print out the action + target line, if the action is quiet the action
     * should be null.
     */
    if ( action )
        out_printf( "%s %s\n", action, target );

    /* Print out the command executed if given -d+2. */
    if ( DEBUG_EXEC )
    {
        out_puts( command );
        out_putc( '\n' );
    }

    /* If the process expired, make user aware with an explicit message, but do
     * this only for non-quiet actions.
     */
    if ( exit_reason == EXIT_TIMEOUT && action )
        out_printf( "%ld second time limit exceeded\n", globs.timeout );

    /* Print out the command output, if requested, or if the program failed, but
     * only output for non-quiet actions.
     */
    if ( action || exit_reason != EXIT_OK )
    {
        if ( out_d &&
           ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) ||
             ( globs.pipe_action == 0 ) ) )
            out_data( out_d );
        if ( err_d && ( globs.pipe_action & 2 /* STDERR_FILENO */ ) )
            err_data( err_d );
    }

    out_flush();
    err_flush();
}
Ejemplo n.º 13
0
void lol_print( LOL * lol )
{
    int i;
    for ( i = 0; i < lol->count; ++i )
    {
        if ( i )
            out_printf( " : " );
        list_print( lol->list[ i ] );
    }
}
Ejemplo n.º 14
0
/* print all event node names */
void
EVTdisplay(wordlist *wl)
{
    Evt_Node_Info_t  *node;
    CKTcircuit       *ckt;
    int node_index, udn_index;
    Evt_Node_Info_t  **node_table;

    NG_IGNORE(wl);
    ckt = g_mif_info.ckt;
    if (!ckt) {
        fprintf(cp_err, "Error: no circuit loaded.\n");
        return;
    }
    node = ckt->evt->info.node_list;
    node_table = ckt->evt->info.node_table;
    out_init();
    if (!node) {
        out_printf("No event node available!\n");
        return;
    }
    out_printf("\nList of event nodes\n");
    out_printf("    %-20s: %-5s, %s\n\n", "node name", "type", "number of events");
    node_index = 0;
    while (node) {
        Evt_Node_t  *node_data = NULL;
        int count = 0;
        char *type;

        udn_index = node_table[node_index]->udn_index;
        if (ckt->evt->data.node)
            node_data = ckt->evt->data.node->head[node_index];
        while (node_data) {
            count++;
            node_data = node_data->next;
        }
        type = g_evt_udn_info[udn_index]->name;
        out_printf("    %-20s: %-5s, %5d\n", node->name, type, count);

        node = node->next;
        node_index++;
    }
}
Ejemplo n.º 15
0
void headers( TARGET * t )
{
    LIST   * hdrscan;
    LIST   * hdrrule;
    #ifndef OPT_HEADER_CACHE_EXT
    LIST   * headlist = L0;
    #endif
    regexp * re[ MAXINC ];
    int rec = 0;
    LISTITER iter;
    LISTITER end;

    hdrscan = var_get( root_module(), constant_HDRSCAN );
    if ( list_empty( hdrscan ) )
        return;

    hdrrule = var_get( root_module(), constant_HDRRULE );
    if ( list_empty( hdrrule ) )
        return;

    if ( DEBUG_HEADER )
        out_printf( "header scan %s\n", object_str( t->name ) );

    /* Compile all regular expressions in HDRSCAN */
    iter = list_begin( hdrscan );
    end = list_end( hdrscan );
    for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) )
    {
        re[ rec++ ] = regex_compile( list_item( iter ) );
    }

    /* Doctor up call to HDRRULE rule */
    /* Call headers1() to get LIST of included files. */
    {
        FRAME frame[ 1 ];
        frame_init( frame );
        lol_add( frame->args, list_new( object_copy( t->name ) ) );
#ifdef OPT_HEADER_CACHE_EXT
        lol_add( frame->args, hcache( t, rec, re, hdrscan ) );
#else
        lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );
#endif

        if ( lol_get( frame->args, 1 ) )
        {
            OBJECT * rulename = list_front( hdrrule );
            /* The third argument to HDRRULE is the bound name of $(<). */
            lol_add( frame->args, list_new( object_copy( t->boundname ) ) );
            list_free( evaluate_rule( bindrule( rulename, frame->module ), rulename, frame ) );
        }

        /* Clean up. */
        frame_free( frame );
    }
}
Ejemplo n.º 16
0
static void print_data(
    Mif_Boolean_t dcop,          /* Is this the operating point data */
    double        step,          /* The analysis step if dcop */
    char          **node_value,  /* The array of values to be printed */
    int           nargs)         /* The size of the value array */
{

    int  i;
    char step_str[100];

    if(dcop)
        strcpy(step_str, "DCOP            ");
    else
        sprintf(step_str, "%-16.9e", step);

    out_printf("%s", step_str);
    for(i = 0; i < nargs; i++)
        out_printf("    %s", node_value[i]);
    out_printf("\n");
}
Ejemplo n.º 17
0
void hashstats_print( struct hashstats * stats, char const * name )
{
    out_printf( "%s table: %d+%d+%d (%dK+%luK+%luK) items+table+hash, %f density\n",
        name,
        stats->count,
        stats->num_items,
        stats->tab_size,
        stats->num_items * stats->item_size / 1024,
        (long unsigned)stats->tab_size * sizeof( ITEM * * ) / 1024,
        (long unsigned)stats->num_hashes * sizeof( struct hash ) / 1024,
        (float)stats->count / (float)stats->sets );
}
Ejemplo n.º 18
0
OBJECT * macro_header_get( OBJECT * macro_name )
{
    HEADER_MACRO * v;
    if ( header_macros_hash && ( v = (HEADER_MACRO *)hash_find(
        header_macros_hash, macro_name ) ) )
    {
        if ( DEBUG_HEADER )
            out_printf( "### macro '%s' evaluated to '%s'\n", object_str( macro_name
                ), object_str( v->filename ) );
        return v->filename;
    }
    return 0;
}
Ejemplo n.º 19
0
static void collect_archive_content_big( int fd, file_archive_info_t * const archive )
{
    struct fl_hdr_big fl_hdr;

    struct {
        struct ar_hdr_big hdr;
        char pad[ 256 ];
    } ar_hdr ;

    char buf[ MAXJPATH ];
    long long offset;
    const char * path = object_str( archive->file->name );

    if ( read( fd, (char *)&fl_hdr, FL_HSZ_BIG ) != FL_HSZ_BIG )
        return;

    sscanf( fl_hdr.fl_fstmoff, "%lld", &offset );

    if ( DEBUG_BINDSCAN )
        out_printf( "scan archive %s\n", path );

    while ( offset > 0 && lseek( fd, offset, 0 ) >= 0 &&
            read( fd, &ar_hdr, sizeof( ar_hdr ) ) >= sizeof( ar_hdr.hdr ) )
    {
        long lar_date;
        int lar_namlen;

        sscanf( ar_hdr.hdr.ar_namlen, "%d"  , &lar_namlen );
        sscanf( ar_hdr.hdr.ar_date  , "%ld" , &lar_date   );
        sscanf( ar_hdr.hdr.ar_nxtmem, "%lld", &offset     );

        if ( !lar_namlen )
            continue;

        ar_hdr.hdr._ar_name.ar_name[ lar_namlen ] = '\0';

        sprintf( buf, "%s", ar_hdr.hdr._ar_name.ar_name );

        if ( strcmp( buf, "") != 0 )
        {
            file_info_t * member = 0;

            archive->members = filelist_push_back( archive->members, object_new( buf ) );
            member = filelist_back( archive->members );
            member->is_file = 1;
            member->is_dir = 0;
            member->exists = 0;
            timestamp_init( &member->time, (time_t)lar_date, 0 );
        }
    }
}
Ejemplo n.º 20
0
static void check_defined( LIST * class_names )
{
    LISTITER iter = list_begin( class_names );
    LISTITER const end = list_end( class_names );
    for ( ; iter != end; iter = list_next( iter ) )
    {
        if ( !hash_find( classes, list_item( iter ) ) )
        {
            out_printf( "Class %s is not defined\n", object_str( list_item( iter ) )
                );
            abort();
        }
    }
}
Ejemplo n.º 21
0
OBJECT * make_class_module( LIST * xname, LIST * bases, FRAME * frame )
{
    OBJECT     * name = class_module_name( list_front( xname ) );
    OBJECT   * * pp;
    module_t   * class_module = 0;
    module_t   * outer_module = frame->module;
    int found;

    if ( !classes )
        classes = hashinit( sizeof( OBJECT * ), "classes" );

    pp = (OBJECT * *)hash_insert( classes, list_front( xname ), &found );
    if ( !found )
    {
        *pp = object_copy( list_front( xname ) );
    }
    else
    {
        out_printf( "Class %s already defined\n", object_str( list_front( xname ) )
            );
        abort();
    }
    check_defined( bases );

    class_module = bindmodule( name );

    {
        /*
            Initialize variables that Boost.Build inserts in every object.
            We want to avoid creating the object's hash if it isn't needed.
         */
        int num = class_module->num_fixed_variables;
        module_add_fixed_var( class_module, constant_name, &num );
        module_add_fixed_var( class_module, constant_class, &num );
        module_set_fixed_variables( class_module, num );
    }

    var_set( class_module, constant_name, xname, VAR_SET );
    var_set( class_module, constant_bases, bases, VAR_SET );

    {
        LISTITER iter = list_begin( bases );
        LISTITER const end = list_end( bases );
        for ( ; iter != end; iter = list_next( iter ) )
            import_base_rules( class_module, list_item( iter ) );
    }

    return name;
}
Ejemplo n.º 22
0
boolean RHBapi_emitter::generate(RHBoutput *out,char const *f)
{
	out_printf(out,"/* %s for %s */\n",__FILE__,f);

	idl_name=f;

	cplusplus=1;
	internal=0;

	preflight_macros_from_idl_filename(f);

	generate_classes(out,GetRepository(),0,1);

	return 1;
}
Ejemplo n.º 23
0
/* Show the next piece on the screen */
static void drawnext(int shapenum,int x,int y) {
    int i;
    block_t ofs[NUMSHAPES] =
    { { 1,  0 }, { 1,  0 }, { 1, -1 }, { 2,  0 }, { 1, -1 }, { 1, -1 }, { 0, -1 } };
    out_setcolor(COLOR_BLACK,COLOR_BLACK);
    for (i = y - 2; i < y + 2; i++) {
        out_gotoxy(x - 2,i);
        out_printf("        ");
    }
    out_setcolor(COLOR_BLACK,SHAPES[shapenum].color);
    for (i = 0; i < NUMBLOCKS; i++) {
        out_gotoxy(x + SHAPES[shapenum].block[i].x * 2 + ofs[shapenum].x,
                y + SHAPES[shapenum].block[i].y + ofs[shapenum].y);
        out_putch(' ');
        out_putch(' ');
    }
}
Ejemplo n.º 24
0
static void file_dirscan_impl( OBJECT * dir, scanback func, void * closure )
{
    file_info_t * const d = file_query( dir );
    if ( !d || !d->is_dir )
        return;

    /* Lazy collect the directory content information. */
    if ( list_empty( d->files ) )
    {
        if ( DEBUG_BINDSCAN )
            out_printf( "scan directory %s\n", object_str( d->name ) );
        if ( file_collect_dir_content_( d ) < 0 )
            return;
    }

    /* OS specific part of the file_dirscan operation. */
    file_dirscan_( d, func, closure );

    /* Report the collected directory content. */
    {
        LISTITER iter = list_begin( d->files );
        LISTITER const end = list_end( d->files );
        for ( ; iter != end; iter = list_next( iter ) )
        {
            OBJECT * const path = list_item( iter );
            file_info_t const * const ffq = file_query( path );
            /* Using a file name read from a file_info_t structure allows OS
             * specific implementations to store some kind of a normalized file
             * name there. Using such a normalized file name then allows us to
             * correctly recognize different file paths actually identifying the
             * same file. For instance, an implementation may:
             *  - convert all file names internally to lower case on a case
             *    insensitive file system
             *  - convert the NTFS paths to their long path variants as that
             *    file system each file system entity may have a long and a
             *    short path variant thus allowing for many different path
             *    strings identifying the same file.
             */
            (*func)( closure, ffq->name, 1 /* stat()'ed */, &ffq->time );
        }
    }
}
Ejemplo n.º 25
0
static void force_rebuilds( TARGET * t )
{
    TARGETS * d;
    for ( d = t->rebuilds; d; d = d->next )
    {
        TARGET * r = d->target;

        /* If it is not already being rebuilt for other reasons. */
        if ( r->fate < T_FATE_BUILD )
        {
            if ( DEBUG_FATE )
                out_printf( "fate change  %s from %s to %s (by rebuild)\n",
                        object_str( r->name ), target_fate[ (int) r->fate ], target_fate[ T_FATE_REBUILD ] );

            /* Force rebuild it. */
            r->fate = T_FATE_REBUILD;

            /* And make sure its dependants are updated too. */
            update_dependants( r );
        }
    }
}
Ejemplo n.º 26
0
/*
 - regdump - dump a regexp onto stdout in vaguely comprehensible form
 */
void
regdump( regexp *r )
{
    register char *s;
    register char op = EXACTLY; /* Arbitrary non-END op. */
    register char *next;


    s = r->program + 1;
    while (op != END) { /* While that wasn't END last time... */
        op = OP(s);
        out_printf("%2d%s", s-r->program, regprop(s));  /* Where, what. */
        next = regnext(s);
        if (next == NULL)       /* Next ptr. */
            out_printf("(0)");
        else
            out_printf("(%d)", (s-r->program)+(next-s));
        s += 3;
        if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
            /* Literal string, where present. */
            while (*s != '\0') {
                out_putc(*s);
                s++;
            }
            s++;
        }
        out_putc('\n');
    }

    /* Header fields of interest. */
    if (r->regstart != '\0')
        out_printf("start `%c' ", r->regstart);
    if (r->reganch)
        out_printf("anchored ");
    if (r->regmust != NULL)
        out_printf("must have \"%s\"", r->regmust);
    out_printf("\n");
}
Ejemplo n.º 27
0
/* output the appropriate keyword value(s) */
static void keyreplace(enum markers marker)
{
	const char *target_lockedby = NULL;	// Not wired in yet

	char const *xxp;
	char *leader = NULL;
	char date_string[25];
	uchar *kdelim_ptr = NULL;
	enum expand_mode exp = Gexpand;
	char const *sp = Keyword[(int)marker];

	strftime(date_string, 25,
		"%Y/%m/%d %H:%M:%S", localtime(&Gversion->date));

	if (exp != EXPANDKV)
		out_printf("%c%s", KDELIM, sp);

	if (exp != EXPANDKK) {
		if (exp != EXPANDKV)
			out_printf("%c%c", VDELIM, ' ');

		switch (marker) {
		case Author:
			out_fputs(Gversion->author);
			break;
		case Date:
			out_fputs(date_string);
			break;
		case Id:
		case Header:
			if (marker == Id )
				escape_string(basefilename(Gfilename));
			else	escape_string(getfullRCSname());
			out_printf(" %s %s %s %s",
				Gversion_number, date_string,
				Gversion->author, Gversion->state);
			if (target_lockedby && exp == EXPANDKKVL)
				out_printf(" %s", target_lockedby);
			break;
		case Locker:
			if (target_lockedby && exp == EXPANDKKVL)
				out_fputs(target_lockedby);
			break;
		case Log:
		case RCSfile:
			escape_string(basefilename(Gfilename));
			break;
		case Revision:
			out_fputs(Gversion_number);
			break;
		case Source:
			escape_string(getfullRCSname());
			break;
		case State:
			out_fputs(Gversion->state);
			break;
		default:
			break;
		}

		if (exp != EXPANDKV)
			out_putc(' ');
	}

#if 0
/* Closing delimiter is processed again in expandline */
	if (exp != EXPANDKV)
	    out_putc(KDELIM);
#endif

	if (marker == Log) {
		int c;
		size_t cs, cw, ls;
		/*
		 * "Closing delimiter is processed again in expandline"
		 * does not apply here, since we consume the input.
		 */
		if (exp != EXPANDKV)
			out_putc(KDELIM);

		sp = Glog;
		ls = strlen(Glog);
		if (sizeof(ciklog)-1<=ls && !memcmp(sp,ciklog,sizeof(ciklog)-1))
			return;

		/* Back up to the start of the current input line */
                int num_kdelims = 0;
		for (;;) {
			c = in_buffer_ungetc();
			if (c == EOF)
				break;
			if (c == '\n') {
				in_buffer_getc();
				break;
			}
			if (c == KDELIM) {
                                num_kdelims++;
                                /* It is possible to have multiple keywords
                                   on one line. Make sure we don't backtrack
                                   into some other keyword! */
                                if (num_kdelims > 2) {
                                        in_buffer_getc();
                                        break;
                                }
				kdelim_ptr = in_buffer_loc();
                        }
		}

		/* Copy characters before `$Log' into LEADER.  */
		xxp = leader = xmalloc(kdelim_ptr - in_buffer_loc());
		for (cs = 0; ;  cs++) {
			c = in_buffer_getc();
			if (c == KDELIM)
				break;
			leader[cs] = c;
		}

		/* Convert traditional C or Pascal leader to ` *'.  */
		for (cw = 0;  cw < cs;  cw++)
			if (!latin1_whitespace(xxp[cw]))
				break;
		if (cw+1 < cs &&  xxp[cw+1] == '*' &&
		    (xxp[cw] == '/'  ||  xxp[cw] == '(')) {
			size_t i = cw+1;
			for (;;) {
				if (++i == cs) {
					leader[cw] = ' ';
					break;
				} else if (!latin1_whitespace(xxp[i]))
					break;
			}
		}

		/* Skip `$Log ... $' string.  */
		do {
			c = in_buffer_getc();
		} while (c != KDELIM);

		out_putc('\n');
		out_awrite(xxp, cs);
		out_printf("Revision %s  %s  %s",
				Gversion_number,
				date_string,
				Gversion->author);

		/* Do not include state: it may change and is not updated.  */
		cw = cs;
		for (;  cw && (xxp[cw-1]==' ' || xxp[cw-1]=='\t');  --cw)
			;
		for (;;) {
			out_putc('\n');
			out_awrite(xxp, cw);
			if (!ls)
				break;
			--ls;
			c = *sp++;
			if (c != '\n') {
				out_awrite(xxp+cw, cs-cw);
				do {
					out_putc(c);
					if (!ls)
						break;
					--ls;
					c = *sp++;
				} while (c != '\n');
			}
		}
		free(leader);
	}
}
Ejemplo n.º 28
0
static void var_dump( OBJECT * symbol, LIST * value, char * what )
{
    out_printf( "%s %s = ", what, object_str( symbol ) );
    list_print( value );
    out_printf( "\n" );
}
Ejemplo n.º 29
0
int main(int argc, char* argv[]) {
    bool finished;
    int ch;
    engine_t engine;
    /* Initialize */
    rand_init();							/* must be called before engine_init () */
    engine_init(&engine, score_function);	/* must be called before using engine.curshape */
    finished = shownext = FALSE;
    memset(shapecount, 0, NUMSHAPES * sizeof(int));
    shapecount[engine.curshape]++;
    parse_options(argc,argv);				/* must be called after initializing variables */
    if (level < MINLEVEL) {
        choose_level();
    }
    io_init();
    drawbackground();
    in_timeout(DELAY);
    /* Main loop */
    do {
        /* draw shape */
        showstatus(&engine);
        drawboard(engine.board);
        out_refresh();
        /* Check if user pressed a key */
        if ((ch = in_getch ()) != ERR) {
            switch (ch) {
            case 'j':
            case KEY_LEFT:
                engine_move(&engine,ACTION_LEFT);
                break;
            case 'k':
            case '\n':
                engine_move(&engine,ACTION_ROTATE);
                break;
            case 'l':
            case KEY_RIGHT:
                engine_move(&engine,ACTION_RIGHT);
                break;
            case ' ':
            case KEY_DOWN:
                engine_move(&engine,ACTION_DROP);
                break;
                /* show next piece */
            case 's':
                shownext = TRUE;
                break;
                /* toggle dotted lines */
            case 'd':
                dottedlines = !dottedlines;
                break;
                /* next level */
            case 'a':
            case KEY_UP:
                if (level < MAXLEVEL) {
                    level++;
                    in_timeout(DELAY);
                }
                else out_beep();
                break;
                /* quit */
            case 'q':
                finished = TRUE;
                break;
                /* pause */
            case 'p':
                out_setcolor(COLOR_WHITE,COLOR_BLACK);
                out_gotoxy((out_width() - 34) / 2,out_height() - 2);
                out_printf("Paused - Press any key to continue");
                while ((ch = in_getch ()) == ERR) ;	/* Wait for a key to be pressed */
                in_flush();							/* Clear keyboard buffer */
                out_gotoxy((out_width() - 34) / 2, out_height() - 2);
                out_printf("                                  ");
                break;
                /* unknown keypress */
            default:
                out_beep();
            }
            in_flush();
        } else {
            switch (engine_evaluate(&engine)) {
            /* game over (board full) */
            case -1:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) level++;
                finished = TRUE;
                break;
                /* shape at bottom, next one released */
            case 0:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) {
                    level++;
                    in_timeout(DELAY);
                }
                shapecount[engine.curshape]++;
                break;
                /* shape moved down one line */
            case 1:
                break;
            }
        }
    } while (!finished);
    /* Restore console settings and exit */
    io_close();
    /* Don't bother the player if he want's to quit */
    if (ch != 'q') {
        showplayerstats(&engine);
        savescores(GETSCORE(engine.score));
    }
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 30
0
/* This show the current status of the game */
static void showstatus(engine_t *engine) {
    static const int shapenum[NUMSHAPES] = { 4, 6, 5, 1, 0, 3, 2 };
    char tmp[MAXDIGITS + 1];
    int i,sum = getsum ();
    out_setattr(ATTR_OFF);
    out_setcolor(COLOR_WHITE,COLOR_BLACK);
    out_gotoxy(1,YTOP + 1);   out_printf ("Your level: %d",level);
    out_gotoxy(1,YTOP + 2);   out_printf ("Full lines: %d",engine->status.droppedlines);
    out_gotoxy(2,YTOP + 4);   out_printf ("Score");
    out_setattr(ATTR_BOLD);
    out_setcolor(COLOR_YELLOW,COLOR_BLACK);
    out_printf("  %d",GETSCORE (engine->score));
    if (shownext) { 
        drawnext(engine->nextshape,3,YTOP + 22);
    }
    out_setattr(ATTR_OFF);
    out_setcolor(COLOR_WHITE,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 12,YTOP + 1);
    out_printf("STATISTICS");
    out_setcolor(COLOR_BLACK,COLOR_MAGENTA);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 3);
    out_printf("      ");
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 4);
    out_printf("  ");
    out_setcolor(COLOR_MAGENTA,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 3);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[0]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 3);
    out_printf("%s",tmp);
    out_setcolor(COLOR_BLACK,COLOR_RED);
    out_gotoxy(out_width () - MAXDIGITS - 13,YTOP + 5);
    out_printf("        ");
    out_setcolor(COLOR_RED,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 5);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[1]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 5);
    out_printf("%s",tmp);
    out_setcolor(COLOR_BLACK,COLOR_WHITE);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 7);
    out_printf("      ");
    out_gotoxy(out_width () - MAXDIGITS - 13,YTOP + 8);
    out_printf("  ");
    out_setcolor(COLOR_WHITE,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 7);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[2]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 7);
    out_printf("%s",tmp);
    out_setcolor(COLOR_BLACK,COLOR_GREEN);
    out_gotoxy(out_width () - MAXDIGITS - 9,YTOP + 9);
    out_printf("    ");
    out_gotoxy(out_width () - MAXDIGITS - 11,YTOP + 10);
    out_printf("    ");
    out_setcolor(COLOR_GREEN,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 9);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[3]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 9);
    out_printf("%s",tmp);
    out_setcolor(COLOR_BLACK,COLOR_CYAN);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 11);
    out_printf("    ");
    out_gotoxy(out_width () - MAXDIGITS - 15,YTOP + 12);
    out_printf("    ");
    out_setcolor(COLOR_CYAN,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 11);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[4]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 11);
    out_printf("%s",tmp);
    out_setcolor(COLOR_BLACK,COLOR_BLUE);
    out_gotoxy(out_width () - MAXDIGITS - 9,YTOP + 13);
    out_printf("    ");
    out_gotoxy(out_width () - MAXDIGITS - 9,YTOP + 14);
    out_printf("    ");
    out_setcolor(COLOR_BLUE,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 13);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[5]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 13);
    out_printf("%s",tmp);
    out_setattr(ATTR_OFF);
    out_setcolor(COLOR_BLACK,COLOR_YELLOW);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 15);
    out_printf("      ");
    out_gotoxy(out_width () - MAXDIGITS - 15,YTOP + 16);
    out_printf("  ");
    out_setcolor(COLOR_YELLOW,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 3,YTOP + 15);
    out_putch('-');
    snprintf(tmp,MAXDIGITS + 1,"%d",shapecount[shapenum[6]]);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 15);
    out_printf("%s",tmp);
    out_setcolor(COLOR_WHITE,COLOR_BLACK);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 17);
    for (i = 0; i < MAXDIGITS + 16; i++) {
        out_putch ('-');
    }
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 18);
    out_printf("Sum          :");
    snprintf(tmp,MAXDIGITS + 1,"%d",sum);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 18);
    out_printf("%s",tmp);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 20);
    for (i = 0; i < MAXDIGITS + 16; i++) {
        out_putch (' ');
    }
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 20);
    out_printf("Score ratio  :");
    snprintf(tmp,MAXDIGITS + 1,"%d",GETSCORE (engine->score) / sum);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 20);
    out_printf("%s",tmp);
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 21);
    for (i = 0; i < MAXDIGITS + 16; i++) {
        out_putch (' ');
    }
    out_gotoxy(out_width () - MAXDIGITS - 17,YTOP + 21);
    out_printf("Efficiency   :");
    snprintf(tmp,MAXDIGITS + 1,"%d",engine->status.efficiency);
    out_gotoxy(out_width () - strlen (tmp) - 1,YTOP + 21);
    out_printf("%s",tmp);
}