Exemplo n.º 1
0
static void do_get(const char *action)
{
  unsigned long u;
  struct stat st;
  char ch;
  int r;
  unsigned int pos;
  int fd;

  if (!flagget)
    strerr_die2x(100,FATAL,MSG(ERR_NOT_AVAILABLE));
  hdr_subject(MSG(SUB_GET_MSG));
  hdr_ctboundary();
  copy(&qq,"text/top",flagcd);

  pos = str_len(ACTION_GET);
  if (!case_starts(action,ACTION_GET))
    pos = str_len(ALT_GET);

  if (action[pos] == '.' || action [pos] == '_') pos++;
  scan_ulong(action + pos,&u);

  stralloc_copys(&line,"archive/");
  stralloc_catb(&line,strnum,fmt_ulong(strnum,u / 100));
  stralloc_cats(&line,"/");
  stralloc_catb(&line,strnum,fmt_uint0(strnum,(unsigned int) (u % 100),2));
  stralloc_0(&line);

  fd = open_read(line.s);
  if (fd == -1)
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,line.s));
    else
      copy_act("text/get-bad");
  else {
    if (fstat(fd,&st) == -1)
      copy_act("text/get-bad");
    else if (!(st.st_mode & 0100))
      copy_act("text/get-bad");
    else {
      showsend("get");
      substdio_fdbuf(&sstext,read,fd,textbuf,sizeof(textbuf));
      qmail_puts(&qq,"> ");
      for (;;) {
	r = substdio_get(&sstext,&ch,1);
	if (r == -1) strerr_die2sys(111,FATAL,MSG1(ERR_READ,line.s));
	if (r == 0) break;
	qmail_put(&qq,&ch,1);
	if (ch == '\n') qmail_puts(&qq,"> ");
      }
      qmail_puts(&qq,"\n");
    }
    close(fd);
  }
  copybottom(0);
  qmail_to(&qq,target.s);
}
Exemplo n.º 2
0
int
call_getc(struct call *cc, char *c)
{
	int r;
	if (cc->flagerr || cc->flagabort) return -1;
	r = substdio_get(&cc->ssfrom, c, 1);
	if (r == -1) {
		cc->flagerr = 1;
		return -1;
	}
	return r;
}
Exemplo n.º 3
0
int call_getln(substdio *ss, stralloc *l)
{
  int i;
  if (!stralloc_copys(l, "")) return -1;
  for (;;) {
    if (!stralloc_readyplus(l,1)) return -1;
    i = substdio_get(ss, l->s + l->len, 1);
    if (i != 1) return i;
    if (l->s[l->len] == '\n') break;
    ++l->len;
  }
  if (l->len > 0) if (l->s[l->len-1] == '\r') --l->len;
  l->s[l->len] = 0;
  return l->len;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
  char *name;
  char *env;
  char value[256];
  int len;

  name = argv[1];
  if (!name) _exit(100);
  env = argv[2];
  if ((len = substdio_get(subfdin,value,sizeof value - 1)) <= 0)
    _exit(100);
  value[len] = 0;
  value[str_chr(value,'\n')] = 0;

  if (env) {
    subputs("#include \"env.h\"\n"
	    "const char *");
    subputs(name);
    subputs("(void)\n"
	    "{\n"
	    "  const char *env;\n"
	    "  if ((env = env_get(\"");
    subputs(env);
    subputs("\")) == 0)\n"
	    "    env = \"");
    subputsbin(value);
    subputs("\";\n"
	    "  return env;\n"
	    "}\n");
  }
  else {
    subputs("const char ");
    subputs(name);
    subputs("[] = \"");
    subputsbin(value);
    subputs("\";\n");
  }
  if (substdio_flush(subfdout) == -1) _exit(111);
  return 0;
  (void)argc;
}