コード例 #1
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;
}
コード例 #2
0
ファイル: servers-reconnect.c プロジェクト: svn2github/irssi
/* SYNTAX: RECONNECT <tag> [<quit message>] */
static void cmd_reconnect(const char *data, SERVER_REC *server)
{
	SERVER_CONNECT_REC *conn;
	RECONNECT_REC *rec;
	char *tag, *msg;
	void *free_arg;
	int tagnum;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
		return;

	if (*tag != '\0' && strcmp(tag, "*") != 0)
		server = server_find_tag(tag);

	if (server != NULL) {
		/* reconnect connected server */
		conn = server_connect_copy_skeleton(server->connrec, TRUE);

		if (server->connected)
			reconnect_save_status(conn, server);

		msg = g_strconcat("* ", *msg == '\0' ?
				  "Reconnecting" : msg, NULL);
		signal_emit("command disconnect", 2, msg, server);
		g_free(msg);

		conn->reconnection = TRUE;
		server_connect(conn);
		server_connect_unref(conn);
		cmd_params_free(free_arg);
                return;
	}

	if (g_strcasecmp(tag, "all") == 0) {
		/* reconnect all servers in reconnect queue */
                reconnect_all();
		cmd_params_free(free_arg);
                return;
	}

	if (*data == '\0') {
		/* reconnect to first server in reconnection list */
		if (reconnects == NULL)
			cmd_param_error(CMDERR_NOT_CONNECTED);
                rec = reconnects->data;
	} else {
		if (g_strncasecmp(data, "RECON-", 6) == 0)
			data += 6;

		tagnum = atoi(tag);
		rec = tagnum <= 0 ? NULL : reconnect_find_tag(tagnum);
	}

	if (rec == NULL) {
		signal_emit("server reconnect not found", 1, data);
	} else {
		conn = rec->conn;
		server_connect_ref(conn);
		server_reconnect_destroy(rec);
		server_connect(conn);
		server_connect_unref(conn);
	}

	cmd_params_free(free_arg);
}
コード例 #3
0
ファイル: nick.c プロジェクト: malinkb/bitlbee
char *nick_gen(bee_user_t *bu)
{
	gboolean ok = FALSE; /* Set to true once the nick contains something unique. */
	GString *ret = g_string_sized_new(MAX_NICK_LENGTH + 1);
	char *rets;
	irc_t *irc = (irc_t *) bu->bee->ui_data;
	char *fmt = set_getstr(&bu->ic->acc->set, "nick_format") ? :
	            set_getstr(&bu->bee->set, "nick_format");

	while (fmt && *fmt && ret->len < MAX_NICK_LENGTH) {
		char *part = NULL, chop = '\0', *asc = NULL, *s;
		int len = INT_MAX;

		if (*fmt != '%') {
			g_string_append_c(ret, *fmt);
			fmt++;
			continue;
		}

		fmt++;
		while (*fmt) {
			/* -char means chop off everything from char */
			if (*fmt == '-') {
				chop = fmt[1];
				if (chop == '\0') {
					g_string_free(ret, TRUE);
					return NULL;
				}
				fmt += 2;
			} else if (g_ascii_isdigit(*fmt)) {
				len = 0;
				/* Grab a number. */
				while (g_ascii_isdigit(*fmt)) {
					len = len * 10 + (*(fmt++) - '0');
				}
			} else if (g_strncasecmp(fmt, "nick", 4) == 0) {
				part = bu->nick ? : bu->handle;
				fmt += 4;
				ok |= TRUE;
				break;
			} else if (g_strncasecmp(fmt, "handle", 6) == 0) {
				part = bu->handle;
				fmt += 6;
				ok |= TRUE;
				break;
			} else if (g_strncasecmp(fmt, "full_name", 9) == 0) {
				part = bu->fullname;
				fmt += 9;
				ok |= part && *part;
				break;
			} else if (g_strncasecmp(fmt, "first_name", 10) == 0) {
				part = bu->fullname;
				fmt += 10;
				ok |= part && *part;
				chop = ' ';
				break;
			} else if (g_strncasecmp(fmt, "group", 5) == 0) {
				part = bu->group ? bu->group->name : NULL;
				fmt += 5;
				break;
			} else if (g_strncasecmp(fmt, "account", 7) == 0) {
				part = bu->ic->acc->tag;
				fmt += 7;
				break;
			} else {
				g_string_free(ret, TRUE);
				return NULL;
			}
		}
コード例 #4
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgPRTree3d *tree;
  gint i;

  VsgVector3d lb;
  VsgVector3d ub;


  MPI_Init (&argc, &argv);

  MPI_Comm_size (MPI_COMM_WORLD, &sz);
  MPI_Comm_rank (MPI_COMM_WORLD, &rk);

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      if (rk == 0)
        g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  if (argc > 1 && g_strncasecmp (argv[1], "--write", 7) == 0)
    {
      _do_write = TRUE;
    }

  vsg_init_gdouble ();

  points = g_ptr_array_new ();
  regions = g_ptr_array_new ();

  if (rk == 0)
    {
      VsgVector3d *pt;
      Sphere *c;

      lb.x = -1.; lb.y = -1.; lb.z = -1.;
      ub.x = 0.; ub.y = 0.; ub.z = 0.;

      pt = pt_alloc (TRUE, NULL);
      pt->x = -0.5; pt->y = -0.5; pt->z = -0.5;

      c = rg_alloc (TRUE, NULL);
      c->center.x = -0.6; c->center.y = -0.6; c->center.z = -0.6;
      c->radius = 0.1;
    }
  else
    {
      VsgVector3d *pt;
      Sphere *c;

      lb.x = 0.; lb.y = 0.; lb.z = 0.;
      ub.x = 1.*rk; ub.y = 1.*rk; ub.z = 1.*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.5*rk; pt->y = 0.5*rk; pt->z = 0.5*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.60*rk; pt->y = 0.65*rk; pt->z = 0.70*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.15*rk; pt->y = 0.75*rk; pt->z = 0.80*rk;

      c = rg_alloc (TRUE, NULL);
      c->center.x = 0.6*rk; c->center.y = 0.6*rk; c->center.z = 0.6*rk;
      c->radius = 0.11;
    }

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           (VsgRegion3dLocFunc) _sphere_loc3, 2);

  /* insert the points */
  for (i=0; i<points->len; i++)
    {
      vsg_prtree3d_insert_point (tree, g_ptr_array_index (points, i));
    }

  /* insert the regions */
  for (i=0; i<regions->len; i++)
    {
      vsg_prtree3d_insert_region (tree, g_ptr_array_index (regions, i));
    }

  /* count total created points and regions */
  init_total_points_count ();
  init_total_regions_count ();

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: set_parallel begin\n", rk); */

  vsg_prtree3d_set_parallel (tree, &pconfig);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: set_parallel ok\n", rk); */

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: before migrate_flush ok\n", rk); */
  {
    VsgVector3d *pt;
    Sphere *c;

    pt = pt_alloc (TRUE, NULL);
    pt->x = 0.5*rk; pt->y = 0.75*rk; pt->z = 0.75*rk;
    vsg_prtree3d_insert_point (tree, pt);

    c = rg_alloc (TRUE, NULL);
    c->center.x = 1.; c->center.y = 0.6*rk; c->center.z = 0.6*rk;
    c->radius = 0.1;
    vsg_prtree3d_insert_region (tree, c);
  }

  /* update total points and regions count */
  init_total_points_count ();
  init_total_regions_count ();

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: migrate_flush begin\n", rk); */

  vsg_prtree3d_migrate_flush (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: migrate_flush ok\n", rk); */

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: distribute_nodes begin\n", rk); */

  for (i=0; i<sz; i++)
    {
      gint dst = (i+1) % sz;

/*       MPI_Barrier (MPI_COMM_WORLD); */
/*       g_printerr ("%d: move to %d\n", rk, dst); */

      vsg_prtree3d_distribute_concentrate (tree, dst);

      ret += check_points_number (tree);
      ret += check_regions_number (tree);
    }

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: split between nodes\n", rk); */

  vsg_prtree3d_distribute_scatter_leaves (tree);

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/* /\*   MPI_Barrier (MPI_COMM_WORLD); *\/ */
/* /\*   g_printerr ("%d: distribute_nodes ok\n", rk); *\/ */

  if (_do_write)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      _tree_write (tree);
    }

  if (_do_write)
    {
      gchar fn[1024];
      FILE *f;

      g_sprintf (fn, "prtree3parallel-%03d.txt", rk);
      f = fopen (fn, "w");
      vsg_prtree3d_write (tree, f);
      fclose (f);
    }

  /* destroy the points */
  g_ptr_array_foreach (points, empty_array, NULL);
  g_ptr_array_free (points, TRUE);

  /* destroy the spheres */
  g_ptr_array_foreach (regions, empty_array, NULL);
  g_ptr_array_free (regions, TRUE);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  MPI_Finalize ();

  return ret;
}
コード例 #5
0
static
void parse_args (int argc, char **argv)
{
  int iarg = 1;
  char *arg;

  while (iarg < argc)
    {
      arg = argv[iarg];

      if (g_ascii_strcasecmp (arg, "-np") == 0)
        {
          guint tmp = 0;
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (sscanf (arg, "%u", &tmp) == 1)
              np = tmp;
          else
            g_printerr ("Invalid particles number (-np %s)\n", arg);
        }
      else if (g_ascii_strcasecmp (arg, "-pr") == 0)
        {
          guint tmp = 0;
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0)
              order = tmp;
          else
            g_printerr ("Invalid precision order value (-pr %s)\n", arg);
        }
      else if (g_ascii_strcasecmp (arg, "-s") == 0)
        {
          guint tmp = 0;
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0)
              maxbox = tmp;
          else
            g_printerr ("Invalid maximum box size value (-s %s)\n", arg);
        }
      else if (g_ascii_strcasecmp (arg, "-err") == 0)
        {
          gdouble tmp = 0;
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (sscanf (arg, "%lf", &tmp) == 1 && tmp > 0.)
              err_lim = tmp;
          else
            g_printerr ("Invalid error limit value (-err %s)\n", arg);
        }
      else if (g_ascii_strcasecmp (arg, "-nocheck") == 0)
        {
          check = FALSE;
        }

      else if (g_ascii_strcasecmp (arg, "-check") == 0)
        {
          check = TRUE;
        }
      else if (g_ascii_strcasecmp (arg, "-direct") == 0)
        {
          direct = TRUE;
        }
      else if (g_ascii_strcasecmp (arg, "-dist") == 0)
        {
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (g_ascii_strcasecmp (arg, "circle") == 0)
            {
              _fill = _one_circle_fill;
            }
          else if (g_ascii_strcasecmp (arg, "random2") == 0)
            {
              _fill = _random2_fill;
            }
          else if (g_ascii_strcasecmp (arg, "random") == 0)
            {
              _fill = _random_fill;
            }
          else if (g_ascii_strcasecmp (arg, "grid") == 0)
            {
              _fill = _grid_fill;
            }
          else if (g_ascii_strcasecmp (arg, "uvsphere") == 0)
            {
              _fill = _uvsphere_fill;
            }
          else if (g_ascii_strcasecmp (arg, "plummer") == 0)
            {
              _fill = _plummer_fill;
            }
          else if (g_ascii_strcasecmp (arg, "load") == 0)
            {
              _fill = _load_fill;

              iarg ++;
              arg = (iarg<argc) ? argv[iarg] : NULL;

              _load_file = g_malloc (1024*sizeof (gchar));
              sscanf (arg, "%s", _load_file);
            }
          else
            {
              g_printerr ("Invalid fill name (-dist %s)\n", arg);
            }
        }
      else if (g_ascii_strcasecmp (arg, "-translation") == 0)
        {
          iarg ++;

          arg = (iarg<argc) ? argv[iarg] : NULL;

          if (g_ascii_strcasecmp (arg, "normal") == 0)
            {
              m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m;

              m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l;

              l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l;
            }
          else if (g_ascii_strcasecmp (arg, "kkylin") == 0)
            {
              m2m =
                (AranMultipole2MultipoleFunc3d) aran_development3d_m2m_kkylin;

              m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l_kkylin;

              l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l_kkylin;
            }
          else if (g_ascii_strcasecmp (arg, "rotate") == 0)
            {
              m2m =
                (AranMultipole2MultipoleFunc3d) aran_development3d_m2m_rotate;

              m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l_rotate;

              l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l_rotate;
            }
          else
            {
              g_printerr ("Invalid translation name (-translation %s)\n", arg);
            }
        }
      else if (g_ascii_strcasecmp (arg, "-hilbert") == 0)
        {
          _hilbert = TRUE;
        }
      else if (g_strncasecmp (arg, "-v", 2) == 0 ||
               g_strncasecmp (arg, "--verbose", 9) == 0)
        {
          _verbose = TRUE;
        }
      else if (g_strncasecmp (arg, "--write", 9) == 0)
        {
          _write = TRUE;
        }
      else if (g_ascii_strcasecmp (arg, "--version") == 0)
        {
          g_printerr ("%s version %s\n", argv[0], PACKAGE_VERSION);
          exit (0);
        }
      else
        {
          g_printerr ("Invalid argument \"%s\"\n", arg);
        }

      iarg ++;
    }
}
コード例 #6
0
ファイル: terminal-find.c プロジェクト: cran/gnomeGUI
int find_update_line_cache(GnomeFindDialog *find_dialog)
{
  int find_text_len;
  int eflags;
  regmatch_t pmatch[1];
  int regex_result;
  char errbuf[ERRBUF_SIZE];
  char messagebuf[MSGBUF_SIZE];
  int strcmp_result;
  int tmp_find_pos;
  gchar *find_line_cache;
  find_selection *find_select;

  GtkWidget *message_dialog;

  /* initialisation */
  find_line_cache = NULL;
  find_text_len = strlen(find_params.find_text);
  line_cache_update = FALSE;

  /* free matches list if necessary */
  if (find_current_match != NULL) {
    find_current_match = g_list_first(find_current_match);
    g_list_foreach(find_current_match, find_free_select, NULL);
    g_list_free(find_current_match);
    find_current_match = NULL;
  }

  /* Move one line */
  switch (find_params.direction) {
  case GNOME_FIND_FORWARDS:
    do {
      if(find_pos > find_pos_max) {
	if(find_params.wrap_search == TRUE) {
	  find_pos = 0;
	  search_wrapped = TRUE;
	}
	else {
	  return GNOME_FIND_NOMATCH;
	}
      }
      else {
	find_pos++;
	if((search_wrapped) && (find_pos >= find_pos_init)) {
	  return GNOME_FIND_NOMATCH;
	}
      }
    } while (find_text_cache[find_pos] == '\n');
    break;
    
  case GNOME_FIND_BACKWARDS:
    do {
      if(find_pos < 0) {
	if(find_params.wrap_search == TRUE) {
	  find_pos = find_pos_max;
	  search_wrapped = TRUE;
	}
	else {
	  return GNOME_FIND_NOMATCH;
	}
      }
      else {
	find_pos--;
	if((search_wrapped) && (find_pos <= find_pos_init)) {
	  return GNOME_FIND_NOMATCH;
	}
      }
    } while (find_text_cache[find_pos] == '\n');
    break;
  }

  line_cache_start = line_cache_end = find_pos;

  while ((line_cache_start > 0) && (find_text_cache[line_cache_start - 1] != '\n')) {
    line_cache_start--;
  }
  while ((line_cache_end < find_pos_max) && (find_text_cache[line_cache_end + 1] != '\n')) {
    line_cache_end++;
  }
  
  /* Grab the line */
  find_line_cache = g_strndup(find_text_cache + line_cache_start,
			      line_cache_end - line_cache_start + 1);

  /* Search line */
  if (find_params.regex == TRUE) {
    /* Regular expression search */
    tmp_find_pos = 0; 
    eflags = 0;
    do {
      if (tmp_find_pos != 0) {
	eflags = REG_NOTBOL;
      }

      /* execute the match */
      regex_result = regexec(preg, find_line_cache + tmp_find_pos, 1, pmatch, eflags);

      if(regex_result == 0) {
	/* construct list item if found */
	find_select = g_new(find_selection, 1);
	find_select->select_start = line_cache_start + tmp_find_pos + pmatch[0].rm_so;
	find_select->select_end = line_cache_start + tmp_find_pos + pmatch[0].rm_eo;
	find_current_match = g_list_append(find_current_match, (gpointer) find_select);

	tmp_find_pos += pmatch[0].rm_so + 1;
      }
      else if (regex_result != REG_NOMATCH) {
	/* report regexec errors and terminate the search */
	regerror(regex_result, preg, errbuf, ERRBUF_SIZE);
	g_snprintf(messagebuf, MSGBUF_SIZE,
		   "Error matching regular expression: %s", errbuf);

	message_dialog = gnome_message_box_new(messagebuf,
					       GNOME_MESSAGE_BOX_ERROR,
					       GNOME_STOCK_BUTTON_OK,
					       NULL);
	if (find_dialog != NULL ) {
	  gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog));
	}
	else {
	  gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window));
	}
	gnome_dialog_run_and_close(GNOME_DIALOG(message_dialog));

	if (find_line_cache != NULL) {
	  g_free(find_line_cache);
	}

	return GNOME_FIND_NOMATCH;
      }
    } while ((tmp_find_pos <= (line_cache_end - line_cache_start)) && (regex_result == 0));
  }
  else {
    /* Literal search */
    for (tmp_find_pos = line_cache_start; tmp_find_pos <= line_cache_end; tmp_find_pos++) {
      if (find_params.case_sensitive == TRUE) {
	strcmp_result = strncmp(find_params.find_text,
				find_text_cache + tmp_find_pos,	find_text_len);
      }
      else {
	strcmp_result = g_strncasecmp(find_params.find_text,
				      find_text_cache + tmp_find_pos, 
				      find_text_len);
      }

      /* construct list item if found */
      if(strcmp_result == 0) {
	find_select = g_new(find_selection, 1);
	find_select->select_start = tmp_find_pos;
	find_select->select_end = tmp_find_pos + find_text_len;
	find_current_match = g_list_append(find_current_match, (gpointer) find_select);
      }
    }
  }

  if (find_line_cache != NULL) {
    g_free(find_line_cache);
  }

  /* Return result */
  if (find_current_match != NULL) {
    if(find_params.direction == GNOME_FIND_BACKWARDS)
      find_current_match = g_list_last(find_current_match);
    return GNOME_FIND_MATCH;
  }

  return GNOME_FIND_NOTFOUND;
}
コード例 #7
0
ファイル: netsplit.c プロジェクト: svn2github/irssi
/* check if quit message is a netsplit message */
int quitmsg_is_split(const char *msg)
{
	const char *host1, *host2, *p;
        int prev, len, host1_dot, host2_dot;

	g_return_val_if_fail(msg != NULL, FALSE);

	/* NOTE: there used to be some paranoia checks (some older IRC
	   clients have even more), but they're pretty useless nowadays,
	   since IRC server prefixes the quit message with a space if it
	   looks like a netsplit message.

	   So, the check is currently just:
             - host1.domain1 host2.domain2
             - top-level domains have to be 2+ characters long,
	       containing only alphabets
	     - only 1 space
	     - no double-dots (".." - probably useless check)
	     - hosts/domains can't start or end with a dot
             - the two hosts can't be identical (probably useless check)
	     - can't contain ':' or '/' chars (some servers allow URLs)
	   */
	host1 = msg; host2 = NULL;
	prev = '\0'; len = 0; host1_dot = host2_dot = 0;
	while (*msg != '\0') {
		if (*msg == ' ') {
			if (prev == '.' || prev == '\0') {
				/* domains can't end with '.', space can't
				   be the first character in msg. */
				return FALSE;
			}
			if (host2 != NULL)
				return FALSE; /* only one space allowed */
			if (!host1_dot)
                                return FALSE; /* host1 didn't have domain */
                        host2 = msg+1; len = -1;
		} else if (*msg == '.') {
			if (prev == '\0' || prev == ' ' || prev == '.') {
				/* domains can't start with '.'
				   and can't have ".." */
				return FALSE;
			}

			if (host2 != NULL)
				host2_dot = TRUE;
			else
                                host1_dot = TRUE;
		} else if (*msg == ':' || *msg == '/')
			return FALSE;

		prev = *msg;
                msg++; len++;
	}

	if (!host2_dot || prev == '.')
                return FALSE;

	if (len == (int) (host2-host1)-1 &&
	    g_strncasecmp(host1, host2, len) == 0)
		return FALSE; /* hosts can't be the same */

        /* top-domain1 must be 2+ chars long and contain only alphabets */
	p = host2-1;
	while (p[-1] != '.') {
		if (!i_isalpha(p[-1]))
                        return FALSE;
		p--;
	}
	if (host2-p-1 < 2) return FALSE;

        /* top-domain2 must be 2+ chars long and contain only alphabets */
	p = host2+strlen(host2);
	while (p[-1] != '.') {
		if (!i_isalpha(p[-1]))
                        return FALSE;
		p--;
	}
	if (strlen(p) < 2) return FALSE;

        return TRUE;
}
コード例 #8
0
ファイル: main_window.c プロジェクト: maheshmohanmu/gphpedit
void plugin_exec(gint plugin_num)
{
	Plugin *plugin;
	gchar *stdout = NULL;
	GError *error = NULL;
	gint exit_status;
	GString *command_line = NULL;
	gint wordStart;
	gint wordEnd;
	gchar *current_selection;
	gint ac_length;
	gchar *data;
	
	if (main_window.current_editor == NULL) {
		return;
	}
	
	plugin = (Plugin *)g_list_nth_data(Plugins, plugin_num);
	if (!plugin) {
		g_print(_("Plugin is null!\n"));
	}
	//g_print("Plugin No: %d:%d (%s):%s\n", plugin_num, plugin->type, plugin->name, plugin->filename->str);
	command_line = g_string_new(plugin->filename->str);
	command_line = g_string_prepend(command_line, "'");
	command_line = g_string_append(command_line, "' '");
	
	if (plugin->type == GPHPEDIT_PLUGIN_TYPE_SELECTION) {
		wordStart = gtk_scintilla_get_selection_start(GTK_SCINTILLA(main_window.current_editor->scintilla));
		wordEnd = gtk_scintilla_get_selection_end(GTK_SCINTILLA(main_window.current_editor->scintilla));
		current_selection = gtk_scintilla_get_text_range (GTK_SCINTILLA(main_window.current_editor->scintilla), wordStart, wordEnd, &ac_length);
		
		command_line = g_string_append(command_line, current_selection);
	}
	else if (plugin->type == GPHPEDIT_PLUGIN_TYPE_FILENAME) {
		command_line = g_string_append(command_line, editor_convert_to_local(main_window.current_editor));		
	}
	command_line = g_string_append(command_line, "'");
	
	//g_print("SPAWNING: %s\n", command_line->str);
	
	if (g_spawn_command_line_sync(command_line->str,&stdout,NULL, &exit_status,&error)) {
		data = strstr(stdout, "\n");
		data++;
		
		//g_print("COMMAND: %s\nSTDOUT:%s\nOUTPUT: %s\n", command_line->str, stdout, data);
		
		if (g_strncasecmp(stdout, "INSERT", MIN(strlen(stdout), 6))==0) {
			if (data) {
				gtk_scintilla_insert_text(GTK_SCINTILLA(main_window.current_editor->scintilla), 
					gtk_scintilla_get_current_pos(GTK_SCINTILLA(main_window.current_editor->scintilla)), data);
			}
		}
		else if (g_strncasecmp(stdout, "REPLACE", MIN(strlen(stdout), 7))==0) {
			if (data) {
				gtk_scintilla_replace_sel(GTK_SCINTILLA(main_window.current_editor->scintilla), data);
			}
		}
		else if (g_strncasecmp(stdout, "MESSAGE", MIN(strlen(stdout),7))==0) {
				info_dialog(plugin->name, data);
		}
		else if (g_strncasecmp(stdout, "OPEN", MIN(strlen(stdout), 4))==0) {
			if (DEBUG_MODE) { g_print("DEBUG: main_window.c:plugin_exec: Opening file :date: %s\n", data); }
			switch_to_file_or_open(data, 0);
		}
		else if (g_strncasecmp(stdout, "DEBUG", MIN(strlen(stdout), 5))==0) {
			debug_dump_editors();
			DEBUG_MODE = TRUE;
		}
		
		g_free(stdout);

	}
	else {
		g_print(_("Spawning %s gave error %s\n"), plugin->filename->str, error->message);
	}
}
コード例 #9
0
ファイル: completion.c プロジェクト: svn2github/irssi
static void cmd_completion(const char *data)
{
	GHashTable *optlist;
	CONFIG_NODE *node;
	GSList *tmp;
	char *key, *value;
	void *free_arg;
	int len;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_GETREST,
			    "completion", &optlist, &key, &value))
		return;

	node = iconfig_node_traverse("completions", *value != '\0');
	if (node != NULL && node->type != NODE_TYPE_BLOCK) {
		/* FIXME: remove after 0.8.5 */
		iconfig_node_remove(mainconfig->mainnode, node);
		node = iconfig_node_traverse("completions", *value != '\0');
	}

	if (node == NULL || (node->value == NULL && *value == '\0')) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    TXT_NO_COMPLETIONS);
		cmd_params_free(free_arg);
		return;
	}

	if (g_hash_table_lookup(optlist, "delete") != NULL && *key != '\0') {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    TXT_COMPLETION_REMOVED, key);

		iconfig_set_str("completions", key, NULL);
		signal_emit("completion removed", 1, key);
	} else if (*key != '\0' && *value != '\0') {
		int automatic = g_hash_table_lookup(optlist, "auto") != NULL;

		node = config_node_section(node, key, NODE_TYPE_BLOCK);
		iconfig_node_set_str(node, "value", value);
		if (automatic)
			iconfig_node_set_bool(node, "auto", TRUE);
		else
			iconfig_node_set_str(node, "auto", NULL);

		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
			    TXT_COMPLETION_LINE,
			    key, value, automatic ? "yes" : "no");

		signal_emit("completion added", 1, key);
	} else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
			    TXT_COMPLETION_HEADER);

		len = strlen(key);
		for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
			node = tmp->data;

			if (len == 0 ||
			    g_strncasecmp(node->key, key, len) == 0) {
				printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
					    TXT_COMPLETION_LINE, node->key,
					    config_node_get_str(node, "value", ""),
					    config_node_get_bool(node, "auto", FALSE) ? "yes" : "no");
			}
		}

		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
			    TXT_COMPLETION_FOOTER);
	}

	cmd_params_free(free_arg);
}
コード例 #10
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};
  NodeCounter counter = {0, 0};
  const guint m = 100;
  const guint n = 1000;

  Pt points[m*n];

  VsgPRTree3d *tree;
  gint i;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_init_gdouble ();

  /* create the tree */
  tree = vsg_prtree3d_new (&lb, &ub, NULL, 1);

  vsg_prtree3d_set_node_data (tree, TYPE_NODE_COUNTER, &counter);

  /* create the points */
  create_points (points, m, n);

  /* insert the points into the tree */
  for (i=0; i<m*n; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

/*    g_printerr ("ok depth = %d size = %d\n", */
/*                vsg_prtree3d_depth (tree), */
/*                vsg_prtree3d_point_count (tree)); */

  /* accumulate the point counts across the tree */
  vsg_prtree3d_traverse (tree, G_POST_ORDER, (VsgPRTree3dFunc) up, NULL);

  /* do some near/far traversal */
  vsg_prtree3d_near_far_traversal (tree, (VsgPRTree3dFarInteractionFunc) far,
                                   (VsgPRTree3dInteractionFunc) near,
                                   &ret);

  /*  distribute back the point counts across the tree */
  vsg_prtree3d_traverse (tree, G_PRE_ORDER, (VsgPRTree3dFunc) down, NULL);

  /* check the results */
  for (i=0; i<m*n; i++)
    {
      if (points[i].count != m*n)
        {
          g_printerr ("ERROR: wrong count on point %d: %d (should be %d).\n",
                      i, points[i].count, n);
          ret ++;
        }
    }

  /* remove the points */
  for (i=0; i<m*n; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}
コード例 #11
0
ファイル: mdmconfig.c プロジェクト: AlbertJP/mdm
/**
 * mdm_config_get_xservers
 *
 * Calls daemon to get xserver config.
 */
GSList *
mdm_config_get_xservers (gboolean flexible)
{
	GSList *xservers = NULL;
        gchar **splitstr, **sec;
	gchar *command = NULL;
	gchar *result  = NULL;
	gchar *temp;

	command = g_strdup_printf ("GET_SERVER_LIST");
	result = mdmcomm_call_mdm (command, NULL /* auth cookie */,
		"1.0.0.0", comm_tries);

	g_free (command);

	if (! result || ve_string_empty (result) ||
	    strncmp (result, "OK ", 3) != 0) {

		mdm_common_error ("Could not access xserver configuration");

		if (result)
			g_free (result);
		return NULL;
	}

	/* skip the "OK " */
	splitstr = g_strsplit (result + 3, ";", 0);
	sec      = splitstr;
	g_free (result);

	while (sec != NULL && *sec != NULL) {
		MdmXserver *svr = g_new0 (MdmXserver, 1);

		temp = mdm_config_get_xserver_details (*sec, "ID");
		if (temp == NULL) {
			g_free (svr);
			continue;
		}
		svr->id = temp;
		temp = mdm_config_get_xserver_details (*sec, "NAME");
		if (temp == NULL) {
			g_free (svr);
			continue;
		}
		svr->name = temp;
		temp = mdm_config_get_xserver_details (*sec, "COMMAND");
		if (temp == NULL) {
			g_free (svr);
			continue;
		}
		svr->command = temp;

		temp = mdm_config_get_xserver_details (*sec, "FLEXIBLE");
		if (temp == NULL) {
			g_free (svr);
			continue;
		} else if (g_strncasecmp (ve_sure_string (temp), "true", 4) == 0)
			svr->flexible = TRUE;
		else
			svr->flexible = FALSE;
		g_free (temp);

		temp = mdm_config_get_xserver_details (*sec, "CHOOSABLE");
		if (temp == NULL) {
			g_free (svr);
			continue;
		} else if (g_strncasecmp (temp, "true", 4) == 0)
			svr->choosable = TRUE;
		else
			svr->choosable = FALSE;
		g_free (temp);

		temp = mdm_config_get_xserver_details (*sec, "HANDLED");
		if (temp == NULL) {
			g_free (svr);
			continue;
		} else if (g_strncasecmp (temp, "true", 4) == 0)
			svr->handled = TRUE;
		else
			svr->handled = FALSE;
		g_free (temp);

		temp = mdm_config_get_xserver_details (*sec, "CHOOSER");
		if (temp == NULL) {
			g_free (svr);
			continue;
		} else if (g_strncasecmp (temp, "true", 4) == 0)
			svr->chooser = TRUE;
		else
			svr->chooser = FALSE;
		g_free (temp);

		temp = mdm_config_get_xserver_details (*sec, "PRIORITY");
		if (temp == NULL) {
			g_free (svr);
			continue;
		} else {
			svr->priority = atoi (temp);
		}
		g_free (temp);

		sec++;

		/* If only flexible was requested, then skip if not flexible */
		if (flexible && !svr->flexible) {
			g_free (svr);
			continue;
		}

		xservers = g_slist_append (xservers, svr);
	}

	g_strfreev (splitstr);
	return xservers;
}
コード例 #12
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};

  VsgVector3d *points;
  gint lvl = 1;
  gint n, np;

  VsgPRTree3d *tree;
  gint i, j, k, l;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  if (argc > 1)
    {
      sscanf (argv[1], "%d", &lvl);
    }

  n = 1<<lvl;
  np = n*n*n;

  vsg_init_gdouble ();

  /* create the points */
  points = g_malloc (np * sizeof (VsgVector3d));
  l = 0;
  for (i=0; i<n; i++)
    {
      gdouble x = 2. * ((i+0.5)/n) - 1.;

      for (j=0; j<n; j++)
        {
          gdouble y = 2. * ((j+0.5)/n) - 1.;

          for (k=0; k<n; k++)
            {
              gdouble z = 2. * ((k+0.5)/n) - 1.;

              vsg_vector3d_set (&points[l], x, y, z);
              l ++;
            }
        }
    }

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           NULL, 1);

  /* configure for hilbert curve order traversal */
  vsg_prtree3d_set_children_order (tree, hilbert3_order,
                                   GINT_TO_POINTER (HK3_0_2_1));

  /* insert some points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

  /* do some traversal */
  i=0;
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) traverse_point_count, &i);

  /* check the results */
  if (i != np)
    {
      g_printerr ("ERROR: traverse point count %d (should be %d)\n",
                  i, n);

      ret ++;
    }

  /* remove the points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  g_free (points);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}
コード例 #13
0
ファイル: fe-settings.c プロジェクト: svn2github/irssi
static void settings_save_confirm(const char *line, char *fname)
{
    if (g_strncasecmp(line, _("Y"), 1) == 0)
        settings_save_fe(fname);
    g_free(fname);
}
コード例 #14
0
ファイル: sasl.c プロジェクト: AlD/bitlbee
/* Non-static function, but not mentioned in jabber.h because it's for internal
   use, just that the unittest should be able to reach it... */
char *sasl_get_part( char *data, char *field )
{
	int i, len;
	
	len = strlen( field );
	
	while( isspace( *data ) || *data == ',' )
		data ++;
	
	if( g_strncasecmp( data, field, len ) == 0 && data[len] == '=' )
	{
		i = strlen( field ) + 1;
	}
	else
	{
		for( i = 0; data[i]; i ++ )
		{
			/* If we have a ", skip until it's closed again. */
			if( data[i] == '"' )
			{
				i ++;
				while( data[i] != '"' || data[i-1] == '\\' )
					i ++;
			}
			
			/* If we got a comma, we got a new field. Check it,
			   find the next key after it. */
			if( data[i] == ',' )
			{
				while( isspace( data[i] ) || data[i] == ',' )
					i ++;
				
				if( g_strncasecmp( data + i, field, len ) == 0 &&
				    data[i+len] == '=' )
				{
					i += len + 1;
					break;
				}
			}
		}
	}
	
	if( data[i] == '"' )
	{
		int j;
		char *ret;
		
		i ++;
		len = 0;
		while( data[i+len] != '"' || data[i+len-1] == '\\' )
			len ++;
		
		ret = g_strndup( data + i, len );
		for( i = j = 0; ret[i]; i ++ )
		{
			if( ret[i] == '\\' )
			{
				ret[j++] = ret[++i];
			}
			else
			{
				ret[j++] = ret[i];
			}
		}
		ret[j] = 0;
		
		return ret;
	}
	else if( data[i] )
	{
		len = 0;
		while( data[i+len] && data[i+len] != ',' )
			len ++;
		
		return g_strndup( data + i, len );
	}
	else
	{
		return NULL;
	}
}
コード例 #15
0
ファイル: xgnokii_cfg.c プロジェクト: pkot/gnokii
void GUI_ReadXConfig()
{
	FILE *file;
	gchar *line;
	const gchar *confdir;
	gchar *rcfile;
	gchar *current;
	register gint len;
	register gint i;

	GetDefaultValues();

#ifdef WIN32
	confdir = g_strconcat(getenv("APPDATA"), "\\gnokii", NULL);
	if (!g_file_test(confdir, G_FILE_TEST_IS_DIR))
		g_mkdir_with_parents(confdir, 0700);
	rcfile = g_strconcat(config, "\\xgnokii-config", NULL);
#else
	confdir = g_strconcat(g_get_user_config_dir(), "/gnokii", NULL);
	if (!g_file_test(confdir, G_FILE_TEST_IS_DIR))
		g_mkdir_with_parents(confdir, 0700);
	rcfile = g_strconcat(confdir, "/xgnokii-config", NULL);
#endif

	if ((file = fopen(rcfile, "r")) == NULL) {
		g_free(rcfile);
		return;
	}

	g_free(rcfile);

	line = g_malloc(255);

	while (fgets(line, 255, file) != NULL) {
		gint v;
		current = line;

		/* Strip leading, trailing whitespace */
		while (isspace((gint) * current))
			current++;

		while ((strlen(current) > 0) && isspace((gint) current[strlen(current) - 1]))
			current[strlen(current) - 1] = '\0';

		/* Ignore blank lines and comments */

		if ((*current == '\n') || (*current == '\0') || (*current == '#'))
			continue;

		i = 0;
		while (*config[i].key != '\0') {
			len = strlen(config[i].key);
			if (g_strncasecmp(config[i].key, current, len) == 0) {
				current += len;
				while (isspace((int) *current))
					current++;
				if (*current == '=') {
					current++;
					while (isspace((int) *current))
						current++;
					g_free(*config[i].value);
					switch (i) {
					case 3:
					case 4:
						*config[i].value =
						    g_strndup(current, max_phonebook_number_length);
						break;

					case 7:
						*config[i].value =
						    g_strndup(current, HTMLVIEWER_LENGTH);
						break;

					case 8:
						*config[i].value =
						    g_strndup(current, MAILBOX_LENGTH);
						break;

					case 9:
					case 10:
						v = atoi(current);
						if (v > 0 && v < 100)
							*config[i].value = g_strndup(current, 3);
						break;

					default:
						*config[i].value =
						    g_strndup(current, MAX_BUSINESS_CARD_LENGTH);
						break;
					}
				}
			}
			i++;
		}
	}

	fclose(file);
	g_free(line);
}
コード例 #16
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};

  VsgVector3d points[] = {
    {-0.5, -0.5, -.5},
    {0.5, -0.5, -.5},
    {-0.5, 0.5, .5},
    {0.25, 0.25, .5},
    {0.75, 0.75, .5},
    {1.75, 1.75, 1.}, /* exterior point */
    {1.75, 100.75, 1.}, /* another exterior point */
    {1.75, -100.75, 1.}, /* another exterior point */
  };

  const guint n = sizeof (points) / sizeof (VsgVector3d);

  VsgPRTree3d *tree;
  VsgPRTree3d *tree_clone;
  gint i;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_init_gdouble ();

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           NULL, 1);

  /* insert some points */
  for (i=0; i<n; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

  /* clone the tree and destroy it */
  tree_clone = vsg_prtree3d_clone (tree);
  vsg_prtree3d_free (tree);

  /* do some traversal */
  i=0;
  vsg_prtree3d_traverse (tree_clone, G_PRE_ORDER,
                         (VsgPRTree3dFunc) traverse_point_count, &i);

  /* check the results */
  if (i != n)
    {
      g_printerr ("ERROR: traverse point count %d (should be %d)\n",
                  i, n);

      ret ++;
    }

  /* remove the points */
  for (i=0; i<n; i++)
    {
      vsg_prtree3d_remove_point (tree_clone, &points[i]);
    }

  /* destroy the cloned tree */
  vsg_prtree3d_free (tree_clone);

  return ret;
}