| 1 |
/* |
| 2 |
* utils.c: Functions common to pdfopen and pdfclose. |
| 3 |
* |
| 4 |
* Copyright (C) 2010--2014 Jim Diamond <[email protected]> |
| 5 |
* You may freely use, modify and/or distribute this file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
#include "utils.h" |
| 12 |
#include "xpdfopen.h" |
| 13 |
#include "externs.h" |
| 14 |
|
| 15 |
/* |
| 16 |
* Allocate memory and create a window name. |
| 17 |
* Return a pointer to the new string or NULL on failure. |
| 18 |
* |
| 19 |
* The caller is responsible for free()ing the memory allocated here. |
| 20 |
* |
| 21 |
* Note: acroread (at least AR 7, 8, 9) uses only the basename in the |
| 22 |
* window title. |
| 23 |
* xpdf uses the whole file name. |
| 24 |
* Other PDF viewers may need other treatment. |
| 25 |
*/ |
| 26 |
|
| 27 |
char * |
| 28 |
make_window_name(const char * fmt, const char * filename) |
| 29 |
{ |
| 30 |
char * window_name; |
| 31 |
const char * title_name; |
| 32 |
|
| 33 |
title_name = filename; |
| 34 |
if (strrchr(title_name, '/') != NULL |
| 35 |
&& strncasecmp(fmt, XPDF_WIN_NAME, strlen(XPDF_WIN_NAME))) |
| 36 |
title_name = strrchr(title_name, '/') + 1; |
| 37 |
|
| 38 |
window_name = malloc(strlen(fmt) + strlen(title_name) + 1); |
| 39 |
if (window_name != NULL) |
| 40 |
sprintf(window_name, fmt, title_name); |
| 41 |
else |
| 42 |
fprintf(stderr, "%s: out of memory\n", progname); |
| 43 |
|
| 44 |
return window_name; |
| 45 |
} |