1: /* Copyright (c) 1979 Regents of the University of California */
   2: 
   3: static char sccsid[] = "@(#)GETNAME.c 1.12 10/18/85";
   4: 
   5: #include "h00vars.h"
   6: #include "libpc.h"
   7: 
   8: /*
   9:  * GETNAME - activate a file
  10:  *
  11:  * takes a name, name length, element size, and variable
  12:  * level and returns a pointer to a file structure.
  13:  *
  14:  * a new file structure is initialized if necessary.
  15:  * temporary names are generated, and given
  16:  * names are blank trimmed.
  17:  */
  18: 
  19: static char *tmpname = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  20: 
  21: struct iorec *
  22: GETNAME(filep, name, namlim, datasize)
  23: 
  24:     register struct iorec   *filep;
  25:     char            *name;
  26:     long            namlim;
  27:     long            datasize;
  28: {
  29:     int     maxnamlen = namlim;
  30:     struct iorec    *prev;
  31:     struct iorec    *next;
  32:     register int    cnt;
  33:     struct iorec    locvar;
  34: 
  35:     if (filep->fblk < MAXFILES && _actfile[filep->fblk] == filep) {
  36:         /*
  37: 		 * Close and immediately reactivate the file.
  38: 		 */
  39:         PFCLOSE(filep, name != NULL);
  40:         _actfile[filep->fblk] = filep;
  41:         filep->funit &= (TEMP | FTEXT);
  42:     } else {
  43:         /*
  44: 		 * Initialize a new file record.
  45: 		 */
  46:         filep->funit = 0;
  47:         if (datasize == 0) {
  48:             filep->funit |= FTEXT;
  49:             datasize = 1;
  50:         }
  51:         filep->fsize = datasize;
  52:         filep->fbuf = 0;
  53:         filep->lcount = 0;
  54:         filep->llimit = 0x7fffffff;
  55:         filep->fileptr = &filep->window[0];
  56:         *filep->fname = NULL;
  57:         /*
  58: 		 * Check to see if file is global, or allocated in
  59: 		 * the stack by checking its address against the
  60: 		 * address of one of our routine's local variables.
  61: 		 */
  62:         if (filep < &locvar)
  63:             filep->flev = GLVL;
  64:         else
  65:             filep->flev = filep;
  66:         for (_filefre++; _filefre < MAXFILES; _filefre++)
  67:             if (_actfile[_filefre] == FILNIL)
  68:                 goto gotone;
  69:         for (_filefre = PREDEF + 1; _filefre < MAXFILES; _filefre++)
  70:             if (_actfile[_filefre] == FILNIL)
  71:                 goto gotone;
  72:         ERROR("File table overflow\n");
  73:         return;
  74: gotone:
  75:         filep->fblk = _filefre;
  76:         _actfile[_filefre] = filep;
  77:         /*
  78: 		 * Link the new record into the file chain.
  79: 		 */
  80:         prev = (struct iorec *)&_fchain;
  81:         next = _fchain.fchain;
  82:         while (filep->flev > next->flev) {
  83:             prev = next;
  84:             next = next->fchain;
  85:         }
  86:         if (filep->flev == GLVL)
  87:             /*
  88: 			 * Must order global files so that all dynamic files
  89: 			 * within a record are grouped together.
  90: 			 */
  91:             while ((next != FILNIL) &&
  92:                    (next->flev == GLVL) &&
  93:                    ((struct iorec *)filep > next)) {
  94:                 prev = next;
  95:                 next = next->fchain;
  96:             }
  97:         filep->fchain = next;
  98:         prev->fchain = filep;
  99:     }
 100:     /*
 101: 	 * Get the filename associated with the buffer.
 102: 	 */
 103:     if (name == NULL) {
 104:         if (*filep->fname != NULL) {
 105:             return(filep);
 106:         }
 107:         /*
 108: 		 * No name given and no previous name, so generate
 109: 		 * a new one of the form #tmp.xxxxxx.
 110: 		 */
 111:         filep->funit |= TEMP;
 112:         sprintf(filep->fname, "#tmp.%c%d", tmpname[filep->fblk],
 113:             getpid());
 114:         filep->pfname = &filep->fname[0];
 115:         return(filep);
 116:     }
 117:     /*
 118: 	 * Trim trailing blanks, and insure that the name
 119: 	 * will fit into the file structure.
 120: 	 */
 121:     for (cnt = 0; cnt < maxnamlen; cnt++)
 122:         if (name[cnt] == '\0' || name[cnt] == ' ')
 123:             break;
 124:     if (cnt >= NAMSIZ) {
 125:         ERROR("%s: File name too long\n", name);
 126:         return;
 127:     }
 128:     maxnamlen = cnt;
 129:     filep->funit &= ~TEMP;
 130:     /*
 131: 	 * Put the new name into the structure.
 132: 	 */
 133:     for (cnt = 0; cnt < maxnamlen; cnt++)
 134:         filep->fname[cnt] = name[cnt];
 135:     filep->fname[cnt] = '\0';
 136:     filep->pfname = &filep->fname[0];
 137:     return(filep);
 138: }

Defined functions

Defined variables

sccsid defined in line 3; never used
tmpname defined in line 19; used 1 times
Last modified: 1985-11-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1152
Valid CSS Valid XHTML 1.0 Strict