home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / archives / dvi2lj-0.49.lha / findfile.c < prev    next >
C/C++ Source or Header  |  1992-09-09  |  3KB  |  111 lines

  1. #include "config.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. #ifdef amiga
  6. # include <exec/types.h>
  7. # include <stat.h>
  8. #else
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. int stat();
  12. #endif
  13.  
  14. char *path_segment();
  15.  
  16. bool
  17. findfile(path,n,fontmag,name)
  18. char path[STRSIZE];  /* PIXEL path */
  19. char n[STRSIZE];     /* name of font */
  20. long fontmag;        /* magnification */
  21. char name[STRSIZE];  /* full name of PXL file  (returned) */
  22. {
  23.     char local_path[STRSIZE];
  24.     char *pathpt;
  25.     struct stat s;
  26.     int rc = -1;
  27.     int resolution, i;
  28.  
  29.     resolution = (int)(fontmag/5.0 +0.5) ;
  30.  
  31.     for(i=0; (pathpt=path_segment((bool)(i==0),path,local_path))!=NULL;i++) {
  32. #ifdef USEPXL
  33. /*       sprintf(name,"%s/dpi%d/%s.pk",pathpt,resolution,n); */
  34.        sprintf(name,"%s/%d/%s.%dpk",pathpt,resolution,n,resolution);
  35.        if ((rc = stat(name,&s))!=0) {
  36.            sprintf(name,"%s/dpi%d/%s.pxl",pathpt,resolution,n);
  37.            if ((rc = stat(name,&s))!=0) {
  38.                sprintf(name,"%s/pxl%ld/%s.pk",pathpt,fontmag,n);
  39.                if ((rc = stat(name,&s))!=0) {
  40.                    sprintf(name,"%s/pxl%ld/%s.pxl",pathpt,fontmag,n);
  41.                    if ((rc = stat(name,&s))!=0) {
  42. #ifndef MSDOS
  43.                       sprintf(name,"%s/%s.%dpk",pathpt,n,resolution);
  44.                       if ((rc = stat(name,&s))!=0) {
  45.                          sprintf(name,"%s/%s.%dpxl",pathpt,n,resolution);
  46.                          if ((rc = stat(name,&s))!=0) {
  47. #endif
  48.                             sprintf(name,"%s/%s.%d",pathpt,n,resolution);
  49.                             rc = stat(name,&s);
  50. #ifndef MSDOS
  51.                          }
  52.                       }
  53. #endif
  54.                    }
  55.                }
  56.            }
  57.        }
  58. #else
  59.        sprintf(name,"%s/%s.%dgf",pathpt,n,resolution);
  60.        if ((rc = stat(name,&s))!=0) {
  61.            sprintf(name,"%s/%s.%ldgf",pathpt,n,fontmag);
  62.            rc = stat(name,&s);
  63.        }
  64. #endif
  65.        if (rc==0) return(TRUE);
  66.      };
  67.  
  68. #ifdef FUTURE
  69.     for(i=0; (pathpt=path_segment((bool)(i==0),VFPATH,local_path))!=NULL;i++) {
  70.        sprintf(name,"%s/%s.vfm",pathpt,n);
  71.        printf("searching virtual font <%s>\n",name);
  72.        if (stat(name,&s) == 0) return(TRUE);
  73.     }
  74. #endif
  75.  
  76. #ifdef USEPXL
  77.     /* return error messaage */
  78.     sprintf(name,"font not found: <%s>/%s.<%d;%ld>gf",
  79.                   path,n,resolution,fontmag);
  80. #else
  81.     sprintf(name,"font not found: <%s>/<dpi%d;pxl%ld>/%s.<pk;pxl>",
  82.                   path,resolution,fontmag,n);
  83. #endif
  84.  
  85. return(FALSE);
  86. }
  87.  
  88. char *
  89. path_segment(first,full_path,local_path)
  90. bool first;
  91. char *full_path, *local_path;
  92. {
  93.     static char *pppt;
  94.     char *pathpt;
  95.  
  96.     if (first) pathpt = strcpy(local_path,full_path);
  97.     else pathpt = pppt;
  98.     if (pathpt != NULL) {
  99. #ifdef unix
  100.                    pppt = strchr(pathpt , ':' );
  101. #else
  102.                 pppt = strchr(pathpt , ';' );
  103. #endif
  104.                 if (pppt != NULL) {
  105.                    *pppt = '\0';
  106.                    pppt++;
  107.                    }
  108.         }
  109. return pathpt;
  110. }
  111.