示例#1
0
文件: post.c 项目: Acidburn0zzz/afdko
static Format2_0 *read2_0(Card32 left)
	{
	IntX i;
	Card8 *end;
	Card8 *name;
	IntX nameSize;
	Format2_0 *format = memNew(sizeof(Format2_0));

	IN1(format->numberGlyphs);
	
	/* Read index */
	format->glyphNameIndex =
		memNew(sizeof(format->glyphNameIndex[0]) * format->numberGlyphs);
	for (i = 0; i < format->numberGlyphs; i++)
		IN1(format->glyphNameIndex[i]);

	/* Read name table */
	nameSize = 
		left - (sizeof(format->numberGlyphs) +
				sizeof(format->glyphNameIndex[0]) * format->numberGlyphs);
	format->names = memNew(nameSize + 1);
	IN_BYTES(nameSize, format->names);

	/* Count names in table */
	nNames = 0;
	end = format->names + nameSize;
	for (name = format->names; name < end; name += *name + 1)
		if (*name == '\0')
			break;
		else
			nNames++;

	return format;
	}
示例#2
0
文件: main.c 项目: Acidburn0zzz/afdko
static char * NextToken(char * str, int *start)
{
	char *token;
	int end, current;
	
	if(str[*start]=='\0') return NULL;
	
	if(str[*start]=='\"'){
		for(end=*start+1; str[end]!='\"' && str[end]!='\0'; end++)
			;
		token=(char *)memNew((end-*start+1) * sizeof(char));
		for(current=*start+1; current<end; current++)
			token[current-*start-1]=str[current];
		token[current-*start-1]='\0';
		
		if(str[end]=='\"') end++;
		while(str[end]==' ') end++;
		*start=end;

	}else{
		for(end=*start; str[end]!=' ' && str[end]!='\0'; end++)
			;
	
		token=(char *)memNew((end-*start+1) * sizeof(char));
		for(current=*start; current<end; current++)
			token[current-*start]=str[current];
		token[current-*start]='\0';
		
		while(str[end]==' ') end++;
		*start=end;
	}
	return token;
}
示例#3
0
文件: MMVR.c 项目: Acidburn0zzz/afdko
void MMVRRead(LongN start, Card32 length)
	{
	IntX i;
	
	if (loaded)
		return;

	MMVR = (MMVRTbl *)memNew(sizeof(MMVRTbl));
	SEEK_ABS(start);

	IN1(MMVR->Version);
	IN1(MMVR->Flags);
	IN1(MMVR->AxisCount);

	MMVR->axis = memNew(sizeof(Axis) * MMVR->AxisCount);
	for (i = 0; i < MMVR->AxisCount; i++)
		{
		Axis *axis = &MMVR->axis[i];
		
		IN1(axis->Tag);
		IN1(axis->Default);
		IN1(axis->Scale);
		}

	loaded = 1;
	}
示例#4
0
文件: post.c 项目: Acidburn0zzz/afdko
static Format2_5 *read2_5(void)
	{
	IntX i;
	Format2_5 *format = memNew(sizeof(Format2_5));

	IN1(format->numberGlyphs);

	format->offset = memNew(sizeof(format->offset[0]) * format->numberGlyphs);
	for (i = 0; i < format->numberGlyphs; i++)
		IN1(format->offset[i]);

	return format;
	}
示例#5
0
文件: WDTH.c 项目: Acidburn0zzz/afdko
void WDTHRead(LongN start, Card32 length)
	{
	IntX i;
	IntX size;
	IntX nElements;
	IntX nOffsets;

	if (loaded)
		return;
	WDTH = (WDTHTbl *)memNew(sizeof(WDTHTbl));

	SEEK_ABS(start);
	
	IN1(WDTH->version);
	IN1(WDTH->flags);
	IN1(WDTH->nMasters);
	IN1(WDTH->nRanges);

	size = (WDTH->flags & LONG_OFFSETS) ? sizeof(Card32) : sizeof(Card16);
	nElements = WDTH->nRanges + 1;

	/* Read first glyphs */
	WDTH->firstGlyph = memNew(sizeof(GlyphId) * nElements);
	for (i = 0; i < nElements; i++)
		IN1(WDTH->firstGlyph[i]);

	/* Read offsets */
	if (WDTH->flags & LONG_OFFSETS)
		{
		Card32 *offset = WDTH->offset = memNew(sizeof(Card32) * nElements);
		for (i = 0; i < nElements; i++)
			IN1(offset[i]);	
		nOffsets = offset[WDTH->nRanges] - offset[0];
		}
	else
		{
		Card16 *offset = WDTH->offset = memNew(sizeof(Card16) * nElements);
		for (i = 0; i < nElements; i++)
			IN1(offset[i]);	
		nOffsets = offset[WDTH->nRanges] - offset[0];
		}

	/* Read widths */
	WDTH->width = memNew(sizeof(uFWord) * WDTH->nMasters * nOffsets);
	for (i = 0; i < nOffsets; i++)
		IN1(WDTH->width[i]);

	loaded = 1;
	}
示例#6
0
文件: map.c 项目: Acidburn0zzz/afdko
void InitAliasFromFile(void)
{
	FILE *file=NULL;
	int counter=0, value, i;
	
	if(glyphaliasfilename!=NULL)
		file = fopen(glyphaliasfilename, "r");
	if (file==NULL)
		{
			fprintf(OUTPUTBUFF, "Could not open GlyphAliasDB\n");
			return;
		}
	while(1){
		char temp1[32], temp2[32], c;
		value = fscanf(file, "%s %s", temp1, temp2);
		if (value==EOF || value == 0)
			break;
		do {
			c = getc(file);
		}while (c!='\r' && c!='\n');
		c = getc(file);
		if (c!='\r' && c!='\n')
			ungetc(c, file);
		counter++;
	}
	MAP2 = (map_MappingType *)memNew(counter * sizeof(map_MappingType));
	
	rewind(file);
	
	for(i=0; i<counter; i++){
		char *oldname, *nicename, c;
		oldname = memNew(32);
		nicename = memNew(32);
		fscanf(file, "%s %s\n", oldname, nicename);
		do {
			c = getc(file);
		}while (c!='\r' && c!='\n' && c!=EOF);
		c = getc(file);
		if (c!='\r' && c!='\n')
			ungetc(c, file);
		MAP2[i].oldname=oldname;
		MAP2[i].nicename=nicename;
	}
	MAP_length=counter;
	qsort(MAP2, counter, sizeof(map_MappingType), mapcmp);
	fclose(file);
}
示例#7
0
static Format1 *readFormat1(void) {
    IntX i;
    Format1 *format = memNew(sizeof(Format1));

    format->format = 1;
    IN1(format->count);

    format->glyphId = memNew(sizeof(format->glyphId[0]) * format->count);
    for (i = 0; i < format->count; i++)
        IN1(format->glyphId[i]);

    format->code = memNew(sizeof(format->code[0]) * format->count);
    for (i = 0; i < format->count; i++)
        IN1(format->code[i]);

    return format;
}
示例#8
0
/* Allocate and read hybrid value */
static FWord *hybridRead(void) {
    IntX i;
    FWord *hybrid = memNew(sizeof(hybrid[0]) * nMasters);

    for (i = 0; i < nMasters; i++)
        IN1(hybrid[i]);
    return hybrid;
}
示例#9
0
文件: MMSD.c 项目: Acidburn0zzz/afdko
void MMSDRead(LongN start, Card32 length)
	{
	if (loaded)
		return;

	MMSD = (MMSDTbl *)memNew(sizeof(MMSDTbl));
	SEEK_ABS(start);
	
	loaded = 1;
	}
示例#10
0
void ENCORead(LongN start, Card32 length) {
    IntX i;

    if (loaded)
        return;

    ENCO = (ENCOTbl *)memNew(sizeof(ENCOTbl));

    if (FNAMGetNEncodings(&nEncodings, ENCO_))
        return;

    SEEK_ABS(start);

    IN1(ENCO->version);

    ENCO->offset = memNew(sizeof(ENCO->offset[0]) * (nEncodings + 1));
    for (i = 0; i < nEncodings + 1; i++)
        IN1(ENCO->offset[i]);

    ENCO->encoding = memNew(sizeof(ENCO->encoding[0]) * nEncodings);
    for (i = 0; i < nEncodings; i++) {
        Card16 format;

        SEEK_ABS(ENCO->offset[i] + start);

        IN1(format);
        switch (format) {
            case ENCO_STANDARD:
                ENCO->encoding[i] = readFormat0();
                break;
            case ENCO_SPARSE:
                ENCO->encoding[i] = readFormat1();
                break;
            case ENCO_DENSE:
                ENCO->encoding[i] = readFormat2();
                break;
            default:
                warning(SPOT_MSG_ENCOUNKENCOD, format);
        }
    }

    loaded = 1;
}
示例#11
0
文件: post.c 项目: Acidburn0zzz/afdko
static Format4_0 *read4_0(LongN start)
	{
	IntX i;
	Format4_0 *format;

	if (maxpGetNGlyphs(&nGlyphs, post_))
		{
		warning(SPOT_MSG_postNONGLYPH);
		return NULL;
		}

	format = memNew(sizeof(Format4_0));
	format->code = memNew(sizeof(format->code[0]) * nGlyphs );
	
	SEEK_ABS(start + TBL_HDR_SIZE);
	for (i = 0; i < nGlyphs; i++)
		IN1(format->code[i]);

	return format;
	}
示例#12
0
文件: main.c 项目: Acidburn0zzz/afdko
static char * MakeFullPath(char *source)
{
	char * dest;
		
	dest = (char *) memNew(256);
	if(sourcepath[0]=='\0' || strchr(source, '\\')!=NULL)
		sprintf(dest, "%s", source);
	else
		sprintf(dest, "%s\\%s", sourcepath, source);
	return dest;
}
示例#13
0
static Format2 *readFormat2(void) {
    IntX i;
    Format2 *format = memNew(sizeof(Format2));

    format->format = 2;

    for (i = 0; i < 256; i++)
        IN1(format->glyphId[i]);

    return format;
}
示例#14
0
文件: MMFX.c 项目: brawer/afdko
void MMFXRead(LongN start, Card32 length)
{
    IntX i;
    Card32 lenstr;

    if (loaded)
        return;

    MMFX = (MMFXTbl *)memNew(sizeof(MMFXTbl));
    SEEK_ABS(start);

    IN1(MMFX->version);
    IN1(MMFX->nMetrics);
    IN1(MMFX->offSize);

    MMFX->offset = memNew(sizeof(Int32) * (MMFX->nMetrics + 1));

    for (i = 0; i < MMFX->nMetrics; i++)
    {
        if (MMFX->offSize == 2)
        {
            Int16 tmp;
            IN1(tmp);
            MMFX->offset[i] = tmp;
        }
        else
        {
            IN1(MMFX->offset[i]);
        }
        if (MMFX->offset[i] < (Int32)minoffset) minoffset = MMFX->offset[i];
        if (MMFX->offset[i] > (Int32)maxoffset) maxoffset = MMFX->offset[i];
    }


    lenstr = (start + length) - TELL();
    MMFX->offset[MMFX->nMetrics] = lenstr + 1;
    MMFX->cstrs = memNew(sizeof(Card8) * (lenstr + 1));
    SEEK_ABS(start + minoffset);
    IN_BYTES(lenstr, MMFX->cstrs);
    loaded = 1;
}
示例#15
0
/*
   Return:
	NULL, failed
	other, the message pushed.
 */
static TT_BMSG_T *tt_bmsg_push (TT_BMSG_QUEUE_T *msg_queue, void *msg_data)
{
	LIST_T *msg_node = memNew (msg_queue->queue.msg_buffer);
	if (msg_node == NULL)
		return NULL;
	else
	{
		TT_BMSG_T *msg	= GetParentAddr (msg_node, TT_BMSG_T, list);
		memcpy(&msg->msg_data[0], msg_data, msg_queue->each_msg_size);
		listAttach (&msg_queue->queue.msg_used, &msg->list);
		return msg;
	}
}
示例#16
0
文件: hdmx.c 项目: Acidburn0zzz/afdko
void hdmxRead(LongN start, Card32 length)
	{
	IntX i;
	LongN recordOffset = start + TBL_HDR_SIZE;

	if (loaded)
		return;

	hdmx = (hdmxTbl *)memNew(sizeof(hdmxTbl));

	if (maxpGetNGlyphs(&nGlyphs, hdmx_))
		return;

	SEEK_ABS(start);

	IN1(hdmx->version);
	IN1(hdmx->nRecords);
	IN1(hdmx->recordSize);

	hdmx->record = memNew(sizeof(DeviceRecord) * hdmx->nRecords);
	for (i = 0; i < hdmx->nRecords; i++)
		{
		IntX j;
		DeviceRecord *rec = &hdmx->record[i];

		IN1(rec->pixelsPerEm);
		IN1(rec->maxWidth);
		
		rec->widths = memNew(sizeof(rec->widths[0]) * nGlyphs);
		for (j = 0; j < nGlyphs; j++)
			IN1(rec->widths[j]);

		recordOffset += hdmx->recordSize;
		SEEK_ABS(recordOffset);
		}
	
	loaded = 1;
	}
示例#17
0
/*
   Return:
	NULL, failed
	other, the message pushed.
 */
static TT_MSG_T *tt_msg_push (TT_MSG_QUEUE_T *msg_queue, FUN_TT_MSG_PROC msg_proc, void *msg_data)
{
	LIST_T *msg_node = memNew (msg_queue->msg_buffer);
	if (msg_node == NULL)
		return NULL;
	else
	{
		TT_MSG_T *msg	= GetParentAddr (msg_node, TT_MSG_T, list);
		msg->msg_proc	= msg_proc;
		msg->msg_data	= msg_data;
		listAttach (&msg_queue->msg_used, &msg->list);
		return msg;
	}
}
示例#18
0
void CID_Read(LongN start, Card32 length) {
    if (loaded)
        return;

    CID_ = (CID_Tbl *)memNew(sizeof(CID_Tbl));

    SEEK_ABS(start);

    IN1(CID_->Version);
    IN1(CID_->Flags);
    IN1(CID_->CIDCount);
    IN1(CID_->TotalLength);
    IN1(CID_->AsciiLength);
    IN1(CID_->BinaryLength);
    IN1(CID_->FDCount);

    loaded = 1;
}
示例#19
0
void HFMXRead(LongN start, Card32 length) {
    if (loaded)
        return;
    HFMX = (HFMXTbl *)memNew(sizeof(HFMXTbl));

    nMasters = BLNDGetNMasters();
    SEEK_ABS(start);

    IN1(HFMX->Version);

    HFMX->Ascent = hybridRead();
    HFMX->Descent = hybridRead();
    HFMX->LineGap = hybridRead();
    HFMX->CaretSlopeRise = hybridRead();
    HFMX->CaretSlopeRun = hybridRead();
    HFMX->CaretOffset = hybridRead();

    loaded = 1;
}
示例#20
0
文件: post.c 项目: Acidburn0zzz/afdko
void postRead(LongN start, Card32 length)
	{
	if (loaded)
		return;

	post = (postTbl *)memNew(sizeof(postTbl));
	SEEK_ABS(start);

	/* Read header */
	IN1(post->version);
	IN1(post->italicAngle);
	IN1(post->underlinePosition);
	IN1(post->underlineThickness);
	IN1(post->isFixedPitch);
	IN1(post->minMemType42);
	IN1(post->maxMemType42);
	IN1(post->minMemType1);
	IN1(post->maxMemType1);

	switch (post->version)
		{
	case VERSION(1,0):
		break;
	case VERSION(2,0):
		post->format = read2_0(length - TBL_HDR_SIZE);
		break;
	case VERSION(2,5):
		post->format = read2_5();
		break;
	case VERSION(3,0):
		break;
	case VERSION(4,0):
		post->format = read4_0(start);
		break;
	default:
		warning(SPOT_MSG_postBADVERS, VERSION_ARG(post->version));
		return;
		}

	loaded = 1;
	}
示例#21
0
void BBOXRead(LongN start, Card32 length) {
    IntX i;

    if (loaded)
        return;

    BBOX = (BBOXTbl *)memNew(sizeof(BBOXTbl));

    SEEK_ABS(start);

    IN1(BBOX->version);
    IN1(BBOX->flags);
    IN1(BBOX->nGlyphs);
    IN1(BBOX->nMasters);

    BBOX->bbox = memNew(sizeof(BBox) * BBOX->nGlyphs);
    for (i = 0; i < BBOX->nGlyphs; i++) {
        IntX j;
        BBox *bbox = &BBOX->bbox[i];

        bbox->left = memNew(sizeof(FWord) * BBOX->nMasters);
        for (j = 0; j < BBOX->nMasters; j++)
            IN1(bbox->left[j]);

        bbox->bottom = memNew(sizeof(FWord) * BBOX->nMasters);
        for (j = 0; j < BBOX->nMasters; j++)
            IN1(bbox->bottom[j]);

        bbox->right = memNew(sizeof(FWord) * BBOX->nMasters);
        for (j = 0; j < BBOX->nMasters; j++)
            IN1(bbox->right[j]);

        bbox->top = memNew(sizeof(FWord) * BBOX->nMasters);
        for (j = 0; j < BBOX->nMasters; j++)
            IN1(bbox->top[j]);
    }

    loaded = 1;
}
示例#22
0
文件: main.c 项目: Acidburn0zzz/afdko
/* Main program */
IntN main(IntN argc, Byte8 *argv[])
	{
	   IntX value = 0;
	  static double glyphptsize = STDPAGE_GLYPH_PTSIZE;
	  static opt_Option opt[] =
		{
		  {"-u", opt_Call, (void*)showUsage},
		  {"-h", opt_Call, (void*)showHelp},
		  {"-ht", opt_Call, (void*)sfntTableSpecificUsage},
#if AUTOSPOOL
		  {"-l", opt_Flag},
		  {"-O", opt_Flag},
#endif
		  {"-r", opt_Flag},
		  {"-n", opt_Flag},
		  {"-nc", opt_Flag},
		  {"-ngid", opt_Flag},
		  {"-T", opt_Flag},
		  {"-F", opt_Flag},
		  {"-f", opt_Flag},
		  {"-G", opt_Flag},
		  {"-V", opt_Flag},
		  {"-m", opt_Flag},
		  {"-d", opt_Flag},
		  {"-br", opt_Flag},
		  {"-i", resIdScan},
		  {"-o", sfntTTCScan},
		  {"-t", sfntTagScan},
		  {"-P", sfntFeatScan}, 
		  {"-A", sfntFeatScan}, 
		  {"-p", proofPolicyScan}, 
		  {"-a", opt_Flag},
		  {"-R", opt_Flag},
		  {"-c", opt_Flag},
		  {"-g", glyfGlyphScan},
		  {"-b", glyfBBoxScan},
		  {"-s", glyfScaleScan},
		  {"-@", opt_Double, &glyphptsize},
		  {"-C", opt_Int, &cmapSelected},
#if AUTOSCRIPT
		  {"-X", opt_String, scriptfilename},
#endif
		  {"-ag", opt_String, &glyphaliasfilename},
		  {"-of", opt_String, &outputfilebase},
		};

	  IntX files, goodFileCount=0;
	  IntN argi;
      Byte8 *filename = NULL;
	  volatile IntX i = 0;
#if AUTOSCRIPT
	  cmdlinetype *cmdl;
	  Byte8 foundXswitch = 0;
#endif
	  int status = 0; /* = setjmp(global.env); only ued when compiled as lib */

	  if (status)
	  {
#if AUTOSCRIPT
	  	if (global.doingScripting)
	  		{
	  		  goto scriptAbEnd;
	  		}
	  	else
#endif
			exit(status - 1);	/* Finish processing */
	  }
	  gcr.reportNumber=0;
	 /*  value = setjmp(mark); only used when comiled as lib */

         if (value==-1)
                 exit(1);

	  da_SetMemFuncs(memNew, memResize, memFree);
	  global.progname = "spot";

#if AUTOSCRIPT
	scriptfilename[0] = '\0'; /* init */

	if (!foundXswitch && (argc < 2)) /* if no -X on cmdline, and no OTHER switches */
	  strcpy(scriptfilename, "spot.scr");

/* see if scriptfile exists to Auto-execute */
	if ((scriptfilename[0] != '\0') && sysFileExists(scriptfilename))
		{
			global.doingScripting = 1;
			makeArgs(scriptfilename);
		}
#endif /* AUTOSCRIPT */

	  if (
#if AUTOSCRIPT
		  !global.doingScripting
#else
		  1
#endif
		  )
		{
	  	argi = opt_Scan(argc, argv, opt_NOPTS(opt), opt, NULL, NULL);
		if (opt_hasError())
			{
			exit(1);
			}
	  
	  if (argi == 0 )
		showUsage();

#if AUTOSCRIPT
	if (!global.doingScripting && opt_Present("-X"))
	{
		if (scriptfilename && scriptfilename[0] != '\0')
		{
		global.doingScripting = 1;
		makeArgs(scriptfilename);
		goto execscript;
		}
	}
#endif


	  if (opt_Present("-@"))
		proofSetGlyphSize(glyphptsize);

	  if (opt_Present("-V"))  /* equivalent to "-p6" */
		proofSetPolicy(6, 1); 

	  if (opt_Present("-ngid")) 
		global.flags |= SUPPRESS_GID_IN_NAME;

	  files = argc - argi;
      if ((files == 0) && (argc > 1)) /* no files on commandline, but other switches */
		{
		}

	  for (; argi < argc; argi++)
		{
		  filename = argv[argi];
		  
		  if (files > 1)
		  	{
			fprintf(stderr, "Proofing %s.\n", filename);
			fflush(stderr);
			}

		  if (outputfilebase== NULL)
		 	outputfilebase = filename;
		  fileOpen(filename);		  
		  
		  if (!fileIsOpened())
		  {
		  	warning(SPOT_MSG_BADFILE, filename);
			fileClose();
			continue;
		  }
		  if (readFile(filename))
			{
			  fileClose();
			  continue;
			}

		  goodFileCount++;
		  fileClose();
		}
		
	}
#if AUTOSCRIPT
	else /* executing cmdlines from a script file */
	{
execscript:
			{
				char * end;
				
			end=strrchr(scriptfilename, '\\');
				if(end==NULL)
					sourcepath="";
				else{
					char *scurr = scriptfilename;
					char *dcurr;
					
					sourcepath=(char *)memNew(strlen(scriptfilename));
					dcurr = sourcepath;
					while(scurr!=end)
					{
						*dcurr++=*scurr++;
					}		
					*dcurr=0;
				}
			
			}

	  for (i = 0; i < script.cmdline.cnt ; i++) 
	  {
		char * tempfilename;
		
		cmdl = da_INDEX(script.cmdline, i);
		if (cmdl->args.cnt < 2) continue;

		proofResetPolicies();
		
		{
			IntX a;
			
			inform(SPOT_MSG_EOLN);
			message(SPOT_MSG_ECHOSCRIPTCMD);
			for (a = 1; a < cmdl->args.cnt; a++)
			{
				inform(SPOT_MSG_RAWSTRING, cmdl->args.array[a]);
			}
			inform(SPOT_MSG_EOLN);
		}
		
		argi = opt_Scan(cmdl->args.cnt, cmdl->args.array, opt_NOPTS(opt), opt, NULL, NULL);		
		if (opt_hasError())
			{
			exit(1);
			}

		if (opt_Present("-@"))
			proofSetGlyphSize(glyphptsize);
	  	if (opt_Present("-V"))  /* equivalent to "-p6" */
			proofSetPolicy(6, 1); 

		tempfilename = MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]);
		
		
		if (fileExists(tempfilename) )
		  { 						/* (new) font filename on cmdline */
			memFree(tempfilename);
			if (filename != NULL) /* not first time */
			{
			  fileClose(); /* previous font file */
	  		  sfntFree(1);
		  	}
			if(sourcepath[0]!='\0')
				filename=MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]);
			else
				filename = cmdl->args.array[cmdl->args.cnt-1];
			fileOpen(filename);
			if (outputfilebase == NULL)
		 		outputfilebase = filename;
			fprintf(stderr, "Proofing %s.\n", filename);
			fflush(stderr);
		    goodFileCount++;
		
		  if (readFile(filename))
			{
			  goodFileCount--;
			  fileClose();
			  continue;
			}
			
		  }
		else
		{
		  /* none specified */
		  fatal(SPOT_MSG_MISSINGFILENAME);
		  memFree(tempfilename);
		  continue;
		}
		
		sfntDump();
		
scriptAbEnd:
		sfntFree(1);
	    fileClose();
	  }
	  global.doingScripting = 0;
	}
#endif /* AUTOSCRIPT */

/*	fprintf(stderr, "\nDone.\n");*/
	if(goodFileCount<=0)
		exit(1);

	quit(0);
	return 0;		
}
示例#23
0
文件: main.c 项目: Acidburn0zzz/afdko
PyObject * main_python(PyObject *self, PyObject *args)
	{
	static double glyphptsize = STDPAGE_GLYPH_PTSIZE;
	static opt_Option opt[] =
		{
		  {"-u", opt_Call, showUsage},
		  {"-h", opt_Call, showHelp},
		  {"-ht", opt_Call, sfntTableSpecificUsage},
		  {"-l", opt_Flag},
		  {"-O", opt_Flag},
		  {"-r", opt_Flag},
		  {"-n", opt_Flag},
		  {"-nc", opt_Flag},
		  {"-T", opt_Flag},
		  {"-F", opt_Flag},
		  {"-f", opt_Flag},
		  {"-G", opt_Flag},
		  {"-V", opt_Flag},
		  {"-m", opt_Flag},
		  {"-d", opt_Flag},
		  {"-br", opt_Flag},
		  {"-i", resIdScan},
		  {"-o", sfntTTCScan},
		  {"-t", sfntTagScan},
		  {"-P", sfntFeatScan}, 
		  {"-A", sfntFeatScan}, 
		  {"-p", proofPolicyScan}, 
		  {"-a", opt_Flag},
		  {"-R", opt_Flag},
		  {"-c", opt_Flag},
		  {"-g", glyfGlyphScan},
		  {"-b", glyfBBoxScan},
		  {"-s", glyfScaleScan},
		  {"-@", opt_Double, &glyphptsize},
		  {"-C", opt_Int, &cmapSelected},
#if AUTOSCRIPT
		  {"-X", opt_String, scriptfilename},
#endif
		  {"-ag", opt_String, &glyphaliasfilename},
		  {"-of", opt_String, &outputfilebase},
		};
	char **argv, **argfree;
	int strIndex, argc, argtotal, tries;
	char * argString, *outfilename;
	IntX files;
	IntN argi;
    Byte8 *filename = NULL;
	Card32 value;
	int i = 0;
#if AUTOSCRIPT
	cmdlinetype *cmdl;
	Byte8 foundXswitch = 0;
#endif
    IntN status;

#ifdef SUNOS
	{
	/* To allow gdb to attach to process */
	char* do_debug_sleep;
	do_debug_sleep = getenv("STOP_OTFPROOF_FOR_GDB");
	while (do_debug_sleep != NULL)
		sleep(1);
	}	
#endif


	/* Resetting globals*/
	gcr.reportNumber=0;
	aliasfromfileinit = 0; 
	
/*	freopen("OTFProof.std.log", "w", stdout);*/
	
	value = setjmp(mark);
	
	if(value==-1){
		PyErr_SetString(ErrorObject, "Fatal Error");
		if (PyOutFile != NULL)
			{
			fclose(PyOutFile);
			PyOutFile = NULL;
			}
		freemap();
		return NULL;
	}
	
	if(!PyArg_ParseTuple(args, "ss", &argString, &outfilename)){
		freemap();
		return NULL;
	}
	
	if (PyOutFile == NULL)
		PyOutFile = fopen(outfilename, "w");
	else
		PyOutFile = freopen(outfilename, "w", PyOutFile);
	
	VORGfound=0;
	strIndex=0;
	argfree= (char **) memNew(MAX_ARGS*sizeof(char *));
	argv=(char **) memNew(MAX_ARGS*sizeof(char *));
	
	for(i=0; i<MAX_ARGS; i++){
		argfree[i]=argv[i]=NextToken(argString, &strIndex);
		if(argv[i]==NULL) {
			argtotal=argc=i;
			break;
		}else{
			/*fprintf(OUTPUTBUFF,  ">>%s<<\n", argv[i]);*/
		}
	}
	  status = setjmp(global.env);
	  if (status)
	  {
#if AUTOSCRIPT
	  	if (global.doingScripting)
	  		{
	  		  goto scriptAbEnd;
	  		}
	  	else
#endif
			if(status==2){
				PyErr_SetString(ErrorObject, "Fatal Error");
				if (PyOutFile != NULL)
					{
					fclose(PyOutFile);
					PyOutFile = NULL;
					}
				freemap();
				argFree(argfree, argv);
				return NULL;
			}else{
				if (PyOutFile != NULL)
					{
					fclose(PyOutFile);
					PyOutFile = NULL;
					}
				freemap();
				argFree(argfree, argv);
				return Py_None;
			}
	  }
	  
	  da_SetMemFuncs(memNew, memResize, memFree);
	  global.progname = "OTFproof";
#if AUTOSCRIPT
	scriptfilename[0]='\0';
	for (i = 0; i < argc; i++)
	{
		if (strcmp(argv[i], "-X") == 0)
		{
			if ((argv[i+1] != NULL) && (argv[i+1][0] != '\0'))
			{
				strcpy(scriptfilename, argv[i+1]);
				foundXswitch = 1;
			}
			break;
		}
	}
#endif 
	proofResetPolicies();
	argi = opt_Scan(argc, argv, opt_NOPTS(opt), opt, NULL, NULL);
	
	if (opt_hasError())
		{
		if (PyOutFile != NULL)
			{
			fclose(PyOutFile);
			PyOutFile = NULL;
			}
 		  freemap();
		  argFree(argfree, argv);
		  return Py_None;
		}
		
	 if (opt_Present("-@"))
		proofSetGlyphSize(glyphptsize);

	  if (opt_Present("-V"))  /* equivalent to "-p6" */
		proofSetPolicy(6, 1); 

	  files = argc - argi;

	  for (; argi < argc; argi++)
		{
		  filename = argv[argi];
		  
			fileOpen(filename);
			if (!fileIsOpened())
		  {
		  	warning(SPOT_MSG_BADFILE, filename);
			fileClose();
			continue;
		  }
/*			fprintf(OUTPUTBUFF, "\nProofing %s.\n", filename);			*/
		  tries = 0;
		  /* See if we can recognize the file type */
		  value = fileSniff();	
		  switch (value)
			{
			case bits_:
			case typ1_:		
			case true_:
			case mor0_:
			case OTTO_:
			case VERSION(1,0):
			  sfntRead(0, -1);	/* Read plain sfnt file */
			  sfntDump();
			  sfntFree(1);		  
			  break;
			case ttcf_:
			  sfntTTCRead(0);		/* Read TTC file */
			  continue;
			  break;
			case 256:
			  SEEK_ABS(0); /* Raw resource file as a data fork */ 
			  resRead(0);			/* Read and dump  Macintosh resource file */
			  continue;
			  break;
			case sig_AppleSingle:
			case sig_AppleDouble:
				doASDFormats((ctlTag)value);
				break;
			default:
				warning(SPOT_MSG_BADFILE, filename);
			  	fileClose();
			  continue;
			}

		  fileClose();
		  freemap();
		  argFree(argfree, argv);
#if MEMCHECK
		  memReport();
#endif
		fclose(PyOutFile);
		PyOutFile = NULL;
		  return Py_None;
		}
#if AUTOSCRIPT	
execscript:
			{
				char * end;
				
				end=strrchr(scriptfilename, '\\');
				if(end==NULL)
					sourcepath="";
				else{
					char *scurr = scriptfilename;
					char *dcurr;
					
					sourcepath=(char *)memNew(strlen(scriptfilename));
					dcurr = sourcepath;
					while(scurr!=end)
					{
						*dcurr++=*scurr++;
					}		
					*dcurr=0;
				}
			
			}

	  for (i = 0; i < script.cmdline.cnt ; i++) 
	  {
		char * tempfilename;
		
		cmdl = da_INDEX(script.cmdline, i);
		if (cmdl->args.cnt < 2) continue;

		proofResetPolicies();
		
		{
			IntX a;
			
			inform(SPOT_MSG_EOLN);
			message(SPOT_MSG_ECHOSCRIPTCMD);
			for (a = 1; a < cmdl->args.cnt; a++)
			{
				inform(SPOT_MSG_RAWSTRING, cmdl->args.array[a]);
			}
			inform(SPOT_MSG_EOLN);
		}
		
		argi = opt_Scan(cmdl->args.cnt, cmdl->args.array, opt_NOPTS(opt), opt, NULL, NULL);		

		if (opt_hasError())
			{
			if (PyOutFile != NULL)
				{
				fclose(PyOutFile);
				PyOutFile = NULL;
				}
			freemap();
			argFree(argfree, argv);
			return Py_None;
			}

		if (opt_Present("-@"))
			proofSetGlyphSize(glyphptsize);
	  	if (opt_Present("-V"))  /* equivalent to "-p6" */
			proofSetPolicy(6, 1); 

		tempfilename = MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]);
		
		
		if (fileExists(tempfilename) )
		  { 						/* (new) font filename on cmdline */
			memFree(tempfilename);
			if (filename != NULL) /* not first time */
			{
			  fileClose(); /* previous font file */
	  		  sfntFree(1);
		  	}
			if(sourcepath[0]!='\0')
				filename=MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]);
			else
				filename = cmdl->args.array[cmdl->args.cnt-1];
			fileOpen(filename);
			  tries=0;
retry:
			/* See if we can recognize the file type */
			value = fileSniff();	
			switch (value)
			  {
			  case bits_:
			  case typ1_:		
			  case true_:
			  case mor0_:
			  case OTTO_:
			  case VERSION(1,0):
				sfntRead(0, -1);	/* Read plain sfnt file */
				break;
			  case ttcf_:
				sfntTTCRead(0);		/* Read TTC file */
				continue;
				break;
			  case 256:
				resRead(0);			/* Read Macintosh resource file */
				continue;
				break;
			  default:	 
 				warning(SPOT_MSG_BADFILE, filename);
				fileClose();
				continue;
			  }
		  }
		else
		{
		  /* none specified */
		  fatal(SPOT_MSG_MISSINGFILENAME);
		  memFree(tempfilename);
		  continue;
		}
		
		sfntDump();
		
scriptAbEnd:
		sfntFree(1);
	    fileClose();
	  }
	  global.doingScripting = 0;
#endif	

	/*fprintf(stderr, "\nDone.\n");*/
	
	fileClose();	
	freemap();
	argFree(argfree, argv);
#if MEMCHECK
	memReport();
#endif
	fclose(PyOutFile);
	PyOutFile = NULL;
	return Py_None;
}
示例#24
0
static Format0 *readFormat0(void) {
    Format0 *format = memNew(sizeof(Format0));

    format->format = 0;
    return format;
}
示例#25
0
void AsmTranslateCode(Assembler *a, AsmCode *code) {                       // 指令的編碼函數           
  char cxCode[9]="00000000";
	code->objCode = memNew(code->size*2+1);
  memset(code->objCode, '\0', code->size*2+1);                              // 目的碼為 0000…
  switch (code->type) {                                                    // 根據指令型態             
    case 'J' :                                                             // 處理 J 型指令              
      AsmCodeParse(code, a);
      sprintf(cxCode, "%8x", code->cx);
      sprintf(code->objCode, "%2x%s", code->opCode, &cxCode[2]);                 //   編出目的碼(16進位)      
      break;                                                                                        
    case 'L' :
      AsmCodeParse(code, a);
      sprintf(cxCode, "%8x", code->cx);
      sprintf(code->objCode, "%2x%x%x%s", code->opCode, code->r[0], code->r[1], &cxCode[4]);
      break;                                                               
    case 'A' :                                                             // 處理 A 型指令         
      AsmCodeParse(code, a);
      sprintf(cxCode, "%8x", code->cx);                                                                   
      sprintf(code->objCode, "%2x%x%x%x%s", code->opCode,code->r[0],code->r[1],code->r[2],&cxCode[5]);   //   編出目的碼(16進位)  
      break;                                                                                        
    case 'D' : {                                                           // 處理是資料宣告                             
      // 我們將資料宣告  RESW, RESB, WORD, BYTE 也視為一種指令,其形態為 D
      Array *tokens = code->tokens;
      char format4[]="%8x", format1[]="%2x", *format = format1;            
      switch (code->opCode) {                                              // 如果是 RESW    
        case OP_RESW:                                                      //       或 RESB 
        case OP_RESB:
          memset(code->objCode, '0', code->size*2);                              // 目的碼為 0000….         
          break;                                                           // 如果是 WORD:            
        case OP_WORD:                                                                
          format = format4;                                                // 設定輸出格式為 %8x 
        case OP_BYTE: {                                                    // 如果是 BYTE : 輸出格式為 %2x
          char *objPtr = code->objCode;
          int i=0, si;
          for (i=code->argStart; i<tokens->count; i++) {                                 
              char *item = tokens->item[i];
              if (item[0] == '"') {
                for (si=1; item[si] != '"'; si++) {
                    sprintf(objPtr, "%2x", item[si]);
                    objPtr += 2;
                }
			} else if (isdigit(item[0])) {
                sprintf(objPtr, format, atoi(item));
            } else {
                AsmCode *itemCode = HashTableGet(a->symTable, item);
                sprintf(objPtr, format, itemCode->address);
              }
//			strFree(item);
              objPtr += strlen(objPtr);
          }
          break;
        } // case OP_BYTE:
      } // switch
      break;
    } // case ' '
    default: 
      break;
  }
  strReplace(code->objCode, " ", '0');
  strToUpper(code->objCode);
}
示例#26
0
文件: main.c 项目: Acidburn0zzz/afdko
static void makeArgs(char *filename)
      {
      int state;
      long i;
      long length;
      IntX file;
      char *start = NULL;     /* Suppress optimizer warning */
      cmdlinetype *cmdl;

      /* Read whole file into buffer */
      file = sysOpenSearchpath(filename);
	  if (file < 0)
      	fatal(SPOT_MSG_BADSCRIPTFILE, filename);
      length = sysFileLen(file);
      if (length < 1) 
      	fatal(SPOT_MSG_BADSCRIPTFILE, filename);
      script.buf = memNew(length + 2);

	  message(SPOT_MSG_ECHOSCRIPTFILE, filename);
      sysSeek(file, 0, 0, filename);
      sysRead(file, (Card8 *)script.buf, length, filename);
      sysClose(file, filename);

      script.buf[length] = '\n';      /* Ensure termination */
      script.buf[length+1] = '\0';    /* Ensure termination */
      /* Parse buffer into args */
      state = 0;
      da_INIT(script.cmdline, 10, 10);
      cmdl = da_NEXT(script.cmdline);
      da_INIT(cmdl->args, 10, 10);
      *da_NEXT(cmdl->args) = global.progname;
      for (i = 0; i < length + 1; i++)
              {
              char c = script.buf[i];
              switch (state)
                      {
              case 0:
                      switch ((int)c)
                              {
                      case '\n':
                      case '\r':
                              cmdl = da_NEXT(script.cmdline);
                              da_INIT(cmdl->args, 10, 10);
                              *da_NEXT(cmdl->args) = global.progname;
                              break;
                      case '\f': 
                      case '\t': 
                              break;
                      case ' ': 
                              break;
                      case '#': 
                              state = 1;
                              break;
                      case '"': 
                              start = &script.buf[i + 1];
                              state = 2; 
                              break;
                      default:  
                              start = &script.buf[i];
                              state = 3; 
                              break;
                              }
                      break;
              case 1: /* Comment */
                      if (c == '\n' || c == '\r')
                              state = 0;
                      break;
              case 2: /* Quoted string */
                      if (c == '"')
                              {
                              script.buf[i] = '\0';   /* Terminate string */
                              *da_NEXT(cmdl->args) = start;
                              state = 0;
                              }
                      break;
              case 3: /* Space-delimited string */
                      if (isspace((int)c))
                              {
                              script.buf[i] = '\0';   /* Terminate string */
                              *da_NEXT(cmdl->args) = start;
                              state = 0;
                              if ((c == '\n') || (c == '\r')) 
                                {
                                      cmdl = da_NEXT(script.cmdline);
                                      da_INIT(cmdl->args, 10, 10);
                                      *da_NEXT(cmdl->args) = global.progname;
                                }
                              }
                      break;
                      }
              }
      }