Ejemplo n.º 1
0
Archivo: db.cpp Proyecto: nyaxt/ptnk
ssize_t
DB::Tx::tableGetName(int idx, BufferRef name)
{
	OverviewPage pgOvv(m_pio->readPage(m_pio->pgidStartPage()));
	
	return bufcpy(name, pgOvv.getTableName(idx));
}
Ejemplo n.º 2
0
int					get_next_line(int const fd, char **line)
{
	t_stock			*stock;
	static t_stock	*save;

	if (!line)
		return (-1);
	stock = save;
	if (!(stock = check_fd(fd, stock, &save)))
		return (-1);
	if (!(ft_strchr(stock->str, '\n')))
		stock->status = fill_tmp(stock);
	if (stock->status == -1)
		return (stock->status);
	stock->status = bufcpy(line, stock, save);
	return (stock->status);
}
Ejemplo n.º 3
0
int aflinread(void *ptr, off_t offset, size_t size)
{
	if ((offset + size) <= bufsize) {
/*		printf("."); fflush(stdout);*/
		bufcpy((unsigned char *)ptr, offset, size);
	} else {
/*		printf("\n%lu %lu %lu\n", (unsigned long) offset,
		(unsigned long) size,
		(unsigned long) bufsize);*/
/*		printf("*"); fflush(stdout);*/
		fseeko(fbuf, offset, SEEK_SET);
		if (fread(ptr, 1, size, fbuf) < size)
			return aferr(AFEDBIO);
	}

	return 0;
}
Ejemplo n.º 4
0
static Word*
subsub(Word *v, char *s, char *end)
{
	int nmid;
	Word *head, *tail, *w, *h;
	Word *a, *b, *c, *d;
	Bufblock *buf;
	char *cp, *enda;

	a = extractpat(s, &cp, "=%&", end);
	b = c = d = 0;
	if(PERCENT(*cp))
		b = extractpat(cp+1, &cp, "=", end);
	if(*cp == '=')
		c = extractpat(cp+1, &cp, "&%", end);
	if(PERCENT(*cp))
		d = stow(cp+1);
	else if(*cp)
		d = stow(cp);

	head = tail = 0;
	buf = newbuf();
	for(; v; v = v->next){
		h = w = 0;
		if(submatch(v->s, a, b, &nmid, &enda)){
			/* enda points to end of A match in source;
			 * nmid = number of chars between end of A and start of B
			 */
			if(c){
				h = w = wdup(c);
				while(w->next)
					w = w->next;
			}
			if(PERCENT(*cp) && nmid > 0){	
				if(w){
					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
				} else {
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					h = w = newword(buf->start);
				}
				buf->current = buf->start;
			}
			if(d && *d->s){
				if(w){

					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, d->s, strlen(d->s));
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
					w->next = wdup(d->next);
					while(w->next)
						w = w->next;
					buf->current = buf->start;
				} else
					h = w = wdup(d);
			}
		}
		if(w == 0)
			h = w = newword(v->s);
	
		if(head == 0)
			head = h;
		else
			tail->next = h;
		tail = w;
	}
	freebuf(buf);
	delword(a);
	delword(b);
	delword(c);
	delword(d);
	return head;
}
Ejemplo n.º 5
0
void
main(int argc, char **argv)
{
	Word *w;
	char *s, *temp;
	char *files[256], **f = files, **ff;
	int sflag = 0;
	int i;
	int tfd = -1;
	Biobuf tb;
	Bufblock *buf;
	Bufblock *whatif;

	/*
	 *  start with a copy of the current environment variables
	 *  instead of sharing them
	 */

	Binit(&bout, 1, OWRITE);
	buf = newbuf();
	whatif = 0;
	USED(argc);
	for(argv++; *argv && (**argv == '-'); argv++)
	{
		bufcpy(buf, argv[0], strlen(argv[0]));
		insert(buf, ' ');
		switch(argv[0][1])
		{
		case 'a':
			aflag = 1;
			break;
		case 'd':
			if(*(s = &argv[0][2]))
				while(*s) switch(*s++)
				{
				case 'p':	debug |= D_PARSE; break;
				case 'g':	debug |= D_GRAPH; break;
				case 'e':	debug |= D_EXEC; break;
				}
			else
				debug = 0xFFFF;
			break;
		case 'e':
			explain = &argv[0][2];
			break;
		case 'f':
			if(*++argv == 0)
				badusage();
			*f++ = *argv;
			bufcpy(buf, argv[0], strlen(argv[0]));
			insert(buf, ' ');
			break;
		case 'i':
			iflag = 1;
			break;
		case 'k':
			kflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case 't':
			tflag = 1;
			break;
		case 'u':
			uflag = 1;
			break;
		case 'w':
			if(whatif == 0)
				whatif = newbuf();
			else
				insert(whatif, ' ');
			if(argv[0][2])
				bufcpy(whatif, &argv[0][2], strlen(&argv[0][2]));
			else {
				if(*++argv == 0)
					badusage();
				bufcpy(whatif, &argv[0][0], strlen(&argv[0][0]));
			}
			break;
		default:
			badusage();
		}
	}
#ifdef	PROF
	{
		extern etext();
		monitor(main, etext, buf, sizeof buf, 300);
	}
#endif

	if(aflag)
		iflag = 1;
	usage();
	syminit();
	initenv();
	usage();

	/*
		assignment args become null strings
	*/
	temp = 0;
	for(i = 0; argv[i]; i++) if(utfrune(argv[i], '=')){
		bufcpy(buf, argv[i], strlen(argv[i]));
		insert(buf, ' ');
		if(tfd < 0){
			temp = maketmp();
			if(temp == 0) {
				perror("temp file");
				Exit();
			}
			close(create(temp, OWRITE, 0600));
			if((tfd = open(temp, 2)) < 0){
				perror(temp);
				Exit();
			}
			Binit(&tb, tfd, OWRITE);
		}
		Bprint(&tb, "%s\n", argv[i]);
		*argv[i] = 0;
	}
	if(tfd >= 0){
		Bflush(&tb);
		LSEEK(tfd, 0L, 0);
		parse("command line args", tfd, 1);
		remove(temp);
	}

	if (buf->current != buf->start) {
		buf->current--;
		insert(buf, 0);
	}
	symlook("MKFLAGS", S_VAR, (void *) stow(buf->start));
	buf->current = buf->start;
	for(i = 0; argv[i]; i++){
		if(*argv[i] == 0) continue;
		if(i)
			insert(buf, ' ');
		bufcpy(buf, argv[i], strlen(argv[i]));
	}
	insert(buf, 0);
	symlook("MKARGS", S_VAR, (void *) stow(buf->start));
	freebuf(buf);

	if(f == files){
		if(access(MKFILE, 4) == 0)
			parse(MKFILE, open(MKFILE, 0), 0);
	} else
		for(ff = files; ff < f; ff++)
			parse(*ff, open(*ff, 0), 0);
	if(DEBUG(D_PARSE)){
		dumpw("default targets", target1);
		dumpr("rules", rules);
		dumpr("metarules", metarules);
		dumpv("variables");
	}
	if(whatif){
		insert(whatif, 0);
		timeinit(whatif->start);
		freebuf(whatif);
	}
	execinit();
	/* skip assignment args */
	while(*argv && (**argv == 0))
		argv++;

	catchnotes();
	if(*argv == 0){
		if(target1)
			for(w = target1; w; w = w->next)
				mk(w->s);
		else {
			fprint(2, "mk: nothing to mk\n");
			Exit();
		}
	} else {
		if(sflag){
			for(; *argv; argv++)
				if(**argv)
					mk(*argv);
		} else {
			Word *head, *tail, *t;

			/* fake a new rule with all the args as prereqs */
			tail = 0;
			t = 0;
			for(; *argv; argv++)
				if(**argv){
					if(tail == 0)
						tail = t = newword(*argv);
					else {
						t->next = newword(*argv);
						t = t->next;
					}
				}
			if(tail->next == 0)
				mk(tail->s);
			else {
				head = newword("command line arguments");
				addrules(head, tail, strdup(""), VIR, mkinline, 0);
				mk(head->s);
			}
		}
	}
	if(uflag)
		prusage();
	exits(0);
}
Ejemplo n.º 6
0
static int setComand(char *comand, buffer_t values[], int nbValues){
  // modification du port
  if(!strcmp(comand, "port")){
    if(b_gl_port){
      return 0;
    }

    for(int i=0; i<nbValues; i++){
      // conversion numerique
      char *ptr = NULL;
      int res =  strtol(values[i].ptr, &ptr, 10);
      if(res > 0 && res < 65536 && ptr != values[i].ptr){
	gl_port = res;
	return 0;
      }
      
      // resolution de nom
      if(values[i].use >= 3){
	struct servent *serv = getservbyname(values[i].ptr, "tcp");
	if(serv != NULL){
	  gl_port = ntohs(serv->s_port);
	  return 0;
	}
	
	if(errno != 0){
	  perror("getservbyname");
	}
      }
    }

    fprintf(stderr, "%s: valeur de la commande invalide\n", comand);
    return 1;
  }

  // modification du mode
  if(!strcmp(comand, "mode")){
    if(b_gl_mode){
      return 0;
    }

    if(values[0].use == 0){
      fprintf(stderr, "%s: valeur null\n", comand);
      return 1;
    }

    if(!strncmp(values[0].ptr, "thread", 7)){
      gl_mode = 1;
      return 0;
    }else if(!strncmp(values[0].ptr, "select", 7)){
      gl_mode = 2;
      return 0;
    }

    fprintf(stderr, "%s: valeur de la commande invalide\n", comand);
    return 1;
  }

  // modification du temps de latence
  if(!strcmp(comand, "latence")){
    if(b_gl_close){
      return 0;
    }

    if(values[0].use == 0){
      fprintf(stderr, "%s: valeur null\n", comand);
      return 1;
    }

    char *ptr;
    int res =  strtol(values[0].ptr, &ptr, 10);
    if(res >= 0 && ptr != values[0].ptr){
      gl_close = res;
      return 0;
    }
    
    fprintf(stderr, "%s: valeur de la commande invalide\n", comand);
    return 1;
  }

  // modification de l'identifiant du serveur
  if(!strcmp(comand, "server")){
    if(values[0].use == 0){
      fprintf(stderr, "%s: valeur null\n", comand);
      return 1;
    }

    if(strchr(values[0].ptr, ':') != NULL){
      fprintf(stderr, "le caractere ':' est interdit dans l'indentifiant du serveur\n");
      return 1;
    }

    bufcpy(&gl_name, values);
    return 0;
  }

  // test des dossiers
  if(!strcmp(comand, "rootpath")){
    if(b_gl_www){
      return 0;
    }

    if(values[0].use == 0){
      fprintf(stderr, "%s: valeur null\n", comand);
      return 1;
    }
    
    int rep = open(values[0].ptr, O_DIRECTORY);
    if(rep != -1){
      close(rep);
      
      bufcpy(&gl_www, values);
      return 0;
    }

    perror("opendir");
    fprintf(stderr, "%s: valeur de la commande invalide\n", comand);
    return 1;
  }

  // test des fichiers
  if(!strcmp(comand, "errorlog") || !strcmp(comand, "accesslog")){
    if(values[0].use == 0){
      fprintf(stderr, "%s: valeur null\n", comand);
      return 1;
    }
    
    int file = open(values[0].ptr, 0);
    if(file != -1){
      close(file);
      
      if(!strcmp(comand, "errorlog")){
	bufcpy(&gl_logError, values);
      }else if(!strcmp(comand, "errorlog")){
	bufcpy(&gl_logAccess, values);
      }
      return 0;
    }

    perror("open");
    fprintf(stderr, "%s: valeur de la commande invalide\n", comand);
    return 1;
  }
  
  fprintf(stderr, "(Warning) %s: commande inconue\n", comand);
  return 0;
}