1: #if !defined(lint) && defined(DOSCCS)
   2: static char sccsid[] = "@(#)context.c	3.7.1 1996/3/22";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include <stdio.h>
  12: #include "defs.h"
  13: #include "value.h"
  14: #include "string.h"
  15: #include "context.h"
  16: 
  17: /*
  18:  * Context push/pop for nested command files.
  19:  */
  20: 
  21: cx_alloc()
  22: {
  23:     register struct context *xp;
  24: 
  25:     if (cx.x_type != 0) {
  26:         xp = (struct context *)
  27:             malloc((unsigned) sizeof (struct context));
  28:         if (xp == 0)
  29:             return -1;
  30:         *xp = cx;
  31:         cx.x_link = xp;
  32:         cx.x_type = 0;
  33:     }
  34:     cx.x_erred = 0;
  35:     cx.x_synerred = 0;
  36:     cx.x_abort = 0;
  37:     return 0;
  38: }
  39: 
  40: cx_free()
  41: {
  42:     struct context *xp;
  43: 
  44:     if ((xp = cx.x_link) != 0) {
  45:         cx = *xp;
  46:         free((char *)xp);
  47:     } else
  48:         cx.x_type = 0;
  49: }
  50: 
  51: cx_beginfile(filename)
  52: char *filename;
  53: {
  54:     if (cx_alloc() < 0)
  55:         return -1;
  56:     cx.x_type = X_FILE;
  57:     if ((cx.x_filename = str_cpy(filename)) == 0)
  58:         goto bad;
  59:     cx.x_fp = fopen(filename, "r");
  60:     if (cx.x_fp == 0)
  61:         goto bad;
  62:     cx.x_bol = 1;
  63:     cx.x_lineno = 0;
  64:     cx.x_errwin = 0;
  65:     cx.x_noerr = 0;
  66:     return 0;
  67: bad:
  68:     if (cx.x_filename != 0)
  69:         str_free(cx.x_filename);
  70:     cx_free();
  71:     return -1;
  72: }
  73: 
  74: cx_beginbuf(buf, arg, narg)
  75: char *buf;
  76: struct value *arg;
  77: int narg;
  78: {
  79:     if (cx_alloc() < 0)
  80:         return -1;
  81:     cx.x_type = X_BUF;
  82:     cx.x_bufp = cx.x_buf = buf;
  83:     cx.x_arg = arg;
  84:     cx.x_narg = narg;
  85:     return 0;
  86: }
  87: 
  88: cx_end()
  89: {
  90:     switch (cx.x_type) {
  91:     case X_BUF:
  92:         break;
  93:     case X_FILE:
  94:         (void) fclose(cx.x_fp);
  95:         str_free(cx.x_filename);
  96:         break;
  97:     }
  98:     cx_free();
  99: }

Defined functions

cx_alloc defined in line 21; used 2 times
cx_beginbuf defined in line 74; used 1 times
cx_beginfile defined in line 51; used 1 times
cx_end defined in line 88; used 2 times
cx_free defined in line 40; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1996-03-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 629
Valid CSS Valid XHTML 1.0 Strict