home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / FaxView.m < prev    next >
Encoding:
Text File  |  1993-01-27  |  4.4 KB  |  165 lines

  1. /* Generated by tgr */
  2.  
  3. #import "FaxView.h"
  4. #include <string.h>
  5.  
  6. @implementation FaxView
  7.  
  8. extern char *faxname ;
  9. static int maxpage ;
  10. + new {
  11.    static NXRect fr = { { 0.0, 0.0 } , { 10.0, 400.0 } } ;
  12.  
  13.    self = [[super new] initFrame:&fr] ;
  14.    return self ;
  15. }
  16.  
  17. - faxPSCode:sender {
  18.    return [super faxPSCode:sender] ;
  19. }
  20. static FILE *f ;
  21. #define LINELEN (400)
  22. static char line[LINELEN] ;
  23. - beginPrologueBBox:(const NXRect *)boundingBox creationDate:(const char *)date
  24.    createdBy:(const char *)anApplication fonts:(const char *)fontNames
  25.    forWhom:(const char *)user pages:(int)numPages title:(const char *)aTitle {
  26.    int i ;
  27.    int numtopass = 0 ;
  28.    char *tp ;
  29.    char tbuf[20000] ;
  30.    char *ignored[100] ;
  31.    extern void error() ;
  32.    extern char *strcpy() ;
  33.    NXRect bb ;
  34.  
  35.    tp = tbuf ;
  36.    if (boundingBox)
  37.       bb = *boundingBox ;
  38.    f = fopen(faxname, "r") ;
  39.    if (f == 0) {
  40.       [super beginPrologueBBox:boundingBox creationDate:date
  41.          createdBy:anApplication fonts:fontNames
  42.          forWhom:user pages:numPages title:aTitle] ;
  43.       return self ;
  44.    }
  45.    fgets(line, LINELEN, f) ;
  46.    while (fgets(line, LINELEN, f)) {
  47.       if (strncmp(line, "%%EndComments", 13)==0)
  48.          break ;
  49.       if (strlen(line) + tp > tbuf + 19990)
  50.          error("! too many header comments?") ;
  51.       strcpy(tp, line) ;
  52.       if (strncmp(line, "%%Creator: ", 11) == 0) {
  53.          anApplication = tp + 11 ;
  54.       } else if (strncmp(line, "%%Title: ", 9) == 0) {
  55.          aTitle = tp + 9 ;
  56.       } else if (strncmp(line, "%%CreationDate: ", 16) == 0) {
  57.          date = tp + 16 ;
  58.       } else if (strncmp(line, "%%For: ", 7) == 0) {
  59.          user = tp + 7 ;
  60.       } else if (strncmp(line, "%%Pages: ", 9) == 0) {
  61.          int nump ;
  62.          sscanf(tp + 9, "%d", &nump) ;
  63.          numPages = nump ;
  64.          maxpage = nump ;
  65.       } else if (strncmp(line, "%%BoundingBox: ", 15) == 0) {
  66.          int llx, lly, urx, ury ;
  67.          sscanf(tp + 15, "%d %d %d %d", &llx, &lly, &urx, &ury) ;
  68.          bb.origin.x = llx ;
  69.          bb.origin.y = lly ;
  70.          bb.size.width = urx - llx ;
  71.          bb.size.height = ury - lly ;
  72.          boundingBox = &bb ;
  73.       } else {
  74.          ignored[numtopass++] = tp ;
  75.       }
  76.       tp = tp + strlen(tp) - 1 ;
  77.       *tp++ = 0 ;
  78.    }
  79.    [super beginPrologueBBox:boundingBox creationDate:date
  80.       createdBy:anApplication fonts:(const char *)""
  81.       forWhom:user pages:numPages title:aTitle] ;
  82.    [super endHeaderComments] ;
  83.    for (i=0; i<numtopass; i++)
  84.       DPSPrintf(DPSGetCurrentContext(), "%s\n", ignored[i]) ;
  85.    while (fgets(line, LINELEN, f)) {
  86. /* we're at the `real' trailer if we hit the %%Trailer comment with
  87.    less than 100 bytes to go.  This is a kludge but it works for dvips
  88.    output, which is the only output we care about.  Note that this code
  89.    will seek for every %%Trailer seen, but that shouldn't be too often. */
  90.       if (strncmp(line, "%%Trailer", 9) == 0) {
  91.          char dummy[100] ;
  92.          long t = ftell(f) ;
  93.          if (fread(dummy, 1, 100, f) < 100) {
  94.             fseek(f, t, 0) ;
  95.             break ;
  96.          }
  97.          fseek(f, t, 0) ;
  98.       }
  99.       DPSPrintf(DPSGetCurrentContext(), "%s", line) ;
  100.    }
  101. /*
  102.  *   Now we disable the coversheet page number, after printing our own.
  103.  *   Serious kludge! 
  104.    DPSPrintf(DPSGetCurrentContext(), "%%%%Page: Coversheet %d\n%%%%%%",
  105.                       numPages+1) ; */
  106.    return self ;
  107. }
  108. - endHeaderComments {
  109.    return self ;
  110. }
  111.  
  112. - endPrologue {
  113.    return self ;
  114. }
  115. - beginSetup {
  116.    return self ;
  117. }
  118. - endSetup {
  119.    return self ;
  120. }
  121. - beginPageSetupRect:(const NXRect *)ar placement:(const NXPoint *)loc {
  122.    return self ;
  123. }
  124. - endPageSetup {
  125.    return self ;
  126. }
  127. - beginPage:(int)ord label:(const char *)as bBox:(const NXRect *)pr
  128.     fonts:(const char *)fn {
  129.    return self ;
  130. }
  131. - endPage {
  132.    return self ;
  133. }
  134. - beginTrailer {
  135.    if (f) {
  136.       DPSPrintf(DPSGetCurrentContext(), "%s", line) ;
  137.       while (fgets(line, LINELEN, f))
  138.          DPSPrintf(DPSGetCurrentContext(), "%s", line) ;
  139.       fclose(f) ;
  140.       f = 0 ;
  141.    }
  142.    return self ;
  143. }
  144. - endTrailer {
  145.    return self ;
  146. }
  147. - copyPSCodeInside:(const NXRect *)rect to:(NXStream *)stream {
  148.    return self ;
  149. }
  150.  
  151. - (BOOL)knowsPagesFirst:(int *)fpn last:(int *)lpn {
  152.    return YES ;
  153. }
  154. - (BOOL)getRect:(NXRect *)theRect forPage:(int)page {
  155.    if (page > maxpage)
  156.       return NO ;
  157.    theRect->origin.x = 0 ;
  158.    theRect->size.width = 10.0 ;
  159.    theRect->origin.y = 400.0 * (page - 1) / (maxpage + 1) ;
  160.    theRect->size.height = 400.0 / (maxpage + 1) ;
  161.    return YES ;
  162. }
  163.  
  164. @end
  165.