Пример #1
0
int number_toInteger(const char *str) {
	assert(str != 0);
	assert(strlen(str) > 0);

	BOOL min = FALSE;
	unsigned int idx = 0;
	int res = 0;
	int old = 0;

	if (str[0] == '-') {
		min = TRUE;
		++idx;
	}

	for (; idx < strlen(str); ++idx) {
        if (!isdigit(str[idx]))                 /* valid */
			message_error("invalid format");
		res *= 10;
        res += str[idx] - '0';                  /* ASCII */
		if (res < old)                          /* overflow */
			message_error("integer overflow");
		old = res;
	}

	if (min) {
		old = res;
		res *= -1;                              /* add sign */
		if (res > old)
			message_error("integer overflow");
	}

	return res;
}
Пример #2
0
void showValue(const char *name, unsigned long value, unit_t unit) {
		/* find the best unit */
		if (unit == a) {
			long long tsize = value;
			unit = b;
			while (tsize > 1024) {
				tsize /= 1024;
				++unit;
			}
		}
        double dsize = (double)value;           /* bytes */
		switch(unit) {
			case y:
				dsize /= 1024.0;
			case z:
				dsize /= 1024.0;
			case e:
				dsize /= 1024.0;
			case p:
				dsize /= 1024.0;
			case t:
				dsize /= 1024.0;
			case g:
				dsize /= 1024.0;
			case m:
				dsize /= 1024.0;
			case k:
				dsize /= 1024.0;
			case b:
				break;
			default:
				message_error("invalid unit");
		}

		if (strlen(name) > 14) {
			message_error("invalid size of string");
		}
		char *tmp = (char *)malloc(16 + 1);
		strcpy(tmp, name);
		strcat(tmp, ":");
		memset(tmp + strlen(tmp), ' ', 16 - strlen(tmp));
		tmp[16] = '\0';

//		dsize = (double)bsize/1000000000.0;
		printf("%s%.3f ", tmp, dsize);
		if (unit > b)
			printf("%c", unit_n[unit - 2]);

		printf("Byte");

		if (dsize != 1.0 && dsize != 0.0)
			printf ( "s" );

		printf("\n");

		free(tmp);
}
static int
cmd_cmdline(globalstate *gstate)

{
    if (gstate->statics->flags.fullcmds)
    {
	gstate->pselect.fullcmd = !gstate->pselect.fullcmd;
	message_error(" %sisplaying full command lines.",
		      gstate->pselect.fullcmd ? "D" : "Not d");
	return CMD_REFRESH;
    }
    message_error(" Full command display not supported.");
    return CMD_OK;
}
Пример #4
0
/** Return the value of a rectangle-type data node.
 * @param data The data node to read from.
 * @param rect A place to store the resulting values.  If the node does
 *  not contain a valid rectangle value, an error message is displayed to the
 *  user, and `rect' is unchanged.
 */
void
data_rectangle(DataNode data, Rectangle *rect)
{
  xmlChar *val;
  gchar *str;

  if (data_type(data)!=DATATYPE_RECTANGLE) {
    message_error("Taking rectangle value of non-rectangle node.");
    return;
  }

  val = xmlGetProp(data, (const xmlChar *)"val");

  rect->left = g_ascii_strtod((char *)val, &str);

  while ((*str != ',') && (*str!=0))
    str++;

  if (*str==0){
    message_error("Error parsing rectangle.");
    xmlFree(val);
    return;
  }

  rect->top = g_ascii_strtod(str+1, &str);

  while ((*str != ';') && (*str!=0))
    str++;

  if (*str==0){
    message_error("Error parsing rectangle.");
    xmlFree(val);
    return;
  }

  rect->right = g_ascii_strtod(str+1, &str);

  while ((*str != ',') && (*str!=0))
    str++;

  if (*str==0){
    message_error("Error parsing rectangle.");
    xmlFree(val);
    return;
  }

  rect->bottom = g_ascii_strtod(str+1, NULL);

  xmlFree(val);
}
static int
cmd_order_x(globalstate *gstate, const char *name, ...)

{
    va_list ap;
    char *p;
    const char **names;
    int i;

    names = gstate->statics->order_names;
    if (names != NULL)
    {
	if ((i = string_index(name, names)) == -1)
	{
	    /* check the alternate list */
	    va_start(ap, name);
	    p = va_arg(ap, char *);
	    while (p != NULL)
	    {
		if ((i = string_index(p, names)) != -1)
		{
		    gstate->order_index = i;
		    return CMD_REFRESH;
		}
		p = va_arg(ap, char *);
	    }
	    message_error(" Sort order not recognized");
	}
	else
	{
static int
cmd_order(globalstate *gstate)

{
    char tmpbuf[MAX_COLS];
    int i;

    if (gstate->statics->order_names != NULL)
    {
	message_prompt("Column to sort: ");
	if (readline(tmpbuf, sizeof(tmpbuf), No) > 0)
	{
	    if ((i = string_index(tmpbuf, gstate->statics->order_names)) == -1)
	    {
		message_error(" Sort order \"%s\" not recognized", tmpbuf);
	    }
	    else
	    {
		gstate->order_index = i;
		return CMD_REFRESH;
	    }
	}
    }
    return CMD_OK;
}
static int
cmd_number(globalstate *gstate)

{
    int newval;
    char tmpbuf[20];

    message_prompt("Number of processes to show: ");
    newval = readline(tmpbuf, 8, Yes);
    if (newval > -1)
    {
	if (newval > gstate->max_topn)
	{
	    message_error(" This terminal can only display %d processes",
			  gstate->max_topn);
	}

	if (newval == 0)
	{
	    /* inhibit the header */
	    display_header(No);
	}

	else if (gstate->topn == 0)
	{
	    display_header(Yes);
	}

	gstate->topn = newval;
    }
    return CMD_REFRESH;
}
Пример #8
0
HashItem *construct_preset(char const *setkey, char *rest)
{
    char *key;
    HashItem *mapItem;

    if (!(key = string_firstword(&rest)))               /* get the key      */
    {                                                   /* e.g., title      */
        message_error("`preset ...: missing key");
        return 0;
    }

    if (strcmp(key, "nohtmlfive") == 0)
        global.d_html5 = 0;
    else
    {
        if (!*string_strip(&rest))                      /* get the value    */
            warning("Empty value of symbol `%s'", key); /* e.g., This is... */
    
        if (strcmp(key, "styleopt") == 0)               /* store styleopts  */
            lines_add(&global.d_styleopt, rest);
        else
        {                                                   
                                                        /* look up the key  */
            mapItem = hashmap_find(&global.d_symbol, key, ANY); 
    
            if (mapItem != PFAILED)                     /* reassign         */
                hashitem_set(mapItem, rest, free);      /* existing value   */
            else                                        /* or insert new    */
                hashmap_insert(&global.d_symbol,        /* element          */
                    hashitem_construct(VOIDPTR, key, new_str(rest), free));
        }
    }
    free(key);
    return hashitem_construct(VOIDPTR, "", 0, root_nop);
}
Пример #9
0
PROCESS *process_new() {
	PROCESS *self = (PROCESS*) malloc(sizeof(PROCESS));
	if (!self) {
		message_error("unable to get memory");
	}
	
	self->id = 0;
	self->wait = TRUE;
	self->dir_work = NULL;
	self->dir_temp = directory_temp();
	self->name = process_createName();
	self->status = PROCESS_STATUS_NONE;
	self->exit = -1;

	size_t dir_len = strlen(self->dir_temp);
	size_t name_len = strlen(self->name);

	self->file_input = (char *)malloc(dir_len + 1 + name_len + 1 + 2 + 1);
	sprintf(self->file_input, "%s%c%s.in", self->dir_temp, DIRECTORY_SEPARATOR_CHAR, self->name);
	unlink(self->file_input);

	self->file_output = (char *)malloc(dir_len + 1 + name_len + 1 + 3 + 1);
	sprintf(self->file_output, "%s%c%s.out", self->dir_temp, DIRECTORY_SEPARATOR_CHAR, self->name);
	unlink(self->file_output);

	self->file_error = (char *)malloc(dir_len + 1 + name_len + 1 + 3 + 1);
	sprintf(self->file_error, "%s%c%s.err", self->dir_temp, DIRECTORY_SEPARATOR_CHAR, self->name);
	unlink(self->file_error);

	return self;
}
Пример #10
0
void config_open(const char *filename) {
	if (!file_exists(filename))
		config_save(filename);

	STRINGBUFFER *cmd = stringbuffer_new();
#ifdef SYSTEM_OS_TYPE_WINDOW
	stringbuffer_append(cmd, "notepad.exe");
#else
	if (file_exists("/usr/bin/vim"))
		stringbuffer_append(cmd, "/usr/bin/vim");
	else if (file_exists("/usr/bin/emacs"))
		stringbuffer_append(cmd, "/usr/bin/emacs");
	else if (file_exists("/usr/bin/nano"))
		stringbuffer_append(cmd, "/usr/bin/nano");
	else if (file_exists("/bin/vi"))
		stringbuffer_append(cmd, "/bin/vi");
	else
		message_error("no editor found");
#endif
	stringbuffer_append(cmd, " ");
	stringbuffer_append(cmd, filename);

	system(stringbuffer_getTextPointer(cmd));

	stringbuffer_free(cmd);

	config_load(filename);
}
Пример #11
0
static void
set_linejoin(DiaRenderer *self, LineJoin mode)
{
    WmfRenderer *renderer = WMF_RENDERER (self);

    DIAG_NOTE(renderer, "set_join %d\n", mode);

    if (!renderer->platform_is_nt)
      return;

    renderer->fnPenStyle &= ~(PS_JOIN_MASK);
    switch(mode) {
    case LINEJOIN_MITER:
      renderer->fnPenStyle |= PS_JOIN_MITER;
      break;
    case LINEJOIN_ROUND:
      renderer->fnPenStyle |= PS_JOIN_ROUND;
      break;
    case LINEJOIN_BEVEL:
      renderer->fnPenStyle |= PS_JOIN_BEVEL;
      break;
    default:
      message_error("WmfRenderer : Unsupported fill mode specified!\n");
    }
}
Пример #12
0
HashItem *construct_label(char const *key, char *rest)
{
    HashItem *item;

    LabelInfo *li = new_memory(1, sizeof(LabelInfo));
    li->d_section = lines_size(&global.d_section) - 1;
    li->d_filenr = global.d_filecount;

    if (!*rest)
    {
        message_error("Missing label name");
        return 0;
    }

    item =  hashitem_construct(VOIDPTR, rest, li, free);

    if (hashmap_insert(&symtab, item) == FAILED)
    {
        message_show(MSG_ERR);
        message("%s: %s doubly defined", args_programName(), key);
        return 0;
    }

    return hashitem_construct(VOIDPTR, rest, 0, root_nop);
}
Пример #13
0
/** Get the type of a data node.
 * @param data The data node.
 * @return The type that the data node defines, or 0 on error.  In case of
 *  error, an error message is displayed.
 * @note This function does a number of strcmp calls, which may not be the
 *  fastest way to check if a node is of the expected type.
 * @bug Make functions that check quickly if a node is of a specific type
 *  (but profile first).
 */
DataType
data_type(DataNode data)
{
  const char *name;

  name = data ? (const char *)data->name : (const char *)"";
  if (strcmp(name, "composite")==0) {
    return DATATYPE_COMPOSITE;
  } else if (strcmp(name, "int")==0) {
    return DATATYPE_INT;
  } else if (strcmp(name, "enum")==0) {
    return DATATYPE_ENUM;
  } else if (strcmp(name, "real")==0) {
    return DATATYPE_REAL;
  } else if (strcmp(name, "boolean")==0) {
    return DATATYPE_BOOLEAN;
  } else if (strcmp(name, "color")==0) {
    return DATATYPE_COLOR;
  } else if (strcmp(name, "point")==0) {
    return DATATYPE_POINT;
  } else if (strcmp(name, "rectangle")==0) {
    return DATATYPE_RECTANGLE;
  } else if (strcmp(name, "string")==0) {
    return DATATYPE_STRING;
  } else if (strcmp(name, "font")==0) {
    return DATATYPE_FONT;
  } else if (strcmp(name, "bezpoint")==0) {
    return DATATYPE_BEZPOINT;
  } else if (strcmp(name, "dict")==0) {
    return DATATYPE_DICT;
  }

  message_error("Unknown type of DataNode");
  return 0;
}
Пример #14
0
/** Return the value of a color-type data node.
 * @param data The XML node to read from
 * @param col A place to store the resulting RGB values.  If the node does
 *  not contain a valid color value, an error message is displayed to the
 *  user, and `col' is unchanged.
 * @note Could be cool to use RGBA data here, even if we can't display it yet.
 */
void
data_color(DataNode data, Color *col)
{
  xmlChar *val;
  int r=0, g=0, b=0;

  if (data_type(data)!=DATATYPE_COLOR) {
    message_error("Taking color value of non-color node.");
    return;
  }

  val = xmlGetProp(data, (const xmlChar *)"val");

  /* Format #RRGGBB */
  /*        0123456 */

  if ((val) && (xmlStrlen(val)>=7)) {
    r = hex_digit(val[1])*16 + hex_digit(val[2]);
    g = hex_digit(val[3])*16 + hex_digit(val[4]);
    b = hex_digit(val[5])*16 + hex_digit(val[6]);
  }

  if (val) xmlFree(val);

  col->red = (float)(r/255.0);
  col->green = (float)(g/255.0);
  col->blue = (float)(b/255.0);
}
Пример #15
0
DiaObject *
create_standard_ellipse(real xpos, real ypos, real width, real height) {
    DiaObjectType *otype = object_get_type("Standard - Ellipse");
    DiaObject *new_obj;
    Handle *h1, *h2;
    
    GPtrArray *props;
    Point point;

    if (otype == NULL){
	message_error(_("Can't find standard object"));
	return NULL;
    }

    point.x = xpos;
    point.y = ypos;

    new_obj = otype->ops->create(&point, otype->default_user_data,
				 &h1, &h2);
  
    props = make_element_props(xpos,ypos,width,height);
    new_obj->ops->set_props(new_obj, props);
    prop_list_free(props);

    return new_obj;
}
Пример #16
0
DiaObject *
create_standard_bezierline(int num_points, 
			   BezPoint *points,
			   Arrow *end_arrow,
			   Arrow *start_arrow) {
    DiaObjectType *otype = object_get_type("Standard - BezierLine");
    DiaObject *new_obj;
    Handle *h1, *h2;
    BezierCreateData bcd;
    GPtrArray *props;

    if (otype == NULL){
	message_error(_("Can't find standard object"));
	return NULL;
    }

    bcd.num_points = num_points;
    bcd.points = points;

    new_obj = otype->ops->create(NULL, &bcd, &h1, &h2);

    props = prop_list_from_descs(create_line_prop_descs,pdtpp_true);
    g_assert(props->len == 2);
    
    if (start_arrow != NULL)
	((ArrowProperty *)g_ptr_array_index(props, 0))->arrow_data = *start_arrow;
    if (end_arrow != NULL)
	((ArrowProperty *)g_ptr_array_index(props, 1))->arrow_data = *end_arrow;

    new_obj->ops->set_props(new_obj, props);
    prop_list_free(props);
    
    return new_obj;
}
Пример #17
0
/** Reusable variant of pixbuf to base64 string conversion
 */
gchar *
pixbuf_encode_base64 (const GdkPixbuf *pixbuf, const char *prefix)
{
  GError *error = NULL;
  EncodeData ed = { 0, };
  const gchar *type = _make_pixbuf_type_name (prefix);
  ed.array = g_byte_array_new ();

  if (prefix) {
    ed.size = strlen (prefix);
    g_byte_array_append (ed.array, (guint8 *)prefix, ed.size);
  }
  if (!gdk_pixbuf_save_to_callback ((GdkPixbuf *)pixbuf, _pixbuf_encode, &ed, type, &error, NULL)) {
    message_error (_("Saving inline pixbuf failed:\n%s"), error->message);
    g_error_free (error);
    return NULL;
  }
  /* g_base64_encode_close ... [needs] up to 5 bytes if line-breaking is enabled */
  /* also make the array 0-terminated */
  g_byte_array_append (ed.array, (guint8 *)"\0\0\0\0\0", 6);
  ed.size += g_base64_encode_close (FALSE, (gchar *)&ed.array->data[ed.size],
				    &ed.state, &ed.save);
  ed.array->data[ed.size] = '\0';

  return (gchar *)g_byte_array_free (ed.array, FALSE);
}
Пример #18
0
/*
 * A little helper to dump pythons last error info either to file only or 
 * additional popup a message_error
 */
void 
_pyerror_report_last (gboolean popup, const char* fn, const char* file, int line)
{
  PyObject *exc, *v, *tb, *ef;
  char* sLoc;

  if (strlen(fn) > 0)
    sLoc = g_strdup_printf ("PyDia Error (%s):\n", fn); /* GNU_PRETTY_FUNCTION is enough */
  else
    sLoc = g_strdup_printf ("PyDia Error (%s:%d):\n", file, line);

  PyErr_Fetch (&exc, &v, &tb);
  PyErr_NormalizeException(&exc, &v, &tb);

  ef = PyDiaError_New(sLoc, popup ? FALSE : TRUE);
  PyFile_WriteObject (exc, ef, 0);
  PyFile_WriteObject (v, ef, 0);
  PyTraceBack_Print(tb, ef);
  if (((PyDiaError*)ef)->str && popup) 
    message_error ("%s", ((PyDiaError*)ef)->str->str);
  g_free (sLoc);
  Py_DECREF (ef);
  Py_XDECREF(exc);
  Py_XDECREF(v);
  Py_XDECREF(tb);
}
Пример #19
0
static void
set_linecaps(DiaRenderer *self, LineCaps mode)
{
    WmfRenderer *renderer = WMF_RENDERER (self);

    DIAG_NOTE(renderer, "set_linecaps %d\n", mode);
	
    // all the advanced line rendering is unsupported on win9x
    if (!renderer->platform_is_nt)
      return;

    renderer->fnPenStyle &= ~(PS_ENDCAP_MASK);
    switch(mode) {
    case LINECAPS_BUTT:
      renderer->fnPenStyle |= PS_ENDCAP_FLAT;
      break;
    case LINECAPS_ROUND:
      renderer->fnPenStyle |= PS_ENDCAP_ROUND;
      break;
    case LINECAPS_PROJECTING:
      renderer->fnPenStyle |= PS_ENDCAP_SQUARE;
      break;
    default:
	message_error("WmfRenderer : Unsupported fill mode specified!\n");
    }
}
Пример #20
0
/** Return the value of a font-type data node.  This handles both the current
 * format (family and style) and the old format (name).
 * @param data The data node to read from.
 * @return The font value found in the node.  If the node is not a
 *  font node, an error message is displayed and NULL is returned.  The
 *  resulting value should be freed after use.
 */
DiaFont *
data_font(DataNode data)
{
  xmlChar *family;
  DiaFont *font;

  if (data_type(data)!=DATATYPE_FONT) {
    message_error("Taking font value of non-font node.");
    return NULL;
  }

  family = xmlGetProp(data, (const xmlChar *)"family");
  /* always prefer the new format */
  if (family) {
    DiaFontStyle style;
    char* style_name = (char *) xmlGetProp(data, (const xmlChar *)"style");
    style = style_name ? atoi(style_name) : 0;

    font = dia_font_new ((char *)family, style, 1.0);
    if (family) free(family);
    if (style_name) xmlFree(style_name);
  } else {
    /* Legacy format support */
    char *name = (char *)xmlGetProp(data, (const xmlChar *)"name");
    font = dia_font_new_from_legacy_name(name);
    free(name);
  }
  return font;
}
Пример #21
0
void context_lua_t::response_tcp_closing(message_t& response)
{
	if (message_error(response) == NL_ETCPLCLOSED) { /* listen socket */
		lua_tcp_listen_handle_t::wakeup_accept(m_lstate, response);
	} else {
		lua_tcp_socket_handle_t::wakeup_read(m_lstate, response);
	}
}
static int
cmd_idle(globalstate *gstate)

{
    gstate->pselect.idle = !gstate->pselect.idle;
    message_error(" %sisplaying idle processes.",
		  gstate->pselect.idle ? "D" : "Not d");
    return CMD_REFRESH;
}
Пример #23
0
static void
set_fillstyle(DiaRenderer *self, FillStyle mode)
{
  switch(mode) {
  case FILLSTYLE_SOLID:
    break;
  default:
    message_error("svg_renderer: Unsupported fill mode specified!\n");
  }
}
Пример #24
0
HashItem *construct_tocentry(char const *key, char *rest)
{
    size_t level;
    char *section = string_firstword(&rest);

    if (!section)
    {
        message_error("incomplete tocentry");
        return 0;
    }
    string_strip(&rest);
                                                /* find the section's index */
    level = lines_find(section, section_levels, sizeofSectionLevels);

    if (level == UFAILED)                       /* no section given is err. */
    {
        message_error("unknown toc-section `%s'", section);
        free(section);
        return 0;
    }

    free(section);
                                            /* write <dd><dl> for deeper
                                               levels */
    for (; level > global.d_toclevel; ++global.d_toclevel)
        lines_add(&global.d_toc, "<dd><dl>");

                                            /* write </dl></dd> when returning
                                               to shallower levels */
    for (; level < global.d_toclevel; --global.d_toclevel)
        lines_add(&global.d_toc, "</dl></dd>");

                                            /* add a new entry              */
    lines_format(&global.d_toc,
                    "<dt>%s<a href=\"%s#l%u\">%s</a>%s</dt>",
                        toc_section[global.d_doctype][level][0],
                        string_str(&global.d_outName),
                        (unsigned)++s_lastLabelNr,
                        rest,
                        toc_section[global.d_doctype][level][1]);

    return hashitem_construct(VOIDPTR, "", (void *)s_lastLabelNr, root_nop);
}
Пример #25
0
extern bool
is_empty_filename(const char *filename)
{
	if (filename[0] == '\0') {
		message_error(_("Empty filename, skipping"));
		return true;
	}

	return false;
}
Пример #26
0
void diagram_group_selected(Diagram *dia)
{
  GList *list;
  GList *group_list;
  DiaObject *group;
  DiaObject *obj;
  GList *orig_list;
  Change *change;

  if (g_list_length(dia->data->selected) < 1) {
    message_error(_("Trying to group with no selected objects."));
    return;
  }
  
#if 0
  /* the following is wrong as it screws up the selected list, see bug #153525
     * I just don't get what was originally intented so please speak up if you know  --hb
     */    
  dia->data->selected = parent_list_affected(dia->data->selected);
#endif
    
  orig_list = g_list_copy(dia->data->active_layer->objects);
  
  /* We have to rebuild the selection list so that it is the same
     order as in the Diagram list. */
  group_list = diagram_get_sorted_selected_remove(dia);
  
  list = group_list;
  while (list != NULL) {
    obj = (DiaObject *)list->data;

    /* Remove connections from obj to objects outside created group. */
    /* strip_connections sets up its own undo info. */
    /* The connections aren't reattached by ungroup. */
    strip_connections(obj, dia->data->selected, dia);
    
    list = g_list_next(list);
  }

  /* Remove list of selected objects */
  textedit_remove_focus_all(dia);
  data_remove_all_selected(dia->data);
  
  group = group_create(group_list);
  change = undo_group_objects(dia, group_list, group, orig_list);
  (change->apply)(change, dia);

  /* Select the created group */
  diagram_select(dia, group);
  
  diagram_modified(dia);
  diagram_flush(dia);
  
  undo_set_transactionpoint(dia->undo);
}
Пример #27
0
/// \brief      Removes the filename suffix of the compressed file
///
/// \return     Name of the uncompressed file, or NULL if file has unknown
///             suffix.
static char *
uncompressed_name(const char *src_name, const size_t src_len)
{
	static const struct {
		const char *compressed;
		const char *uncompressed;
	} suffixes[] = {
		{ ".xz",    "" },
		{ ".txz",   ".tar" }, // .txz abbreviation for .txt.gz is rare.
		{ ".lzma",  "" },
		{ ".tlz",   ".tar" },
		// { ".gz",    "" },
		// { ".tgz",   ".tar" },
	};

	const char *new_suffix = "";
	size_t new_len = 0;

	if (opt_format == FORMAT_RAW) {
		// Don't check for known suffixes when --format=raw was used.
		if (custom_suffix == NULL) {
			message_error(_("%s: With --format=raw, "
					"--suffix=.SUF is required unless "
					"writing to stdout"), src_name);
			return NULL;
		}
	} else {
		for (size_t i = 0; i < ARRAY_SIZE(suffixes); ++i) {
			new_len = test_suffix(suffixes[i].compressed,
					src_name, src_len);
			if (new_len != 0) {
				new_suffix = suffixes[i].uncompressed;
				break;
			}
		}
	}

	if (new_len == 0 && custom_suffix != NULL)
		new_len = test_suffix(custom_suffix, src_name, src_len);

	if (new_len == 0) {
		message_warning(_("%s: Filename has an unknown suffix, "
				"skipping"), src_name);
		return NULL;
	}

	const size_t new_suffix_len = strlen(new_suffix);
	char *dest_name = xmalloc(new_len + new_suffix_len + 1);

	memcpy(dest_name, src_name, new_len);
	memcpy(dest_name + new_len, new_suffix, new_suffix_len);
	dest_name[new_len + new_suffix_len] = '\0';

	return dest_name;
}
Пример #28
0
extern bool
is_tty_stdout(void)
{
	const bool ret = isatty(STDOUT_FILENO);

	if (ret)
		message_error(_("Compressed data cannot be written to "
				"a terminal"));

	return ret;
}
Пример #29
0
extern bool
is_tty_stdin(void)
{
	const bool ret = isatty(STDIN_FILENO);

	if (ret)
		message_error(_("Compressed data cannot be read from "
				"a terminal"));

	return ret;
}
Пример #30
0
ARRAY *array_new() {
	ARRAY *self = (ARRAY*) malloc(sizeof(ARRAY));
	if (!self) {
		message_error("unable to get memory");
	}
	
	self->size = 0;
	self->array = NULL;

	return self;
}