예제 #1
0
파일: libfunc.c 프로젝트: vidarh/ACE
BOOL found_func(char * libname,char * ut_funcname,SYM * declared_func)
{
     /* 
     ** Search for function in bmap file and record register usage
     ** and library base offset in symbol table entry for function.
     */

  make_bmap_name(libname);

  if (search_func(bmapname,ut_funcname,declared_func)) {
	/* store library name */
	declared_func->libname = (char *)sym_alloc(MAXIDSIZE+8);
	if (declared_func->libname == NULL) {
	  puts("Can't allocate memory for library name in symbol table!");
	  early_exit=TRUE;
	  kill_all_lists();
	  cleanup();
	} else {
	  /* found the function */  
	  strcpy(declared_func->libname,libname);
	  return(TRUE);
	}
  }

  /* didn't find the function */
  return(FALSE); 
}
예제 #2
0
파일: jwrapper.c 프로젝트: ScottDaniels/vfd
/*
	Given a json string, parse it, and put the things into a symtab.
	return the symtab pointer to the caller. They pass the symtab
	pointer back to the various get functions.

	This is the entry point. It sets up the symbol table and invokes the parse object
	funtion to start at the first level. Parse object will recurse for nested objects
	if present.
*/
extern void* jw_new( char* json ) {
	void	*st;				// symbol table

	st = sym_alloc( MAX_THINGS );
	if( st == NULL ) {
		return NULL;
	}

	json = strdup( json );												// allows user to free/overlay their buffer as needed
	sym_fmap( st, (unsigned char *) JSON_SYM_NAME, 0, json );			// save a pointer so we can free on nuke (fmap flags the data to be free'd when deleted)

	return parse_jobject( st,  json, "" );								// empty prefix for the root object
}
예제 #3
0
void
Init_PreSymbol(void)
{
    sym_id = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
    assert(sym_id != NULL);
    id_str = CFDictionaryCreateMutable(NULL, 0, NULL,
	    &kCFTypeDictionaryValueCallBacks);
    assert(id_str != NULL);
    last_id = 1000;

    // Pre-register parser symbols.
    for (int i = 0; rb_op_tbl[i].token != 0; i++) {
	ID id = rb_op_tbl[i].token;
	VALUE str = rb_str_new2(rb_op_tbl[i].name);
	rb_sym_t *sym = sym_alloc(str, id);
	unsigned long name_hash = rb_str_hash(str);

//printf("pre-register %s hash %ld id %ld\n", RSTRING_PTR(str), name_hash, id);

	CFDictionarySetValue(sym_id, (const void *)name_hash, (const void *)id);
	CFDictionarySetValue(id_str, (const void *)id, (const void *)sym);
    }
}
예제 #4
0
파일: jwrapper.c 프로젝트: ScottDaniels/vfd
/*
	Real work for parsing an object ({...}) from the json.   Called by jw_new() and 
	recurses to deal with sub-objects.
*/
void* parse_jobject( void* st, char *json, char* prefix ) {
	jthing_t	*jtp; 			// json thing that we just created
	int 	i;
	int 	n;					
	char	*name;				// name in the json
	char	*data;				// data string from the json
	jthing_t*	jarray;			// array of jthings we'll coonstruct
	int		size;
	int		osize;
	int		njtokens; 			// tokens actually sussed out
	jsmn_parser jp;				// 'parser' object
	jsmntok_t *jtokens;			// pointer to tokens returned by the parser
	char	pname[1024];		// name with prefix
	char	wbuf[256];			// temp buf to build a working name in
	char*	dstr;				// dup'd string

	jsmn_init( &jp );			// does this have a failure mode?

	jtokens = (jsmntok_t *) malloc( sizeof( *jtokens ) * MAX_THINGS );
	if( jtokens == NULL ) {
		fprintf( stderr, "abort: cannot allocate tokens array\n" );
		exit( 1 );
	}

	njtokens = jsmn_parse( &jp, json, strlen( json ), jtokens, MAX_THINGS );

	if( jtokens[0].type != JSMN_OBJECT ) {				// if it's not an object then we can't parse it.
		fprintf( stderr, "warn: badly formed json; initial opening bracket ({) not detected\n" );
		return NULL;
	}

	/* DEBUG
	for( i = 1; i < njtokens-1; i++ ) {					// we'll silently skip the last token if its "name" without a value
		fprintf( stderr, ">>> %4d: size=%d start=%d end=%d %s\n", i, jtokens[i].size, jtokens[i].start, jtokens[i].end, extract( json, &jtokens[i] ) );
	}
	*/

	for( i = 1; i < njtokens-1; i++ ) {					// we'll silently skip the last token if its "name" without a value
		if( jtokens[i].type != JSMN_STRING ) {
			fprintf( stderr, "warn: badly formed json [%d]; expected name (string) found type=%d %s\n", i, jtokens[i].type, extract( json, &jtokens[i] ) );
			sym_free( st );
			return NULL;
		}
		name = extract( json, &jtokens[i] );
		if( *prefix != 0 ) {
			snprintf( pname, sizeof( pname ), "%s.%s", prefix, name );
			name = pname;
		}

		size = jtokens[i].size;

		i++;										// at the data token now
		switch( jtokens[i].type ) {
			case JSMN_UNDEFINED: 
				fprintf( stderr, "warn: element [%d] in json is undefined\n", i );
				break;

    		case JSMN_OBJECT:				// save object in two ways: as an object 'blob' and in the current symtab using name as a base (original)
				dstr = strdup( extract( json, &jtokens[i] ) );
				snprintf( wbuf, sizeof( wbuf ), "%s_json", name );	// must stash the json string in the symtab for clean up during nuke	
				sym_fmap( st, (unsigned char *) wbuf, 0, dstr );
				parse_jobject( st, dstr, name );					// recurse to add the object as objectname.xxxx elements
				
				jtp = mk_thing( st, name, jtokens[i].type );		// create thing and reference it in current symtab
				if( jtp == NULL ) {
					fprintf( stderr, "warn: memory alloc error processing element [%d] in json\n", i );
					free( dstr );
					sym_free( st );
					return NULL;
				}
				jtp->v.pv = (void *) sym_alloc( 255 );						// object is just a blob
				if( jtp->v.pv == NULL ) {
					fprintf( stderr, "error: [%d] symtab for object blob could not be allocated\n", i );
					sym_free( st );
					free( dstr );
					return NULL;
				}
				dstr = strdup( extract( json, &jtokens[i] ) );
				sym_fmap( jtp->v.pv, (unsigned char *) JSON_SYM_NAME, 0, dstr );		// must stash json so it is freed during nuke()
				parse_jobject( jtp->v.pv,  dstr, "" );							// recurse acorss the string and build a new symtab

				size = jtokens[i].end;											// done with them, we need to skip them 
				i++;
				while( i < njtokens-1  &&  jtokens[i].end < size ) {
					//fprintf( stderr, "\tskip: [%d] object element start=%d end=%d (%s)\n", i, jtokens[i].start, jtokens[i].end, extract( json, &jtokens[i])  );
					i++;
				} 

				i--;						// must allow loop to bump past the last
				break;

    		case JSMN_ARRAY:
				size = jtokens[i].size;		// size is burried here, and not with the name
				jtp = mk_thing( st, name, jtokens[i].type );

				i++;						// first thing is the whole array string which I don't grock the need for, but it's their code...
				if( jtp == NULL ) {
					fprintf( stderr, "warn: memory alloc error processing element [%d] in json\n", i );
					sym_free( st );
					return NULL;
				}
				jarray = jtp->v.pv = (jsmntok_t *) malloc( sizeof( *jarray ) * size );		// allocate the array
				memset( jarray, 0, sizeof( *jarray ) * size );
				jtp->nele = size;

				for( n = 0; n < size; n++ ) {								// for each array element
					jarray[n].prim_type	 = PT_UNKNOWN;						// assume not primative type
					switch( jtokens[i+n].type ) {
						case JSMN_UNDEFINED:
							fprintf( stderr, "warn: [%d] array element %d is not valid type (undefined) is not string or primative\n", i, n );
							fprintf( stderr, "\tstart=%d end=%d\n", jtokens[i+n].start, jtokens[i+n].end );
							break;

						case JSMN_OBJECT:
							jarray[n].v.pv = (void *) sym_alloc( 255 );
							if( jarray[n].v.pv == NULL ) {
								fprintf( stderr, "error: [%d] array element %d size=%d could not allocate symtab\n", i, n, jtokens[i+n].size );
								sym_free( st );
								return NULL;
							}

							jarray[n].jsmn_type = JSMN_OBJECT;
							parse_jobject( jarray[n].v.pv,  extract( json, &jtokens[i+n]  ), "" );		// recurse acorss the string and build a new symtab
							osize = jtokens[i+n].end;									// done with them, we need to skip them 
							i++;
							while( i+n < njtokens-1  &&  jtokens[n+i].end < osize ) {
								//fprintf( stderr, "\tskip: [%d] object element start=%d end=%d (%s)\n", i, jtokens[i].start, jtokens[i].end, extract( json, &jtokens[i])  );
								i++;
							}
							i--;					// allow incr at loop end
							break;

						case JSMN_ARRAY:
							fprintf( stderr, "warn: [%d] array element %d is not valid type (array) is not string or primative\n", i, n );
							n += jtokens[i+n].size;			// this should skip the nested array
							break;

						case JSMN_STRING:
							data = extract( json, &jtokens[i+n] );
							jarray[n].v.pv = (void *) data;
							jarray[n].jsmn_type = JSMN_STRING;
							break;

						case JSMN_PRIMITIVE:
							data = extract( json, &jtokens[i+n] );
							switch( *data ) {
								case 0:
									jarray[n].prim_type	 = PT_VALUE;
									jarray[n].v.fv = 0;
									break;

								case 'T':
								case 't':
									jarray[n].v.fv = 1;
									jarray[n].prim_type	 = PT_BOOL;
									break;

								case 'F':
								case 'f':
									jarray[n].prim_type	 = PT_BOOL;
									jarray[n].v.fv = 0;
									break;

								case 'N':										// assume null, nil, or some variant
								case 'n':
									jarray[n].prim_type	 = PT_NULL;
									jarray[n].v.fv = 0;
									break;

								default:
									jarray[n].prim_type	 = PT_VALUE;
									jarray[n].v.fv = strtof( data, NULL ); 		// store all numerics as float
									break;
							}

							jarray[n].jsmn_type = JSMN_PRIMITIVE;
							break;
						
						default:
							fprintf( stderr, "warn: [%d] array element %d is not valid type (unknown=%d) is not string or primative\n", i, n, jtokens[i].type  );
							sym_free( st );
							return NULL;
							break;
					}
				}

				i += size - 1;		// must allow loop to push to next
				break;

    		case JSMN_STRING:
				data = extract( json, &jtokens[i] );
				jtp = mk_thing( st, name, jtokens[i].type );
				if( jtp == NULL ) {
					fprintf( stderr, "warn: memory alloc error processing element [%d] in json\n", i );
					sym_free( st );
					return NULL;
				}
				jtp->v.pv =  (void *) data;						// just point into the large json string
				break;

    		case JSMN_PRIMITIVE:
				data = extract( json, &jtokens[i] );
				jtp = mk_thing( st, name, jtokens[i].type );
				if( jtp == NULL ) {
					fprintf( stderr, "warn: memory alloc error processing element [%d] in json\n", i );
					sym_free( st );
					return NULL;
				}
				switch( *data ) {								// assume T|t is true and F|f is false
					case 0:
						jtp->v.fv = 0;
						jtp->prim_type = PT_VALUE;
						break;

					case 'T':
					case 't':
						jtp->prim_type = PT_BOOL;
						jtp->v.fv = 1; 
						break;

					case 'F':
					case 'f':
						jtp->prim_type = PT_BOOL;
						jtp->v.fv = 0; 
						break;

					case 'N':									// Null or some form of that
					case 'n':
						jtp->prim_type = PT_NULL;
						jtp->v.fv = 0; 
						break;

					default:
						jtp->prim_type = PT_VALUE;
						jtp->v.fv = strtof( data, NULL ); 		// store all numerics as float
						break;
				}
				break;

			default:
				fprintf( stderr, "unknown type at %d\n", i );
				break;
		}
	}

	free( jtokens );
	return st;
}
예제 #5
0
파일: stash.c 프로젝트: proftpd/proftpd
int pr_stash_add_symbol(pr_stash_type_t sym_type, void *data) {
  struct stash *sym = NULL;
  unsigned int hash;
  int idx = 0;
  xaset_t **symbol_table;
  size_t sym_namelen = 0;

  if (data == NULL) {
    errno = EINVAL;
    return -1;
  }

  switch (sym_type) {
    case PR_SYM_CONF:
      sym = sym_alloc();
      sym->sym_type = PR_SYM_CONF;
      sym->sym_name = ((conftable *) data)->directive;
      sym->sym_module = ((conftable *) data)->m;
      sym->ptr.sym_conf = data;
      symbol_table = conf_symbol_table;
      break;

    case PR_SYM_CMD:
      sym = sym_alloc();
      sym->sym_type = PR_SYM_CMD;
      sym->sym_name = ((cmdtable *) data)->command;
      sym->sym_module = ((cmdtable *) data)->m;
      sym->ptr.sym_cmd = data;
      symbol_table = cmd_symbol_table;
      break;

    case PR_SYM_AUTH:
      sym = sym_alloc();
      sym->sym_type = PR_SYM_AUTH;
      sym->sym_name = ((authtable *) data)->name;
      sym->sym_module = ((authtable *) data)->m;
      sym->ptr.sym_auth = data;
      symbol_table = auth_symbol_table;
      break;

    case PR_SYM_HOOK:
      sym = sym_alloc();
      sym->sym_type = PR_SYM_HOOK;
      sym->sym_name = ((cmdtable *) data)->command;
      sym->sym_module = ((cmdtable *) data)->m;
      sym->ptr.sym_hook = data;
      symbol_table = hook_symbol_table;
      break;

    default:
      errno = EINVAL;
      return -1;
  }

  /* XXX Should we check for null sym->sym_module as well? */
  if (sym->sym_name == NULL) {
    destroy_pool(sym->sym_pool);
    errno = EPERM;
    return -1;
  }

  sym_namelen = strlen(sym->sym_name);
  if (sym_namelen == 0) {
    destroy_pool(sym->sym_pool);
    errno = EPERM;
    return -1;
  }

  /* Don't forget to include one for the terminating NUL. */
  sym->sym_namelen = sym_namelen + 1;

  hash = sym_type_hash(sym_type, sym->sym_name, sym->sym_namelen);
  idx = hash % PR_TUNABLE_HASH_TABLE_SIZE;
  sym->sym_hash = hash;

  if (!symbol_table[idx]) {
    symbol_table[idx] = xaset_create(symbol_pool, (XASET_COMPARE) sym_cmp);
  }

  xaset_insert_sort(symbol_table[idx], (xasetmember_t *) sym, TRUE);
  return 0;
}
예제 #6
0
파일: libfunc.c 프로젝트: vidarh/ACE
BOOL search_func(char * bmap,char * func,SYM * declared_func)
{
  /* 
  ** Search for function in .bmap file, recording register usage
  ** and library base offset in symbol table entry for function. 
  */

  unsigned char		*buf;
  FILE * f;
  char		ch,name[MAXIDSIZE];
  LONG	 		bmap_size,count,cc,rc;
  SHORT			offset=0;
  BOOL     		found=FALSE;
  
  if ((bmap_size=fsize(bmap)) == -1L)  /* if not -1 -> file exists and
										  we get size of file in bytes. */
    { _error(50); return(FALSE); }
  else
	{
	  /* read whole bmap file into a buffer */
	  buf = (unsigned char *)alloc(bmap_size);
	  f = fopen(bmap,"r");
	  if(!f) return FALSE;
	  if(fread(buf,1,bmap_size,f) < (ULONG)bmap_size) return FALSE;
	  fclose(f);
	  
	  count=0;  /* start of buffer */
	  
	  while (!found && count < bmap_size) {
		/* build function name */
		cc=0;
		while (count < bmap_size && cc < MAXIDSIZE) {
		  ch=name[cc++]=buf[count++];
		  if (ch == '\0') break;  /* exit loop when EOS reached */
		}
		
		name[cc-1]='\0';  /* make sure we have an EOS symbol (may exit early) */
		
		if (strcmp(name,func) != 0) {
		  /* skip 2-byte offset */
		  count += 2;
		  /* skip to next name */
		  while (count < bmap_size && (ch=buf[count++]) != '\0');
		}
		else found=TRUE;  /* that's it! -> get the info' */
	  }
	  
	  if (!found) return(FALSE);
	  
	  /* get library base offset (2 bytes) */
	  if (count < bmap_size) {
		ch=buf[count++];
		offset += ch*256;
	  } else return(FALSE);

	  if (count < bmap_size) {
		ch=buf[count++];
		offset += ch;
	  } else return(FALSE);

	  declared_func->address = (SHORT)offset;  /* record library base offset */
	  
	  /* get n bytes of register data */
	  declared_func->reg = (UBYTE *)sym_alloc(15);
	  if (declared_func->reg == NULL) {
		puts("Can't allocate memory for function register info!");
		early_exit=TRUE;
		kill_all_lists();
       	cleanup();
	  }
	  
	  rc=0;
	  while (count < bmap_size && 
			 (ch=buf[count++]) != '\0') declared_func->reg[rc++]=ch;
	  
	  declared_func->no_of_params=rc;  /* record no. of parameters */
	  
	  if (ch != '\0') return(FALSE);  /* last character should be NULL */   
	  
	  /* we found it -> return */
	  return(TRUE);
	}
}
예제 #7
0
파일: fminit.c 프로젝트: ScottDaniels/xfm
/*
****************************************************************************
*
*  Mnemonic: FMinit
*  Abstract: This routine opens the initial input file and the output file
*            and does other necessary house keeping chores.
*  Parms:    argc - Number of arguments passed to fm from command line
*            argv - Argument vector list passed from command line
*  Returns:  Valid if all is well, ERROR if system could not be initialized.
*  Date:     17 November 1988
*  Author:   E. Scott Daniels
*
*  Modified:  22 Apr 1991 - To remove need to have dedicated page num buffer
*              3 May 1991 - To initialize flags2 variable
*              3 May 1992 - To convert for post script output
*              7 Nov 1992 - To alloc header font buffers
*             12 Nov 1992 - To add justify PS proc
*             13 Nov 1992 - To allocate current font buffer before use
*             10 Dec 1992 - To use AFIwrite for ansi compat on sun
*              6 Apr 1993 - To create a dummy variable block for psuedo
*                           commands generated by .gm and .gd commands.
*             26 May 1993 - To add stroke command to box routine.
*             13 Jun 1993 - To set the psfm variable by placing a dv command
*                           into the initial input buffer.
*             12 Jul 1993 - To set the def item list font ptr to null
*             21 Feb 1994 - To open output file just "w"
*                           To put out the PS routine rightxy for header/footer
*             22 Feb 1994 - To init figure font (ffont)
*              7 Apr 1994 - To seup for TOC now that linelen is points related
*              7 Oct 2000 - To use new AFI tokeniser
*	      		10 Oct 2001 - To add new justification PS functions
*	      		13 Jan 2001 - Added sym table support
*				08 Nov 2006 - Some cleanup and now allow default input from stdin.
*				10 Apr 2007 - Memory leak cleanup 
*				16 Sep 2007 - added page geometry argument support
*				13 Nov 2007 - Changed the imbed/run() mechanism to better support the 
*						oneject processing.
*				22 Mar 2011 - Correctly set boty when geometry (-g) is given.
*				07 Jul 2013 - Changed initialisation of text colour to use setcolour. 
*				17 Jul 2016 - Bring decls into the modern world.
*****************************************************************************
*/
extern int FMinit( int argc, char **argv )
{
	int i;               /* loop index */
	char buf[1024];
	char *ptr;           /* pointer to argument */
	char	*ifname = "stdin";
	char	*ofname = "stdout";
	int 	geomh = 0;		/* geometry from -g hxw */
	int 	geomw = 0;

	argc--;
	argv++;
	while( argc > 0 && argv[0][0] == '-' )
	{
		switch( argv[0][1] )
		{
			case 'g': 
				geomh = atoi( argv[1] ) * 72;
				if( (ptr = strchr( argv[1], 'x' )) != NULL )
					geomw = atoi( ptr + 1 ) * 72;
				argv++;
				argc--;
				break;

			case 't':
				trace = atoi( argv[1] );
				argv++;
				argc--;
				break;

			case 'v':
				flags2 |= F2_NOISY;
				break;

			case '?':
				FMmsg( ERROR, "Usage: tfm [input-file [output-file [inital command tokens]]]" );
				exit( 1 );

			default:	
				fprintf( stderr, "unrecognised option: %s\n", argv[0] );
				exit( 1 );
		}	

		argv++;
		argc--;
	}

	if( argc >= 1 )
	{
		if( *argv[0] != '-' )		/* allow - to default to stdin */
			ifname = argv[0];
	}

	if( argc > 1 )
	{
		if( *argv[1] != '-' )		/* allow - to default to stdout */
			ofname = argv[1];
	}

	if( strcmp( ifname, ofname ) == 0 )
	{
		FMmsg( ERROR, "input name cannot be same as output; this is just wrong");
		return ERROR;
	}

	if( FMopen( ifname ) < VALID )       /* open the initial input file */
		return ERROR;                     

	symtab = sym_alloc( 4999 );		/* symtab for variables */
	AFIsettoken( fptr->file, symtab, " \t", '&', '^', ":" );
	AFIsetflag( fptr->file, AFI_F_EOBSIG, AFI_SET );		/* end of buffer notifications */
#ifdef KEEP
this is dropped because imbed now puts a run/stop command into the stream to pop the call to fmrun() at end of file
	AFIsetflag( fptr->file, AFI_F_EOFSIG, AFI_SET );		/* end of file notifications -- must have so .im file .cmd works */
#endif

	ofile = AFIopen( ofname, "w" );      /* open output file */
	if( ofile < VALID )
	{
		FMmsg( E_CANTOPEN, ofname );
		FMclose( );
		return ERROR;
	}

	version = "pfm V2.8/17243"; 		/* returned by .gv v command */
	snprintf( buf, sizeof( buf ), "+PFM text formatter (%s) started", version );
	FMmsg( -1, buf );

	/* write out our postscript routines that make life easier */
	snprintf( buf, sizeof( buf ), "%%! %s generated this postscript file\n", version );
	AFIwrite( ofile, buf );
	/*AFIwrite( ofile, "%! PFM 1.1-02282 PostScript output\n" );*/
	/*AFIwrite( ofile, "% Copyright (c) 1994-2002 by E. Scott Daniels. All Rights Reserved!\n" );*/
	AFIwrite( ofile, "% A happy programme is one that generates other programmes;\n" );
	AFIwrite( ofile, "% This was generated by a happy programme!\n" );

	boty = (10 * 71);			/* default to 11" page with a 1" bottom margin */
	if( cury <= 0 )
		cury = topy = 71;			/* default to 1" top margin */
	if( top_gutter <= 0 )
		top_gutter = cury/2;		// space above first line for running matter
	pagew = MAX_X;
	pageh = MAX_Y;

	AFIwrite( ofile, "%these functions are Copyright (c) 2001-2013 by E. Scott Daniels. All Rights Reserved!\n" );
	/*  new page macro to showpage and set the origion of the 0,0 */
	if( geomh )
	{
		pagew = geomw;			/* override defaults with user setting */
		pageh = geomh;

		AFIwrite( ofile, "%%BeginSetup\n" );
		AFIwrite( ofile, "mark {\n" );
		AFIwrite( ofile, "%BeginFeature: *PageRegion C\n" );
		snprintf( buf, sizeof( buf ), "<</PageSize [%d %d]>> setpagedevice\n", pagew, pageh );
		AFIwrite( ofile, buf );
		AFIwrite( ofile, "%EndFeature\n" );
		AFIwrite( ofile, "} stopped cleartomark\n" );
 		AFIwrite( ofile, "%%EndSetup\n" );
		snprintf( buf, sizeof( buf ), "/xlate {0 %d translate} def\n/newp {showpage xlate} def\n", pageh );
		AFIwrite( ofile, buf );
		boty = pageh - 42;			/* adjust botom y based on geometry */
	}
	else
		AFIwrite( ofile, "/xlate {0 792 translate} def\n/newp {showpage xlate} def\n" );
	
	/* the remainder of the native ps that we dump on initialisation is in init.ps which is 
		parsed and compressed by a mk rule and put into init_ps.c
	*/
#include "init_ps.c"		/* easier to manage postscript functions we need */

	/* now initialize from a C point of view */

	difont = NULL;     /* initially no def list item font string defined */
	ffont = NULL;      /* no figure font defined */
	//textcolour = strdup( "000000" );
	FMsetcolour( "#000000" );					/* default to black */
	curfont = strdup( DEF_TEXTFONT );
	runfont = strdup( DEF_RUNFONT );
	FMfmt_add( );


	textspace = 2;
	iptr = 0;
	optr = 0;                 /* start at beginning of the output buffer */
	obuf = (char *) malloc( sizeof( char ) * 2048 );
	inbuf = (char *) malloc( sizeof( char ) * 2048 );
	if( ! obuf || ! inbuf )
	{
		fprintf( stderr, "malloc of obuffer failed\n" );
		return ERROR;
	}
	*obuf = (char) 0;

	sprintf( inbuf, ".dv pfm 1 : " );   /* simulate a user command - define compiler name */
	AFIpushtoken( fptr->file, inbuf );  /* and push onto the input stack */

	if( (path = getenv( "PFM_PATH" )) == NULL )
		path = getenv( "XFM_PATH" );

	cur_col = firstcol = (struct col_blk *) malloc( sizeof( struct col_blk ) );
	if( cur_col == NULL )
		return ERROR;

	cur_col->lmar = DEF_LMAR;
	cur_col->width = 550 - DEF_LMAR; /* set single column width */
	cur_col->next = NULL;          /* by default we are in single column mode */

	flags = PARA_NUM;              /* turn on paragraph numbering */


	memset( tocname, 0, sizeof(tocname ) );
	snprintf( tocname, sizeof( tocname )-5, "%s",  ifname );
	if( (ptr = strrchr( tocname, '.' )) != NULL )
		*ptr = 0;
	strcat( tocname, ".toc" );		/* same filename with .toc extension */

	memset( pnum, 0, sizeof( pnum ) );

	for( i = argc - 1; i > 2; i-- )
		AFIpushtoken( fptr->file, argv[i] );	/* whatever is after output file we use as input */


	for( i = 0; i < MAX_HLEVELS; i++ )   /* allocate and init header blks */
	{
		headers[i] = (struct header_blk *) malloc( sizeof( struct header_blk ) );
		if( headers[i] == NULL )
			return ERROR;

		headers[i]->font = (char *) malloc( (strlen( DEF_HEADFONT )) + 1 );
		strcpy( headers[i]->font, DEF_HEADFONT );  /* move in default string */
	
		headers[i]->flags = HTOC;              /* initially only TOC flag set */
		headers[i]->indent = DEF_HEADINDENT;   /* set default indention */
		headers[i]->level = i+1;               /* set the level */
		headers[i]->skip = 21;                  /* skip down 2 lines before/1after */
	}

	headers[0]->size = DEF_H1SIZE;   /* set default header text sizes */
	headers[1]->size = DEF_H2SIZE;
	headers[2]->size = DEF_H3SIZE;
	headers[3]->size = DEF_H4SIZE;
	headers[0]->flags |= HEJECTC+HTOUPPER;   /* header level 1 defaults */

	return VALID;
}
예제 #8
0
static ID
rb_intern_uchars(const UChar *chars, const size_t chars_len, VALUE str)
{
    const unsigned long name_hash = rb_str_hash_uchars(chars, chars_len);
    LOCK();
    ID id = (ID)CFDictionaryGetValue(sym_id, (const void *)name_hash); 
    UNLOCK();
    if (id != 0) {
	goto return_id;
    }
 
    if (str == Qnil) {
	str = rb_unicode_str_new(chars, chars_len);
    }

    rb_sym_t *sym = NULL;
    long pos = 0;
    if (chars_len > 0) {
	UChar c = chars[0];
	switch (c) {
	    case '$':
		id = ID_GLOBAL;
		goto new_id;

	    case '@':
		if (chars_len > 1 && chars[1] == '@') {
		    pos++;
		    id = ID_CLASS;
		}
		else {
		    id = ID_INSTANCE;
		}
		pos++;
		break;

	    default:
		if (chars_len > 1 && chars[chars_len - 1] == '=') {
		    // Attribute assignment.
		    id = rb_intern_str(rb_str_substr(str, 0, chars_len - 1));
		    if (!is_attrset_id(id)) {
			id = rb_id_attrset(id);
			goto id_register;
		    }
		    id = ID_ATTRSET;
		}
		else if (iswupper(c)) {
		    id = ID_CONST;
		}
		else {
		    id = ID_LOCAL;
		}
		break;
	}
    }

    if (pos < chars_len && !isdigit(chars[pos])) {
	for (; pos < chars_len; pos++) {
	    if (!is_identchar(chars[pos])) {
		break;
	    }
	}
    }
    if (pos < chars_len) {
	id = ID_JUNK;
    }

new_id:
    id |= ++last_id << ID_SCOPE_SHIFT;

id_register:
//printf("register %s hash %ld id %ld\n", RSTRING_PTR(str), name_hash, id);
    sym = sym_alloc(str, id);
    LOCK();
    CFDictionarySetValue(sym_id, (const void *)name_hash, (const void *)id);
    CFDictionarySetValue(id_str, (const void *)id, (const void *)sym);
    UNLOCK();

return_id:
    return id;
}