Пример #1
0
static void reportRetry(void)
{
	if (reportFile != NULL) {
		fclose(reportFile);
		openReportFile(bezName, fileSuffix);
	}
}
Пример #2
0
int main(int argc, char *argv[])
{
	int allowEdit, allowHintSub, fixStems, debug, badParam;
	char *fontInfoFileName=NULL; /* font info file name, or suffix of environment variable holding the fontfino string. */
	char *fontinfo = NULL; /* the string of fontinfo data */
	int firstFileNameIndex = -1; /* arg index for first bez file name, or  suffix of environment variable holding the bez string. */
	register char *current_arg;
	short total_files = 0; 
	int result, argi;
  
	badParam = fixStems = debug = doAligns = doStems = allstems = FALSE;
	allowEdit = allowHintSub = TRUE;
	fileSuffix = (char*)dfltExt;

	/* read in options */
	argi = 0;
	while (++argi < argc)
		{
	   current_arg = argv[argi];
	   
		if (current_arg[0] == '\0')
			continue;
		else if (current_arg[0] != '-')
			{
			if (firstFileNameIndex == -1)
				firstFileNameIndex = argi;
			total_files++;
			continue;
			}
		else if (firstFileNameIndex != -1)
			{
			fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-\" option found after first file name.\n");
			exit(1);
 			}

		switch (current_arg[1])
			{
			case '\0':
				badParam = TRUE;
				break;
			case 'u':
				printUsage();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			case 'h':
				printHelp();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			 case 'e':
				allowEdit = FALSE;
				break;
			 case 'f':
				fontInfoFileName = argv[++argi];
				if  ((fontInfoFileName[0] == '\0') || (fontInfoFileName[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-f\" option must be followed by a file name.\n");
					exit(1);
					}
				break;
			 case 's':
				fileSuffix = argv[++argi];
				if  ((fileSuffix[0] == '\0') || (fileSuffix[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-s\" option must be followed by a string, and the string must not begin with '-'.\n");
					exit(1);
					}
				break;
			case 'n':
				allowHintSub = FALSE;
				break;
			case 'q':
				verbose = FALSE;
				break;
			 case 'D':
				debug = TRUE;
				break;
			case 'F':
				fixStems = TRUE;
			  break;
			case 'a':
				allstems = 1;
				break;
				
			case 'r':
				allowEdit = allowHintSub = FALSE;
				fileSuffix = (char *)reportExt;
				switch (current_arg[2])
					{
					case 'a':
						reportRetryCB = reportRetry;
						addCharExtremesCB = charZoneCB;
						addStemExtremesCB = stemZoneCB;
						doAligns = 1;

						addHStemCB = NULL;
						addVStemCB = NULL;
						doStems = 0;
						break;
					case 's':
						reportRetryCB = reportRetry;
						addHStemCB = hstemCB;
						addVStemCB = vstemCB;
						doStems = 1;

						addCharExtremesCB = NULL;
						addStemExtremesCB = NULL;
						doAligns = 0;
						break;
					default:
						fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
						badParam = TRUE;
						break;
					}
					break;
			case 'v':
				printVersions();
				exit(0);
				break;
			  break;
#if ALLOWCSOUTPUT
			case 'C':
				charstringoutput = TRUE;
				break;
#endif
			default:
				fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
				badParam = TRUE;
				break;
			}
		}

	if (firstFileNameIndex == -1)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide bez file name.\n");
		badParam = TRUE;
		}
	if (fontInfoFileName == NULL)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide font info file name.\n");
		badParam = TRUE;
		}
		
	if (badParam) 
#ifdef EXECUTABLE
		exit(NONFATALERROR);
#else
		longjmp(aclibmark, -1);
#endif

#if ALLOWCSOUTPUT
	if (charstringoutput)
		read_char_widths();
#endif

	AC_SetReportCB(reportCB, verbose);
	fontinfo = getFileData(fontInfoFileName);
	argi = firstFileNameIndex-1;
	while (++argi < argc)
		{
		char *bezdata;
		char *output;
		size_t outputsize = 0;
		bezName = argv[argi];
		bezdata = getFileData(bezName);
		outputsize = 4*strlen(bezdata);
		output = malloc(outputsize); 

		if (doAligns || doStems)
			openReportFile(bezName, fileSuffix);
			
		result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
		if (result == AC_DestBuffOfloError)
			{
			free(output);
			if (reportFile != NULL)
				closeReportFile();
			if (doAligns || doStems)
				openReportFile(bezName, fileSuffix);
			output = malloc(outputsize); 
			/* printf("NOTE: trying again. Input size %d output size %d.\n", strlen(bezdata), outputsize); */
			AC_SetReportCB(reportCB, FALSE);
			result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
			AC_SetReportCB(reportCB, verbose);
			}
		if (reportFile != NULL)
			closeReportFile();
		else
			{
			if ((outputsize != 0) && (result == AC_Success))
				writeFileData(bezName, output, fileSuffix);
			}
		free(output);
		main_cleanup( (result == AC_Success) ? OK : FATALERROR);
		}
		

  return 0;
  }