コード例 #1
0
ファイル: pubkey2c.c プロジェクト: kzlin129/tt-gpl
static void print_structs( FILE *fd, int count )
{
	int i; 
	fprintf(fd, "static struct _mpi const\n");

	print_struct(fd, "p", "P", count); 
	print_struct(fd, "q", "Q", count); 
	print_struct(fd, "g", "G", count); 
	print_struct(fd, "y", "Y", count); 

	fprintf(fd, "*const base[][3] = {");
	for (i = 0; i < count; i++)
		fprintf(fd, "{ &g[%d], &y[%d], NULL},", i, i);
	fprintf(fd,"}; \n");
}
コード例 #2
0
ファイル: b.c プロジェクト: ythunder/thunder
int main()
{
	struct student s[3]={ {10000,"zhang",'m',21,"shang hai"},
				{10001,"li",'f',20,"bei jing"},
				{10002,"liu",'m',22,"guang dong"} };
	printf("%d,%d,%d\n",s[0].age,s[1].age,s[2].age);
 	struct student *p;
	for(p=s;p<s+3;p++)
	print_struct(p);
	printf("%d,%d,%d\n",s[0].age,s[1].age,s[2].age);
	return 0;
}
コード例 #3
0
ファイル: gff.c プロジェクト: trieck/source
/* print structs */
void print_structs(void)
{
    Struct s;
    unsigned i;

    if (header.StructCount == 0)
        error("gff must contain a top-level struct.\n");

    /* seek to struct offset */
    if (fseek(fp, header.StructOffset, SEEK_SET) != 0) {
        error("unable to seek to struct array.\n");
    }

    /* read top-level struct */
    if (!fread(&s, sizeof(Struct), 1, fp)) {
        error("unable to read top-level struct.\n");
    }

    /* ensure valid top-level struct */
    if (s.Type != GFF_TOPLEVEL_STRUCTID) {
        error("top level struct expected type 0x%.8x.\n",
              GFF_TOPLEVEL_STRUCTID);
    }

    printf("\nSTRUCTS\n_______\n\n");
    printf("Struct #1\n");
    print_struct(&s);

    /* print structs */
    for (i = 1; i < header.StructCount; i++) {
        if (!fread(&s, sizeof(Struct), 1, fp)) {
            error("unable to read struct.\n");
        }
        printf("\n");
        printf("\nStruct #%d\n", i+1);
        print_struct(&s);
    }
}
コード例 #4
0
static void
switch_on_type(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
{
	boolean_t allocated = B_FALSE;

	if (format == NULL) {
		allocated = B_TRUE;
		format = uc(mlp->name);
	}

	switch (tdp->type) {
	case INTRINSIC:
		print_intrinsic(mlp, tdp, format, level);
		break;
	case POINTER:
		print_pointer(mlp, tdp, format, level);
		break;
	case ARRAY:
		print_array(mlp, tdp, format, level);
		break;
	case FUNCTION:
		print_function(mlp, tdp, format, level);
		break;
	case UNION:
		print_union(mlp, tdp, format, level);
		break;
	case ENUM:
		print_enum(mlp, tdp, format, level);
		break;
	case FORWARD:
		print_forward(mlp, tdp, format, level);
		break;
	case TYPEOF:
		print_typeof(mlp, tdp, format, level);
		break;
	case STRUCT:
		print_struct(mlp, tdp, format, level);
		break;
	case VOLATILE:
		print_volatile(mlp, tdp, format, level);
		break;
	default:
		fprintf(stderr, "Switch to Unknown type\n");
		error = B_TRUE;
		break;
	}
	if (allocated)
		free(format);
}
コード例 #5
0
ファイル: copy.c プロジェクト: HKNTutorials/memory-intro
/**
 * Print out Sesame Street letters and numbers of the day, making
 * sure to delete your memory when you're done with it.
 *
 * This code asks for a day, letter, and number, and then prints
 * them out as "<day> is sponsored by the letter <letter> and the number <number>"
 *
 * this code should work, but doesn't because some of the helper
 * functions are broken.
 */
int main() {
    sponsorships *temp_day, *today;
    temp_day = init_day();
    today = init_day();

    printf("day letter number: ");
    scanf("%s %c %d", temp_day->day, &(temp_day->letter), &(temp_day->number));

    copy_struct(today, temp_day);
    destroy(temp_day);

    print_struct(today);
    destroy(today);

    return 0;
}
コード例 #6
0
ファイル: LFSCProof.cpp プロジェクト: clconway/cvc3-debian
void LFSCProof::print_structure( std::ostream& s, int ind ){
  LFSCProof* p = rplProof ? rplProof : lambdaPrintMap[this];
  if( p ){
    p->print( s, ind );
  }else{
    indent( s, ind );
    if( lambdaMap.find( this )!=lambdaMap.end() && printCounter>0 ){
      //just a warning, print it out in ose
      print_warning( "ERROR: printing out lambda abstracted proof more than once" );
#ifdef IGNORE_PRINT_MULTI_LAMBDA
      return;
#endif
    }
    printCounter++;
    print_struct( s, ind );
  }
}
コード例 #7
0
ファイル: moca.c プロジェクト: chubbymaggie/MOCA
// Handle allocation (retrieve backtrace and print it to output file
void handle_alloc(size_t sz, int *addr, char *prefix)
{
    if(sz < PAGE_SIZE)
        return;
    void *array[MAXSTACKSIZE];
    size_t size;
    char **strings;
    size_t i=0;

    size = backtrace (array, MAXSTACKSIZE);
    strings = backtrace_symbols (array, size);
    char *newstring=ShortCallStack(strings,size);

    print_struct(newstring+1/*ignore starting '/'*/,prefix,(unsigned long)addr,sz);
    free (strings);
    free(newstring);
}
コード例 #8
0
ファイル: gff.c プロジェクト: trieck/source
/* print a List */
void print_list(Field *field)
{
    unsigned i, size, index;
    int offset;
    Struct s;

    /* a List is a list of Structs whose members are indices into
     * the Struct array. Unlike most of the complex Field data types,
     * a List Field's data is located not in the Field Data Block,
     * but in the List Indices Array.  The starting address of a List
     * is specified in its Field's DataOrDataOffset value as a byte offset
     * element.
     */
    offset = header.ListIndicesOffset + field->DataOrDataOffset;
    if (fseek(fp, offset, SEEK_SET) != 0) {
        error("unable to seek into list data.\n");
    }

    if (!fread(&size, sizeof(unsigned int), 1, fp)) {
        error("unable to read list size.\n");
    }

    printf("\nSTRUCTS\n_______\n\n");

    for (i = 0; i < size; i++) {
        if (!fread(&index, sizeof(unsigned int), 1, fp)) {
            error("unable to read list index.\n");
        }

        fppush();

        offset = header.StructOffset + index * sizeof(Struct);
        if (fseek(fp, offset, SEEK_SET) != 0) {
            error("unable to seek into Struct array.\n");
        }

        if (!fread(&s, sizeof(Struct), 1, fp)) {
            error("unable to read struct.\n");
        }

        printf("\nStruct #%d\n", i+1);
        print_struct(&s);

        fppop();
    }
}
コード例 #9
0
ファイル: gencfile.C プロジェクト: bougyman/sfs
static void
dumpprint (const rpc_sym *s)
{
  switch (s->type) {
  case rpc_sym::STRUCT:
    print_struct (s->sstruct.addr ());
    break;
  case rpc_sym::UNION:
    print_union (s->sunion.addr ());
    break;
  case rpc_sym::ENUM:
    print_enum (s->senum.addr ());
    break;
  case rpc_sym::TYPEDEF:
    print_print (s->stypedef->id);
  default:
    break;
  }
}
コード例 #10
0
ファイル: gff.c プロジェクト: trieck/source
/* print complex field struct */
void print_cstruct(Field *field)
{
    int offset;
    Struct s;

    /* Unlike most of the complex Field data types, a Struct Field's data
     * is located not in the Field Data Block, but in the Struct Array.
     * Normally, a Field's DataOrDataOffset value would be a byte offset
     * into the Field Data Block, but for a Struct, it is an index into
     * the Struct Array
     */
    offset = header.StructOffset + field->DataOrDataOffset * sizeof(Struct);
    if (fseek(fp, offset, SEEK_SET) != 0) {
        error("unable to seek into struct array.\n");
    }

    if (!fread(&s, sizeof(Struct), 1, fp)) {
        error("unable to read struct.\n");
    }

    print_struct(&s);
}
コード例 #11
0
ファイル: moca.c プロジェクト: chubbymaggie/MOCA
int get_structs(const char* file, unsigned long offset)
{
    Elf *elf;                       /* Our Elf pointer for libelf */
    Elf_Scn *scn=NULL;                   /* Section Descriptor */
    Elf_Data *edata=NULL;                /* Data Descriptor */
    GElf_Sym sym;			/* Symbol */
    GElf_Dyn dyn;			/* Dynamic */
    GElf_Shdr shdr;                 /* Section Header */


    int fd; 		// File Descriptor
    char *base_ptr;		// ptr to our object in memory
    struct stat elf_stats;	// fstat struct
    printf("Retrieving structures for file '%s' at offset %lu\n",file, offset);

    if((fd = open(file, O_RDONLY)) == ERR)
    {
        fprintf(stderr,"Unable to open: '%s'\n", file);
        return ERR;
    }

    if((fstat(fd, &elf_stats)))
    {
        fprintf(stderr,"Unable to fstat: '%s'\n", file);
        close(fd);
        return ERR;
    }

    if((base_ptr = (char *) malloc(elf_stats.st_size)) == NULL)
    {
        fprintf(stderr,"Unable to malloc: '%lu'\n", elf_stats.st_size);
        close(fd);
        return ERR;
    }

    if((read(fd, base_ptr, elf_stats.st_size)) < elf_stats.st_size)
    {
        fprintf(stderr,"Unable to read fstat: '%s'\n", file);
        free(base_ptr);
        close(fd);
        return ERR;
    }

    /* Check libelf version first */
    if(elf_version(EV_CURRENT) == EV_NONE)
    {
        fprintf(stderr,"Elf library is out of date\n");
        close(fd);
        return ERR;
    }

    elf = elf_begin(fd, ELF_C_READ, NULL);	// Initialize 'elf' pointer to our file descriptor

    elf = elf_begin(fd, ELF_C_READ, NULL);

    int symbol_count;
    int i;

    while((scn = elf_nextscn(elf, scn)) != NULL)
    {
        gelf_getshdr(scn, &shdr);
        // Get the symbol table
        if(shdr.sh_type == SHT_SYMTAB)
        {
            // edata points to our symbol table
            edata = elf_getdata(scn, edata);
            // how many symbols are there? this number comes from the size of
            // the section divided by the entry size
            symbol_count = shdr.sh_size / shdr.sh_entsize;
            // loop through to grab all symbols
            for(i = 0; i < symbol_count; i++)
            {
                // libelf grabs the symbol data using gelf_getsym()
                gelf_getsym(edata, i, &sym);
                // Keep only objects big enough
                if(ELF32_ST_TYPE(sym.st_info)==STT_OBJECT &&
                        sym.st_size >= PAGE_SIZE)
                {
                    print_struct("NA",elf_strptr(elf, shdr.sh_link, sym.st_name),
                            sym.st_value+offset, sym.st_size);
                }
            }
        }
    }
    return 0;
}
コード例 #12
0
ファイル: smbios.c プロジェクト: fdotli/illumos-gate
int
main(int argc, char *argv[])
{
	const char *ifile = NULL;
	const char *ofile = NULL;
	int oflags = 0;

	smbios_hdl_t *shp;
	smbios_struct_t s;
	int err, fd, c;
	char *p;

	if ((p = strrchr(argv[0], '/')) == NULL)
		g_pname = argv[0];
	else
		g_pname = p + 1;

	while (optind < argc) {
		while ((c = getopt(argc, argv, "Bei:Ost:w:xZ")) != EOF) {
			switch (c) {
			case 'B':
				oflags |= SMB_O_NOCKSUM | SMB_O_NOVERS;
				break;
			case 'e':
				opt_e++;
				break;
			case 'i':
				opt_i = getu16("struct ID", optarg);
				break;
			case 'O':
				opt_O++;
				break;
			case 's':
				opt_s++;
				break;
			case 't':
				if (isdigit(optarg[0]))
					opt_t = getu16("struct type", optarg);
				else
					opt_t = getstype("struct type", optarg);
				break;
			case 'w':
				ofile = optarg;
				break;
			case 'x':
				opt_x++;
				break;
			case 'Z':
				oflags |= SMB_O_ZIDS; /* undocumented */
				break;
			default:
				return (usage(stderr));
			}
		}

		if (optind < argc) {
			if (ifile != NULL) {
				(void) fprintf(stderr, "%s: illegal "
				    "argument -- %s\n", g_pname, argv[optind]);
				return (SMBIOS_USAGE);
			}
			ifile = argv[optind++];
		}
	}

	if ((shp = smbios_open(ifile, SMB_VERSION, oflags, &err)) == NULL) {
		(void) fprintf(stderr, "%s: failed to load SMBIOS: %s\n",
		    g_pname, smbios_errmsg(err));
		return (SMBIOS_ERROR);
	}

	if (ofile != NULL) {
		if ((fd = open(ofile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
			(void) fprintf(stderr, "%s: failed to open %s: %s\n",
			    g_pname, ofile, strerror(errno));
			err = SMBIOS_ERROR;
		} else if (smbios_write(shp, fd) != 0) {
			(void) fprintf(stderr, "%s: failed to write %s: %s\n",
			    g_pname, ofile, smbios_errmsg(smbios_errno(shp)));
			err = SMBIOS_ERROR;
		}
		smbios_close(shp);
		return (err);
	}

	if (opt_e) {
		print_smbios(shp, stdout);
		smbios_close(shp);
		return (SMBIOS_SUCCESS);
	}

	if (opt_O && (opt_i != -1 || opt_t != -1))
		opt_O++; /* -i or -t imply displaying obsolete records */

	if (opt_i != -1)
		err = smbios_lookup_id(shp, opt_i, &s);
	else
		err = smbios_iter(shp, print_struct, stdout);

	if (err != 0) {
		(void) fprintf(stderr, "%s: failed to access SMBIOS: %s\n",
		    g_pname, smbios_errmsg(smbios_errno(shp)));
		smbios_close(shp);
		return (SMBIOS_ERROR);
	}

	if (opt_i != -1)
		(void) print_struct(shp, &s, stdout);

	smbios_close(shp);
	return (SMBIOS_SUCCESS);
}