Пример #1
0
static int rpmfd_init(rpmfdObject *s, PyObject *args, PyObject *kwds)
{
    char *kwlist[] = { "obj", "mode", "flags", NULL };
    const char *mode = "r";
    const char *flags = "ufdio";
    char *rpmio_mode = NULL;
    PyObject *fo = NULL;
    FD_t fd = NULL;
    int fdno;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, 
				     &fo, &mode, &flags))
	return -1;

    rpmio_mode = rstrscat(NULL, mode, ".", flags, NULL);

    if (PyBytes_Check(fo)) {
	fd = openPath(PyBytes_AsString(fo), rpmio_mode);
    } else if (PyUnicode_Check(fo)) {
	PyObject *enc = NULL;
	int rc;
#if PY_MAJOR_VERSION >= 3
	rc = PyUnicode_FSConverter(fo, &enc);
#else
	rc = utf8FromPyObject(fo, &enc);
#endif
	if (rc) {
	    fd = openPath(PyBytes_AsString(enc), rpmio_mode);
	    Py_DECREF(enc);
	}
    } else if (rpmfdObject_Check(fo)) {
	rpmfdObject *fdo = (rpmfdObject *)fo;
	fd = openFd(fdDup(Fileno(fdo->fd)), rpmio_mode);
    } else if ((fdno = PyObject_AsFileDescriptor(fo)) >= 0) {
	fd = openFd(fdDup(fdno), rpmio_mode);
    } else {
	PyErr_SetString(PyExc_TypeError, "path or file object expected");
    }

    if (fd != NULL) {
	Fclose(s->fd); /* in case __init__ was called again */
	free(s->mode);
	free(s->flags);
	s->fd = fd;
	s->mode = rstrdup(mode);
	s->flags = rstrdup(flags);
    } else {
	PyErr_SetString(PyExc_IOError, Fstrerror(fd));
    }

    free(rpmio_mode);
    return (fd == NULL) ? -1 : 0;
}
Пример #2
0
/* Declare a new temporary that can be assigned a value of type t.
   Place the declaration at the start of block. 
   Return it's declaration */
data_declaration add_temporary(region r, compound_stmt block, type t)
{
  const char *name = next_temporary();
  data_decl dd = build_declaration(r, NULL, t, name, NULL, NULL);
  struct data_declaration tempdecl;
  data_declaration ddecl;

  /* Add to the function's declarations */
  dd->next = CAST(node, block->decls);
  block->decls = CAST(declaration, dd);

#if 0
  /* Set parent pointers */
  AST_set_parents(CAST(node, dd));
  dd->parent = CAST(node, block);
  dd->parent_ptr = CASTSRPTR(node, &block->decls);
  if (dd->next)
    dd->next->parent_ptr = &dd->next;
#endif

  /* Declare the variable */
  init_data_declaration(&tempdecl, dd->decls, rstrdup(r, name), t);
  tempdecl.kind = decl_variable;
  tempdecl.vtype = variable_normal;
  tempdecl.islocal = TRUE;
  ddecl = declare(block->env, &tempdecl, FALSE);
  CAST(variable_decl, dd->decls)->ddecl = ddecl;

  return ddecl;
}
Пример #3
0
static void add_program_files(const char *file_list, dd_list files)
{
  FILE *list = fopen(file_list, "r");
  
  if(!list)
    {
      error("unable to open %s", file_list);
      return;
    }

  /* each line in */
  while(!ferror(list) && !feof(list))
    {
      char *newline = NULL;
      char name[PATH_MAX] = {0};
      
      if(!fgets(name, PATH_MAX, list))
	break;

      /* if there is a \n, replace it with \0 */
      newline = strchr(name, (int)'\n');
      if (newline)
	*newline = '\0';

      /* add the file to the files list */
      dd_add_last(parse_region, files, rstrdup(parse_region, name));
    }
}
Пример #4
0
int main(int argc, char *argv[])
{
  region r[11];
  int i = 0;
  node n = NULL;
  region node_region;
  
  region_init();
  list_init();
  hash_table_init();
  banshee_region_persistence_init();
  seed_fn_ptr_table(newregion());

  node_region = newregion();

  r[10] = NULL;
  r[9] = strbucket_region;
  r[8] = banshee_ptr_region;
  r[7] = list_strnode_region;
  r[6] = list_node_region;
  r[5] = list_header_region;
  r[4] = banshee_nonptr_region;
  r[3] = bucket_region;
  r[2] = table_region;
  r[1] = bucketptr_region;
  r[0] = node_region;

  thetable = make_persistent_string_hash_table(8, 1);
  thelist = new_persistent_node_list();

  for(i = 0; i < NUM_NODES; i++) {
    char str[512];
    node prev = n;
    n = ralloc(node_region, struct node_);
    n->data = i;
    n->next = prev;

    snprintf(str, 512,"node(%d)", i);

    hash_table_insert(thetable, (hash_key)rstrdup(banshee_nonptr_region, str),
		      (hash_data)n);
    node_list_append_tail(n, thelist);
  }

  serialize(r, "data", "offsets");

  update();
  if (!verify()) {
    printf("Failed region persist test\n");
    exit(1);
  }
  else {
    printf("Passed region persist test\n");
    exit(0);
  }

}
Пример #5
0
static void processProgHeaders(elfInfo *ei, GElf_Ehdr *ehdr)
{
    for (size_t i = 0; i < ehdr->e_phnum; i++) {
	GElf_Phdr mem;
	GElf_Phdr *phdr = gelf_getphdr(ei->elf, i, &mem);

	if (phdr && phdr->p_type == PT_INTERP) {
	    size_t maxsize;
	    char * filedata = elf_rawfile(ei->elf, &maxsize);

	    if (filedata && phdr->p_offset < maxsize) {
		ei->interp = rstrdup(filedata + phdr->p_offset);
		break;
	    }
	}
    }
}
Пример #6
0
static bool var_info_insert(var_info v_info)
{
  char buf[MAX_STR];

  /* This extra renaming step is here because of a slight difference
      in hash table semantics-- in dhash (which env uses), a scan will
      see hidden bindings, but not so w/ Jeff's hash implementation
  */
  snprintf(buf, MAX_STR, "%s::%d", v_info->name, acnt.collection_count++);

  if(v_info->visible)
    hash_table_insert(collection_hash,(hash_key)rstrdup(banshee_nonptr_region, buf),
		      (hash_data)v_info->t_type);
  switch (v_info->kind)
    {
    case vk_local :
      {
	env_add(local_env, v_info->name, v_info);
	return TRUE;
      }
      break;
    case vk_static :
      {
	env_add(file_env, v_info->name, v_info);
	return TRUE;
      }
      break;
    case vk_global :
      {
	assert(!seen_global(v_info->name));
	//env_add(global_var_env, v_info->name, v_info);
	hash_table_insert(global_var_hash, (hash_key)v_info->name, 
			  (hash_data)v_info);
	return FALSE;
      }
      break;
    }
  assert(0);
  return FALSE;
}
Пример #7
0
static void processVerDef(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
{
    Elf_Data *data = NULL;
    unsigned int offset, auxoffset;
    char *soname = NULL;

    while ((data = elf_getdata(scn, data)) != NULL) {
	offset = 0;

	for (int i = shdr->sh_info; --i >= 0; ) {
	    GElf_Verdef def_mem, *def;
	    def = gelf_getverdef (data, offset, &def_mem);
	    if (def == NULL)
		break;
	    auxoffset = offset + def->vd_aux;
	    offset += def->vd_next;

	    for (int j = def->vd_cnt; --j >= 0; ) {
		GElf_Verdaux aux_mem, * aux;
		const char *s;
		aux = gelf_getverdaux (data, auxoffset, &aux_mem);
		if (aux == NULL)
		    break;
		s = elf_strptr(ei->elf, shdr->sh_link, aux->vda_name);
		if (s == NULL)
		    break;
		if (def->vd_flags & VER_FLG_BASE) {
		    rfree(soname);
		    soname = rstrdup(s);
		    auxoffset += aux->vda_next;
		    continue;
		} else if (soname && !soname_only && !skipPrivate(s)) {
		    addDep(&ei->provides, soname, s, ei->marker);
		}
	    }
		    
	}
    }
    rfree(soname);
}
Пример #8
0
static void processVerNeed(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
{
    Elf_Data *data = NULL;
    char *soname = NULL;
    while ((data = elf_getdata(scn, data)) != NULL) {
	unsigned int offset = 0, auxoffset;
	for (int i = shdr->sh_info; --i >= 0; ) {
	    const char *s = NULL;
	    GElf_Verneed need_mem, *need;
	    need = gelf_getverneed (data, offset, &need_mem);
	    if (need == NULL)
		break;

	    s = elf_strptr(ei->elf, shdr->sh_link, need->vn_file);
	    if (s == NULL)
		break;
	    rfree(soname);
	    soname = rstrdup(s);
	    auxoffset = offset + need->vn_aux;

	    for (int j = need->vn_cnt; --j >= 0; ) {
		GElf_Vernaux aux_mem, * aux;
		aux = gelf_getvernaux (data, auxoffset, &aux_mem);
		if (aux == NULL)
		    break;
		s = elf_strptr(ei->elf, shdr->sh_link, aux->vna_name);
		if (s == NULL)
		    break;

		if (ei->isExec && soname && !soname_only && !skipPrivate(s)) {
		    addDep(&ei->requires, soname, s, ei->marker);
		}
		auxoffset += aux->vna_next;
	    }
	    offset += need->vn_next;
	}
    }
    rfree(soname);
}
Пример #9
0
static void processDynamic(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
{
    Elf_Data *data = NULL;
    while ((data = elf_getdata(scn, data)) != NULL) {
	for (int i = 0; i < (shdr->sh_size / shdr->sh_entsize); i++) {
	    const char *s = NULL;
	    GElf_Dyn dyn_mem, *dyn;

	    dyn = gelf_getdyn (data, i, &dyn_mem);
	    if (dyn == NULL)
		break;

	    switch (dyn->d_tag) {
	    case DT_HASH:
		ei->gotHASH = 1;
		break;
	    case DT_GNU_HASH:
		ei->gotGNUHASH = 1;
		break;
	    case DT_DEBUG:
		ei->gotDEBUG = 1;
		break;
	    case DT_SONAME:
		s = elf_strptr(ei->elf, shdr->sh_link, dyn->d_un.d_val);
		if (s)
		    ei->soname = rstrdup(s);
		break;
	    case DT_NEEDED:
		if (ei->isExec) {
		    s = elf_strptr(ei->elf, shdr->sh_link, dyn->d_un.d_val);
		    if (s)
			addDep(&ei->requires, s, NULL, ei->marker);
		}
		break;
	    }
	}
    }
}
Пример #10
0
static int exec_cond(int op, int arg1, int arg2)
{
  int i;
  
  switch(op) 
    {
    /* First the conditions */
    case 0: cret(loc+first_room==arg1);  /* AtLoc(Room) */
    case 1: cret(loc+first_room>arg1); 
    case 2: cret(loc+first_room<arg1); 
    case 3: return musiccmd(-1,-1); /* SongPlaying */
    case 4: return musiccmd(-2,-1); /* SoundIsOn */
    case 5: cret(vb<=13 && vb>0 && 
		 room[loc].path[vb-1]>=first_room);/*DirOK*/
    case 6: cret(vb==arg1);  /* DirectionIs */
    case 7: cret(loc+first_room>=arg1 && 
		 loc+first_room<=arg2); /* BetweenRooms  ?? */
    case 8: cret(room[arg1-first_room].seen);
    case 9:  /* Entered Object? i.e. is iobj valid */
      cret(do_disambig==1 || iobj>0); 
    case 10: cret(curr_time>arg1);  /* TimeGT */
    case 11: cret(curr_time<arg1);  /* TimeLT */
    case 12: cret(first_visit_flag);
    case 13: cret(newlife_flag);
    case 14: cret(player_contents!=0);  /* CarrySome */
    case 15: cret(player_contents==0); /* CarryNo */
    case 16: cret(player_worn!=0);  /* WearSome */
    case 18: cret(player_worn==0); /* WearNo */
    case 17:          /* CarryTreas */
      contloop(i,1)
	if (tnoun(i) && noun[i-first_noun].points>=arg1) return 1;
      contloop(i,1000)
	if (tnoun(i) && noun[i-first_noun].points>=arg1) return 1;	
      return 0;
    case 19:cret(totwt==arg1);
    case 20:cret(totwt>arg1);
    case 21:cret(totwt<arg1);
    case 22: case 23: case 24: case 25: case 26: case 27: case 28:
      return obj_cond(op-22,arg1,arg2);
    case 29:cret(it_loc(arg1)==it_loc(arg2));
    case 30: case 31:
      return obj_cond(op-23,arg1,arg2);
    case 32:cret(it_group(arg1));
    case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40:
      return obj_cond(op-24,arg1,arg2);
    case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48:
    case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56:
    case 57:
      return obj_cond(op-41,dobj,arg1);
    case 58:cretn(dobj,points==arg1);
    case 59:cretn(dobj,points>arg1);
    case 60:cretn(dobj,points<arg1);
    case 61:cretn(dobj,weight==arg1);
    case 62:cretn(dobj,weight>arg1);
    case 63:cretn(dobj,weight<arg1);
    case 64:cret(islit());
    case 65:cret(room[loc].light!=0);
    case 66:cret(flag[arg1]);
    case 67:cret(!flag[arg1]);
    case 68:cret(room[loc].flag_noun_bits & (1 << (arg1-1) )  );
    case 70:cret( !(room[loc].flag_noun_bits & (1 << (arg1-1) ) ));
    case 69:cret(room[loc].PIX_bits & (1 << (arg1-1) )); /* Room Pix here? */
    case 71:cret(tscore==arg1);
    case 72:cret(tscore>arg1);
    case 73:cret(tscore<arg1);
    case 74:cret(agt_number==arg1);
    case 75:cret(agt_number>arg1);
    case 76:cret(agt_number<arg1);
    case 77:cret(agt_answer);
    case 78:cret(!agt_answer);
    case 79:cret(turncnt==arg1);
    case 80:cret(turncnt>arg1);
    case 81:cret(turncnt<arg1);
    case 82:cret(cnt_val(agt_counter[arg1])==arg2);
    case 83:cret(cnt_val(agt_counter[arg1])>arg2);
    case 84:cret(cnt_val(agt_counter[arg1])<arg2);
	
    case 85:cret(agt_var[arg1]==arg2);
    case 86:cret(agt_var[arg1]>arg2);
    case 87:cret(agt_var[arg1]<arg2);
    case 88:cret(agt_var[arg1]<agt_var[arg2]);      
    case 89:cret(agt_var[arg1]<agt_rand(1,arg2));
    case 90:cret( (actor!=0) && (it_loc(actor)==loc+first_room));
    case 91:cret(actor==arg1);
    case 92:cret(dobj==arg1);
    case 93:cret(do_disambig==1 || iobj==arg1);
    case 94:cret(it_contents(arg1)!=0);
    case 95:cret(agt_rand(1,100)<=arg1);
    case 96:cret(yesno("Yes or no? "));
    case 97:cret(!yesno("Yes or no? "));
    case 98:cret(vb>0 && vb<=13);
    case 99:cret(tcreat(dobj));
    case 100:cretc(dobj,gender==2); /* man */
    case 101:cretc(dobj,gender==1); /* woman */
    case 102:cretc(dobj,gender==0); /* thing */
    case 103:cretc(iobj,gender==2);
    case 104:cretc(iobj,gender==1); /* woman */
    case 105:cretc(iobj,gender==0); /* thing */      
    case 106:cret(do_disambig==1 || tcreat(iobj));
    case 107:return (do_disambig==1 || obj_cond(0,iobj,0));
      /* OR and NOT are handled higher up. */
      /* The following are all v1.8x metacommands */
    case 110:cret(beforecmd);   
    case 111:cret(!beforecmd); 
    case 112:cret(curr_time/100==arg1); /* HoursEqual */
    case 113:cret(curr_time/100>arg1);  
    case 114:cret(curr_time/100<arg1);
    case 115:cret(curr_time%100==arg1); /* MinutesEqual */
    case 116:cret(curr_time%100>arg1);
    case 117:cret(curr_time%100<arg1);
    case 118:cret(curr_time<1200);    /* IsAM */ 

    case 119:cret(do_disambig);     /* OnDisambig */
    case 120:cretc(arg1,hostile);    /* IsHostile */
    case 121:         /* HostilePresent */
      creatloop(i)
	if (creature[i].location==loc+first_room &&
	    creature[i].hostile) return 1;
      return 0;
      /* Otherwise, we're in trouble. */
    case 122: cret(actor_in_scope); /* NameWasPresent */
    case 123: /* OncePerTurn */
      if (beforecmd)
	cret(start_of_turn);  
      else 
	cret(end_of_turn);
    case 124:  /* IsClass */
      cret(arg2==0 || matchclass(arg1,arg2));
    case 125: cret(getattr(arg1,arg2)); /* IsSet */
    case 126: cret(is_numeric(dobj_rec));
    case 127: cret(is_numeric(iobj_rec));
    case 128: cret(arg1==arg2);
    case 129: cret(arg1>arg2);
    case 130: cret(arg1<arg2);
    case 131: cret(arg1>=arg2);
    case 132: cret(arg1<=arg2);
    case 133: cret(strcmp(userstr[arg1-1],userstr[arg2-1])==0);
    case 134: cret(strcmp(userstr[arg1-1],userstr[arg2-1])<0);
    case 135: cret(strcmp(userstr[arg1-1],userstr[arg2-1])>0);
    case 136: cret(strcasecmp(userstr[arg1-1],userstr[arg2-1])==0);
    case 137: cret(strcasecmp(userstr[arg1-1],userstr[arg2-1])<0);
    case 138: cret(strcasecmp(userstr[arg1-1],userstr[arg2-1])>0);
    case 139: cret(match_answer(rstrdup(userstr[arg1-1]),arg2-1));
      /* Note that match_answer rfrees it's first argument */
    case 140: cret(it_seen(arg1));
    case 141: cret(op_objflag(2,arg1,arg2));
    case 142: cret(!op_objflag(2,arg1,arg2));
    case 143: 
      i=it_room(arg1);
      cret( troom(i) && troom(room[i-first_room].path[arg2-1]) );
    default: writeln("INTERNAL ERROR: Condition token not supported.");
	rprintf("Condition #%d",op);
	writeln(""); 
	return 0;
      }
}
Пример #11
0
static char *getname(int inum)
/* Name should be 20 chars or less */
{
  if (inum==0) return rstrdup("* 0 *");
  return objname(inum);
}
Пример #12
0
static int processFile(const char *fn, int dtype)
{
    int rc = 1;
    int fdno = -1;
    struct stat st;
    GElf_Ehdr *ehdr, ehdr_mem;
    elfInfo *ei = rcalloc(1, sizeof(*ei));

    fdno = open(fn, O_RDONLY);
    if (fdno < 0 || fstat(fdno, &st) < 0)
	goto exit;

    (void) elf_version(EV_CURRENT);
    ei->elf = elf_begin(fdno, ELF_C_READ, NULL);
    if (ei->elf == NULL || elf_kind(ei->elf) != ELF_K_ELF)
	goto exit;

    ehdr = gelf_getehdr(ei->elf, &ehdr_mem);
    if (ehdr == NULL)
	goto exit;

    if (ehdr->e_type == ET_DYN || ehdr->e_type == ET_EXEC) {
	ei->marker = mkmarker(ehdr);
    	ei->isDSO = (ehdr->e_type == ET_DYN);
	ei->isExec = (st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH));

	processProgHeaders(ei, ehdr);
	processSections(ei);
    }

    /*
     * For DSOs which use the .gnu_hash section and don't have a .hash
     * section, we need to ensure that we have a new enough glibc.
     */
    if (ei->isExec && ei->gotGNUHASH && !ei->gotHASH && !soname_only) {
	argvAdd(&ei->requires, "rtld(GNU_HASH)");
    }

    /*
     * For DSOs, add DT_SONAME as provide. If its missing, we can fake
     * it from the basename if requested. The bizarre looking DT_DEBUG
     * check is used to avoid adding basename provides for PIE executables.
     */
    if (ei->isDSO && !ei->gotDEBUG) {
	if (!ei->soname && fake_soname) {
	    const char *bn = strrchr(fn, '/');
	    ei->soname = rstrdup(bn ? bn + 1 : fn);
	}
	if (ei->soname)
	    addDep(&ei->provides, ei->soname, NULL, ei->marker);
    }

    /* If requested and present, add dep for interpreter (ie dynamic linker) */
    if (ei->interp && require_interp)
	argvAdd(&ei->requires, ei->interp);

    rc = 0;
    /* dump the requested dependencies for this file */
    for (ARGV_t dep = dtype ? ei->requires : ei->provides; dep && *dep; dep++) {
	fprintf(stdout, "%s\n", *dep);
    }

exit:
    if (fdno >= 0) close(fdno);
    if (ei) {
	argvFree(ei->provides);
	argvFree(ei->requires);
	free(ei->soname);
	free(ei->interp);
    	if (ei->elf) elf_end(ei->elf);
	rfree(ei);
    }
    return rc;
}
Пример #13
0
bool sv_eq(setif_var v1, setif_var v2)
{
  return ( sv_get_stamp(v1) == sv_get_stamp(v2) );
}

static setif_var make_var(region r, const char *name, stamp st)
{
  setif_var result = ralloc(setif_var_region, struct setif_var_);
  sv_info info = ralloc(sv_info_region, struct sv_info_);
 
  info->st = st;
  info->lbs = bounds_persistent_create();
  info->ubs = bounds_persistent_create();
  info->tlb_cache = NULL;
  info->ub_projs = new_gen_e_list(r);
  info->name = name ? rstrdup(banshee_nonptr_region,name) : rstrdup(banshee_nonptr_region, "fv");
  info->component = new_uf_element(NULL, NULL, BANSHEE_PERSIST_KIND_nonptr);

  result->type = VAR_TYPE;
  result->elt = new_sv_elt(NULL,info); 
  
#ifdef NONSPEC
  result->sort = setif_sort;
#endif  
  
  return result;
}

setif_var sv_fresh(region r, const char *name)
{
  return make_var(r,name,stamp_fresh());
Пример #14
0
/* Entry point of cc1/c++.  Decode command args, then call compile_file.
   Exit code is 35 if can't open files, 34 if fatal error,
   33 if had nonfatal errors, else success.  */
int main(int argc, char **argv)
{
  register int i;
  dd_list files, preludes;
  dd_list_pos cur;
  int version_flag = 0;
  char *p;
  char *config_file = NULL;

#ifdef TIMER_USERTIME
  reset_timer(&total_time);
#endif
  start_timer(&total_time);
  region_init();
  parse_region = newregion();
  in_prelude = FALSE;
  num_hotspots = 0;
  parsed_files = dd_new_list(parse_region);

  copy_argc = 0;
  copy_argv = xmalloc((argc + 1) * sizeof(*copy_argv));
  files = dd_new_list(parse_region);
  preludes = dd_new_list(parse_region);

  p = argv[0] + strlen (argv[0]);
  while (p != argv[0] && p[-1] != '/'
#ifdef DIR_SEPARATOR
	 && p[-1] != DIR_SEPARATOR
#endif
	 )
    --p;
  progname = p;

#ifdef SIGPIPE
  signal (SIGPIPE, pipe_closed);
#endif

  copy_argv[0] = argv[0];
  copy_argc = 1;
  for (i = 1; i < argc; i++)
    {
      int j;
      bool copy_arg = TRUE;

      /* If this is a language-specific option,
	 decode it in a language-specific way.  */
      for (j = 0; lang_options[j] != 0; j++)
	if (!strncmp (argv[i], lang_options[j],
		      strlen (lang_options[j])))
	  break;
      if (lang_options[j] != 0)
	/* If the option is valid for *some* language,
	   treat it as valid even if this language doesn't understand it.  */
	c_decode_option(argv[i]);
      else if (argv[i][0] == '-' && argv[i][1] != 0)
	{
	  register char *str = argv[i] + 1;
	  if (str[0] == 'Y')
	    str++;

	  if (!strcmp (str, "dumpbase"))
	    copy_argv[copy_argc++] = argv[i++];
	  else if (str[0] == 'f')
	    {
	      register char *p = &str[1];
	      int found = 0;

	      /* Some kind of -f option.
		 P's value is the option sans `-f'.
		 Search for it in the table of options.  */

	      for (j = 0;
		   !found && j < sizeof (f_options) / sizeof (f_options[0]);
		   j++)
		{
		  if (!strcmp (p, f_options[j].string))
		    {
		      *f_options[j].variable = f_options[j].on_value;
		      /* A goto here would be cleaner,
			 but breaks the vax pcc.  */
		      found = 1;
		    }
		  if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
		      && ! strcmp (p+3, f_options[j].string))
		    {
		      *f_options[j].variable = ! f_options[j].on_value;
		      found = 1;
		    }
		}
	    }
	  else if (!strcmp (str, "pedantic"))
	    pedantic = 1;
	  else if (!strcmp (str, "pedantic-errors"))
	    flag_pedantic_errors = pedantic = 1;
	  else if (!strcmp (str, "quiet"))
	    quiet_flag = 1;
	  else if (!strcmp (str, "version"))
	    version_flag = 1;
	  else if (!strcmp (str, "w"))
	    inhibit_warnings = 1;
	  else if (!strcmp (str, "W"))
	    {
	      extra_warnings = 1;
	      /* We save the value of warn_uninitialized, since if they put
		 -Wuninitialized on the command line, we need to generate a
		 warning about not using it without also specifying -O.  */
	      if (warn_uninitialized != 1)
		warn_uninitialized = 2;
	    }
	  else if (str[0] == 'W')
	    {
	      register char *p = &str[1];
	      int found = 0;

	      /* Some kind of -W option.
		 P's value is the option sans `-W'.
		 Search for it in the table of options.  */

	      for (j = 0;
		   !found && j < sizeof (W_options) / sizeof (W_options[0]);
		   j++)
		{
		  if (!strcmp (p, W_options[j].string))
		    {
		      *W_options[j].variable = W_options[j].on_value;
		      /* A goto here would be cleaner,
			 but breaks the vax pcc.  */
		      found = 1;
		    }
		  if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
		      && ! strcmp (p+3, W_options[j].string))
		    {
		      *W_options[j].variable = ! W_options[j].on_value;
		      found = 1;
		    }
		}

	      if (found)
		;
	      else if (!strncmp (p, "id-clash-", 9))
		{
		  char *endp = p + 9;

		  while (*endp)
		    {
		      if (*endp >= '0' && *endp <= '9')
			endp++;
		      else
			{
			  error ("Invalid option `%s'", argv[i]);
			  goto id_clash_lose;
			}
		    }
		  warn_id_clash = 1;
		  id_clash_len = atoi (str + 10);
		id_clash_lose: ;
		}
	      else if (!strncmp (p, "larger-than-", 12))
		{
		  char *endp = p + 12;

		  while (*endp)
		    {
		      if (*endp >= '0' && *endp <= '9')
			endp++;
		      else
			{
			  error ("Invalid option `%s'", argv[i]);
			  goto larger_than_lose;
			}
		    }
		  warn_larger_than = 1;
		  larger_than_size = atoi (str + 13);
		larger_than_lose: ;
		}
	    }
	  else if (!strcmp (str, "o"))
	    copy_argv[copy_argc++] = argv[i++];
	  else if (str[0] == 'G')
	    {
	      if (str[1] == '\0')
		copy_argv[copy_argc++] = argv[i++];
	    }
	  else if (!strncmp (str, "aux-info", 8))
	    {
	      if (str[8] == '\0')
		copy_argv[copy_argc++] = argv[i++];
	    }
	  else if (!strcmp(str, "config"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  config_file = strdup(argv[i]);
		}
	      else
		error ("Missing -config file");
	    }
	  else if (!strcmp(str, "prelude"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  dd_add_last(parse_region, preludes,
			      rstrdup(parse_region, argv[i]));
		}
	      else
		error("Missing -prelude file");
	    }
	  else if (!strcmp(str, "hotspots"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  num_hotspots = atoi(argv[i]);
		  if (num_hotspots < 0)
		    error("Negative value for -hotspots count");
		}
	      else
		error("Missing -hotspots count");
	    }
	  else if (!strcmp( str, "program-files"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  add_program_files(argv[i], files);
		}
	      else
		error("Missing -program-files file");
	    }
	}
      else if (argv[i][0] == '+')
	;
      else
	{
	  /* Allow wildcards, because PAM won't expand files */
	  glob_t globbuf;
	  char **cur;

	  if (glob(argv[i], 0, NULL, &globbuf))
	    {
	      /* glob returned non-zero error status; abort */
	      fprintf(stderr, "%s: file not found\n", argv[i]);
	      exit(FATAL_EXIT_CODE);
	    }
	  else
	    for (cur = globbuf.gl_pathv; *cur; cur++)
	      {
		/* Assume anything called prelude.i is a prelude file */
		if ( strlen(*cur) >= 9 &&
                    !strncmp("prelude.i", *cur + strlen(*cur) - 9, 9))
		  dd_add_last(parse_region, preludes,
			      rstrdup(parse_region, *cur));
		else
		  dd_add_last(parse_region, files,
			      rstrdup(parse_region, *cur));
	      }
	  copy_arg = FALSE;
	}

      if (copy_arg)
	copy_argv[copy_argc++] = argv[i];
    }
  copy_argv[copy_argc] = NULL;

  if (flag_casts_preserve && flag_flow_sensitive) {
    fprintf(stderr, "-fcasts-preserve currently not allowed with "
	    "-fflow_sensitive");
    exit(FATAL_EXIT_CODE);
  }

  /* Now analyze *all* of the files.  First, initialize all appropriate
     data structures. */
  init_types();
  cval_init();
  init_effects();
  init_qtype();
  init_quals();
  init_qerror();

  init_store();

  if (config_file)
    load_config_file_quals(config_file);

  /* Add const so that we can do -fconst-subtyping no matter what */
  if (!const_qual)
    {
      begin_po_qual();
      const_qual = add_qual("const");
      add_level_qual(const_qual, level_ref);
      set_po_nonprop();
      end_po_qual();
    }

  /* Add volatile so we can handle noreturn functions */
  if (!volatile_qual)
    {
      begin_po_qual();
      volatile_qual = add_qual("volatile");
      add_level_qual(volatile_qual, level_ref);
      add_sign_qual(volatile_qual, sign_eq);
      set_po_nonprop();
      end_po_qual();
    }

  /* Add noreturn, for non-returning functions */
  if (!noreturn_qual)
    {
      begin_po_qual();
      noreturn_qual = add_qual("noreturn");
      add_level_qual(noreturn_qual, level_value);
      add_sign_qual(noreturn_qual, sign_eq);
      set_po_nonprop();
      end_po_qual();
    }

  end_define_pos(); /* Allow cqual to run with no qualifiers */

  init_pam();
  init_analyze();
  found_fs_qual = FALSE; /* Force reset, since init_analyze may
			    look up some quals */

  /* Now analyze the prelude files */
  in_prelude = TRUE;
  dd_scan(cur, preludes)
    {
      char *file;
      
      file = DD_GET(char *, cur);
      fprintf(stderr, "Analyzing prelude %s\n", file);
      compile_file(file);
    }
Пример #15
0
static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag)
{
    struct Source *p;
    int flag = 0;
    const char *name = NULL;
    char *nump;
    char *fieldp = NULL;
    char *buf = NULL;
    uint32_t num = 0;

    switch (tag) {
      case RPMTAG_SOURCE:
	flag = RPMBUILD_ISSOURCE;
	name = "source";
	fieldp = spec->line + 6;
	break;
      case RPMTAG_PATCH:
	flag = RPMBUILD_ISPATCH;
	name = "patch";
	fieldp = spec->line + 5;
	break;
      case RPMTAG_ICON:
	flag = RPMBUILD_ISICON;
	fieldp = NULL;
	break;
      default:
	return -1;
	break;
    }

    /* Get the number */
    if (tag != RPMTAG_ICON) {
	/* We already know that a ':' exists, and that there */
	/* are no spaces before it.                          */
	/* This also now allows for spaces and tabs between  */
	/* the number and the ':'                            */
	char ch;
	char *fieldp_backup = fieldp;

	while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) {
	    fieldp++;
	}
	ch = *fieldp;
	*fieldp = '\0';

	nump = fieldp_backup;
	SKIPSPACE(nump);
	if (nump == NULL || *nump == '\0') {
	    num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX;
	} else {
	    if (parseUnsignedNum(fieldp_backup, &num)) {
		rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"),
			 spec->lineNum, name, spec->line);
		*fieldp = ch;
		return RPMRC_FAIL;
	    }
	}
	*fieldp = ch;
    }

    /* Check whether tags of the same number haven't already been defined */
    for (p = spec->sources; p != NULL; p = p->next) {
	if ( p->num != num ) continue;
	if ((tag == RPMTAG_SOURCE && p->flags == RPMBUILD_ISSOURCE) ||
	    (tag == RPMTAG_PATCH  && p->flags == RPMBUILD_ISPATCH)) {
		rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num);
		return RPMRC_FAIL;
	    }
    }

    /* Create the entry and link it in */
    p = xmalloc(sizeof(*p));
    p->num = num;
    p->fullSource = xstrdup(field);
    p->flags = flag;
    p->source = strrchr(p->fullSource, '/');
    if (p->source) {
	if ((buf = strrchr(p->source,'='))) p->source = buf;
	p->source++;
    } else {
	p->source = p->fullSource;
    }

    if (tag != RPMTAG_ICON) {
	p->next = spec->sources;
	spec->sources = p;
    } else {
	p->next = pkg->icon;
	pkg->icon = p;
    }

    spec->numSources++;

    if (tag != RPMTAG_ICON) {
	char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL);
	struct stat st;
	int nofetch = (spec->flags & RPMSPEC_FORCE) ||
		      rpmExpandNumeric("%{_disable_source_fetch}");

	/* try to download source/patch if it's missing */
	if (lstat(body, &st) != 0 && errno == ENOENT && !nofetch) {
	    char *url = NULL;
	    if (urlIsURL(p->fullSource) != URL_IS_UNKNOWN) {
		url = rstrdup(p->fullSource);
	    } else {
		url = rpmExpand("%{_default_source_url}", NULL);
		rstrcat(&url, p->source);
		if (*url == '%') url = _free(url);
	    }
	    if (url) {
		rpmlog(RPMLOG_WARNING, _("Downloading %s to %s\n"), url, body);
		if (urlGetFile(url, body) != 0) {
		    free(url);
		    rpmlog(RPMLOG_ERR, _("Couldn't download %s\n"), p->fullSource);
		    return RPMRC_FAIL;
		}
		free(url);
	    }
	}

	rasprintf(&buf, "%s%d",
		(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
	rpmPushMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
	free(buf);
	rasprintf(&buf, "%sURL%d",
		(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
	rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
	free(buf);
#ifdef WITH_LUA
	{
	    rpmlua lua = NULL; /* global state */
	    const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources";
	    rpmluaPushTable(lua, what);
	    rpmluav var = rpmluavNew();
	    rpmluavSetListMode(var, 1);
	    rpmluavSetValue(var, RPMLUAV_STRING, body);
	    rpmluaSetVar(lua, var);
	    rpmluavFree(var);
	    rpmluaPop(lua);
	}
#endif
	free(body);
    }
    
    return 0;
}