Example #1
0
static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
{
	unsigned int off;	/* Offset of last byte */
	u8 *addr = page_address(page);

	print_tracking(s, p);

	print_page_info(page);

	printk(KERN_ERR "INFO: Object 0x%p @offset=%tu fp=0x%p\n\n",
			p, p - addr, get_freepointer(s, p));

	if (p > addr + 16)
		print_section("Bytes b4", p - 16, 16);

	print_section("Object", p, min_t(unsigned long, s->objsize, PAGE_SIZE));

	if (s->flags & SLAB_RED_ZONE)
		print_section("Redzone", p + s->objsize,
			s->inuse - s->objsize);

	if (s->offset)
		off = s->offset + sizeof(void *);
	else
		off = s->inuse;

	if (s->flags & SLAB_STORE_USER)
		off += 2 * sizeof(struct track);

	if (off != s->size)
		/* Beginning of the filler is the free pointer */
		print_section("Padding", p + off, s->size - off);

	dump_stack();
}
int main(int argc, char *argv[]) {
    int list[LIST_LEN] = {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7};

    // recursive method, described in the book
    section result2 = find_max_subarray(list, 0, LIST_LEN - 1);
    print_section(result2);

    // faster algorithm
    section result1 = find_max_value(list);
    print_section(result1);

    return 0;
}
Example #3
0
static void AddTables ( FILE * df )
{
    ASSERT(df);

    //--------------------------------------------------

 #if 0 // [[2do]] not needed yet

    print_section(df,sep2,"Region Info");

    char ch;
    for ( ch = 'A'; ch <= 'Z'; ch++ )
    {
	const RegionInfo_t * reg = GetRegionInfo(ch);
	fprintf(df,"#:def_tab(\"region\",'%c',%u,%u,\"%s\",\"%s\")\n",
		ch, reg->reg, reg->mandatory, reg->name4, reg->name );
    }
    const RegionInfo_t * reg = GetRegionInfo(0);
    fprintf(df,"#:def_tab(\"region\",'',%2u,%u,\"%s\",\"%s\")\n",
	reg->reg, reg->mandatory, reg->name4, reg->name );

 #endif

    //--------------------------------------------------
}
Example #4
0
File: vasm.c Project: ezrec/vasm
void leave(void)
{
    section *sec;
    symbol *sym;

    if(outfile) {
        fclose(outfile);
        if (errors)
            remove(outname);
    }

    if(DEBUG) {
        fprintf(stdout,"Sections:\n");
        for(sec=first_section; sec; sec=sec->next)
            print_section(stdout,sec);

        fprintf(stdout,"Symbols:\n");
        for(sym=first_symbol; sym; sym=sym->next) {
            print_symbol(stdout,sym);
            fprintf(stdout,"\n");
        }
    }

    if(errors)
        exit(EXIT_FAILURE);
    else
        exit(EXIT_SUCCESS);
}
Example #5
0
void show_directives(void)
{
	while(mini_next(ini)) {
		if(!ini->key) { print_section(ini); }
		else          { print_option(ini); }
	}
}
Example #6
0
/* Check the pad bytes at the end of a slab page */
static int slab_pad_check(struct kmem_cache *s, struct page *page)
{
	u8 *start;
	u8 *fault;
	u8 *end;
	int length;
	int remainder;

	if (!(s->flags & SLAB_POISON))
		return 1;

	start = page_address(page);
	length = (PAGE_SIZE << compound_order(page)) - s->reserved;
	end = start + length;
	remainder = length % s->size;
	if (!remainder)
		return 1;

	fault = check_bytes(end - remainder, POISON_INUSE, remainder);
	if (!fault)
		return 1;
	while (end > fault && end[-1] == POISON_INUSE)
		end--;

	slab_err(s, page, "Padding overwritten. 0x%p-0x%p", fault, end - 1);
	print_section("Padding", end - remainder, remainder);

	restore_bytes(s, "slab padding", POISON_INUSE, end - remainder, end);
	return 0;
}
Example #7
0
int
main(int argc, char **argv)
{
    FILE *f;
    FILE_HEADER filehead;
    size_t symtab_off;
    u32 i;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <xdf>\n", argv[0]);
        return EXIT_FAILURE;
    }

    f = fopen(argv[1], "rb");
    if (!f) {
        fprintf(stderr, "Could not open `%s'\n", argv[1]);
        return EXIT_FAILURE;
    }

    fread(&filehead.f_magic, sizeof(filehead.f_magic), 1, f);
    fread(&filehead.f_nsect, sizeof(filehead.f_nsect), 1, f);
    fread(&filehead.f_nsyms, sizeof(filehead.f_nsyms), 1, f);
    fread(&filehead.f_size, sizeof(filehead.f_size), 1, f);

    if (filehead.f_magic != XDF_MAGIC) {
        fprintf(stderr, "Magic number mismatch (expected %08X, got %08X\n",
                XDF_MAGIC, filehead.f_magic);
        return EXIT_FAILURE;
    }

    print_file_header(&filehead);
    symtab_off = FILE_HEADER_SIZE+filehead.f_nsect*SECTION_HEADER_SIZE;
    for (i=0; i<filehead.f_nsect; i++) {
        SECTION_HEADER secthead;
        fread(&secthead.s_name_idx, sizeof(secthead.s_name_idx), 1, f);
        fread(&secthead.s_addr, sizeof(secthead.s_addr), 1, f);
        fread(&secthead.s_vaddr, sizeof(secthead.s_vaddr), 1, f);
        fread(&secthead.s_align, sizeof(secthead.s_align), 1, f);
        fread(&secthead.s_flags, sizeof(secthead.s_flags), 1, f);
        fread(&secthead.s_data_off, sizeof(secthead.s_data_off), 1, f);
        fread(&secthead.s_data_size, sizeof(secthead.s_data_size), 1, f);
        fread(&secthead.s_reltab_off, sizeof(secthead.s_reltab_off), 1, f);
        fread(&secthead.s_num_reloc, sizeof(secthead.s_num_reloc), 1, f);
        print_section(&secthead, f, symtab_off);
    }

    printf("Symbol Table:\n");
    for (i=0; i<filehead.f_nsyms; i++) {
        SYMBOL_ENTRY syment;
        read_syment(&syment, f);
        print_symbol(&syment, f, symtab_off, sizeof(FILE_HEADER));
    }

    return EXIT_SUCCESS;
}
Example #8
0
int		dump_obj(const char* filename)
{
  Elf_data	*data;

  if ((data = create_elf_data(filename)) == 0)
  {
    printf("Error: %s\n", strerror(errno));
    return (-1);
  }
  print_header(data);
  print_section(data, -1);
  clean_elf_data(data);
  return (0);
}
Example #9
0
/**
 * The main method. You should pass the size of the array as command-line
 * argument.
 */
int main(int argc, char **argv) {
    std::string path = "/home/";

    if (argc >= 2) {
        path += argv[1];
    }

    std::cout << std::endl << path << std::endl;

    Node *root = create_tree();

    print_section(root, path);

    return 0;
}
Example #10
0
static void trace(struct kmem_cache *s, struct page *page, void *object,
								int alloc)
{
	if (s->flags & SLAB_TRACE) {
		printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n",
			s->name,
			alloc ? "alloc" : "free",
			object, page->inuse,
			page->freelist);

		if (!alloc)
			print_section("Object", (void *)object, s->objsize);

		dump_stack();
	}
}
Example #11
0
File: help.c Project: 0xheart0/vlc
static void print_item(const module_t *m, const module_config_t *item,
                       const module_config_t **section, bool color, bool desc)
{
#ifndef _WIN32
# define OPTION_VALUE_SEP " "
#else
# define OPTION_VALUE_SEP "="
#endif
    const char *bra = OPTION_VALUE_SEP "<", *type, *ket = ">";
    const char *prefix = NULL, *suffix = NULL;
    char *typebuf = NULL;

    switch (CONFIG_CLASS(item->i_type))
    {
        case 0: // hint class
            switch (item->i_type)
            {
                case CONFIG_HINT_CATEGORY:
                case CONFIG_HINT_USAGE:
                    printf(color ? GREEN "\n %s\n" GRAY : "\n %s\n",
                           module_gettext(m, item->psz_text));

                    if (desc && item->psz_longtext != NULL)
                        printf(color ? CYAN " %s\n" GRAY : " %s\n",
                               module_gettext(m, item->psz_longtext));
                    break;

                case CONFIG_SECTION:
                    *section = item;
                    break;
            }
            return;

        case CONFIG_ITEM_STRING:
            type = _("string");
            if (item->list_count > 0)
            {
                size_t len = 0;

                for (unsigned i = 0; i < item->list_count; i++)
                    len += strlen(item->list.psz[i]) + 1;

                typebuf = malloc(len);
                if (typebuf == NULL)
                    break;

                bra = OPTION_VALUE_SEP "{";
                type = typebuf;
                ket = "}";

                *typebuf = 0;
                for (unsigned i = 0; i < item->list_count; i++)
                {
                    if (i > 0)
                        strcat(typebuf, ",");
                    strcat(typebuf, item->list.psz[i]);
                }
            }
            break;

        case CONFIG_ITEM_INTEGER:
            type = _("integer");

            if (item->list_count > 0)
            {
                size_t len = 0;

                for (unsigned i = 0; i < item->list_count; i++)
                    len += strlen(module_gettext(m, item->list_text[i]))
                           + 4 * sizeof (int) + 5;

                typebuf = malloc(len);
                if (typebuf == NULL)
                    break;

                bra = OPTION_VALUE_SEP "{";
                type = typebuf;
                ket = "}";

                *typebuf = 0;
                for (unsigned i = 0; i < item->list_count; i++)
                {
                    if (i != 0)
                        strcat(typebuf, ", ");
                    sprintf(typebuf + strlen(typebuf), "%i (%s)",
                            item->list.i[i],
                            module_gettext(m, item->list_text[i]));
                }
            }
            else if (item->min.i != 0 || item->max.i != 0)
            {
                if (asprintf(&typebuf, "%s [%"PRId64" .. %"PRId64"]",
                             type, item->min.i, item->max.i) >= 0)
                    type = typebuf;
                else
                    typebuf = NULL;
            }
            break;

        case CONFIG_ITEM_FLOAT:
            type = _("float");
            if (item->min.f != 0.f || item->max.f != 0.f)
            {
                if (asprintf(&typebuf, "%s [%f .. %f]", type,
                             item->min.f, item->max.f) >= 0)
                    type = typebuf;
                else
                    typebuf = NULL;
            }
            break;

        case CONFIG_ITEM_BOOL:
            bra = type = ket = "";
            prefix = ", --no-";
            suffix = item->value.i ? _("(default enabled)")
                                   : _("(default disabled)");
            break;
       default:
            return;
    }

    print_section(m, section, color, desc);

    /* Add short option if any */
    char shortopt[4];
    if (item->i_short != '\0')
        sprintf(shortopt, "-%c,", item->i_short);
    else
        strcpy(shortopt, "   ");

    if (CONFIG_CLASS(item->i_type) == CONFIG_ITEM_BOOL)
        printf(color ? WHITE"  %s --%s"      "%s%s%s%s%s "GRAY
                     : "  %s --%s%s%s%s%s%s ", shortopt, item->psz_name,
               prefix, item->psz_name, bra, type, ket);
    else
        printf(color ? WHITE"  %s --%s"YELLOW"%s%s%s%s%s "GRAY
                     : "  %s --%s%s%s%s%s%s ", shortopt, item->psz_name,
               "", "",  /* XXX */      bra, type, ket);

    /* Wrap description */
    int offset = PADDING_SPACES - strlen(item->psz_name)
               - strlen(bra) - vlc_swidth(type) - strlen(ket) - 1;
    if (CONFIG_CLASS(item->i_type) == CONFIG_ITEM_BOOL)
        offset -= strlen(item->psz_name) + vlc_swidth(prefix);
    if (offset < 0)
    {
        putchar('\n');
        offset = PADDING_SPACES + LINE_START;
    }

    printf("%*s", offset, "");
    print_desc(module_gettext(m, item->psz_longtext),
               PADDING_SPACES + LINE_START, color);

    if (suffix != NULL)
    {
        printf("%*s", offset, "");
        print_desc(suffix, PADDING_SPACES + LINE_START, color);
    }

    if (desc && (item->psz_longtext != NULL && item->psz_longtext[0]))
    {   /* Wrap long description */
        printf("%*s", LINE_START + 2, "");
        print_desc(module_gettext(m, item->psz_longtext),
                   LINE_START + 2, false);
    }

    free(typebuf);
}
Example #12
0
static enumError Generate ( control_t * ctrl )
{
    ASSERT(ctrl);
    ASSERT(ctrl->info);

    FILE * cf = ctrl->cf;
    FILE * hf = ctrl->hf;
    ASSERT(cf);
    ASSERT(hf);

    FREE(ctrl->opt_allow_grp);
    FREE(ctrl->opt_allow_cmd);
    ctrl->opt_allow_grp = ctrl->opt_allow_cmd = 0;

    const info_t *info;


    //----- ui header

    fprintf(cf,text_ui_head);
    fprintf(hf,text_ui_head);


    //----- setup guard

    char guard[100];
    snprintf(guard,sizeof(guard),"WIT_UI_%s_h",ctrl->info->c_name);
    char * ptr;
    for ( ptr = guard; *ptr; ptr++ )
	*ptr = *ptr == '-' ? '_' : toupper((int)*ptr);
    fprintf(hf,"\n#ifndef %s\n#define %s\n",guard,guard);


    //----- header

    ASSERT( ctrl->info->type & T_DEF_TOOL );
    ccp tool_name = ctrl->info->c_name;

    fprintf(cf,"#include <getopt.h>\n");
    fprintf(cf,"#include \"ui-%s.h\"\n",tool_name);

    fprintf(hf,"#include \"lib-std.h\"\n");
    fprintf(hf,"#include \"ui.h\"\n");


    //----- print enum enumOptions & OptionInfo[]

    print_section(cf,sep1,"OptionInfo[]");
    print_section(hf,sep1,"enum enumOptions");

    char * var_ptr = var_buf;
    char * var_end = var_buf + sizeof(var_buf);
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const InfoOption_t OptionInfo[OPT__N_TOTAL+1];\n");

    fprintf(cf,
	    "const InfoOption_t OptionInfo[OPT__N_TOTAL+1] =\n"
	    "{\n"
	    "    {0,0,0,0,0}, // OPT_NONE,\n"
	    "\n"
	    );

    fprintf(hf,
	    "typedef enum enumOptions\n"
	    "{\n"
	    "\tOPT_NONE,\n"
	    "\n"
	    );

    ctrl->n_opt = 1;
    ctrl->n_opt_specific = 0;
    if ( ctrl->n_cmd )
    {
	fprintf(cf,"    //----- command specific options -----\n\n");
	fprintf(hf,"\t//----- command specific options -----\n\n");

	for ( info = ctrl->info; info < ctrl->end; info++ )
	    if ( info->type & F_OPT_COMMAND )
		print_opt(ctrl,info);

	ctrl->n_opt_specific = ctrl->n_opt;

	fprintf(cf,
		"    {0,0,0,0,0}, // OPT__N_SPECIFIC == %d\n\n"
		"    //----- global options -----\n\n",
		ctrl->n_opt_specific );

	fprintf(hf,
		"\n\tOPT__N_SPECIFIC, // == %d \n\n"
		"\t//----- global options -----\n\n",
		ctrl->n_opt_specific );
    }

    for ( info = ctrl->info; info < ctrl->end; info++ )
	if ( info->type & F_OPT_GLOBAL )
	    print_opt(ctrl,info);

    fprintf(cf,
	    "    {0,0,0,0,0} // OPT__N_TOTAL == %d\n\n"
	    "};\n"
	    ,ctrl->n_opt );

    fprintf(hf,
	    "\n\tOPT__N_TOTAL // == %d\n\n"
	    "} enumOptions;\n"
	    ,ctrl->n_opt );

    if (ctrl->n_opt_specific)
    {
	noTRACE("opt_allowed = ( %2u + %2u ) * %2u\n",
		ctrl->n_grp, ctrl->n_cmd, ctrl->n_opt_specific );
	if (ctrl->n_grp)
	    ctrl->opt_allow_grp = CALLOC(ctrl->n_grp,ctrl->n_opt_specific);
	ctrl->opt_allow_cmd = CALLOC(ctrl->n_cmd,ctrl->n_opt_specific);
    }


    //----- print alternate option infos

    bool done = false;
    const info_t * last_cmd = ctrl->info;
    ctrl->opt_prefix = "def";
    for ( info = ctrl->info; info < ctrl->end; info++ )
    {
	if ( info->type & T_CMD_BEG )
	{
	    ctrl->opt_prefix = "cmd";
	    last_cmd = info;
	}
	else if ( info->type & T_GRP_BEG )
	{
	    ctrl->opt_prefix = "grp";
	    last_cmd = info;
	}
	else if ( info->type & T_CMD_OPT && info->help && *info->help )
	{
	    if (!done)
	    {
		print_section(cf,sep1,"alternate option infos");
		done = true;
	    }

	    const info_t * info0;
	    for ( info0 = ctrl->info; info0 < info; info0++ )
		if ( info0->type & T_DEF_OPT && !strcmp(info->c_name,info0->c_name) )
		{
		    print_info_opt(ctrl,info,info0,last_cmd->c_name);
		    break;
		}
	}
    }

    //----- print enum enumOptionsBit

    if ( ctrl->n_cmd )
    {
	print_section(hf,sep1,"enum enumOptionsBit");

	fprintf(hf,
		"//\t*****  only for verification  *****\n"
		"\n"
		"//typedef enum enumOptionsBit\n"
		"//{\n"
		"//\t//----- command specific options -----\n"
		"//\n"
		);

	for ( info = ctrl->info; info < ctrl->end; info++ )
	    if ( info->type & F_OPT_COMMAND )
		fprintf(hf,"//\tOB_%s%.*s= 1llu << OPT_%s,\n",
			info->c_name,
			( 28 - (int)strlen(info->c_name) ) / 8, tabs,
			info->c_name );

	fprintf(hf,"//\n//\t//----- group & command options -----\n");

	for ( info = ctrl->info; info < ctrl->end; )
	{
	    ccp cmd_name;
	    u8 * opt_allow = 0;
	    if ( info->type & T_CMD_BEG )
	    {
		cmd_name = info->c_name;
		fprintf(hf,"//\n//\tOB_CMD_%s%.*s=",
			info->c_name,
			( 24 - (int)strlen(info->c_name) ) / 8, tabs );
		if (ctrl->opt_allow_cmd)
		{
		    //PRINT("SELECT ALLOW CMD %u/%s\n",info->index,info->c_name);
		    opt_allow = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific;
		}
	    }
	    else if ( info->type & T_GRP_BEG )
	    {
		cmd_name = info->c_name;
		fprintf(hf,"//\n//\tOB_GRP_%s%.*s=",
			info->c_name,
			( 24 - (int)strlen(info->c_name) ) / 8, tabs );
		if (ctrl->opt_allow_grp)
		{
		    //PRINT("SELECT ALLOW GRP %u/%s\n",info->index,info->c_name);
		    opt_allow = ctrl->opt_allow_grp + info->index * ctrl->n_opt_specific;
		}
	    }
	    else
	    {
		info++;
		continue;
	    }

	    info++;
	    char * dest = iobuf;
	    while ( info < ctrl->end )
	    {
		if ( info->type & T_ALL_OPT )
		{
		    dest += sprintf(dest,"\n//\t\t\t\t| ~(u64)0");
		    if (opt_allow)
		    {
			//PRINT("ALLOW ALL\n");
			memset(opt_allow,1,ctrl->n_opt_specific);
		    }
		}
		else if ( info->type & T_COPY_CMD )
		{
		    dest += sprintf(dest,"\n//\t\t\t\t| OB_CMD_%s",info->c_name);
		    if (opt_allow)
		    {
			//PRINT("OR CMD %u/%s\n",info->index,info->c_name);
			DASSERT(ctrl->opt_allow_cmd);
			u8 * src = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific;
			u8 * dest = opt_allow;
			int count = ctrl->n_opt_specific;
			while ( count-- > 0 )
			    *dest++ |= *src++;
		    }
		}
		else if ( info->type & T_COPY_GRP )
		{
		    dest += sprintf(dest,"\n//\t\t\t\t| OB_GRP_%s",info->c_name);
		    if ( opt_allow && ctrl->opt_allow_grp )
		    {
			//PRINT("OR GRP %u/%s\n",info->index,info->c_name);
			u8 * src = ctrl->opt_allow_grp + info->index * ctrl->n_opt_specific;
			u8 * dest = opt_allow;
			int count = ctrl->n_opt_specific;
			while ( count-- > 0 )
			    *dest++ |= *src++;
		    }
		}
		else if ( info->type & T_CMD_OPT )
		{
		    if (FindStringField(&ctrl->copt,info->c_name))
		    {
			dest += sprintf(dest,"\n//\t\t\t\t| OB_%s",info->c_name);
			if ( opt_allow && info->index )
			{
			    //PRINT("ALLOW OPT %u/%s\n",info->index,info->c_name);
			    opt_allow[info->index] = 1;
			}
		    }
		    else if (!FindStringField(&ctrl->gopt,info->c_name))
			ERROR0(ERR_SEMANTIC,"Option not defined: %s %s --%s",
				tool_name, cmd_name, info->c_name );
		}
		else if ( info->type & (T_CMD_BEG|T_GRP_BEG) )
		    break;
		ASSERT( dest < iobuf + sizeof(iobuf) );
		info++;
	    }
	    if ( dest == iobuf )
		fprintf(hf," 0,\n");
	    else
		fprintf(hf,"%s,\n",iobuf+8);
	}

	fprintf(hf,"//\n//} enumOptionsBit;\n");
    }


    //----- print enum enumCommands & CommandTab[]

    print_section(hf,sep1,"enum enumCommands");
    fprintf(hf,
	    "typedef enum enumCommands\n"
	    "{\n"
	    "\tCMD__NONE,"
	    );

    if ( ctrl->n_cmd )
    {
	print_section(cf,sep1,"CommandTab[]");
	fputs("\n\n",hf);

	var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const CommandTab_t CommandTab[];\n");

	fprintf(cf,
		"const CommandTab_t CommandTab[] =\n"
		"{\n"
		);

	for ( info = ctrl->info; info < ctrl->end; info++ )
	    if ( info->type & T_DEF_CMD )
	    {
		fprintf( hf, "\tCMD_%s,\n",info->c_name);
		ccp ptr = info->namelist;
		while (*ptr)
		{
		    ccp n1 = ptr;
		    while ( *ptr && *ptr != '|' )
			ptr++;
		    const int l1 = ptr - n1;
		    while ( *ptr == '|' )
			ptr++;
		    if (*ptr)
		    {
			ccp n2 = ptr;
			while ( *ptr && *ptr != '|' )
			    ptr++;
			const int l2 = ptr - n2;

			fprintf(cf,
				"    { CMD_%s,%.*s\"%.*s\",%.*s\"%.*s\",%.*s0 },\n",
				info->c_name, (20-(int)strlen(info->c_name))/8, tabs,
				l1, n1, (20-l1)/8, tabs,
				l2, n2, (20-l2)/8, tabs );

			while ( *ptr == '|' )
			    ptr++;
		    }
		    else
			fprintf(cf, "    { CMD_%s,%.*s\"%.*s\",%.*s0,\t\t0 },\n",
				info->c_name, (20-(int)strlen(info->c_name))/8, tabs,
				l1, n1, (20-l1)/8, tabs );
		}
	    }
	    else if ( info->type == T_SEP_CMD )
		fprintf(hf,"\n");

	fprintf(cf,
		"\n    { CMD__N,0,0,0 }\n"
		"};\n"
		);
    }

    fprintf(hf,
	    "\n\tCMD__N // == %u\n\n"
	    "} enumCommands;\n"
	    , ctrl->n_cmd );


    //----- print options

    print_section(cf,sep1,"OptionShort & OptionLong");

    char * dest = iobuf;
    for ( info = ctrl->info; info < ctrl->end; info++ )
	if ( info->type & T_DEF_OPT && info->namelist[1] == '|' )
	{
	    *dest++ = info->namelist[0];
	    if ( info->type & F_OPT_OPTPARAM )
		*dest++ = ':';
	    if ( info->type & (F_OPT_OPTPARAM|F_OPT_PARAM) )
		*dest++ = ':';
	}
    *dest = 0;
    fprintf(cf,"const char OptionShort[] = \"%s\";\n\n",iobuf);
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const char OptionShort[];\n");

    ccp opt_buf[OPT_INDEX_SIZE];
    memset(opt_buf,0,sizeof(opt_buf));
    int getopt_idx = OPT_LONG_BASE;

    fprintf(cf,"const struct option OptionLong[] =\n{\n");
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const struct option OptionLong[];\n");

    for ( info = ctrl->info; info < ctrl->end; info++ )
	if ( info->type & T_DEF_OPT )
	{
	    ccp ptr = info->namelist;
	    const int pmode = (info->type & F_OPT_OPTPARAM)
				? 2
				: (info->type & F_OPT_PARAM)
					? 1
					: 0;

	    if ( info->namelist[1] == '|' )
	    {
		snprintf(iobuf,sizeof(iobuf),"%d, 0, '%c'",
			pmode, info->namelist[0] );
		ptr += 2;
		opt_buf[(u8)(info->namelist[0])] = info->c_name;
	    }
	    else
	    {
		snprintf(iobuf,sizeof(iobuf),"%d, 0, GO_%s",
			pmode, info->c_name );
		ASSERT_MSG( getopt_idx < OPT_INDEX_SIZE,
				"getopt_idx[%x] >= OPT_INDEX_SIZE[%x]\n",
				getopt_idx, OPT_INDEX_SIZE );
		opt_buf[(u8)(getopt_idx++)] = info->c_name;
	    }

	    int indent = 0;
	    while (*ptr)
	    {
		ccp start = ptr;
		while ( *ptr && *ptr != '|' )
		    ptr++;
		const int len = ptr - start;
		fprintf(cf,"\t%s{ \"%.*s\",%.*s%s },\n",
			indent ? " " : "", len, start, (26-len-indent)/8, tabs, iobuf );
		if (*ptr)
		    ptr++;
		indent = 1;
	    }
	}
    fprintf(cf,"\n\t{0,0,0,0}\n};\n");
    

    //----- print enumGetOpt

    print_section(hf,sep1,"enumGetOpt");
    fprintf(hf,"typedef enum enumGetOpt\n{");

    // add '?' temporary;
    ASSERT(!opt_buf['?']);
    opt_buf['?'] = "_ERR";
    
    static const int septab[] = { 0, '0', '9'+1, '?', '?'+1,
				  'A', 'Z'+1, 'a', 'z'+1,
				  OPT_LONG_BASE, OPT_INDEX_SIZE };
    const int * sepptr = septab;
    int i;
    for ( i = 0; i < OPT_INDEX_SIZE; i++ )
	if ( opt_buf[i] )
	{
	    if ( i >= *sepptr )
	    {
		fputc('\n',hf);
		while ( i >= *sepptr )
		    sepptr++;
	    }
	    if ( i < OPT_LONG_BASE )
		fprintf(hf,"\tGO_%s%.*s= '%c',\n",
			opt_buf[i], (28-(int)strlen(opt_buf[i]))/8, tabs, i );
	    else if ( i == OPT_LONG_BASE )
		fprintf(hf,"\tGO_%s%.*s= 0x%02x,\n",
			opt_buf[i], (28-(int)strlen(opt_buf[i]))/8, tabs, i );
	    else
		fprintf(hf,"\tGO_%s,\n",opt_buf[i]);
	}

    fprintf(hf,"\n} enumGetOpt;\n");
    opt_buf['?'] = 0;


    //----- print option index

    print_section(cf,sep1,"OptionUsed & OptionIndex");

    fprintf(cf,"u8 OptionUsed[OPT__N_TOTAL+1] = {0};\n\n");
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern u8 OptionUsed[OPT__N_TOTAL+1];\n");

    fprintf(cf,"const u8 OptionIndex[OPT_INDEX_SIZE] = \n{\n");
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const u8 OptionIndex[OPT_INDEX_SIZE];\n");

    for ( i = 0; i < OPT_INDEX_SIZE; )
    {
	int start = i;
	while ( i < OPT_INDEX_SIZE && !opt_buf[i] )
	    i++;
	int len = i - start;
	while ( len > 0 )
	{
	    const int now_len = len < 16 ? len : 16 - start % 16;
	    fprintf(cf,"\t/* 0x%02x   */\t %.*s\n",
		    start,
		    2*now_len + now_len/4,
		    "0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0," );
	    start += now_len;
	    len -= now_len;
	}
	    
	while ( i < OPT_INDEX_SIZE && opt_buf[i] )
	{
	    fprintf(cf,"\t/* 0x%02x %c */\tOPT_%s,\n",
		i, i > ' ' && i < 0x7f ? i : ' ', opt_buf[i]);
	    i++;
	}
    }
    fprintf(cf,"};\n");


    //----- option allowed

    if (ctrl->opt_allow_cmd)
    {
	print_section(cf,sep1,"opt_allowed_cmd_*");
	for ( info = ctrl->info; info < ctrl->end; info++ )
	{
	    if ( !( info->type & T_DEF_CMD ) )
		continue;

	    fprintf(cf,"static u8 option_allowed_cmd_%s[%u] = // cmd #%u\n{",
		info->c_name, ctrl->n_opt_specific, info->index );

	    int i;
	    u8 * ptr = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific;
	    for ( i = 0; i < ctrl->n_opt_specific; i++ )
		fprintf(cf, "%s%u%s",
			    !(i%30) ? "\n    " : !(i%10) ? "  " : !(i%5) ? " " : "",
			    ptr[i],
			    i < ctrl->n_opt_specific-1 ? "," : "" );

	    fprintf(cf,"\n};\n\n");
	}
    }

    //----- InfoCommand

    print_links(ctrl);
    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const InfoCommand_t CommandInfo[CMD__N+1];\n");

    //----- InfoUI

    print_section(cf,sep1,"InfoUI");

    var_ptr += snprintf(var_ptr,var_end-var_ptr,
		"extern const InfoUI_t InfoUI;\n");

    fprintf(cf,
	    "const InfoUI_t InfoUI =\n"
	    "{\n"
	    "\t\"%s\",\n"	// tool_name
	    "\t%s\n"		// n_cmd
	    "\t%s\n"		// cmd_tab
	    "\tCommandInfo,\n"	// cmd_info
	    "\t%s\n"		// n_opt_specific
	    "\tOPT__N_TOTAL,\n"	// n_opt_total
	    "\tOptionInfo,\n"	// opt_info
	    "\tOptionUsed,\n"	// opt_used
	    "\tOptionIndex,\n"	// opt_index
	    "\tOptionShort,\n"	// opt_short
	    "\tOptionLong\n"	// opt_long
	    "};\n",
	    ctrl->info->c_name,
	    ctrl->n_cmd ? "CMD__N," : "0, // n_cmd",
	    ctrl->n_cmd ? "CommandTab," : "0, // cmd_tab",
	    ctrl->n_cmd ? "OPT__N_SPECIFIC," : "0, // n_opt_specific" );


    //----- external vars

    print_section(hf,sep1,"external vars");
    fputs(var_buf,hf);


    //----- terminate

    print_section(cf,sep1,"END");
    print_section(hf,sep1,"END");
    fprintf(hf,"#endif // %s\n\n",guard);

    return ERR_OK;
};
Example #13
0
static void print_links ( control_t * ctrl )
{
    ASSERT(ctrl);
    FILE * cf = ctrl->cf;
    ASSERT(cf);

    print_section(cf,sep1,"InfoOption tabs");

    char * temp_param	= iobuf;
    char * temp_help	= iobuf +  sizeof(iobuf)/8;
    char * sum_beg	= iobuf + sizeof(iobuf)/2;
    char * sum_end	= iobuf + sizeof(iobuf);
    char * sum		= sum_beg;

    const info_t * info_cmd = ctrl->info;
    ASSERT ( info_cmd->type & T_DEF_TOOL );
    fprintf(cf,"const InfoOption_t * option_tab_tool[] =\n{\n");

    ctrl->n_cmd_opt	= 0;
    ctrl->need_sep	= false;

    print_links_iterator(ctrl,info_cmd,"def");
    fprintf(cf,"\n\t0\n};\n\n");

    DumpText(0,temp_param,iobuf+sizeof(iobuf),info_cmd->param,0,"");
    DumpText(0,temp_help,iobuf+sizeof(iobuf),info_cmd->help,0,"");
    sum += snprintf(sum,sum_end-sum,
			"    {\t0,\n"		// id
			"\tfalse,\n"		// hidden
			"\tfalse,\n"		// separator
			"\t\"%s\",\n"		// name1
			"\t0,\n"		// name2
			"%s,\n"			// param
			"%s,\n"			// help
			"\t%u,\n"		// n_opt
			"\toption_tab_tool,\n"	// opt
			"\t0\n"			// opt_allowed
			"    },\n\n"
			,info_cmd->c_name
			,temp_param
			,temp_help
			,ctrl->n_cmd_opt
			);
    
    bool separator = false;
    for ( info_cmd++; info_cmd < ctrl->end; info_cmd++ )
    {
	if ( info_cmd->type & T_SEP_CMD )
	    separator = true;
	//if ( !( info_cmd->type & T_DEF_CMD ) || info_cmd->type & F_HIDDEN )
	if ( !( info_cmd->type & T_DEF_CMD ) )
	    continue;

	fprintf(cf,"static const InfoOption_t * option_tab_cmd_%s[] =\n{\n",
		info_cmd->c_name);

	ctrl->n_cmd_opt	= 0;
	ctrl->need_sep	= false;
	ctrl->cmd_name	= info_cmd->c_name;
	ResetStringField(&ctrl->opt_done);

	const info_t * info;
	for ( info = info_cmd;  info < ctrl->end; info++ )
	    if ( info->type & T_CMD_BEG && !strcmp(info->c_name,info_cmd->c_name) )
	    {
		print_links_iterator(ctrl,info,"cmd");
		break;
	    }
	fprintf(cf,"\n\t0\n};\n\n");

	ccp name1 = info_cmd->namelist, ptr = name1;
	while ( *ptr && *ptr != '|' )
	    ptr++;
	const int len1 = ptr - name1;
	char name2[100] = "0";
	if ( *ptr == '|' )
	{
	    ccp n2 = ++ptr;
	    while ( *ptr && *ptr != '|' )
		ptr++;
	    if ( ptr > n2 )
		snprintf(name2,sizeof(name2),"\"%.*s\"",(int)(ptr-n2),n2);
	}
	
	DumpText(0,temp_param,iobuf+sizeof(iobuf),info_cmd->param,0,"");
	DumpText(0,temp_help,iobuf+sizeof(iobuf),info_cmd->help,0,"");
	sum += snprintf(sum,sum_end-sum,
			"    {\tCMD_%s,\n"		// id
			"\t%s,\n"			// hidden
			"\t%s,\n"			// separator
			"\t\"%.*s\",\n"			// name1
			"\t%s,\n"			// name2
			"%s,\n"				// param
			"%s,\n"				// help
			"\t%u,\n"			// n_opt
			"\toption_tab_cmd_%s,\n"	// opt
			"\toption_allowed_cmd_%s\n"	// opt_allowed
			"    },\n\n"
			,info_cmd->c_name
			,info_cmd->type & F_HIDDEN ? "true" : "false"
			,separator ? "true" : "false"
			,len1 ,name1
			,name2
			,temp_param
			,temp_help
			,ctrl->n_cmd_opt
			,info_cmd->c_name
			,info_cmd->c_name
			);
	separator = false;
    }

    print_section(cf,sep1,"InfoCommand");
    fprintf(cf,"const InfoCommand_t CommandInfo[CMD__N+1] =\n{\n");
    fputs(sum_beg,cf);
    fprintf(cf,"    {0,0,0,0,0,0,0,0,0}\n};\n");
}
Example #14
0
int main ( int argc, char ** argv )
{
    SetupLib(argc,argv,"gen-ui",PROG_UNKNOWN);

    static ccp def_null_name = "/dev/null";
    FILE * nf = fopen(def_null_name,"wb");
    if (!nf)
    {
	fprintf(stderr,"!!! Can't create file: %s\n",def_null_name);
	return ERR_CANT_CREATE;
    }

    static ccp def_fname = "src/ui/ui.def";
    FILE * df = fopen(def_fname,"wb");
    if (!df)
    {
	fprintf(stderr,"!!! Can't create file: %s\n",def_fname);
	return ERR_CANT_CREATE;
    }

    char fname[200];
    info_t * info = info_tab;

    while ( info->type != T_END )
    {
	if ( ! ( info->type & T_DEF_TOOL ) )
	{
	    fprintf(stderr,"!!! Missing T_DEF_TOOL entry.\n");
	    return ERR_SYNTAX;
	}

	control_t ctrl;
	memset(&ctrl,0,sizeof(ctrl));
	ctrl.df = nf;
	ctrl.opt_prefix = "";
	InitializeStringField(&ctrl.gopt);
	InitializeStringField(&ctrl.copt);
	InitializeStringField(&ctrl.opt_done);

	if ( !( info->type & F_HIDDEN ) )
	{
	    ctrl.df = df;
	    snprintf(iobuf,sizeof(iobuf),"Tool '%s'",info->c_name);
	    print_section(df,sep2,iobuf);
	    fprintf(df,"#:def_tool( \"%s\", \\\n",info->c_name);
	    DumpText(df,0,0,info->param,1,", \\\n");
	    DumpText(df,0,0,info->help,1," )\n\n");
	}

	snprintf(fname,sizeof(fname),"src/ui/ui-%s.c",info->c_name);
	ctrl.cf = fopen(fname,"wb");
	if (!ctrl.cf)
	{
	    fprintf(stderr,"!!! Can't create file: %s\n",fname);
	    return ERR_CANT_CREATE;
	}

	snprintf(fname,sizeof(fname),"src/ui/ui-%s.h",info->c_name);
	ctrl.hf = fopen(fname,"wb");
	if (!ctrl.hf)
	{
	    fprintf(stderr,"!!! Can't create file: %s\n",fname);
	    return ERR_CANT_CREATE;
	}

	ctrl.info = info++;
	while ( ! ( info->type & (T_END|T_DEF_TOOL)) )
	{
	    if ( info->type & T_DEF_OPT )
	    {
		if ( info->type & F_OPT_GLOBAL )
		{
		    InsertStringField(&ctrl.gopt,info->c_name,false);
		    ++ctrl.n_opt;
		    //opt_index = 0 for global options
		}
		else
		{
		    InsertStringField(&ctrl.copt,info->c_name,false);
		    info->index = ++ctrl.n_opt_specific;
		}

		if ( !info->help )
		{
		    // copy 'param' and 'help' info from previous tool
		    const info_t * search;
		    for ( search = info; search >= info_tab; search-- )
			if ( search->type & T_DEF_OPT
			    && search->help
			    && !strcmp(search->c_name,info->c_name) )
			{
			    info->help  = search->help;
			    if (!info->param)
				info->param = search->param;
			    break;
			}
		}

		if ( !( info->type & F_HIDDEN ) )
		{
		    fprintf(ctrl.df,"#:def_opt( \"%s\", \"%s\", \"%s%s%s%s%s\", \\\n",
			info->c_name, info->namelist,
			info->type & F_OPT_COMMAND  ? "C" : "",
			info->type & F_OPT_GLOBAL   ? "G" : "",
			info->type & F_OPT_MULTIUSE ? "M" : "",
			info->type & F_OPT_PARAM    ? "P" : "",
			info->type & F_OPT_OPTPARAM ? "O" : "" );
		    DumpText(ctrl.df,0,0,info->param,1,", \\\n");
		    DumpText(ctrl.df,0,0,info->help,1," )\n\n");
		}
	    }
	    else if ( info->type & T_DEF_CMD )
	    {
		info->index = ++ctrl.n_cmd;

		if ( !info->help )
		{
		    // copy 'param' and 'help' info from previous tool
		    const info_t * search = info-1;
		    for ( search = info; search >= info_tab; search-- )
			if ( search->type & T_DEF_CMD
			    && search->help
			    && !strcmp(search->c_name,info->c_name) )
			{
			    info->help  = search->help;
			    if (!info->param)
				info->param = search->param;
			    break;
			}
		}

		if ( !( info->type & F_HIDDEN ) )
		{
		    fprintf(ctrl.df,"#:def_cmd( \"%s\", \"%s\", \\\n",
			info->c_name, info->namelist );
		    DumpText(ctrl.df,0,0,info->param,1,", \\\n");
		    DumpText(ctrl.df,0,0,info->help,1," )\n\n");
		}
	    }
	    else if ( info->type & T_GRP_BEG )
		info->index = ctrl.n_grp++; // NULL based
	    else if ( info->type & (T_CMD_OPT|T_CMD_BEG|T_COPY_GRP|T_COPY_CMD) )
	    {
		const int type	= info->type & T_CMD_OPT  ? T_DEF_OPT
				: info->type & T_COPY_GRP ? T_GRP_BEG
				: T_DEF_CMD;
			    
		const info_t * search;
		for ( search = ctrl.info; search < info; search++ )
		    if ( search->type & type
			&& !strcmp(search->c_name,info->c_name) )
		    {
			//PRINT("COPY INDEX #%x: %s\n",info->type,info->c_name);
			info->index = search->index;
			break;
		    }
	    }

	    info++;
	}
	ctrl.end = info;

	if (ctrl.n_cmd)
	    ctrl.n_cmd++; // one more for CMD_NONE;

	if (ctrl.n_opt_specific)
	    ctrl.n_opt += ++ctrl.n_opt_specific;

	TRACE("N: cmd=%u, grp=%u, opt=%d/%d\n",
		ctrl.n_cmd, ctrl.n_grp, ctrl.n_opt_specific, ctrl.n_opt );
	const enumError err = Generate(&ctrl);

	fclose(ctrl.cf);
	fclose(ctrl.hf);
	ResetStringField(&ctrl.gopt);
	ResetStringField(&ctrl.copt);
	ResetStringField(&ctrl.opt_done);

	if (err)
	    return err;
    }

    AddTables(df);
    print_section(df,sep2,"END");
    fclose(df);
    fclose(nf);
    CloseAll();
    return ERR_OK;
}
Example #15
0
File: showq.c Project: fasrc/showq
/* Main routine. */
int main(int argc, char **argv) {
 	struct numq nq; /* Struct for passing information between routines */
  	int c; /* Used for holding information passed in from the command line */
  	char *user = "******", *queue=NULL, *hosts=NULL; /* Pointers to the information we are querying */
  	int i, def; /* counters */


  	/* Initialize Default Flag and structs*/
  	def=1;
  	nq.cores=0;
  	nq.nodes=0;

	/* Read in and interpret command line options */
  	while (1) {
      		static struct option long_options[] =
		{
	  		/* These options set a flag. */
	  		{"help", no_argument,0, 'h'},
	  		{"q",  required_argument, 0, 'q'},
	  		{"u",  required_argument, 0, 'u'},
	  		{"n",  required_argument, 0, 'n'},
	  		{0, 0, 0, 0}
		};
      		/* Get information from command line */
      		int option_index = 0;
     
      		c = getopt_long (argc, argv, "u:q:n:help",long_options, &option_index);
     
      		/* Detect the end of the options. */
      		if (c == -1) break;

		/* Check what options we are using */
      
      		/* Default Flag set to false, we are actually passing options so the default is not used */
      		def=0;

      		switch (c) {
		case 0:
	  		/* If this option set a flag, do nothing else now. */
	  		if (long_options[option_index].flag != 0) break;
	  		printf ("option %s", long_options[option_index].name);
	  		if (optarg) printf (" with arg %s", optarg);
	  		printf ("\n");
	  		break;

		case 'q':
	  		queue = optarg;
	  		break;
	  
		case 'u':
	  		user = optarg;
	  		break;

		case 'n':
	  		hosts = optarg;
	  		break;

		case '?':
	  		/* This section handles when getopt_long is confused about what you are passing it */
	  		/* getopt_long already printed an error message. */
	  		exit(-1);

		case 'h':
	  		/* Displays this help page then exits */
	  		printf("Welcome to the Help Section.\n");
	  		printf("Showq provides an overview of the cluster and LSF queues in a similar way to showq in PBS.Torque.\n");
	  		printf("By default showq will show you your running, pending and suspended jobs plus an overview of the cluster.\n");
	  		printf("Depending on cluster activity this command could take a few minutes to complete.\n");
	  		printf("Each job has several fields which are listed below.\n");
	  		printf("\n");
	  		printf("JOBID           The LSF job id.\n");
	  		printf("\n");
	  		printf("USER            The name of the user.\n");
	  		printf("\n");
	  		printf("STAT            The current job state.  RUN if it is running, PEND if it is pending,\n");
	  		printf("                PSUSP if suspended by the owner or admin,\n");
	  		printf("                SSUSP if suspended due to host being overloaded or queue run window closure.\n");
	  		printf("\n");
	  		printf("QUEUE           The LSF queue the job was submitted from.\n");
	  		printf("\n");
	  		printf("CORES/NODES     This lists the number of cores used by the process followed by the number of nodes after the /.\n");
	  		printf("                Additionally if the job is running in Exclusive mode a X appears next to the node count.\n");
	  		printf("\n");
	  		printf("TIME REMAINING  The amount of time remaining on this run.  This is based off of the queue run time limit\n");
	  		printf("                or if the user defines a run time using BSUB -W it will use that.  Jobs that overrun\n");
	  		printf("                the a time limit show up with negative time equal to the amount they have overrun.\n");
	  		printf("                Jobs from queues with no time limit and no user defined limit show up as negative as well.\n");
	  		printf("                The value in that case is just the negative value of the time the job has run for.\n");
	  		printf("\n");
	  		printf("SUBMIT TIME     The time at which the job was submitted to the queue.\n");
	  		printf("\n");
	  		printf("START TIME      The time at which the job started running.\n"); 
	  		printf("\n");
	  		printf("Additional Usage options are as below.\n");
	  		printf("\n");
	  		printf("-help           Gets you to this convenient help page.\n");
	  		printf("\n");
	  		printf("-q queue_name   Shows you what is going on in that queue currently.\n");
	  		printf("\n");
	  		printf("-u user_name    Shows the jobs current associated with that user.\n");
	  		printf("                By default this is set to all if -n or -q is used other wise it is set to the current user.\n");
	  		printf("                If -u is used in tandem with -q it will show only the jobs running on that queue for that user.\n");
	  		printf("\n");
	  		printf("-n host_name    Shows what is going on for this host or group of hosts.  Does not show pending jobs for these hosts.\n");
	  		exit(-1);
	  
		default:
	  		abort ();
		}
	}

  	/* Sets what will happen when the default flag is set */
  	/* In this case it will simply return what jobs belong to the user and the node summary */
  	if (def) user = NULL;
  
  	/* initialize LSBLIB  and  get  the  configuration environment */
	if (lsb_init(argv[0]) < 0) {
    		lsb_perror("simbjobs: lsb_init() failed");
    		exit(-1);
  	}

	/* Query about the following information */
  	printf("ACTIVE JOBS-------------\n");
  	nq = print_section(RUN_JOB, queue, user, hosts, nq.cores, nq.nodes);

  	printf("\nSUSPENDED JOBS-------------\n");
  	nq = print_section(SUSP_JOB, queue, user, hosts, nq.cores, nq.nodes);

  	printf("\n");
  	print_summary(queue, user, hosts, nq.cores, nq.nodes);

  	printf("\n");
  	printf("PENDING JOBS-------------\n");
  	nq = print_section(PEND_JOB, queue, user, hosts, nq.cores, nq.nodes);

  	/* when finished to display the job info, close the connection to the mbatchd */
	lsb_closejobinfo();
  
	exit(0);
}
Example #16
0
void print_test_pages(RDArsrc *parent,HoldReport *h)
{
	int z,y;
	RDAdisplay *d;
	RDArunrpt *rrpt;
	RDAreport *rpt;
	RDAcontrol *c;
	char *temp=NULL;

#ifdef USE_RDA_DIAGNOSTICS
	if(diagrptgen || diagrptgen_field)
	{
		prterr("DIAG print_test_pages Printing Test Pages for Alignment.");
	}
#endif /* ifdef USE_RDA_DIAGNOSTICS */
	rrpt=h->rrpt;
	rpt=h->rpt;
	d=rpt->display;
	rrpt->pageno=0;
	rrpt->page_count=(int)d->page_length*72;
	if(rrpt->curfont!=NULL) Rfree(rrpt->curfont);
	rrpt->curfont=NULL;
	if(rrpt->longfont!=NULL) Rfree(rrpt->longfont);
	rrpt->longfont=NULL;
	rrpt->curpoints=0;
	rrpt->curpitch=0;
	rrpt->points=0;
	rrpt->startline=FALSE;
	rrpt->pitch=0;
	rrpt->forced=FALSE;
	rrpt->body_count=0;
	rrpt->numlines=0;
	if(d->device==0 || d->device==5)
	{
		rrpt->pfile=RDA_popen(d->set_lpp,"w");
		rrpt->fp=NULL;
	} else {
		rrpt->pfile=NULL;
		if(d->device==1)
		{
			rrpt->fp=fopen(d->set_lpp,"w");
		} else {
			rrpt->fp=fopen(d->set_lpp,"a+");
		}
	}
	if(rrpt->pfile==NULL && rrpt->fp==NULL)
	{
		prterr("Error Couldn't open device [%s].",d->set_lpp);
		return;
	}
	while(rrpt->pageno<d->test_pages)
	{
		if(rpt->control!=NULL)
		{
			for(y=rpt->numcontrols;y>0;--y)
			{
				c=rpt->control+(y-1);
				temp=Rmalloc(RDAstrlen(c->name)+8);
				sprintf(temp,"%s HEADER",c->name);
				print_section(rrpt,rpt,temp,TRUE);
			}
		}
		if(rpt->display->body_count==0)
		{
				print_section(rrpt,rpt,"DETAIL LINES",TRUE);
		} else {
			for(z=0;z<rpt->display->body_count;++z)
			{
				print_section(rrpt,rpt,"DETAIL LINES",TRUE);
				++rrpt->body_count;
			}
		}
		if(rpt->control!=NULL)
		{
			for(y=rpt->numcontrols;y>0;--y)
			{
				c=rpt->control+(y-1);
				temp=Rmalloc(RDAstrlen(c->name)+8);
				sprintf(temp,"%s FOOTER",c->name);
				print_section(rrpt,rpt,temp,TRUE);
				if(rrpt->body_count>0) rrpt->body_count=0;
			}
		}
		if(rpt->display->page_length>0.0)
		{
			rrpt->forced=TRUE;
			print_section(rrpt,rpt,"PAGE FOOTER",TRUE);
			rrpt->forced=FALSE;
		}
		rrpt->body_count=0;
	}
	RDA_pclose(rrpt->pfile);
	rrpt->pageno=0;
	rrpt->page_count=(int)d->page_length*72;
	if(rrpt->curfont!=NULL) Rfree(rrpt->curfont);
	rrpt->curfont=NULL;
	if(rrpt->longfont!=NULL) Rfree(rrpt->longfont);
	rrpt->longfont=NULL;
	rrpt->curpoints=0;
	rrpt->curpitch=0;
	rrpt->points=0;
	rrpt->startline=FALSE;
	rrpt->pitch=0;
	rrpt->forced=FALSE;
	rrpt->body_count=0;
	rrpt->numlines=0;
}
Example #17
0
int
main(int argc, char *argv[]) {
	int ch, i, gai_error;
	struct addrinfo hints, *res;
	isc_textregion_t tr;
	dns_client_t *client = NULL;
	isc_result_t result;
	isc_sockaddr_t sa;
	dns_message_t *qmessage, *rmessage;
	dns_rdatatype_t type = dns_rdatatype_a;
	isc_buffer_t *outputbuf;

	while ((ch = getopt(argc, argv, "t:")) != -1) {
		switch (ch) {
		case 't':
			tr.base = optarg;
			tr.length = strlen(optarg);
			result = dns_rdatatype_fromtext(&type, &tr);
			if (result != ISC_R_SUCCESS) {
				fprintf(stderr,
					"invalid RRtype: %s\n", optarg);
				exit(1);
			}
			break;
		default:
			usage();
		}
	}

	argc -= optind;
	argv += optind;
	if (argc < 2)
		usage();

	isc_lib_register();
	result = dns_lib_init();
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "dns_lib_init failed: %d\n", result);
		exit(1);
	}

	result = dns_client_create(&client, 0);
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "dns_client_create failed: %d\n", result);
		exit(1);
	}

	/* Prepare message structures */
	mctx = NULL;
	qmessage = NULL;
	rmessage = NULL;

	result = isc_mem_create(0, 0, &mctx);
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "failed to create a memory context\n");
		exit(1);
	}
	result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage);
	if (result == ISC_R_SUCCESS) {
		result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE,
					    &rmessage);
	}
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "failed to create messages\n");
		exit(1);
	}

	/* Initialize the nameserver address */
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_protocol = IPPROTO_UDP;
	hints.ai_flags = AI_NUMERICHOST;
	gai_error = getaddrinfo(argv[0], "53", &hints, &res);
	if (gai_error != 0) {
		fprintf(stderr, "getaddrinfo failed: %s\n",
			gai_strerror(gai_error));
		exit(1);
	}
	INSIST(res->ai_addrlen <= sizeof(sa.type));
	memcpy(&sa.type, res->ai_addr, res->ai_addrlen);
	freeaddrinfo(res);
	sa.length = res->ai_addrlen;
	ISC_LINK_INIT(&sa, link);

	/* Construct qname */
	result = make_querymessage(qmessage, argv[1], type);
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "failed to create a query\n");
		exit(1);
	}

	/* Send request and wait for a response */
	result = dns_client_request(client, qmessage, rmessage, &sa, 0, 0,
				    NULL, 60, 0, 3);
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "failed to get a response: %s\n",
			dns_result_totext(result));
	}

	/* Dump the response */
	outputbuf = NULL;
	result = isc_buffer_allocate(mctx, &outputbuf, 65535);
	if (result != ISC_R_SUCCESS) {
		fprintf(stderr, "failed to allocate a result buffer\n");
		exit(1);
	}
	for (i = 0; i < DNS_SECTION_MAX; i++) {
		print_section(rmessage, i, outputbuf);
		isc_buffer_clear(outputbuf);
	}
	isc_buffer_free(&outputbuf);

	/* Cleanup */
	dns_message_destroy(&qmessage);
	dns_message_destroy(&rmessage);
	isc_mem_destroy(&mctx);
	dns_client_destroy(&client);
	dns_lib_shutdown();

	exit(0);
}
Example #18
0
int main(int argc, char *argv[])
{
	int fd;
	int exit_code = EXIT_SUCCESS;
	struct stat st;
	unsigned int size;
	uint8_t *buffer;
	uint8_t *buffer_iterator;
	struct actions_firmware_header header;
	struct actions_firmware_section section;
	unsigned int i = 0;
	int ret = 1;
	int err = 0;
	int dump = 1;
	const char *path_prefix;

	if (argc != 3) {
		usage(argv[0]);
		exit(1);
	}

	path_prefix = argv[2];
	err = mkdir(path_prefix, 0755);
	if (err < 0) {
		perror("mkdir");
		exit_code = EXIT_FAILURE;
		goto out;
	}

	fd = open(argv[1], O_RDONLY);
	if (fd < 0) {
		perror("open");
		exit_code = EXIT_FAILURE;
		goto out;
	}
	if (fstat(fd, &st) < 0) {
		perror("fstat");
		exit_code = EXIT_FAILURE;
		goto out_close_fd;
	}
	size = st.st_size;

	buffer = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
	if (buffer == NULL) {
		perror("mmap");
		exit_code = EXIT_FAILURE;
		goto out_close_fd;
	}

	if (size < ACTIONS_HEADER_DISK_SIZE) {
		fprintf(stderr, "File cannot contain an Actions firmware header.\n");
		exit_code = EXIT_FAILURE;
		goto out_munmap;
	}

	/* iterate over a copy of the pointer */
	buffer_iterator = buffer;

	err = parse_header(&buffer_iterator, &header);
	if (err) {
		fprintf(stderr, "Cannot parse the header.\n");
		exit_code = EXIT_FAILURE;
		goto out_munmap;
	}

	print_header(&header);

	while((err = parse_section(&buffer_iterator, &section)) == 0) {
		print_section(&section);
		i++;

		if (strncmp((char *)section.name, "FIRM", 16) == 0) {
			uint8_t *firm_buffer_iterator = buffer + section.start_address + 0x200;
			struct actions_firmware_section firm_section;
			struct actions_firmware_section prev_section = {
				.start_address = section.start_address + 0x2000,
				.length = 0,
			};
			while((err = parse_section(&firm_buffer_iterator, &firm_section)) == 0) {

				/*
				 * unknown1 seems to be some form of checksum for
				 * firm sections, if a sections have the same
				 * checksum of the previous on they are not
				 * duplicated but refer to the same memory
				 * region, so do not increase che start
				 * address
				 */
				if (firm_section.unknown1 == prev_section.unknown1) {
					firm_section.start_address = prev_section.start_address;
				} else {
					firm_section.start_address = prev_section.start_address + prev_section.length;
				}

				printf("\t");
				print_section(&firm_section);

				if (dump)
					dump_section(path_prefix, "FIRM_", buffer, &firm_section);

				prev_section = firm_section;
			}
		} else if (strncmp((char *)section.name, "LINUX", 16) == 0) {
			continue;
		}

		if (dump)
			dump_section(path_prefix, "", buffer, &section);

	}