Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and CMake support #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(neatpost C)
set(FDIR "${CMAKE_INSTALL_PREFIX}/share/neatroff/font" CACHE PATH "Default font directory")
add_compile_definitions("TROFFFDIR=\"${FDIR}\"")
add_executable(post post.c ps.c font.c dev.c clr.c dict.c iset.c sbuf.c)
add_executable(pdf post.c pdf.c pdfext.c font.c dev.c clr.c dict.c iset.c sbuf.c)
install(TARGETS post pdf)
4 changes: 2 additions & 2 deletions clr.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ static int clrcomp(char *s, int len)

int clr_get(char *s)
{
int i;
size_t i;
if (s[0] == '#' && strlen(s) == 7)
return CLR_RGB(clrcomp(s + 1, 2), clrcomp(s + 3, 2), clrcomp(s + 5, 2));
if (s[0] == '#' && strlen(s) == 4)
return CLR_RGB(clrcomp(s + 1, 1), clrcomp(s + 2, 1), clrcomp(s + 3, 1));
if (isdigit(s[0]) && atoi(s) >= 0 && atoi(s) < LEN(colors))
if (isdigit(s[0]) && atoi(s) >= 0 && (size_t) atoi(s) < LEN(colors))
return colors[atoi(s)].value;
for (i = 0; i < LEN(colors); i++)
if (!strcmp(colors[i].name, s))
Expand Down
2 changes: 2 additions & 0 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void font_close(struct font *fn)
/* return width w for the given font and size */
int font_wid(struct font *fn, int sz, int w)
{
/* not used */
(void) fn;
return (w * sz + dev_uwid / 2) / dev_uwid;
}

Expand Down
30 changes: 27 additions & 3 deletions pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ static void obj_end(void)

void out(char *s, ...)
{
/* not used */
(void) s;
}

/* the length of the clear-text, encrypted, and fixed-content portions */
Expand Down Expand Up @@ -491,17 +493,23 @@ void outcolor(int c)

void outrotate(int deg)
{
/* not used */
(void) deg;
}

void outeps(char *eps, int hwid, int vwid)
{
/* not used */
(void) eps;
(void) hwid;
(void) vwid;
}

/* return a copy of a PDF object; returns a static buffer */
static char *pdf_copy(char *pdf, int len, int pos)
{
static char buf[1 << 12];
int datlen;
size_t datlen;
pos += pdf_ws(pdf, len, pos);
datlen = pdf_len(pdf, len, pos);
if (datlen > sizeof(buf) - 1)
Expand Down Expand Up @@ -590,7 +598,8 @@ static void pdf_rescopy(char *pdf, int len, int pos, struct sbuf *sb)
{
char *res_fields[] = {"/ProcSet", "/ExtGState", "/ColorSpace",
"/Pattern", "/Shading", "/Properties", "/Font", "/XObject"};
int res, i;
int res;
size_t i;
sbuf_printf(sb, " /Resources <<\n");
for (i = 0; i < LEN(res_fields); i++) {
if ((res = pdf_dval_val(pdf, len, pos, res_fields[i])) >= 0) {
Expand Down Expand Up @@ -638,7 +647,7 @@ static int pdfext(char *pdf, int len, int hwid, int vwid)
int dim[4];
int hzoom = 100, vzoom = 100;
struct sbuf *sb;
int i;
size_t i;
if (xobj_n == LEN(xobj))
return -1;
if ((trailer = pdf_trailer(pdf, len)) < 0)
Expand Down Expand Up @@ -863,6 +872,8 @@ void outmnt(int f)

void outgname(int g)
{
/* not used */
(void) g;
}

void drawbeg(void)
Expand Down Expand Up @@ -900,10 +911,14 @@ void drawend(int close, int fill)

void drawmbeg(char *s)
{
/* not used */
(void) s;
}

void drawmend(char *s)
{
/* not used */
(void) s;
}

void drawl(int h, int v)
Expand Down Expand Up @@ -965,6 +980,9 @@ void drawa(int h1, int v1, int h2, int v2)
/* draw an spline */
void draws(int h1, int v1, int h2, int v2)
{
/* not used */
(void) h2;
(void) v2;
outrel(h1, v1);
sbuf_printf(pg, "%s l\n", pdfpos(o_h, o_v));
}
Expand All @@ -987,6 +1005,8 @@ void doctrailer(int pages)
int i;
int xref_off;
int info_id;
/* not used */
(void) pages;
/* pdf pages object */
obj_beg(pdf_pages);
pdfout("<<\n");
Expand Down Expand Up @@ -1046,6 +1066,8 @@ void doctrailer(int pages)

void docpagebeg(int n)
{
/* not used */
(void) n;
pg = sbuf_make();
sbuf_printf(pg, "BT\n");
}
Expand All @@ -1054,6 +1076,8 @@ void docpageend(int n)
{
int cont_id;
int i;
/* not used */
(void) n;
o_flush();
sbuf_printf(pg, "ET\n");
/* page contents */
Expand Down
4 changes: 3 additions & 1 deletion pdfext.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int pdf_dval(char *pdf, int len, int pos, char *key)
pos += 2;
while (pos + 2 < len && (pdf[pos] != '>' || pdf[pos + 1] != '>')) {
pos += pdf_ws(pdf, len, pos);
if (pdf_len(pdf, len, pos) == strlen(key) && startswith(key, pdf + pos)) {
if ((size_t) pdf_len(pdf, len, pos) == strlen(key) && startswith(key, pdf + pos)) {
pos += pdf_len(pdf, len, pos);
pos += pdf_ws(pdf, len, pos);
return pos;
Expand Down Expand Up @@ -186,6 +186,8 @@ static void *my_memrchr(void *m, int c, long n)
static int prevline(char *pdf, int len, int off)
{
char *nl = my_memrchr(pdf, '\n', off);
/* not used */
(void) len;
if (nl && nl > pdf) {
char *nl2 = my_memrchr(pdf, '\n', nl - pdf - 1);
if (nl2)
Expand Down
5 changes: 3 additions & 2 deletions post.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void postps(void)
if (!strcmp("info", cmd)) {
char *spec = arg;
char kwd[128];
int i = 0;
size_t i = 0;
while (*spec == ' ')
spec++;
while (*spec && *spec != ' ') {
Expand Down Expand Up @@ -504,7 +504,8 @@ static struct paper {

static void setpagesize(char *s)
{
int d1, d2, n, i;
int d1, d2, n;
size_t i;
/* predefined paper sizes */
for (i = 0; i < LEN(papers); i++) {
if (!strcmp(papers[i].name, s)) {
Expand Down
9 changes: 9 additions & 0 deletions ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ void outeps(char *eps, int hwid, int vwid)

void outpdf(char *pdf, int hwid, int vwid)
{
/* not used */
(void) pdf;
(void) hwid;
(void) vwid;
}

void outlink(char *lnk, int hwid, int vwid)
Expand Down Expand Up @@ -368,6 +372,9 @@ void outinfo(char *kwd, char *val)

void outset(char *var, char *val)
{
/* not used */
(void) var;
(void) val;
}

void docpagebeg(int n)
Expand All @@ -380,6 +387,8 @@ void docpagebeg(int n)

void docpageend(int n)
{
/* not used */
(void) n;
out("cleartomark\n");
out("showpage\n");
out("saveobj restore\n");
Expand Down