Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/dvi/mdvi-lib/common.c
diff options
context:
space:
mode:
authorNickolay V. Shmyrev <nshmyrev@yandex.ru>2005-04-07 15:28:06 (GMT)
committer Nickolay V. Shmyrev <nshmyrev@src.gnome.org>2005-04-07 15:28:06 (GMT)
commitc3e1500a4815225f08e1b20dd066559e8c92c280 (patch)
tree7474fe16fce807cda4845df116fec07c60b161e6 /dvi/mdvi-lib/common.c
parent52f67b9ce7a9f2282b2c85139d1d10f8c4df5786 (diff)
Recent files support.
2005-04-07 Nickolay V. Shmyrev <nshmyrev@yandex.ru> * cut-n-paste/recent-files/Makefile.am: * data/evince-ui.xml, shell/Makefile.am: * shell/ev-application.c, shell/ev-application.h: * shell/ev-window.c: Recent files support. * configure.ac: Added "ru" to ALL_LINGUAS. * dvju: new backend to support DJVU files. * dvi: new backend to support DVI. * configure.ac, Makefile.am, shell/Makefile.am, ev-window.c: * ev-application.c: Support for new backends. * help, ev-window.c, main.c shell/Makefile.am:
Diffstat (limited to 'dvi/mdvi-lib/common.c')
-rw-r--r--dvi/mdvi-lib/common.c187
1 files changed, 187 insertions, 0 deletions
diff --git a/dvi/mdvi-lib/common.c b/dvi/mdvi-lib/common.c
new file mode 100644
index 0000000..cf714eb
--- /dev/null
+++ b/dvi/mdvi-lib/common.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2000, Matias Atria
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "common.h"
+
+static Int32 scaled_width(Int32 fix, int scale);
+
+long fsgetn(FILE *p, size_t n)
+{
+ long v;
+
+ v = fgetbyte(p);
+ if(v & 0x80)
+ v -= 0x100;
+ while(--n > 0)
+ v = (v << 8) | fgetbyte(p);
+ return v;
+}
+
+Ulong fugetn(FILE *p, size_t n)
+{
+ Ulong v;
+
+ v = fgetbyte(p);
+ while(--n > 0)
+ v = (v << 8) | fgetbyte(p);
+ return v;
+}
+
+long msgetn(const Uchar *p, size_t n)
+{
+ long v = (long)*p++;
+
+ if(v & 0x80)
+ v -= 0x100;
+ while(--n > 0)
+ v = (v << 8) | *p++;
+ return v;
+}
+
+Ulong mugetn(const Uchar *p, size_t n)
+{
+ Ulong v = (Ulong)*p++;
+
+ while(--n > 0)
+ v = (v << 8) | *p++;
+ return v;
+}
+
+char *read_string(FILE *in, int s, char *buffer, size_t len)
+{
+ int n;
+ char *str;
+
+ n = fugetn(in, s ? s : 1);
+ if((str = buffer) == NULL || n + 1 > len)
+ str = xmalloc(n + 1);
+ if(fread(str, 1, n, in) != n) {
+ if(str != buffer) xfree(str);
+ return NULL;
+ }
+ str[n] = 0;
+ return str;
+}
+
+size_t read_bcpl(FILE *in, char *buffer, size_t maxlen, size_t wanted)
+{
+ size_t i;
+
+ i = (int)fuget1(in);
+ if(maxlen && i > maxlen)
+ i = maxlen;
+ if(fread(buffer, i, 1, in) != 1)
+ return -1;
+ buffer[i] = '\0';
+ while(wanted-- > i)
+ (void)fgetc(in);
+ return i;
+}
+
+char *read_alloc_bcpl(FILE *in, size_t maxlen, size_t *size)
+{
+ size_t i;
+ char *buffer;
+
+ i = (size_t)fuget1(in);
+ if(maxlen && i > maxlen)
+ i = maxlen;
+ buffer = (char *)malloc(i + 1);
+ if(buffer == NULL)
+ return NULL;
+ if(fread(buffer, i, 1, in) != 1) {
+ free(buffer);
+ return NULL;
+ }
+ buffer[i] = '\0';
+ if(size) *size = i;
+ return buffer;
+}
+
+/* stolen from dvips */
+static Int32 scaled_width(Int32 fix, int scale)
+{
+ Int32 al, bl;
+
+ if(fix < 0)
+ return -scaled_width(-fix, scale);
+ if(scale < 0)
+ return -scaled_width(fix, -scale);
+ al = fix & 32767;
+ bl = scale & 32767;
+ al >>= 15;
+ bl >>= 15;
+
+ return (((al*bl / 32768) + fix*bl + al*scale) / 32 +
+ fix * scale / 1024);
+}
+
+/* buffers */
+
+void buff_free(Buffer *buf)
+{
+ if(buf->data)
+ xfree(buf->data);
+ buff_init(buf);
+}
+
+void buff_init(Buffer *buf)
+{
+ buf->data = NULL;
+ buf->size = 0;
+ buf->length = 0;
+}
+
+size_t buff_add(Buffer *buf, const char *data, size_t len)
+{
+ if(!len && data)
+ len = strlen(data);
+ if(buf->length + len + 1 > buf->size) {
+ buf->size = buf->length + len + 256;
+ buf->data = xrealloc(buf->data, buf->size);
+ }
+ memcpy(buf->data + buf->length, data, len);
+ buf->length += len;
+ return buf->length;
+}
+
+char *buff_gets(Buffer *buf, size_t *length)
+{
+ char *ptr;
+ char *ret;
+ size_t len;
+
+ ptr = strchr(buf->data, '\n');
+ if(ptr == NULL)
+ return NULL;
+ ptr++; /* include newline */
+ len = ptr - buf->data;
+ ret = xmalloc(len + 1);
+ if(len > 0) {
+ memcpy(ret, buf->data, len);
+ memmove(buf->data, buf->data + len, buf->length - len);
+ buf->length -= len;
+ }
+ ret[len] = 0;
+ if(length) *length = len;
+ return ret;
+}
+