static void
exec_cmd_proc (void *cls, const char *line)
{
  struct SysmonProperty *sp = cls;
  unsigned long long tmp;
  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property output: `%s'\n", line);
  if (NULL == line)
  {
      GNUNET_OS_command_stop (sp->cmd_exec_handle);
      sp->cmd_exec_handle = NULL;
      return;
  }

  switch (sp->value_type) {
    case v_numeric:
      if (1 != sscanf (line, "%llu", &tmp))
      {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Command output was not a numerical value: `%s'\n", line);
        return;
      }
      break;
    case v_string:
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NOT IMPLEMENTED\n");
      break;
    default:
      break;

  }
  sp->num_val = tmp;

  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property output: `%s'\n", line);
  put_property (sp);


}
static void
update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct SysmonProperty *sp = cls;
  sp->num_val ++;
  put_property (sp);
}
Exemple #3
0
static LISP lput_property(LISP bname, LISP key, LISP value)
{
	buffer *b;
	char *retval;

	if (NULLP(bname)) b = buffer_of_window(w_list);
	else b = find_buffer_by_name(get_c_string(bname));
	if (!b) {
		llpr("No such buffer");
		return NIL;
	}

	retval = put_property(b, get_c_string(key), get_c_string(value));
	if (retval) return strcons(strlen(retval), retval);
	return NIL;
}
static int
run_properties (void)
{
  struct SysmonProperty *sp;

  for (sp = sp_head; NULL != sp; sp = sp->next)
  {
      if (t_static == sp->type)
      {
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running static property `%s' \n", sp->desc);
          put_property (sp);
      }
      else
      {
          if (NULL == sp->task)
          {
            GNUNET_break (0);
            continue;
          }
          sp->task_id = GNUNET_SCHEDULER_add_now (&run_property, sp);
      }
  }
  return GNUNET_OK;
}
Exemple #5
0
static int load_flat(char *fn, buffer *buf)
{
	int i, j, intp;
	char *texti;
	FILE *fp;
	int *fmts = NULL;
	int nfmt = -1;
	char instring[256], *p, *coords, *contents, *comma;
	int sw = 80, sh = 20, sf = 0, f;
	int s = 0;
	int *styles = NULL;
	int nsty = 0;
	int n;
	MwFmt fmt;
	int lastph = -1;
	cval value;
	char *endp;
	int type;
	value.number = 0;

	if ((fp = fopen(fn, "r")) == NULL)
		return 1;

	for (s = 0; s < buf->nsht; s++) {
		for (i = line_last_used(buf, s); i > 0; i--) {
			for (j = col_last_changed(buf, s, i, sf); j > 0; j--) {
				ins_data(buf, siod_interpreter, NULL,
					value, EMPTY, s, i, j);
				ins_format(buf, s, i, j, sf);
			}
		}
	}

	buf->a1_refs = a1_refs;

	s = 0;	/* old files have no .sheet tags, so start at first sheet */
	while (fgets(instring, 250, fp) != NULL) {
		char b[1024];
		b[0] = '\0';	/* make sure we don't keep stuff between loops */

		/* strip off \r\n */
/*
   if ((p = strpbrk(instring, "\r\n")) != NULL) *p = '\0';
 */

		switch (instring[0]) {
		case '\0':
		case '#':
			break;
		case '.':
                        if (!strncmp(instring, ".margins ", 9)) {
                                sscanf(instring, ".margins %d %d %d %d %d %d",
                                       &(buf->top_margin),
                                       &(buf->bottom_margin),
                                       &(buf->left_margin),
                                       &(buf->right_margin),
                                       &(buf->header_margin),
                                       &(buf->footer_margin));
			} else if (!strncmp(instring, ".a1_refs ", 9)) {
				sscanf(instring, ".a1_refs %d",
					&(buf->a1_refs));
                        } else if (!strncmp(instring, ".paper ", 7)) {
                                sscanf(instring, ".paper %s %d %d %d",
                                       b,
                                       &(buf->paper_width),
                                       &(buf->paper_height),
                                       &(buf->orientation));
                                buf->paper_name = MwStrdup(b);
                        } else if (!strncmp(instring, ".header ", 8)) {
                                sscanf(instring, ".header %[^\n]", b);
                                buf->header = MwStrdup(b);
                        } else if (!strncmp(instring, ".footer ", 8)) {
                                sscanf(instring, ".footer %[^\n]", b);
                                buf->footer = MwStrdup(b);
                        } else if (!strncmp(instring, ".header_on_first ", 17)) {
                                sscanf(instring, ".header_on_first %d",
                                       &(buf->header_on_first));
                        } else if (!strncmp(instring, ".first_page ", 12)) {
                                sscanf(instring, ".first_page %d",
                                       &(buf->first_page_number));
                        } else if (!strncmp(instring, ".sw ", 4)) {
				sscanf(instring, ".sw %d", &sw);
				buf->sw = sw;
			} else if (!strncmp(instring, ".sh ", 4)) {
				sscanf(instring, ".sh %d", &sh);
				buf->sh = sh;
/* The old "standard format" used the .sf tag, which was bitmapped and
must no longer be used. Thus .nsf (new standard format)
*/
			} else if (!strncmp(instring, ".nsf ", 5)) {
				sscanf(instring, ".nsf %d", &sf);
				std_fmt_set(buf, sf);
			} else if (!strncmp(instring, ".cw ", 4)) {
				int w;
				sscanf(instring, ".cw %d %d", &i, &w);
				set_width(buf, s, i, w);
			} else if (!strncmp(instring, ".rh ", 4)) {
				int h;
				sscanf(instring, ".rh %d %d", &i, &h);
				set_height(buf, s, i, h);
			} else if (!strncmp(instring, ".ft", 3)) {
				sscanf(instring, ".ft%d", &n);
				if (n > nfmt) {
					nfmt = n;
					fmts = MwRealloc(fmts,
							(nfmt+1)*sizeof *fmts);
				}
				fmts[n] = MwLoadFormats(fp);
				/* now replace style with the real one */
				MwDecodeFormat(fmts[n], ~0, &fmt);
				/* Careful now. Some versions of Siag
				   produced bogus styles
				*/
				if (fmt.style < nsty
					&& styles[fmt.style] < nstyle) {
					fmt.style = styles[fmt.style];
					fmts[n] = MwEncodeFormat(~0, &fmt);
				} else {
					fmt.style = 0;
				}
			} else if (!strncmp(instring, ".style ", 7)) {
				int n;
				sscanf(instring, ".style %d", &n);
				if (n >= nsty) {
					nsty = n;
					styles = MwRealloc(styles,
							(nsty+1)*sizeof *styles);
				}
				styles[n] = load_styles(fp);
			} else if (!strncmp(instring, ".sheet ", 7)) {
				char name[1000];
				sscanf(instring, ".sheet %d %[^\n]", &s, name);
				if (s >= buf->nsht)
					buffer_add_sheet(buf, s);
				buffer_rename_sheet(buf, s, name);
			} else if (!strncmp(instring, ".fmt", 4)) {
				int h;
				char b[256];
				sscanf(instring, ".fmt%d %[^\n]", &h, b);
				h >>= MW_FMT_SHIFT;	/* 0 <= h <= 15 */
				lookup_style(style2name(h), b,
						style_table[h].type);
			} else if (!strncmp(instring, ".plugin-geometry ", 17)) {
				int n, width, height;
				n = sscanf(instring, ".plugin-geometry %d %d",
						&width, &height);
				if (lastph >= 0 && n >= 2) {
					plugin_size_set(lastph,
						width, height);
				}
			} else if (!strncmp(instring, ".plugin ", 8)) {
				int n;
				int row, col;
				char name[1024];
				plugin_t plugin;
				sscanf(instring, ".plugin %d %d %s",
					&row, &col, name);
				plugin.row = row;
				plugin.col = col;
				plugin.name = MwStrdup(name);
				p = file_name(buf, name);
				lastph = plugin.ph = plugin_start(p);
				MwFree(p);
				plugin.displayed = 0;
				if (plugin.ph != -1) {
					n = buf->sht[s].nplugin++;
					buf->sht[s].plugin = MwRealloc(buf->sht[s].plugin,
						buf->sht[s].nplugin*sizeof(plugin_t));
					buf->sht[s].plugin[n] = plugin;
				}
			} else if (!strncmp(instring, ".p", 2)) {
				int n;
				char key[256], *value;
				sscanf(instring, ".p%d %s", &n, key);
				value = MwMalloc(n+1);
				fread(value, n, 1, fp);
				value[n] = '\0';
				put_property(buf, key, value);
				MwFree(value);
			}
			break;
		default:	/* cell definition */
			if ((coords = strtok(instring, "\t")) == NULL)
				break;
			if ((contents = strtok((char *) 0, "\t\n\r")) == NULL)
				break;
			if ((p = strtok(coords, " ")) == NULL)
				break;
			i = atoi(p);
			if ((p = strtok(NULL, " ")) == NULL)
				break;
			j = atoi(p);
			if ((p = strtok(NULL, " ")) == NULL)
				break;
			f = atoi(p);
			if (nfmt == -1 || f > nfmt) {	/* old */
				f = MwFmtOldToNew(f);
			} else {
				f = fmts[f];
			}
			switch (contents[0]) {
			case '$':	/* string expression */
				if ((texti = (contents+1)) == 0)
					return 1;
				ins_data(buf, siod_interpreter, texti,
					value, STRING, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '=':	/* old style expression */
	/* Special case SIOD and C for backward compatibility. */
				if (contents[1] == '=') {	/* C */
					intp = C_interpreter;
					texti = (contents+2);
				} else {	/* SIOD */
					intp = siod_interpreter;
					texti = (contents+1);
				}
				value.number = strtod(texti, &endp);
				if (texti != endp && only_space(endp)) {
					type = CONSTANT;
				} else {
					type = EXPRESSION;
				}
				if (texti == 0) return 1;
				ins_data(buf, intp, texti,
					value, type, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '+':	/* new style expression */
				if ((comma = strchr(contents, ',')) == NULL)
					return 1;
				*comma = '\0';
				intp = name2interpreter(contents+1);
				if (intp < 0) return 1;
				if (intp == siod_interpreter &&
						comma[1] == '=') {
			/* C expression masquerading as SIOD */
					intp = C_interpreter;
					texti = (comma+2);
				} else {
					texti = (comma+1);
				}
				if (texti == 0) return 1;
				ins_data(buf, intp,
					texti, value, EXPRESSION, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '\"':	/* label */
				if ((texti = (contents + 1)) == 0)
					return 1;
				ins_data(buf, siod_interpreter, texti,
					value, LABEL, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case 'm':	/* embedded */
				if ((texti = (contents + 1)) == 0)
					return 1;
				embed_load(contents+1);
				ins_data(buf, siod_interpreter, texti,
					value, EMBED, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			default:	/* anything else means empty */
				ins_format(buf, s, i, j, f);
				break;
			}
			break;
		}