Ejemplo n.º 1
0
/*
 * Initialize the local and parameter symbol table information.
 */
void
initlocals(void)
{
	initstr(&localnames);
	initstr(&paramnames);
	curfunc->f_localcount = 0;
	curfunc->f_paramcount = 0;
}
Ejemplo n.º 2
0
/*
 * kernel commandline can be read from /proc/cmdline
 */
static int cmdline_parse()
{
	char *p, buf[512];
	int fd;
	ssize_t n;
	
	fd = open("/proc/cmdline", O_RDONLY);
	if(fd >= 0) {
		n = read(fd, buf, sizeof(buf)-1);
		if(n > 0) {
			buf[n] = 0;
			p = initstr(buf, "rootdelay=");
			if(p) {
				cmdline.rootdelay = strtoul(p+10, NULL, 0);
			}
			p = initstr(buf, "root=");
			if(p) {
				cmdline.rootdev = strdup(p+5);
				strgetarg(&cmdline.rootdev);
			}
			p = initstr(buf, "rootfstype=");
			if(p) {
				cmdline.rootfstype = strdup(p+11);
				strgetarg(&cmdline.rootfstype);
			}
			p = initstr(buf, "init=");
			if(p) {
				cmdline.init = strdup(p+5);
				strgetarg(&cmdline.init);
			}
			p = initstr(buf, "rootfslabel=");
			if(p) {
				cmdline.rootfslabel = strdup(p+12);
				strgetarg(&cmdline.rootfslabel);
			}
			p = initstr(buf, "usbreset");
			if(p) {
				cmdline.usbreset = 1;
			}
			p = initstr(buf, "async");
			if(p) {
				cmdline.async = 1;
			}
			p = initstr(buf, "noresize");
			if(p) {
				cmdline.autoresize = 0;
			}
			p = initstr(buf, "install");
			if(p) {
				cmdline.install = 1;
			}
		}
		close(fd);
	}
	return 0;
}
Ejemplo n.º 3
0
void
scompile(		/* get definitions from a string */
	char  *str,
	char  *fn,
	int  ln
)
{
    initstr(str, fn, ln);
    while (nextc != EOF)
	getstatement();
}
Ejemplo n.º 4
0
/*
 * Initialize the global symbol table.
 */
void
initglobals(void)
{
	int i;		/* index counter */

	for (i = 0; i < HASHSIZE; i++)
		globalhash[i] = NULL;
	initstr(&globalnames);
	filescope = SCOPE_STATIC;
	funcscope = 0;
}
Ejemplo n.º 5
0
Archivo: 100.c Proyecto: leolas95/c
int main(int argc, char **argv)
{
	FILE *fp;
	if (argc == 1) {
		puts("ERROR - NO ARGUMENTS");
	} else {
		char badword[MAXLENGTH];
		strncpy(badword, argv[1], MAXLENGTH);
		int badwlen = strnlen(badword, MAXLENGTH);
		initstr(badword, badwlen);
	}
	return 0;
}
Ejemplo n.º 6
0
EPNODE *
eparse(			/* parse an expression string */
    char  *expr
)
{
    EPNODE  *ep;

    initstr(expr, NULL, 0);
    curfunc = NULL;
    ep = getE1();
    if (nextc != EOF)
	syntax("unexpected character");
    return(ep);
}
Ejemplo n.º 7
0
/*
 * Initialize the table of user defined functions.
 */
void
initfunctions()
{
	initstr(&funcnames);
	maxopcodes = OPCODEALLOCSIZE;
	functemplate = (FUNC *) malloc(funcsize(maxopcodes));
	if (functemplate == NULL)
		math_error("Cannot allocate function template");
	functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
	if (functions == NULL)
		math_error("Cannot allocate function table");
	funccount = 0;
	funcavail = FUNCALLOCSIZE;
}
Ejemplo n.º 8
0
/*
 * Define a (possibly) new element name for an object.
 * Returns an index which identifies the element name.
 */
int
addelement(char *name)
{
	STRINGHEAD *hp;
	int index;

	hp = &elements;
	if (hp->h_list == NULL)
		initstr(hp);
	index = findstr(hp, name);
	if (index >= 0)
		return index;
	if (addstr(hp, name) == NULL) {
		math_error("Cannot allocate element name");
		/*NOTREACHED*/
	}
	return findstr(hp, name);
}
Ejemplo n.º 9
0
int	main()
{
  int	pid;
  char  *client_pid;

  client_pid = NULL;
  client_pid = initstr(client_pid);
  recep.client_cond = 0;
  recep.cond = 0;
  pid = getpid();
  my_put_nbr(pid);
  recep.pbit = 0;
  recep.lastpbit = recep.pbit;
  signal(SIGUSR1, get_sig1);
  signal(SIGUSR2, get_sig2);
  serv_loop(client_pid);
  return (0);
}
Ejemplo n.º 10
0
int	serv_loop(char *client_pid)
{
  while (1)
    {
      if (recep.pbit == 8 && recep.client_cond == 0)
	client_pid = recep_pid(client_pid);
      if (recep.pbit == 8 && recep.client_cond == -1)
	{
	  recep = fill_union(recep);
	  if (recep.byte.u8loctet == 0)
	    {
	      recep.pbit = -1;
	      client_pid = initstr(client_pid);
	      recep.client_cond = 0;
	    }
	  my_putchar(recep.byte.u8loctet);
	}
      if (recep.pbit == -1)
	recep.pbit = 0;
      while (recep.cond != 1);
      recep.cond = 0;
    }
  return (0);
}
Ejemplo n.º 11
0
/*
 * Define a (possibly) new class of objects.
 * The list of indexes for the element names is also specified here,
 * and the number of elements defined for the object.
 *
 * given:
 *	name		name of object type
 *	indices		table of indices for elements
 *	count		number of elements defined for the object
 */
int
defineobject(char *name, int indices[], int count)
{
	OBJECTACTIONS *oap;	/* object definition structure */
	STRINGHEAD *hp;
	OBJECTACTIONS **newobjects;
	int index;

	hp = &objectnames;
	if (hp->h_list == NULL)
		initstr(hp);
	index = findstr(hp, name);
	if (index >= 0) {
		/*
		 * Object is already defined.  Give an error unless this
		 * new definition is exactly the same as the old one.
		 */
		oap = objects[index];
		if (oap->oa_count == count) {
			for (index = 0; ; index++) {
				if (index >= count)
					return 0;
				if (oap->oa_elements[index] != indices[index])
					break;
			}
		}
		return 1;
	}

	if (hp->h_count >= maxobjcount) {
		if (maxobjcount == 0) {
			newobjects = (OBJECTACTIONS **) malloc(
				OBJALLOC * sizeof(OBJECTACTIONS *));
			maxobjcount = OBJALLOC;
		} else {
			maxobjcount += OBJALLOC;
			newobjects = (OBJECTACTIONS **) realloc(objects,
				maxobjcount * sizeof(OBJECTACTIONS *));
		}
		if (newobjects == NULL) {
			math_error("Allocation failure for new object type");
			/*NOTREACHED*/
		}
		objects = newobjects;
	}

	oap = (OBJECTACTIONS *) malloc(objectactionsize(count));
	name = addstr(hp, name);
	if ((oap == NULL) || (name == NULL)) {
		math_error("Cannot allocate object type");
		/*NOTREACHED*/
	}
	oap->oa_count = count;
	for (index = OBJ_MAXFUNC; index >= 0; index--)
		oap->oa_indices[index] = -1;
	for (index = 0; index < count; index++)
		oap->oa_elements[index] = indices[index];
	index = findstr(hp, name);
	oap->oa_index = index;
	objects[index] = oap;
	return 0;
}
Ejemplo n.º 12
0
int main(int argc, char **argv)
{
  int ch;
  int i;
  dynstr nam1;
  size_t nam1baselen;
  d * dp;
  DIR *dh;
  struct dirent *di;
  while ((ch = getopt (argc, argv, "cnvh")) != -1) {
    switch (ch) {
    case 'n':
      no_link++;
      break;
    case 'v':
      verbose++;
      break;
    case 'c':
      content_only++;
      break;
    case 'h':
    default:
      usage(argv[0]);
    }
  }
  if (optind >= argc)
    usage(argv[0]);
  for (i = optind; i < argc; i++)
    rf(argv[i]);
  initstr(&nam1);
  while (dirs) {
    dp = dirs;
    dirs = dp->next;
    growstr(&nam1, add2(nam1baselen = strlen(dp->name), 1));
    memcpy(nam1.buf, dp->name, nam1baselen);
    free (dp);
    nam1.buf[nam1baselen++] = '/';
    nam1.buf[nam1baselen] = 0;
    dh = opendir (nam1.buf);
    if (dh == NULL)
      continue;
    ndirs++;
    while ((di = readdir (dh)) != NULL) {
      if (!di->d_name[0])
        continue;
      if (di->d_name[0] == '.') {
        char *q;
        if (!di->d_name[1] || !strcmp (di->d_name, "..") || !strncmp (di->d_name, ".in.", 4))
          continue;
        q = strrchr (di->d_name, '.');
        if (q && strlen (q) == 7 && q != di->d_name) {
          nam1.buf[nam1baselen] = 0;
          if (verbose)
            fprintf(stderr, "Skipping %s%s\n", nam1.buf, di->d_name);
          continue;
        }
      }
      {
        size_t subdirlen;
        growstr(&nam1, add2(nam1baselen, subdirlen = strlen(di->d_name)));
        memcpy(&nam1.buf[nam1baselen], di->d_name, add2(subdirlen, 1));
      }
      rf(nam1.buf);
    }
    closedir(dh);
  }
  doexit(0);
  return 0;
}
Ejemplo n.º 13
0
static void rf (char *name)
{
  struct stat st, st2, st3;
  nobjects++;
  if (lstat (name, &st))
    return;
  if (S_ISDIR (st.st_mode)) {
    size_t namelen;
    d * dp = malloc(add3(sizeof(d), namelen = strlen(name), 1));
    if (!dp) {
      fprintf(stderr, "\nOut of memory 3\n");
      doexit(3);
    }
    memcpy(dp->name, name, namelen + 1);
    dp->next = dirs;
    dirs = dp;
  } else if (S_ISREG (st.st_mode)) {
    int fd, i;
    f * fp, * fp2;
    h * hp;
    char *n1, *n2;
    int cksumsize = sizeof(buf);
    unsigned int cksum;
    time_t mtime = content_only ? 0 : st.st_mtime;
    unsigned int hsh = hash (st.st_size, mtime);
    off_t fsize;
    nregfiles++;
    if (verbose > 1)
      fprintf(stderr, "  %s", name);
    fd = open (name, O_RDONLY | O_NOCTTY | O_NOFOLLOW);
    if (fd < 0) return;
    if (st.st_size < sizeof(buf)) {
      cksumsize = st.st_size;
      memset (((char *)buf) + cksumsize, 0, (sizeof(buf) - cksumsize) % sizeof(buf[0]));
    }
    if (read (fd, buf, cksumsize) != cksumsize) {
      close(fd);
      if (verbose > 1) {
        size_t namelen = strlen(name);
        if (namelen <= NAMELEN)
          fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
      }
      return;
    }
    cksumsize = (cksumsize + sizeof(buf[0]) - 1) / sizeof(buf[0]);
    for (i = 0, cksum = 0; i < cksumsize; i++) {
      if (cksum + buf[i] < cksum)
        cksum += buf[i] + 1;
      else
        cksum += buf[i];
    }
    for (hp = hps[hsh]; hp; hp = hp->next)
      if (hp->size == st.st_size && hp->mtime == mtime)
        break;
    if (!hp) {
      hp = malloc(sizeof(h));
      if (!hp) {
        fprintf(stderr, "\nOut of memory 1\n");
        doexit(1);
      }
      hp->size = st.st_size;
      hp->mtime = mtime;
      hp->chain = NULL;
      hp->next = hps[hsh];
      hps[hsh] = hp;
    }
    for (fp = hp->chain; fp; fp = fp->next)
      if (fp->cksum == cksum)
        break;
    for (fp2 = fp; fp2 && fp2->cksum == cksum; fp2 = fp2->next)
      if (fp2->ino == st.st_ino && fp2->dev == st.st_dev) {
        close(fd);
        if (verbose > 1) {
          size_t namelen = strlen(name);
          if (namelen <= NAMELEN)
            fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
        }
        return;
      }
    for (fp2 = fp; fp2 && fp2->cksum == cksum; fp2 = fp2->next)
      if (!lstat (fp2->name, &st2) && S_ISREG (st2.st_mode) &&
          !stcmp (&st, &st2, content_only) &&
          st2.st_ino != st.st_ino &&
          st2.st_dev == st.st_dev) {
        int fd2 = open (fp2->name, O_RDONLY | O_NOCTTY | O_NOFOLLOW);
        if (fd2 < 0) continue;
        if (fstat (fd2, &st2) || !S_ISREG (st2.st_mode) || st2.st_size == 0) {
          close (fd2);
          continue;
        }
        ncomp++;
	if (lseek(fd, 0, SEEK_SET)) {
          close(fd);
          close(fd2);
          fprintf(stderr, "\nSeeking error\n");
          return;
        }
	for (fsize = st.st_size; fsize > 0; fsize -= NIOBUF) {
	  off_t rsize = fsize >= NIOBUF ? NIOBUF : fsize;
	  if (read (fd, iobuf1, rsize) != rsize || read (fd2, iobuf2, rsize) != rsize) {
	    close(fd);
	    close(fd2);
	    fprintf(stderr, "\nReading error\n");
	    return;
	  }
	  if (memcmp (iobuf1, iobuf2, rsize)) break;
	}
	close(fd2);
	if (fsize > 0) continue;
        if (lstat (name, &st3)) {
          fprintf(stderr, "\nCould not stat %s again\n", name);
          close(fd);
          return;
        }
        st3.st_atime = st.st_atime;
        if (stcmp (&st, &st3, 0)) {
          fprintf(stderr, "\nFile %s changed underneath us\n", name);
          close(fd);
          return;
        }
        n1 = fp2->name;
        n2 = name;
        if (!no_link) {
          const char *suffix = ".$$$___cleanit___$$$";
          const size_t suffixlen = strlen(suffix);
          size_t n2len = strlen(n2);
          dynstr nam2;
          initstr(&nam2);
          growstr(&nam2, add2(n2len, suffixlen));
          memcpy(nam2.buf, n2, n2len);
          memcpy(&nam2.buf[n2len], suffix, suffixlen + 1);
          if (rename (n2, nam2.buf)) {
            fprintf(stderr, "\nFailed to rename %s to %s\n", n2, nam2.buf);
            free(nam2.buf);
            continue;
          }
          if (link (n1, n2)) {
            fprintf(stderr, "\nFailed to hardlink %s to %s\n", n1, n2);
            if (rename (nam2.buf, n2)) {
              fprintf(stderr, "\nBad bad - failed to rename back %s to %s\n", nam2.buf, n2);
            }
            close(fd);
            free(nam2.buf);
            return;
          }
          unlink (nam2.buf);
          free(nam2.buf);
        }
        nlinks++;
        if (st3.st_nlink > 1) {
	  /* We actually did not save anything this time, since the link second argument
	     had some other links as well.  */
          if (verbose > 1) {
            size_t namelen = strlen(name);
            if (namelen > NAMELEN)
              namelen = 0;
            fprintf(stderr, "\r%*s\r%s %s to %s\n", (int)(namelen + 2), "", (no_link ? "Would link" : "Linked"), n1, n2);
          }
        } else {
          nsaved+=((st.st_size+4095)/4096)*4096;
          if (verbose > 1) {
            size_t namelen = strlen(name);
            if (namelen > NAMELEN)
              namelen = 0;
            fprintf(stderr, "\r%*s\r%s %s to %s, %s %ld\n", (int)(namelen + 2), "", (no_link ? "Would link" : "Linked"), n1, n2, (no_link ? "would save" : "saved"), st.st_size);
          }
	}
        close(fd);
        return;
      }
    {
      size_t namelen;
      fp2 = malloc(add3(sizeof(f), namelen = strlen(name), 1));
      if (!fp2) {
        fprintf(stderr, "\nOut of memory 2\n");
        doexit(2);
      }
      close(fd);
      fp2->ino = st.st_ino;
      fp2->dev = st.st_dev;
      fp2->cksum = cksum;
      memcpy(fp2->name, name, namelen + 1);
      if (fp) {
        fp2->next = fp->next;
        fp->next = fp2;
      } else {
        fp2->next = hp->chain;
        hp->chain = fp2;
      }
      if (verbose > 1 && namelen <= NAMELEN)
        fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
    }
    return;
  }
}
Ejemplo n.º 14
0
/*
 * Initialize the table of labels for a function.
 */
void
initlabels(void)
{
	labelcount = 0;
	initstr(&labelnames);
}