void showStructArray(struct Student *a[5])
{
	int i = 0;
	while (i < 5) {
		showStruct(*a[i]);
		i = i + 1;
	}
}
Exemple #2
0
static PyObject *__pyx_pf_13cython_struct_test_struct(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  myStruct __pyx_v_mst;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("test_struct");
  __pyx_self = __pyx_self;

  /* "cython_struct.pyx":10
 * def test_struct():
 *     cdef myStruct mst
 *     initStruct(&mst)             # <<<<<<<<<<<<<<
 *     showStruct(&mst)
 *     return mst
 */
  initStruct((&__pyx_v_mst));

  /* "cython_struct.pyx":11
 *     cdef myStruct mst
 *     initStruct(&mst)
 *     showStruct(&mst)             # <<<<<<<<<<<<<<
 *     return mst
 * 
 */
  showStruct((&__pyx_v_mst));

  /* "cython_struct.pyx":12
 *     initStruct(&mst)
 *     showStruct(&mst)
 *     return mst             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_convert__to_py_myStruct(__pyx_v_mst); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cython_struct.test_struct", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
Exemple #3
0
int
Cast(int argc,char *argv[])
{
	long	flags;
	int		opt, tfd, index;
	char	*structtype, *structfile, *tablename, *linkname, *name;

	flags = 0;
	name = (char *)0;
	linkname = (char *)0;
	tablename = (char *)0;
	while((opt=getopt(argc,argv,"apl:n:t:")) != -1) {
		switch(opt) {
		case 'a':
			flags |= STRUCT_SHOWADD;
			break;
		case 'l':
			linkname = optarg;
			break;
		case 'n':
			name = optarg;
			break;
		case 'p':
			flags |= STRUCT_SHOWPAD;
			break;
		case 't':
			tablename = optarg;
			break;
		default:
			return(CMD_PARAM_ERROR);
		}
	}
	if (argc != optind + 2)
		return(CMD_PARAM_ERROR);

	structtype = argv[optind];
	memAddr = strtoul(argv[optind+1],0,0);

	/* Start by detecting the presence of a structure definition file... */
	structfile = getenv("STRUCTFILE");
	if (!structfile)
		structfile = STRUCTFILE;

	tfd = tfsopen(structfile,TFS_RDONLY,0);
	if (tfd < 0) {
		printf("Structure definition file '%s' not found\n",structfile);
		return(CMD_FAILURE);
	}

	index = 0;
	do {
		castDepth = 0;
		showStruct(tfd,flags,structtype,name,linkname);
		index++;
		if (linkname)
			printf("Link #%d = 0x%lx\n",index,memAddr);
		if (tablename || linkname) {
			if (askuser("next?"))  {
				if (tablename)
					printf("%s[%d]:\n",tablename,index);
			}
			else
				tablename = linkname = (char *)0;
		}
	} while(tablename || linkname);

	tfsclose(tfd,0);
	return(CMD_SUCCESS);
}
Exemple #4
0
/* showStruct():
 *	The workhorse of cast.  This function parses the structfile looking for
 *	the structure type; then it attempts to display the memory block that
 *	begins at memAddr as if it was the structure.  Note that there is no
 *	pre-processing done to verify valid syntax of the structure definition.
 */
int
showStruct(int tfd,long flags,char *structtype,char *structname,char *linkname)
{
	struct mbrinfo *mptr;
	ulong curpos, nextlink;
	int	i, state, snl, retval, tblsize;
	char line[96], addrstr[16], format[64];
	char *cp, *eol, *type, *eotype, *name, *bracket, *eoname, tmp;

	type = (char *)0;
	retval = nextlink = 0;
	curpos = tfsctrl(TFS_TELL,tfd,0);
	tfsseek(tfd,0,TFS_BEGIN);
	castIndent();
	if (structname)
		printf("struct %s %s:\n",structtype,structname);
	else
		printf("struct %s @0x%lx:\n",structtype,memAddr);
	castDepth++;

	state = STRUCT_SEARCH;
	snl = strlen(structtype);

	while(1) {
		if (tfsgetline(tfd,line,sizeof(line)-1) == 0) {
			printf("Structure definition '%s' not found\n",structtype);
			break;
		}
		if ((line[0] == '\r') || (line[0] == '\n'))	/* empty line? */
			continue;

		eol = strpbrk(line,";#\r\n");
		if (eol)
			*eol = 0;

		if (state == STRUCT_SEARCH) {
			if (!strncmp(line,"struct",6)) {
				cp = line+6;
				while(isspace(*cp))
					cp++;
				if (!strncmp(cp,structtype,snl)) {
					cp += snl;
					while(isspace(*cp))
						cp++;
					if (*cp == OPEN_BRACE) 
						state = STRUCT_DISPLAY;
					else {
						retval = -1;
						break;
					}
				}
			}
		}
		else if (state == STRUCT_DISPLAY) {
			type = line;
			while(isspace(*type))
				type++;

			if (*type == CLOSE_BRACE) {
				state = STRUCT_ALLDONE;
				break;
			}

			eotype = type;
			while(!isspace(*eotype))
				eotype++;
			*eotype = 0;
			name = eotype+1;
			while(isspace(*name))
				name++;
			bracket = strchr(name,'[');
			if (bracket)
				tblsize = atoi(bracket+1);						
			else
				tblsize = 1;

			if (*name == '*') {
				castIndent();
				printf("%s%-8s %s: ",strAddr(flags,addrstr),type,name);
				if (!strcmp(type,"char.c"))
					printf("\"%s\"\n",*(char **)memAddr);
				else
					printf("0x%lx\n",*(ulong *)memAddr);
				memAddr += 4;
				continue;
			}
			mptr = mbrinfotbl;			
			while(mptr->type) {
				if (!strcmp(type,mptr->type)) {
					castIndent();
					eoname = name;
					while(!isspace(*eoname))
						eoname++;
					tmp = *eoname;
					*eoname = 0;

					if (bracket) {
						if (!strcmp(type,"char.c")) {
							printf("%s%-8s %s: ",
								strAddr(flags,addrstr),mptr->type,name);
							cp = (char *)memAddr;
							for(i=0;i<tblsize && isprint(*cp);i++)
								printf("%c",*cp++);
							printf("\n");
						}
						else
							printf("%s%-8s %s\n",
								strAddr(flags,addrstr),mptr->type,name);
						memAddr += mptr->size * tblsize;
					}
					else {
						sprintf(format,"%s%-8s %%s: %s\n",
							strAddr(flags,addrstr),mptr->type,mptr->format);
						switch(mptr->size) {
							case 1:
								printf(format,name,*(uchar *)memAddr);
								break;
							case 2:
								printf(format,name,*(ushort *)memAddr);
								break;
							case 4:
								printf(format,name,*(ulong *)memAddr);
								break;
						}
						memAddr += mptr->size;
					}
					*eoname = tmp;
					break;
				}
				mptr++;
			}
			if (!(mptr->type)) {
				int	padsize;
				char *subtype, *subname, *eossn;

				if (!strcmp(type,"struct")) {
					subtype = eotype+1;
					while(isspace(*subtype))
						subtype++;
					subname = subtype;
					while(!isspace(*subname))
						subname++;
					*subname = 0;
					
					subname++;
					while(isspace(*subname))
						subname++;
					eossn = subname;
					while(!isspace(*eossn))
						eossn++;
					*eossn = 0;
					if (*subname == '*') {
						castIndent();
						printf("%s%s %s %s: 0x%08lx\n",strAddr(flags,addrstr),
							type,subtype,subname,*(ulong *)memAddr);
						if (linkname) {
							if (!strcmp(linkname,subname+1))
								nextlink = *(ulong *)memAddr;
						}
						memAddr += 4;
					}
					else {
						for (i=0;i<tblsize;i++) {
							if (bracket)
								sprintf(bracket+1,"%d]",i);
							if (showStruct(tfd,flags,subtype,subname,0) < 0) {
								state = STRUCT_ALLDONE;
								goto done;
							}
						}
					}
				}
				else if (!strncmp(type,"pad[",4)) {
					padsize = atoi(type+4);
					if (flags & STRUCT_SHOWPAD) {
						castIndent();
						printf("%spad[%d]\n",strAddr(flags,addrstr),padsize);
					}
					memAddr += padsize;
				}
				else  {
					retval = -1;
					break;
				}
			}
		}
		else {
			state = STRUCT_ERROR;
			break;
		}
	}
done:

	switch(state) {
		case STRUCT_SEARCH:
			printf("struct %s not found\n",structtype);
			retval = -1;
			break;
		case STRUCT_DISPLAY:
			printf("invalid member type: %s\n",type);
			retval = -1;
			break;
		case STRUCT_ERROR:
			printf("unknown error\n");
			retval = -1;
			break;
	}
	tfsseek(tfd,curpos,TFS_BEGIN);
	if (linkname)
		memAddr = nextlink;
	castDepth--;
	return(retval);
}
int main()
{
	showStruct(fetchStruct());
	return(0);
}