⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pstotxtd.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 2 页
字号:
    return 0;}intunload_pstotext(void){    if (pstotextInstance)        dllfn_pstotextExit(pstotextInstance);    pstotextInstance = NULL;    if (pstotextModule)        DosFreeModule(pstotextModule);    pstotextModule = (HMODULE)NULL;    return 0;}intsend_prolog(FILE *f, int resource){  char *prolog, *p;APIRET rc;int code = -1;	rc = DosGetResource(pstotextModule, RT_RCDATA, resource, (PPVOID)&prolog);	if (!rc && (prolog != (char *)NULL) ) {	    code = 0;	    p = prolog;	    while (*p) {		if (!code)		    fputs(p, f);		p += strlen(p)+1;	    }	    DosFreeResource(prolog);	}	else {	    fprintf(stderr, "Failed to load pstotext resource %d\n", resource);	}	return code;}#endif /* OS/2   (!MSDOS) */#endif /* (!_Windows) *//* create an empty temporary file and return its name */static char *scratch_file(void) {    FILE *f;    char *temp;    char *path = malloc(256);    if (path == NULL)	return NULL;    if ( (temp = getenv("TEMP")) != NULL )	strcpy(path, temp);    else if ( (temp = getenv("TMP")) != NULL )	strcpy(path, temp);    else	strcpy(path, "c:\\");    /* Prevent X's in path from being converted by mktemp. */    for ( temp = path; *temp; temp++ ) {	    *temp = (char)tolower(*temp);	    if (*temp == '/')		*temp = '\\';    }    if ( strlen(path) && (path[strlen(path)-1] != '\\') )	    strcat(path, "\\");    strcat(path, "ptXXXXXX");    mktemp(path);    f = fopen(path, "w");    if (f==NULL) {perror(cmd); exit(1);}    fclose(f);    return path;}static char *make_temp(int resource) {  /* Return pathname of temporary file containing prolog from resources.  Caller     should unlink file (and, technically, free pathname). */    FILE *f;    char *path = scratch_file();    if (path == NULL) {perror(cmd); cleanup(); exit(1);}	    f = fopen(path, "w");    if (f==NULL) {perror(cmd); cleanup(); exit(1);}    send_prolog(f, resource);    fclose(f);    return path;}static char *ocr_path = NULL, *rotate_path = NULL;static FILE *gs = NULL;char *gstemp = NULL;static void *instance; /* pstotext state */static int cleanup(void) {  int status = 0;  unload_pstotext();  if (gs!=NULL) {#if defined(_Windows) || defined(MSDOS)    fclose(gs);#else    pclose(gs);#endif  }  if (gstemp!=NULL && !debug)    unlink(gstemp);  if (rotate_path!=NULL && strcmp(rotate_path, "")!=0 && !debug)     unlink(rotate_path);  if (ocr_path!=NULL && !debug)      unlink(ocr_path);  return status;}static void handler(int code) {  int status = code; /* suppress unreference 'code' warning */  status = cleanup();  if (status!=0)    exit(status);  exit(2);}static void do_it(char *path) {  /* If "path" is NULL, then "stdin" should be processed. */  char gs_cmd[2*MAXPATHLEN];  char input[MAXPATHLEN];  int status;  FILE *fileout;#ifdef MSDOS  char *gsargtemp;  FILE *gsargfile;#endif  fileout = stdout;  if (strlen(outfile) != 0) {    fileout = fopen(outfile, "w");    if (fileout == NULL) {perror(cmd); exit(1);}  }  signal(SIGINT, handler);  signal(SIGTERM, handler);  status = load_pstotext();  if (status!=0) {    fprintf(stderr, "%s: internal error %d\n", cmd, status);    exit(5);  }  if (cork) {    status = dllfn_pstotextSetCork(pstotextInstance, TRUE);    if (status!=0) {      fprintf(stderr, "%s: internal error %d\n", cmd, status);      exit(5);    }  }  ocr_path = make_temp(OCR_PROLOG);  switch (orientation) {  case portrait: rotate_path = ""; break;  case landscape: rotate_path = make_temp(ROT270_PROLOG); break;  case landscapeOther: rotate_path = make_temp(ROT90_PROLOG); break;  }  if (path==NULL) strcpy(input, "-");  else {strcpy(input, "-- "); strcat(input, path);}#if defined(_Windows) || defined(MSDOS)  /* don't support pipes, so write gs output to a temporary file */  if ( (gstemp = scratch_file()) == NULL) {	cleanup();	exit(1);  }#endif#ifdef MSDOS  /* MSDOS has command line length problems */  if ( (gsargtemp = scratch_file()) == NULL) {	cleanup();	exit(1);  }  if ( (gsargfile = fopen(gsargtemp, "w")) == (FILE *)NULL) {	cleanup();	exit(1);  }  fprintf(gsargfile, "-r72 -dNODISPLAY -dFIXEDMEDIA -dDELAYBIND -dWRITESYSTEMDICT %s -dNOPAUSE\n",    (debug ? "" : "-q"));  fputs(rotate_path, gsargfile);  fputs("\n", gsargfile);  fputs(ocr_path, gsargfile);  fputs("\n", gsargfile);  fputs(input, gsargfile);  fputs("\n", gsargfile);  fclose(gsargfile);    sprintf(gs_cmd, "%s @%s %s %s", gscommand, gsargtemp, #if defined(_Windows) || defined(MSDOS)    "> ", gstemp#else    "", ""#endif    );#else   /* !MSDOS */  sprintf(gs_cmd, "%s -r72 -dNODISPLAY -dFIXEDMEDIA -dDELAYBIND -dWRITESYSTEMDICT %s -dNOPAUSE %s %s %s %s %s",    gscommand,    (debug ? "" : "-q"),    ocr_path,    rotate_path,    input,#if defined(_Windows) || defined(MSDOS)    "> ", gstemp#else    "", ""#endif    );#endif  if (debug) {    fputs(gs_cmd, stdout);    fputc('\n', stdout);  }#if defined(_Windows) || defined(MSDOS)  if (system(gs_cmd)) {    fprintf(stderr,"\nCan't run (errno=%d):\n   %s\n", errno, gs_cmd);    cleanup();    exit(1);  }  gs = fopen(gstemp, "r");#else  gs = popen(gs_cmd, "r");#endif#ifdef MSDOS  if (!debug)     unlink(gsargtemp);  free(gsargtemp);#endif  if( gs==NULL ) {perror(cmd); cleanup(); exit(1);}  while (gs != NULL) {   /* while TRUE */    char line[LINELEN];    char *pre, *word, *post;    int llx, lly, urx, ury;    if (fgets(line, LINELEN, gs)==NULL) break;    if (debug)	fputs(line, stdout);    status = dllfn_pstotextFilter(      pstotextInstance, line, &pre, &word, &post, &llx, &lly, &urx, &ury);    if (status!=0) {      fprintf(stderr, "%s: internal error %d\n", cmd, status);      cleanup();      exit(5);    }    if (word!=NULL)      if (!bboxes) {        fputs(pre, fileout); fputs(word, fileout); fputs(post, fileout);	if (debug)	    fputc('\n', stdout);      }      else {	if (pre) {	    if (*pre == ' ')		pre++;	    fputs(pre, fileout);	}        fprintf(fileout, "%6d\t%6d\t%6d\t%6d\t%s\n", llx, lly, urx, ury, word);	if (post)	    fputs(post, fileout);      }  }  if (fileout != stdout) fclose(fileout);  status = cleanup();  if (status!=0) exit(status);}int main(int argc, char *argv[]) {  int i;  char *arg;  cmd = argv[0];  for (i = 1; i<argc; i++) {    arg = argv[i];    if (strcasecmp(arg, "-landscape")==0) orientation = landscape;    else if (strcasecmp(arg, "-cork")==0) cork = TRUE;    else if (strcasecmp(arg, "-landscapeOther")==0) orientation = landscapeOther;    else if (strcasecmp(arg, "-portrait")==0) orientation = portrait;    else if (strcasecmp(arg, "-bboxes")==0) bboxes = TRUE;    else if (strcasecmp(arg, "-debug")==0) debug = TRUE;    else if (strcasecmp(arg, "-gs")==0) {	i++;	if (i<argc)	    gscommand = argv[i];    }    else if (strcasecmp(arg, "-output") == 0) {	i++;	if (i>=argc) {usage(); exit(1);}	outfile = argv[i];    }    else if (strcmp(arg, "-")==0) do_it(NULL);    else if (arg[0] == '-') {usage(); exit(1);}    else /* file */ {      explicitFiles++;      do_it(arg);    }  }  if (explicitFiles==0) do_it(NULL);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -