X-Git-Url: http://git.savannah.gnu.org/gitweb/?p=enscript.git;a=blobdiff_plain;f=src%2Futil.c;h=0b4be6a6094f959111fe72fdb1042b37c4663218;hp=39b8441ce6c3caf4697fba7034a14ce5e6b0bc50;hb=3ca061ac1462c6f9aad2e9542bba3d763a90ec38;hpb=9510e4315705329e51b27fa2f3f688989b9fb37f diff --git a/src/util.c b/src/util.c index 39b8441..0b4be6a 100644 --- a/src/util.c +++ b/src/util.c @@ -23,6 +23,7 @@ */ #include "gsint.h" +#include /* * Types and definitions. @@ -30,7 +31,7 @@ #define CFG_FATAL(body) \ do { \ - fprintf (stderr, "%s:%s:%d: ", program, fname, line); \ + fprintf (stderr, "%s:%s:%d: ", program, buffer_ptr(&fname), line); \ fprintf body; \ fprintf (stderr, "\n"); \ fflush (stderr); \ @@ -92,6 +93,19 @@ static struct if (token2 == NULL) \ CFG_FATAL ((stderr, _("missing argument: %s"), token)); +void search_and_replace(char *str, char *search, char *replace) { + char *pos; + int search_len = strlen(search); + int replace_len = strlen(replace); + + while ((pos = strstr(str, search)) != NULL) { + char tmp[strlen(str) + 1]; + strcpy(tmp, pos + search_len); + strcpy(pos, replace); + strcpy(pos + replace_len, tmp); + str = pos + replace_len; + } +} int read_config (char *path, char *file) { @@ -108,10 +122,13 @@ read_config (char *path, char *file) fp = fopen (buffer_ptr (&fname), "r"); - buffer_uninit (&fname); + /* We wait to uninit the buffer so that CFG_FATAL can use it. */ if (fp == NULL) - return 0; + { + buffer_uninit (&fname); + return 0; + } while (fgets (buf, sizeof (buf), fp)) { @@ -135,6 +152,7 @@ read_config (char *path, char *file) { token2 = GET_TOKEN (NULL); CHECK_TOKEN (); + search_and_replace(token2,"$HOME",getenv("HOME")); xfree (afm_path); afm_path = xstrdup (token2); } @@ -168,6 +186,16 @@ read_config (char *path, char *file) { token2 = GET_TOKEN (NULL); CHECK_TOKEN (); +#ifdef LC_PAPER + if (!strcasecmp("LC_PAPER", token2)) + { + unsigned int paperheight = (unsigned int)nl_langinfo(_NL_PAPER_HEIGHT); + if (paperheight && paperheight == 279) + token2 = "letter"; + else + token2 = "a4"; + } +#endif xfree (media_name); media_name = xstrdup (token2); } @@ -436,6 +464,9 @@ read_config (char *path, char *file) else CFG_FATAL ((stderr, _("illegal option: %s"), token)); } + + fclose (fp); + buffer_uninit (&fname); return 1; } @@ -571,6 +602,7 @@ paste_file (char *name, char *suffix) (void **) &cp2)) { /* Not it is not, we must include this resource. */ +#include fprintf (ofp, "%%%%IncludeResource: font %s\n", cp); /* @@ -623,7 +655,7 @@ paste_file (char *name, char *suffix) if (j >= sizeof (name) - 1) FATAL ((stderr, _("%s:%d: %%Format: too long name, maxlen=%d"), - buffer_ptr (ctx.fullname), line, sizeof (name) - 1)); + buffer_ptr (ctx.fullname), line, (int)(sizeof (name) - 1))); /* Find the start of the format string. */ for (; buf[i] && isspace (buf[i]); i++) @@ -1354,7 +1386,8 @@ format_user_string (char *context_name, char *str) break; case 'c': /* `%c' trailing component of pwd. */ - getcwd (buf, sizeof (buf)); + if (!getcwd (buf, sizeof (buf))) + perror("getcwd"); cp = strrchr (buf, '/'); if (cp) cp++; @@ -1370,7 +1403,8 @@ format_user_string (char *context_name, char *str) break; case 'd': /* `%d' current working directory */ - getcwd (buf, sizeof (buf)); + if (!getcwd (buf, sizeof (buf))) + perror("getcwd"); APPEND_STR (buf); break; @@ -1838,7 +1872,7 @@ parse_float (char *string, int units, int horizontal) case 'l': if (horizontal) - val *= CHAR_WIDTH ('m'); + val *= FNT_CHAR_WIDTH ('m'); else val *= LINESKIP; break;