예제 #1
0
파일: verbose.c 프로젝트: GerHobbelt/BtYacc
void verbose(void)
{
    register int i;

    if (!vflag) return;

    null_rules = (Yshort *) NEW2(nrules, null_rules[0]);
    if (null_rules == 0) no_space();

    BtYacc_puts("\f\n", verbose_file);

    for (i = 0; i < nstates; ++i)
        print_state(i);
    FREE(null_rules);

    if (nunused)
        log_unused();
    if (SRtotal || RRtotal)
        log_conflicts();

    print_tokens();

    BtYacc_printf(verbose_file, "\n\n%d terminals, %d nonterminals\n%d grammar rules, %d states\n",
                  ntokens, nvars, nrules - 2, nstates);
}
예제 #2
0
파일: lexer.c 프로젝트: tmerlier/42sh
void		lexer(char *line, t_lex *lst)
{
	int		param[3];

	param[2] = 0;
	while (*line)
	{
		no_space(&line);
		if (!*line)
			break ;
		if ((is_token(line, param)))
		{
			add_token(&lst, param);
			line = line + param[1];
		}
		else if ((is_word(line, param)))
		{
			add_word(&lst, param, line);
			line = line + param[1];
		}
		else
		{
			add_word(&lst, NULL, line);
			line++;
		}
	}
	parser(&lst);
}
예제 #3
0
파일: verbose.c 프로젝트: SylvestreG/bitrig
void
verbose(void)
{
	int i;

	if (!vflag)
		return;

	null_rules = malloc(nrules * sizeof(short));
	if (null_rules == NULL)
		no_space();
	fprintf(verbose_file, "\f\n");
	for (i = 0; i < nstates; i++)
		print_state(i);
	free(null_rules);

	if (nunused)
		log_unused();
	if (SRtotal || RRtotal)
		log_conflicts();

	fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
	fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2,
	    nstates);
}
예제 #4
0
파일: reader.c 프로젝트: ChrisDodd/btyacc
static int cachec(int c)
{
    assert(cinc >= 0);
    if (cinc >= cache_size) {
	if (!(cache = REALLOC(cache, cache_size += 256))) no_space(); }
    return cache[cinc++] = c;
}
예제 #5
0
파일: mkpar.c 프로젝트: varialus/DragonFlyX
static void
unused_rules(void)
{
    int i;
    action *p;

    rules_used = (short *) MALLOC(nrules*sizeof(short));
    if (rules_used == NULL) no_space();

    for (i = 0; i < nrules; ++i)
        rules_used[i] = 0;

    for (i = 0; i < nstates; ++i)
    {
        for (p = parser[i]; p; p = p->next)
        {
            if (p->action_code == REDUCE && p->suppressed == 0)
                rules_used[p->number] = 1;
        }
    }

    nunused = 0;
    for (i = 3; i < nrules; ++i)
        if (!rules_used[i]) ++nunused;

    if (nunused) {
        if (nunused == 1)
            warnx("1 rule never reduced");
        else
            warnx("%d rules never reduced", nunused);
    }
}
예제 #6
0
파일: main.c 프로젝트: Mirocow/balancer
static void create_temp_name(char** filename, const char* prefix, const char* suffix) {
	*filename = MALLOC( strlen(prefix) + strlen(suffix) + 1 );
    if (0 == *filename)
        no_space();
	strcpy(*filename, prefix);
	strcat(*filename, suffix);
}
예제 #7
0
파일: mkpar.c 프로젝트: IanANGrant/mosml
void unused_rules(void)
{
    register int i;
    register action *p;

    rules_used = (short *) MALLOC(nrules*sizeof(short));
    if (rules_used == 0) no_space();

    for (i = 0; i < nrules; ++i)
	rules_used[i] = 0;

    for (i = 0; i < nstates; ++i)
    {
	for (p = parser[i]; p; p = p->next)
	{
	    if (p->action_code == REDUCE && p->suppressed == 0)
		rules_used[p->number] = 1;
	}
    }

    nunused = 0;
    for (i = 3; i < nrules; ++i)
	if (!rules_used[i]) ++nunused;

    if (nunused)
	if (nunused == 1)
	    fprintf(stderr, "%s: 1 rule never reduced\n", myname);
	else
	    fprintf(stderr, "%s: %d rules never reduced\n", myname, nunused);
}
예제 #8
0
파일: lr0.c 프로젝트: AhmadTux/DragonFlyBSD
static void
initialize_states(void)
{
    int i;
    short *start_derives;
    core *p;

    start_derives = derives[start_symbol];
    for (i = 0; start_derives[i] >= 0; ++i)
	continue;

    p = (core *) MALLOC(sizeof(core) + i*sizeof(short));
    if (p == NULL) no_space();

    p->next = 0;
    p->link = 0;
    p->number = 0;
    p->accessing_symbol = 0;
    p->nitems = i;

    for (i = 0;  start_derives[i] >= 0; ++i)
	p->items[i] = rrhs[start_derives[i]];

    first_state = last_state = this_state = p;
    nstates = 1;
}
예제 #9
0
void verbose(void)
{
    register int i;

    if (!vflag)
	return xml_output();
    
	
	/* else */
    null_rules = (short *)MALLOC(nrules * sizeof(short));
    if (null_rules == 0)
	no_space();
    fprintf(verbose_file, "\f\n");
    for (i = 0; i < nstates; i++)
	print_state(i);
    FREE(null_rules);

    if (nunused)
	log_unused();
    if (SRtotal || RRtotal)
	log_conflicts();

    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
}
예제 #10
0
char * allocate(unsigned n)
{
    register char *p;

    p = NULL;
    if (n)
    {
	p = CALLOC(1, n);
	if (!p) no_space();
    }
    return (p);
}
예제 #11
0
char *allocate(unsigned int n)
{
	char *p;

	p = NULL;
	if (n)
	{
		p = CALLOC(1, n);
		if (!p)
			no_space();
	}
	return (p);
}
예제 #12
0
파일: main.c 프로젝트: Alexpux/firebird
char *allocate(unsigned n)
{
    register char *p = NULL;
    if (n)
    {
        /* VM: add a few bytes here, cause 
         * Linux calloc does not like sizes like 32768 */
		p = CALLOC(1, n + 10);
		if (!p) 
			no_space();
    }
    return (p);
}
예제 #13
0
파일: readskel.c 프로젝트: ChrisDodd/btyacc
static void add_string(char *s)
{
int	len = strlen(s)+1;

    if (len > cp_end - cp) {
	int size = len > CHUNK ? len : CHUNK;
	if (!(cp = malloc(size)))
	    no_space();
	cp_end = cp + size; }
    memcpy(cp, s, len);
    add_ptr(cp);
    cp += len;
}
예제 #14
0
void set_nullable(void)
{
	register int i,
	    j;
	register int empty;
	int done;

	nullable = MALLOC(nsyms);
	if (nullable == 0)
		no_space();

	for (i = 0; i < nsyms; ++i)
		nullable[i] = 0;

	done = 0;
	while (!done)
	{
		done = 1;
		for (i = 1; i < nitems; i++)
		{
			empty = 1;
			while ((j = ritem[i]) >= 0)
			{
				if (!nullable[j])
					empty = 0;
				++i;
			}
			if (empty)
			{
				j = rlhs[-j];
				if (!nullable[j])
				{
					nullable[j] = 1;
					done = 0;
				}
			}
		}
	}

#ifdef DEBUG
	for (i = 0; i < nsyms; i++)
	{
		if (nullable[i])
			printf("%s is nullable\n", symbol_name[i]);
		else
			printf("%s is not nullable\n", symbol_name[i]);
	}
#endif
}
예제 #15
0
파일: readskel.c 프로젝트: ChrisDodd/btyacc
static void add_ptr(char *p)
{
    if (ap == ap_end) {
	int size = CHUNK;
	char **nap;
	while ((ap-ap_start) * sizeof(char *) >= size)
	    size = size * 2;
	if (!(nap = malloc(size)))
	    no_space();
	if (ap > ap_start)
	    memcpy(nap, ap_start, (ap-ap_start) * sizeof(char *));
	ap = nap + (ap - ap_start);
	ap_start = nap;
	ap_end = nap + size/sizeof(char *); }
    *ap++ = p;
}
예제 #16
0
파일: main.c 프로젝트: puppeh/ocaml-sh4
void getargs(int argc, char **argv)
{
    register int i;
    register char *s;

    if (argc > 0) myname = argv[0];
    for (i = 1; i < argc; ++i)
    {
        s = argv[i];
        if (*s != '-') break;
        switch (*++s)
        {
        case '\0':
            input_file = stdin;
            file_prefix = "stdin";
            if (i + 1 < argc) usage();
            return;

        case '-':
            ++i;
            goto no_more_options;

        case 'v':
            if (!strcmp (argv[i], "-version")){
              printf ("The Objective Caml parser generator, version "
                      OCAML_VERSION "\n");
              exit (0);
            }else{
              vflag = 1;
            }
            break;

        case 'q':
            qflag = 1;
            break;

        case 'b':
            if (*++s)
                 file_prefix = s;
            else if (++i < argc)
                file_prefix = argv[i];
            else
                usage();
            continue;

        default:
            usage();
        }

        for (;;)
        {
            switch (*++s)
            {
            case '\0':
                goto end_of_option;

            case 'v':
                vflag = 1;
                break;

            case 'q':
                qflag = 1;
                break;

            default:
                usage();
            }
        }
end_of_option:;
    }

no_more_options:;
    if (i + 1 != argc) usage();
    input_file_name = argv[i];
    if (file_prefix == 0) {
      int len;
      len = strlen(argv[i]);
      file_prefix = malloc(len + 1);
      if (file_prefix == 0) no_space();
      strcpy(file_prefix, argv[i]);
      while (len > 0) {
        len--;
        if (file_prefix[len] == '.') {
          file_prefix[len] = 0;
          break;
        }
      }
    }
}
예제 #17
0
파일: reader.c 프로젝트: ChrisDodd/btyacc
/*
 * Get line
 * Return: 1 - reg. line finished with '\n'.
 *         0 - EOF.
 */
char *get_line() {
  extern int Eflag;
  int c;
  int i;

 NextLine:;
  i = 0;

  if (saw_eof || (c = getc(input_file->file)) == EOF) {

    /* end of current file */
    if (input_file->next) {
      void *t = input_file;
      while (ifdef && ifdef->file == input_file) {
	void *t1 = ifdef;
	error(ifdef->lineno, 0, 0, "No %%endif for %%if");
	ifdef = ifdef->next;
	FREE(t1); }
      fclose(input_file->file);
      FREE(input_file->name);
      input_file = input_file->next;
      FREE(t);
      goto NextLine;
    }

    if (line) FREE(line);
    saw_eof = 1;
    return line = cptr = 0;
  }
  if (line == 0 || linesize != (LINESIZE + 1)) {
    if (line) FREE(line);
    linesize = LINESIZE + 1;
    if (!(line = MALLOC(linesize))) no_space();
  }
  ++input_file->lineno;
  while ((line[i] = c) != '\n') {
    if (++i + 1 >= linesize)
      if (!(line = REALLOC(line, linesize += LINESIZE)))
	no_space();
    if ((c = getc(input_file->file)) == EOF) {
      c = '\n';
      saw_eof = 1;
    }
  }
  line[i+1] = 0;

  /* VM: process %ifdef/%ifndef line */
  if (!strncmp(&line[0], "%ifdef ", 7) || !strncmp(&line[0], "%ifndef ", 8)) {
    char *var_name = line + 7;
    char **ps;
    while (isspace(*var_name)) var_name++;
    for(i=0; var_name[i]!='\n' && var_name[i]!=' '; i++);
    var_name[i] = 0;
    if (ifdef && ifdef->state) {
      ifdef->nested++;
    } else {
      struct ifdef_state *n = NEW(struct ifdef_state);
      n->next = ifdef;
      n->file = input_file;
      n->lineno = input_file->lineno;
      n->state = line[3] != 'n';
      n->nested = 0;
      ifdef = n;
      /* Find the preprocessor variable */
      for(ps=&defd_vars[0]; *ps; ps++) {
	if(strcmp(*ps,var_name)==0) {
	  n->state ^= 1;
	  break;
	}
      }
    }
    goto NextLine;
  }
예제 #18
0
static void
create_file_names(void)
{
    int i, len;
    const char *tmpdir;

    tmpdir = getenv("TMPDIR");
    if (tmpdir == NULL) tmpdir = "/tmp";

    len = strlen(tmpdir);
    i = len + 17;
    if (len && tmpdir[len-1] != '/')
	++i;

    action_file_name = MALLOC(i);
    if (action_file_name == NULL) no_space();
    text_file_name = MALLOC(i);
    if (text_file_name == NULL) no_space();
    union_file_name = MALLOC(i);
    if (union_file_name == NULL) no_space();

    strcpy(action_file_name, tmpdir);
    strcpy(text_file_name, tmpdir);
    strcpy(union_file_name, tmpdir);

    if (len && tmpdir[len - 1] != '/')
    {
	action_file_name[len] = '/';
	text_file_name[len] = '/';
	union_file_name[len] = '/';
	++len;
    }

    strcpy(action_file_name + len, temp_form);
    strcpy(text_file_name + len, temp_form);
    strcpy(union_file_name + len, temp_form);

    action_file_name[len + 5] = 'a';
    text_file_name[len + 5] = 't';
    union_file_name[len + 5] = 'u';

    if (output_file_name != NULL)
    {
	file_prefix = output_file_name;
	len = strlen(file_prefix);
    }
    else
    {
	len = strlen(file_prefix);
	output_file_name = MALLOC(len + 7);
	if (output_file_name == NULL)
	    no_space();
	strcpy(output_file_name, file_prefix);
	strcpy(output_file_name + len, OUTPUT_SUFFIX);
    }

    if (rflag)
    {
	code_file_name = MALLOC(len + 8);
	if (code_file_name == NULL)
	    no_space();
	strcpy(code_file_name, file_prefix);
	if (file_prefix == output_file_name)
	{
	    /*
	     * XXX ".tab.c" here is OUTPUT_SUFFIX, but since its length is
	     * in various magic numbers, don't bother using the macro.
	     */
	    if (len >= 6 && strcmp(code_file_name + len - 6, ".tab.c") == 0)
		strcpy(code_file_name + len - 6, CODE_SUFFIX);
	    else if (len >= 2 && strcmp(code_file_name + len - 2, ".c") == 0)
		strcpy(code_file_name + len - 2, CODE_SUFFIX);
	    else
		strcpy(code_file_name + len, CODE_SUFFIX);
	}
	else
	    strcpy(code_file_name + len, CODE_SUFFIX);
    }
    else
	code_file_name = output_file_name;

    if (dflag)
    {
	defines_file_name = MALLOC(len + 7);
	if (defines_file_name == NULL)
	    no_space();
	strcpy(defines_file_name, file_prefix);
	if (file_prefix == output_file_name)
	{
#define BISON_DEFINES_SUFFIX  ".h"
	    if (len >= 2 && strcmp(defines_file_name + len - 2, ".c") == 0)
		strcpy(defines_file_name + len - 2, BISON_DEFINES_SUFFIX);
	    else
		strcpy(defines_file_name + len, BISON_DEFINES_SUFFIX);
	}
	else
	    strcpy(defines_file_name + len, DEFINES_SUFFIX);
    }

    if (vflag)
    {
	verbose_file_name = MALLOC(len + 8);
	if (verbose_file_name == NULL)
	    no_space();
	strcpy(verbose_file_name, file_prefix);
	if (file_prefix == output_file_name)
	{
	    if (len >= 6 && strcmp(verbose_file_name + len - 6, ".tab.c") == 0)
		strcpy(verbose_file_name + len - 6, VERBOSE_SUFFIX);
	    else if (len >= 2 && strcmp(verbose_file_name + len - 2, ".c") == 0)
		strcpy(verbose_file_name + len - 2, VERBOSE_SUFFIX);
	    else
		strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
	}
	else
	    strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
    }
}
예제 #19
0
파일: main.c 프로젝트: LogosBible/mono
static void
create_file_names (void)
{
    int i, len;
    const char *tmpdir;
    int mkstemp_res GNUC_UNUSED;

#if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
    tmpdir = ".";
#else
    tmpdir = getenv("TMPDIR");
    if (tmpdir == 0) tmpdir = getenv ("TMP");
    if (tmpdir == 0) tmpdir = getenv ("TEMP");
    if (tmpdir == 0) tmpdir = "/tmp";
#endif

    len = strlen(tmpdir);
    i = len + 13;
    if (len && tmpdir[len-1] != '/')
	++i;

    action_file_name = (char*)MALLOC(i);
    if (action_file_name == 0) no_space();
    prolog_file_name =  (char*)MALLOC(i);
    if (prolog_file_name == 0) no_space();
    local_file_name =  (char*)MALLOC(i);
    if (local_file_name == 0) no_space();

    strcpy(action_file_name, tmpdir);
    strcpy(prolog_file_name, tmpdir);
    strcpy(local_file_name, tmpdir);

    if (len && tmpdir[len - 1] != '/')
    {
	action_file_name[len] = '/';
	prolog_file_name[len] = '/';
	local_file_name[len] = '/';
	++len;
    }

    strcpy(action_file_name + len, temp_form);
    strcpy(prolog_file_name + len, temp_form);
    strcpy(local_file_name + len, temp_form);

    action_file_name[len + 5] = 'a';
    prolog_file_name[len + 5] = 'p';
    local_file_name[len + 5] = 'l';

    mkstemp_res = mkstemp(action_file_name);
    mkstemp_res = mkstemp(prolog_file_name);
    mkstemp_res = mkstemp(local_file_name);

    len = strlen(file_prefix);

    if (vflag)
    {
	verbose_file_name = (char*)MALLOC(len + 8);
	if (verbose_file_name == 0)
	    no_space();
	strcpy(verbose_file_name, file_prefix);
	strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
    }
}
예제 #20
0
파일: main.c 프로젝트: Mirocow/balancer
static void create_file_names(void)
{
    register int len;
    register char *defines_suffix;
    register char *prefix;

    prefix = NULL;
    defines_suffix = DEFINES_SUFFIX;

    /* compute the file_prefix from the user provided output_file_name */
    if (output_file_name != 0)
    {
        defines_suffix = ".h";
	if (!(prefix = is_suffix(output_file_name, ".cpp")))
	    prefix = is_suffix(output_file_name, "");
    }

    if (prefix != NULL)
    {
	len = prefix - output_file_name;
	file_prefix = (char *)MALLOC(len + 1);
	if (file_prefix == 0)
	    no_space();
	strncpy(file_prefix, output_file_name, len)[len] = 0;
    }
    else
	len = strlen(file_prefix);

    /* if "-o filename" was not given */
    if (output_file_name == 0)
    {
	oflag = 1;
	CREATE_FILE_NAME(output_file_name, OUTPUT_SUFFIX);
    }

    if (rflag)
    {
	CREATE_FILE_NAME(code_file_name, CODE_SUFFIX);
    }
    else
	code_file_name = output_file_name;

    if (dflag)
    {
	CREATE_FILE_NAME(defines_file_name, defines_suffix);
    }

    if (vflag)
    {
	CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX);
    }

    if (gflag)
    {
	CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX);
    }

    if (prefix != NULL)
    {
	FREE(file_prefix);
    }

	create_temp_name(&text_file_name, output_file_name, ".byacc.text");
	create_temp_name(&union_file_name, output_file_name, ".byacc.union");
	create_temp_name(&action_file_name, output_file_name, ".byacc.action");
}
예제 #21
0
void create_file_names(void)
{
	int i,
	    len;
	char *tmpdir;

	tmpdir = getenv("TMPDIR");
#ifdef __WIN32__
	if (tmpdir == 0)
		tmpdir = ".";
#else
	if (tmpdir == 0)
		tmpdir = "/tmp";
#endif

	len = strlen(tmpdir);
	i = len + 13;
	if (len && tmpdir[len - 1] != '/')
		++i;

	action_file_name = MALLOC(i);
	if (action_file_name == 0)
		no_space();
	text_file_name = MALLOC(i);
	if (text_file_name == 0)
		no_space();
	union_file_name = MALLOC(i);
	if (union_file_name == 0)
		no_space();

	strcpy(action_file_name, tmpdir);
	strcpy(text_file_name, tmpdir);
	strcpy(union_file_name, tmpdir);

	if (len && tmpdir[len - 1] != '/')
	{
		action_file_name[len] = '/';
		text_file_name[len] = '/';
		union_file_name[len] = '/';
		++len;
	}

	strcpy(action_file_name + len, temp_form);
	strcpy(text_file_name + len, temp_form);
	strcpy(union_file_name + len, temp_form);

	action_file_name[len + 5] = 'a';
	text_file_name[len + 5] = 't';
	union_file_name[len + 5] = 'u';

	mktemp(action_file_name);
	mktemp(text_file_name);
	mktemp(union_file_name);

	if (ec_flag)
	{
		if (! file_prefix)
			file_prefix = ec_class_name;
	} else
	{
		if (! file_prefix)
			file_prefix = "y";
	}

	if (ec_flag)
	{
		len = strlen(file_prefix);

		if (!output_file_name)
		{
			output_file_name = MALLOC(len + strlen(EC_OUTPUT_SUFFIX) + 1);
			if (output_file_name == 0)
				no_space();
			strcpy(output_file_name, file_prefix);
			strcpy(output_file_name + len, EC_OUTPUT_SUFFIX);
		}
	} else
	{
		len = strlen(file_prefix);

		if (!output_file_name)
		{
			output_file_name = MALLOC(len + strlen(OUTPUT_SUFFIX) + 1);
			if (output_file_name == 0)
				no_space();
			strcpy(output_file_name, file_prefix);
			strcpy(output_file_name + len, OUTPUT_SUFFIX);
		}
	}

	if (rflag)
	{
		code_file_name = MALLOC(len + 8);
		if (code_file_name == 0)
			no_space();
		strcpy(code_file_name, file_prefix);
		strcpy(code_file_name + len, CODE_SUFFIX);
	} else
		code_file_name = output_file_name;

	if (dflag)
	{
		if (explicit_file_name)
		{
			defines_file_name = MALLOC(strlen(output_file_name));
			if (defines_file_name == 0)
				no_space();
			strcpy(defines_file_name, output_file_name);
			if (!strcmp(output_file_name + (strlen(output_file_name) - 2), ".c"))
				defines_file_name[strlen(output_file_name) - 1] = 'h';
		} else
		{
			defines_file_name = MALLOC(len + 7);
			if (defines_file_name == 0)
				no_space();
			strcpy(defines_file_name, file_prefix);
			strcpy(defines_file_name + len, DEFINES_SUFFIX);
		}
	}

	if (vflag)
	{
		verbose_file_name = MALLOC(len + 8);
		if (verbose_file_name == 0)
			no_space();
		strcpy(verbose_file_name, file_prefix);
		strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
	}
}
예제 #22
0
파일: main.c 프로젝트: puppeh/ocaml-sh4
void create_file_names(void)
{
    int i, len;
    char *tmpdir;

#ifdef NO_UNIX
    len = 0;
    i = sizeof(temp_form);
#else
    tmpdir = getenv("TMPDIR");
    if (tmpdir == 0) tmpdir = "/tmp";
    len = strlen(tmpdir);
    i = len + sizeof(temp_form);
    if (len && tmpdir[len-1] != '/')
        ++i;
#endif

    action_file_name = MALLOC(i);
    if (action_file_name == 0) no_space();
    entry_file_name = MALLOC(i);
    if (entry_file_name == 0) no_space();
    text_file_name = MALLOC(i);
    if (text_file_name == 0) no_space();
    union_file_name = MALLOC(i);
    if (union_file_name == 0) no_space();

#ifndef NO_UNIX
    strcpy(action_file_name, tmpdir);
    strcpy(entry_file_name, tmpdir);
    strcpy(text_file_name, tmpdir);
    strcpy(union_file_name, tmpdir);

    if (len && tmpdir[len - 1] != '/')
    {
        action_file_name[len] = '/';
        entry_file_name[len] = '/';
        text_file_name[len] = '/';
        union_file_name[len] = '/';
        ++len;
    }
#endif

    strcpy(action_file_name + len, temp_form);
    strcpy(entry_file_name + len, temp_form);
    strcpy(text_file_name + len, temp_form);
    strcpy(union_file_name + len, temp_form);

    action_file_name[len + 5] = 'a';
    entry_file_name[len + 5] = 'e';
    text_file_name[len + 5] = 't';
    union_file_name[len + 5] = 'u';

#ifndef NO_UNIX
    mktemp(action_file_name);
    mktemp(entry_file_name);
    mktemp(text_file_name);
    mktemp(union_file_name);
#endif

    len = strlen(file_prefix);

    output_file_name = MALLOC(len + 7);
    if (output_file_name == 0)
        no_space();
    strcpy(output_file_name, file_prefix);
    strcpy(output_file_name + len, OUTPUT_SUFFIX);

    code_file_name = output_file_name;

    if (vflag)
    {
        verbose_file_name = MALLOC(len + 8);
        if (verbose_file_name == 0)
            no_space();
        strcpy(verbose_file_name, file_prefix);
        strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
    }

    interface_file_name = MALLOC(len + 8);
    if (interface_file_name == 0)
        no_space();
    strcpy(interface_file_name, file_prefix);
    strcpy(interface_file_name + len, INTERFACE_SUFFIX);

}
예제 #23
0
void getargs(int argc, char *argv[])
{
    register int i;
    register char *s;

    if (argc > 0) myname = argv[0];
    for (i = 1; i < argc; ++i)
    {
	s = argv[i];
	if (*s != '-') break;
	switch (*++s)
	{
	case '\0':
	    input_file = stdin;
	    if (i + 1 < argc) usage();
	    return;

	case '-':
	    ++i;
	    goto no_more_options;

	case 'b':
	    if (*++s)
		 file_prefix = s;
	    else if (++i < argc)
		file_prefix = argv[i];
	    else
		usage();
	    continue;

	case 'v':
	    vflag = 1;
	    break;

	case 's':
	    sflag();
	    break;

	default:
	    usage();
	}

	for (;;)
	{
	    switch (*++s)
	    {
	    case '\0':
		goto end_of_option;

	    case 'v':
		vflag = 1;
		break;

	    case 's':
		sflag();
		break;

	    default:
		usage();
	    }
	}
end_of_option:;
    }

no_more_options:;
    if (i + 1 != argc) usage();
    input_file_name = argv[i];
    if (file_prefix == 0) {
      int len;
      len = strlen(argv[i]);
      file_prefix = malloc(len + 1);
      if (file_prefix == 0) no_space();
      strcpy(file_prefix, argv[i]);
      while (len > 0) {
        len--;
        if (file_prefix[len] == '.') {
          file_prefix[len] = 0;
          break;
        }
      }
    }
}
예제 #24
0
파일: output.c 프로젝트: sunfirefox/btyacc
void output_debug()
{
    register int i, j, k, max;
    char **symnam, *s;

    ++outline;
    fprintf(code_file, "#define YYFINAL %d\n", final_state);
    outline += 3;
    fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
	    tflag);
    if (rflag)
	fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
		tflag);

    max = 0;
    for (i = 2; i < ntokens; ++i)
	if (symbol_value[i] > max)
	    max = symbol_value[i];
    ++outline;
    fprintf(code_file, "#define YYMAXTOKEN %d\n", max);

    symnam = (char **) MALLOC((max+1)*sizeof(char *));
    if (symnam == 0) no_space();

    /* Note that it is  not necessary to initialize the element		*/
    /* symnam[max].							*/
    for (i = 0; i < max; ++i)
	symnam[i] = 0;
    for (i = ntokens - 1; i >= 2; --i)
	symnam[symbol_value[i]] = symbol_name[i];
    symnam[0] = "end-of-file";

    if (!rflag) ++outline;
    fprintf(output_file, "#if YYDEBUG\n");
    if (!rflag)
	fprintf(output_file, "static ");
    fprintf(output_file, "char *yyname[] = {");
    j = 80;
    for (i = 0; i <= max; ++i)
    {
	if ((s = symnam[i]))
	{
	    if (s[0] == '"')
	    {
		k = 7;
		while (*++s != '"')
		{
		    ++k;
		    if (*s == '\\')
		    {
			k += 2;
			if (*++s == '\\')
			    ++k;
		    }
		}
		j += k;
		if (j > 80)
		{
		    if (!rflag) ++outline;
		    putc('\n', output_file);
		    j = k;
		}
		fprintf(output_file, "\"\\\"");
		s = symnam[i];
		while (*++s != '"')
		{
		    if (*s == '\\')
		    {
			fprintf(output_file, "\\\\");
			if (*++s == '\\')
			    fprintf(output_file, "\\\\");
			else
			    putc(*s, output_file);
		    }
		    else
			putc(*s, output_file);
		}
		fprintf(output_file, "\\\"\",");
	    }
	    else if (s[0] == '\'')
	    {
		if (s[1] == '"')
		{
		    j += 7;
		    if (j > 80)
		    {
			if (!rflag) ++outline;
			putc('\n', output_file);
			j = 7;
		    }
		    fprintf(output_file, "\"'\\\"'\",");
		}
		else
		{
		    k = 5;
		    while (*++s != '\'')
		    {
			++k;
			if (*s == '\\')
			{
			    k += 2;
			    if (*++s == '\\')
				++k;
			}
		    }
		    j += k;
		    if (j > 80)
		    {
			if (!rflag) ++outline;
			putc('\n', output_file);
			j = k;
		    }
		    fprintf(output_file, "\"'");
		    s = symnam[i];
		    while (*++s != '\'')
		    {
			if (*s == '\\')
			{
			    fprintf(output_file, "\\\\");
			    if (*++s == '\\')
				fprintf(output_file, "\\\\");
			    else
				putc(*s, output_file);
			}
			else
			    putc(*s, output_file);
		    }
		    fprintf(output_file, "'\",");
		}
	    }
	    else
	    {
		k = strlen(s) + 3;
		j += k;
		if (j > 80)
		{
		    if (!rflag) ++outline;
		    putc('\n', output_file);
		    j = k;
		}
		putc('"', output_file);
		do { putc(*s, output_file); } while (*++s);
		fprintf(output_file, "\",");
	    }
	}
	else
	{
	    j += 2;
	    if (j > 80)
	    {
		if (!rflag) ++outline;
		putc('\n', output_file);
		j = 2;
	    }
	    fprintf(output_file, "0,");
	}
    }
    if (!rflag) outline += 2;
    fprintf(output_file, "\n};\n");
    FREE(symnam);

    if (!rflag) ++outline;
    if (!rflag)
	fprintf(output_file, "static ");
    fprintf(output_file, "char *yyrule[] = {\n");
    for (i = 2; i < nrules; ++i)
    {
	fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
	for (j = rrhs[i]; ritem[j] > 0; ++j)
	{
	    s = symbol_name[ritem[j]];
	    if (s[0] == '"')
	    {
		fprintf(output_file, " \\\"");
		while (*++s != '"')
		{
		    if (*s == '\\')
		    {
			if (s[1] == '\\')
			    fprintf(output_file, "\\\\\\\\");
			else
			    fprintf(output_file, "\\\\%c", s[1]);
			++s;
		    }
		    else
			putc(*s, output_file);
		}
		fprintf(output_file, "\\\"");
	    }
	    else if (s[0] == '\'')
	    {
		if (s[1] == '"')
		    fprintf(output_file, " '\\\"'");
		else if (s[1] == '\\')
		{
		    if (s[2] == '\\')
			fprintf(output_file, " '\\\\\\\\");
		    else
			fprintf(output_file, " '\\\\%c", s[2]);
		    s += 2;
		    while (*++s != '\'')
			putc(*s, output_file);
		    putc('\'', output_file);
		}
		else
		    fprintf(output_file, " '%c'", s[1]);
	    }
	    else
		fprintf(output_file, " %s", s);
	}
	if (!rflag) ++outline;
	fprintf(output_file, "\",\n");
    }

    if (!rflag) outline += 2;
    fprintf(output_file, "};\n#endif\n");
}
예제 #25
0
파일: output.c 프로젝트: sunfirefox/btyacc
int pack_vector(int vector)
{
    register int i, j, k, l;
    register int t;
    register int loc;
    register int ok;
    register Yshort *from;
    register Yshort *to;
    int newmax;

    i = order[vector];
    t = tally[i];
    assert(t);

    from = froms[i];
    to = tos[i];

    j = lowzero - from[0];
    for (k = 1; k < t; ++k)
	if (lowzero - from[k] > j)
	    j = lowzero - from[k];
    for (;; ++j)
    {
	if (j == 0)
	    continue;
	ok = 1;
	for (k = 0; ok && k < t; k++)
	{
	    loc = j + from[k];
	    if (loc >= maxtable)
	    {
		if (loc >= MAXTABLE)
		    fatal("maximum table size exceeded");

		newmax = maxtable;
		do { newmax += 200; } while (newmax <= loc);
		table = (Yshort *) REALLOC(table, newmax*sizeof(Yshort));
		if (table == 0) no_space();
		check = (Yshort *) REALLOC(check, newmax*sizeof(Yshort));
		if (check == 0) no_space();
		for (l  = maxtable; l < newmax; ++l)
		{
		    table[l] = 0;
		    check[l] = -1;
		}
		maxtable = newmax;
	    }

	    if (check[loc] != -1)
		ok = 0;
	}
	for (k = 0; ok && k < vector; k++)
	{
	    if (pos[k] == j)
		ok = 0;
	}
	if (ok)
	{
	    for (k = 0; k < t; k++)
	    {
		loc = j + from[k];
		table[loc] = to[k];
		check[loc] = from[k];
		if (loc > high) high = loc;
	    }

	    while (check[lowzero] != -1)
		++lowzero;

	    return (j);
	}
    }
}
예제 #26
0
파일: main.c 프로젝트: sunfirefox/btyacc
void create_file_names()
{
    int i, len;
    char *tmpdir;

    tmpdir = getenv("TMPDIR");
    if (tmpdir == 0) tmpdir = DEFAULT_TMPDIR;

    len = strlen(tmpdir);
    i = len + 13;
    if (len && tmpdir[len-1] != DIR_CHAR)
	++i;

    action_file_name = MALLOC(i);
    if (action_file_name == 0) no_space();
    text_file_name = MALLOC(i);
    if (text_file_name == 0) no_space();
    union_file_name = MALLOC(i);
    if (union_file_name == 0) no_space();

    strcpy(action_file_name, tmpdir);
    strcpy(text_file_name, tmpdir);
    strcpy(union_file_name, tmpdir);

    if (len && tmpdir[len - 1] != DIR_CHAR)
    {
	action_file_name[len] = DIR_CHAR;
	text_file_name[len] = DIR_CHAR;
	union_file_name[len] = DIR_CHAR;
	++len;
    }

    strcpy(action_file_name + len, temp_form);
    strcpy(text_file_name + len, temp_form);
    strcpy(union_file_name + len, temp_form);

    action_file_name[len + 5] = 'a';
    text_file_name[len + 5] = 't';
    union_file_name[len + 5] = 'u';

    if(mktemp(action_file_name)==NULL) {
      fprintf(stderr, "btyacc: Cannot create temporary file\n");
      exit(1);
    }
    if(mktemp(text_file_name)==NULL) {
      fprintf(stderr, "btyacc: Cannot create temporary file\n");
      exit(1);
    }
    if(mktemp(union_file_name)==NULL) {
      fprintf(stderr, "btyacc: Cannot create temporary file\n");
      exit(1);
    }

    len = strlen(file_prefix);

    output_file_name = MALLOC(len + 7);
    if (output_file_name == 0)
	no_space();
    strcpy(output_file_name, file_prefix);
    strcpy(output_file_name + len, OUTPUT_SUFFIX);

    if (rflag)
    {
	code_file_name = MALLOC(len + 8);
	if (code_file_name == 0)
	    no_space();
	strcpy(code_file_name, file_prefix);
	strcpy(code_file_name + len, CODE_SUFFIX);
    }
    else
	code_file_name = output_file_name;

    if (dflag)
    {
	defines_file_name = MALLOC(len + 7);
	if (defines_file_name == 0)
	    no_space();
	strcpy(defines_file_name, file_prefix);
	strcpy(defines_file_name + len, DEFINES_SUFFIX);
    }

    if (vflag)
    {
	verbose_file_name = MALLOC(len + 8);
	if (verbose_file_name == 0)
	    no_space();
	strcpy(verbose_file_name, file_prefix);
	strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
    }
}
예제 #27
0
파일: main.c 프로젝트: AgamAgarwal/minix
static void
create_file_names(void)
{
    size_t len;
    const char *defines_suffix;
    const char *externs_suffix;
    char *prefix;

    prefix = NULL;
    defines_suffix = DEFINES_SUFFIX;
    externs_suffix = EXTERNS_SUFFIX;

    /* compute the file_prefix from the user provided output_file_name */
    if (output_file_name != 0)
    {
	if (!(prefix = strstr(output_file_name, ".tab.c"))
	    && (prefix = strstr(output_file_name, ".c")))
	{
	    defines_suffix = ".h";
	    externs_suffix = ".i";
	}
    }

    if (prefix != NULL)
    {
	len = (size_t) (prefix - output_file_name);
	file_prefix = MALLOC(len + 1);
	NO_SPACE(file_prefix);
	strncpy(file_prefix, output_file_name, len)[len] = 0;
    }
    else
	len = strlen(file_prefix);

    /* if "-o filename" was not given */
    if (output_file_name == 0)
    {
	oflag = 1;
	CREATE_FILE_NAME(output_file_name, OUTPUT_SUFFIX);
    }

    if (rflag)
    {
	CREATE_FILE_NAME(code_file_name, CODE_SUFFIX);
    }
    else
	code_file_name = output_file_name;

    if (dflag)
    {
	if (explicit_file_name)
	{
	    char *suffix;
	    defines_file_name = strdup(output_file_name);
	    if (defines_file_name == 0)
		no_space();
	    /* does the output_file_name have a known suffix */
            suffix = strrchr(output_file_name, '.');
            if (suffix != 0 &&
		(!strcmp(suffix, ".c") ||   /* good, old-fashioned C */
                 !strcmp(suffix, ".C") ||   /* C++, or C on Windows */
                 !strcmp(suffix, ".cc") ||  /* C++ */
                 !strcmp(suffix, ".cxx") || /* C++ */
                 !strcmp(suffix, ".cpp")))  /* C++ (Windows) */
            {
                strncpy(defines_file_name, output_file_name,
                        suffix - output_file_name + 1);
                defines_file_name[suffix - output_file_name + 1] = 'h';
                defines_file_name[suffix - output_file_name + 2] = 0;
            } else {
                fprintf(stderr,"%s: suffix of output file name %s"
                               " not recognized, no -d file generated.\n",
                        myname, output_file_name);
                dflag = 0;
                free(defines_file_name);
                defines_file_name = 0;
            }
	} else {
	    CREATE_FILE_NAME(defines_file_name, defines_suffix);
	}
    }

    if (iflag)
    {
	CREATE_FILE_NAME(externs_file_name, externs_suffix);
    }

    if (vflag)
    {
	CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX);
    }

    if (gflag)
    {
	CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX);
    }

    if (prefix != NULL)
    {
	FREE(file_prefix);
    }
}