コード例 #1
0
ファイル: sync_log.c プロジェクト: martinpal/cyrus-imapd
/*
 * Read a single log item from a sync log file.  The item will be
 * returned as three constant strings.  The first string is the type of
 * the item (e.g. "MAILBOX") and is always capitalised.  The second and
 * third strings are arguments.
 *
 * Returns 0 on success, EOF when the end of the file is reached, or an
 * IMAP error code on failure.
 */
EXPORTED int sync_log_reader_getitem(sync_log_reader_t *slr,
				     const char *args[3])
{
    int c;
    const char *arg1s = NULL;
    const char *arg2s = NULL;

    if (!slr->input)
	return EOF;

    for (;;) {
	if ((c = getword(slr->input, &slr->type)) == EOF)
	    return EOF;

	/* Ignore blank lines */
	if (c == '\r') c = prot_getc(slr->input);
	if (c == '\n')
	    continue;

	if (c != ' ') {
	    syslog(LOG_ERR, "Invalid input");
	    eatline(slr->input, c);
	    continue;
	}

	if ((c = getastring(slr->input, 0, &slr->arg1)) == EOF) return EOF;
	arg1s = slr->arg1.s;

	arg2s = NULL;
	if (c == ' ') {
	    if ((c = getastring(slr->input, 0, &slr->arg2)) == EOF) return EOF;
	    arg2s = slr->arg2.s;
	}

	if (c == '\r') c = prot_getc(slr->input);
	if (c != '\n') {
	    syslog(LOG_ERR, "Garbage at end of input line");
	    eatline(slr->input, c);
	    continue;
	}

	break;
    }

    ucase(slr->type.s);
    args[0] = slr->type.s;
    args[1] = arg1s;
    args[2] = arg2s;
    return 0;
}
コード例 #2
0
ファイル: moldenplugin.c プロジェクト: gzoppetti/ExscitechVmd
static int read_next_timestep(void *mydata, int natoms, molfile_timestep_t *ts) {

  int i;
  char *k;
  char atname[1024];
  char buffer[1024];
  float x, y, z;
  
  moldendata *data = (moldendata *)mydata;
  
/* read the coordinates */

  for(i=0;i<data->numatoms;i++) 
  {
      k=fgets(buffer,1024,data->file);
      sscanf(buffer,"%s %f %f %f",atname,&x,&y,&z);

/* save coordinates only if given a timestep pointer
** otherwise assume that VMD would like to skip past
** it */

/* if I don't check for EOF file I get stuck in
** an infinite loop */

      if ( k==NULL)
      {
	return MOLFILE_ERROR;
      }
      
      if (ts!=NULL) 
      {
       ts->coords[3*i  ] = x;
       ts->coords[3*i+1] = y;
       ts->coords[3*i+2] = z;     
      } 
  }     

/* skip the two comment lines, which separate
** the individual coordinate entries 
** (for now, cause contains useful information
** like energies) */

  eatline(data->file);
  eatline(data->file); 

/* done and go back */

  return MOLFILE_SUCCESS;
}
コード例 #3
0
ファイル: 4b.c プロジェクト: Ricky-Hao/C-Primer-Plus-Demo
int main()
{
    struct data1 person[MAXID];
    int n=0;

    puts("Please enter the ID (press EOF to quit): ");

    while(n<MAXID&&(scanf("%d",&person[n].id)!=EOF))
	{
	    eatline();
		puts("Please enter the first name:");
		gets(person[n].name.fname);
		puts("Please enter the middle name(press [enter] don't have the middle name):");
		gets(person[n].name.mname);
		puts("Please enter the last name:");
		gets(person[n].name.lname);
        if(n<MAXID-1)
            puts("Please enter the ID (press EOF to quit): ");
		n++;
	}
	puts("Your information is: ");
	for(int t=0;t<n;t++)
        output(person[t]);
	puts("Bye.");
	return 0;
}
コード例 #4
0
ファイル: lcb_internal.c プロジェクト: brong/cyrus-imapd
HIDDEN int parse_backup_line(struct protstream *in, time_t *ts,
                             struct buf *cmd, struct dlist **kin)
{
    struct dlist *dl = NULL;
    struct buf buf = BUF_INITIALIZER;
    int64_t t;
    int c;

    c = prot_getc(in);
    if (c == '#')
        eatline(in, c);
    else
        prot_ungetc(c, in);

    c = getint64(in, &t);
    if (c == EOF)
        goto fail;

    c = getword(in, &buf);
    if (c == EOF)
        goto fail;

    c = dlist_parse(&dl, /*parsekeys*/ 1, 1, in);

    if (!dl) {
        fprintf(stderr, "\ndidn't parse dlist, error %i\n", c);
        goto fail;
    }

    if (c == '\r') c = prot_getc(in);
    if (c != '\n') {
        fprintf(stderr, "expected newline, got '%c'\n", c);
        eatline(in, c);
        goto fail;
    }

    if (kin) *kin = dl;
    if (cmd) buf_copy(cmd, &buf);
    if (ts) *ts = (time_t) t;
    buf_free(&buf);
    return c;

fail:
    if (dl) dlist_free(&dl);
    buf_free(&buf);
    return c;
}
コード例 #5
0
static int read_edm_data(void *v, int set, float *datablock,
                         float *colorblock) {
  edm_t *edm = (edm_t *)v;
  float * cell = datablock;
  int z, sentinel, convcnt;
  char readbuf[16];
 
  int xsize = edm->vol[0].xsize;
  int ysize = edm->vol[0].ysize;
  int zsize = edm->vol[0].zsize;

  // number of lines of text per slice
  int nperslice = xsize * ysize;
  int nlines = (int)(nperslice / 6.0);
  if ((nlines * 6) < nperslice) {
    nlines++;
  }

  for (z=0; z<zsize; z++) {
    int c;
    eatline(edm->fd);                // Eat the Z-plane index and throw away

    // read one plane of data, one cell at a time
    for (c=0; c<nperslice; c++) {
      convcnt = fscanf(edm->fd, "%f", cell);
      if (convcnt != 1) {
        printf("edmplugin) failed reading cell data\n");
        printf("edmplugin) cell %d of %d, slice %d\n", c, nperslice, z);
        return MOLFILE_ERROR; // bad file format encountered
      }
      cell++;
    }
    eatline(edm->fd);                // go on to next line
  }

  // read the -9999 end-of-file sentinel record
  sentinel = 0;
  fgets(readbuf, 13, edm->fd);
  sscanf(readbuf, "%d", &sentinel);  
  if (sentinel != -9999) {
    printf("edmplugin) EOF sentinel != -9999\n");
    // return MOLFILE_ERROR; // bad file format encountered, no sentinel record
  }
 
  return MOLFILE_SUCCESS;
}
コード例 #6
0
/*% parses a file and fills in the data structure. */
lwres_result_t
lwres_conf_parse(lwres_context_t *ctx, const char *filename) {
	FILE *fp = NULL;
	char word[256];
	lwres_result_t rval, ret;
	lwres_conf_t *confdata;
	int stopchar;

	REQUIRE(ctx != NULL);
	confdata = &ctx->confdata;

	REQUIRE(filename != NULL);
	REQUIRE(strlen(filename) > 0U);
	REQUIRE(confdata != NULL);

	errno = 0;
	if ((fp = fopen(filename, "r")) == NULL)
		return (LWRES_R_NOTFOUND);

	ret = LWRES_R_SUCCESS;
	do {
		stopchar = getword(fp, word, sizeof(word));
		if (stopchar == EOF) {
			rval = LWRES_R_SUCCESS;
			POST(rval);
			break;
		}

		if (strlen(word) == 0U)
			rval = LWRES_R_SUCCESS;
		else if (strcmp(word, "nameserver") == 0)
			rval = lwres_conf_parsenameserver(ctx, fp);
		else if (strcmp(word, "lwserver") == 0)
			rval = lwres_conf_parselwserver(ctx, fp);
		else if (strcmp(word, "domain") == 0)
			rval = lwres_conf_parsedomain(ctx, fp);
		else if (strcmp(word, "search") == 0)
			rval = lwres_conf_parsesearch(ctx, fp);
		else if (strcmp(word, "sortlist") == 0)
			rval = lwres_conf_parsesortlist(ctx, fp);
		else if (strcmp(word, "options") == 0)
			rval = lwres_conf_parseoption(ctx, fp);
		else {
			/* unrecognised word. Ignore entire line */
			rval = LWRES_R_SUCCESS;
			stopchar = eatline(fp);
			if (stopchar == EOF) {
				break;
			}
		}
		if (ret == LWRES_R_SUCCESS && rval != LWRES_R_SUCCESS)
			ret = rval;
	} while (1);

	fclose(fp);

	return (ret);
}
コード例 #7
0
ファイル: func_ptr.c プロジェクト: mysticTot/learn_c
char showmenu(void) {
    char ans;
    puts("Enter menu choice:");
    puts("u) uppercase       l) lowercase");
    puts("t) transposed case o) original case");
    puts("n) next string");
    ans = getchar();    // get response
    ans = tolower(ans); // convert to lowercase
    eatline();          // dispose of rest of line

    while (strchr("ulton", ans) == NULL) {
        puts("Please enter a u, l, t, o, or n:");
        ans = tolower(getchar());
        eatline();
    }

    return ans;
}
コード例 #8
0
ファイル: pro-7-8.c プロジェクト: qhan/CGuideforGodSon
char showmenu(void)
{
  char ans;
  puts("Enter menu choice:");
  puts("u) uppercase \nl) lowercase");
  puts("t) transposed case \no) original case");
  puts("n) next string \nq) quit");
  ans = getchar();
  ans = tolower(ans);
  eatline();
  while (strchr("ultonq", ans) == NULL)
    {
      puts("Please enter: u, l, t, o, n or q: ");
      ans = tolower(getchar());
      eatline();
    }
  return ans;
}
コード例 #9
0
ファイル: func_ptr.c プロジェクト: suicidejack/c_primer_plus
char showmenu(void)
{
    char ans;
    puts("Enter menu choice:");
    puts("u) upper case       l) lowercase");
    puts("t) transposted case o) original case");
    puts("n) next string");
    ans = getchar();
    ans = tolower(ans);
    eatline();
    while (strchr("ulton", ans) == NULL) {
        puts("Enter a u, l, t, o, or n:");
        ans = tolower(getchar());
        eatline();
    }

    return ans;
}
コード例 #10
0
ファイル: pe14-5.c プロジェクト: jnksu/CPP
//读取成绩
float get_float(void)
{
	float va;
	int ch;
	
	while(scanf("%f", &va) != 1 || va < 0 || va > 100){
		if(va < 0 || va > 100){
			printf("please enter fit number.\n");
			eatline();
		}
		else{
			while((ch = getchar()) != '\n')
				putchar(ch);
			printf(" is not number,\nplease enter the ");
			printf("number value, such as 25.0, 23.4 or 78.0: ");
		}	
	}
	
	eatline();
	return va;
}
コード例 #11
0
ファイル: Exercise 14.9.c プロジェクト: zpiao1/C-Primer-Plus
void assign_customer(SEAT * seats, int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        if (!seats[i].assigned)
        {
            printf("Seat ID: %d\n", i);
            puts("Enter your first name:");
            s_gets(seats[i].first, NAMELEN);
            puts("Enter your last name:");
            s_gets(seats[i].last, NAMELEN);
            seats[i].assigned = true;
            seats[i].assigned = false;
            eatline();
            return;
        }
    }
    puts("Sorry, no vacancy.");
    eatline();
}
コード例 #12
0
ファイル: lwconfig.c プロジェクト: SylvestreG/bitrig
/*!
 * Eats white space up to next newline or non-whitespace character (of
 * EOF). Returns the last character read. Comments are considered white
 * space.
 */
static int
eatwhite(FILE *fp) {
	int ch;

	ch = fgetc(fp);
	while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
		ch = fgetc(fp);

	if (ch == ';' || ch == '#')
		ch = eatline(fp);

	return (ch);
}
コード例 #13
0
ファイル: Exercise 14.9.c プロジェクト: zpiao1/C-Primer-Plus
char * s_gets(char * st, int n)
{
    char * ret_val, * find;
    ret_val = fgets(st, n, stdin);
    if (ret_val)
    {
        find = strchr(st, '\n');
        if (find)
            *find = '\0';
        else
            eatline();
    }
    return ret_val;
}
コード例 #14
0
ファイル: Exercise 14.9.c プロジェクト: zpiao1/C-Primer-Plus
void confirm(SEAT * seats, int n)
{
    int i, id;
    puts("Enter your seat ID:");
    scanf("%d", &id);
    eatline();
    for (i = 0; i < n; i++)
    {
        if (seats[i].seat_id == id)
        {
            if (!seats[i].confirmed && seats[i].assigned)
                seats[i].confirmed = true;
            else if (seats[i].confirmed)
                puts("The seat has been confirmed.");
            else if (!seats[i].assigned)
                puts("You need to be assigned to the seat first.");
            return;
        }
    }
    puts("Sorry, your seat ID is invalid.");
}
コード例 #15
0
ファイル: Exercise 14.9.c プロジェクト: zpiao1/C-Primer-Plus
void del_assign(SEAT * seats, int n)
{
    int id, i;

    puts("Enter your seat ID:");
    scanf("%d", &id);
    eatline();
    for (i = 0; i < n; i++)
    {
        if (seats[i].seat_id == id)
        {
            if (seats[i].assigned)
            {
                seats[i].assigned = false;
                seats[i].confirmed = false;
            }
            else
                puts("The seat is not assigned to anyone.");
            return;
        }
    }
    puts("Sorry, your seat ID is not found.");
}
コード例 #16
0
ファイル: 7.c プロジェクト: Ricky-Hao/C-Primer-Plus-Demo
int show_menu(long *font)
{
	char ch;
	int k=1;
	show_font(*font);
	puts("f)change font s)change size a)change alignment");
	puts("b)toggle bold i)toggle italic u)toggle underline");
	puts("q)quit");

	ch=getchar();

	switch(ch)
	{
		case 'f':_id(font);break;
		case 's':_size(font);break;
		case 'a':_alignment(font);break;
		case 'b':_bold(font);break;
		case 'i':_italic(font);break;
		case 'u':_underline(font);break;
		case 'q':k=0;
	}
	eatline();
	return k;
}
コード例 #17
0
ファイル: imap_proxy.c プロジェクト: JensErat/cyrus-imapd
static void proxy_part_filldata(partlist_t *part_list, int idx)
{
    char mytag[128];
    struct backend *be;
    partitem_t *item = &part_list->items[idx];

    item->id = 0;
    item->available = 0;
    item->total = 0;
    item->quota = 0.;

    syslog(LOG_DEBUG, "checking free space on server '%s'", item->value);

    /* connect to server */
    be = proxy_findserver(item->value, &imap_protocol,
            proxy_userid, &backend_cached,
            &backend_current, &backend_inbox, imapd_in);

    if (be) {
        uint64_t server_available = 0;
        uint64_t server_total = 0;
        const char *annot =
            (part_list->mode == PART_SELECT_MODE_FREESPACE_MOST) ?
            "freespace/total" : "freespace/percent/most";
        struct buf cmd = BUF_INITIALIZER;
        int c;

        /* fetch annotation from remote */
        proxy_gentag(mytag, sizeof(mytag));
        if (CAPA(be, CAPA_METADATA)) {
            buf_printf(&cmd, "METADATA \"\" (\"/shared" IMAP_ANNOT_NS "%s\"",
                       annot);
        }
        else {
            buf_printf(&cmd, "ANNOTATION \"\" \"" IMAP_ANNOT_NS "%s\" "
                       "(\"value.shared\"", annot);
        }
        prot_printf(be->out, "%s GET%s)\r\n", mytag, buf_cstring(&cmd));
        prot_flush(be->out);

        for (/* each annotation response */;;) {
            /* read a line */
            c = prot_getc(be->in);
            if (c != '*') break;
            c = prot_getc(be->in);
            if (c != ' ') { /* protocol error */ c = EOF; break; }

            c = chomp(be->in, buf_cstring(&cmd));
            if (c == ' ') c = prot_getc(be->in);
            if ((c == EOF) || (c != '\"')) {
                /* we don't care about this response */
                eatline(be->in, c);
                continue;
            }

            /* read available */
            c = getuint64(be->in, &server_available);
            if (c != ';') { c = EOF; break; }

            /* read total */
            c = getuint64(be->in, &server_total);
            if (c != '\"') { c = EOF; break; }
            eatline(be->in, c); /* we don't care about the rest of the line */
        }
        buf_free(&cmd);
        if (c != EOF) {
            prot_ungetc(c, be->in);

            /* we should be looking at the tag now */
            eatline(be->in, c);
        }
        if (c == EOF) {
            /* uh oh, we're not happy */
            fatal("Lost connection to backend", EC_UNAVAILABLE);
        }

        /* unique id */
        item->id = idx;
        item->available = server_available;
        item->total = server_total;
    }
}
コード例 #18
0
ファイル: imap_proxy.c プロジェクト: JensErat/cyrus-imapd
int proxy_catenate_url(struct backend *s, struct imapurl *url, FILE *f,
                       unsigned long *size, const char **parseerr)
{
    char mytag[128];
    int c, r = 0, found = 0;
    unsigned int uidvalidity = 0;

    *size = 0;
    *parseerr = NULL;

    /* select the mailbox (read-only) */
    proxy_gentag(mytag, sizeof(mytag));
    prot_printf(s->out, "%s Examine {" SIZE_T_FMT "+}\r\n%s\r\n",
                mytag, strlen(url->mailbox), url->mailbox);
    for (/* each examine response */;;) {
        /* read a line */
        c = prot_getc(s->in);
        if (c != '*') break;
        c = prot_getc(s->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        c = chomp(s->in, "ok [uidvalidity");
        if (c == EOF) {
            /* we don't care about this response */
            eatline(s->in, c);
            continue;
        }

        /* read uidvalidity */
        c = getuint32(s->in, &uidvalidity);
        if (c != ']') { c = EOF; break; }
        eatline(s->in, c); /* we don't care about the rest of the line */
    }
    if (c != EOF) {
        prot_ungetc(c, s->in);

        /* we should be looking at the tag now */
        eatline(s->in, c);
    }
    if (c == EOF) {
        /* uh oh, we're not happy */
        fatal("Lost connection to backend", EC_UNAVAILABLE);
    }

    if (url->uidvalidity && (uidvalidity != url->uidvalidity)) {
        *parseerr = "Uidvalidity of mailbox has changed";
        r = IMAP_BADURL;
        goto unselect;
    }

    /* fetch the bodypart */
    proxy_gentag(mytag, sizeof(mytag));
    prot_printf(s->out, "%s Uid Fetch %lu Body.Peek[%s]\r\n",
                mytag, url->uid, url->section ? url->section : "");
    for (/* each fetch response */;;) {
        unsigned int seqno;

      next_resp:
        /* read a line */
        c = prot_getc(s->in);
        if (c != '*') break;
        c = prot_getc(s->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* read seqno */
        c = getuint32(s->in, &seqno);
        if (seqno == 0 || c != ' ') {
            /* we suck and won't handle this case */
            c = EOF; break;
        }
        c = chomp(s->in, "fetch (");
        if (c == EOF) { /* not a fetch response */
            eatline(s->in, c);
            continue;
        }

        for (/* each fetch item */;;) {
            unsigned uid, sz = 0;

            switch (c) {
            case 'u': case 'U':
                c = chomp(s->in, "id");
                if (c != ' ') { c = EOF; }
                else {
                    c = getuint32(s->in, &uid);
                    if (uid != url->uid) {
                        /* not our response */
                        eatline(s->in, c);
                        goto next_resp;
                    }
                }
                break;

            case 'b': case 'B':
                c = chomp(s->in, "ody[");
                while (c != ']') c = prot_getc(s->in);
                if (c == ']') c = prot_getc(s->in);
                if (c == ' ') c = prot_getc(s->in);
                if (c == '{') {
                    c = getuint32(s->in, &sz);
                    if (c == '}') c = prot_getc(s->in);
                    if (c == '\r') c = prot_getc(s->in);
                    if (c != '\n') c = EOF;
                }
                else if (c == 'n' || c == 'N') {
                    c = chomp(s->in, "il");
                    r = IMAP_BADURL;
                    *parseerr = "No such message part";
                }

                if (c != EOF) {
                    /* catenate to f */
                    found = 1;
                    *size = sz;

                    while (sz) {
                        char buf[2048];
                        int j = (sz > sizeof(buf) ? sizeof(buf) : sz);

                        j = prot_read(s->in, buf, j);
                        if(!j) break;
                        fwrite(buf, j, 1, f);
                        sz -= j;
                    }
                    c = prot_getc(s->in);
                }

                break; /* end of case */
            default:
                /* probably a FLAGS item */
                eatline(s->in, c);
                goto next_resp;
            }
            /* looking at either SP separating items or a RPAREN */
            if (c == ' ') { c = prot_getc(s->in); }
            else if (c == ')') break;
            else { c = EOF; break; }
        }

        /* if c == EOF we have either a protocol error or a situation
           we can't handle, and we should die. */
        if (c == ')') c = prot_getc(s->in);
        if (c == '\r') c = prot_getc(s->in);
        if (c != '\n') { c = EOF; break; }
    }
    if (c != EOF) {
        prot_ungetc(c, s->in);

        /* we should be looking at the tag now */
        eatline(s->in, c);
    }
    if (c == EOF) {
        /* uh oh, we're not happy */
        fatal("Lost connection to backend", EC_UNAVAILABLE);
    }

  unselect:
    /* unselect the mailbox */
    proxy_gentag(mytag, sizeof(mytag));
    prot_printf(s->out, "%s Unselect\r\n", mytag);
    for (/* each unselect response */;;) {
        /* read a line */
        c = prot_getc(s->in);
        if (c != '*') break;
        c = prot_getc(s->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* we don't care about this response */
        eatline(s->in, c);
    }
    if (c != EOF) {
        prot_ungetc(c, s->in);

        /* we should be looking at the tag now */
        eatline(s->in, c);
    }
    if (c == EOF) {
        /* uh oh, we're not happy */
        fatal("Lost connection to backend", EC_UNAVAILABLE);
    }

    if (!r && !found) {
        r = IMAP_BADURL;
        *parseerr = "No such message in mailbox";
    }

    return r;
}
コード例 #19
0
ファイル: moldenplugin.c プロジェクト: gzoppetti/ExscitechVmd
static void *open_molden_read(const char *filename, const char *filetype, int *natoms) {

  FILE *fd;
  moldendata *data;
  char moldentest1[7];
  char moldentest2[7];
  char buffer[1024];
  char tester[20];
  int i;
  char *s;

  fd = fopen(filename, "rb");
  if (!fd) return NULL;
  
  data = (moldendata *)malloc(sizeof(moldendata));
  data->file = fd;
  data->file_name = strdup(filename);

/* check if the file is MOLDEN format */

  fscanf(data->file, "%s %s",moldentest1,moldentest2);
  if (!strcmp(moldentest1,"[Molden") && \
      !strcmp(moldentest2,"Format]"))
  {
    printf("Detected MOLDEN file format!\n");
  }
  else
  {
    printf("The file does not seem to be in MOLDEN format!\n");
    return NULL;
  }

/* Unfortunately the molden file format has two possibilities:
** either there is a [ATOMS] section which provides the atom
** name, charges and coordinates or there is only a 
** XYZ style [GEOMETRIES] section, which still provides atom
** type and geometry information, hence I have to check which
** case I have */
  
/* check if there is an [ATOMS] section */

  do
  {
    i=fscanf(data->file, "%s",tester); 
    if (!strcmp(tester,"[Atoms]"))
    {
/* start counting the atoms; 
** read until I hit the first line that starts with a "["
** bracket */

      eatline(fd); 
      (*natoms)=0; 
      s=fgets(buffer,1024,fd);

/* Here I assume that the [Atoms] section goes
** on until another section starts, i.e. ther is
** a "[" or I encounter EOF */

      while ((buffer[0]!='[') && (s != NULL))
      {
       	(*natoms)++;     
	s=fgets(buffer,1024,fd);
      }
      data->numatoms=*natoms;
      rewind(fd);
      data->trajectory = 0;
      return data;
    }
    else if (!strcmp(tester,"[GEOMETRIES]"))
    {
      printf("Found [Geometry] section ...\n");
      data->trajectory = 1;	    
       
/* In this case I am lucky because the first line
** of the XYZ type [GEOMETRIES] input contains the
** number of atoms, i.e. skip to this line and the
** read this entry */

      eatline(fd);

      i=fscanf(data->file, "%d",natoms);
      if (i!=1)
      {
	printf("The [GEOMTRIES] output does not have \n");
	printf("the number of atoms in line number one !! \n");
      }

      data->numatoms=*natoms;
     
/* skip the next two lines, so the file can be parsed in the 
** structure section */      

      eatline(fd);
      eatline(fd);

      return data; 
    }
   } while (i>0);
  
  return NULL;
}
コード例 #20
0
/*% parses a file and fills in the data structure. */
isc_result_t
irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
{
	FILE *fp = NULL;
	char word[256];
	isc_result_t rval, ret = ISC_R_SUCCESS;
	irs_resconf_t *conf;
	int i, stopchar;

	REQUIRE(mctx != NULL);
	REQUIRE(filename != NULL);
	REQUIRE(strlen(filename) > 0U);
	REQUIRE(confp != NULL && *confp == NULL);

	conf = isc_mem_get(mctx, sizeof(*conf));
	if (conf == NULL)
		return (ISC_R_NOMEMORY);

	conf->mctx = mctx;
	ISC_LIST_INIT(conf->nameservers);
	conf->numns = 0;
	conf->domainname = NULL;
	conf->searchnxt = 0;
	conf->resdebug = 0;
	conf->ndots = 1;
	for (i = 0; i < RESCONFMAXSEARCH; i++)
		conf->search[i] = NULL;

	errno = 0;
	if ((fp = fopen(filename, "r")) != NULL) {
		do {
			stopchar = getword(fp, word, sizeof(word));
			if (stopchar == EOF) {
				rval = ISC_R_SUCCESS;
				POST(rval);
				break;
			}

			if (strlen(word) == 0U)
				rval = ISC_R_SUCCESS;
			else if (strcmp(word, "nameserver") == 0)
				rval = resconf_parsenameserver(conf, fp);
			else if (strcmp(word, "domain") == 0)
				rval = resconf_parsedomain(conf, fp);
			else if (strcmp(word, "search") == 0)
				rval = resconf_parsesearch(conf, fp);
			else if (strcmp(word, "sortlist") == 0)
				rval = resconf_parsesortlist(conf, fp);
			else if (strcmp(word, "options") == 0)
				rval = resconf_parseoption(conf, fp);
			else {
				/* unrecognised word. Ignore entire line */
				rval = ISC_R_SUCCESS;
				stopchar = eatline(fp);
				if (stopchar == EOF) {
					break;
				}
			}
			if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS)
				ret = rval;
		} while (1);

		fclose(fp);
	} else {
		switch (errno) {
		case ENOENT:
			break;
		default:
			isc_mem_put(mctx, conf, sizeof(*conf));
			return (ISC_R_INVALIDFILE);
		}
	}

	/* If we don't find a nameserver fall back to localhost */
	if (conf->numns == 0) {
		INSIST(ISC_LIST_EMPTY(conf->nameservers));

		/* XXX: should we catch errors? */
		(void)add_server(conf->mctx, "127.0.0.1", &conf->nameservers);
		(void)add_server(conf->mctx, "::1", &conf->nameservers);
	}

	/*
	 * Construct unified search list from domain or configured
	 * search list
	 */
	ISC_LIST_INIT(conf->searchlist);
	if (conf->domainname != NULL) {
		ret = add_search(conf, conf->domainname);
	} else if (conf->searchnxt > 0) {
		for (i = 0; i < conf->searchnxt; i++) {
			ret = add_search(conf, conf->search[i]);
			if (ret != ISC_R_SUCCESS)
				break;
		}
	}

	conf->magic = IRS_RESCONF_MAGIC;

	if (ret != ISC_R_SUCCESS)
		irs_resconf_destroy(&conf);
	else {
		if (fp == NULL)
			ret = ISC_R_FILENOTFOUND;
		*confp = conf;
	}

	return (ret);
}
コード例 #21
0
ファイル: Exercise 14.9.c プロジェクト: zpiao1/C-Primer-Plus
int main(void)
{
    char choice;
    PLANE flights[FLIGHTS];
    int i, j;
    int fl_num;
    int index;
    FILE * fp;
    int flight_nums[] = {102, 311, 444, 519};
    fp = fopen("flight2.dat", "r+b");
    if (!fp)
    {
        fputs("Can't open flight2.dat", stderr);
        exit(EXIT_FAILURE);
    }

    rewind(fp);

    if (getc(fp) == EOF)
    {
        for (i = 0; i < FLIGHTS; i++)
        {
            flights[i].flight_num = flight_nums[i];
            for (j = 0; j < SEATS; j++)
            {
                flights[i].vacancy[j].seat_id = j;
                flights[i].vacancy[j].assigned = false;
                flights[i].vacancy[j].confirmed = false;
                flights[i].vacancy[j].first[0] = '\0';
                flights[i].vacancy[j].last[0] = '\0';
            }
        }
        puts("Done for initialization.");
    }
    else
    {
        fread(flights, sizeof(PLANE), FLIGHTS, fp);

        puts("We have Flights 102, 311, 444, 519");
        puts("Enter the flight number, non-numeric value to quit:");
        while (scanf("%d", &fl_num) == 1)
        {
            eatline();
            if (index = findint(flight_nums, FLIGHTS, fl_num) == -1)
            {
                puts("No such flight number. Enter again:");
                continue;
            }
            do
            {
                puts("To choose a function, enter its letter label:");
                puts("a) Show number of empty seats");
                puts("b) Show list of empty seats");
                puts("c) Show alphabetical list of seats");
                puts("d) Assign a customer to a seat assignment");
                puts("e) Delete a seat assignment");
                puts("f) Confirming a seat assignment");
                puts("g) Back to the top level menu");
                choice = getchar();
                eatline();
                if (choice != 'g')
                    switch (choice)
                    {
                        case 'a' :
                            show_empty_seat_num(flights[index].vacancy, SEATS);
                            break;
                        case 'b' :
                            show_empty_seat_lst(flights[index].vacancy, SEATS);
                            break;
                        case 'c' :
                            show_alpha_lst(flights[index].vacancy, SEATS);
                            break;
                        case 'd' :
                            assign_customer(flights[index].vacancy, SEATS);
                            break;
                        case 'e' :
                            del_assign(flights[index].vacancy, SEATS);
                            break;
                        case 'f' :
                            confirm(flights[index].vacancy, SEATS);
                        default :
                            puts("Wrong choice!");
                    }
            } while (choice != 'g');
            puts("Enter the next flight number, non-numeric value to quit:");
        }
    }



    rewind(fp);
    fwrite(flights, sizeof(PLANE), FLIGHTS, fp);
    fclose(fp);

    return 0;
}
コード例 #22
0
ファイル: moldenplugin.c プロジェクト: gzoppetti/ExscitechVmd
static int read_molden_structure(void *mydata, int *optflags, 
    molfile_atom_t *atoms) 
 {
  int i;
  char atname[1024];
  char buffer[1024];
  char geotest[11];
  int num,charge;
  float x,y,z;
  molfile_atom_t *atom;
  moldendata *data = (moldendata *)mydata;

  *optflags = MOLFILE_NOOPTIONS; /* no optional data */

/* here I have two possibilities, either there is an
** [Atoms] section (i.e. data->trajectory=0) and I can
** read there structure information right there,
** or I have to extract it from the [GEOMETRIES]
** output (i.e. data->trajectory=1) */

  if(data->trajectory==0)
  { 

/* Skip the first three lines */

    eatline(data->file);
    eatline(data->file);

/* Now read in the atom types, names, charges as well
** as x,y,z coordinates */

    for(i=0;i<data->numatoms;i++) 
    {
      atom = atoms+i;
      fgets(buffer,1024,data->file);    
      sscanf(buffer,"%s %d %d %f %f %f",atname,&num,&charge,\
	  &x,&y,&z);
      strncpy(atom->name,atname,sizeof(atom->name)); 
      strncpy(atom->type, atom->name, sizeof(atom->type));
      atom->resname[0] = '\0';
      atom->resid = 1;
      atom->chain[0] = '\0';
      atom->segid[0] = '\0';
    }


/* finally and important skip the the beginning of the xyz
** section */

    do 
    {
      fscanf(data->file, "%s",geotest);   
    } while (strcmp(geotest,"[GEOMETRIES]")!=0);
  
     printf("Found Geometry Section\n");

  /* advance to the beginning of the XYZ list */

    eatline(data->file);
    eatline(data->file);
    eatline(data->file); 

/* time to go back */

    return MOLFILE_SUCCESS; 
  }
  else if(data->trajectory==1)
  {
    
/* in the read section I already forwarded to the correct
** location in the file hence I can start reading right
** away */


    for(i=0;i<data->numatoms;i++) 
    {
      atom = atoms+i;
      fgets(buffer,1024,data->file);    
      sscanf(buffer,"%s %f %f %f",atname,&x,&y,&z);
      strncpy(atom->name,atname,sizeof(atom->name)); 
      strncpy(atom->type, atom->name, sizeof(atom->type));
      atom->resname[0] = '\0';
      atom->resid = 1;
      atom->chain[0] = '\0';
      atom->segid[0] = '\0';
    }

/* now rewind the file and go back to the [GEOMETRIES]
** section */

    rewind(data->file);
    
    do 
    {
      fscanf(data->file, "%s",geotest);   
    } while (strcmp(geotest,"[GEOMETRIES]")!=0);
  
     printf("Found Geometry Section\n");

/* advance to the beginning of the XYZ list */

     eatline(data->file);
     eatline(data->file);
     eatline(data->file);

/* time to go back */

     return MOLFILE_SUCCESS;

   }

  printf("Sorry, could not obtain structure information \n");
  printf("from either the [Atoms] or [GEOMETRIES] section! \n");
  printf("Please check your MOLDEN output file! \n"); 
  return MOLFILE_ERROR; 
}
コード例 #23
0
ファイル: imap_proxy.c プロジェクト: JensErat/cyrus-imapd
void proxy_copy(const char *tag, char *sequence, char *name, int myrights,
                int usinguid, struct backend *s)
{
    char mytag[128];
    struct d {
        char *idate;
        char *flags;
        unsigned int seqno, uid;
        struct d *next;
    } *head, *p, *q;
    int c;

    /* find out what the flags & internaldate for this message are */
    proxy_gentag(mytag, sizeof(mytag));
    prot_printf(backend_current->out,
                "%s %s %s (Flags Internaldate)\r\n",
                tag, usinguid ? "Uid Fetch" : "Fetch", sequence);
    head = (struct d *) xmalloc(sizeof(struct d));
    head->flags = NULL; head->idate = NULL;
    head->seqno = head->uid = 0;
    head->next = NULL;
    p = head;
    /* read all the responses into the linked list */
    for (/* each FETCH response */;;) {
        unsigned int seqno = 0, uidno = 0;
        char *flags = NULL, *idate = NULL;

        /* read a line */
        c = prot_getc(backend_current->in);
        if (c != '*') break;
        c = prot_getc(backend_current->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* check for OK/NO/BAD/BYE response */
        if (!isdigit(c = prot_getc(backend_current->in))) {
            prot_printf(imapd_out, "* %c", c);
            pipe_to_end_of_response(backend_current, 0);
            continue;
        }

        /* read seqno */
        prot_ungetc(c, backend_current->in);
        c = getuint32(backend_current->in, &seqno);
        if (seqno == 0 || c != ' ') {
            /* we suck and won't handle this case */
            c = EOF; break;
        }
        c = chomp(backend_current->in, "fetch (");
        if (c == EOF) {
            c = chomp(backend_current->in, "exists\r");
            if (c == '\n') { /* got EXISTS response */
                prot_printf(imapd_out, "* %d EXISTS\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            /* XXX  the "exists" check above will eat "ex" */
            c = chomp(backend_current->in, "punge\r");
            if (c == '\n') { /* got EXPUNGE response */
                prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            c = chomp(backend_current->in, "recent\r");
            if (c == '\n') { /* got RECENT response */
                prot_printf(imapd_out, "* %d RECENT\r\n", seqno);
                continue;
            }
        }
        /* huh, don't get this response */
        if (c == EOF) break;
        for (/* each fetch item */;;) {
            /* looking at the first character in an item */
            switch (c) {
            case 'f': case 'F': /* flags? */
                c = chomp(backend_current->in, "lags");
                if (c != ' ') { c = EOF; }
                else c = prot_getc(backend_current->in);
                if (c != '(') { c = EOF; }
                else {
                    flags = grab(backend_current->in, ')');
                    c = prot_getc(backend_current->in);
                }
                break;
            case 'i': case 'I': /* internaldate? */
                c = chomp(backend_current->in, "nternaldate");
                if (c != ' ') { c = EOF; }
                else c = prot_getc(backend_current->in);
                if (c != '"') { c = EOF; }
                else {
                    idate = grab(backend_current->in, '"');
                    c = prot_getc(backend_current->in);
                }
                break;
            case 'u': case 'U': /* uid */
                c = chomp(backend_current->in, "id");
                if (c != ' ') { c = EOF; }
                else c = getuint32(backend_current->in, &uidno);
                break;
            default: /* hmm, don't like the smell of it */
                c = EOF;
                break;
            }
            /* looking at either SP seperating items or a RPAREN */
            if (c == ' ') { c = prot_getc(backend_current->in); }
            else if (c == ')') break;
            else { c = EOF; break; }
        }
        /* if c == EOF we have either a protocol error or a situation
           we can't handle, and we should die. */
        if (c == ')') c = prot_getc(backend_current->in);
        if (c == '\r') c = prot_getc(backend_current->in);
        if (c != '\n') {
            c = EOF;
            free(flags);
            free(idate);
            break;
        }

        /* if we're missing something, we should echo */
        if (!flags || !idate) {
            char sep = '(';
            prot_printf(imapd_out, "* %d FETCH ", seqno);
            if (uidno) {
                prot_printf(imapd_out, "%cUID %d", sep, uidno);
                sep = ' ';
            }
            if (flags) {
                prot_printf(imapd_out, "%cFLAGS %s", sep, flags);
                sep = ' ';
            }
            if (idate) {
                prot_printf(imapd_out, "%cINTERNALDATE %s", sep, flags);
                sep = ' ';
            }
            prot_printf(imapd_out, ")\r\n");
            if (flags) free(flags);
            if (idate) free(idate);
            continue;
        }

        /* add to p->next */
        p->next = xmalloc(sizeof(struct d));
        p = p->next;
        p->idate = idate;
        p->flags = editflags(flags);
        p->uid = uidno;
        p->seqno = seqno;
        p->next = NULL;
    }
    if (c != EOF) {
        prot_ungetc(c, backend_current->in);

        /* we should be looking at the tag now */
        pipe_until_tag(backend_current, tag, 0);
    }
    if (c == EOF) {
        /* uh oh, we're not happy */
        fatal("Lost connection to selected backend", EC_UNAVAILABLE);
    }

    /* start the append */
    prot_printf(s->out, "%s Append {" SIZE_T_FMT "+}\r\n%s",
                tag, strlen(name), name);
    prot_printf(backend_current->out, "%s %s %s (Rfc822.peek)\r\n",
                mytag, usinguid ? "Uid Fetch" : "Fetch", sequence);
    for (/* each FETCH response */;;) {
        unsigned int seqno = 0, uidno = 0;

        /* read a line */
        c = prot_getc(backend_current->in);
        if (c != '*') break;
        c = prot_getc(backend_current->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* check for OK/NO/BAD/BYE response */
        if (!isdigit(c = prot_getc(backend_current->in))) {
            prot_printf(imapd_out, "* %c", c);
            pipe_to_end_of_response(backend_current, 0);
            continue;
        }

        /* read seqno */
        prot_ungetc(c, backend_current->in);
        c = getuint32(backend_current->in, &seqno);
        if (seqno == 0 || c != ' ') {
            /* we suck and won't handle this case */
            c = EOF; break;
        }
        c = chomp(backend_current->in, "fetch (");
        if (c == EOF) { /* not a fetch response */
            c = chomp(backend_current->in, "exists\r");
            if (c == '\n') { /* got EXISTS response */
                prot_printf(imapd_out, "* %d EXISTS\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) { /* not an exists response */
            /* XXX  the "exists" check above will eat "ex" */
            c = chomp(backend_current->in, "punge\r");
            if (c == '\n') { /* got EXPUNGE response */
                prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) { /* not an exists response */
            c = chomp(backend_current->in, "recent\r");
            if (c == '\n') { /* got RECENT response */
                prot_printf(imapd_out, "* %d RECENT\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            /* huh, don't get this response */
            break;
        }
        /* find seqno in the list */
        p = head;
        while (p->next && seqno != p->next->seqno) p = p->next;
        if (!p->next) break;
        q = p->next;
        p->next = q->next;
        for (/* each fetch item */;;) {
            int sz = 0;

            switch (c) {
            case 'u': case 'U':
                c = chomp(backend_current->in, "id");
                if (c != ' ') { c = EOF; }
                else c = getuint32(backend_current->in, &uidno);
                break;

            case 'r': case 'R':
                c = chomp(backend_current->in, "fc822");
                if (c == ' ') c = prot_getc(backend_current->in);
                if (c != '{') {
                    /* NIL? */
                    eatline(backend_current->in, c);
                    c = EOF;
                }
                else c = getint32(backend_current->in, &sz);
                if (c == '}') c = prot_getc(backend_current->in);
                if (c == '\r') c = prot_getc(backend_current->in);
                if (c != '\n') c = EOF;

                if (c != EOF) {
                    /* append p to s->out */
                    prot_printf(s->out, " (%s) \"%s\" {%d+}\r\n",
                                q->flags, q->idate, sz);
                    while (sz) {
                        char buf[2048];
                        int j = (sz > (int) sizeof(buf) ?
                                 (int) sizeof(buf) : sz);

                        j = prot_read(backend_current->in, buf, j);
                        if(!j) break;
                        prot_write(s->out, buf, j);
                        sz -= j;
                    }
                    c = prot_getc(backend_current->in);
                }

                break; /* end of case */
            default:
                c = EOF;
                break;
            }
            /* looking at either SP seperating items or a RPAREN */
            if (c == ' ') { c = prot_getc(backend_current->in); }
            else if (c == ')') break;
            else { c = EOF; break; }
        }

        /* if c == EOF we have either a protocol error or a situation
           we can't handle, and we should die. */
        if (c == ')') c = prot_getc(backend_current->in);
        if (c == '\r') c = prot_getc(backend_current->in);
        if (c != '\n') { c = EOF; break; }

        /* free q */
        free(q->idate);
        free(q->flags);
        free(q);
    }
    if (c != EOF) {
        char *appenduid, *b;
        int res;

        /* pushback the first character of the tag we're looking at */
        prot_ungetc(c, backend_current->in);

        /* nothing should be left in the linked list */
        assert(head->next == NULL);

        /* ok, finish the append; we need the UIDVALIDITY and UIDs
           to return as part of our COPYUID response code */
        prot_printf(s->out, "\r\n");

        /* should be looking at 'mytag' on 'backend_current',
           'tag' on 's' */
        pipe_until_tag(backend_current, mytag, 0);
        res = pipe_until_tag(s, tag, 0);

        if (res == PROXY_OK) {
            if (myrights & ACL_READ) {
                appenduid = strchr(s->last_result.s, '[');
                /* skip over APPENDUID */
                if (appenduid) {
                    appenduid += strlen("[appenduid ");
                    b = strchr(appenduid, ']');
                    if (b) *b = '\0';
                    prot_printf(imapd_out, "%s OK [COPYUID %s] %s\r\n", tag,
                                appenduid, error_message(IMAP_OK_COMPLETED));
                }
                else
                    prot_printf(imapd_out, "%s OK %s\r\n", tag, s->last_result.s);
            }
            else {
                prot_printf(imapd_out, "%s OK %s\r\n", tag,
                            error_message(IMAP_OK_COMPLETED));
            }
        } else {
            prot_printf(imapd_out, "%s %s", tag, s->last_result.s);
        }
    } else {
        /* abort the append */
        prot_printf(s->out, " {0+}\r\n\r\n");
        pipe_until_tag(backend_current, mytag, 0);
        pipe_until_tag(s, tag, 0);

        /* report failure */
        prot_printf(imapd_out, "%s NO inter-server COPY failed\r\n", tag);
    }

    /* free dynamic memory */
    while (head) {
        p = head;
        head = head->next;
        if (p->idate) free(p->idate);
        if (p->flags) free(p->flags);
        free(p);
    }
}
コード例 #24
0
static void *open_edm_read(const char *filepath, const char *filetype,
    int *natoms) {
  FILE *fd;
  edm_t *edm;
  int ntitle, na, nb, nc, xsize, ysize, zsize;
  int amin, amax, bmin, bmax, cmin, cmax;
  float a, b, c, alpha, beta, gamma;
  float xdelta, ydelta, zdelta;
  float alpha1, beta1, gamma1;
  float xaxis[3], yaxis[3], zaxis[3], z1, z2, z3;
  int i, convcnt;
  
  fd = fopen(filepath, "rb");
  if (!fd) 
    return NULL;

  edm = new edm_t;
  edm->fd = fd;
  edm->vol = NULL;
  *natoms = MOLFILE_NUMATOMS_NONE;

  edm->vol = new molfile_volumetric_t[1];
 
  edm->nsets = 1; // this EDM file contains only one data set

  // read in EDM file header information
  eatline(edm->fd);               // skip first header line 

  convcnt = fscanf(edm->fd, "%d", &ntitle); // read number of title lines
  if (convcnt != 1) {
    printf("edmplugin) failed to read in title line count\n");
    fclose(edm->fd);
    delete [] edm->vol;
    delete edm;
    return NULL;
  }
    
  eatline(edm->fd);               // go on to next line

  // skip past title and comment lines in header
  for (i=0; i<ntitle; i++) {
    eatline(edm->fd);             // skip a line
  }

  // read in the box dimensions and grid spacing deltas
  convcnt = fscanf(edm->fd, "%d %d %d %d %d %d %d %d %d",
         &na, &amin, &amax, &nb, &bmin, &bmax, &nc, &cmin, &cmax);
  if (convcnt != 9) {
    printf("edmplugin) failed to read in box dimensions\n");
    fclose(edm->fd);
    delete [] edm->vol;
    delete edm;
    return NULL;
  }

  eatline(edm->fd);               // go on to next line
  
  // calculate number of samples in each dimension
  xsize = amax - amin + 1;    
  ysize = bmax - bmin + 1;    
  zsize = cmax - cmin + 1;    
  edm->vol[0].xsize = xsize;
  edm->vol[0].ysize = ysize;
  edm->vol[0].zsize = zsize;
  edm->vol[0].has_color = 0;

  // read in 6 values for unit cell box orientation 
  convcnt = fscanf(edm->fd, "%f %f %f %f %f %f", 
                   &a, &b, &c, &alpha, &beta, &gamma);
  if (convcnt != 6) {
    printf("edmplugin) failed to read in box lengths and angles\n");
    fclose(edm->fd);
    delete [] edm->vol;
    delete edm;
    return NULL;
  }
  eatline(edm->fd);            // go on to next line

  // find box coordinates 
  xdelta = a / (float) na;
  ydelta = b / (float) nb;
  zdelta = c / (float) nc;

  strcpy(edm->vol[0].dataname, "X-PLOR Electron Density Map");

  // convert degrees to radians
  alpha1 = 3.14159265358979323846 * alpha / 180.0;
  beta1  = 3.14159265358979323846 *  beta / 180.0;
  gamma1 = 3.14159265358979323846 * gamma / 180.0;

  // calculate non-orthogonal unit cell coordinates
  xaxis[0] = xdelta;
  xaxis[1] = 0;
  xaxis[2] = 0;

  yaxis[0] = cos(gamma1) * ydelta;
  yaxis[1] = sin(gamma1) * ydelta;
  yaxis[2] = 0;

  z1 = cos(beta1);
  z2 = (cos(alpha1) - cos(beta1)*cos(gamma1)) / sin(gamma1);
  z3 = sqrt(1.0 - z1*z1 - z2*z2);
  zaxis[0] = z1 * zdelta;
  zaxis[1] = z2 * zdelta;
  zaxis[2] = z3 * zdelta;

  edm->vol[0].origin[0] = xaxis[0] * amin + yaxis[0] * bmin + zaxis[0] * cmin;
  edm->vol[0].origin[1] = yaxis[1] * bmin + zaxis[1] * cmin;
  edm->vol[0].origin[2] = zaxis[2] * cmin;

  edm->vol[0].xaxis[0] = xaxis[0] * (xsize-1);
  edm->vol[0].xaxis[1] = 0;
  edm->vol[0].xaxis[2] = 0;

  edm->vol[0].yaxis[0] = yaxis[0] * (ysize-1);
  edm->vol[0].yaxis[1] = yaxis[1] * (ysize-1);
  edm->vol[0].yaxis[2] = 0;

  edm->vol[0].zaxis[0] = zaxis[0] * (zsize-1);
  edm->vol[0].zaxis[1] = zaxis[1] * (zsize-1);
  edm->vol[0].zaxis[2] = zaxis[2] * (zsize-1);

  // Check that the EDM file is stored in the "ZYX" format we expect,
  // and return NULL if it is not a supported file type.
  char planeorder[4];
  memset(planeorder, 0, sizeof(planeorder));
  convcnt = fscanf(edm->fd, "%3s", planeorder);
  if (convcnt != 1) {
    printf("edmplugin) failed to read in plane order\n");
    fclose(edm->fd);
    delete [] edm->vol;
    delete edm;
    return NULL;
  }

  if (strcmp(planeorder, "ZYX")) { 
    printf("edmplugin) unsupported plane ordering %s\n", planeorder);
    fclose(edm->fd);
    delete [] edm->vol;
    delete edm;
    return NULL;
  }
  eatline(edm->fd);               // go on to next line

  return edm;
}
コード例 #25
0
ファイル: pol.cpp プロジェクト: leila1349/OPT_recon
int
POL::getpol_tok (struct token_st *token)
{
  KeywordCodeEntry* sym;

  token->ready = false;
nexttok:
  gettok (token);

  if (token->type == TT_BLANK)
    goto nexttok;
  if (token->type == TT_SPECLCHAR) {
    if (strchr(m_szSkipChars, token->tokstr[0]) != NULL)
      goto nexttok;
    if (token->tokstr[0] == NEWLINE)
      goto nexttok;
    if (token->tokstr[0] == meta.cmd) {
      getcmd();
      goto nexttok;
    }
    if (token->tokstr[0] == meta.com) {         /* skip comment */
      eatline ();
      goto nexttok;
    }
    if (token->tokstr[0] == meta.out) {
      getescape(token->tokstr, meta.out, MAXTOK);
      fputs (token->tokstr, stderr);
      goto nexttok;
    }
    if (token->tokstr[0] == meta.con) {         /* continuation across NEWLINE */
      while (lookchar() == BLANK || lookchar() == TAB)
        inchar();
      if (lookchar() == NEWLINE)
        inchar();
    }
    if (token->tokstr[0] == meta.ter) {         /* get input from terminal */
      usefile (P_USE_FILE, "");
      tok (token);
      closefile();
      return (token->type);
    }
  }

  /* look for filler words */

  if (skiptable.lookup (token->tokstr) != NULL) /* ignore words in skip table */
    goto nexttok;

  /* look for user defined symbols */

  if ((sym = usertable.lookup (token->tokstr)) != NULL) {
    token->type = TT_USERTOK;
    token->code = sym->getCode();
  } else
    token->code = 0;

  if (m_bTrace)
    sys_error (ERR_TRACE, "POL read token '%s', type = %d\n", token->tokstr, token->type);

  return (token->type);
}
コード例 #26
0
ファイル: gettoken.c プロジェクト: tangentforks/zpl
static int yylex2(void) {
  int ch;
  int chkcomment = FALSE;

yuk_a_goto:
	eatwhite();
	if ((ch = GETC(fname)) == EOF) {
	  if (firstsemi == 1) {
	    firstsemi = 0;
	    fclose(fname);
	    fname = fnamesave;
	    goto yuk_a_goto;
	  }
	  else {
	    return(TENDOFFILE);
	  }
	}
	do {
		if (ch == '/')
			if ((ch = GETC(fname)) == '*') {
				eatcomment();
				eatwhite();
				chkcomment = TRUE;
				if ((ch = GETC(fname)) == EOF)
					return(TENDOFFILE);
			} else {
				UNGETC(ch, fname);
				ch = '/';
				chkcomment = FALSE;
			}
		else if (ch == '-')	/* -- is a comment in our language */
		{
			if ((ch = GETC(fname)) == '-')
			{
				eatline();	 /* ignore rest of line */
				if (firstsemi != 1) yylineno++;
				eatwhite();
				chkcomment = TRUE;
				if ((ch = GETC(fname)) == EOF)
					return(TENDOFFILE);
			}
			else
			{
				UNGETC(ch, fname);
				ch = '-';
				chkcomment = FALSE;
			}
		}
		else
			chkcomment = FALSE;
	} while (chkcomment);
	if (isalpha(ch) || ch == '_')
		return(eatident(ch));
	if (isdigit(ch))
		return(eatnumber(ch));
	if (ch == '"')
		return(eatstring());
	if (ch == '\'') {
	  char ch2;
	  char ch3;
	  char chat;
	  int ate;
	  
	  ch2 = GETC(fname);
	  ch3 = GETC(fname);
	  UNGETC(ch3,fname);
	  UNGETC(ch2,fname);
	  if (ch2 != ' ' || ch3 != '\'') {
	    /* can't eat whitespace if char contains whitespace */
	    ate = eatwhite();
	    chat = GETC(fname);
	    UNGETC(chat,fname);
	    if (chat == '@') {
	      if (ate || (ch2 != '@' && ch3 != '\'')) {
		return TPRIME;
	      }
	    }
	  }
	  return eatcharacter();
	}
	if (ch == '.') {
		if (isdigit(ch = GETC(fname))) {
			UNGETC(ch, fname);
			ch = '.';
			return(eatnumber(ch));
		} else {
			UNGETC(ch, fname);
			ch = '.';
		}
	}
	if (ch == '#') {
	  char ch2;
		eatwhite();
		/* remove "line" if it exists - some vers of cpp have this */
		if ((ch2 = GETC(fname)) == '[') {
		  UNGETC(ch2, fname);
		  return eatleftovers(ch);
		}
		else {
		  UNGETC(ch2, fname);
		}
		if (!isdigit(ch = GETC(fname))) {
			UNGETC(ch, fname);
			yylex2();
			if (!strcmp(buffer,"pragma")) {
			  for (ch = GETC(fname); ch != '\n'; ch = GETC(fname)) ;
			  goto yuk_a_goto;
			}
			if (strcmp(buffer,"line")) {
			  USR_FATALX(yylineno, in_file,
				     "syntax error (appears to be a cpp directive: try -cpp)");
			}
			eatwhite();
		} else {
			UNGETC(ch, fname);
		}

		if (!isdigit(ch = GETC(fname))) {
			UNGETC(ch, fname);
			USR_FATALX(yylineno, in_file,
				   "syntax error (appears to be a cpp directive: use -cpp)");
		} else
			UNGETC(ch, fname);
		yylex2();
		yylineno = atoi(buffer);

		for (ch = GETC(fname); ch != '"' && ch != '\n'; ch = GETC(fname))
			;
		if (ch != '"') {
			goto yuk_a_goto;
		} else
			UNGETC(ch, fname);
		yylex2();

		
		in_file = (char *)PMALLOC((strlen(buffer) + 1)*sizeof(char));
		strcpy(in_file, buffer);
		base_in_file = strrchr(in_file,'/');
		if (base_in_file == NULL) {
		  base_in_file = in_file;
		} else {
		  base_in_file++;
		}
		for (ch = GETC(fname); ch != '\n'; ch = GETC(fname))
			;

		goto yuk_a_goto;
	}
	if (ispunct(ch))
		return(eatleftovers(ch));

	
	buffer[0] = ch; buffer[1] = '\0';

	  if (firstsemi == 1) {
	    firstsemi = 0;
	    fclose(fname);
	    fname = fnamesave;
	    goto yuk_a_goto;
	  }

	return(-1);
}
コード例 #27
0
ファイル: imap_proxy.c プロジェクト: pmhahn/cyrus-imapd
char *find_free_server(void)
{
    const char *servers = config_getstring(IMAPOPT_SERVERLIST);
    unsigned long max_avail = 0;
    char *server = NULL;

    if (servers) {
	char *tmpbuf, *cur_server, *next_server;
	char mytag[128];
	struct backend *be;

	/* make a working copy of the list */
	cur_server = tmpbuf = xstrdup(servers);

	while (cur_server) {
	    /* eat any leading whitespace */
	    while (Uisspace(*cur_server)) cur_server++;

	    if (!*cur_server) break;

	    /* find end of server */
	    if ((next_server = strchr(cur_server, ' ')) ||
		(next_server = strchr(cur_server, '\t')))
		*next_server++ = '\0';

	    syslog(LOG_DEBUG, "checking free space on server '%s'", cur_server);

	    /* connect to server */
	    be = proxy_findserver(cur_server, &imap_protocol,
				  proxy_userid, &backend_cached,
				  &backend_current, &backend_inbox, imapd_in);
	    if (be) {
		unsigned avail = 0;
		int c;

		/* fetch annotation from remote */
		proxy_gentag(mytag, sizeof(mytag));
		prot_printf(be->out,
			    "%s GETANNOTATION \"\" "
			    "\"/vendor/cmu/cyrus-imapd/freespace\" "
			    "\"value.shared\"\r\n", mytag);
		prot_flush(be->out);

		for (/* each annotation response */;;) {
		    /* read a line */
		    c = prot_getc(be->in);
		    if (c != '*') break;
		    c = prot_getc(be->in);
		    if (c != ' ') { /* protocol error */ c = EOF; break; }

		    c = chomp(be->in,
			      "ANNOTATION \"\" "
			      "\"/vendor/cmu/cyrus-imapd/freespace\" "
			      "(\"value.shared\" \"");
		    if (c == EOF) {
			/* we don't care about this response */
			eatline(be->in, c);
			continue;
		    }

		    /* read uidvalidity */
		    c = getuint32(be->in, &avail);
		    if (c != '\"') { c = EOF; break; }
		    eatline(be->in, c); /* we don't care about the rest of the line */
		}
		if (c != EOF) {
		    prot_ungetc(c, be->in);

		    /* we should be looking at the tag now */
		    eatline(be->in, c);
		}
		if (c == EOF) {
		    /* uh oh, we're not happy */
		    fatal("Lost connection to backend", EC_UNAVAILABLE);
		}
		if (avail > max_avail) {
		    server = cur_server;
		    max_avail = avail;
		}
	    }

	    /* move to next server */
	    cur_server = next_server;
	}

	if (server) server = xstrdup(server);

	free(tmpbuf);
    }

    return server;
}