コード例 #1
0
/**
 * @brief
 * 		add string to string array
 *
 * @param[in]	str_arr	-	pointer to an array of strings to be added to(i.e. char ***)
 * @param[in]	str	-	string to add to array
 *
 * @return	int
 * @retval	index	-	index of string on success
 * @retval	-1	: failure
 */
int
add_str_to_array(char ***str_arr, char *str)
{
    char **tmp_arr;
    int cnt;

    if (str_arr == NULL || str == NULL)
        return -1;

    if (*str_arr == NULL)
        cnt = 0;
    else
        cnt = count_array((void **) *str_arr);

    tmp_arr = realloc(*str_arr, (cnt+2)*sizeof(char*));
    if (tmp_arr == NULL)
        return -1;

    tmp_arr[cnt] = string_dup(str);
    tmp_arr[cnt+1] = NULL;

    *str_arr = tmp_arr;

    return cnt;
}
コード例 #2
0
ファイル: node_partition.c プロジェクト: Klovely/pbspro
/**
 * @brief
 *		add_np_cache - add an np_cache to an array
 *
 * @param[in]	policy	-	policy info
 * @param[in,out]	pnpc_arr	-	pointer to np_cache array -- if *npc_arr == NULL
 *
 * @return	1	: on success
 * @return	0	: on failure
 */
int
add_np_cache(np_cache ***npc_arr, np_cache *npc)

{
	np_cache **new_cache;
	np_cache **cur_cache;
	int ct;

	if (npc_arr == NULL || npc == NULL)
		return 0;

	cur_cache = *npc_arr;

	ct = count_array((void **) cur_cache);

	/* ct+2: 1 for new element 1 for NULL ptr */
	new_cache = realloc(cur_cache, (ct+2) * sizeof(np_cache *));

	if (new_cache == NULL)
		return 0;

	new_cache[ct] = npc;
	new_cache[ct+1] = NULL;

	*npc_arr = new_cache;
	return 1;
}
コード例 #3
0
ファイル: simulate.c プロジェクト: altair4/pbspro
/**
 * @brief
 *		create_events - creates an timed_event list from running jobs
 *			    and confirmed reservations
 *
 * @param[in] sinfo - server universe to act upon
 *
 * @return	timed_event list
 *
 */
timed_event *
create_events(server_info *sinfo)
{
	timed_event	*events = NULL;
	timed_event	*te = NULL;
	resource_resv	**all = NULL;
	int		errflag = 0;
	int		i = 0;
	time_t 		end = 0;

	/* all_resresv is sorted such that the timed events are in the front of
	 * the array.  Once the first non-timed event is reached, we're done
	 */
	all = sinfo->all_resresv;

	/* sort the all resersv list so all the timed events are in the front */
	qsort(all, count_array((void **)all), sizeof(resource_resv *), cmp_events);

	for (i = 0; all[i] != NULL && is_timed(all[i]); i++) {
		if (all[i]->is_resv && all[i]->resv &&
			all[i]->resv->resv_state == RESV_BEING_ALTERED)
			continue;
		/* only add a run event for a job or reservation if they're
		 * in a runnable state (i.e. don't add it if they're running)
		 */
		if (in_runnable_state(all[i])) {
			te = create_event(TIMED_RUN_EVENT, all[i]->start, all[i], NULL, NULL);
			if (te == NULL) {
				errflag++;
				break;
			}
			events = add_timed_event(events, te);
		}

		if (sinfo->use_hard_duration)
			end = all[i]->start + all[i]->hard_duration;
		else
			end = all[i]->end;
		te = create_event(TIMED_END_EVENT, end, all[i], NULL, NULL);
		if (te == NULL) {
			errflag++;
			break;
		}
		events = add_timed_event(events, te);
	}

	/* A malloc error was encountered, free all allocated memory and return */
	if (errflag > 0) {
		free_timed_event_list(events);
		return 0;
	}

	return events;
}
コード例 #4
0
ファイル: analyse.c プロジェクト: chudur-budur/Wiz-Compiler
BOOL
validate_array_dims(Expr *e, char *scope_id, sym_table *table) {
    symbol *asym = retrieve_symbol(e->id, scope_id, table);
    if (asym == NULL) {
        //Array has not been defined
        return FALSE;
    } else {
        Decl *d = (Decl *) asym->sym_value;
        return count_array(d->array) == count_list(e->indices);
    }
}
コード例 #5
0
ファイル: sproto.c プロジェクト: xiuzhifu/sproto
/*
.type {
	.field {
		name 0 : string
		buildin	1 :	integer
		type 2 : integer
		tag	3 :	integer
		array 4	: boolean
	}
	name 0 : string
	fields 1 : *field
}
*/
static const uint8_t *
import_type(struct sproto *s, struct sproto_type *t, const uint8_t * stream) {
	uint32_t sz = todword(stream);
	stream += SIZEOF_LENGTH;
	const uint8_t * result = stream + sz;
	int fn = struct_field(stream, sz);
	if (fn <= 0 || fn > 2)
		return NULL;
	int i;
	for (i=0;i<fn*SIZEOF_FIELD;i+=SIZEOF_FIELD) {
		// name and fields must encode to 0
		int v = toword(stream + SIZEOF_HEADER + i);
		if (v != 0)
			return NULL;
	}
	memset(t, 0, sizeof(*t));
	stream += SIZEOF_HEADER + fn * SIZEOF_FIELD;
	t->name = import_string(s, stream);
	if (fn == 1) {
		return result;
	}
	stream += todword(stream)+SIZEOF_LENGTH;	// second data
	int n = count_array(stream);
	if (n<0)
		return NULL;
	stream += SIZEOF_LENGTH;
	int maxn = n;
	int last = -1;
	t->n = n;
	t->f = pool_alloc(&s->memory, sizeof(struct field) * n);
	for (i=0;i<n;i++) {
		struct field *f = &t->f[i];
		stream = import_field(s, f, stream);
		if (stream == NULL)
			return NULL;
		int tag = f->tag;
		if (tag < last)
			return NULL;	// tag must in ascending order
		if (tag > last+1) {
			++maxn;
		}
		last = tag;
	}
	t->maxn = maxn;
	t->base = t->f[0].tag;
	n = t->f[n-1].tag - t->base + 1;
	if (n != t->n) {
		t->base = -1;
	}
	return result;
}
コード例 #6
0
ファイル: node_partition.c プロジェクト: Klovely/pbspro
/**
 * @brief
 * 		create_specific_nodepart - create a node partition with specific
 *				          nodes, rather than from a placement
 *				          set resource=value
 *
 * @param[in]	policy	-	policy info
 * @param[in]	name	-	the name of the node partition
 * @param[in]	nodes	-	the nodes to create the placement set with
 *
 * @return	node_partition * - the node partition
 * @NULL	: on error
 */
node_partition *
create_specific_nodepart(status *policy, char *name, node_info **nodes)
{
	node_partition *np;
	int i, j;
	int cnt;

	if (name == NULL || nodes == NULL)
		return NULL;

	np = new_node_partition();
	if (np == NULL)
		return NULL;

	cnt = count_array((void **) nodes);

	np->name = string_dup(name);
	np->def = NULL;
	np->res_val = string_dup("none");
	np->rank = get_sched_rank();

	np->ninfo_arr = malloc((cnt + 1) * sizeof(node_info*));
	if (np->ninfo_arr == NULL) {
		log_err(errno, __func__, MEM_ERR_MSG);
		free_node_partition(np);
		return NULL;
	}

	j = 0;
	for (i = 0; i < cnt; i++) {
		if (!nodes[i]->is_stale) {
			np->ninfo_arr[j] = nodes[i];
			j++;
		}

	}
	np->tot_nodes = j;



	np->ninfo_arr[np->tot_nodes] = NULL;

	if (node_partition_update(policy, np) == 0) {
		free_node_partition(np);
		return NULL;
	}

	return np;
}
コード例 #7
0
ファイル: sproto.c プロジェクト: xiuzhifu/sproto
static struct sproto *
create_from_bundle(struct sproto *s, const uint8_t * stream, size_t sz) {
	int fn = struct_field(stream, sz);
	if (fn < 0)
		return NULL;

	stream += SIZEOF_HEADER;

	const uint8_t * content = stream + fn*SIZEOF_FIELD;
	const uint8_t * typedata = NULL;
	const uint8_t * protocoldata = NULL;

	int i;
	for (i=0;i<fn;i++) {
		int value = toword(stream + i*SIZEOF_FIELD);
		if (value != 0)
			return NULL;
		int n = count_array(content);
		if (n<0)
			return NULL;
		if (i == 0) {
			typedata = content+SIZEOF_LENGTH;
			s->type_n = n;
			s->type = pool_alloc(&s->memory, n * sizeof(*s->type));
		} else {
			protocoldata = content+SIZEOF_LENGTH;
			s->protocol_n = n;
			s->proto = pool_alloc(&s->memory, n * sizeof(*s->proto));
		}
		content += todword(content) + SIZEOF_LENGTH;
	}

	for (i=0;i<s->type_n;i++) {
		typedata = import_type(s, &s->type[i], typedata);
		if (typedata == NULL) {
			return NULL;
		}
	}
	for (i=0;i<s->protocol_n;i++) {
		protocoldata = import_protocol(s, &s->proto[i], protocoldata);
		if (protocoldata == NULL) {
			return NULL;
		}
	}

	return s;
}
コード例 #8
0
ファイル: array.c プロジェクト: peterlintang/apue
void destroy_array(array_t **parray, array_del_func del)
{
	array_t *array = NULL;

	if (!parray || !(*parray)) return ;

	array = *parray;

	if (del) {
		while (count_array(array)) {
			remove_array_item(array, del);
		}
	}

	if (array->items) free(array->items);
	free(array);
	*parray = NULL;
}
コード例 #9
0
ファイル: bookmark.c プロジェクト: acgarcia/winefish
/* this function will load the bookmarks
 * from bfwin->session->bmarks and parse
 * them into treestore bfwin->bookmarkstore
 *
 * this function should ALSO check all dcouments that are
 * opened (bfwin->documentlist) if they have bookmarks !!
 */
void bmark_reload(Tbfwin * bfwin)
{
	GList *tmplist = g_list_first(bfwin->session->bmarks);
	DEBUG_MSG("bmark_reload for bfwin %p\n",bfwin);
	if (bfwin->bmark_files != NULL)
		g_hash_table_destroy(bfwin->bmark_files);
	bfwin->bmark_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	while (tmplist) {
		gchar **items = (gchar **) tmplist->data;
		if (items && count_array(items) == 6) {
			gchar *ptr;
			Tbmark *b;
			b = g_new0(Tbmark, 1);
			b->name = g_strdup(items[0]);
			b->description = g_strdup(items[1]);
			b->filepath = g_strdup(items[2]);
			b->offset = atoi(items[3]);
			b->text = g_strdup(items[4]);
			b->len = atoi(items[5]);
			b->strarr = items;
			bmark_get_iter_at_tree_position(bfwin, b);
			if (b->name && strlen(b->name)>0) {
				ptr = g_strconcat(b->name, " - ", b->text, NULL);
			} else {
				ptr = g_strdup(b->text);
			}
			gtk_tree_store_set(bfwin->bookmarkstore, &(b->iter), NAME_COLUMN, ptr, PTR_COLUMN, b,
							   -1);
			g_free(ptr);
		}
		tmplist = g_list_next(tmplist);
	}
	
	tmplist = g_list_first(bfwin->documentlist);
	while (tmplist) {
		DEBUG_MSG("bmark_reload, calling bmark_set_for_doc for doc=%p\n",tmplist->data);
		bmark_set_for_doc(DOCUMENT(tmplist->data));
		bmark_check_length(bfwin, DOCUMENT(tmplist->data));
		tmplist = g_list_next(tmplist);
	}
}
コード例 #10
0
ファイル: cam.c プロジェクト: cmehay/our_rt
t_data	*set_cam(char **input, int line)
{
	static t_data	*cam = NULL;

	if ((cam && input) || (input && count_array(input) != 10))
		return ((t_data*)display_parse_error(CAM, line));
	if (!cam && input)
	{
		cam = (t_data *)safe_malloc(sizeof(t_data));
		cam->obj = CAM;
		cam->pos.x = ft_atoi(input[1]);
		cam->pos.y = ft_atoi(input[2]);
		cam->pos.z = ft_atoi(input[3]);
		cam->vect.x = ft_atoi(input[4]);
		cam->vect.y = ft_atoi(input[5]);
		cam->vect.z = ft_atoi(input[6]);
		cam->angle.x = ft_atoi(input[7]);
		cam->angle.y = ft_atoi(input[8]);
		cam->angle.z = ft_atoi(input[9]);
	}
	return (cam);
}
コード例 #11
0
ファイル: bookmark.c プロジェクト: acgarcia/winefish
/* this function re-uses the b->strarr if possible, otherwise it will create a new one and
append it to the list */
static void bmark_store(Tbfwin * bfwin, Tbmark * b) {
	gchar **strarr;
	if (b->is_temp) {
		DEBUG_MSG("bmark_store, called for temp bookmark %p ?!?! weird!!!! returning\n", b);
		return;
	}

	/* if there is a strarr already, we only update the fields, else we append a new one */
	if (b->strarr == NULL) {
		DEBUG_MSG("bmark_store, creating new strarr for bookmark %p\n",b);
		strarr = g_malloc0(sizeof(gchar *) * 7);
		DEBUG_MSG("name=%s, description=%s, filepath=%s, text=%s\n", b->name, b->description, b->filepath, b->text);
		strarr[2] = g_strdup(b->filepath);
		strarr[4] = g_strdup(b->text);
	} else {
		DEBUG_MSG("bmark_store, bookmark %p has strarr at %p\n",b,b->strarr);
		strarr = b->strarr;
		/* free the ones we are going to update */
		g_free(strarr[0]);
		g_free(strarr[1]);
		g_free(strarr[3]);
		g_free(strarr[5]);
	}
	strarr[0] = g_strdup(b->name);
	strarr[1] = g_strdup(b->description);
	if (b->doc)
		b->len = b->doc->statbuf.st_size;
	strarr[3] = g_strdup_printf("%d", b->offset);
	DEBUG_MSG("bmark_store, offset string=%s, offset int=%d\n",strarr[3],b->offset);
	strarr[5] = g_strdup_printf("%d", b->len);
	DEBUG_MSG("bmark_store, arracount=%d\n",count_array(strarr));
	if (b->strarr == NULL) {
		bfwin->session->bmarks = g_list_append(bfwin->session->bmarks, strarr);
		DEBUG_MSG("added new (previously unstored) bookmark to session list, list length=%d\n",
				  g_list_length(bfwin->session->bmarks));
		b->strarr = strarr;
	}
}
コード例 #12
0
ファイル: analyse.c プロジェクト: chudur-budur/Wiz-Compiler
Type get_expr_type(Expr *e, Expr *parent,
                   sym_table *table, char *scope_id, int line_no) {

    //Find the type of an expression
    ExprKind kind = e->kind;
    // Switch on kind to print
    switch (kind) {
        case EXPR_ID:
            //Find the symbol and get it's type
            if (retrieve_symbol(e->id, scope_id, table)) {
                //Lets check the type
                Type t = get_type(retrieve_symbol(e->id, scope_id, table));
                e->inferred_type = t;
                return t;
            } else {
                //Not good. Let the user know.
                print_undefined_variable_error(e, parent, line_no);
                isValid = FALSE;
                e->inferred_type = INVALID_TYPE;
                return INVALID_TYPE;
            }
            break;
        case EXPR_CONST:
            if (e != NULL) { //f**k c.
                Type t =  get_const_type(e);
                e->inferred_type = t;
                return t;
            }

            break;
        case EXPR_BINOP:
            //We need the types of each expression
            //Then we determine the type if allowed using the binop
            return get_binop_type(get_expr_type(e->e1, e, table, scope_id,
                line_no), get_expr_type(e->e2, e, table, scope_id, line_no),
                e->binop, line_no, e);
            break;
        case EXPR_UNOP:
            //Get the type of the expression
            //Then we determine the type if allowed using the binop
            return get_unop_type(get_expr_type(e->e1, e, table, scope_id,
                                               line_no), e->unop, line_no, e);
            break;
        case EXPR_ARRAY:
            //We need to check array dimensions, then check all expressions are
            //int equiv.
            if (validate_array_dims(e, scope_id, table)) {
                symbol *a = retrieve_symbol(e->id, scope_id, table);
                validate_array_indices(e->indices, e->id,
                                       line_no, table, scope_id, a);
                e->inferred_type = get_type(a);
                return e->inferred_type;
            } else {
                symbol *a = retrieve_symbol(e->id, scope_id, table);
                if (a != NULL) {
                    // Now check if a is an array
                    if (a->bounds == NULL) {
                        print_not_array_error(e, a->sym_value, line_no);
                    } else {
                        Decl *d = (Decl *) a->sym_value;
                        print_array_dims_error(e, count_array(d->array),
                                               count_list(e->indices), line_no);
                    }
                    isValid = FALSE;
                } else {
                    print_undefined_variable_error(e, NULL, line_no);
                    isValid = FALSE;
                }
                e->inferred_type = INVALID_TYPE;
                return INVALID_TYPE;
            }
            return INVALID_TYPE;
            break;
    }

    return INVALID_TYPE;
}
コード例 #13
0
ファイル: rcfile.c プロジェクト: driedfruit/barefish
/*
static GList *arraylist_load_defaults(GList *thelist, const gchar *filename, const gchar *name) {
	GList *deflist,*tmplist = g_list_first(thelist);
	if (name) {
		while (tmplist) {
			gchar **tmparr = tmplist->data;
			if (strcmp(tmparr[0],name)==0) {
				GList *todelete = tmplist;
				tmplist = g_list_next(tmplist);
				if (tmplist) {
					g_list_delete_link(tmplist, todelete);
					g_strfreev(tmparr);
					g_list_free_1(todelete);
				} else {
					thelist = NULL;
					g_strfreev(tmparr);
					g_list_free(todelete);
				}
			} else {
				tmplist = g_list_next(tmplist);
			}
		}
	} else {
		while (tmplist) {
			g_strfreev((gchar **)tmplist->data);
			tmplist = g_list_next(tmplist);
		}
		g_list_free(thelist);
		thelist = NULL;
	}
	if (name) {
		deflist = get_list(filename,NULL,TRUE);
		tmplist = g_list_first(deflist);
		while (tmplist) {
			gchar **tmparr = tmplist->data;
			DEBUG_MSG("arraylist_load_defaults, testing if %s should be added (requested=%s)\n",tmparr[0],name);
			if (strcmp(tmparr[0],name)==0) {
				DEBUG_MSG("adding %s to thelist\n",tmparr[0]);
				thelist = g_list_append(thelist, duplicate_stringarray(tmparr));
			}
			tmplist = g_list_next(tmplist);
		}
		free_arraylist(deflist);
	} else {
		thelist = get_list(filename,NULL,TRUE);
	}
	return thelist;
}
*/
void rcfile_parse_main(void)
{
	gchar *filename;

	DEBUG_MSG("rcfile_parse_main, started\n");

	/* set the props struct completely empty */
	memset(&main_v->props, 0, sizeof(Tproperties));

	/*Make the config_rc list ready for filling with data and set default values */
	main_configlist = props_init_main(NULL);

	filename = g_strconcat(g_get_home_dir(), "/.bluefish/rcfile_v2", NULL);
	if (!parse_config_file(main_configlist, filename)) {
		/* should we initialize some things ?? */
	}
	g_free(filename);
	/* do some default configuration for the lists */
	if (main_v->props.browsers == NULL) {
		/* if the user does not have browsers --> set them to defaults values */
		gchar **arr;
		arr = array_from_arglist(_("Galeon"), "galeon -x %s&",NULL);
		main_v->props.browsers = g_list_append(main_v->props.browsers,arr);
		arr = array_from_arglist(_("Mozilla"), "mozilla -remote 'openURL(%s, new-window)' || mozilla %s&",NULL);
		main_v->props.browsers = g_list_append(main_v->props.browsers,arr);
		arr = array_from_arglist(_("Opera"), "opera -remote 'openURL(%s,new-window)' || opera %s&",NULL);
		main_v->props.browsers = g_list_append(main_v->props.browsers,arr);
		arr = array_from_arglist(_("Netscape"), "/usr/lib/netscape/477/communicator/communicator-smotif %s&",NULL);
		main_v->props.browsers = g_list_append(main_v->props.browsers,arr);
		arr = array_from_arglist(_("Gnome default"), "gnome-moz-remote --newwin %s&",NULL);
		main_v->props.browsers = g_list_append(main_v->props.browsers,arr);
	}
	{
		gchar *defaultfile = return_first_existing_filename(PKGDATADIR"encodings.default",
											"data/encodings.default",
										"../data/encodings.default",NULL);
		if (main_v->props.encodings == NULL) {
			/* if the user does not have encodings --> set them to defaults values */
			if (defaultfile) {
				main_v->props.encodings = get_list(defaultfile,NULL,TRUE);
			} else {
				g_print("Unable to find '"PKGDATADIR"encodings.default'\n");
			}
		} else {
			if (config_file_is_newer(main_v->globses.lasttime_encodings,defaultfile)) {
				main_v->props.encodings = arraylist_load_new_identifiers_from_file(main_v->props.encodings,defaultfile,1);
				main_v->globses.lasttime_encodings = TIME_T_TO_GINT(time(NULL));
			}
		}
		g_free(defaultfile);
	}
	if (main_v->props.outputbox==NULL) {
		/* if the user does not have outputbox settings --> set them to defaults values */
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("make"),"([a-zA-Z0-9/_.-]+):([0-9]+):(.*)","1","2","3","make","1",NULL));
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("weblint HTML checker"),"([a-zA-Z0-9/_.-]+) \\(([0-9:]+)\\) (.*)","1","2","3","weblint '%s'","0",NULL));
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("tidy HTML validator"),"line ([0-9]+) column [0-9]+ - (.*)","-1","1","2","tidy -qe '%s'","0",NULL));
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("javac"),"([a-zA-Z0-9/_.-]+):([0-9]+):(.*)","1","2","3","javac '%s'","0",NULL));
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("xmllint XML checker"),"([a-zA-Z0-9/_.-]+)\\:([0-9]+)\\: (.*)","1","2","3","xmllint --noout --valid '%s'","0",NULL));
		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(_("php"),"(.*) in (/[a-zA-Z0-9/_.-]+) on line ([0-9]+)","1","2","3","php '%s'","0",NULL));
/*		main_v->props.outputbox = g_list_append(main_v->props.outputbox,array_from_arglist(,NULL)); */
	}
	if (main_v->props.external_commands == NULL) {
		/* if the user does not have external commands --> set them to defaults values */
		gchar **arr;
		arr = array_from_arglist(_("Dos2Unix filter"), "cat '%s' | dos2unix > '%f'",NULL);
		main_v->props.external_commands = g_list_append(main_v->props.external_commands,arr);
		arr = array_from_arglist(_("Tidy cleanup filter"), "cat '%s' | tidy -utf8 -q >'%f' 2>/dev/null",NULL);
		main_v->props.external_commands = g_list_append(main_v->props.external_commands,arr);
	}
	{
		gchar *defaultfile = return_first_existing_filename(PKGDATADIR"filetypes.default",
									"data/filetypes.default",
									"../data/filetypes.default",NULL);
		if (main_v->props.filetypes == NULL) {
			/* if the user does not have file-types --> set them to defaults values */
			if (defaultfile) {
				main_v->props.filetypes = get_list(defaultfile,NULL,TRUE);
			} else {
				g_print("Unable to find '"PKGDATADIR"filetypes.default'\n");
			}
		} else {
			if (config_file_is_newer(main_v->globses.lasttime_filetypes,defaultfile)) {
				main_v->props.filetypes = arraylist_load_new_identifiers_from_file(main_v->props.filetypes,defaultfile,1);
				main_v->globses.lasttime_filetypes = TIME_T_TO_GINT(time(NULL));
			}
		}
		g_free(defaultfile);
	}
	if (main_v->props.filefilters == NULL) {
		/* if the user does not have file filters --> set them to defaults values */
		gchar **arr;
		arr = array_from_arglist(_("C programming"),"1","c:image", NULL);
		main_v->props.filefilters = g_list_append(main_v->props.filefilters, arr);
		arr = array_from_arglist(_("All web files"),"1", "html:php:webimage:xml:javascript:stylesheet:jsp", NULL);
		main_v->props.filefilters = g_list_append(main_v->props.filefilters, arr);
		arr = array_from_arglist(_("Java programming"),"1", "java:image:jsp", NULL);
		main_v->props.filefilters = g_list_append(main_v->props.filefilters, arr);
		arr = array_from_arglist(_("Images"),"1", "image", NULL);
		main_v->props.filefilters = g_list_append(main_v->props.filefilters, arr);
		arr = array_from_arglist(_("Hide objectfiles"),"0", "objectfile", NULL);
		main_v->props.filefilters = g_list_append(main_v->props.filefilters, arr);
	}
	if (main_v->props.reference_files == NULL) {
		gchar *userdir = g_strconcat(g_get_home_dir(), "/.bluefish/", NULL);
		/* if the user does not yet have any function reference files, set them to default values */
		fref_rescan_dir(PKGDATADIR);
		fref_rescan_dir(userdir);
		g_free(userdir);
	}
	/* for backwards compatibility with old filetypes, 
		before version 0.10 had length 4, 
		before version 0.13 had length 6 */
	{
		GList *tmplist = g_list_first(main_v->props.filetypes);
		while (tmplist) {
			gchar **orig = (gchar **)tmplist->data;
			if (count_array(orig)==4) {
				gchar **new = array_from_arglist(orig[0], orig[1], orig[2], orig[3], "1", "", "1", NULL);
				tmplist->data = new;
				g_strfreev(orig);
			}
			if (count_array(orig)==6) {
				gchar **new = array_from_arglist(orig[0], orig[1], orig[2], orig[3], orig[4], orig[5], "0", NULL);
				tmplist->data = new;
				if (strcmp(orig[0], "xml")==0) {
					new[6][0] = '1';
				} else if (strcmp(orig[0], "html")==0 || strcmp(orig[0], "php")==0 || strcmp(orig[0], "jsp")==0 || strcmp(orig[0], "cfml")==0) {
コード例 #14
0
ファイル: rcfile.c プロジェクト: driedfruit/barefish
static gboolean parse_config_file(GList * config_list, gchar * filename)
{
	gboolean retval = FALSE;
	gchar *tmpstring = NULL, *tmpstring2;
	gchar **tmparray;
	GList *rclist, *tmplist, *tmplist2;
	Tconfig_list_item *tmpitem;

	DEBUG_MSG("parse_config_file, started\n");

	rclist = NULL;
	rclist = get_list(filename, rclist,FALSE);
	
	if (rclist == NULL) {
		DEBUG_MSG("no rclist, returning!\n");
		return retval;
	}

	/* empty all variables that have type GList ('l') */
	tmplist = g_list_first(config_list);
	while (tmplist != NULL) {
		tmpitem = (Tconfig_list_item *) tmplist->data;
		DEBUG_MSG("parse_config_file, type=%c, identifier=%s\n", tmpitem->type, tmpitem->identifier);
		if (tmpitem->type == 'l' || tmpitem->type == 'a') {
			DEBUG_MSG("parse_config_file, freeing list before filling it\n");
			free_stringlist((GList *) * (void **) tmpitem->pointer);
			*(void **) tmpitem->pointer = (GList *)NULL;
		}
		DEBUG_MSG("parse_config_file, type=%c, identifier=%s\n", tmpitem->type, tmpitem->identifier);
		tmplist = g_list_next(tmplist);
	}
	DEBUG_MSG("parse_config_file, all the type 'l' and 'a' have been emptied\n");
	DEBUG_MSG("parse_config_file, length rclist=%d\n", g_list_length(rclist));
/* And now for parsing every line in the config file, first check if there is a valid identifier at the start. */
	tmplist = g_list_first(rclist);
	while (tmplist) {
		tmpstring = (gchar *) tmplist->data;

		if (tmpstring != NULL) {
			DEBUG_MSG("parse_config_file, tmpstring=%s\n", tmpstring);
			g_strchug(tmpstring);

			tmplist2 = g_list_first(config_list);
			while (tmplist2) {
				tmpitem = (Tconfig_list_item *) tmplist2->data;
#ifdef DEVELOPMENT
				if (!tmpitem || !tmpitem->identifier || !tmpstring) {
					g_print("WARNING: almost a problem!\n");
				}
#endif
				if (g_strncasecmp(tmpitem->identifier, tmpstring, strlen(tmpitem->identifier)) == 0) {
					/* we have found the correct identifier */
					retval = TRUE;
					DEBUG_MSG("parse_config_file, identifier=%s, string=%s\n", tmpitem->identifier, tmpstring);
					/* move pointer past the identifier */
					tmpstring += strlen(tmpitem->identifier);
					trunc_on_char(tmpstring, '\n');
					g_strstrip(tmpstring);

					switch (tmpitem->type) {
					case 'i':
						*(int *) (void *) tmpitem->pointer = atoi(tmpstring);
						break;
					case 's':
						*(void **) tmpitem->pointer = (char *) realloc((char *) *(void **) tmpitem->pointer, strlen(tmpstring) + 1);
						strcpy((char *) *(void **) tmpitem->pointer, tmpstring);
						break;
					case 'e':
						tmpstring2 = unescape_string(tmpstring, FALSE); /* I wonder if that should be TRUE */
						*(void **) tmpitem->pointer = (char *) realloc((char *) *(void **) tmpitem->pointer, strlen(tmpstring2) + 1);
						strcpy((char *) *(void **) tmpitem->pointer, tmpstring2);
						g_free(tmpstring2);
						break;
					case 'l':
					case 'm':
						tmpstring2 = g_strdup(tmpstring);
						* (void **) tmpitem->pointer = g_list_prepend((GList *) * (void **) tmpitem->pointer, tmpstring2);
						DEBUG_MSG("parse_config_file, *(void **)tmpitem->pointer=%p\n", *(void **) tmpitem->pointer);
						break;
					case 'a':
						tmparray = string_to_array(tmpstring);
						if (tmpitem->len <= 0 || tmpitem->len == count_array(tmparray)) {
							* (void **) tmpitem->pointer = g_list_prepend((GList *) * (void **) tmpitem->pointer, tmparray);
						} else {
							DEBUG_MSG("parse_config_file, not storing array, count_array() != tmpitem->len\n");
							g_strfreev(tmparray);
						}
						DEBUG_MSG("parse_config_file, *(void **)tmpitem->pointer=%p\n", *(void **) tmpitem->pointer);
						break;
					default:
						break;
					}
					tmplist2 = g_list_last(tmplist2);
				}
				tmplist2 = g_list_next(tmplist2);
			}
		}
		tmplist = g_list_next(tmplist);
	}
	DEBUG_MSG("parse_config_file, parsed all entries, freeing list read from file\n");	
	free_stringlist(rclist);
	return retval;
}
コード例 #15
0
void
generate_code_ccplus_window(char *path,WrkWindow *wi)
{
	char tmp[B_PATH_NAME_LENGTH],*fichier = &tmp[0];

	FILE *fi;

	BRect rct = wi->Frame();

	int k,nb,idx = projet.IndexOf(wi) + 1;

	sprintf(fichier,"%s/form%d.cpp",path,idx);
	
	if (fi = fopen(fichier,"w+"))
	{
		BAutolock win(wi);

		generate_copyright_include(fi);

		sprintf(&buf[0],"#include \"form%d.h\"",idx);

		xwrite_string(fi,&buf[0]);
	
		xwrite_cr(fi);

		generate_header_derived_h(fi,wi);

		xwrite_cr(fi);
		xwrite_cr(fi);

		sprintf(&buf[0],"Window%d::Window%d(void):BWindow(BRect(%d,%d,%d,%d),\"%s\",%s,0,%s)",idx,idx,(int)rct.left,(int)rct.top,(int)rct.right,(int)rct.bottom,&wi->WTitle[0],type_win[wi->typewin],wrk_win[wi->wrk]);

		xwrite_string(fi,&buf[0]);

		xwrite_string(fi,"{");
	
		if (wi->minw != 0 || wi->minh != 0 || wi->maxh != 32768 || wi->maxw != 32768)
		{
			sprintf(&buf[0],"\tSetSizeLimits(%d,%d,%d,%d);",wi->minw,wi->maxw,wi->minh,wi->maxh);

			xwrite_string(fi,&buf[0]);
		}

		xwrite_string(fi,"\tback = new BView(Bounds(),\"\",B_FOLLOW_ALL,B_WILL_DRAW);");

		rgb_color cl = wi->bck->ViewColor(),white = { 255,255,255 };

		if (!IsSameColor(&cl,&white))
		{
			sprintf(&buf[0],"\tback->SetViewColor(%d,%d,%d);",cl.red,cl.green,cl.blue);

			xwrite_string(fi,&buf[0]);
		}	

		{
			char *str = "";
			struct MyGadget *gad;
			int t;

			int nb_button = 0;
			int nb_tab = 0;
			int nb_checkbox = 0;
			int nb_radio = 0;
			int nb_color = 0;
			int nb_mx = 0;
			int nb_slider = 0;
			int nb_scroller = 0;
			int nb_string = 0;
			int nb_box = 0;
			int nb_text = 0;
			int nb_status = 0;
			int nb_listview = 0;
			int nb_outlistview = 0;
			int nb_tedit = 0;
			int nb_menu = 0;
			int nb_view = 0;

			for (t = 0; t < wi->list.CountItems(); t++)
			{
				if (gad = (struct MyGadget *)wi->list.ItemAt(t))
				{
					int x = gad->x,y = gad->y,wi = gad->x + gad->wi,he = gad->y + gad->he;

					if (gad->parent)
					{
						BRect rct = gad->pt->Frame();						
						
						x = (int)rct.left;
						y = (int)rct.top;
						wi = (int)rct.Width();
						he = (int)rct.Height();
					}

					if (gad->derived)
					{
						switch(gad->type)
						{
							case	VIEW_KIND:					++nb_view;		nb = nb_view;	str = "View";			break;
							case	BUTTON_KIND:				++nb_button;	nb = nb_button;	str = "Button";			break;
							case	MX_KIND:					++nb_mx;		nb = nb_mx;	str = "MenuField";					break;
							case	TAB_KIND:					++nb_tab;		nb = nb_tab;	str = "Tab";			break;
							case	CHECKBOX_KIND:				++nb_checkbox;	nb = nb_checkbox;	str = "CheckBox";	break;
							case	RADIO_KIND:					++nb_radio;		nb = nb_radio;	str = "RadioButton";			break;
							case	COLOR_KIND:					++nb_color;		nb = nb_color;	str = "Color";			break;
							case	SLIDER_HORIZ_KIND:
							case	SLIDER_VERT_KIND:			++nb_slider;	nb = nb_slider;	str = "Slider";			break;
							case	SCROLLER_HORIZ_KIND:	
							case	SCROLLER_VERT_KIND:			++nb_scroller;	nb = nb_scroller;	str = "ScrollBar";	break;
							case	STRING_KIND:			
							case	INTEGER_KIND:		
							case	PASSWORD_KIND:				
							case	FLOAT_KIND:					++nb_string;	nb = nb_string;	str = "TextControl";		break;
							case	BOX_KIND:					++nb_box;		nb = nb_box;	str = "Box";		break;
							case	NUMBER_KIND:
							case	TEXT_KIND:					++nb_text;		nb = nb_text;	str = "StringView";		break;
							case	STATUSBAR_KIND:				++nb_status;	nb = nb_status;	str = "StatusBar";		break;
							case	LISTVIEW_KIND:
							case	LISTVIEW_HORIZ_KIND:
							case	LISTVIEW_VERT_KIND:
							case	LISTVIEW_ALL_KIND:			++nb_listview;	nb = nb_listview;	str = "ListView";	break;
							case	OUTLISTVIEW_KIND:
							case	OUTLISTVIEW_HORIZ_KIND:
							case	OUTLISTVIEW_VERT_KIND:
							case	OUTLISTVIEW_ALL_KIND:		++nb_outlistview; nb = nb_outlistview;	str = "OutlineListView";	break;
							case	TEDIT_KIND:
							case	TEDIT_HORIZ_KIND:
							case	TEDIT_VERT_KIND:
							case	TEDIT_ALL_KIND:				++nb_tedit;	nb = nb_tedit;		str = "TextView";	break;
						}
					
						sprintf(&buf[0],"\t%s = new B%s%d(BRect(%d,%d,%d,%d));",&gad->Name[0],str,nb,x,y,x + wi,y + he);

						xwrite_string(fi,&buf[0]);	
					
						switch(gad->type)
						{
							case	LISTVIEW_HORIZ_KIND:
							case	LISTVIEW_VERT_KIND:
							case	LISTVIEW_ALL_KIND:
							case	OUTLISTVIEW_HORIZ_KIND:
							case	OUTLISTVIEW_VERT_KIND:
							case	OUTLISTVIEW_ALL_KIND:
							case	TEDIT_HORIZ_KIND:
							case	TEDIT_VERT_KIND:
							case	TEDIT_ALL_KIND:
							{
								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,false,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));

								xwrite_string(fi,&buf[0]);	
							}
							break;
						}
					}
						else
					{
						switch(gad->type)
						{
							case	VIEW_KIND:
							{
								sprintf(&buf[0],"\t%s = new BView(BRect(%d,%d,%d,%d),\"%s\",%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	BUTTON_KIND:
							{
								sprintf(&buf[0],"\t%s = new BButton(BRect(%d,%d,%d,%d),\"%s\",\"%s\",new BMessage((uint32)%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg,GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	CHECKBOX_KIND:
							{
								sprintf(&buf[0],"\t%s = new BCheckBox(BRect(%d,%d,%d,%d),\"%s\",\"%s\",new BMessage((uint32)%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg,GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	BOX_KIND:
							{
								sprintf(&buf[0],"\t%s = new BBox(BRect(%d,%d,%d,%d),\"%s\",%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	RADIO_KIND:
							{
								sprintf(&buf[0],"\t%s = new BRadioButton(BRect(%d,%d,%d,%d),\"%s\",\"%s\",new BMessage((uint32)%d));",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg);
							}
							break;	

							case	COLOR_KIND:
							{
								sprintf(&buf[0],"\t%s = new BColorControl(BPoint(%d,%d),B_CELLS_32x8,8,\"%s\",new BMessage((uint32)%d));",&gad->Name[0],x,y,GetTitle(gad),gad->msg);
							}
							break;	

							case	SLIDER_HORIZ_KIND:
							case	SLIDER_VERT_KIND:
							{
								sprintf(&buf[0],"\t%s = new BSlider(BRect(%d,%d,%d,%d),\"%s\",\"%s\",new BMessage((uint32)%d),0,100,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg,orientation_str[(gad->type == SLIDER_HORIZ_KIND) ? 0 : 1]);
							}
							break;	

							case	SCROLLER_VERT_KIND:
							case	SCROLLER_HORIZ_KIND:
							{
								sprintf(&buf[0],"\t%s = new BScrollBar(BRect(%d,%d,%d,%d),\"%s\",NULL,0,100,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),orientation_str[(gad->type == SCROLLER_HORIZ_KIND) ? 0 : 1]);
							}
							break;	

							case	STATUSBAR_KIND:
							{
								sprintf(&buf[0],"\t%s = new BStatusBar(BRect(%d,%d,%d,%d),\"%s\",\"%s\");",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0]);
							}
							break;	

							case	TAB_KIND:
							{
								int tb = 0;

								switch(gad->data.tab.tabwidth)
								{
									case	B_WIDTH_FROM_WIDEST:	tb = 0;		break;
									case	B_WIDTH_AS_USUAL:		tb = 1;		break;
									case	B_WIDTH_FROM_LABEL:		tb = 2;		break;
								}

								sprintf(&buf[0],"\t%s = new BTabView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),mtab_width[tb],GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	FLOAT_KIND:			
							case	INTEGER_KIND:		
							case	PASSWORD_KIND:				
							case	STRING_KIND:
							{
								sprintf(&buf[0],"\t%s = new BTextControl(BRect(%d,%d,%d,%d),\"%s\",\"%s\",NULL,new BMessage((uint32)%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg,GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	MENU_KIND:
							{
								sprintf(&buf[0],"\t%s = new BMenuBar(BRect(%d,%d,%d,%d),\"%s\");",&gad->Name[0],x,y,wi,he,GetTitle(gad));

								xwrite_string(fi,&buf[0]);	

								generate_code_menu(fi,gad);
							}
							break;	

							case	MX_KIND:
							{
								sprintf(&buf[0],"\t%s = new BMenuField(BRect(%d,%d,%d,%d),\"%s\",\"%s\",new BMenu(\"\"),new BMessage((uint32)%d));",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],gad->msg,orientation_str[(gad->type == SCROLLER_HORIZ_KIND) ? 0 : 1]);
							}
							break;	

							case	TEXT_KIND:
							case	NUMBER_KIND:
							{
								sprintf(&buf[0],"\t%s = new BStringView(BRect(%d,%d,%d,%d),\"%s\",\"%s\",%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),&gad->Title[0],GetAlign(gad),GetFlagView(gad->view));
							}
							break;	

							case	TEDIT_KIND:
							{
								sprintf(&buf[0],"\t%s = new BTextView(BRect(%d,%d,%d,%d),\"%s\",BRect(%d,%d,%d,%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),x,y,wi,he,GetAlign(gad),GetFlagView(gad->view));
							}
							break;

							case	TEDIT_HORIZ_KIND:
							{
								sprintf(&buf[0],"\t%s = new BTextView(BRect(%d,%d,%d,%d),\"%s\",BRect(%d,%d,%d,%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),x,y,wi,he,GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,false,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	TEDIT_VERT_KIND:
							{
								sprintf(&buf[0],"\t%s = new BTextView(BRect(%d,%d,%d,%d),\"%s\",BRect(%d,%d,%d,%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),x,y,wi,he,GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,false,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	TEDIT_ALL_KIND:
							{
								sprintf(&buf[0],"\t%s = new BTextView(BRect(%d,%d,%d,%d),\"%s\",BRect(%d,%d,%d,%d),%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),x,y,wi,he,GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	LISTVIEW_KIND:
							{
								sprintf(&buf[0],"\t%s = new BListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.lv.multi],GetAlign(gad),GetFlagView(gad->view));
							}
							break;

							case	LISTVIEW_HORIZ_KIND:
							{
								sprintf(&buf[0],"\t%s = new BListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.lv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,false,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	LISTVIEW_VERT_KIND:
							{
								sprintf(&buf[0],"\t%s = new BListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.lv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,false,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	LISTVIEW_ALL_KIND:
							{
								sprintf(&buf[0],"\t%s = new BListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.lv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	OUTLISTVIEW_KIND:
							{
								sprintf(&buf[0],"\t%s = new BOutlineListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.olv.multi],GetAlign(gad),GetFlagView(gad->view));
							}
							break;

							case	OUTLISTVIEW_HORIZ_KIND:
							{
								sprintf(&buf[0],"\t%s = new BOutlineListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.olv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,false,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	OUTLISTVIEW_VERT_KIND:
							{
								sprintf(&buf[0],"\t%s = new BOutlineListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.olv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,false,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;

							case	OUTLISTVIEW_ALL_KIND:
							{
								sprintf(&buf[0],"\t%s = new BOutlineListView(BRect(%d,%d,%d,%d),\"%s\",%s,%s,%s);",&gad->Name[0],x,y,wi,he,GetTitle(gad),selection_lv[gad->data.olv.multi],GetAlign(gad),GetFlagView(gad->view));

								xwrite_string(fi,&buf[0]);	

								sprintf(&buf[0],"\t__%s = new BScrollView(\"\",%s,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE,true,true,B_FANCY_BORDER);",&gad->Name[0],GetTitle(gad));
							}
							break;
						}
				
						if (gad->type != MENU_KIND)
						{
							xwrite_string(fi,&buf[0]);	
						}
					}	
				}
			}
		}	

		xwrite_cr(fi);

		{
			char tmp[512];

			struct MyGadget *gad;
			int t;

			for (t = 0; t < wi->list.CountItems(); t++)
			{
				if (gad = (struct MyGadget *)wi->list.ItemAt(t))
				{
					switch(gad->type)
					{
						case	FLOAT_KIND:			
						case	INTEGER_KIND:		
						case	PASSWORD_KIND:				
						case	STRING_KIND:
						case	BUTTON_KIND:
						case	CHECKBOX_KIND:
						case	BOX_KIND:
						case	VIEW_KIND:
						case	RADIO_KIND:
						case	COLOR_KIND:
						case	OUTLISTVIEW_KIND:
						case	SLIDER_HORIZ_KIND:
						case	SLIDER_VERT_KIND:
						case	SCROLLER_VERT_KIND:
						case	SCROLLER_HORIZ_KIND:
						case	STATUSBAR_KIND:
						case	TAB_KIND:
						case	MENU_KIND:
						case	MX_KIND:
						case	TEXT_KIND:
						case	NUMBER_KIND:
						case	TEDIT_KIND:
						case	LISTVIEW_KIND:
						{
							sprintf(&buf[0],&gad->Name[0]);
						}
						break;	

						case	TEDIT_HORIZ_KIND:
						case	TEDIT_VERT_KIND:
						case	TEDIT_ALL_KIND:
						case	LISTVIEW_HORIZ_KIND:
						case	LISTVIEW_VERT_KIND:
						case	LISTVIEW_ALL_KIND:
						case	OUTLISTVIEW_HORIZ_KIND:
						case	OUTLISTVIEW_VERT_KIND:
						case	OUTLISTVIEW_ALL_KIND:
						{
							sprintf(&buf[0],"__%s",&gad->Name[0]);
						}
						break;
					}	

					{
						char xt[256],jp[256];
						
						strcpy(&jp[0],ToLower(&buf[0]));					

						if (!gad->parent)
						{
							sprintf(&tmp[0],"\tback->AddChild(%s);",&jp[0]);

							xwrite_string(fi,&tmp[0]);	
						}
							else
						{
							strcpy(&xt[0],ToLower(&gad->parent->Name[0]));					

							sprintf(&tmp[0],"\t%s->AddChild(%s);",&xt[0],&jp[0]);

							xwrite_string(fi,&tmp[0]);	
						}
					}
				}
			}
		}	

		xwrite_string(fi,"\tAddChild(back);");

		xwrite_string(fi,"\tShow();");

		xwrite_string(fi,"}");

		xwrite_cr(fi);

		sprintf(&buf[0],"Window%d::~Window%d(void)\n{",idx,idx);

		xwrite_string(fi,&buf[0]);

		if (!(wi->idcmp & (1L << 18)))
		{
			xwrite_string(fi,"\tbe_app->PostMessage(B_QUIT_REQUESTED);");
		}
		
		xwrite_string(fi,"}\n");

		nb = count_array(&msg_winevents_ccplus_gencode[0]);

		for (k = 0; k < nb; k++)
		{
			if (wi->idcmp & (1L << k))
			{
				char *fd,tmp[512];
				
				strcpy(&tmp[0],msg_winevents_ccplus_gencode[k]);

				if (fd = strchr(&tmp[0],' '))
				{
					*fd++ = '\0';

					xwrite_string(fi,&tmp[0]);

					sprintf(&buf[0],"Window%d::%s",idx,fd);

					buf[strlen(&buf[0]) - 1] = 0;

					xwrite_string(fi,&buf[0]);	

					xwrite_string(fi,"{");

					if (k == 18)
					{
						xwrite_string(fi,"\tbe_app->PostMessage(B_QUIT_REQUESTED);");
						xwrite_string(fi,"\treturn true;");
					}

					xwrite_string(fi,"}");

					xwrite_cr(fi);
				}
			}
		}

		fclose(fi);	

		set_sourcecode(fichier);
	}
}
コード例 #16
0
void
generate_header_ccplus_window(char *path,WrkWindow *wi)
{
	char tmp[B_PATH_NAME_LENGTH],*fichier = &tmp[0],*str = "";
	struct MyGadget *gad;
	FILE *fi;

	int t,k,nb,idx = projet.IndexOf(wi) + 1;

	sprintf(fichier,"%s/form%d.h",path,idx);
	
	if (fi = fopen(fichier,"w+"))
	{
		generate_copyright_include(fi);

		generate_header_derived_h(fi,wi);

		sprintf(&buf[0],"#ifndef __Window%d",idx);

		xwrite_string(fi,&buf[0]);	

		xwrite_cr(fi);

		sprintf(&buf[0],"class Window%d : public BWindow",idx);

		xwrite_string(fi,&buf[0]);	

		xwrite_string(fi,"{\npublic:\n");	

		sprintf(&buf[0],"\tWindow%d(void);",idx);

		xwrite_string(fi,&buf[0]);	

		sprintf(&buf[0],"\t~Window%d(void);",idx);

		xwrite_string(fi,&buf[0]);	

		xwrite_cr(fi);

		nb = count_array(&msg_winevents_ccplus_gencode[0]);

		for (k = 0; k < nb; k++)
		{
			if (wi->idcmp & (1L << k))
			{
				sprintf(&buf[0],"\tvirtual %s",msg_winevents_ccplus_gencode[k]);

				xwrite_string(fi,&buf[0]);	
			}
		}
		
		xwrite_cr(fi);

		xwrite_string(fi,"\tBView *back;");	

		if (add_scrollview_adress(wi))
		{
			for (t = 0; t < wi->list.CountItems(); t++)
			{
				if (gad = (struct MyGadget *)wi->list.ItemAt(t))
				{
					switch(gad->type)
					{
						case	LISTVIEW_HORIZ_KIND:
						case	LISTVIEW_VERT_KIND:
						case	LISTVIEW_ALL_KIND:
						case	OUTLISTVIEW_HORIZ_KIND:
						case	OUTLISTVIEW_VERT_KIND:
						case	OUTLISTVIEW_ALL_KIND:
						case	TEDIT_HORIZ_KIND:
						case	TEDIT_VERT_KIND:
						case	TEDIT_ALL_KIND:
						{
							sprintf(&buf[0],"\tBScrollView *__%s;",&gad->Name[0]);
	
							xwrite_string(fi,&buf[0]);	
						}
						break;
					}
				}
			}
		}
	
		xwrite_cr(fi);

		{
			int nb_button = 0;
			int nb_tab = 0;
			int nb_checkbox = 0;
			int nb_radio = 0;
			int nb_color = 0;
			int nb_mx = 0;
			int nb_slider = 0;
			int nb_scroller = 0;
			int nb_string = 0;
			int nb_box = 0;
			int nb_text = 0;
			int nb_status = 0;
			int nb_listview = 0;
			int nb_outlistview = 0;
			int nb_tedit = 0;
			int nb_menu = 0;
			int nb_view = 0;

			for (t = 0; t < wi->list.CountItems(); t++)
			{
				if (gad = (struct MyGadget *)wi->list.ItemAt(t))
				{
					if (gad->derived)
					{
						switch(gad->type)
						{
							case	VIEW_KIND:					++nb_view;		nb = nb_view;		str = "View";			break;
							case	BUTTON_KIND:				++nb_button;	nb = nb_button;		str = "Button";			break;
							case	MX_KIND:					++nb_mx;		nb = nb_mx;			str = "MenuField";		break;
							case	TAB_KIND:					++nb_tab;		nb = nb_tab;		str = "Tab";			break;
							case	CHECKBOX_KIND:				++nb_checkbox;	nb = nb_checkbox;	str = "CheckBox";		break;
							case	RADIO_KIND:					++nb_radio;		nb = nb_radio;		str = "RadioButton";	break;
							case	COLOR_KIND:					++nb_color;		nb = nb_color;		str = "Color";			break;
							case	SLIDER_HORIZ_KIND:
							case	SLIDER_VERT_KIND:			++nb_slider;	nb = nb_slider;		str = "Slider";			break;
							case	SCROLLER_HORIZ_KIND:	
							case	SCROLLER_VERT_KIND:			++nb_scroller;	nb = nb_scroller;	str = "ScrollBar";	break;
							case	STRING_KIND:			
							case	INTEGER_KIND:		
							case	PASSWORD_KIND:				
							case	FLOAT_KIND:					++nb_string;	nb = nb_string;		str = "TextControl";		break;
							case	BOX_KIND:					++nb_box;		nb = nb_box;		str = "Box";		break;
							case	NUMBER_KIND:
							case	TEXT_KIND:					++nb_text;		nb = nb_text;		str = "StringView";		break;
							case	STATUSBAR_KIND:				++nb_status;	nb = nb_status;		str = "StatusBar";		break;
							case	LISTVIEW_KIND:
							case	LISTVIEW_HORIZ_KIND:
							case	LISTVIEW_VERT_KIND:
							case	LISTVIEW_ALL_KIND:			++nb_listview;	nb = nb_listview;	str = "ListView";	break;
							case	OUTLISTVIEW_KIND:
							case	OUTLISTVIEW_HORIZ_KIND:
							case	OUTLISTVIEW_VERT_KIND:
							case	OUTLISTVIEW_ALL_KIND:		++nb_outlistview; nb = nb_outlistview;	str = "OutlineListView";	break;
							case	TEDIT_KIND:
							case	TEDIT_HORIZ_KIND:
							case	TEDIT_VERT_KIND:
							case	TEDIT_ALL_KIND:				++nb_tedit;	nb = nb_tedit;			str = "TextView";	break;
						}
					
						if (gad->type != MENU_KIND)
						{
							sprintf(&buf[0],"\tB%s%d *%s;",str,nb,&gad->Name[0]);

							xwrite_string(fi,&buf[0]);	
						}
					}
						else
					{	
						switch(gad->type)
						{
							case	VIEW_KIND:				++nb_view;		nb = nb_view;		str = "BView";			break;
							case	BUTTON_KIND:			++nb_button;	nb = nb_button;		str = "BButton";		break;
							case	MENU_KIND:				++nb_menu;		nb = nb_menu;		str = "BMenuBar";		break;
							case	MX_KIND:				++nb_mx;		nb = nb_mx;			str = "BMenuField";		break;
							case	TAB_KIND:				++nb_tab;		nb = nb_tab;		str = "BTabView";		break;
							case	CHECKBOX_KIND:			++nb_checkbox;	nb = nb_checkbox;	str = "BCheckBox";		break;
							case	RADIO_KIND:				++nb_radio;		nb = nb_radio;		str = "BRadioButton";	break;
							case	COLOR_KIND:				++nb_color;		nb = nb_color;		str = "BColorControl";	break;
							case	SLIDER_HORIZ_KIND:
							case	SLIDER_VERT_KIND:		++nb_slider;	nb = nb_slider;		str = "BSlider";		break;
							case	SCROLLER_HORIZ_KIND:	
							case	SCROLLER_VERT_KIND:		++nb_scroller;	nb = nb_scroller;	str = "BScrollBar";		break;
							case	STRING_KIND:			
							case	INTEGER_KIND:		
							case	PASSWORD_KIND:				
							case	FLOAT_KIND:				++nb_string;	nb = nb_string;		str = "BTextControl";	break;
							case	BOX_KIND:				++nb_box;		nb = nb_box;		str = "BBox";			break;
							case	NUMBER_KIND:
							case	TEXT_KIND:				++nb_text;		nb = nb_text;		str = "BStringView";		break;
							case	STATUSBAR_KIND:			++nb_status;	nb = nb_status;		str = "BStatusBar";			break;
							case	LISTVIEW_KIND:
							case	LISTVIEW_HORIZ_KIND:
							case	LISTVIEW_VERT_KIND:
							case	LISTVIEW_ALL_KIND:		++nb_listview;	nb = nb_listview;	str = "BListView";		break;
							case	OUTLISTVIEW_KIND:
							case	OUTLISTVIEW_HORIZ_KIND:
							case	OUTLISTVIEW_VERT_KIND:
							case	OUTLISTVIEW_ALL_KIND:	++nb_outlistview; nb = nb_outlistview;	str = "BOutlineListView";	break;
							case	TEDIT_KIND:
							case	TEDIT_HORIZ_KIND:
							case	TEDIT_VERT_KIND:
							case	TEDIT_ALL_KIND:			++nb_tedit;	nb = nb_tedit;		str = "BTextView";	break;
						}

						sprintf(&buf[0],"\t%s *%s;",str,&gad->Name[0]);

						xwrite_string(fi,&buf[0]);	

						if (gad->type == MENU_KIND)
						{
							xwrite_string(fi,"\tBMenu *mn,*sb;");	
							xwrite_string(fi,"\tBMenuItem *it;");	
						}
					}
				}
			}
		}
			
		xwrite_string(fi,"};");	

		xwrite_cr(fi);

		xwrite_cr(fi);

		sprintf(&buf[0],"#define __Window%d",idx);

		xwrite_string(fi,&buf[0]);	

		xwrite_string(fi,"#endif");	

		fclose(fi);	

		set_sourcecode(fichier);
	}
}