home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / addr / ap_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.7 KB  |  114 lines

  1. /* ap_file.c: ap file handling routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_file.c,v 6.0 1991/12/18 20:21:24 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_file.c,v 6.0 1991/12/18 20:21:24 jpo Rel $
  9.  *
  10.  * $Log: ap_file.c,v $
  11.  * Revision 6.0  1991/12/18  20:21:24  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "ap.h"
  20.  
  21. /*
  22. parse state saving uses a linked list of state information, recorded in
  23. ap_prevstruct structures. the list is manipulated as a simple stack.
  24. */
  25.  
  26. static struct ap_prevstruct     *ap_file; /* -- parse state top of stack -- */
  27. extern int                      (*ap_gfunc)(); /* -- ptr to char get fn -- */
  28. extern int                      ap_peek; /* -- basic parse state info -- */
  29. extern int                      ap_perlev;
  30. extern int                      ap_grplev;
  31. extern AP_ptr                   ap_pstrt,
  32.                 ap_pcur;
  33.  
  34. int ap_ppush (gfunc)   /* -- save parse context, ap_iinit -- */
  35. int     (*gfunc)();
  36. {
  37.     register struct ap_prevstruct  *tfil;
  38.  
  39.     if ((tfil = (struct ap_prevstruct *)
  40.             malloc (sizeof (struct ap_prevstruct))) ==
  41.                 (struct ap_prevstruct *) NOTOK)
  42.                     return (NOTOK);
  43.  
  44.     tfil -> ap_opeek    = ap_peek;   /* -- save regular parse info -- */
  45.     tfil -> ap_ogroup   = ap_grplev;
  46.     tfil -> ap_operson  = ap_perlev;
  47.     tfil -> ap_prvgfunc = ap_gfunc;
  48.     tfil -> ap_next     = ap_file;   /* -- save previous stack entry -- */
  49.     ap_file             = tfil;      /* -- save current stack entry -- */
  50.     ap_iinit (gfunc);                /* -- create new parse state -- */
  51.     return (OK);
  52. }
  53.  
  54.  
  55.  
  56. void ap_ppop()  /* -- restore previous parse state -- */
  57. {
  58.     register struct ap_prevstruct  *tfil;
  59.  
  60.     tfil            = ap_file;
  61.     ap_peek         = tfil -> ap_opeek;
  62.     ap_grplev       = tfil -> ap_ogroup;
  63.     ap_perlev       = tfil -> ap_operson;
  64.     ap_gfunc        = tfil -> ap_prvgfunc;
  65.     ap_file         = tfil -> ap_next;
  66.     free ((char *) tfil);
  67. }
  68.  
  69.  
  70.  
  71. /*
  72. the next three routines handle most of the overhead for acquiring
  73. the address list from a file.
  74. */
  75.  
  76.  
  77. int ap_flget()  /* -- get character from included file -- */
  78. {
  79.     register int    c;
  80.  
  81.     c = getc (ap_file -> ap_curfp);
  82.  
  83.     if (c == '\n')
  84.         return (',');   /* -- a minor convenience -- */
  85.  
  86.     return (c);
  87. }
  88.  
  89.  
  90.  
  91. int ap_fpush (file)  /* -- indirect input from file -- */
  92. char    file[];
  93. {
  94.     if (ap_ppush (ap_flget) == NOTOK)
  95.         /* -- save current & set for file input -- */
  96.         return (NOTOK);
  97.  
  98.     if ((ap_file -> ap_curfp = fopen (file, "r")) == NULLFILE) {
  99.         /* -- couldn't get the file, tho -- */
  100.         ap_ppop();
  101.         return (NOTOK);
  102.     }
  103.     return (OK);
  104. }
  105.  
  106.  
  107.  
  108. void ap_fpop()  /* -- pop the stack, if any input nested -- */
  109. {
  110.     if (ap_file -> ap_curfp != NULLFILE)
  111.         (void) fclose (ap_file -> ap_curfp);
  112.     ap_ppop();
  113. }
  114.