コード例 #1
0
ファイル: auvirt.c プロジェクト: yubo/audit
/*
 * machine_id records are used to get the selinux context associated to a
 * guest.
 */
int process_machine_id_event(auparse_state_t *au)
{
	uid_t uid;
	time_t time;
	const char *seclevel, *uuid, *name;
	struct event *event;
	int success;

	seclevel = get_seclevel(auparse_find_field(au, "vm-ctx"));
	if (seclevel == NULL) {
		if (debug)
			fprintf(stderr, "Security context not found for "
					"MACHINE_ID event.\n");
	}

	if (extract_virt_fields(au, &uuid, &uid, &time, &name, &success))
		return 0;

	event = event_alloc();
	if (event == NULL)
		return 1;
	event->type = ET_MACHINE_ID;
	event->uuid = copy_str(uuid);
	event->name = copy_str(name);
	event->success = success;
	event->seclevel = copy_str(seclevel);
	event->uid = uid;
	event->start = time;
	add_proof(event, au);
	if (list_append(events, event) == NULL) {
		event_free(event);
		return 1;
	}
	return 0;
}
コード例 #2
0
ファイル: answer10.c プロジェクト: chenyiyi/ECE264
/* copy location_t to location 
 */
struct Location* copy_location( struct Location_t* loc, FILE* file ) {
	int i, stars;
	struct Location* copy;
	FILE* file_t = file;
	char str[10000];

	copy = (struct Location*)malloc( sizeof(struct Location) );
	copy->address = copy_str(loc->address);
	copy->city = copy_str(loc->city);
	copy->state = copy_str(loc->state);
	copy->zip_code = copy_str(loc->zip_code);
	copy->num_reviews = loc->num_reviews;
	copy->reviews = NULL;

	if( copy->num_reviews >0 ) {
		copy->reviews = (struct	Review*)malloc( sizeof(struct Review)*copy->num_reviews );
		for( i=0 ; i<copy->num_reviews ; i++ ) {
			// transform offset to actually review text
			fseek( file_t, loc->reviews[i].offset, SEEK_SET);
			fscanf( file_t, "%*d %d %*d %*d %*d ", &stars );
			copy->reviews[i].stars = stars;
			fgets(str, 10000, file_t);
			copy->reviews[i].text = copy_str(str);
		}
	}
	/*
	for( i=0 ; i<copy->num_reviews ; i++ ) {
		printf( "%d, %s\n" , i, copy->reviews[i].text );
	}
	*/

	return copy;
}
コード例 #3
0
ファイル: filename_modifiers.c プロジェクト: cfillion/vifm
const char *
apply_mods(const char path[], const char parent[], const char mod[],
		int for_shell)
{
	static char buf[PATH_MAX];
	int napplied = 0;

	copy_str(buf, sizeof(buf), path);
	while(*mod != '\0')
	{
		int mod_len;
		const char *const p = apply_mod(buf, parent, mod, &mod_len, for_shell);
		if(p == NULL)
		{
			break;
		}
		copy_str(buf, sizeof(buf), p);
		mod += mod_len;
		napplied++;
	}

#ifdef _WIN32
	/* This is needed to run something like explorer.exe, which isn't smart enough
	 * to understand forward slashes. */
	if(for_shell && curr_stats.shell_type != ST_CMD && napplied == 0)
	{
		to_back_slash(buf);
	}
#endif

	return buf;
}
コード例 #4
0
ファイル: TestString.c プロジェクト: Blurred-9L/NodesAndLinks
int main(){
    String s;
    char* str;
    
    init_string( &s );
    copy_str( s, "Hello world..." );
    print_string( s );
    putchar( '\n' );
    
    concat_str( s, " my name is Blur." );
    print_string( s );
    putchar( '\n' );
    
    copy_str( s, "Hi" );
    print_string( s );
    putchar( '\n' );
    
    printf( "Is it equal to hi? %d\n", compare_str( s, "hi" ) );
    printf( "Is it equal to Hi? %d\n", compare_str( s, "Hi" ) );
    printf( "Is it equal to hello? %d\n", compare_str( s, "hello" ) );
    printf( "Is it equal to Hello? %d\n", compare_str( s, "Hello" ) );
    
    str = to_c_str( s );
    printf( "%s\n", str );
    free( str );
    
    clear_string( &s );
    
    return 0;
}
コード例 #5
0
ファイル: sort.c プロジェクト: lyuts/vifm
/* Compares two filenames.  Returns positive value if s greater than t, zero if
 * they are equal, otherwise negative value is returned. */
static int
compare_file_names(int dirs, const char s[], const char t[], int ignore_case)
{
	char s_buf[NAME_MAX];
	char t_buf[NAME_MAX];

	/* TODO: FIXME: get rid of this when slash is removed from directory names. */
	if(dirs)
	{
		copy_substr(s_buf, sizeof(s_buf), s, '/');
		s = s_buf;

		copy_substr(t_buf, sizeof(t_buf), t, '/');
		t = t_buf;
	}

	if(ignore_case)
	{
		if(!dirs)
		{
			copy_str(s_buf, sizeof(s_buf), s);
			s = s_buf;

			copy_str(t_buf, sizeof(t_buf), t);
			t = t_buf;
		}

		strtolower(s_buf);
		strtolower(t_buf);
	}

	return cfg.sort_numbers ? strnumcmp(s, t) : strcmp(s, t);
}
コード例 #6
0
/* Navigates the view to a given dir/file combination specified by the path. */
static void
navigate_to_selected_file(FileView *view, const char path[])
{
	char name[NAME_MAX];
	char *dir = strdup(path);
	char *const last_slash = find_slashr(dir);

	if(last_slash == NULL)
	{
		copy_str(name, sizeof(name), dir);
	}
	else
	{
		*last_slash = '\0';
		copy_str(name, sizeof(name), last_slash + 1);
	}

	if(change_directory(view, dir) >= 0)
	{
		ui_sb_quick_msgf("%s", "Finding the correct directory...");

		load_dir_list(view, 0);

		(void)ensure_file_is_selected(view, name);
	}
	else
	{
		show_error_msgf("Invalid path", "Cannot change dir to \"%s\"", dir);
	}

	free(dir);
}
コード例 #7
0
ファイル: aesgav.c プロジェクト: BrianGladman/AES
void do_tests(int do_cmp, int ttype[3], f_ectx alg[1], const unsigned long blen, const unsigned long klen)
{   char       name1[128], name2[128], *sp1, *sp2;
    int        i;
    FILE       *outf;

    printf("\nGenerate%s tests for aes (AES_BLOCK_SIZE = %lu, key size = %lu)\n",
            (do_cmp ? " and verify" : ""), 8 * blen, 8 * klen);

    for(i = 0; i < 8; ++i)  // for each type of test /k /x /e /c (2 tests each)
        if(ttype[i / 2])    // if this test required
        {
            // name of file for output of generated test vectors
            sp1 = copy_str(name1, ar_path);
            sp1 = copy_str(sp1, out_path);
            sp2 = copy_str(name2, ar_path);
            sp2 = copy_str(sp2, ref_path);
            file_name(sp1, 128, i, blen, klen);
            copy_str(sp2, sp1);

            if(!fopen_s(&outf, name1, "w"))
            {
                header(outf, i, blen, klen);
                f_ptr[i](outf, alg, blen, klen);
                fprintf(outf, "\n"); fclose(outf);

                if(do_cmp)  // compare it with reference if required
                    comp_vecs(name2, name1);
            } 
            else 
            {
                printf("ERROR: failed to open %s for writing\n", name1);
            }
       }
}
コード例 #8
0
void encode_entry( char *str )
{
  int   match_cnt;
  int   len;
  char  buf[ MAX_STR ];

  if ( cur_entry - 1 >= 0 ) {

    compare_entry(str, &match_cnt);

    /* need to match more than one char to be useful */
    
    if ( match_cnt > 1 ) {

      buf[0] = (signed char) - match_cnt;
      copy_str(&buf[1], str + match_cnt);
      len = get_strlen( buf );
      entry[ cur_entry ] = (char *) malloc( len + 1 );
      copy_str( entry[ cur_entry ], buf );

    } else {

      entry[ cur_entry ] = (char *) strdup( str );
    }

  } else {
    
    entry[ cur_entry ] = (char *) strdup( str );
  }
}
コード例 #9
0
ファイル: decode_edid.c プロジェクト: luciang/haiku
static void
decode_detailed_monitor(edid1_detailed_monitor *monitor,
	const edid1_detailed_monitor_raw *raw, bool enableExtra)
{
	int i, j;

	for (i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i, ++monitor, ++raw) {

		// workaround: normally, all four bytes must be zero for detailed
		// description, but at least some Formac monitors violate that:
		// they have some additional info that start at zero_4(!),
		// so even if only the first two _or_ the other two bytes are
		// zero, we accept it as a monitor description block
		if (enableExtra
			&& ((raw->extra.zero_0[0] == 0 && raw->extra.zero_0[1] == 0)
				|| (raw->extra.zero_0[2] == 0 && raw->extra.zero_4 == 0))) {
			monitor->monitor_desc_type = raw->extra.monitor_desc_type;

			switch (raw->extra.monitor_desc_type) {
				case EDID1_SERIAL_NUMBER:
					copy_str(monitor->data.serial_number, 
						raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN);
					break;

				case EDID1_ASCII_DATA:
					copy_str(monitor->data.ascii_data, 
						raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN);
					break;

				case EDID1_MONITOR_RANGES:
					monitor->data.monitor_range = raw->extra.data.monitor_range;
					break;

				case EDID1_MONITOR_NAME:
					copy_str(monitor->data.monitor_name, 
						raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN);
					break;

				case EDID1_ADD_COLOUR_POINTER:
					decode_whitepoint(monitor->data.whitepoint, 
						&raw->extra.data.whitepoint);
					break;

				case EDID1_ADD_STD_TIMING:
					for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
						decode_std_timing(&monitor->data.std_timing[j],
							&raw->extra.data.std_timing[j]);
					}
					break;
			}
		} else if (raw->detailed_timing.pixel_clock > 0) {
			monitor->monitor_desc_type = EDID1_IS_DETAILED_TIMING;
			decode_detailed_timing(&monitor->data.detailed_timing,
				&raw->detailed_timing);
		}
	}
}
コード例 #10
0
static enum Nagios_status
get_hlth_status_str (struct ilo_oid_list **oid_list_ptr, void *data) 
{
  enum Nagios_status	n_status = NAGIOS_UNKNOWN;
  int			hlth_status; 
  struct ilo_snmp_priv	*priv_ptr = NULL;
  struct ilo_oid_info   *oid_info_ptr = (struct ilo_oid_info *) data;

  char *status_str[] = {"N/A", "Other", "OK", "Degraded", "Failed"};

  hlth_status = (*oid_list_ptr)->integer;

  copy_str(&(*oid_list_ptr)->string, (*oid_list_ptr)->value_len,
	  status_str[hlth_status]);

  (*oid_list_ptr)->value_len = strlen((*oid_list_ptr)->string);
  (*oid_list_ptr)->type = ASN_OCTET_STR;

  switch (hlth_status) 
    {
    case ILO_HLTH_STATUS_NA:
    case ILO_HLTH_STATUS_OTHER:
      n_status = NAGIOS_UNKNOWN;
      break;
    case ILO_HLTH_STATUS_DEGRADED:
      if (oid_info_ptr->oid_pool[HLTH_COMP_OID].oid_len) 
		get_failed_component_status(oid_list_ptr, oid_info_ptr,
					    status_str);
      n_status = NAGIOS_WARNING;
      break;
    case ILO_HLTH_STATUS_FAILED: 
      priv_ptr = container_of((struct ilo_oid_list **) oid_list_ptr, 
			       struct ilo_snmp_priv, oid_list);

      if (oid_info_ptr->oid_pool[HLTH_COMP_OID].oid_len) 
		get_failed_component_status(oid_list_ptr, oid_info_ptr,
					    status_str);
      if(priv_ptr->err_str) 
	{ 
	  copy_str(&priv_ptr->err_str, strlen(priv_ptr->err_str),
		   (*oid_list_ptr)->string);
	} 
      else 
	{
	  asprintf(&priv_ptr->err_str, (*oid_list_ptr)->string);
	}
	  
      n_status = NAGIOS_CRITICAL;
      break;
    case ILO_HLTH_STATUS_OK:
      n_status = NAGIOS_OK;
      break;
    }

  return n_status;
}
コード例 #11
0
ファイル: auvirt.c プロジェクト: yubo/audit
int add_start_guest_event(auparse_state_t *au)
{
	struct event *start;
	uid_t uid;
	time_t time;
	const char *uuid, *name;
	int success;
	list_node_t *it;

	/* Just skip this record if it failed to get some of the fields */
	if (extract_virt_fields(au, &uuid, &uid, &time, &name, &success))
		return 0;

	/* On failure, loop backwards to update all the resources associated to
	 * the last session of this guest. When a machine_id or a stop event is
	 * found the loop can be broken because a machine_id is created at the
	 * beginning of a session and a stop event indicates a previous
	 * session.
	 */
	if (!success) {
		for (it = events->tail; it; it = it->prev) {
			struct event *event = it->data;
			if (event->success && event->uuid &&
			    strcmp(uuid, event->uuid) == 0) {
				if (event->type == ET_STOP ||
				    event->type == ET_MACHINE_ID) {
					/* An old session found. */
					break;
				} else if (event->type == ET_RES &&
				           event->end == 0) {
					event->end = time;
					add_proof(event, au);
				}
			}
		}
	}

	start = event_alloc();
	if (start == NULL)
		return 1;
	start->type = ET_START;
	start->uuid = copy_str(uuid);
	start->name = copy_str(name);
	start->success = success;
	start->uid = uid;
	start->start = time;
	auparse_first_record(au);
	if (auparse_find_field(au, "vm-pid"))
		start->pid = auparse_get_field_int(au);
	add_proof(start, au);
	if (list_append(events, start) == NULL) {
		event_free(start);
		return 1;
	}
	return 0;
}
コード例 #12
0
ファイル: filename_modifiers.c プロジェクト: cfillion/vifm
/* Implementation of :. filename modifier. */
static int
apply_dot_mod(const char *path, char *buf, size_t buf_len)
{
	size_t len = strlen(curr_view->curr_dir);
	if(strnoscmp(path, curr_view->curr_dir, len) != 0 || path[len] == '\0')
		copy_str(buf, buf_len, path);
	else
		copy_str(buf, buf_len, path + len + 1);
	return 0;
}
コード例 #13
0
/* Completely resets the cs to builtin default color scheme.  Changes: colors,
 * name, state. */
static void
reset_to_default_color_scheme(col_scheme_t *cs)
{
	reset_color_scheme_colors(cs);

	copy_str(cs->name, sizeof(cs->name), DEF_CS_NAME);
	copy_str(cs->dir, sizeof(cs->dir), "/");

	cs->state = CSS_NORMAL;
}
コード例 #14
0
ファイル: aes_rav.c プロジェクト: Cristo-Conklin/LibreCrypt
void do_tests(const bool vkt, const bool ecb, const bool cbc, AESREF alg)
{   char    path[128], *sp;

    con_string("\nRun tests for the "); con_string(alg.name()); con_string(" algorithm"); 

    sp = copy_str(path, ref_path);  sp = copy_str(sp, alg.name());
    
    if(vkt)
    {
        copy_str(sp, aes_name[0]); ref_test(path, 1, ecb_vk, alg);
        copy_str(sp, aes_name[1]); ref_test(path, 1, ecb_vt, alg);
    }

    if(ecb)
    {
        copy_str(sp, aes_name[2]);  ref_test(path, 10000, ecb_me, alg);
        copy_str(sp, aes_name[3]);  ref_test(path, 10000, ecb_md, alg);
    }

    if(cbc)
    {
        copy_str(sp, aes_name[4]);  ref_test(path, 10000, cbc_me, alg);
        copy_str(sp, aes_name[5]);  ref_test(path, 10000, cbc_md, alg);
    }
}
コード例 #15
0
ファイル: sort.c プロジェクト: acklinr/vifm
/* Compares two file names according to grouping regular expression.  Returns
 * standard -1, 0, 1 for comparisons. */
static int
compare_group(const char f[], const char s[], regex_t *regex)
{
	char fname[NAME_MAX + 1], sname[NAME_MAX + 1];
	regmatch_t fmatch = get_group_match(regex, f);
	regmatch_t smatch = get_group_match(regex, s);

	copy_str(fname, MIN(sizeof(fname), fmatch.rm_eo - fmatch.rm_so + 1U),
			f + fmatch.rm_so);
	copy_str(sname, MIN(sizeof(sname), smatch.rm_eo - smatch.rm_so + 1U),
			s + smatch.rm_so);

	return strcmp(fname, sname);
}
コード例 #16
0
ファイル: disk.c プロジェクト: asqz/tagger
int disk_set_fname (disk_t* disk, const char* fname)
{
   if (disk == NULL)
      return ERR_INVALIDARG;

   return copy_str(fname, &disk->fname);
}
コード例 #17
0
ファイル: macros.c プロジェクト: serjepatoff/vifm
/* Appends path to the entry to the expanded string.  Returns new value of
 * expanded string. */
static char *
append_entry(FileView *view, char expanded[], PathType type, dir_entry_t *entry,
		int quotes, const char mod[], int for_shell)
{
	char path[PATH_MAX];
	const char *modified;

	switch(type)
	{
		case PT_NAME:
			copy_str(path, sizeof(path), entry->name);
			break;
		case PT_REL:
			get_short_path_of(view, entry, 0, sizeof(path), path);
			break;
		case PT_FULL:
			get_full_path_of(entry, sizeof(path), path);
			break;

		default:
			assert(0 && "Unexpected path type");
			path[0] = '\0';
			break;
	}

	modified = apply_mods(path, flist_get_dir(view), mod, for_shell);
	expanded = append_path_to_expanded(expanded, quotes, modified);

	return expanded;
}
コード例 #18
0
char	*replace_by_alias(char *str, t_alias *list)
{
  char	*new_str;
  char	*word;
  int	save;
  int	x;

  x = -1;
  if ((new_str = copy_str(str)) == NULL)
    return (NULL);
  while (new_str[++x])
    {
      if (new_str[x] != ';' && new_str[x] != ' ' && new_str[x] != '\t' &&
	  new_str[x] != '|' && new_str[x] != '&')
	{
	  save = x;
	  if ((word = get_a_word(new_str, &x)) && is_alias(&word, list))
	    {
	      if ((new_str = replace_word(word, new_str, save, &x)) == NULL)
		return (NULL);
	    }
	  else if (word)
	    free(word);
	}
    }
  return (new_str);
}
コード例 #19
0
ファイル: filtering.c プロジェクト: vifm/vifm
/* Appends slash to the name and stores result in the buffer. */
static void
append_slash(const char name[], char buf[], size_t buf_size)
{
	const size_t nchars = copy_str(buf, buf_size - 1, name);
	buf[nchars - 1] = '/';
	buf[nchars] = '\0';
}
コード例 #20
0
ファイル: jzon.c プロジェクト: KarlZylinski/Bowtie
char* parse_string_internal(const char** input, JzonAllocator* allocator)
{
	if (current(input) != '"')
		return NULL;

	if (is_multiline_string_quotes(*input))
		return parse_multiline_string(input, allocator);

	next(input);
	char* start = (char*)*input;

	while (current(input))
	{
		if (current(input) == '"')
		{
			char* end = (char*)*input;
			next(input);
			return copy_str(allocator, start, (unsigned)(end - start));
			break;
		}

		next(input);
	}

	return NULL;
}
コード例 #21
0
ファイル: config.c プロジェクト: phantasea/vifm
/* Writes path configuration file and directories for further usage. */
static void
store_config_paths(void)
{
	LOG_FUNC_ENTER;

	const char *const trash_dir_fmt =
#ifndef _WIN32
			"%%r/.vifm-Trash-%%u,%s/" TRASH ",%%r/.vifm-Trash";
#else
			"%%r/.vifm-Trash,%s/" TRASH;
#endif

	char *fuse_home;
	const char *trash_base = path_exists_at(env_get(VIFM_EV), TRASH, DEREF)
	                       ? cfg.config_dir
	                       : cfg.data_dir;
	const char *base = path_exists(cfg.data_dir, DEREF)
	                 ? cfg.data_dir
	                 : cfg.config_dir;

	snprintf(cfg.home_dir, sizeof(cfg.home_dir), "%s/", env_get(HOME_EV));
	copy_str(cfg.config_dir, sizeof(cfg.config_dir), env_get(VIFM_EV));
	snprintf(cfg.colors_dir, sizeof(cfg.colors_dir), "%s/colors/",
			cfg.config_dir);
	snprintf(cfg.trash_dir, sizeof(cfg.trash_dir), trash_dir_fmt, trash_base);
	snprintf(cfg.log_file, sizeof(cfg.log_file), "%s/" LOG, base);

	fuse_home = format_str("%s/fuse/", base);
	(void)cfg_set_fuse_home(fuse_home);
	free(fuse_home);
}
コード例 #22
0
ファイル: parse.c プロジェクト: Reen/gnuplot
/* find or add value and return pointer */
struct udvt_entry *
add_udv(int t_num)
{
    char varname[MAX_ID_LEN+1];
    copy_str(varname, t_num, MAX_ID_LEN);
    return add_udv_by_name(varname);
}
コード例 #23
0
ファイル: parse.c プロジェクト: Reen/gnuplot
/* find or add function at index <t_num>, and return pointer */
struct udft_entry *
add_udf(int t_num)
{
    struct udft_entry **udf_ptr = &first_udf;

    int i;
    while (*udf_ptr) {
	if (equals(t_num, (*udf_ptr)->udf_name))
	    return (*udf_ptr);
	udf_ptr = &((*udf_ptr)->next_udf);
    }

    /* get here => not found. udf_ptr points at first_udf or
     * next_udf field of last udf
     */

    if (is_builtin_function(t_num))
	int_warn(t_num, "Warning : udf shadowed by built-in function of the same name");

    /* create and return a new udf slot */

    *udf_ptr = (struct udft_entry *)
	gp_alloc(sizeof(struct udft_entry), "function");
    (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
    (*udf_ptr)->definition = NULL;
    (*udf_ptr)->at = NULL;
    (*udf_ptr)->udf_name = gp_alloc (token_len(t_num)+1, "user func");
    copy_str((*udf_ptr)->udf_name, t_num, token_len(t_num)+1);
    for (i = 0; i < MAX_NUM_VAR; i++)
	(void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
    return (*udf_ptr);
}
コード例 #24
0
ファイル: op_lib_core.c プロジェクト: xyuan/OP2-Common
op_set
op_decl_set_core ( int size, char const * name )
{
  if ( size < 0 )
  {
    printf ( " op_decl_set error -- negative/zero size for set: %s\n", name );
    exit ( -1 );
  }

  if ( OP_set_index == OP_set_max )
  {
    OP_set_max += 10;
    OP_set_list = ( op_set * ) realloc ( OP_set_list, OP_set_max * sizeof ( op_set ) );

    if ( OP_set_list == NULL )
    {
      printf ( " op_decl_set error -- error reallocating memory\n" );
      exit ( -1 );
    }

  }

  op_set set = ( op_set ) malloc ( sizeof ( op_set_core ) );
  set->index = OP_set_index;
  set->size = size;
  set->core_size = size;
  set->name = copy_str( name );
  set->exec_size = 0;
  set->nonexec_size = 0;
  OP_set_list[OP_set_index++] = set;

  return set;
}
コード例 #25
0
ファイル: op_lib_core.c プロジェクト: xyuan/OP2-Common
op_map
op_decl_map_core ( op_set from, op_set to, int dim, int * imap, char const * name )
{
  if ( from == NULL )
  {
    printf ( " op_decl_map error -- invalid 'from' set for map %s\n", name );
    exit ( -1 );
  }

  if ( to == NULL )
  {
    printf ( "op_decl_map error -- invalid 'to' set for map %s\n", name );
    exit ( -1 );
  }

  if ( dim <= 0 )
  {
    printf ( "op_decl_map error -- negative/zero dimension for map %s\n", name );
    exit ( -1 );
  }

  /*This check breaks for MPI - need to fix this  */
  /*for ( int d = 0; d < dim; d++ )
  {
    for ( int n = 0; n < from->size; n++ )
    {
      if ( imap[d + n * dim] < 0 || imap[d + n * dim] >= to->size )
      {
        printf ( "op_decl_map error -- invalid data for map %s\n", name );
        printf ( "element = %d, dimension = %d, map = %d\n", n, d, imap[d + n * dim] );
        exit ( -1 );
      }
    }
  }*/

  if ( OP_map_index == OP_map_max )
  {
    OP_map_max += 10;
    OP_map_list = ( op_map * ) realloc ( OP_map_list, OP_map_max * sizeof ( op_map ) );

    if ( OP_map_list == NULL )
    {
      printf ( " op_decl_map error -- error reallocating memory\n" );
      exit ( -1 );
    }
  }

  op_map map = ( op_map ) malloc ( sizeof ( op_map_core ) );
  map->index = OP_map_index;
  map->from = from;
  map->to = to;
  map->dim = dim;
  map->map = imap;
  map->name = copy_str( name );
  map->user_managed = 1;

  OP_map_list[OP_map_index++] = map;

  return map;
}
コード例 #26
0
ファイル: answer10.c プロジェクト: chenyiyi/ECE264
/* copy Business_t to Business ,and
 * state code and ZIP code to filter locations by, or NULL
 * to include all states.
 */
struct Business* copy_filte_business( struct Business_t* business, char* state, char* zip_code, FILE* file ) {
	int i;
	struct Business* ret;
	struct Location_t *loc_t;
	
	ret = (struct Business*)malloc( sizeof(struct Business) );
	ret->name = copy_str(business->name);
	ret->locations = NULL;
	ret->num_locations = 0;
	
	for( i=0 ; i<business->num_locations ; i++ ) {
		loc_t = &(business->locations[i]);
		if( (state==NULL || !strcmp(state, loc_t->state)) &&
			(zip_code==NULL || !strcmp(zip_code, loc_t->zip_code)) ) {	// Using state and ZIP_code to filter locations by
				ret->locations = (struct Location*)realloc( ret->locations, (ret->num_locations+1)*sizeof(struct Location) );
				ret->locations[ ret->num_locations ] = *copy_location( loc_t, file );
				ret->num_locations ++;
		}
	}
	/*
	struct Business* bis = ret;
	printf( "num_locations = %d\n" , bis->num_locations );
	for( int i=0 ; i<bis->num_locations ; i++ ) {
		printf( "location = %s\n", bis->locations[i].address );
	}printf( "\n" );
	*/

	return ret;
}
コード例 #27
0
ファイル: path.c プロジェクト: jubalh/vifm
int
find_cmd_in_path(const char cmd[], size_t path_len, char path[])
{
	size_t i;
	size_t paths_count;
	char **paths;

	paths = get_paths(&paths_count);
	for(i = 0; i < paths_count; i++)
	{
		char tmp_path[PATH_MAX];
		snprintf(tmp_path, sizeof(tmp_path), "%s/%s", paths[i], cmd);

		/* Need to check for executable, not just a file, as this additionally
		 * checks for path with different executable extensions on Windows. */
		if(executable_exists(tmp_path))
		{
			if(path != NULL)
			{
				copy_str(path, path_len, tmp_path);
			}
			return 0;
		}
	}
	return 1;
}
コード例 #28
0
ファイル: autocmds.c プロジェクト: cfillion/vifm
void
vle_aucmd_remove(const char event[], const char patterns[])
{
	int i;
	int len;
	char **pats = get_patterns(patterns, &len);

	for(i = (int)DA_SIZE(autocmds) - 1; i >= 0; --i)
	{
		char pat[1U + strlen(autocmds[i].pattern) + 1U];

		copy_str(&pat[1], sizeof(pat) - 1U, autocmds[i].pattern);
		pat[0] = autocmds[i].negated ? '!' : '=';

		if(event != NULL && strcasecmp(event, autocmds[i].event) != 0)
		{
			continue;
		}
		if(patterns != NULL && !is_in_string_array(pats, len, pat))
		{
			continue;
		}

		free_autocmd_data(&autocmds[i]);
		DA_REMOVE(autocmds, &autocmds[i]);
	}

	free_string_array(pats, len);
}
コード例 #29
0
ファイル: autocmds.c プロジェクト: cfillion/vifm
void
vle_aucmd_list(const char event[], const char patterns[], vle_aucmd_list_cb cb,
		void *arg)
{
	size_t i;
	int len;
	char **pats = get_patterns(patterns, &len);

	for(i = 0U; i < DA_SIZE(autocmds); ++i)
	{
		char pat[1U + strlen(autocmds[i].pattern) + 1U];

		copy_str(&pat[1], sizeof(pat) - 1U, autocmds[i].pattern);
		pat[0] = autocmds[i].negated ? '!' : '=';

		if(event != NULL && strcasecmp(event, autocmds[i].event) != 0)
		{
			continue;
		}
		if(patterns != NULL && !is_in_string_array(pats, len, pat))
		{
			continue;
		}

		cb(autocmds[i].event, autocmds[i].pattern, autocmds[i].negated,
				autocmds[i].action, arg);
	}

	free_string_array(pats, len);
}
コード例 #30
0
void expand_str(char *buf, int idx)
{
  int   len;

  if ( (signed char) entry[ idx ][ 0 ] >= 0 ) {

    copy_str(buf, entry[ idx ]);
    
  } else {
    
    expand_str(buf, idx - 1);
    len = - (signed char) entry[ idx ][ 0 ];
    buf += len;
    copy_str(buf, &entry[ idx ][ 1 ]);
  }
}