Exemplo n.º 1
0
static void read_dangle(int use_dna_params, tab3_t *d3p, tab3_t *d5p)
{
  fill3(d3p, NOT_A_NUMBER);
  fill3(d5p, NOT_A_NUMBER);
  FILE *f = parfile("dangle", use_dna_params);
  char buf[MAXLINE+1];
  while (fgets(buf, MAXLINE, f)) {
    if (strlen(buf) >= MAXLINE)
      die("read_dangle: line too long");
    if (is_only_whitespace(buf))
      continue;
    look_for_line_containing(f, "5' --> 3'");
    read_next_line(f, buf);
    tab3_t *d = strchr(buf,'X') ? d3p : d5p;
    base_t a[4], b[4];
    read_four_bases(buf, a);
    read_next_line(f, buf);
    read_four_bases(buf, b);
    expect_line_containing(f, "3' <-- 5'");
    int_t val[16];
    read_next_values(f, val, 16);
    int i, j;
    for (i = 0; i < 4; i++)
      for (j = 0; j < 4; j++)
	(*d)[a[i]][b[i]][j] = val[4*i+j];
  }
  fclose(f);
}
Exemplo n.º 2
0
static void read_int21(int use_dna_params, tab7_t *t)
{
  fill7(t, NOT_A_NUMBER);
  FILE *f = parfile("int21", use_dna_params);
  look_for_line_containing(f, "5' --> 3'");
  char buf[MAXLINE+1];
  while (fgets(buf, MAXLINE, f)) {
    if (strlen(buf) >= MAXLINE)
      die("read_int21: line too long");
    if (is_only_whitespace(buf))
      continue;
    look_for_line_containing(f, "5' --> 3'");
    expect_line_containing(f, "X");
    base_t b1[12], b2[12], b3[6];
    read_next_line(f, buf);
    read_twelve_bases(buf, b1);
    read_next_line(f, buf);
    read_twelve_bases(buf, b2);
    read_next_line(f, buf);
    read_six_bases(buf, b3);
    expect_line_containing(f, "3' <-- 5'");
    int i;
    for (i = 0; i < 4; i++) {
      int_t val[24];
      read_next_values(f, val, 24);
      int j, k;
      for (j = 0; j < 6; j++)
	for (k = 0; k < 4; k++)
	  (*t)[b1[2*j]][b2[2*j]][i][k][b3[j]][b1[2*j+1]][b2[2*j+1]] = val[4*j+k];
    }
  }
  fclose(f);
}
  inline bool
  hash_commented_file_reader::read_to_next_valid_line()
  {

    if( file_is_open() )
      {

        while( !(read_next_line())
               &&
               !finished_reading_flag )
          {

            /* just keep reading in lines until either a valid line is found,
             * or we run out of file to read. when the loop is done,
             * finished_reading_flag is true if we didn't find a new valid
             * line, so we should return false, or it is false if we did, so we
             * should return true.
             */

          }

      }

    return !finished_reading_flag;

  }
Exemplo n.º 4
0
void
read_int(int *int_ptr)
{
	read_next_line();
	if (sscanf(top_file_ptr->line_buf, "%d", int_ptr) != 1)
		file_error("'%s' is not a valid integer", top_file_ptr->line_buf);
}
Exemplo n.º 5
0
static int_t next_value(FILE *f)
{
  look_for_arrow(f);
  char buf[MAXLINE+1];
  read_next_line(f, buf);
  return value_from_string(strtok(buf,whitespace));
}
Exemplo n.º 6
0
void	obj_read(t_obj *obj, int fd)
{
	ssize_t	readed;
	char	*line;

	while ((line = read_next_line(fd, &readed)) && readed > 0)
	{
		if (!(line = ft_strtrim(line)))
			ERROR("Failed to trim line");
		if (line[0] == 'v' && line[1] == ' ')
			obj_read_vertex(obj, line);
		else if (line[0] == 'f' && line[1] == ' ')
			obj_read_face(obj, line);
		else if (line[0] == 's' && line[1] == ' ')
			obj_read_smooth(obj, line);
		else if (line[0] == 'g' || line[0] == 'o')
			ft_putstr("");
		else if (ft_strlen(line) >= 7 && !ft_strncmp(line, "usemtl ", 7))
			obj_read_usemtl(obj, line);
		else if (ft_strlen(line) >= 7 && !ft_strncmp(line, "mtllib ", 7))
			obj_read_mtllib(obj, line);
		else if (ft_strlen(line) > 0 && line[0] != '#')
			ERROR("invalid obj file");
		free(line);
	}
	if (readed == -1)
		ERROR("failed to read file");
}
Exemplo n.º 7
0
static void read_next_values(FILE *f, int_t *v, int n)
{
  char buf[MAXLINE+1];
  read_next_line(f, buf);
  int i;
  for (i = 0; i < n; i++)
    v[i] = value_from_string(strtok(i == 0 ? buf : 0, whitespace));
}
Exemplo n.º 8
0
void
read_double(double *double_ptr)
{
	read_next_line();
	if (sscanf(top_file_ptr->line_buf, "%lf", double_ptr) != 1)
		file_error("'%s' is not a valid floating point number", 
			top_file_ptr->line_buf);
}
Exemplo n.º 9
0
static void
read_next_file_token(void)
{
	// If no file is open, generate an error.
	
	if (top_file_ptr == NULL)
		file_error("Internal error--attempt to read a file when no file is "
			"open");

	// If no tokens have been read from this file, read the first line.

	if (top_file_ptr->line_no == 0)
		read_next_line();

	// Repeat the following loop until we have the next available token.

	while (true) {

		// Extract the next token from the current line, after skipping over 
		// blank lines.

		extract_token();
		while (file_token == TOKEN_NONE) {
			read_next_line();
			extract_token();
		}

		// If the token is the start of a comment, skip over all tokens until
		// we find the end of the comment.

		if (file_token == TOKEN_OPEN_COMMENT) {
			extract_token();
			while (file_token != TOKEN_CLOSE_COMMENT) {
				if (file_token == TOKEN_NONE)
					read_next_line();
				extract_token();
			}
		}

		// Otherwise break out of this loop.

		else
			break;
	}
}
Exemplo n.º 10
0
static void stats_dump(const char *path, const char *cmd)
{
	struct istream *input;
	const char *const *args;
	unsigned int i;
	int fd;

	fd = doveadm_connect(path);
	net_set_nonblock(fd, FALSE);

	input = i_stream_create_fd(fd, (size_t)-1, TRUE);
	if (write_full(fd, cmd, strlen(cmd)) < 0)
		i_fatal("write(%s) failed: %m", path);

	/* read header */
	args = read_next_line(input);
	if (args == NULL)
		i_fatal("read(%s) unexpectedly disconnected", path);
	if (*args == NULL)
		i_info("no statistics available");
	else {
		for (; *args != NULL; args++)
			doveadm_print_header_simple(*args);

		/* read lines */
		do {
			T_BEGIN {
				args = read_next_line(input);
				if (args != NULL && args[0] == NULL)
					args = NULL;
				if (args != NULL) {
					for (i = 0; args[i] != NULL; i++)
						doveadm_print(args[i]);
				}
			} T_END;
		} while (args != NULL);
	}
	if (input->stream_errno != 0)
		i_fatal("read(%s) failed: %m", path);
	i_stream_destroy(&input);
}
Exemplo n.º 11
0
static void load_nls(void)
{
	const char *lang_file =
		ReadString(extensionsrcPath(), "blackbox.options.language:", NULL);
	if (NULL == lang_file) return;

	char full_path[MAX_PATH];
	FILE *fp = fopen (make_bb_path(full_path, lang_file), "rb");
	if (NULL == fp) return;

	char line[4000], key[200], new_text[4000], *np;
	int nl;
	key[0] = 0;

	new_text[0] = 0;
	np = new_text;
	nl = 0;
	for (;;)
	{
		bool eof = false == read_next_line(fp, line, sizeof line);
		char *s = line, c = *s;
		if ('$' == c || eof)
		{
			if (key[0] && new_text[0])
			{
				struct nls *t = (struct nls *)c_alloc(sizeof *t + strlen(key));
				t->hash = calc_hash(t->key, key, &t->k);
				t->translation = new_str(new_text);
				cons_node(&pNLS, t);
			}
			if (eof) break;
			if (' ' == s[1]) s += 2;
			decode_escape(key, s);
			new_text[0] = 0;
			np = new_text;
			nl = 0;
			continue;
		}

		if ('#' == c || '!' == c) continue;

		if ('\0' != c)
		{
			while (nl--) *np++ = '\n';
			np += decode_escape(np, s);
			nl = 0;
		}

		nl ++;
	}
	fclose(fp);
	reverse_list(&pNLS);
}
Exemplo n.º 12
0
void
read_name(char *name)
{
	char *end_ptr;

	read_next_line();
	end_ptr = strchr(top_file_ptr->line_buf, '_');
	if (end_ptr) {
		strncpy(name, top_file_ptr->line_buf, end_ptr - top_file_ptr->line_buf);
		name[end_ptr - top_file_ptr->line_buf] = '\0';
	} else
		strcpy(name, top_file_ptr->line_buf);
}
Exemplo n.º 13
0
static bool stats_top_round(struct top_context *ctx)
{
#define TOP_CMD "EXPORT\tsession\tconnected\n"
	const char *const *args;
	pool_t tmp_pool;

	if (write_full(ctx->fd, TOP_CMD, strlen(TOP_CMD)) < 0)
		i_fatal("write(%s) failed: %m", ctx->path);

	/* read header */
	if (ctx->headers != NULL) {
		args = read_next_line(ctx->input);
		if (args == NULL)
			i_fatal("read(%s) unexpectedly disconnected", ctx->path);
		if (*args == NULL)
			return TRUE;
		if (str_array_length(args) != ctx->headers_count)
			i_fatal("headers changed");
	} else {
		ctx->headers = p_read_next_line(default_pool, ctx->input);
		if (ctx->headers == NULL)
			i_fatal("read(%s) unexpectedly disconnected", ctx->path);
		if (*ctx->headers == NULL) {
			i_free_and_null(ctx->headers);
			return FALSE;
		}
		ctx->headers_count = str_array_length((void *)ctx->headers);
		if (!stats_header_find(ctx, "last_update", &ctx->last_update_idx))
			i_fatal("last_update header missing");
		if (!stats_header_find(ctx, "user", &ctx->user_idx))
			i_fatal("user header missing");
		stats_top_get_sorting(ctx);
	}

	array_clear(&ctx->lines);
	p_clear(ctx->prev_pool);
	tmp_pool = ctx->prev_pool;
	ctx->prev_pool = ctx->cur_pool;
	ctx->cur_pool = tmp_pool;

	ctx->flip = !ctx->flip;
	stats_read(ctx);
	stats_drop_stale(ctx);

	sort_ctx = ctx;
	array_sort(&ctx->lines, *ctx->lines_sort);
	sort_ctx = NULL;
	return TRUE;
}
Exemplo n.º 14
0
bool
read_int(int *int_ptr)
{
	// Read the next line.

	if (!read_next_line())
		return(false);

	// Parse the line as an integer.

	if (sscanf(line, "%d", int_ptr) != 1) {
		file_error("'%s' is not a valid integer", line);
		return(false);
	}
	return(true);
}
Exemplo n.º 15
0
bool
read_double(double *double_ptr)
{
	// Extract the next file token.

	if (!read_next_line())
		return(false);

	// Parse the token as a double.

	if (sscanf(line, "%lf", double_ptr) != 1) {
		file_error("'%s' is not a valid floating point number", line);
		return(false);
	}
	return(true);
}
Exemplo n.º 16
0
void PluginManager_Init()
{
    bbplugins = NULL;
    PluginManager_FT.dwLowDateTime =
    PluginManager_FT.dwHighDateTime = 0;

    const char *path=plugrcPath();
    get_filetime(path, &PluginManager_FT);

    FILE *fp = fopen(path,"rb");
    if (fp)
    {
        char szBuffer[MAX_PATH];
        while (read_next_line(fp, szBuffer, sizeof szBuffer))
            parse_plugin(szBuffer);
        fclose(fp);
    }
    load_all_plugins();
}
Exemplo n.º 17
0
static void run_client(gchar *host, gint port){
    register SocketClient *sc = SocketClient_create(host, port);
    register gchar *msg, *reply;
    while(TRUE){
        msg = read_next_line("> ");
        g_message("client going to send [%s]", msg);
        if(!msg)
            continue;
        if(!strncmp(msg, "quit client", 11))
            break;
        reply = SocketClient_send(sc, msg);
        if(reply){
            g_print(" reply [%s]", reply);
            g_free(reply);
            }
        g_free(msg);
        }
    SocketClient_destroy(sc);
    return;
    }
Exemplo n.º 18
0
static void rendertoiltiff( evalcontext* ecntxt )
{
  int nx=0, ny, nc, y;
  unsigned int *buf, *line;
  char *lbuf;
  ILTIFF *tif;

  if ( !renderfs )
    return;
  fflush( renderfs );
  rewind( renderfs );
  open_targa_rle( renderfs, &nx, &ny, &nc, ecntxt );
  if ( !( buf = (unsigned int*)malloc( nx*ny*sizeof( unsigned int ) ) ) )
  {
    ecntxt->cycles->errormsg( 408 );
    return;
  }
  lbuf = (char*)calloc( nx, 4 );
  line = buf;
  for ( y = 0; y < ny; y++, line += nx )
    read_next_line( renderfs, line, nx, nc, lbuf );
  sprintf_s( tifname , 128, "%s.%s", renderfilename, "tif" );
  tif = iltfwopen( "prd", tifname );
  iltiff_out( tif, (unsigned long*)buf, nx, ny, 64, 64, numcols==4, compressiltiff );
  ILTIFFClose( tif );

  fclose( renderfs );

  if ( !ecntxt->cycles->error )
    if ( remove( vstname ) )
      printf( "could not delete %s, %s\n", vstname, strerror( errno ) );


  free( lbuf );
  free( buf );
}
Exemplo n.º 19
0
/** Convert <b>po</b> from the PO format to a TS-formatted XML document.
 * <b>ts</b> will be set to the resulting TS document. Return the number of
 * converted strings on success, or -1 on error and <b>errorMessage</b> will
 * be set. */
int
po2ts(QTextStream *po, QDomDocument *ts, QString *errorMessage)
{
  QString line;
  QString msgctxt, msgid, msgstr;
  QHash<QString,QDomElement> contextElements;
  QDomElement contextElement, msgElement, transElement;
  int n_strings = 0;

  Q_ASSERT(po);
  Q_ASSERT(ts);
  Q_ASSERT(errorMessage);

  *ts = new_ts_document();
  
  skip_po_header(po);
  line = read_next_line(po);
  while (!po->atEnd()) {
    /* Ignore all "#" lines except "#:" */
    while (line.startsWith("#")) {
      if (line.startsWith("#:")) {
        /* Context was specified with the stupid overloaded "#:" syntax.*/
        msgctxt = line.section(" ", 1);
        msgctxt = parse_message_context_lame(msgctxt);
      }
      line = read_next_line(po);
    }

    /* A context specified on a "msgctxt" line takes precedence over a context
     * specified using the overload "#:" notation. */
    if (line.startsWith("msgctxt ")) {    
      msgctxt = line.section(" ", 1);
      msgctxt = parse_message_context(msgctxt);
      line = read_next_line(po);
    }
    
    /* Parse the (possibly multiline) message source string */
    if (!line.startsWith("msgid ")) {
      *errorMessage = "expected 'msgid' line";
      return -1;
    }
    msgid = line.section(" ", 1);
    
    line = read_next_line(po);
    while (line.startsWith("\"")) {
      msgid.append(line);
      line = read_next_line(po);
    }
    msgid = parse_message_string(msgid);

    /* Parse the (possibly multiline) translated string */
    if (!line.startsWith("msgstr ")) {
      *errorMessage = "expected 'msgstr' line";
      return -1;
    }
    msgstr = line.section(" ", 1);
    
    line = read_next_line(po);
    while (line.startsWith("\"")) {
      msgstr.append(line);
      line = read_next_line(po);
    }
    msgstr = parse_message_string(msgstr);

    /* Add the message and translation to the .ts document */
    if (contextElements.contains(msgctxt)) {
      contextElement = contextElements.value(msgctxt);
    } else {
      contextElement = new_context_element(ts, msgctxt);
      ts->documentElement().appendChild(contextElement);
      contextElements.insert(msgctxt, contextElement);
    }
    contextElement.appendChild(new_message_element(ts, msgid, msgstr)); 
    
    n_strings++;
  }
  return n_strings;
}
Exemplo n.º 20
0
TC_Error_Code TCDS_Ascii_Harmonic::LoadHarmonicData(IDX_entry *pIDX)
{
    Station_Data *psd = NULL;

    //    Look in the index first
    if(pIDX->pref_sta_data)
        return TC_NO_ERROR;         //easy


    // Try the member array of "already-looked-at" master stations
    for(unsigned int i=0 ; i < m_msd_array.GetCount() ; i++)
    {
        psd = &m_msd_array.Item(i);
        //    In the following comparison, it is allowed that the sub-station reference_name may be
        //          a pre-subset of the master station name.
        //          e.g  IDX_refence_name:  The Narrows midchannel New York
        //                            as found in HARMONIC.IDX
        //                 psd_station_name:      The Narrows, Midchannel, New York Harbor, New York Current
        //                            as found in HARMONIC
        if( (!slackcmp(psd->station_name, pIDX->IDX_reference_name)) && (toupper(pIDX->IDX_type) == psd->station_type) )
        {
            pIDX->pref_sta_data = psd;                // save for later
            return TC_NO_ERROR;
        }
    }


    //    OK, have to read and create from the raw file
    psd = NULL;

    //    If reference station was recently sought, and not found, don't bother
    //            if(!strcmp(pIDX->IDX_reference_name, plast_reference_not_found->mb_str()))
    if(m_last_reference_not_found.IsSameAs(wxString(pIDX->IDX_reference_name, wxConvUTF8)))
        return TC_MASTER_HARMONICS_NOT_FOUND;

    //    Clear for this looking
    m_last_reference_not_found.Clear();

    //    Find and load appropriate constituents
    FILE *fp;
    char linrec[linelen];
    fp = fopen (m_harmfile_name.mb_str(), "r");

    while (read_next_line (fp, linrec, 1))
    {
        nojunk (linrec);
        int curonly = 0;
        if (curonly)
            if (!strstr (linrec, "Current"))
                continue;
        //    See the note above about station names
        //                  if(!strncmp(linrec, "Rivi", 4))
        //                        int ggl = 4;

        if (slackcmp (linrec, pIDX->IDX_reference_name))
            continue;

        //    Got the right location, so load the data

        psd = new Station_Data;

        psd->amplitude = (double *)malloc(num_csts * sizeof(double));
        psd->epoch     = (double *)malloc(num_csts * sizeof(double));
        psd->station_name = (char *)malloc(strlen(linrec) +1);

        char junk[80];
        int a;
        strcpy (psd->station_name, linrec);

        //    Establish Station Type
        wxString caplin(linrec, wxConvUTF8);
        caplin.MakeUpper();
        if(caplin.Contains(_T("CURRENT")))
            psd->station_type = 'C';
        else
            psd->station_type = 'T';



        /* Get meridian */
        read_next_line (fp, linrec, 0);
        psd->meridian = hhmm2seconds (linrec);
        psd->zone_offset = 0;
        
        /* Get tzfile, if present */
        if (sscanf (nojunk(linrec), "%s %s", junk, psd->tzfile) < 2)
            strcpy (psd->tzfile, "UTC0");

        /* Get DATUM and units */
        read_next_line (fp, linrec, 0);
        if (sscanf (nojunk(linrec), "%lf %s", &(psd->DATUM), psd->unit) < 2)
            strcpy (psd->unit, "unknown");

        if ((a = findunit (psd->unit)) == -1)
        {
            // Nonsense....
            //                        strcpy (psd->units_abbrv, psd->unit);
            //                        strcpy (psd->units_conv, known_units[a].name);
        }

        psd->have_BOGUS = (findunit(psd->unit) != -1) && (known_units[findunit(psd->unit)].type == BOGUS);

        int unit_c;
        if (psd->have_BOGUS)
            unit_c = findunit("knots");
        else
            unit_c = findunit(psd->unit);

        if (unit_c != -1)
        {
            strcpy (psd->units_conv,       known_units[unit_c].name);
            strcpy (psd->units_abbrv,      known_units[unit_c].abbrv);
        }

        /* Get constituents */
        double loca, loce;
        for (a=0; a<num_csts; a++)
        {
            read_next_line (fp, linrec, 0);
            sscanf (linrec, "%s %lf %lf", junk, &loca, &loce);
            //          loc_epoch[a] *= M_PI / 180.0;
            psd->amplitude[a] = loca;
            psd->epoch[a] = loce * M_PI / 180.;
        }
        fclose (fp);

        break;
    }

    if(!psd) {
        m_last_reference_not_found = wxString(pIDX->IDX_reference_name, wxConvUTF8);
        return TC_MASTER_HARMONICS_NOT_FOUND;
    }
    else {
        m_msd_array.Add(psd);                     // add it to the member array
        pIDX->pref_sta_data = psd;
        return TC_NO_ERROR;
    }

}
Exemplo n.º 21
0
Arquivo: syntax.c Projeto: kusma/vasm
void parse(void)
{
  char *s,*line,*inst;
  char *ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1];
  char *op[MAX_OPERANDS];
  int ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1];
  int op_len[MAX_OPERANDS];
  int ext_cnt,op_cnt,inst_len;
  instruction *ip;

  while (line = read_next_line()) {

    if (!cond_state()) {
      /* skip source until ELSE or ENDIF */
      int idx = -1;

      s = skip(line);
      if (labname = parse_labeldef(&s,1)) {
        if (*s == ':')
          s++;  /* skip double-colon */
        myfree(labname);
        s = skip(s);
      }
      else {
        if (inst = skip_identifier(s)) {
          inst = skip(inst);
          idx = check_directive(&inst);
        }
      }
      if (idx < 0)
        idx = check_directive(&s);
      if (idx >= 0) {
        if (directives[idx].func == handle_if)
          cond_skipif();
        else if (directives[idx].func == handle_else)
          cond_else();
        else if (directives[idx].func == handle_endif)
          cond_endif();
      }
      continue;
    }

    s = skip(line);
again:
    if (*s=='\0' || *line=='*' || *s==commentchar)
      continue;

    if (labname = parse_labeldef(&s,1)) {
      /* we have found a valid global or local label */
      symbol *sym = new_labsym(0,labname);

      if (*s == ':') {
        /* double colon automatically declares label as exported */
        sym->flags |= EXPORT;
        s++;
      }
      add_atom(0,new_label_atom(sym));
      myfree(labname);
      s = skip(s);
    }
    else {
      /* there can still be a sym. in the 1st fld and an assignm. directive */
      inst = s;
      labname = parse_symbol(&s);
      if (labname == NULL) {
        syntax_error(10);  /* identifier expected */
        continue;
      }
      s = skip(s);

      /* Now we have labname pointing to the first field in the line
         and s pointing to the second. Find out where the directive is. */
      if (!ISEOL(s)) {
#ifdef PARSE_CPU_LABEL
        if (PARSE_CPU_LABEL(labname,&s)) {
          myfree(labname);
          continue;
        }
#endif
        if (handle_directive(s)) {
          myfree(labname);
          continue;
        }
      }

      /* directive or mnemonic must be in the first field */
      myfree(labname);
      s = inst;
    }

    if (!strnicmp(s,".iif",4) || !(strnicmp(s,"iif",3))) {
      /* immediate conditional assembly: parse line after ',' when true */
      s = skip(*s=='.'?s+4:s+3);
      if (do_cond(&s)) {
        s = skip(s);
        if (*s == ',') {
          s = skip(s+1);
          goto again;
        }
        else
          syntax_error(0);  /* malformed immediate-if */
      }
      continue;
    }

    /* check for directives */
    s = parse_cpu_special(s);
    if (ISEOL(s))
      continue;

    if (handle_directive(s))
      continue;

    /* read mnemonic name */
    inst = s;
    ext_cnt = 0;
    if (!ISIDSTART(*s)) {
      syntax_error(10);  /* identifier expected */
      continue;
    }
#if MAX_QUALIFIERS==0
    while (*s && !isspace((unsigned char)*s))
      s++;
    inst_len = s - inst;
#else
    s = parse_instruction(s,&inst_len,ext,ext_len,&ext_cnt);
#endif
    if (!isspace((unsigned char)*s) && *s!='\0')
      syntax_error(2);  /* no space before operands */
    s = skip(s);

    if (execute_macro(inst,inst_len,ext,ext_len,ext_cnt,s))
      continue;

    /* read operands, terminated by comma or blank (unless in parentheses) */
    op_cnt = 0;
    while (!ISEOL(s) && op_cnt<MAX_OPERANDS) {
      op[op_cnt] = s;
      s = skip_operand(s);
      op_len[op_cnt] = oplen(s,op[op_cnt]);
#if !ALLOW_EMPTY_OPS
      if (op_len[op_cnt] <= 0)
        syntax_error(5);  /* missing operand */
      else
#endif
        op_cnt++;
      s = skip(s);
      if (*s != ',')
        break;
      else
        s = skip(s+1);
    }
    eol(s);

    ip = new_inst(inst,inst_len,op_cnt,op,op_len);

#if MAX_QUALIFIERS>0
    if (ip) {
      int i;

      for (i=0; i<ext_cnt; i++)
        ip->qualifiers[i] = cnvstr(ext[i],ext_len[i]);
      for(; i<MAX_QUALIFIERS; i++)
        ip->qualifiers[i] = NULL;
    }
#endif

    if (ip)
      add_atom(0,new_inst_atom(ip));
  }

  cond_check();  /* check for open conditional blocks */
}
Exemplo n.º 22
0
Arquivo: syntax.c Projeto: ezrec/vasm
void parse(void)
{
  char *s,*line,*ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1],*op[MAX_OPERANDS];
  char *labname,*start;
  int inst_len,ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1],op_len[MAX_OPERANDS];
  int ext_cnt,op_cnt;
  instruction *ip;

  while (line=read_next_line()){
    if (clev >= MAXCONDLEV)
      syntax_error(16,clev);  /* nesting depth exceeded */

    if (!cond[clev]) {
      /* skip source until ELSE or ENDIF */
      int idx;

      s = line;
      idx = check_directive(&s);
      if (idx >= 0) {
        if (!strncmp(directives[idx].name,"if",2)) {
          ifnesting++;
        }
        else if (ifnesting==0 && !strncmp(directives[idx].name,"else",4)) {
          cond[clev] = 1;
        }
        else if (directives[idx].func == handle_endif) {
          if (ifnesting == 0) {
            if (clev > 0)
              clev--;
            else
              syntax_error(14);  /* endif without if */
          }
          else
            ifnesting--;
        }
      }
      continue;
    }

    s=skip(line);

    if(handle_directive(s))
      continue;

    /* skip spaces */
    s=skip(s);
    if(!*s||*s==commentchar)
      continue;

    /* check for label */
    start=s;
    if(labname=get_local_label(&s)){   /* local label? */
      if(*s!=':'){
        s=start;
        myfree(labname);
        labname=NULL;
      }
    }
    else if(ISIDSTART(*s)){            /* or global label? */
      s++;
      while(ISIDCHAR(*s)) s++;
      if(*s!=':')
        s=start;
      else
        labname=cnvstr(start,s-start);
    }
    if(labname){
      /* we have found a valid global or local label */
      add_atom(0,new_label_atom(new_labsym(0,labname)));
      s=skip(s+1);
      myfree(labname);
    }

    if(!*s||*s==commentchar)
      continue;

    s=skip(parse_cpu_special(s));
    if(*s==0||*s==commentchar)
      continue;

    if(handle_directive(s))
      continue;

    /* read mnemonic name */
    start=s;
    ext_cnt=0;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      continue;
    }
#if MAX_QUALIFIERS==0
    while(*s&&!isspace((unsigned char)*s))
      s++;
    inst_len=s-start;
#else
    s=parse_instruction(s,&inst_len,ext,ext_len,&ext_cnt);
#endif
    s=skip(s);

    if(execute_macro(start,inst_len,ext,ext_len,ext_cnt,s,clev))
      continue;

    /* read operands, terminated by comma (unless in parentheses)  */
    op_cnt=0;
    while(*s&&*s!=commentchar&&op_cnt<MAX_OPERANDS){
      op[op_cnt]=s;
      s=skip_operand(s);
      op_len[op_cnt]=oplen(s,op[op_cnt]);
#if !ALLOW_EMPTY_OPS
      if(op_len[op_cnt]<=0)
        syntax_error(5);
      else
#endif
        op_cnt++;
      s=skip(s);
      if(*s!=','){
        break;
      }else{
        s=skip(s+1);
      }
    }      
    s=skip(s);
    if(*s!=0&&*s!=commentchar) syntax_error(6);
    ip=new_inst(start,inst_len,op_cnt,op,op_len);
#if MAX_QUALIFIERS>0
    if(ip){
      int i;
      for(i=0;i<ext_cnt;i++)
        ip->qualifiers[i]=cnvstr(ext[i],ext_len[i]);
      for(;i<MAX_QUALIFIERS;i++)
        ip->qualifiers[i]=0;
    }
#endif
    if(ip){
      add_atom(0,new_inst_atom(ip));
    }else
      ;
  }

  if (clev > 0)
    syntax_error(15);  /* if without endif */
}
Exemplo n.º 23
0
Arquivo: syntax.c Projeto: ezrec/vasm
/* Very simple, very incomplete. */
void parse(void)
{
  char *s,*line,*inst,*ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1],*op[MAX_OPERANDS];
  int inst_len,ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1],op_len[MAX_OPERANDS];
  int i,ext_cnt,op_cnt,par_cnt;
  instruction *ip;
  while(line=read_next_line()){
    s=line;

    if(isalnum((unsigned char)*s)){
      /* Handle labels at beginning of line */
      char *labname,*equ;
      symbol *label;
      while(*s&&!isspace((unsigned char)*s)&&*s!=':')
        s++;
      labname=cnvstr(line,s-line);
      s=skip(s+1);
      if(!strncmp(s,"equ",3)&&isspace((unsigned char)s[3])){
        s=skip(s+3);
        label=new_abs(labname,parse_expr(&s));
      }else{
        label=new_labsym(0,labname);
        add_atom(0,new_label_atom(label));
      }
      free(labname);
    }

    s=parse_cpu_special(s);

    if(handle_directive(s))
      continue;

    /* skip spaces */
    s=skip(s);
    if(!*s)
      continue;

    /* read mnemonic name */
    inst=s;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      continue;
    }
#if MAX_QUALIFIERS==0
    while(*s&&!isspace((unsigned char)*s))
      s++;
#else
    while(*s&&*s!='.'&&!isspace((unsigned char)*s))
      s++;
#endif
    inst_len=s-inst;

    /* read qualifiers */
    ext_cnt=0;
    while(*s=='.'&&ext_cnt<MAX_QUALIFIERS){
      s++;
      ext[ext_cnt]=s;
      while(*s&&*s!='.'&&!isspace((unsigned char)*s))
        s++;
      ext_len[ext_cnt]=s-ext[ext_cnt];
      if(ext_len[ext_cnt]<=0)
        syntax_error(1);
      else
        ext_cnt++;
    }

    if(!isspace((unsigned char)*s)) syntax_error(2);
    
    /* read operands, terminated by comma (unless in parentheses)  */
    s=skip(s);
    op_cnt=0;
    while(*s&&op_cnt<MAX_OPERANDS){
      op[op_cnt]=s;
      s=skip_operand(s);
      op_len[op_cnt]=s-op[op_cnt];
      if(op_len[op_cnt]<=0)
        syntax_error(5);
      else
        op_cnt++;
      s=skip(s);
      if(*s!=','){
        break;
      }else{
        s=skip(s+1);
      }
    }      
    s=skip(s);
    if(*s!=0) syntax_error(6);
    ip=new_inst(inst,inst_len,op_cnt,op,op_len);
#if MAX_QUALIFIERS>0
    if(ip){
      for(i=0;i<ext_cnt;i++)
        ip->qualifiers[i]=cnvstr(ext[i],ext_len[i]);
      for(;i<MAX_QUALIFIERS;i++)
        ip->qualifiers[i]=0;
    }
#endif
    if(ip){
      add_atom(0,new_inst_atom(ip));
    }else
      ;
  }
}
Exemplo n.º 24
0
//    Load the Harmonic Constant Invariants
TC_Error_Code TCDS_Ascii_Harmonic::LoadHarmonicConstants(const wxString &data_file_path)
{
    FILE *fp;
    char linrec[linelen];
    char junk[80];
    int a, b;

    free_data();

    fp = fopen (data_file_path.mb_str(), "r");
    if (NULL == fp)
        return TC_FILE_NOT_FOUND;

    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_csts);

    m_cst_speeds = (double *) malloc (num_csts * sizeof (double));
    m_work_buffer = (double *) malloc (num_csts * sizeof (double));

    /* Load constituent speeds */
    for (a=0; a<num_csts; a++) {
        read_next_line (fp, linrec, 0);
        sscanf (linrec, "%s %lf", junk, &(m_cst_speeds[a]));
        m_cst_speeds[a] *= M_PI / 648000; /* Convert to radians per second */
    }

    /* Get first year for nodes and epochs */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &m_first_year);

    /* Load epoch table */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_epochs);

    m_cst_epochs = (double **) malloc (num_csts * sizeof (double *));
    for (int i=0; i<num_csts; i++)
        m_cst_epochs[i] = (double *) malloc (num_epochs * sizeof (double));

    for (int i=0; i<num_csts; i++)
    {
        if(EOF == fscanf (fp, "%s", linrec))
            return TC_HARM_FILE_CORRUPT;
        for (int b=0; b<num_epochs; b++)
        {
            if(EOF == fscanf (fp, "%lf", &(m_cst_epochs[i][b])))
                return TC_HARM_FILE_CORRUPT;
            m_cst_epochs[i][b] *= M_PI / 180.0;
        }
    }


    /* Sanity check */
    if(EOF == fscanf (fp, "%s", linrec))
        return TC_HARM_FILE_CORRUPT;
    skipnl (fp);

    /* Load node factor table */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_nodes);

    m_cst_nodes = (double **) malloc (num_csts * sizeof (double *));
    for (int a=0; a<num_csts; a++)
        m_cst_nodes[a] = (double *) malloc (num_nodes * sizeof (double));

    for (int a=0; a<num_csts; a++) {
        int ignore = fscanf (fp, "%s", linrec);
        for (b=0; b<num_nodes; b++)
            ignore = fscanf (fp, "%lf", &(m_cst_nodes[a][b]));
    }

    fclose(fp);

    return TC_NO_ERROR;
}